staging: vme: make match() driver specific to improve non-VME64x support
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / vme / vme_api.txt
CommitLineData
bf39f9a5
MW
1 VME Device Driver API
2 =====================
3
4Driver registration
5===================
6
7As with other subsystems within the Linux kernel, VME device drivers register
8with the VME subsystem, typically called from the devices init routine. This is
25985edc 9achieved via a call to the following function:
bf39f9a5
MW
10
11 int vme_register_driver (struct vme_driver *driver);
12
13If driver registration is successful this function returns zero, if an error
14occurred a negative error code will be returned.
15
16A pointer to a structure of type 'vme_driver' must be provided to the
17registration function. The structure is as follows:
18
19 struct vme_driver {
20 struct list_head node;
5d6abf37
MV
21 const char *name;
22 int (*match)(struct vme_dev *);
23 int (*probe)(struct vme_dev *);
24 int (*remove)(struct vme_dev *);
25 void (*shutdown)(void);
26 struct device_driver driver;
27 struct list_head devices;
28 unsigned int ndev;
bf39f9a5
MW
29 };
30
5d6abf37
MV
31At the minimum, the '.name', '.match' and '.probe' elements of this structure
32should be correctly set. The '.name' element is a pointer to a string holding
33the device driver's name.
bf39f9a5 34
5d6abf37
MV
35The '.match' function allows controlling the number of devices that need to
36be registered. The match function should return 1 if a device should be
37probed and 0 otherwise. This example match function (from vme_user.c) limits
38the number of devices probed to one:
bf39f9a5 39
5d6abf37
MV
40 #define USER_BUS_MAX 1
41 ...
42 static int vme_user_match(struct vme_dev *vdev)
43 {
44 if (vdev->id.num >= USER_BUS_MAX)
45 return 0;
46 return 1;
47 }
8f966dc4 48
5d6abf37
MV
49The '.probe' element should contain a pointer to the probe routine. The
50probe routine is passed a 'struct vme_dev' pointer as an argument. The
51'struct vme_dev' structure looks like the following:
8f966dc4
MV
52
53 struct vme_dev {
54 struct vme_device_id id;
55 struct vme_bridge *bridge;
56 struct device dev;
57 };
58
59The 'bridge' field contains a pointer to the bridge device. The 'id' field
60contains information useful for the probe function:
61
62 struct vme_device_id {
63 int bus;
64 int slot;
5d6abf37 65 int num;
8f966dc4
MV
66 };
67
5d6abf37
MV
68Here, 'bus' is the number of the bus the device being probed is on. 'slot'
69refers to the specific slot on the VME bus. The 'num' field refers to the
70sequential device ID for this specific driver.
bf39f9a5
MW
71
72A function is also provided to unregister the driver from the VME core and is
73usually called from the device driver's exit routine:
74
75 void vme_unregister_driver (struct vme_driver *driver);
76
77
78Resource management
79===================
80
81Once a driver has registered with the VME core the provided probe routine will
82be called for each of the bus/slot combination that becomes valid as VME buses
83are themselves registered. The probe routine is passed a pointer to the devices
84device structure. This pointer should be saved, it will be required for
85requesting VME resources.
86
87The driver can request ownership of one or more master windows, slave windows
88and/or dma channels. Rather than allowing the device driver to request a
89specific window or DMA channel (which may be used by a different driver) this
90driver allows a resource to be assigned based on the required attributes of the
91driver in question:
92
8f966dc4 93 struct vme_resource * vme_master_request(struct vme_dev *dev,
bf39f9a5
MW
94 vme_address_t aspace, vme_cycle_t cycle, vme_width_t width);
95
8f966dc4 96 struct vme_resource * vme_slave_request(struct vme_dev *dev,
bf39f9a5
MW
97 vme_address_t aspace, vme_cycle_t cycle);
98
8f966dc4 99 struct vme_resource *vme_dma_request(struct vme_dev *dev,
4f723df4 100 vme_dma_route_t route);
bf39f9a5
MW
101
102For slave windows these attributes are split into those of type 'vme_address_t'
4f723df4
MW
103and 'vme_cycle_t'. Master windows add a further set of attributes
104'vme_cycle_t'. These attributes are defined as bitmasks and as such any
105combination of the attributes can be requested for a single window, the core
106will assign a window that meets the requirements, returning a pointer of type
107vme_resource that should be used to identify the allocated resource when it is
108used. For DMA controllers, the request function requires the potential
109direction of any transfers to be provided in the route attributes. This is
110typically VME-to-MEM and/or MEM-to-VME, though some hardware can support
111VME-to-VME and MEM-to-MEM transfers as well as test pattern generation. If an
112unallocated window fitting the requirements can not be found a NULL pointer
113will be returned.
bf39f9a5
MW
114
115Functions are also provided to free window allocations once they are no longer
116required. These functions should be passed the pointer to the resource provided
117during resource allocation:
118
119 void vme_master_free(struct vme_resource *res);
120
121 void vme_slave_free(struct vme_resource *res);
122
123 void vme_dma_free(struct vme_resource *res);
124
125
126Master windows
127==============
128
129Master windows provide access from the local processor[s] out onto the VME bus.
25985edc 130The number of windows available and the available access modes is dependent on
bf39f9a5
MW
131the underlying chipset. A window must be configured before it can be used.
132
133
134Master window configuration
135---------------------------
136
137Once a master window has been assigned the following functions can be used to
138configure it and retrieve the current settings:
139
140 int vme_master_set (struct vme_resource *res, int enabled,
141 unsigned long long base, unsigned long long size,
142 vme_address_t aspace, vme_cycle_t cycle, vme_width_t width);
143
144 int vme_master_get (struct vme_resource *res, int *enabled,
145 unsigned long long *base, unsigned long long *size,
146 vme_address_t *aspace, vme_cycle_t *cycle, vme_width_t *width);
147
148The address spaces, transfer widths and cycle types are the same as described
149under resource management, however some of the options are mutually exclusive.
150For example, only one address space may be specified.
151
152These functions return 0 on success or an error code should the call fail.
153
154
155Master window access
156--------------------
157
158The following functions can be used to read from and write to configured master
159windows. These functions return the number of bytes copied:
160
161 ssize_t vme_master_read(struct vme_resource *res, void *buf,
162 size_t count, loff_t offset);
163
164 ssize_t vme_master_write(struct vme_resource *res, void *buf,
165 size_t count, loff_t offset);
166
167In addition to simple reads and writes, a function is provided to do a
168read-modify-write transaction. This function returns the original value of the
169VME bus location :
170
171 unsigned int vme_master_rmw (struct vme_resource *res,
172 unsigned int mask, unsigned int compare, unsigned int swap,
173 loff_t offset);
174
175This functions by reading the offset, applying the mask. If the bits selected in
176the mask match with the values of the corresponding bits in the compare field,
177the value of swap is written the specified offset.
178
179
180Slave windows
181=============
182
183Slave windows provide devices on the VME bus access into mapped portions of the
184local memory. The number of windows available and the access modes that can be
25985edc 185used is dependent on the underlying chipset. A window must be configured before
bf39f9a5
MW
186it can be used.
187
188
189Slave window configuration
190--------------------------
191
192Once a slave window has been assigned the following functions can be used to
193configure it and retrieve the current settings:
194
195 int vme_slave_set (struct vme_resource *res, int enabled,
196 unsigned long long base, unsigned long long size,
197 dma_addr_t mem, vme_address_t aspace, vme_cycle_t cycle);
198
199 int vme_slave_get (struct vme_resource *res, int *enabled,
200 unsigned long long *base, unsigned long long *size,
201 dma_addr_t *mem, vme_address_t *aspace, vme_cycle_t *cycle);
202
203The address spaces, transfer widths and cycle types are the same as described
204under resource management, however some of the options are mutually exclusive.
205For example, only one address space may be specified.
206
207These functions return 0 on success or an error code should the call fail.
208
209
210Slave window buffer allocation
211------------------------------
212
213Functions are provided to allow the user to allocate and free a contiguous
214buffers which will be accessible by the VME bridge. These functions do not have
215to be used, other methods can be used to allocate a buffer, though care must be
216taken to ensure that they are contiguous and accessible by the VME bridge:
217
218 void * vme_alloc_consistent(struct vme_resource *res, size_t size,
219 dma_addr_t *mem);
220
221 void vme_free_consistent(struct vme_resource *res, size_t size,
222 void *virt, dma_addr_t mem);
223
224
225Slave window access
226-------------------
227
228Slave windows map local memory onto the VME bus, the standard methods for
229accessing memory should be used.
230
231
232DMA channels
233============
234
235The VME DMA transfer provides the ability to run link-list DMA transfers. The
236API introduces the concept of DMA lists. Each DMA list is a link-list which can
237be passed to a DMA controller. Multiple lists can be created, extended,
238executed, reused and destroyed.
239
240
241List Management
242---------------
243
244The following functions are provided to create and destroy DMA lists. Execution
245of a list will not automatically destroy the list, thus enabling a list to be
246reused for repetitive tasks:
247
248 struct vme_dma_list *vme_new_dma_list(struct vme_resource *res);
249
250 int vme_dma_list_free(struct vme_dma_list *list);
251
252
253List Population
254---------------
255
256An item can be added to a list using the following function ( the source and
257destination attributes need to be created before calling this function, this is
258covered under "Transfer Attributes"):
259
260 int vme_dma_list_add(struct vme_dma_list *list,
261 struct vme_dma_attr *src, struct vme_dma_attr *dest,
262 size_t count);
263
4f723df4
MW
264NOTE: The detailed attributes of the transfers source and destination
265 are not checked until an entry is added to a DMA list, the request
266 for a DMA channel purely checks the directions in which the
267 controller is expected to transfer data. As a result it is
268 possible for this call to return an error, for example if the
269 source or destination is in an unsupported VME address space.
bf39f9a5
MW
270
271Transfer Attributes
272-------------------
273
274The attributes for the source and destination are handled separately from adding
275an item to a list. This is due to the diverse attributes required for each type
276of source and destination. There are functions to create attributes for PCI, VME
277and pattern sources and destinations (where appropriate):
278
279Pattern source:
280
281 struct vme_dma_attr *vme_dma_pattern_attribute(u32 pattern,
282 vme_pattern_t type);
283
284PCI source or destination:
285
286 struct vme_dma_attr *vme_dma_pci_attribute(dma_addr_t mem);
287
288VME source or destination:
289
290 struct vme_dma_attr *vme_dma_vme_attribute(unsigned long long base,
291 vme_address_t aspace, vme_cycle_t cycle, vme_width_t width);
292
293The following function should be used to free an attribute:
294
295 void vme_dma_free_attribute(struct vme_dma_attr *attr);
296
297
298List Execution
299--------------
300
301The following function queues a list for execution. The function will return
302once the list has been executed:
303
304 int vme_dma_list_exec(struct vme_dma_list *list);
305
306
307Interrupts
308==========
309
310The VME API provides functions to attach and detach callbacks to specific VME
311level and status ID combinations and for the generation of VME interrupts with
312specific VME level and status IDs.
313
314
315Attaching Interrupt Handlers
316----------------------------
317
318The following functions can be used to attach and free a specific VME level and
319status ID combination. Any given combination can only be assigned a single
320callback function. A void pointer parameter is provided, the value of which is
321passed to the callback function, the use of this pointer is user undefined:
322
8f966dc4 323 int vme_irq_request(struct vme_dev *dev, int level, int statid,
bf39f9a5
MW
324 void (*callback)(int, int, void *), void *priv);
325
8f966dc4 326 void vme_irq_free(struct vme_dev *dev, int level, int statid);
bf39f9a5
MW
327
328The callback parameters are as follows. Care must be taken in writing a callback
329function, callback functions run in interrupt context:
330
331 void callback(int level, int statid, void *priv);
332
333
334Interrupt Generation
335--------------------
336
337The following function can be used to generate a VME interrupt at a given VME
338level and VME status ID:
339
8f966dc4 340 int vme_irq_generate(struct vme_dev *dev, int level, int statid);
bf39f9a5
MW
341
342
343Location monitors
344=================
345
346The VME API provides the following functionality to configure the location
347monitor.
348
349
350Location Monitor Management
351---------------------------
352
353The following functions are provided to request the use of a block of location
354monitors and to free them after they are no longer required:
355
8f966dc4 356 struct vme_resource * vme_lm_request(struct vme_dev *dev);
bf39f9a5
MW
357
358 void vme_lm_free(struct vme_resource * res);
359
360Each block may provide a number of location monitors, monitoring adjacent
361locations. The following function can be used to determine how many locations
362are provided:
363
364 int vme_lm_count(struct vme_resource * res);
365
366
367Location Monitor Configuration
368------------------------------
369
370Once a bank of location monitors has been allocated, the following functions
371are provided to configure the location and mode of the location monitor:
372
373 int vme_lm_set(struct vme_resource *res, unsigned long long base,
374 vme_address_t aspace, vme_cycle_t cycle);
375
376 int vme_lm_get(struct vme_resource *res, unsigned long long *base,
377 vme_address_t *aspace, vme_cycle_t *cycle);
378
379
380Location Monitor Use
381--------------------
382
383The following functions allow a callback to be attached and detached from each
384location monitor location. Each location monitor can monitor a number of
385adjacent locations:
386
387 int vme_lm_attach(struct vme_resource *res, int num,
388 void (*callback)(int));
389
390 int vme_lm_detach(struct vme_resource *res, int num);
391
392The callback function is declared as follows.
393
394 void callback(int num);
395
396
397Slot Detection
398==============
399
400This function returns the slot ID of the provided bridge.
401
8f966dc4 402 int vme_slot_get(struct vme_dev *dev);