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.
19 #include <linux/device.h>
22 #include "vme_bridge.h"
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)
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
;
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__
);
63 /* Now fill it with the parameters we got */
65 desc
->read_prefetch_enabled
= 1;
66 desc
->read_prefetch_size
= VME_PREFETCH_2
;
71 desc
->data_width
= VME_D16
;
74 desc
->data_width
= VME_D32
;
77 printk(KERN_ERR PFX
"%s - Unsupported data width %ld\n",
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).
94 desc
->vme_addrl
= vmeaddr
;
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
);
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
;
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
);
141 printk(KERN_ERR PFX
"%s - mapping not found @ 0x%x",
146 err
= vme_release_mapping(desc
, 1);
150 printk(KERN_ERR PFX
"%s - failed to remove mapping @ 0x%x (err=%d)\n",
151 __func__
, logaddr
, err
);
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
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
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
);