Blame view

include/linux/pci-epc.h 9.47 KB
8cfab3cf6   Bjorn Helgaas   PCI: Add SPDX GPL...
1
  /* SPDX-License-Identifier: GPL-2.0 */
347269c11   Krzysztof Wilczyński   PCI: Fix kernel-d...
2
  /*
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
3
4
5
6
   * PCI Endpoint *Controller* (EPC) header file
   *
   * Copyright (C) 2017 Texas Instruments
   * Author: Kishon Vijay Abraham I <kishon@ti.com>
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
7
8
9
10
11
12
13
14
   */
  
  #ifndef __LINUX_PCI_EPC_H
  #define __LINUX_PCI_EPC_H
  
  #include <linux/pci-epf.h>
  
  struct pci_epc;
63840ff53   Kishon Vijay Abraham I   PCI: endpoint: Ad...
15
16
17
18
19
  enum pci_epc_interface_type {
  	UNKNOWN_INTERFACE = -1,
  	PRIMARY_INTERFACE,
  	SECONDARY_INTERFACE,
  };
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
20
21
22
23
  enum pci_epc_irq_type {
  	PCI_EPC_IRQ_UNKNOWN,
  	PCI_EPC_IRQ_LEGACY,
  	PCI_EPC_IRQ_MSI,
8963106ea   Gustavo Pimentel   PCI: endpoint: Ad...
24
  	PCI_EPC_IRQ_MSIX,
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
25
  };
63840ff53   Kishon Vijay Abraham I   PCI: endpoint: Ad...
26
27
28
29
30
31
32
33
34
35
36
37
  static inline const char *
  pci_epc_interface_string(enum pci_epc_interface_type type)
  {
  	switch (type) {
  	case PRIMARY_INTERFACE:
  		return "primary";
  	case SECONDARY_INTERFACE:
  		return "secondary";
  	default:
  		return "UNKNOWN interface";
  	}
  }
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
38
39
40
41
42
43
44
45
46
47
48
  /**
   * struct pci_epc_ops - set of function pointers for performing EPC operations
   * @write_header: ops to populate configuration space header
   * @set_bar: ops to configure the BAR
   * @clear_bar: ops to reset the BAR
   * @map_addr: ops to map CPU address to PCI address
   * @unmap_addr: ops to unmap CPU address and PCI address
   * @set_msi: ops to set the requested number of MSI interrupts in the MSI
   *	     capability register
   * @get_msi: ops to get the number of MSI interrupts allocated by the RC from
   *	     the MSI capability register
8963106ea   Gustavo Pimentel   PCI: endpoint: Ad...
49
50
51
52
   * @set_msix: ops to set the requested number of MSI-X interrupts in the
   *	     MSI-X capability register
   * @get_msix: ops to get the number of MSI-X interrupts allocated by the RC
   *	     from the MSI-X capability register
d3c70a98d   Gustavo Pimentel   PCI: Update xxx_p...
53
   * @raise_irq: ops to raise a legacy, MSI or MSI-X interrupt
87d5972e4   Kishon Vijay Abraham I   PCI: endpoint: Ad...
54
   * @map_msi_irq: ops to map physical address to MSI address and return MSI data
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
55
56
   * @start: ops to start the PCI link
   * @stop: ops to stop the PCI link
347269c11   Krzysztof Wilczyński   PCI: Fix kernel-d...
57
   * @get_features: ops to get the features supported by the EPC
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
58
59
60
   * @owner: the module owner containing the ops
   */
  struct pci_epc_ops {
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
61
  	int	(*write_header)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
62
  				struct pci_epf_header *hdr);
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
63
  	int	(*set_bar)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
bc4a48976   Niklas Cassel   PCI: endpoint: Si...
64
  			   struct pci_epf_bar *epf_bar);
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
65
  	void	(*clear_bar)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
77d08dbda   Niklas Cassel   PCI: endpoint: Ma...
66
  			     struct pci_epf_bar *epf_bar);
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
67
  	int	(*map_addr)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
4494738de   Cyrille Pitchen   PCI: endpoint: Ad...
68
  			    phys_addr_t addr, u64 pci_addr, size_t size);
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
69
  	void	(*unmap_addr)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
