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