]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/pci-epf.h
Documentation: PCI: Guide to use PCI endpoint configfs
[mirror_ubuntu-bionic-kernel.git] / include / linux / pci-epf.h
CommitLineData
5e8cb403
KVA
1/**
2 * PCI Endpoint *Function* (EPF) header file
3 *
4 * Copyright (C) 2017 Texas Instruments
5 * Author: Kishon Vijay Abraham I <kishon@ti.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 of
9 * the License as published by the Free Software Foundation.
10 */
11
12#ifndef __LINUX_PCI_EPF_H
13#define __LINUX_PCI_EPF_H
14
15#include <linux/device.h>
16#include <linux/mod_devicetable.h>
17
18struct pci_epf;
19
20enum pci_interrupt_pin {
21 PCI_INTERRUPT_UNKNOWN,
22 PCI_INTERRUPT_INTA,
23 PCI_INTERRUPT_INTB,
24 PCI_INTERRUPT_INTC,
25 PCI_INTERRUPT_INTD,
26};
27
28enum pci_barno {
29 BAR_0,
30 BAR_1,
31 BAR_2,
32 BAR_3,
33 BAR_4,
34 BAR_5,
35};
36
37/**
38 * struct pci_epf_header - represents standard configuration header
39 * @vendorid: identifies device manufacturer
40 * @deviceid: identifies a particular device
41 * @revid: specifies a device-specific revision identifier
42 * @progif_code: identifies a specific register-level programming interface
43 * @subclass_code: identifies more specifically the function of the device
44 * @baseclass_code: broadly classifies the type of function the device performs
45 * @cache_line_size: specifies the system cacheline size in units of DWORDs
46 * @subsys_vendor_id: vendor of the add-in card or subsystem
47 * @subsys_id: id specific to vendor
48 * @interrupt_pin: interrupt pin the device (or device function) uses
49 */
50struct pci_epf_header {
51 u16 vendorid;
52 u16 deviceid;
53 u8 revid;
54 u8 progif_code;
55 u8 subclass_code;
56 u8 baseclass_code;
57 u8 cache_line_size;
58 u16 subsys_vendor_id;
59 u16 subsys_id;
60 enum pci_interrupt_pin interrupt_pin;
61};
62
63/**
64 * struct pci_epf_ops - set of function pointers for performing EPF operations
65 * @bind: ops to perform when a EPC device has been bound to EPF device
66 * @unbind: ops to perform when a binding has been lost between a EPC device
67 * and EPF device
68 * @linkup: ops to perform when the EPC device has established a connection with
69 * a host system
70 */
71struct pci_epf_ops {
72 int (*bind)(struct pci_epf *epf);
73 void (*unbind)(struct pci_epf *epf);
74 void (*linkup)(struct pci_epf *epf);
75};
76
77/**
78 * struct pci_epf_driver - represents the PCI EPF driver
79 * @probe: ops to perform when a new EPF device has been bound to the EPF driver
80 * @remove: ops to perform when the binding between the EPF device and EPF
81 * driver is broken
82 * @driver: PCI EPF driver
83 * @ops: set of function pointers for performing EPF operations
84 * @owner: the owner of the module that registers the PCI EPF driver
85 * @id_table: identifies EPF devices for probing
86 */
87struct pci_epf_driver {
88 int (*probe)(struct pci_epf *epf);
89 int (*remove)(struct pci_epf *epf);
90
91 struct device_driver driver;
92 struct pci_epf_ops *ops;
93 struct module *owner;
94 const struct pci_epf_device_id *id_table;
95};
96
97#define to_pci_epf_driver(drv) (container_of((drv), struct pci_epf_driver, \
98 driver))
99
100/**
101 * struct pci_epf_bar - represents the BAR of EPF device
102 * @phys_addr: physical address that should be mapped to the BAR
103 * @size: the size of the address space present in BAR
104 */
105struct pci_epf_bar {
106 dma_addr_t phys_addr;
107 size_t size;
108};
109
110/**
111 * struct pci_epf - represents the PCI EPF device
112 * @dev: the PCI EPF device
113 * @name: the name of the PCI EPF device
114 * @header: represents standard configuration header
115 * @bar: represents the BAR of EPF device
116 * @msi_interrupts: number of MSI interrupts required by this function
117 * @func_no: unique function number within this endpoint device
118 * @epc: the EPC device to which this EPF device is bound
119 * @driver: the EPF driver to which this EPF device is bound
120 * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc
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;
128 u8 func_no;
129
130 struct pci_epc *epc;
131 struct pci_epf_driver *driver;
132 struct list_head list;
133};
134
135#define to_pci_epf(epf_dev) container_of((epf_dev), struct pci_epf, dev)
136
137#define pci_epf_register_driver(driver) \
138 __pci_epf_register_driver((driver), THIS_MODULE)
139
140static inline void epf_set_drvdata(struct pci_epf *epf, void *data)
141{
142 dev_set_drvdata(&epf->dev, data);
143}
144
145static inline void *epf_get_drvdata(struct pci_epf *epf)
146{
147 return dev_get_drvdata(&epf->dev);
148}
149
150struct pci_epf *pci_epf_create(const char *name);
151void pci_epf_destroy(struct pci_epf *epf);
152int __pci_epf_register_driver(struct pci_epf_driver *driver,
153 struct module *owner);
154void pci_epf_unregister_driver(struct pci_epf_driver *driver);
155void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar);
156void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar);
157int pci_epf_bind(struct pci_epf *epf);
158void pci_epf_unbind(struct pci_epf *epf);
159void pci_epf_linkup(struct pci_epf *epf);
160#endif /* __LINUX_PCI_EPF_H */