4494738de   Cyrille Pitchen   PCI: endpoint: Ad...
70
  			      phys_addr_t addr);
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
71
72
73
74
75
76
77
  	int	(*set_msi)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
  			   u8 interrupts);
  	int	(*get_msi)(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
  	int	(*set_msix)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
  			    u16 interrupts, enum pci_barno, u32 offset);
  	int	(*get_msix)(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
  	int	(*raise_irq)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
d3c70a98d   Gustavo Pimentel   PCI: Update xxx_p...
78
  			     enum pci_epc_irq_type type, u16 interrupt_num);
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
79
  	int	(*map_msi_irq)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
87d5972e4   Kishon Vijay Abraham I   PCI: endpoint: Ad...
80
81
82
  			       phys_addr_t phys_addr, u8 interrupt_num,
  			       u32 entry_size, u32 *msi_data,
  			       u32 *msi_addr_offset);
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
83
84
  	int	(*start)(struct pci_epc *epc);
  	void	(*stop)(struct pci_epc *epc);
41cb8d189   Kishon Vijay Abraham I   PCI: endpoint: Ad...
85
  	const struct pci_epc_features* (*get_features)(struct pci_epc *epc,
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
86
  						       u8 func_no, u8 vfunc_no);
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
87
88
89
90
  	struct module *owner;
  };
  
  /**
d45e3c1a5   Lad Prabhakar   PCI: endpoint: Ad...
91
92
93
94
95
96
97
98
99
100
101
102
   * struct pci_epc_mem_window - address window of the endpoint controller
   * @phys_base: physical base address of the PCI address window
   * @size: the size of the PCI address window
   * @page_size: size of each page
   */
  struct pci_epc_mem_window {
  	phys_addr_t	phys_base;
  	size_t		size;
  	size_t		page_size;
  };
  
  /**
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
103
   * struct pci_epc_mem - address space of the endpoint controller
d45e3c1a5   Lad Prabhakar   PCI: endpoint: Ad...
104
   * @window: address window of the endpoint controller
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
105
106
   * @bitmap: bitmap to manage the PCI address space
   * @pages: number of bits representing the address region
04e046ca5   Kishon Vijay Abraham I   PCI: endpoint: Fi...
107
   * @lock: mutex to protect bitmap
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
108
109
   */
  struct pci_epc_mem {
d45e3c1a5   Lad Prabhakar   PCI: endpoint: Ad...
110
  	struct pci_epc_mem_window window;
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
111
112
  	unsigned long	*bitmap;
  	int		pages;
04e046ca5   Kishon Vijay Abraham I   PCI: endpoint: Fi...
113
114
  	/* mutex to protect against concurrent access for memory allocation*/
  	struct mutex	lock;
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
115
116
117
118
119
120
121
  };
  
  /**
   * struct pci_epc - represents the PCI EPC device
   * @dev: PCI EPC device
   * @pci_epf: list of endpoint functions present in this EPC device
   * @ops: function pointers for performing endpoint operations
d45e3c1a5   Lad Prabhakar   PCI: endpoint: Ad...
122
123
124
125
126
   * @windows: array of address space of the endpoint controller
   * @mem: first window of the endpoint controller, which corresponds to
   *       default address space of the endpoint controller supporting
   *       single window.
   * @num_windows: number of windows supported by device
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
127
   * @max_functions: max number of functions that can be configured in this EPC
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
128
129
   * @max_vfs: Array indicating the maximum number of virtual functions that can
   *   be associated with each physical function
3a401a2ce   Kishon Vijay Abraham I   PCI: endpoint: Cr...
130
   * @group: configfs group representing the PCI EPC device
3d3248dbd   Kishon Vijay Abraham I   PCI: endpoint: Re...
131
   * @lock: mutex to protect pci_epc ops
2499ee84e   Kishon Vijay Abraham I   PCI: endpoint: As...
132
   * @function_num_map: bitmap to manage physical function number
5779dd0a7   Kishon Vijay Abraham I   PCI: endpoint: Us...
133
   * @notifier: used to notify EPF of any EPC events (like linkup)
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
134
135
136
137
138
   */
  struct pci_epc {
  	struct device			dev;
  	struct list_head		pci_epf;
  	const struct pci_epc_ops	*ops;
d45e3c1a5   Lad Prabhakar   PCI: endpoint: Ad...
139
  	struct pci_epc_mem		**windows;
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
140
  	struct pci_epc_mem		*mem;
d45e3c1a5   Lad Prabhakar   PCI: endpoint: Ad...
141
  	unsigned int			num_windows;
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
142
  	u8				max_functions;
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
143
  	u8				*max_vfs;
3a401a2ce   Kishon Vijay Abraham I   PCI: endpoint: Cr...
144
  	struct config_group		*group;
3d3248dbd   Kishon Vijay Abraham I   PCI: endpoint: Re...
145
146
  	/* mutex to protect against concurrent access of EP controller */
  	struct mutex			lock;
2499ee84e   Kishon Vijay Abraham I   PCI: endpoint: As...
147
  	unsigned long			function_num_map;
5779dd0a7   Kishon Vijay Abraham I   PCI: endpoint: Us...
148
  	struct atomic_notifier_head	notifier;
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
149
  };
