RTEMS  5.0.0
ambapp.h
Go to the documentation of this file.
1 
6 /*
7  * COPYRIGHT (c) 2009.
8  * Aeroflex Gaisler.
9  *
10  * The license and distribution terms for this file may be
11  * found in the file LICENSE in this distribution or at
12  * http://www.rtems.org/license/LICENSE.
13  */
14 
15 #ifndef __AMBAPP_H__
16 #define __AMBAPP_H__
17 
28 /* Include VENDOR and DEVICE definitions */
29 #include "ambapp_ids.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /* Max supported AHB buses */
36 #define AHB_BUS_MAX 6
37 
38 struct ambapp_dev;
39 struct ambapp_core;
40 struct ambapp_apb_info;
41 struct ambapp_ahb_info;
42 
43 struct ambapp_dev {
44  struct ambapp_dev *next; /* Next */
45  struct ambapp_dev *prev; /* Previous Device. If (this ==
46  * rev->child) prev is bus bridge */
47  struct ambapp_dev *children; /* Points to first device on sub-bus */
48  void *owner; /* Owner of this AMBA device */
49  unsigned char dev_type; /* AHB MST, AHB SLV or APB SLV*/
50  unsigned char vendor; /* Vendor ID */
51  unsigned short device; /* Device ID */
52  int devinfo[0]; /* Device info (APB/AHB dep. on type) */
53 };
54 
55 #define AMBAPP_FLAG_FFACT_DIR 0x100 /* Frequency factor direction, 0=down, 1=up */
56 #define AMBAPP_FLAG_FFACT 0x0f0 /* Frequency factor against top bus */
57 #define AMBAPP_FLAG_MBUS 0x00c
58 #define AMBAPP_FLAG_SBUS 0x003
59 
60 /* Get APB or AHB information from a AMBA device */
61 #define DEV_TO_APB(adev) ((struct ambapp_apb_info *)((adev)->devinfo))
62 #define DEV_TO_AHB(adev) ((struct ambapp_ahb_info *)((adev)->devinfo))
63 #define DEV_TO_COMMON(adev) ((struct ambapp_common_info *)((adev)->devinfo))
64 /* Convert address of ambapp_apb_info/ambapp_ahb_info into ambapp_dev */
65 #define APB_TO_DEV(apb_info) ((struct ambapp_dev *)(unsigned int(apb_info) - \
66  offsetof(struct ambapp_dev, devinfo)))
67 #define AHB_TO_DEV(ahb_info) ((struct ambapp_dev *)(unsigned int(ahb_info) - \
68  offsetof(struct ambapp_dev, devinfo)))
69 
71  unsigned char irq;
72  unsigned char ver;
73  unsigned char ahbidx; /* AHB Bus Index */
74 };
75 
77  /* COMMON */
78  unsigned char irq;
79  unsigned char ver;
80  unsigned char ahbidx; /* AHB Bus Index */
81 
82  /* APB SPECIFIC */
83  unsigned int start;
84  unsigned int mask;
85 };
86 
88  /* COMMON */
89  unsigned char irq;
90  unsigned char ver;
91  unsigned char ahbidx; /* AHB Bus Index */
92 
93  /* AHB SPECIFIC */
94  unsigned int start[4];
95  unsigned int mask[4];
96  char type[4]; /* type[N] Determine type of start[N]-mask[N],
97  * 2=AHB Memory Space, 3=AHB I/O Space */
98  unsigned int custom[3];
99 };
100 
101 /* Describes a complete AMBA Core. Each device may consist of 3 interfaces */
102 struct ambapp_core {
103  char irq; /* irq=-1 indicate no IRQ */
104  unsigned char vendor;
105  unsigned short device;
106  int index; /* Core index */
107  struct ambapp_ahb_info *ahb_mst;
108  struct ambapp_ahb_info *ahb_slv;
109  struct ambapp_apb_info *apb_slv;
110 };
111 
113  unsigned int ioarea; /* AHB Bus IOAREA */
114  unsigned int freq_hz; /* Frequency of AHB Bus */
115  struct ambapp_dev *bridge;/* Bridge Device on Parent AHB Bus */
116  struct ambapp_dev *dev; /* First Device on AHB Bus */
117 };
118 
119 struct ambapp_mmap {
120  unsigned int size;
121  unsigned int local_adr;
122  unsigned int remote_adr;
123 };
124 
125 /* Complete AMBA PnP information */
126 struct ambapp_bus {
127  struct ambapp_dev *root; /* AHB/APB Device Tree*/
128  struct ambapp_mmap *mmaps; /* Memory MAP Array */
129  struct ambapp_ahb_bus ahbs[AHB_BUS_MAX]; /* AHB Buses */
130 };
131 
132 /*
133  * Return values
134  * 0 - continue
135  * 1 - stop scanning
136  */
137 typedef int (*ambapp_func_t)(struct ambapp_dev *dev, int index, void *arg);
138 
139 #define DEV_IS_FREE(dev) (dev->owner == NULL)
140 #define DEV_IS_ALLOCATED(dev) (dev->owner != NULL)
141 
142 /* Options to ambapp_for_each */
143 #define OPTIONS_AHB_MSTS 0x00000001
144 #define OPTIONS_AHB_SLVS 0x00000002
145 #define OPTIONS_APB_SLVS 0x00000004
146 #define OPTIONS_ALL_DEVS (OPTIONS_AHB_MSTS|OPTIONS_AHB_SLVS|OPTIONS_APB_SLVS)
147 
148 #define OPTIONS_FREE 0x00000010
149 #define OPTIONS_ALLOCATED 0x00000020
150 #define OPTIONS_ALL (OPTIONS_FREE|OPTIONS_ALLOCATED)
151 
152 /* Depth first search, Defualt is breath first search. */
153 #define OPTIONS_DEPTH_FIRST 0x00000100
154 
155 #define DEV_AHB_NONE 0
156 #define DEV_AHB_MST 1
157 #define DEV_AHB_SLV 2
158 #define DEV_APB_SLV 3
159 
160 /* Structures used to access Plug&Play information directly */
162  const unsigned int id; /* VENDOR, DEVICE, VER, IRQ, */
163  const unsigned int custom[3];
164  const unsigned int mbar[4]; /* MASK, ADDRESS, TYPE, CACHABLE/PREFETCHABLE */
165 };
166 
168  const unsigned int id; /* VENDOR, DEVICE, VER, IRQ, */
169  const unsigned int iobar; /* MASK, ADDRESS, TYPE, CACHABLE/PREFETCHABLE */
170 };
171 
172 #define ambapp_pnp_vendor(id) (((id) >> 24) & 0xff)
173 #define ambapp_pnp_device(id) (((id) >> 12) & 0xfff)
174 #define ambapp_pnp_ver(id) (((id)>>5) & 0x1f)
175 #define ambapp_pnp_irq(id) ((id) & 0x1f)
176 
177 #define ambapp_pnp_start(mbar) (((mbar) & 0xfff00000) & (((mbar) & 0xfff0) << 16))
178 #define ambapp_pnp_mbar_mask(mbar) (((mbar)>>4) & 0xfff)
179 #define ambapp_pnp_mbar_type(mbar) ((mbar) & 0xf)
180 
181 #define ambapp_pnp_apb_start(iobar, base) ((base) | ((((iobar) & 0xfff00000)>>12) & (((iobar) & 0xfff0)<<4)) )
182 #define ambapp_pnp_apb_mask(iobar) ((~(ambapp_pnp_mbar_mask(iobar)<<8) & 0x000fffff) + 1)
183 
184 #define AMBA_TYPE_AHBIO_ADDR(addr,base_ioarea) ((unsigned int)(base_ioarea) | ((addr) >> 12))
185 
186 #define AMBA_TYPE_APBIO 0x1
187 #define AMBA_TYPE_MEM 0x2
188 #define AMBA_TYPE_AHBIO 0x3
189 
190 /* Copy Data from AMBA PnP I/O Area */
191 typedef void *(*ambapp_memcpy_t)(
192  void *dest, /* Destination RAM copy */
193  const void *src, /* Source AMBA PnP Address to copy from */
194  int n, /* Number of bytes to be copied */
195  struct ambapp_bus *abus /* Optional AMBA Bus pointer */
196  );
197 
198 /* Scan a AMBA Plug & Play bus and create all device structures describing the
199  * the devices. The devices will form a tree, where every node describes one
200  * interface. The resulting tree is placed in the location pointed to by root.
201  *
202  * Since it the tree is located in RAM it is easier to work with AMBA buses
203  * that is located over PCI and SpaceWire etc.
204  *
205  * \param ioarea The IO-AREA where Plug & Play information can be found.
206  * \param parent Used internally when recursing down a bridge. Set to NULL.
207  * \param mmaps Is used to perform address translation if needed.
208  * \param root Resulting device node tree root is stored here.
209  *
210  */
211 extern int ambapp_scan(
212  struct ambapp_bus *abus,
213  unsigned int ioarea,
214  ambapp_memcpy_t memfunc,
215  struct ambapp_mmap *mmaps
216  );
217 
218 /* Initialize the frequency [Hz] of all AHB Buses from knowing the frequency
219  * of one particular APB/AHB Device.
220  */
221 extern void ambapp_freq_init(
222  struct ambapp_bus *abus,
223  struct ambapp_dev *dev,
224  unsigned int freq);
225 
226 /* Returns the frequency [Hz] of a AHB/APB device */
227 extern unsigned int ambapp_freq_get(
228  struct ambapp_bus *abus,
229  struct ambapp_dev *dev);
230 
231 /* Iterates through all AMBA devices previously found, it calls func
232  * once for every device that match the search arguments.
233  *
234  * SEARCH OPTIONS
235  * All search options must be fulfilled, type of devices searched (options)
236  * and AMBA Plug&Play ID [VENDOR,DEVICE], before func() is called. The options
237  * can be use to search only for AMBA APB or AHB Slaves or AHB Masters for
238  * example. Note that when VENDOR=-1 or DEVICE=-1 it will match any vendor or
239  * device ID, this means setting both VENDOR and DEVICE to -1 will result in
240  * calling all devices matches the options argument.
241  *
242  * \param abus AMBAPP Bus to search
243  * \param options Search options, see OPTIONS_* above
244  * \param vendor AMBAPP VENDOR ID to search for
245  * \param device AMBAPP DEVICE ID to search for
246  * \param func Function called for every device matching search options
247  * \param arg Optional argument passed on to func
248  *
249  * func return value affects the search, returning a non-zero value will
250  * stop the search and ambapp_for_each will return immediately returning the
251  * same non-zero value.
252  *
253  * Return Values
254  * 0 - all devices was scanned
255  * non-zero - stopped by user function returning the non-zero value
256  */
257 extern int ambapp_for_each(
258  struct ambapp_bus *abus,
259  unsigned int options,
260  int vendor,
261  int device,
262  ambapp_func_t func,
263  void *arg);
264 
265 /* Helper function for ambapp_for_each(), find a device by index. If pcount
266  * is NULL the first device is returned, else pcount is interpreted as index
267  * by decrementing the value until zero is reaced: *count=0 first device,
268  * *count=1 second device etc.
269  *
270  * The matching device is returned, which will stop the ambapp_for_each search.
271  * If zero is returned from ambapp_for_each no device matching the index was
272  * found
273  */
274 extern int ambapp_find_by_idx(struct ambapp_dev *dev, int index, void *pcount);
275 
276 /* Get number of devices matching the options/vendor/device arguments, the
277  * arguments are passed onto ambapp_for_each().
278  */
279 extern int ambapp_dev_count(struct ambapp_bus *abus, unsigned int options,
280  int vendor, int device);
281 
282 /* Print short information about devices on the AMBA bus onto the console */
283 extern void ambapp_print(struct ambapp_bus *abus, int show_depth);
284 
285 /* Mark a device taken (allocate), Owner field is set with owner Data. Returns
286  * -1 if device has already been allocated.
287  */
288 extern int ambapp_alloc_dev(struct ambapp_dev *dev, void *owner);
289 
290 /* Owner field is cleared, which indicates that device is not allocated */
291 extern void ambapp_free_dev(struct ambapp_dev *dev);
292 
293 /* Find AHB/APB Bridge or AHB/AHB Bridge Parent */
294 extern struct ambapp_dev *ambapp_find_parent(struct ambapp_dev *dev);
295 
296 /* Returns bus depth (number of sub AHB buses) of device from root bus */
297 extern int ambapp_depth(struct ambapp_dev *dev);
298 
299 /* Get Device Name from AMBA PnP name database */
300 extern char *ambapp_device_id2str(int vendor, int id);
301 
302 /* Get Vendor Name from AMBA PnP name database */
303 extern char *ambapp_vendor_id2str(int vendor);
304 
305 /* Set together VENDOR_DEVICE Name from AMBA PnP name database. Return length
306  * of C-string stored in buf not including string termination '\0'.
307  */
308 extern int ambapp_vendev_id2str(int vendor, int id, char *buf);
309 
310 /* Help functions for backwards compability */
311 
312 extern int ambapp_find_apbslv(
313  struct ambapp_bus *abus,
314  int vendor,
315  int device,
316  struct ambapp_apb_info *dev);
317 
318 extern int ambapp_find_apbslv_next(
319  struct ambapp_bus *abus,
320  int vendor,
321  int device,
322  struct ambapp_apb_info *dev,
323  int index);
324 
325 extern int ambapp_find_apbslvs_next(
326  struct ambapp_bus *abus,
327  int vendor,
328  int device,
329  struct ambapp_apb_info *dev,
330  int index,
331  int maxno);
332 
333 extern int ambapp_find_apbslvs(
334  struct ambapp_bus *abus,
335  int vendor,
336  int device,
337  struct ambapp_apb_info *dev,
338  int maxno);
339 
340 extern int ambapp_find_ahbslv(
341  struct ambapp_bus *abus,
342  int vendor,
343  int device,
344  struct ambapp_ahb_info *dev);
345 
346 extern int ambapp_find_ahbslv_next(
347  struct ambapp_bus *abus,
348  int vendor,
349  int device,
350  struct ambapp_ahb_info *dev,
351  int index);
352 
353 extern int ambapp_find_ahbslvs_next(
354  struct ambapp_bus *abus,
355  int vendor,
356  int device,
357  struct ambapp_ahb_info *dev,
358  int index,
359  int maxno);
360 
361 extern int ambapp_find_ahbslvs(
362  struct ambapp_bus *abus,
363  int vendor,
364  int device,
365  struct ambapp_ahb_info *dev,
366  int maxno);
367 
368 
369 extern int ambapp_get_number_ahbslv_devices(
370  struct ambapp_bus *abus,
371  int vendor,
372  int device);
373 
374 extern int ambapp_get_number_apbslv_devices(
375  struct ambapp_bus *abus,
376  int vendor,
377  int device);
378 
379 #ifdef __cplusplus
380 }
381 #endif
382 
385 #endif
Definition: ambapp.h:43
Definition: ambapp.h:70
Definition: ambapp.h:119
Definition: ambapp.h:87
Definition: rtemscompat1.h:15
Definition: ambapp.h:126
Definition: ambapp.h:167
Definition: ambapp.h:112
Definition: ambapp.h:102
Definition: ambapp.h:76
unsigned size
Definition: tte.h:74
AMBA Plug & Play Bus Vendor and Device IDs.
Definition: ambapp.h:161