blob: fa3aca43eb19203ac461f456bcdb4041a9946762 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* SPDX-License-Identifier: GPL-2.0 */
2/**
3 * PCI Endpoint *Function* (EPF) header file
4 *
5 * Copyright (C) 2017 Texas Instruments
6 * Author: Kishon Vijay Abraham I <kishon@ti.com>
7 */
8
9#ifndef __LINUX_PCI_EPF_H
10#define __LINUX_PCI_EPF_H
11
12#include <linux/device.h>
13#include <linux/mod_devicetable.h>
14#include <linux/pci.h>
15
16struct pci_epf;
17
Olivier Deprez157378f2022-04-04 15:47:50 +020018enum pci_notify_event {
19 CORE_INIT,
20 LINK_UP,
21};
22
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000023enum pci_barno {
Olivier Deprez157378f2022-04-04 15:47:50 +020024 NO_BAR = -1,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000025 BAR_0,
26 BAR_1,
27 BAR_2,
28 BAR_3,
29 BAR_4,
30 BAR_5,
31};
32
33/**
34 * struct pci_epf_header - represents standard configuration header
35 * @vendorid: identifies device manufacturer
36 * @deviceid: identifies a particular device
37 * @revid: specifies a device-specific revision identifier
38 * @progif_code: identifies a specific register-level programming interface
39 * @subclass_code: identifies more specifically the function of the device
40 * @baseclass_code: broadly classifies the type of function the device performs
41 * @cache_line_size: specifies the system cacheline size in units of DWORDs
42 * @subsys_vendor_id: vendor of the add-in card or subsystem
43 * @subsys_id: id specific to vendor
44 * @interrupt_pin: interrupt pin the device (or device function) uses
45 */
46struct pci_epf_header {
47 u16 vendorid;
48 u16 deviceid;
49 u8 revid;
50 u8 progif_code;
51 u8 subclass_code;
52 u8 baseclass_code;
53 u8 cache_line_size;
54 u16 subsys_vendor_id;
55 u16 subsys_id;
56 enum pci_interrupt_pin interrupt_pin;
57};
58
59/**
60 * struct pci_epf_ops - set of function pointers for performing EPF operations
61 * @bind: ops to perform when a EPC device has been bound to EPF device
62 * @unbind: ops to perform when a binding has been lost between a EPC device
63 * and EPF device
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000064 */
65struct pci_epf_ops {
66 int (*bind)(struct pci_epf *epf);
67 void (*unbind)(struct pci_epf *epf);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000068};
69
70/**
71 * struct pci_epf_driver - represents the PCI EPF driver
72 * @probe: ops to perform when a new EPF device has been bound to the EPF driver
73 * @remove: ops to perform when the binding between the EPF device and EPF
74 * driver is broken
75 * @driver: PCI EPF driver
76 * @ops: set of function pointers for performing EPF operations
77 * @owner: the owner of the module that registers the PCI EPF driver
78 * @epf_group: list of configfs group corresponding to the PCI EPF driver
79 * @id_table: identifies EPF devices for probing
80 */
81struct pci_epf_driver {
82 int (*probe)(struct pci_epf *epf);
83 int (*remove)(struct pci_epf *epf);
84
85 struct device_driver driver;
86 struct pci_epf_ops *ops;
87 struct module *owner;
88 struct list_head epf_group;
89 const struct pci_epf_device_id *id_table;
90};
91
92#define to_pci_epf_driver(drv) (container_of((drv), struct pci_epf_driver, \
93 driver))
94
95/**
96 * struct pci_epf_bar - represents the BAR of EPF device
97 * @phys_addr: physical address that should be mapped to the BAR
Olivier Deprez157378f2022-04-04 15:47:50 +020098 * @addr: virtual address corresponding to the @phys_addr
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000099 * @size: the size of the address space present in BAR
100 */
101struct pci_epf_bar {
102 dma_addr_t phys_addr;
Olivier Deprez157378f2022-04-04 15:47:50 +0200103 void *addr;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000104 size_t size;
105 enum pci_barno barno;
106 int flags;
107};
108
109/**
110 * struct pci_epf - represents the PCI EPF device
111 * @dev: the PCI EPF device
112 * @name: the name of the PCI EPF device
113 * @header: represents standard configuration header
114 * @bar: represents the BAR of EPF device
115 * @msi_interrupts: number of MSI interrupts required by this function
116 * @func_no: unique function number within this endpoint device
117 * @epc: the EPC device to which this EPF device is bound
118 * @driver: the EPF driver to which this EPF device is bound
119 * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc
Olivier Deprez157378f2022-04-04 15:47:50 +0200120 * @nb: notifier block to notify EPF of any EPC events (like linkup)
121 * @lock: mutex to protect pci_epf_ops
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000122 */
123struct pci_epf {
124 struct device dev;
125 const char *name;
126 struct pci_epf_header *header;
127 struct pci_epf_bar bar[6];
128 u8 msi_interrupts;
129 u16 msix_interrupts;
130 u8 func_no;
131
132 struct pci_epc *epc;
133 struct pci_epf_driver *driver;
134 struct list_head list;
Olivier Deprez157378f2022-04-04 15:47:50 +0200135 struct notifier_block nb;
136 /* mutex to protect against concurrent access of pci_epf_ops */
137 struct mutex lock;
138};
139
140/**
141 * struct pci_epf_msix_tbl - represents the MSIX table entry structure
142 * @msg_addr: Writes to this address will trigger MSIX interrupt in host
143 * @msg_data: Data that should be written to @msg_addr to trigger MSIX interrupt
144 * @vector_ctrl: Identifies if the function is prohibited from sending a message
145 * using this MSIX table entry
146 */
147struct pci_epf_msix_tbl {
148 u64 msg_addr;
149 u32 msg_data;
150 u32 vector_ctrl;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000151};
152
153#define to_pci_epf(epf_dev) container_of((epf_dev), struct pci_epf, dev)
154
155#define pci_epf_register_driver(driver) \
156 __pci_epf_register_driver((driver), THIS_MODULE)
157
158static inline void epf_set_drvdata(struct pci_epf *epf, void *data)
159{
160 dev_set_drvdata(&epf->dev, data);
161}
162
163static inline void *epf_get_drvdata(struct pci_epf *epf)
164{
165 return dev_get_drvdata(&epf->dev);
166}
167
168const struct pci_epf_device_id *
169pci_epf_match_device(const struct pci_epf_device_id *id, struct pci_epf *epf);
170struct pci_epf *pci_epf_create(const char *name);
171void pci_epf_destroy(struct pci_epf *epf);
172int __pci_epf_register_driver(struct pci_epf_driver *driver,
173 struct module *owner);
174void pci_epf_unregister_driver(struct pci_epf_driver *driver);
David Brazdil0f672f62019-12-10 10:32:29 +0000175void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
176 size_t align);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000177void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar);
178int pci_epf_bind(struct pci_epf *epf);
179void pci_epf_unbind(struct pci_epf *epf);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000180#endif /* __LINUX_PCI_EPF_H */