1
2
3
4
5
6
7
8
9#ifndef __LINUX_PCI_EPC_H
10#define __LINUX_PCI_EPC_H
11
12#include <linux/pci-epf.h>
13
14struct pci_epc;
15
16enum pci_epc_irq_type {
17 PCI_EPC_IRQ_UNKNOWN,
18 PCI_EPC_IRQ_LEGACY,
19 PCI_EPC_IRQ_MSI,
20 PCI_EPC_IRQ_MSIX,
21};
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43struct pci_epc_ops {
44 int (*write_header)(struct pci_epc *epc, u8 func_no,
45 struct pci_epf_header *hdr);
46 int (*set_bar)(struct pci_epc *epc, u8 func_no,
47 struct pci_epf_bar *epf_bar);
48 void (*clear_bar)(struct pci_epc *epc, u8 func_no,
49 struct pci_epf_bar *epf_bar);
50 int (*map_addr)(struct pci_epc *epc, u8 func_no,
51 phys_addr_t addr, u64 pci_addr, size_t size);
52 void (*unmap_addr)(struct pci_epc *epc, u8 func_no,
53 phys_addr_t addr);
54 int (*set_msi)(struct pci_epc *epc, u8 func_no, u8 interrupts);
55 int (*get_msi)(struct pci_epc *epc, u8 func_no);
56 int (*set_msix)(struct pci_epc *epc, u8 func_no, u16 interrupts);
57 int (*get_msix)(struct pci_epc *epc, u8 func_no);
58 int (*raise_irq)(struct pci_epc *epc, u8 func_no,
59 enum pci_epc_irq_type type, u16 interrupt_num);
60 int (*start)(struct pci_epc *epc);
61 void (*stop)(struct pci_epc *epc);
62 const struct pci_epc_features* (*get_features)(struct pci_epc *epc,
63 u8 func_no);
64 struct module *owner;
65};
66
67
68
69
70
71
72
73
74
75struct pci_epc_mem {
76 phys_addr_t phys_base;
77 size_t size;
78 unsigned long *bitmap;
79 size_t page_size;
80 int pages;
81};
82
83
84
85
86
87
88
89
90
91
92
93struct pci_epc {
94 struct device dev;
95 struct list_head pci_epf;
96 const struct pci_epc_ops *ops;
97 struct pci_epc_mem *mem;
98 u8 max_functions;
99 struct config_group *group;
100
101 spinlock_t lock;
102};
103
104
105
106
107
108
109
110
111
112
113
114struct pci_epc_features {
115 unsigned int linkup_notifier : 1;
116 unsigned int msi_capable : 1;
117 unsigned int msix_capable : 1;
118 u8 reserved_bar;
119 u8 bar_fixed_64bit;
120 u64 bar_fixed_size[BAR_5 + 1];
121 size_t align;
122};
123
124#define to_pci_epc(device) container_of((device), struct pci_epc, dev)
125
126#define pci_epc_create(dev, ops) \
127 __pci_epc_create((dev), (ops), THIS_MODULE)
128#define devm_pci_epc_create(dev, ops) \
129 __devm_pci_epc_create((dev), (ops), THIS_MODULE)
130
131#define pci_epc_mem_init(epc, phys_addr, size) \
132 __pci_epc_mem_init((epc), (phys_addr), (size), PAGE_SIZE)
133
134static inline void epc_set_drvdata(struct pci_epc *epc, void *data)
135{
136 dev_set_drvdata(&epc->dev, data);
137}
138
139static inline void *epc_get_drvdata(struct pci_epc *epc)
140{
141 return dev_get_drvdata(&epc->dev);
142}
143
144struct pci_epc *
145__devm_pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
146 struct module *owner);
147struct pci_epc *
148__pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
149 struct module *owner);
150void devm_pci_epc_destroy(struct device *dev, struct pci_epc *epc);
151void pci_epc_destroy(struct pci_epc *epc);
152int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf);
153void pci_epc_linkup(struct pci_epc *epc);
154void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf);
155int pci_epc_write_header(struct pci_epc *epc, u8 func_no,
156 struct pci_epf_header *hdr);
157int pci_epc_set_bar(struct pci_epc *epc, u8 func_no,
158 struct pci_epf_bar *epf_bar);
159void pci_epc_clear_bar(struct pci_epc *epc, u8 func_no,
160 struct pci_epf_bar *epf_bar);
161int pci_epc_map_addr(struct pci_epc *epc, u8 func_no,
162 phys_addr_t phys_addr,
163 u64 pci_addr, size_t size);
164void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no,
165 phys_addr_t phys_addr);
166int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 interrupts);
167int pci_epc_get_msi(struct pci_epc *epc, u8 func_no);
168int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u16 interrupts);
169int pci_epc_get_msix(struct pci_epc *epc, u8 func_no);
170int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no,
171 enum pci_epc_irq_type type, u16 interrupt_num);
172int pci_epc_start(struct pci_epc *epc);
173void pci_epc_stop(struct pci_epc *epc);
174const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
175 u8 func_no);
176unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features
177 *epc_features);
178struct pci_epc *pci_epc_get(const char *epc_name);
179void pci_epc_put(struct pci_epc *epc);
180
181int __pci_epc_mem_init(struct pci_epc *epc, phys_addr_t phys_addr, size_t size,
182 size_t page_size);
183void pci_epc_mem_exit(struct pci_epc *epc);
184void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc,
185 phys_addr_t *phys_addr, size_t size);
186void pci_epc_mem_free_addr(struct pci_epc *epc, phys_addr_t phys_addr,
187 void __iomem *virt_addr, size_t size);
188#endif
189