1 | /* |
---|
2 | * AMBA Plag & Play Bus Driver Macros for LEON2 |
---|
3 | * |
---|
4 | * Macros used for AMBA Plug & Play bus scanning |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 2007. |
---|
7 | * Gaisler Research |
---|
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.com/license/LICENSE. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #ifndef __AMBAPP_H__ |
---|
17 | #define __AMBAPP_H__ |
---|
18 | |
---|
19 | #ifdef __cplusplus |
---|
20 | extern "C" { |
---|
21 | #endif |
---|
22 | |
---|
23 | #define AMBA_CONF_AREA 0xff000 |
---|
24 | #define AMBA_AHB_SLAVE_CONF_AREA (1 << 11) |
---|
25 | |
---|
26 | #define AMBA_AHB_CONF_WORDS 8 |
---|
27 | #define AMBA_APB_CONF_WORDS 2 |
---|
28 | #define AMBA_AHB_MASTERS 16 |
---|
29 | #define AMBA_AHB_SLAVES 16 |
---|
30 | #define AMBA_APB_SLAVES 16 |
---|
31 | #define AMBA_APBUARTS 8 |
---|
32 | |
---|
33 | /* Vendor codes */ |
---|
34 | #define VENDOR_GAISLER 1 |
---|
35 | #define VENDOR_PENDER 2 |
---|
36 | #define VENDOR_ESA 4 |
---|
37 | #define VENDOR_OPENCORES 8 |
---|
38 | |
---|
39 | /* Gaisler Research device id's */ |
---|
40 | #define GAISLER_LEON3 0x03 |
---|
41 | #define GAISLER_LEON3DSU 0x04 |
---|
42 | #define GAISLER_ETHAHB 0x05 |
---|
43 | #define GAISLER_APBMST 0x06 |
---|
44 | #define GAISLER_AHBUART 0x07 |
---|
45 | #define GAISLER_SRCTRL 0x08 |
---|
46 | #define GAISLER_SDCTRL 0x09 |
---|
47 | #define GAISLER_APBUART 0x0C |
---|
48 | #define GAISLER_IRQMP 0x0D |
---|
49 | #define GAISLER_AHBRAM 0x0E |
---|
50 | #define GAISLER_GPTIMER 0x11 |
---|
51 | #define GAISLER_PCITRG 0x12 |
---|
52 | #define GAISLER_PCISBRG 0x13 |
---|
53 | #define GAISLER_PCIFBRG 0x14 |
---|
54 | #define GAISLER_PCITRACE 0x15 |
---|
55 | #define GAISLER_DMACTRL 0x16 |
---|
56 | #define GAISLER_OCCAN 0x19 |
---|
57 | #define GAISLER_PIOPORT 0x1A |
---|
58 | #define GAISLER_ETHMAC 0x1D |
---|
59 | #define GAISLER_SPACEWIRE 0x1f |
---|
60 | #define GAISLER_AHB2AHB 0x20 |
---|
61 | #define GAISLER_I2CMST 0x28 |
---|
62 | #define GAISLER_GRSPW2 0x29 |
---|
63 | #define GAISLER_I2CMST 0x28 |
---|
64 | #define GAISLER_GRSPW2 0x29 |
---|
65 | #define GAISLER_GRCAN 0x34 |
---|
66 | #define GAISLER_GRHCAN 0x3d |
---|
67 | #define GAISLER_GRFIFO 0x35 |
---|
68 | #define GAISLER_GRADCDAC 0x36 |
---|
69 | #define GAISLER_GRPULSE 0x37 |
---|
70 | #define GAISLER_GRTIMER 0x38 |
---|
71 | #define GAISLER_FTAHBRAM 0x50 |
---|
72 | #define GAISLER_FTMCTRL 0x54 |
---|
73 | #define GAISLER_BRM 0x72 |
---|
74 | |
---|
75 | |
---|
76 | /* European Space Agency device id's */ |
---|
77 | #define ESA_LEON2 0x2 |
---|
78 | #define ESA_MCTRL 0xF |
---|
79 | #define ESA_SPW2 0x12 |
---|
80 | |
---|
81 | /* Opencores device id's */ |
---|
82 | #define OPENCORES_PCIBR 0x4 |
---|
83 | #define OPENCORES_ETHMAC 0x5 |
---|
84 | |
---|
85 | /* |
---|
86 | * |
---|
87 | * Macros for manipulating Configuration registers |
---|
88 | * |
---|
89 | */ |
---|
90 | #define amba_get_confword(tab, index, word) (*((tab).addr[(index)]+(word))) |
---|
91 | |
---|
92 | #define amba_vendor(x) (((x) >> 24) & 0xff) |
---|
93 | |
---|
94 | #define amba_device(x) (((x) >> 12) & 0xfff) |
---|
95 | |
---|
96 | #define amba_ahb_get_membar(tab, index, nr) (*((tab).addr[(index)]+4+(nr))) |
---|
97 | |
---|
98 | #define amba_ahb_get_custom(tab, index, nr) (*((tab).addr[(index)]+1+(nr))) |
---|
99 | |
---|
100 | #define amba_apb_get_membar(tab, index) (*((tab).addr[(index)]+1)) |
---|
101 | |
---|
102 | #define amba_membar_start(mbar) (((mbar) & 0xfff00000) & (((mbar) & 0xfff0) << 16)) |
---|
103 | |
---|
104 | #define amba_iobar_start(base, iobar) ((base) | ((((iobar) & 0xfff00000)>>12) & (((iobar) & 0xfff0)<<4)) ) |
---|
105 | |
---|
106 | #define amba_irq(conf) ((conf) & 0x1f) |
---|
107 | |
---|
108 | #define amba_ver(conf) (((conf)>>5) & 0x1f) |
---|
109 | |
---|
110 | #define amba_membar_type(mbar) ((mbar) & 0xf) |
---|
111 | |
---|
112 | #define AMBA_TYPE_APBIO 0x1 |
---|
113 | #define AMBA_TYPE_MEM 0x2 |
---|
114 | #define AMBA_TYPE_AHBIO 0x3 |
---|
115 | |
---|
116 | #define AMBA_TYPE_AHBIO_ADDR(addr,base_ioarea) ((unsigned int)(base_ioarea) | ((addr) >> 12)) |
---|
117 | |
---|
118 | /* |
---|
119 | * Types and structure used for AMBA Plug & Play bus scanning |
---|
120 | * |
---|
121 | */ |
---|
122 | typedef struct amba_device_table { |
---|
123 | int devnr; /* numbrer of devices on AHB or APB bus */ |
---|
124 | unsigned int *addr[16]; /* addresses to the devices configuration tables */ |
---|
125 | } amba_device_table; |
---|
126 | |
---|
127 | typedef struct { |
---|
128 | int devnr; |
---|
129 | unsigned int *addr[AMBA_APB_SLAVES]; /* addresses to the devices configuration tables */ |
---|
130 | unsigned int apbmst[AMBA_APB_SLAVES]; /* pointer to AHB slave (which is a APB master) */ |
---|
131 | } amba_apb_dev; |
---|
132 | |
---|
133 | struct amba_mmap { |
---|
134 | unsigned int cpu_adr; |
---|
135 | unsigned int size; |
---|
136 | unsigned int remote_amba_adr; |
---|
137 | }; |
---|
138 | |
---|
139 | typedef struct _amba_confarea_type amba_confarea_type; |
---|
140 | |
---|
141 | struct _amba_confarea_type { |
---|
142 | amba_confarea_type *next; /* next bus in chain */ |
---|
143 | int notroot; /* is root of a bus (mother AHB has 64 masters/slaves rest 16) */ |
---|
144 | unsigned int ioarea; |
---|
145 | struct amba_mmap *mmaps; |
---|
146 | amba_device_table ahbmst; |
---|
147 | amba_device_table ahbslv; |
---|
148 | amba_apb_dev apbslv; |
---|
149 | }; |
---|
150 | |
---|
151 | typedef struct { |
---|
152 | unsigned int start, irq, bus_id; |
---|
153 | } amba_apb_device; |
---|
154 | |
---|
155 | typedef struct { |
---|
156 | unsigned int start[4], irq, ver; |
---|
157 | } amba_ahb_device; |
---|
158 | |
---|
159 | /* Scans AMBA Plug&Play Information and convers that information |
---|
160 | * to a more readable format in RAM. |
---|
161 | * |
---|
162 | * Will scan for - AHB Masters |
---|
163 | * - AHB Slaves |
---|
164 | * - APB Slaves (if a AHB/APB bridge is found) |
---|
165 | * |
---|
166 | * \param amba_conf AMBA P&P device info is placed here. |
---|
167 | * \param ioarea address of AMBA Plug&Play information, |
---|
168 | * on LEON3 systems default is 0xfff00000 |
---|
169 | * \param mmaps Memory mmap specific to this amba bus, |
---|
170 | * if NULL no translation will be made (default). |
---|
171 | * A array of maps, ending with a entry with size=0. |
---|
172 | */ |
---|
173 | void amba_scan (amba_confarea_type * amba_conf, unsigned int ioarea, |
---|
174 | struct amba_mmap *mmaps); |
---|
175 | |
---|
176 | /* Print AMBA Plug&Play info on terminal */ |
---|
177 | void amba_print_conf (amba_confarea_type * amba_conf); |
---|
178 | |
---|
179 | |
---|
180 | |
---|
181 | |
---|
182 | /***** APB SLAVES *****/ |
---|
183 | |
---|
184 | /* Return number of APB Slave devices which has given vendor and device */ |
---|
185 | int amba_get_number_apbslv_devices (amba_confarea_type * amba_conf, int vendor, |
---|
186 | int device); |
---|
187 | |
---|
188 | /* Get First APB Slave device of this vendor&device id */ |
---|
189 | int amba_find_apbslv (amba_confarea_type * amba_conf, int vendor, int device, |
---|
190 | amba_apb_device * dev); |
---|
191 | |
---|
192 | /* Get APB Slave device of this vendor&device id. (setting nr to 0 is eqivalent to calling amba_find_apbslv() ) */ |
---|
193 | int amba_find_next_apbslv (amba_confarea_type * amba_conf, int vendor, |
---|
194 | int device, amba_apb_device * dev, int index); |
---|
195 | |
---|
196 | /* Get first nr APB Slave devices, put them into dev (which is an array of nr length) */ |
---|
197 | int amba_find_apbslvs (amba_confarea_type * amba_conf, int vendor, int device, |
---|
198 | amba_apb_device * devs, int maxno); |
---|
199 | |
---|
200 | |
---|
201 | |
---|
202 | /***** AHB SLAVES *****/ |
---|
203 | |
---|
204 | /* Return number of AHB Slave devices which has given vendor and device */ |
---|
205 | int amba_get_number_ahbslv_devices (amba_confarea_type * amba_conf, int vendor, |
---|
206 | int device); |
---|
207 | |
---|
208 | /* Get First AHB Slave device of this vendor&device id */ |
---|
209 | int amba_find_ahbslv (amba_confarea_type * amba_conf, int vendor, int device, |
---|
210 | amba_ahb_device * dev); |
---|
211 | |
---|
212 | /* Get AHB Slave device of this vendor&device id. (setting nr to 0 is eqivalent to calling amba_find_ahbslv() ) */ |
---|
213 | int amba_find_next_ahbslv (amba_confarea_type * amba_conf, int vendor, |
---|
214 | int device, amba_ahb_device * dev, int index); |
---|
215 | |
---|
216 | /* Get first nr AHB Slave devices, put them into dev (which is an array of nr length) */ |
---|
217 | int amba_find_ahbslvs (amba_confarea_type * amba_conf, int vendor, int device, |
---|
218 | amba_ahb_device * devs, int maxno); |
---|
219 | |
---|
220 | |
---|
221 | |
---|
222 | /***** AHB MASTERS *****/ |
---|
223 | |
---|
224 | /* Return number of AHB Master devices which has given vendor and device */ |
---|
225 | int amba_get_number_ahbmst_devices (amba_confarea_type * amba_conf, int vendor, |
---|
226 | int device); |
---|
227 | |
---|
228 | /* Get First AHB Master device of this vendor&device id */ |
---|
229 | int amba_find_ahbmst (amba_confarea_type * amba_conf, int vendor, int device, |
---|
230 | amba_ahb_device * dev); |
---|
231 | |
---|
232 | /* Get AHB Master device of this vendor&device id. (setting nr to 0 is eqivalent to calling amba_find_ahbmst() ) */ |
---|
233 | int amba_find_next_ahbmst (amba_confarea_type * amba_conf, int vendor, |
---|
234 | int device, amba_ahb_device * dev, int index); |
---|
235 | |
---|
236 | /* Get first nr AHB Master devices, put them into dev (which is an array of nr length) */ |
---|
237 | int amba_find_ahbmsts (amba_confarea_type * amba_conf, int vendor, int device, |
---|
238 | amba_ahb_device * devs, int maxno); |
---|
239 | |
---|
240 | |
---|
241 | /******** AMBA DEVICES *******/ |
---|
242 | |
---|
243 | /* ESA MEMORY CONTROLLER */ |
---|
244 | typedef struct { |
---|
245 | unsigned int mcfg1; |
---|
246 | unsigned int mcfg2; |
---|
247 | unsigned int mcfg3; |
---|
248 | } ambapp_regmap_mctrl; |
---|
249 | |
---|
250 | /* APB UART */ |
---|
251 | typedef struct { |
---|
252 | volatile unsigned int data; |
---|
253 | volatile unsigned int status; |
---|
254 | volatile unsigned int ctrl; |
---|
255 | volatile unsigned int scaler; |
---|
256 | } ambapp_apb_uart; |
---|
257 | |
---|
258 | typedef struct { |
---|
259 | volatile unsigned int ilevel; |
---|
260 | volatile unsigned int ipend; |
---|
261 | volatile unsigned int iforce; |
---|
262 | volatile unsigned int iclear; |
---|
263 | volatile unsigned int mpstat; |
---|
264 | volatile unsigned int notused01; |
---|
265 | volatile unsigned int notused02; |
---|
266 | volatile unsigned int notused03; |
---|
267 | volatile unsigned int notused10; |
---|
268 | volatile unsigned int notused11; |
---|
269 | volatile unsigned int notused12; |
---|
270 | volatile unsigned int notused13; |
---|
271 | volatile unsigned int notused20; |
---|
272 | volatile unsigned int notused21; |
---|
273 | volatile unsigned int notused22; |
---|
274 | volatile unsigned int notused23; |
---|
275 | volatile unsigned int mask[16]; |
---|
276 | volatile unsigned int force[16]; |
---|
277 | } LEON3_IrqCtrl_Regs_Map; |
---|
278 | |
---|
279 | /*****************************/ |
---|
280 | |
---|
281 | #ifdef __cplusplus |
---|
282 | } |
---|
283 | #endif |
---|
284 | |
---|
285 | #endif |
---|