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