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