41cb8d189   Kishon Vijay Abraham I   PCI: endpoint: Ad...
150
151
152
  /**
   * struct pci_epc_features - features supported by a EPC device per function
   * @linkup_notifier: indicate if the EPC device can notify EPF driver on link up
347269c11   Krzysztof Wilczyński   PCI: Fix kernel-d...
153
154
   * @core_init_notifier: indicate cores that can notify about their availability
   *			for initialization
41cb8d189   Kishon Vijay Abraham I   PCI: endpoint: Ad...
155
156
157
158
159
   * @msi_capable: indicate if the endpoint function has MSI capability
   * @msix_capable: indicate if the endpoint function has MSI-X capability
   * @reserved_bar: bitmap to indicate reserved BAR unavailable to function driver
   * @bar_fixed_64bit: bitmap to indicate fixed 64bit BARs
   * @bar_fixed_size: Array specifying the size supported by each BAR
2a9a80162   Kishon Vijay Abraham I   PCI: endpoint: Ad...
160
   * @align: alignment size required for BAR buffer allocation
41cb8d189   Kishon Vijay Abraham I   PCI: endpoint: Ad...
161
162
163
   */
  struct pci_epc_features {
  	unsigned int	linkup_notifier : 1;
3d5f7d9f6   Vidya Sagar   PCI: endpoint: Ad...
164
  	unsigned int	core_init_notifier : 1;
41cb8d189   Kishon Vijay Abraham I   PCI: endpoint: Ad...
165
166
167
168
  	unsigned int	msi_capable : 1;
  	unsigned int	msix_capable : 1;
  	u8	reserved_bar;
  	u8	bar_fixed_64bit;
c9c13ba42   Denis Efremov   PCI: Add PCI_STD_...
169
  	u64	bar_fixed_size[PCI_STD_NUM_BARS];
2a9a80162   Kishon Vijay Abraham I   PCI: endpoint: Ad...
170
  	size_t	align;
41cb8d189   Kishon Vijay Abraham I   PCI: endpoint: Ad...
171
  };
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
  #define to_pci_epc(device) container_of((device), struct pci_epc, dev)
  
  #define pci_epc_create(dev, ops)    \
  		__pci_epc_create((dev), (ops), THIS_MODULE)
  #define devm_pci_epc_create(dev, ops)    \
  		__devm_pci_epc_create((dev), (ops), THIS_MODULE)
  
  static inline void epc_set_drvdata(struct pci_epc *epc, void *data)
  {
  	dev_set_drvdata(&epc->dev, data);
  }
  
  static inline void *epc_get_drvdata(struct pci_epc *epc)
  {
  	return dev_get_drvdata(&epc->dev);
  }
