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 enum pci_epc_interface_type;
20 enum pci_notify_event {
36 * struct pci_epf_header - represents standard configuration header
37 * @vendorid: identifies device manufacturer
38 * @deviceid: identifies a particular device
39 * @revid: specifies a device-specific revision identifier
40 * @progif_code: identifies a specific register-level programming interface
41 * @subclass_code: identifies more specifically the function of the device
42 * @baseclass_code: broadly classifies the type of function the device performs
43 * @cache_line_size: specifies the system cacheline size in units of DWORDs
44 * @subsys_vendor_id: vendor of the add-in card or subsystem
45 * @subsys_id: id specific to vendor
46 * @interrupt_pin: interrupt pin the device (or device function) uses
48 struct pci_epf_header {
58 enum pci_interrupt_pin interrupt_pin;
62 * struct pci_epf_ops - set of function pointers for performing EPF operations
63 * @bind: ops to perform when a EPC device has been bound to EPF device
64 * @unbind: ops to perform when a binding has been lost between a EPC device
66 * @add_cfs: ops to initialize function specific configfs attributes
69 int (*bind)(struct pci_epf *epf);
70 void (*unbind)(struct pci_epf *epf);
71 struct config_group *(*add_cfs)(struct pci_epf *epf,
72 struct config_group *group);
76 * struct pci_epf_driver - represents the PCI EPF driver
77 * @probe: ops to perform when a new EPF device has been bound to the EPF driver
78 * @remove: ops to perform when the binding between the EPF device and EPF
80 * @driver: PCI EPF driver
81 * @ops: set of function pointers for performing EPF operations
82 * @owner: the owner of the module that registers the PCI EPF driver
83 * @epf_group: list of configfs group corresponding to the PCI EPF driver
84 * @id_table: identifies EPF devices for probing
86 struct pci_epf_driver {
87 int (*probe)(struct pci_epf *epf);
88 int (*remove)(struct pci_epf *epf);
90 struct device_driver driver;
91 struct pci_epf_ops *ops;
93 struct list_head epf_group;
94 const struct pci_epf_device_id *id_table;
97 #define to_pci_epf_driver(drv) (container_of((drv), struct pci_epf_driver, \
101 * struct pci_epf_bar - represents the BAR of EPF device
102 * @phys_addr: physical address that should be mapped to the BAR
103 * @addr: virtual address corresponding to the @phys_addr
104 * @size: the size of the address space present in BAR
107 dma_addr_t phys_addr;
110 enum pci_barno barno;
115 * struct pci_epf - represents the PCI EPF device
116 * @dev: the PCI EPF device
117 * @name: the name of the PCI EPF device
118 * @header: represents standard configuration header
119 * @bar: represents the BAR of EPF device
120 * @msi_interrupts: number of MSI interrupts required by this function
121 * @func_no: unique function number within this endpoint device
122 * @epc: the EPC device to which this EPF device is bound
123 * @driver: the EPF driver to which this EPF device is bound
124 * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc
125 * @nb: notifier block to notify EPF of any EPC events (like linkup)
126 * @lock: mutex to protect pci_epf_ops
127 * @sec_epc: the secondary EPC device to which this EPF device is bound
128 * @sec_epc_list: to add pci_epf as list of PCI endpoint functions to secondary
130 * @sec_epc_bar: represents the BAR of EPF device associated with secondary EPC
131 * @sec_epc_func_no: unique (physical) function number within the secondary EPC
132 * @group: configfs group associated with the EPF device
137 struct pci_epf_header *header;
138 struct pci_epf_bar bar[6];
144 struct pci_epf_driver *driver;
145 struct list_head list;
146 struct notifier_block nb;
147 /* mutex to protect against concurrent access of pci_epf_ops */
150 /* Below members are to attach secondary EPC to an endpoint function */
151 struct pci_epc *sec_epc;
152 struct list_head sec_epc_list;
153 struct pci_epf_bar sec_epc_bar[6];
155 struct config_group *group;
159 * struct pci_epf_msix_tbl - represents the MSIX table entry structure
160 * @msg_addr: Writes to this address will trigger MSIX interrupt in host
161 * @msg_data: Data that should be written to @msg_addr to trigger MSIX interrupt
162 * @vector_ctrl: Identifies if the function is prohibited from sending a message
163 * using this MSIX table entry
165 struct pci_epf_msix_tbl {
171 #define to_pci_epf(epf_dev) container_of((epf_dev), struct pci_epf, dev)
173 #define pci_epf_register_driver(driver) \
174 __pci_epf_register_driver((driver), THIS_MODULE)
176 static inline void epf_set_drvdata(struct pci_epf *epf, void *data)
178 dev_set_drvdata(&epf->dev, data);
181 static inline void *epf_get_drvdata(struct pci_epf *epf)
183 return dev_get_drvdata(&epf->dev);
186 struct pci_epf *pci_epf_create(const char *name);
187 void pci_epf_destroy(struct pci_epf *epf);
188 int __pci_epf_register_driver(struct pci_epf_driver *driver,
189 struct module *owner);
190 void pci_epf_unregister_driver(struct pci_epf_driver *driver);
191 void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
192 size_t align, enum pci_epc_interface_type type);
193 void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar,
194 enum pci_epc_interface_type type);
195 int pci_epf_bind(struct pci_epf *epf);
196 void pci_epf_unbind(struct pci_epf *epf);
197 struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf,
198 struct config_group *group);
199 #endif /* __LINUX_PCI_EPF_H */