1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Adapted from Linux kernel driver
4 * Copyright (C) 2017 Texas Instruments
5 * Author: Kishon Vijay Abraham I <kishon@ti.com>
8 * Ramon Fried <ramon.fried@gmail.com>
17 * enum pci_interrupt_pin - PCI INTx interrupt values
18 * @PCI_INTERRUPT_UNKNOWN: Unknown or unassigned interrupt
19 * @PCI_INTERRUPT_INTA: PCI INTA pin
20 * @PCI_INTERRUPT_INTB: PCI INTB pin
21 * @PCI_INTERRUPT_INTC: PCI INTC pin
22 * @PCI_INTERRUPT_INTD: PCI INTD pin
24 * Corresponds to values for legacy PCI INTx interrupts, as can be found in the
25 * PCI_INTERRUPT_PIN register.
27 enum pci_interrupt_pin {
28 PCI_INTERRUPT_UNKNOWN,
44 enum pci_ep_irq_type {
52 * struct pci_bar - represents the BAR (Base Address Register) of EP device
53 * @phys_addr: physical address that should be mapped to the BAR
54 * @size: the size of the address space present in BAR
55 * pci_barno: number of pci BAR to set (0..5)
56 * @flags: BAR access flags
66 * struct pci_ep_header - represents standard configuration header
67 * @vendorid: identifies device manufacturer
68 * @deviceid: identifies a particular device
69 * @revid: specifies a device-specific revision identifier
70 * @progif_code: identifies a specific register-level programming interface
71 * @subclass_code: identifies more specifically the function of the device
72 * @baseclass_code: broadly classifies the type of function the device performs
73 * @cache_line_size: specifies the system cacheline size in units of DWORDs
74 * @subsys_vendor_id: vendor of the add-in card or subsystem
75 * @subsys_id: id specific to vendor
76 * @interrupt_pin: interrupt pin the device (or device function) uses
78 struct pci_ep_header {
88 enum pci_interrupt_pin interrupt_pin;
91 /* PCI endpoint operations */
94 * write_header() - Write a PCI configuration space header
96 * @dev: device to write to
97 * @func_num: EP function to fill
98 * @hdr: header to write
99 * @return 0 if OK, -ve on error
101 int (*write_header)(struct udevice *dev, uint func_num,
102 struct pci_ep_header *hdr);
104 * read_header() - Read a PCI configuration space header
106 * @dev: device to write to
107 * @func_num: EP function to fill
108 * @hdr: header to read to
109 * @return 0 if OK, -ve on error
111 int (*read_header)(struct udevice *dev, uint func_num,
112 struct pci_ep_header *hdr);
114 * set_bar() - Set BAR (Base Address Register) properties
116 * @dev: device to set
117 * @func_num: EP function to set
119 * @return 0 if OK, -ve on error
121 int (*set_bar)(struct udevice *dev, uint func_num,
122 struct pci_bar *bar);
124 * read_bar() - Read BAR (Base Address Register) properties
126 * @dev: device to read
127 * @func_num: EP function to read
128 * @bar: struct to copy data to
129 * @barno: bar number to read
130 * @return 0 if OK, -ve on error
132 int (*read_bar)(struct udevice *dev, uint func_num,
133 struct pci_bar *bar, enum pci_barno barno);
135 * clear_bar() - clear BAR (Base Address Register)
137 * @dev: device to clear
138 * @func_num: EP function to clear
140 * @return 0 if OK, -ve on error
142 int (*clear_bar)(struct udevice *dev, uint func_num,
145 * map_addr() - map CPU address to PCI address
147 * outband region is used in order to generate PCI read/write
148 * transaction from local memory/write.
150 * @dev: device to set
151 * @func_num: EP function to set
152 * @addr: local physical address base
153 * @pci_addr: pci address to translate to
155 * @return 0 if OK, -ve on error
157 int (*map_addr)(struct udevice *dev, uint func_num,
158 phys_addr_t addr, u64 pci_addr, size_t size);
160 * unmap_addr() - unmap CPU address to PCI address
162 * unmap previously mapped region.
164 * @dev: device to set
165 * @func_num: EP function to set
166 * @addr: local physical address base
167 * @return 0 if OK, -ve on error
169 int (*unmap_addr)(struct udevice *dev, uint func_num,
172 * set_msi() - set msi capability property
174 * set the number of required MSI vectors the device
175 * needs for operation.
177 * @dev: device to set
178 * @func_num: EP function to set
179 * @interrupts: required interrupts count
180 * @return 0 if OK, -ve on error
182 int (*set_msi)(struct udevice *dev, uint func_num, uint interrupts);
185 * get_msi() - get the number of MSI interrupts allocated by the host.
187 * Read the Multiple Message Enable bitfield from
188 * Message control register.
190 * @dev: device to use
191 * @func_num: EP function to use
192 * @return msi count if OK, -EINVAL if msi were not enabled at host.
194 int (*get_msi)(struct udevice *dev, uint func_num);
197 * set_msix() - set msix capability property
199 * set the number of required MSIx vectors the device
200 * needs for operation.
202 * @dev: device to set
203 * @func_num: EP function to set
204 * @interrupts: required interrupts count
205 * @return 0 if OK, -ve on error
207 int (*set_msix)(struct udevice *dev, uint func_num,
211 * get_msix() - get the number of MSIx interrupts allocated by the host.
213 * Read the Multiple Message Enable bitfield from
214 * Message control register.
216 * @dev: device to use
217 * @func_num: EP function to use
218 * @return msi count if OK, -EINVAL if msi were not enabled at host.
220 int (*get_msix)(struct udevice *dev, uint func_num);
223 * raise_irq() - raise a legacy, MSI or MSI-X interrupt
225 * @dev: device to set
226 * @func_num: EP function to set
227 * @type: type of irq to send
228 * @interrupt_num: interrupt vector to use
229 * @return 0 if OK, -ve on error
231 int (*raise_irq)(struct udevice *dev, uint func_num,
232 enum pci_ep_irq_type type, uint interrupt_num);
234 * start() - start the PCI link
236 * @dev: device to set
237 * @return 0 if OK, -ve on error
239 int (*start)(struct udevice *dev);
242 * stop() - stop the PCI link
244 * @dev: device to set
245 * @return 0 if OK, -ve on error
247 int (*stop)(struct udevice *dev);
250 #define pci_ep_get_ops(dev) ((struct pci_ep_ops *)(dev)->driver->ops)
253 * pci_ep_write_header() - Write a PCI configuration space header
255 * @dev: device to write to
256 * @func_num: EP function to fill
257 * @hdr: header to write
258 * @return 0 if OK, -ve on error
260 int pci_ep_write_header(struct udevice *dev, uint func_num,
261 struct pci_ep_header *hdr);
264 * dm_pci_ep_read_header() - Read a PCI configuration space header
266 * @dev: device to write to
267 * @func_num: EP function to fill
268 * @hdr: header to read to
269 * @return 0 if OK, -ve on error
271 int pci_ep_read_header(struct udevice *dev, uint func_num,
272 struct pci_ep_header *hdr);
274 * pci_ep_set_bar() - Set BAR (Base Address Register) properties
276 * @dev: device to set
277 * @func_num: EP function to set
279 * @return 0 if OK, -ve on error
281 int pci_ep_set_bar(struct udevice *dev, uint func_num, struct pci_bar *bar);
284 * pci_ep_read_bar() - Read BAR (Base Address Register) properties
286 * @dev: device to read
287 * @func_num: EP function to read
288 * @bar: struct to copy data to
289 * @barno: bar number to read
290 * @return 0 if OK, -ve on error
292 int pci_ep_read_bar(struct udevice *dev, uint func_no, struct pci_bar *ep_bar,
293 enum pci_barno barno);
296 * pci_ep_clear_bar() - Clear BAR (Base Address Register)
297 * mark the BAR as empty so host won't map it.
298 * @dev: device to clear
299 * @func_num: EP function to clear
301 * @return 0 if OK, -ve on error
303 int pci_ep_clear_bar(struct udevice *dev, uint func_num, enum pci_barno bar);
305 * pci_ep_map_addr() - map CPU address to PCI address
307 * outband region is used in order to generate PCI read/write
308 * transaction from local memory/write.
310 * @dev: device to set
311 * @func_num: EP function to set
312 * @addr: local physical address base
313 * @pci_addr: pci address to translate to
315 * @return 0 if OK, -ve on error
317 int pci_ep_map_addr(struct udevice *dev, uint func_num, phys_addr_t addr,
318 u64 pci_addr, size_t size);
320 * pci_ep_unmap_addr() - unmap CPU address to PCI address
322 * unmap previously mapped region.
324 * @dev: device to set
325 * @func_num: EP function to set
326 * @addr: local physical address base
327 * @return 0 if OK, -ve on error
329 int pci_ep_unmap_addr(struct udevice *dev, uint func_num, phys_addr_t addr);
332 * pci_ep_set_msi() - set msi capability property
334 * set the number of required MSI vectors the device
335 * needs for operation.
337 * @dev: device to set
338 * @func_num: EP function to set
339 * @interrupts: required interrupts count
340 * @return 0 if OK, -ve on error
342 int pci_ep_set_msi(struct udevice *dev, uint func_num, uint interrupts);
345 * pci_ep_get_msi() - get the number of MSI interrupts allocated by the host.
347 * Read the Multiple Message Enable bitfield from
348 * Message control register.
350 * @dev: device to use
351 * @func_num: EP function to use
352 * @return msi count if OK, -EINVAL if msi were not enabled at host.
354 int pci_ep_get_msi(struct udevice *dev, uint func_num);
357 * pci_ep_set_msix() - set msi capability property
359 * set the number of required MSIx vectors the device
360 * needs for operation.
362 * @dev: device to set
363 * @func_num: EP function to set
364 * @interrupts: required interrupts count
365 * @return 0 if OK, -ve on error
367 int pci_ep_set_msix(struct udevice *dev, uint func_num, uint interrupts);
370 * pci_ep_get_msix() - get the number of MSIx interrupts allocated by the host.
372 * Read the Multiple Message Enable bitfield from
373 * Message control register.
375 * @dev: device to use
376 * @func_num: EP function to use
377 * @return msi count if OK, -EINVAL if msi were not enabled at host.
379 int pci_ep_get_msix(struct udevice *dev, uint func_num);
382 * pci_ep_raise_irq() - raise a legacy, MSI or MSI-X interrupt
384 * @dev: device to set
385 * @func_num: EP function to set
386 * @type: type of irq to send
387 * @interrupt_num: interrupt vector to use
388 * @return 0 if OK, -ve on error
390 int pci_ep_raise_irq(struct udevice *dev, uint func_num,
391 enum pci_ep_irq_type type, uint interrupt_num);
393 * pci_ep_start() - start the PCI link
395 * Enable PCI endpoint device and start link
398 * @dev: device to set
399 * @return 0 if OK, -ve on error
401 int pci_ep_start(struct udevice *dev);
404 * pci_ep_stop() - stop the PCI link
406 * Disable PCI endpoint device and stop
409 * @dev: device to set
410 * @return 0 if OK, -ve on error
412 int pci_ep_stop(struct udevice *dev);