vmod/vmodttl: fixed bug related to luns not ordered and/or not starting from zero.
[ht-drivers.git] / vmebridge / driver / vme_cesif.c
bloba751fdbdbea7b91a072d1344ac4c86a80df505ec
1 /*
2 * vme_cesif - Emulation for the LynxOS CES driver
4 * Copyright (c) 2009 Sebastien Dugue
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
14 * This file provides emulation for the find_controller(), return_controller(),
15 * vme_intset() and vme_intclr() interfaces of the LynxOS CES driver.
18 #define DEBUG
19 #include <linux/device.h>
21 #include "vmebus.h"
22 #include "vme_bridge.h"
24 /**
25 * find_controller() - Maps a VME address space into the PCI address space
26 * @vmeaddr: VME physical start address of the mapping
27 * @len: Window size (must be a multiple of 64k)
28 * @am: VME address modifier
29 * @offset: Offset in the mapping for read access test (Not used)
30 * @size: Data width
31 * @param: VME mapping parameters
33 * This function is an emulation of the CES driver functionality on LynxOS.
35 * The CES function interface does not give all the needed VME parameters, so
36 * the following choices were made and may have to be tweaked.
38 * - if read prefetch is enabled the the prefetch size is set to 2 cache lines
39 * - the VME address and size are automatically aligned on 64k if needed
40 * - the VME address is limited to 32 bits
42 * The kernel allocated mapping descriptor address (cookie) is stored in
43 * the pdparam_master sgmin field for use by return_controller().
45 * @return virtual address of the mapping - if success.
46 * @return -1 - on failure.
49 unsigned long find_controller(unsigned long vmeaddr, unsigned long len,
50 unsigned long am, unsigned long offset,
51 unsigned long size, struct pdparam_master *param)
53 struct vme_mapping *desc;
54 int rc = 0;
56 /* Allocate our mapping descriptor */
57 if ((desc = kzalloc(sizeof(struct vme_mapping), GFP_KERNEL)) == NULL) {
58 printk(KERN_ERR PFX "%s - "
59 "Failed to allocate mapping descriptor\n", __func__);
60 return -1;
63 /* Now fill it with the parameters we got */
64 if (param->rdpref) {
65 desc->read_prefetch_enabled = 1;
66 desc->read_prefetch_size = VME_PREFETCH_2;
69 switch (size) {
70 case 2:
71 desc->data_width = VME_D16;
72 break;
73 case 4:
74 desc->data_width = VME_D32;
75 break;
76 default:
77 printk(KERN_ERR PFX "%s - Unsupported data width %ld\n",
78 __func__, size);
79 rc = -1;
80 goto out_free;
81 break;
84 desc->am = am;
85 desc->bcast_select = 0;
88 * Note: no rounding up/down for size and address at this point,
89 * since that's taken care of when creating the window (if any).
91 desc->sizel = len;
92 desc->sizeu = 0;
94 desc->vme_addrl = vmeaddr;
95 desc->vme_addru = 0;
98 * Now we're all set up, just call the mapping function. We force
99 * window creation if no existing mapping can be found.
101 if ((rc = vme_find_mapping(desc, 1))) {
102 printk(KERN_ERR PFX "%s - "
103 "Failed (rc is %d) to find a mapping "
104 "for VME addr: %.8lx Size:%8lx AM: %.2lx\n",
105 __func__, rc, vmeaddr, len, am);
106 rc = -1;
107 goto out_free;
110 printk(KERN_DEBUG PFX "%s - "
111 "Mapping found, VME addr: %.8lx "
112 "Size:%.8lx AM: %.2lx mapped at %p\n",
113 __func__, vmeaddr, len, am, desc->kernel_va);
115 return (unsigned long)desc->kernel_va;
117 out_free:
118 kfree(desc);
120 return rc;
122 EXPORT_SYMBOL_GPL(find_controller);
125 * @brief Release a VME mapping
127 * @param logaddr - CPU logical address returned by @ref find_controller()
128 * @param len - size of the mapped window in bytes.
130 * This function is an emulation of the CES driver functionality on LynxOS.
132 * @return 0 - on success.
133 * @return -1 - if fails.
135 unsigned long return_controller(unsigned logaddr, unsigned len)
137 struct vme_mapping *desc = find_vme_mapping_from_addr(logaddr);
138 int err;
140 if (!desc) {
141 printk(KERN_ERR PFX "%s - mapping not found @ 0x%x",
142 __func__, logaddr);
143 return -1;
146 err = vme_release_mapping(desc, 1);
147 if (!err)
148 return 0;
150 printk(KERN_ERR PFX "%s - failed to remove mapping @ 0x%x (err=%d)\n",
151 __func__, logaddr, err);
152 return -1;
154 EXPORT_SYMBOL_GPL(return_controller);
157 * vme_intset() - Install an interrupt handler for the given vector
158 * @vec: Interrupt vector
159 * @handler: Handler function
160 * @arg: Handler argument
161 * @sav: Unused
163 * This function is an emulation of the CES driver functionality on LynxOS.
165 * Returns 0 on success, or a standard kernel error
167 int vme_intset(int vec, int (*handler)(void *), void *arg, void *sav)
169 return vme_request_irq(vec, handler, arg, NULL);
171 EXPORT_SYMBOL_GPL(vme_intset);
174 * vme_intclr() - Uninstall the interrupt handler for the given vector
175 * @vec: Interrupt vector
176 * @sav: Unused
178 * This function is an emulation of the CES driver functionality on LynxOS.
180 * Returns 0 on success, or a standard kernel error
182 int vme_intclr(int vec, void *sav)
184 return vme_free_irq(vec);
186 EXPORT_SYMBOL_GPL(vme_intclr);