1 /* SPDX-License-Identifier: GPL-2.0 */
3 * PCI Endpoint *Function* (EPF) header file
5 * Copyright (C) 2017 Texas Instruments
6 * Author: Kishon Vijay Abraham I <kishon@ti.com>
9 #ifndef __LINUX_PCI_EPF_H
10 #define __LINUX_PCI_EPF_H
12 #include <linux/configfs.h>
13 #include <linux/device.h>
14 #include <linux/mod_devicetable.h>
15 #include <linux/pci.h>
18 struct pci_epc_features;
19 enum pci_epc_interface_type;
32 * struct pci_epf_header - represents standard configuration header
33 * @vendorid: identifies device manufacturer
34 * @deviceid: identifies a particular device
35 * @revid: specifies a device-specific revision identifier
36 * @progif_code: identifies a specific register-level programming interface
37 * @subclass_code: identifies more specifically the function of the device
38 * @baseclass_code: broadly classifies the type of function the device performs
39 * @cache_line_size: specifies the system cacheline size in units of DWORDs
40 * @subsys_vendor_id: vendor of the add-in card or subsystem
41 * @subsys_id: ID specific to vendor
42 * @interrupt_pin: interrupt pin the device (or device function) uses
44 struct pci_epf_header {
54 enum pci_interrupt_pin interrupt_pin;
58 * struct pci_epf_ops - set of function pointers for performing EPF operations
59 * @bind: ops to perform when a EPC device has been bound to EPF device
60 * @unbind: ops to perform when a binding has been lost between a EPC device
62 * @add_cfs: ops to initialize function-specific configfs attributes
65 int (*bind)(struct pci_epf *epf);
66 void (*unbind)(struct pci_epf *epf);
67 struct config_group *(*add_cfs)(struct pci_epf *epf,
68 struct config_group *group);
72 * struct pci_epc_event_ops - Callbacks for capturing the EPC events
73 * @epc_init: Callback for the EPC initialization complete event
74 * @epc_deinit: Callback for the EPC deinitialization event
75 * @link_up: Callback for the EPC link up event
76 * @link_down: Callback for the EPC link down event
77 * @bus_master_enable: Callback for the EPC Bus Master Enable event
79 struct pci_epc_event_ops {
80 int (*epc_init)(struct pci_epf *epf);
81 void (*epc_deinit)(struct pci_epf *epf);
82 int (*link_up)(struct pci_epf *epf);
83 int (*link_down)(struct pci_epf *epf);
84 int (*bus_master_enable)(struct pci_epf *epf);
88 * struct pci_epf_driver - represents the PCI EPF driver
89 * @probe: ops to perform when a new EPF device has been bound to the EPF driver
90 * @remove: ops to perform when the binding between the EPF device and EPF
92 * @driver: PCI EPF driver
93 * @ops: set of function pointers for performing EPF operations
94 * @owner: the owner of the module that registers the PCI EPF driver
95 * @epf_group: list of configfs group corresponding to the PCI EPF driver
96 * @id_table: identifies EPF devices for probing
98 struct pci_epf_driver {
99 int (*probe)(struct pci_epf *epf,
100 const struct pci_epf_device_id *id);
101 void (*remove)(struct pci_epf *epf);
103 struct device_driver driver;
104 const struct pci_epf_ops *ops;
105 struct module *owner;
106 struct list_head epf_group;
107 const struct pci_epf_device_id *id_table;
110 #define to_pci_epf_driver(drv) container_of_const((drv), struct pci_epf_driver, driver)
113 * struct pci_epf_bar - represents the BAR of EPF device
114 * @phys_addr: physical address that should be mapped to the BAR
115 * @addr: virtual address corresponding to the @phys_addr
116 * @size: the size of the address space present in BAR
117 * @aligned_size: the size actually allocated to accommodate the iATU alignment
120 * @flags: flags that are set for the BAR
123 dma_addr_t phys_addr;
127 enum pci_barno barno;
132 * struct pci_epf - represents the PCI EPF device
133 * @dev: the PCI EPF device
134 * @name: the name of the PCI EPF device
135 * @header: represents standard configuration header
136 * @bar: represents the BAR of EPF device
137 * @msi_interrupts: number of MSI interrupts required by this function
138 * @msix_interrupts: number of MSI-X interrupts required by this function
139 * @func_no: unique (physical) function number within this endpoint device
140 * @vfunc_no: unique virtual function number within a physical function
141 * @epc: the EPC device to which this EPF device is bound
142 * @epf_pf: the physical EPF device to which this virtual EPF device is bound
143 * @driver: the EPF driver to which this EPF device is bound
144 * @id: pointer to the EPF device ID
145 * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc
146 * @lock: mutex to protect pci_epf_ops
147 * @sec_epc: the secondary EPC device to which this EPF device is bound
148 * @sec_epc_list: to add pci_epf as list of PCI endpoint functions to secondary
150 * @sec_epc_bar: represents the BAR of EPF device associated with secondary EPC
151 * @sec_epc_func_no: unique (physical) function number within the secondary EPC
152 * @group: configfs group associated with the EPF device
153 * @is_bound: indicates if bind notification to function driver has been invoked
154 * @is_vf: true - virtual function, false - physical function
155 * @vfunction_num_map: bitmap to manage virtual function number
156 * @pci_vepf: list of virtual endpoint functions associated with this function
157 * @event_ops: callbacks for capturing the EPC events
162 struct pci_epf_header *header;
163 struct pci_epf_bar bar[PCI_STD_NUM_BARS];
170 struct pci_epf *epf_pf;
171 struct pci_epf_driver *driver;
172 const struct pci_epf_device_id *id;
173 struct list_head list;
174 /* mutex to protect against concurrent access of pci_epf_ops */
177 /* Below members are to attach secondary EPC to an endpoint function */
178 struct pci_epc *sec_epc;
179 struct list_head sec_epc_list;
180 struct pci_epf_bar sec_epc_bar[PCI_STD_NUM_BARS];
182 struct config_group *group;
183 unsigned int is_bound;
185 unsigned long vfunction_num_map;
186 struct list_head pci_vepf;
187 const struct pci_epc_event_ops *event_ops;
191 * struct pci_epf_msix_tbl - represents the MSI-X table entry structure
192 * @msg_addr: Writes to this address will trigger MSI-X interrupt in host
193 * @msg_data: Data that should be written to @msg_addr to trigger MSI-X
195 * @vector_ctrl: Identifies if the function is prohibited from sending a message
196 * using this MSI-X table entry
198 struct pci_epf_msix_tbl {
204 #define to_pci_epf(epf_dev) container_of((epf_dev), struct pci_epf, dev)
206 #define pci_epf_register_driver(driver) \
207 __pci_epf_register_driver((driver), THIS_MODULE)
209 static inline void epf_set_drvdata(struct pci_epf *epf, void *data)
211 dev_set_drvdata(&epf->dev, data);
214 static inline void *epf_get_drvdata(struct pci_epf *epf)
216 return dev_get_drvdata(&epf->dev);
219 struct pci_epf *pci_epf_create(const char *name);
220 void pci_epf_destroy(struct pci_epf *epf);
221 int __pci_epf_register_driver(struct pci_epf_driver *driver,
222 struct module *owner);
223 void pci_epf_unregister_driver(struct pci_epf_driver *driver);
224 void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
225 const struct pci_epc_features *epc_features,
226 enum pci_epc_interface_type type);
227 void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar,
228 enum pci_epc_interface_type type);
229 int pci_epf_bind(struct pci_epf *epf);
230 void pci_epf_unbind(struct pci_epf *epf);
231 int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
232 void pci_epf_remove_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
233 #endif /* __LINUX_PCI_EPF_H */