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