~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/pci-epc.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /*
  3  * PCI Endpoint *Controller* (EPC) header file
  4  *
  5  * Copyright (C) 2017 Texas Instruments
  6  * Author: Kishon Vijay Abraham I <kishon@ti.com>
  7  */
  8 
  9 #ifndef __LINUX_PCI_EPC_H
 10 #define __LINUX_PCI_EPC_H
 11 
 12 #include <linux/pci-epf.h>
 13 
 14 struct pci_epc;
 15 
 16 enum pci_epc_interface_type {
 17         UNKNOWN_INTERFACE = -1,
 18         PRIMARY_INTERFACE,
 19         SECONDARY_INTERFACE,
 20 };
 21 
 22 static inline const char *
 23 pci_epc_interface_string(enum pci_epc_interface_type type)
 24 {
 25         switch (type) {
 26         case PRIMARY_INTERFACE:
 27                 return "primary";
 28         case SECONDARY_INTERFACE:
 29                 return "secondary";
 30         default:
 31                 return "UNKNOWN interface";
 32         }
 33 }
 34 
 35 /**
 36  * struct pci_epc_ops - set of function pointers for performing EPC operations
 37  * @write_header: ops to populate configuration space header
 38  * @set_bar: ops to configure the BAR
 39  * @clear_bar: ops to reset the BAR
 40  * @map_addr: ops to map CPU address to PCI address
 41  * @unmap_addr: ops to unmap CPU address and PCI address
 42  * @set_msi: ops to set the requested number of MSI interrupts in the MSI
 43  *           capability register
 44  * @get_msi: ops to get the number of MSI interrupts allocated by the RC from
 45  *           the MSI capability register
 46  * @set_msix: ops to set the requested number of MSI-X interrupts in the
 47  *           MSI-X capability register
 48  * @get_msix: ops to get the number of MSI-X interrupts allocated by the RC
 49  *           from the MSI-X capability register
 50  * @raise_irq: ops to raise a legacy, MSI or MSI-X interrupt
 51  * @map_msi_irq: ops to map physical address to MSI address and return MSI data
 52  * @start: ops to start the PCI link
 53  * @stop: ops to stop the PCI link
 54  * @get_features: ops to get the features supported by the EPC
 55  * @owner: the module owner containing the ops
 56  */
 57 struct pci_epc_ops {
 58         int     (*write_header)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 59                                 struct pci_epf_header *hdr);
 60         int     (*set_bar)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 61                            struct pci_epf_bar *epf_bar);
 62         void    (*clear_bar)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 63                              struct pci_epf_bar *epf_bar);
 64         int     (*map_addr)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 65                             phys_addr_t addr, u64 pci_addr, size_t size);
 66         void    (*unmap_addr)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 67                               phys_addr_t addr);
 68         int     (*set_msi)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 69                            u8 interrupts);
 70         int     (*get_msi)(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
 71         int     (*set_msix)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 72                             u16 interrupts, enum pci_barno, u32 offset);
 73         int     (*get_msix)(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
 74         int     (*raise_irq)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 75                              unsigned int type, u16 interrupt_num);
 76         int     (*map_msi_irq)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 77                                phys_addr_t phys_addr, u8 interrupt_num,
 78                                u32 entry_size, u32 *msi_data,
 79                                u32 *msi_addr_offset);
 80         int     (*start)(struct pci_epc *epc);
 81         void    (*stop)(struct pci_epc *epc);
 82         const struct pci_epc_features* (*get_features)(struct pci_epc *epc,
 83                                                        u8 func_no, u8 vfunc_no);
 84         struct module *owner;
 85 };
 86 
 87 /**
 88  * struct pci_epc_mem_window - address window of the endpoint controller
 89  * @phys_base: physical base address of the PCI address window
 90  * @size: the size of the PCI address window
 91  * @page_size: size of each page
 92  */
 93 struct pci_epc_mem_window {
 94         phys_addr_t     phys_base;
 95         size_t          size;
 96         size_t          page_size;
 97 };
 98 
 99 /**
100  * struct pci_epc_mem - address space of the endpoint controller
101  * @window: address window of the endpoint controller
102  * @bitmap: bitmap to manage the PCI address space
103  * @pages: number of bits representing the address region
104  * @lock: mutex to protect bitmap
105  */
106 struct pci_epc_mem {
107         struct pci_epc_mem_window window;
108         unsigned long   *bitmap;
109         int             pages;
110         /* mutex to protect against concurrent access for memory allocation*/
111         struct mutex    lock;
112 };
113 
114 /**
115  * struct pci_epc - represents the PCI EPC device
116  * @dev: PCI EPC device
117  * @pci_epf: list of endpoint functions present in this EPC device
118  * @list_lock: Mutex for protecting pci_epf list
119  * @ops: function pointers for performing endpoint operations
120  * @windows: array of address space of the endpoint controller
121  * @mem: first window of the endpoint controller, which corresponds to
122  *       default address space of the endpoint controller supporting
123  *       single window.
124  * @num_windows: number of windows supported by device
125  * @max_functions: max number of functions that can be configured in this EPC
126  * @max_vfs: Array indicating the maximum number of virtual functions that can
127  *   be associated with each physical function
128  * @group: configfs group representing the PCI EPC device
129  * @lock: mutex to protect pci_epc ops
130  * @function_num_map: bitmap to manage physical function number
131  * @domain_nr: PCI domain number of the endpoint controller
132  * @init_complete: flag to indicate whether the EPC initialization is complete
133  *                 or not
134  */
135 struct pci_epc {
136         struct device                   dev;
137         struct list_head                pci_epf;
138         struct mutex                    list_lock;
139         const struct pci_epc_ops        *ops;
140         struct pci_epc_mem              **windows;
141         struct pci_epc_mem              *mem;
142         unsigned int                    num_windows;
143         u8                              max_functions;
144         u8                              *max_vfs;
145         struct config_group             *group;
146         /* mutex to protect against concurrent access of EP controller */
147         struct mutex                    lock;
148         unsigned long                   function_num_map;
149         int                             domain_nr;
150         bool                            init_complete;
151 };
152 
153 /**
154  * @BAR_PROGRAMMABLE: The BAR mask can be configured by the EPC.
155  * @BAR_FIXED: The BAR mask is fixed by the hardware.
156  * @BAR_RESERVED: The BAR should not be touched by an EPF driver.
157  */
158 enum pci_epc_bar_type {
159         BAR_PROGRAMMABLE = 0,
160         BAR_FIXED,
161         BAR_RESERVED,
162 };
163 
164 /**
165  * struct pci_epc_bar_desc - hardware description for a BAR
166  * @type: the type of the BAR
167  * @fixed_size: the fixed size, only applicable if type is BAR_FIXED_MASK.
168  * @only_64bit: if true, an EPF driver is not allowed to choose if this BAR
169  *              should be configured as 32-bit or 64-bit, the EPF driver must
170  *              configure this BAR as 64-bit. Additionally, the BAR succeeding
171  *              this BAR must be set to type BAR_RESERVED.
172  *
173  *              only_64bit should not be set on a BAR of type BAR_RESERVED.
174  *              (If BARx is a 64-bit BAR that an EPF driver is not allowed to
175  *              touch, then both BARx and BARx+1 must be set to type
176  *              BAR_RESERVED.)
177  */
178 struct pci_epc_bar_desc {
179         enum pci_epc_bar_type type;
180         u64 fixed_size;
181         bool only_64bit;
182 };
183 
184 /**
185  * struct pci_epc_features - features supported by a EPC device per function
186  * @linkup_notifier: indicate if the EPC device can notify EPF driver on link up
187  * @msi_capable: indicate if the endpoint function has MSI capability
188  * @msix_capable: indicate if the endpoint function has MSI-X capability
189  * @bar: array specifying the hardware description for each BAR
190  * @align: alignment size required for BAR buffer allocation
191  */
192 struct pci_epc_features {
193         unsigned int    linkup_notifier : 1;
194         unsigned int    msi_capable : 1;
195         unsigned int    msix_capable : 1;
196         struct  pci_epc_bar_desc bar[PCI_STD_NUM_BARS];
197         size_t  align;
198 };
199 
200 #define to_pci_epc(device) container_of((device), struct pci_epc, dev)
201 
202 #ifdef CONFIG_PCI_ENDPOINT
203 
204 #define pci_epc_create(dev, ops)    \
205                 __pci_epc_create((dev), (ops), THIS_MODULE)
206 #define devm_pci_epc_create(dev, ops)    \
207                 __devm_pci_epc_create((dev), (ops), THIS_MODULE)
208 
209 static inline void epc_set_drvdata(struct pci_epc *epc, void *data)
210 {
211         dev_set_drvdata(&epc->dev, data);
212 }
213 
214 static inline void *epc_get_drvdata(struct pci_epc *epc)
215 {
216         return dev_get_drvdata(&epc->dev);
217 }
218 
219 struct pci_epc *
220 __devm_pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
221                       struct module *owner);
222 struct pci_epc *
223 __pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
224                  struct module *owner);
225 void devm_pci_epc_destroy(struct device *dev, struct pci_epc *epc);
226 void pci_epc_destroy(struct pci_epc *epc);
227 int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf,
228                     enum pci_epc_interface_type type);
229 void pci_epc_linkup(struct pci_epc *epc);
230 void pci_epc_linkdown(struct pci_epc *epc);
231 void pci_epc_init_notify(struct pci_epc *epc);
232 void pci_epc_notify_pending_init(struct pci_epc *epc, struct pci_epf *epf);
233 void pci_epc_deinit_notify(struct pci_epc *epc);
234 void pci_epc_bus_master_enable_notify(struct pci_epc *epc);
235 void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf,
236                         enum pci_epc_interface_type type);
237 int pci_epc_write_header(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
238                          struct pci_epf_header *hdr);
239 int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
240                     struct pci_epf_bar *epf_bar);
241 void pci_epc_clear_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
242                        struct pci_epf_bar *epf_bar);
243 int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
244                      phys_addr_t phys_addr,
245                      u64 pci_addr, size_t size);
246 void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
247                         phys_addr_t phys_addr);
248 int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
249                     u8 interrupts);
250 int pci_epc_get_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
251 int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
252                      u16 interrupts, enum pci_barno, u32 offset);
253 int pci_epc_get_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
254 int pci_epc_map_msi_irq(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
255                         phys_addr_t phys_addr, u8 interrupt_num,
256                         u32 entry_size, u32 *msi_data, u32 *msi_addr_offset);
257 int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
258                       unsigned int type, u16 interrupt_num);
259 int pci_epc_start(struct pci_epc *epc);
260 void pci_epc_stop(struct pci_epc *epc);
261 const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
262                                                     u8 func_no, u8 vfunc_no);
263 enum pci_barno
264 pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features);
265 enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features
266                                          *epc_features, enum pci_barno bar);
267 struct pci_epc *pci_epc_get(const char *epc_name);
268 void pci_epc_put(struct pci_epc *epc);
269 
270 int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t base,
271                      size_t size, size_t page_size);
272 int pci_epc_multi_mem_init(struct pci_epc *epc,
273                            struct pci_epc_mem_window *window,
274                            unsigned int num_windows);
275 void pci_epc_mem_exit(struct pci_epc *epc);
276 void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc,
277                                      phys_addr_t *phys_addr, size_t size);
278 void pci_epc_mem_free_addr(struct pci_epc *epc, phys_addr_t phys_addr,
279                            void __iomem *virt_addr, size_t size);
280 
281 #else
282 static inline void pci_epc_init_notify(struct pci_epc *epc)
283 {
284 }
285 
286 static inline void pci_epc_deinit_notify(struct pci_epc *epc)
287 {
288 }
289 #endif /* CONFIG_PCI_ENDPOINT */
290 #endif /* __LINUX_PCI_EPC_H */
291 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php