1 | /* LEON3 GRLIB AMBA Plug & Play bus driver. |
---|
2 | * |
---|
3 | * COPYRIGHT (c) 2008. |
---|
4 | * Cobham Gaisler AB. |
---|
5 | * |
---|
6 | * This is driver is a wrapper for the general AMBA Plug & Play bus |
---|
7 | * driver. This is the root bus driver for GRLIB systems. |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.rtems.org/license/LICENSE. |
---|
12 | */ |
---|
13 | |
---|
14 | #include <stdlib.h> |
---|
15 | #include <stdio.h> |
---|
16 | #include <string.h> |
---|
17 | #include <stdint.h> |
---|
18 | #include <libcpu/access.h> |
---|
19 | |
---|
20 | #include <drvmgr/ambapp_bus.h> |
---|
21 | #include <drvmgr/ambapp_bus_grlib.h> |
---|
22 | #include <bsp/genirq.h> |
---|
23 | |
---|
24 | #include <bsp.h> |
---|
25 | |
---|
26 | #define DBG(args...) |
---|
27 | /*#define DBG(args...) printk(args)*/ |
---|
28 | |
---|
29 | int ambapp_grlib_int_register( |
---|
30 | struct drvmgr_dev *dev, |
---|
31 | int irq, |
---|
32 | const char *info, |
---|
33 | drvmgr_isr isr, |
---|
34 | void *arg); |
---|
35 | int ambapp_grlib_int_unregister( |
---|
36 | struct drvmgr_dev *dev, |
---|
37 | int irq, |
---|
38 | drvmgr_isr isr, |
---|
39 | void *arg); |
---|
40 | int ambapp_grlib_int_clear( |
---|
41 | struct drvmgr_dev *dev, |
---|
42 | int irq); |
---|
43 | int ambapp_grlib_int_mask( |
---|
44 | struct drvmgr_dev *dev, |
---|
45 | int irq); |
---|
46 | int ambapp_grlib_int_unmask( |
---|
47 | struct drvmgr_dev *dev, |
---|
48 | int irq); |
---|
49 | int ambapp_grlib_get_params( |
---|
50 | struct drvmgr_dev *dev, |
---|
51 | struct drvmgr_bus_params *params); |
---|
52 | |
---|
53 | int ambapp_grlib_init1(struct drvmgr_dev *dev); |
---|
54 | int ambapp_grlib_init2(struct drvmgr_dev *dev); |
---|
55 | int ambapp_grlib_remove(struct drvmgr_dev *dev); |
---|
56 | |
---|
57 | /* READ/WRITE access to SpaceWire target over RMAP */ |
---|
58 | void *ambapp_grlib_rw_arg(struct drvmgr_dev *dev); |
---|
59 | |
---|
60 | struct ambapp_ops ambapp_grlib_ops = { |
---|
61 | .int_register = ambapp_grlib_int_register, |
---|
62 | .int_unregister = ambapp_grlib_int_unregister, |
---|
63 | .int_clear = ambapp_grlib_int_clear, |
---|
64 | .int_mask = ambapp_grlib_int_mask, |
---|
65 | .int_unmask = ambapp_grlib_int_unmask, |
---|
66 | .get_params = ambapp_grlib_get_params |
---|
67 | }; |
---|
68 | |
---|
69 | void *ambapp_grlib_rw_arg(struct drvmgr_dev *dev) |
---|
70 | { |
---|
71 | return dev; /* No argument really needed, but for debug? */ |
---|
72 | } |
---|
73 | |
---|
74 | struct drvmgr_func ambapp_grlib_funcs[] = |
---|
75 | { |
---|
76 | DRVMGR_FUNC(AMBAPP_RW_ARG, ambapp_grlib_rw_arg), |
---|
77 | |
---|
78 | DRVMGR_FUNC(AMBAPP_R8, _ld8), |
---|
79 | DRVMGR_FUNC(AMBAPP_R16, _ld16), |
---|
80 | DRVMGR_FUNC(AMBAPP_R32, _ld32), |
---|
81 | DRVMGR_FUNC(AMBAPP_R64, _ld64), |
---|
82 | |
---|
83 | DRVMGR_FUNC(AMBAPP_W8, _st8), |
---|
84 | DRVMGR_FUNC(AMBAPP_W16, _st16), |
---|
85 | DRVMGR_FUNC(AMBAPP_W32, _st32), |
---|
86 | DRVMGR_FUNC(AMBAPP_W64, _st64), |
---|
87 | |
---|
88 | DRVMGR_FUNC(AMBAPP_RMEM, memcpy), |
---|
89 | DRVMGR_FUNC(AMBAPP_WMEM, memcpy), |
---|
90 | |
---|
91 | DRVMGR_FUNC_END, |
---|
92 | }; |
---|
93 | |
---|
94 | struct drvmgr_drv_ops ambapp_grlib_drv_ops = |
---|
95 | { |
---|
96 | .init = {ambapp_grlib_init1, ambapp_grlib_init2, NULL, NULL}, |
---|
97 | .remove = ambapp_grlib_remove, |
---|
98 | .info = NULL, |
---|
99 | }; |
---|
100 | |
---|
101 | struct drvmgr_drv ambapp_bus_drv_grlib = |
---|
102 | { |
---|
103 | DRVMGR_OBJ_DRV, /* Driver */ |
---|
104 | NULL, /* Next driver */ |
---|
105 | NULL, /* Device list */ |
---|
106 | DRIVER_GRLIB_AMBAPP_ID, /* Driver ID */ |
---|
107 | "AMBAPP_GRLIB_DRV", /* Driver Name */ |
---|
108 | DRVMGR_BUS_TYPE_ROOT, /* Bus Type */ |
---|
109 | &ambapp_grlib_drv_ops, |
---|
110 | NULL, /* Funcs */ |
---|
111 | 0, |
---|
112 | 0, |
---|
113 | }; |
---|
114 | |
---|
115 | static struct grlib_config *drv_mgr_grlib_config = NULL; |
---|
116 | |
---|
117 | void ambapp_grlib_register(void) |
---|
118 | { |
---|
119 | drvmgr_drv_register(&ambapp_bus_drv_grlib); |
---|
120 | } |
---|
121 | |
---|
122 | int ambapp_grlib_root_register(struct grlib_config *config) |
---|
123 | { |
---|
124 | |
---|
125 | /* Save the configuration for later */ |
---|
126 | drv_mgr_grlib_config = config; |
---|
127 | |
---|
128 | /* Register root device driver */ |
---|
129 | drvmgr_root_drv_register(&ambapp_bus_drv_grlib); |
---|
130 | |
---|
131 | return 0; |
---|
132 | } |
---|
133 | |
---|
134 | /* Function called from Driver Manager Initialization Stage 1 */ |
---|
135 | int ambapp_grlib_init1(struct drvmgr_dev *dev) |
---|
136 | { |
---|
137 | struct ambapp_config *config; |
---|
138 | |
---|
139 | dev->priv = NULL; |
---|
140 | dev->name = "GRLIB AMBA PnP"; |
---|
141 | |
---|
142 | DBG("AMBAPP GRLIB: intializing\n"); |
---|
143 | |
---|
144 | config = malloc(sizeof(struct ambapp_config)); |
---|
145 | if ( !config ) |
---|
146 | return RTEMS_NO_MEMORY; |
---|
147 | |
---|
148 | config->ops = &ambapp_grlib_ops; |
---|
149 | config->maps_up = DRVMGR_TRANSLATE_ONE2ONE; |
---|
150 | config->maps_down = DRVMGR_TRANSLATE_ONE2ONE; |
---|
151 | config->abus = drv_mgr_grlib_config->abus; |
---|
152 | config->resources = drv_mgr_grlib_config->resources; |
---|
153 | config->funcs = ambapp_grlib_funcs; |
---|
154 | config->bus_type = DRVMGR_BUS_TYPE_AMBAPP; |
---|
155 | |
---|
156 | /* Initialize the generic part of the AMBA Bus */ |
---|
157 | return ambapp_bus_register(dev, config); |
---|
158 | } |
---|
159 | |
---|
160 | int ambapp_grlib_init2(struct drvmgr_dev *dev) |
---|
161 | { |
---|
162 | return 0; |
---|
163 | } |
---|
164 | |
---|
165 | int ambapp_grlib_remove(struct drvmgr_dev *dev) |
---|
166 | { |
---|
167 | return 0; |
---|
168 | } |
---|
169 | |
---|
170 | int ambapp_grlib_int_register |
---|
171 | ( |
---|
172 | struct drvmgr_dev *dev, |
---|
173 | int irq, |
---|
174 | const char *info, |
---|
175 | drvmgr_isr isr, |
---|
176 | void *arg |
---|
177 | ) |
---|
178 | { |
---|
179 | return BSP_shared_interrupt_register(irq, info, isr, arg); |
---|
180 | } |
---|
181 | |
---|
182 | int ambapp_grlib_int_unregister |
---|
183 | ( |
---|
184 | struct drvmgr_dev *dev, |
---|
185 | int irq, |
---|
186 | drvmgr_isr isr, |
---|
187 | void *arg |
---|
188 | ) |
---|
189 | { |
---|
190 | return BSP_shared_interrupt_unregister(irq, isr, arg); |
---|
191 | } |
---|
192 | |
---|
193 | int ambapp_grlib_int_clear |
---|
194 | ( |
---|
195 | struct drvmgr_dev *dev, |
---|
196 | int irq) |
---|
197 | { |
---|
198 | BSP_shared_interrupt_clear(irq); |
---|
199 | return DRVMGR_OK; |
---|
200 | } |
---|
201 | |
---|
202 | int ambapp_grlib_int_mask |
---|
203 | ( |
---|
204 | struct drvmgr_dev *dev, |
---|
205 | int irq |
---|
206 | ) |
---|
207 | { |
---|
208 | BSP_shared_interrupt_mask(irq); |
---|
209 | return DRVMGR_OK; |
---|
210 | } |
---|
211 | |
---|
212 | int ambapp_grlib_int_unmask |
---|
213 | ( |
---|
214 | struct drvmgr_dev *dev, |
---|
215 | int irq |
---|
216 | ) |
---|
217 | { |
---|
218 | BSP_shared_interrupt_unmask(irq); |
---|
219 | return DRVMGR_OK; |
---|
220 | } |
---|
221 | |
---|
222 | int ambapp_grlib_get_params(struct drvmgr_dev *dev, struct drvmgr_bus_params *params) |
---|
223 | { |
---|
224 | /* Leave params->freq_hz untouched for default */ |
---|
225 | params->dev_prefix = ""; |
---|
226 | return 0; |
---|
227 | } |
---|