summaryrefslogtreecommitdiffstats
path: root/include/linux/pci-epc.h
diff options
context:
space:
mode:
authorKishon Vijay Abraham I <kishon@ti.com>2017-04-10 09:55:10 -0400
committerBjorn Helgaas <bhelgaas@google.com>2017-04-11 15:18:35 -0400
commit5e8cb4033807e39849b753e5399ec130c0995f1f (patch)
treec2d924acfd79187ad4066f075998c3b21890d109 /include/linux/pci-epc.h
parentd4c7d1a089d6fddf38c4fcdc91f15791bfb59a95 (diff)
PCI: endpoint: Add EP core layer to enable EP controller and EP functions
Introduce a new EP core layer in order to support endpoint functions in linux kernel. This comprises the EPC library (Endpoint Controller Library) and EPF library (Endpoint Function Library). EPC library implements functions specific to an endpoint controller and EPF library implements functions specific to an endpoint function. Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com> Acked-by: Joao Pinto <jpinto@synopsys.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'include/linux/pci-epc.h')
-rw-r--r--include/linux/pci-epc.h142
1 files changed, 142 insertions, 0 deletions
diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
new file mode 100644
index 000000000000..8c63d3c37f76
--- /dev/null
+++ b/include/linux/pci-epc.h
@@ -0,0 +1,142 @@
1/**
2 * PCI Endpoint *Controller* (EPC) 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_EPC_H
13#define __LINUX_PCI_EPC_H
14
15#include <linux/pci-epf.h>
16
17struct pci_epc;
18
19enum pci_epc_irq_type {
20 PCI_EPC_IRQ_UNKNOWN,
21 PCI_EPC_IRQ_LEGACY,
22 PCI_EPC_IRQ_MSI,
23};
24
25/**
26 * struct pci_epc_ops - set of function pointers for performing EPC operations
27 * @write_header: ops to populate configuration space header
28 * @set_bar: ops to configure the BAR
29 * @clear_bar: ops to reset the BAR
30 * @map_addr: ops to map CPU address to PCI address
31 * @unmap_addr: ops to unmap CPU address and PCI address
32 * @set_msi: ops to set the requested number of MSI interrupts in the MSI
33 * capability register
34 * @get_msi: ops to get the number of MSI interrupts allocated by the RC from
35 * the MSI capability register
36 * @raise_irq: ops to raise a legacy or MSI interrupt
37 * @start: ops to start the PCI link
38 * @stop: ops to stop the PCI link
39 * @owner: the module owner containing the ops
40 */
41struct pci_epc_ops {
42 int (*write_header)(struct pci_epc *pci_epc,
43 struct pci_epf_header *hdr);
44 int (*set_bar)(struct pci_epc *epc, enum pci_barno bar,
45 dma_addr_t bar_phys, size_t size, int flags);
46 void (*clear_bar)(struct pci_epc *epc, enum pci_barno bar);
47 int (*map_addr)(struct pci_epc *epc, phys_addr_t addr,
48 u64 pci_addr, size_t size);
49 void (*unmap_addr)(struct pci_epc *epc, phys_addr_t addr);
50 int (*set_msi)(struct pci_epc *epc, u8 interrupts);
51 int (*get_msi)(struct pci_epc *epc);
52 int (*raise_irq)(struct pci_epc *pci_epc,
53 enum pci_epc_irq_type type, u8 interrupt_num);
54 int (*start)(struct pci_epc *epc);
55 void (*stop)(struct pci_epc *epc);
56 struct module *owner;
57};
58
59/**
60 * struct pci_epc_mem - address space of the endpoint controller
61 * @phys_base: physical base address of the PCI address space
62 * @size: the size of the PCI address space
63 * @bitmap: bitmap to manage the PCI address space
64 * @pages: number of bits representing the address region
65 */
66struct pci_epc_mem {
67 phys_addr_t phys_base;
68 size_t size;
69 unsigned long *bitmap;
70 int pages;
71};
72
73/**
74 * struct pci_epc - represents the PCI EPC device
75 * @dev: PCI EPC device
76 * @pci_epf: list of endpoint functions present in this EPC device
77 * @ops: function pointers for performing endpoint operations
78 * @mem: address space of the endpoint controller
79 * @max_functions: max number of functions that can be configured in this EPC
80 * @lock: spinlock to protect pci_epc ops
81 */
82struct pci_epc {
83 struct device dev;
84 struct list_head pci_epf;
85 const struct pci_epc_ops *ops;
86 struct pci_epc_mem *mem;
87 u8 max_functions;
88 /* spinlock to protect against concurrent access of EP controller */
89 spinlock_t lock;
90};
91
92#define to_pci_epc(device) container_of((device), struct pci_epc, dev)
93
94#define pci_epc_create(dev, ops) \
95 __pci_epc_create((dev), (ops), THIS_MODULE)
96#define devm_pci_epc_create(dev, ops) \
97 __devm_pci_epc_create((dev), (ops), THIS_MODULE)
98
99static inline void epc_set_drvdata(struct pci_epc *epc, void *data)
100{
101 dev_set_drvdata(&epc->dev, data);
102}
103
104static inline void *epc_get_drvdata(struct pci_epc *epc)
105{
106 return dev_get_drvdata(&epc->dev);
107}
108
109struct pci_epc *
110__devm_pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
111 struct module *owner);
112struct pci_epc *
113__pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
114 struct module *owner);
115void devm_pci_epc_destroy(struct device *dev, struct pci_epc *epc);
116void pci_epc_destroy(struct pci_epc *epc);
117int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf);
118void pci_epc_linkup(struct pci_epc *epc);
119void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf);
120int pci_epc_write_header(struct pci_epc *epc, struct pci_epf_header *hdr);
121int pci_epc_set_bar(struct pci_epc *epc, enum pci_barno bar,
122 dma_addr_t bar_phys, size_t size, int flags);
123void pci_epc_clear_bar(struct pci_epc *epc, int bar);
124int pci_epc_map_addr(struct pci_epc *epc, phys_addr_t phys_addr,
125 u64 pci_addr, size_t size);
126void pci_epc_unmap_addr(struct pci_epc *epc, phys_addr_t phys_addr);
127int pci_epc_set_msi(struct pci_epc *epc, u8 interrupts);
128int pci_epc_get_msi(struct pci_epc *epc);
129int pci_epc_raise_irq(struct pci_epc *epc, enum pci_epc_irq_type type,
130 u8 interrupt_num);
131int pci_epc_start(struct pci_epc *epc);
132void pci_epc_stop(struct pci_epc *epc);
133struct pci_epc *pci_epc_get(const char *epc_name);
134void pci_epc_put(struct pci_epc *epc);
135
136int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t phys_addr, size_t size);
137void pci_epc_mem_exit(struct pci_epc *epc);
138void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc,
139 phys_addr_t *phys_addr, size_t size);
140void pci_epc_mem_free_addr(struct pci_epc *epc, phys_addr_t phys_addr,
141 void __iomem *virt_addr, size_t size);
142#endif /* __LINUX_PCI_EPC_H */