5779dd0a7   Kishon Vijay Abraham I   PCI: endpoint: Us...
188
189
190
191
192
  static inline int
  pci_epc_register_notifier(struct pci_epc *epc, struct notifier_block *nb)
  {
  	return atomic_notifier_chain_register(&epc->notifier, nb);
  }
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
193
194
195
196
197
198
199
200
  struct pci_epc *
  __devm_pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
  		      struct module *owner);
  struct pci_epc *
  __pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
  		 struct module *owner);
  void devm_pci_epc_destroy(struct device *dev, struct pci_epc *epc);
  void pci_epc_destroy(struct pci_epc *epc);
63840ff53   Kishon Vijay Abraham I   PCI: endpoint: Ad...
201
202
  int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf,
  		    enum pci_epc_interface_type type);
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
203
  void pci_epc_linkup(struct pci_epc *epc);
0ef22dcf0   Vidya Sagar   PCI: endpoint: Ad...
204
  void pci_epc_init_notify(struct pci_epc *epc);
63840ff53   Kishon Vijay Abraham I   PCI: endpoint: Ad...
205
206
  void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf,
  			enum pci_epc_interface_type type);
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
207
  int pci_epc_write_header(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
4494738de   Cyrille Pitchen   PCI: endpoint: Ad...
208
  			 struct pci_epf_header *hdr);
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
209
  int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
bc4a48976   Niklas Cassel   PCI: endpoint: Si...
210
  		    struct pci_epf_bar *epf_bar);
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
211
  void pci_epc_clear_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
77d08dbda   Niklas Cassel   PCI: endpoint: Ma...
212
  		       struct pci_epf_bar *epf_bar);
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
213
  int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
4494738de   Cyrille Pitchen   PCI: endpoint: Ad...
214
  		     phys_addr_t phys_addr,
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
215
  		     u64 pci_addr, size_t size);
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
216
  void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
4494738de   Cyrille Pitchen   PCI: endpoint: Ad...
217
  			phys_addr_t phys_addr);
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
218
219
220
221
222
223
224
  int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
  		    u8 interrupts);
  int pci_epc_get_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
  int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
  		     u16 interrupts, enum pci_barno, u32 offset);
  int pci_epc_get_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
  int pci_epc_map_msi_irq(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
87d5972e4   Kishon Vijay Abraham I   PCI: endpoint: Ad...
225
226
  			phys_addr_t phys_addr, u8 interrupt_num,
  			u32 entry_size, u32 *msi_data, u32 *msi_addr_offset);
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
227
  int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
d3c70a98d   Gustavo Pimentel   PCI: Update xxx_p...
228
  		      enum pci_epc_irq_type type, u16 interrupt_num);
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
229
230
  int pci_epc_start(struct pci_epc *epc);
  void pci_epc_stop(struct pci_epc *epc);
41cb8d189   Kishon Vijay Abraham I   PCI: endpoint: Ad...
231
  const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
53fd3cbe5   Kishon Vijay Abraham I   PCI: endpoint: Ad...
232
  						    u8 func_no, u8 vfunc_no);
0e27aeccf   Kishon Vijay Abraham I   PCI: endpoint: Ma...
233
234
235
236
  enum pci_barno
  pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features);
  enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features
  					 *epc_features, enum pci_barno bar);
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
237
238
  struct pci_epc *pci_epc_get(const char *epc_name);
  void pci_epc_put(struct pci_epc *epc);
975cf23e3   Lad Prabhakar   PCI: endpoint: Pa...
239
240
  int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t base,
  		     size_t size, size_t page_size);
d45e3c1a5   Lad Prabhakar   PCI: endpoint: Ad...
241
242
243
  int pci_epc_multi_mem_init(struct pci_epc *epc,
  			   struct pci_epc_mem_window *window,
  			   unsigned int num_windows);
5e8cb4033   Kishon Vijay Abraham I   PCI: endpoint: Ad...
244
245
246
247
248
249
  void pci_epc_mem_exit(struct pci_epc *epc);
  void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc,
  				     phys_addr_t *phys_addr, size_t size);
  void pci_epc_mem_free_addr(struct pci_epc *epc, phys_addr_t phys_addr,
  			   void __iomem *virt_addr, size_t size);
  #endif /* __LINUX_PCI_EPC_H */