blob: d79fcedb4139a059fb650dcb626270be8c27ebf3 [file] [log] [blame]
Daniel Hellstromb552dbe2008-03-26 22:51:29 +01001/* Interface for accessing Gaisler AMBA Plug&Play Bus.
2 * The AHB bus can be interfaced with a simpler bus -
3 * the APB bus, also freely available in GRLIB at
4 * www.gaisler.com.
5 *
Daniel Hellstrom02e2a842010-01-25 09:54:51 +01006 * (C) Copyright 2009, 2015
7 * Daniel Hellstrom, Cobham Gaisler, daniel@gaisler.com.
Daniel Hellstromb552dbe2008-03-26 22:51:29 +01008 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010010 */
11
12#ifndef __AMBAPP_H__
13#define __AMBAPP_H__
14
Daniel Hellstrom02e2a842010-01-25 09:54:51 +010015#include <ambapp_ids.h>
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010016
Daniel Hellstrom02e2a842010-01-25 09:54:51 +010017#ifndef __ASSEMBLER__
18/* Structures used to access Plug&Play information directly */
19struct ambapp_pnp_ahb {
20 const unsigned int id; /* VENDOR, DEVICE, VER, IRQ, */
21 const unsigned int custom[3];
22 const unsigned int mbar[4]; /* MASK, ADDRESS, TYPE,
23 * CACHABLE/PREFETCHABLE */
24};
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010025
Daniel Hellstrom02e2a842010-01-25 09:54:51 +010026struct ambapp_pnp_apb {
27 const unsigned int id; /* VENDOR, DEVICE, VER, IRQ, */
28 const unsigned int iobar; /* MASK, ADDRESS, TYPE,
29 * CACHABLE/PREFETCHABLE */
30};
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010031
Daniel Hellstrom02e2a842010-01-25 09:54:51 +010032/* AMBA Plug&Play AHB Masters & Slaves information locations
33 * Max devices is 64 supported by HW, however often only 16
34 * are used.
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010035 */
Daniel Hellstrom02e2a842010-01-25 09:54:51 +010036struct ambapp_pnp_info {
37 struct ambapp_pnp_ahb masters[64];
38 struct ambapp_pnp_ahb slaves[63];
39 const unsigned int unused[4];
40 const unsigned int systemid[4];
41};
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010042
Daniel Hellstrom02e2a842010-01-25 09:54:51 +010043/* Describes a AMBA PnP bus */
44struct ambapp_bus {
45 int buses; /* Number of buses */
46 unsigned int ioareas[6]; /* PnP I/O AREAs of AHB buses */
47 unsigned int freq; /* Frequency of bus0 [Hz] */
48};
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010049
Daniel Hellstrom02e2a842010-01-25 09:54:51 +010050/* Processor Local AMBA bus */
51extern struct ambapp_bus ambapp_plb;
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010052
Daniel Hellstrom02e2a842010-01-25 09:54:51 +010053/* Get Bus frequency of a certain AMBA bus */
54extern unsigned int ambapp_bus_freq(
55 struct ambapp_bus *abus,
56 int ahb_bus_index
57 );
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010058
Daniel Hellstrom02e2a842010-01-25 09:54:51 +010059/* AMBA PnP information of a APB Device */
60typedef struct {
61 unsigned int vendor;
62 unsigned int device;
63 unsigned char irq;
64 unsigned char ver;
65 unsigned int address;
66 unsigned int mask;
67 int ahb_bus_index;
68} ambapp_apbdev;
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010069
Daniel Hellstrom02e2a842010-01-25 09:54:51 +010070/* AMBA PnP information of a AHB Device */
71typedef struct {
72 unsigned int vendor;
73 unsigned int device;
74 unsigned char irq;
75 unsigned char ver;
76 unsigned int userdef[3];
77 unsigned int address[4];
78 unsigned int mask[4];
79 int type[4];
80 int ahb_bus_index;
81} ambapp_ahbdev;
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010082
Daniel Hellstrom02e2a842010-01-25 09:54:51 +010083/* Scan AMBA Bus for AHB Bridges */
84extern void ambapp_bus_init(
85 unsigned int ioarea,
86 unsigned int freq,
87 struct ambapp_bus *abus);
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010088
Daniel Hellstrom02e2a842010-01-25 09:54:51 +010089/* Find APB Slave device by index using breath first search.
90 *
91 * When vendor and device are both set to zero, any device
92 * with a non-zero device ID will match the search. It may be
93 * useful when processing all devices on a AMBA bus.
94 */
95extern int ambapp_apb_find(
96 struct ambapp_bus *abus,
97 int vendor,
98 int device,
99 int index,
100 ambapp_apbdev *dev
101 );
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100102
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100103/* Find AHB Master device by index using breath first search.
104 *
105 * When vendor and device are both set to zero, any device
106 * with a non-zero device ID will match the search. It may be
107 * useful when processing all devices on a AMBA bus.
108 */
109extern int ambapp_ahbmst_find(
110 struct ambapp_bus *abus,
111 int vendor,
112 int device,
113 int index,
114 ambapp_ahbdev *dev
115 );
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100116
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100117/* Find AHB Slave device by index using breath first search.
118 *
119 * When vendor and device are both set to zero, any device
120 * with a non-zero device ID will match the search. It may be
121 * useful when processing all devices on a AMBA bus.
122 */
123extern int ambapp_ahbslv_find(
124 struct ambapp_bus *abus,
125 int vendor,
126 int device,
127 int index,
128 ambapp_ahbdev *dev
129 );
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100130
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100131/* Return number of APB Slave devices of a certain ID (VENDOR:DEVICE)
132 * zero is returned if no devices was found.
133 */
134extern int ambapp_apb_count(struct ambapp_bus *abus, int vendor, int device);
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100135
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100136/* Return number of AHB Master devices of a certain ID (VENDOR:DEVICE)
137 * zero is returned if no devices was found.
138 */
139extern int ambapp_ahbmst_count(struct ambapp_bus *abus, int vendor, int device);
140
141/* Return number of AHB Slave devices of a certain ID (VENDOR:DEVICE)
142 * zero is returned if no devices was found.
143 */
144extern int ambapp_ahbslv_count(struct ambapp_bus *abus, int vendor, int device);
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100145
Daniel Hellstromfeb0c262008-03-26 23:00:38 +0100146#ifdef CONFIG_CMD_AMBAPP
147
148/* AMBA Plug&Play relocation & initialization */
149int ambapp_init_reloc(void);
150
151/* AMBA Plug&Play Name of Vendors and devices */
152
153/* Return name of device */
154char *ambapp_device_id2str(int vendor, int id);
155
156/* Return name of vendor */
157char *ambapp_vendor_id2str(int vendor);
Daniel Hellstromfeb0c262008-03-26 23:00:38 +0100158
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100159/* Return description of a device */
160char *ambapp_device_id2desc(int vendor, int id);
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100161
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100162#endif
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100163
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100164#endif /* defined(__ASSEMBLER__) */
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100165
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100166#define AMBA_DEFAULT_IOAREA 0xfff00000
167#define AMBA_CONF_AREA 0xff000
168#define AMBA_AHB_SLAVE_CONF_AREA 0x800
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100169
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100170#define DEV_NONE 0
171#define DEV_AHB_MST 1
172#define DEV_AHB_SLV 2
173#define DEV_APB_SLV 3
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100174
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100175#define AMBA_TYPE_APBIO 0x1
176#define AMBA_TYPE_MEM 0x2
177#define AMBA_TYPE_AHBIO 0x3
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100178
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100179/* ID layout for APB and AHB devices */
180#define AMBA_PNP_ID(vendor, device) (((vendor)<<24) | ((device)<<12))
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100181
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100182/* APB Slave PnP layout definitions */
183#define AMBA_APB_ID_OFS (0*4)
184#define AMBA_APB_IOBAR_OFS (1*4)
185#define AMBA_APB_CONF_LENGH (2*4)
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100186
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100187/* AHB Master/Slave layout PnP definitions */
188#define AMBA_AHB_ID_OFS (0*4)
189#define AMBA_AHB_CUSTOM0_OFS (1*4)
190#define AMBA_AHB_CUSTOM1_OFS (2*4)
191#define AMBA_AHB_CUSTOM2_OFS (3*4)
192#define AMBA_AHB_MBAR0_OFS (4*4)
193#define AMBA_AHB_MBAR1_OFS (5*4)
194#define AMBA_AHB_MBAR2_OFS (6*4)
195#define AMBA_AHB_MBAR3_OFS (7*4)
196#define AMBA_AHB_CONF_LENGH (8*4)
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100197
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100198/* Macros for extracting information from AMBA PnP information
199 * registers.
200 */
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100201
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100202#define amba_vendor(x) (((x) >> 24) & 0xff)
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100203
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100204#define amba_device(x) (((x) >> 12) & 0xfff)
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100205
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100206#define amba_irq(conf) ((conf) & 0x1f)
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100207
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100208#define amba_ver(conf) (((conf)>>5) & 0x1f)
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100209
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100210#define amba_iobar_start(base, iobar) \
211 ((base) | ((((iobar) & 0xfff00000)>>12) & (((iobar) & 0xfff0)<<4)))
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100212
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100213#define amba_membar_start(mbar) \
214 (((mbar) & 0xfff00000) & (((mbar) & 0xfff0) << 16))
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100215
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100216#define amba_membar_type(mbar) ((mbar) & 0xf)
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100217
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100218#define amba_membar_mask(mbar) (((mbar) >> 4) & 0xfff)
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100219
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100220#define amba_ahbio_adr(addr, base_ioarea) \
221 ((unsigned int)(base_ioarea) | ((addr) >> 12))
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100222
Daniel Hellstrom02e2a842010-01-25 09:54:51 +0100223#define amba_apb_mask(iobar) ((~(amba_membar_mask(iobar)<<8) & 0x000fffff) + 1)
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100224
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100225#endif