]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/pci-epf.h
ACPI: fix acpi_find_child_device() invocation in acpi_preset_companion()
[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>
b352baf1 17#include <linux/pci.h>
5e8cb403
KVA
18
19struct pci_epf;
20
5e8cb403
KVA
21enum pci_barno {
22 BAR_0,
23 BAR_1,
24 BAR_2,
25 BAR_3,
26 BAR_4,
27 BAR_5,
28};
29
30/**
31 * struct pci_epf_header - represents standard configuration header
32 * @vendorid: identifies device manufacturer
33 * @deviceid: identifies a particular device
34 * @revid: specifies a device-specific revision identifier
35 * @progif_code: identifies a specific register-level programming interface
36 * @subclass_code: identifies more specifically the function of the device
37 * @baseclass_code: broadly classifies the type of function the device performs
38 * @cache_line_size: specifies the system cacheline size in units of DWORDs
39 * @subsys_vendor_id: vendor of the add-in card or subsystem
40 * @subsys_id: id specific to vendor
41 * @interrupt_pin: interrupt pin the device (or device function) uses
42 */
43struct pci_epf_header {
44 u16 vendorid;
45 u16 deviceid;
46 u8 revid;
47 u8 progif_code;
48 u8 subclass_code;
49 u8 baseclass_code;
50 u8 cache_line_size;
51 u16 subsys_vendor_id;
52 u16 subsys_id;
53 enum pci_interrupt_pin interrupt_pin;
54};
55
56/**
57 * struct pci_epf_ops - set of function pointers for performing EPF operations
58 * @bind: ops to perform when a EPC device has been bound to EPF device
59 * @unbind: ops to perform when a binding has been lost between a EPC device
60 * and EPF device
61 * @linkup: ops to perform when the EPC device has established a connection with
62 * a host system
63 */
64struct pci_epf_ops {
65 int (*bind)(struct pci_epf *epf);
66 void (*unbind)(struct pci_epf *epf);
67 void (*linkup)(struct pci_epf *epf);
68};
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
3a401a2c 78 * @group: configfs group corresponding to the PCI EPF driver
5e8cb403
KVA
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;
3a401a2c 88 struct config_group *group;
5e8cb403
KVA
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
98 * @size: the size of the address space present in BAR
99 */
100struct pci_epf_bar {
101 dma_addr_t phys_addr;
102 size_t size;
103};
104
105/**
106 * struct pci_epf - represents the PCI EPF device
107 * @dev: the PCI EPF device
108 * @name: the name of the PCI EPF device
109 * @header: represents standard configuration header
110 * @bar: represents the BAR of EPF device
111 * @msi_interrupts: number of MSI interrupts required by this function
112 * @func_no: unique function number within this endpoint device
113 * @epc: the EPC device to which this EPF device is bound
114 * @driver: the EPF driver to which this EPF device is bound
115 * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc
116 */
117struct pci_epf {
118 struct device dev;
119 const char *name;
120 struct pci_epf_header *header;
121 struct pci_epf_bar bar[6];
122 u8 msi_interrupts;
123 u8 func_no;
124
125 struct pci_epc *epc;
126 struct pci_epf_driver *driver;
127 struct list_head list;
128};
129
130#define to_pci_epf(epf_dev) container_of((epf_dev), struct pci_epf, dev)
131
132#define pci_epf_register_driver(driver) \
133 __pci_epf_register_driver((driver), THIS_MODULE)
134
135static inline void epf_set_drvdata(struct pci_epf *epf, void *data)
136{
137 dev_set_drvdata(&epf->dev, data);
138}
139
140static inline void *epf_get_drvdata(struct pci_epf *epf)
141{
142 return dev_get_drvdata(&epf->dev);
143}
144
f01f969e
KVA
145const struct pci_epf_device_id *
146pci_epf_match_device(const struct pci_epf_device_id *id, struct pci_epf *epf);
5e8cb403
KVA
147struct pci_epf *pci_epf_create(const char *name);
148void pci_epf_destroy(struct pci_epf *epf);
149int __pci_epf_register_driver(struct pci_epf_driver *driver,
150 struct module *owner);
151void pci_epf_unregister_driver(struct pci_epf_driver *driver);
152void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar);
153void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar);
154int pci_epf_bind(struct pci_epf *epf);
155void pci_epf_unbind(struct pci_epf *epf);
156void pci_epf_linkup(struct pci_epf *epf);
157#endif /* __LINUX_PCI_EPF_H */