25 #define _SDB_MAGIC 0x5344422d
35 sdbBusTypeWishbone = 0x00
38 #define SDB_WB_WIDTH_MASK 0x0f
39 #define SDB_WB_ACCESS8 0x01
40 #define SDB_WB_ACCESS16 0x02
41 #define SDB_WB_ACCESS32 0x04
42 #define SDB_WB_ACCESS64 0x08
43 #define SDB_WB_LITTLE_ENDIAN 0x80
47 sdbTypeInterconnect = 0x00,
50 sdbTypeIntegration = 0x80,
101 uint8_t reserved[63];
107 #define _MAX_SCAN_DEPTH 3
110 static int _stackIdx = 0;
111 static char _spaces[_MAX_SCAN_DEPTH + 1];
112 static uint32_t _addrOffset = 0;
119 if (_stackIdx == _MAX_SCAN_DEPTH)
return false;
121 for (i = 0; i < _stackIdx; ++i) {
122 if (_stack[i] == ic)
return false;
124 _spaces[_stackIdx] =
'\t';
125 _stack[_stackIdx++] = ic;
126 _spaces[_stackIdx] =
'\0';
130 static void sdbIcPop()
133 _spaces[_stackIdx] =
'\0';
136 #define sdb_printf(STR, ...) \
137 printf("%s" STR, _spaces, __VA_ARGS__)
139 #define DEVICE_TYPE(PTR) \
140 (((uint8_t *)ptr)[63])
142 static void sdbDisplayProduct(
const SdbProduct * prodPtr)
145 memcpy(name, prodPtr->name, 19);
147 sdb_printf(
" DeviceId : %08lx\n", prodPtr->deviceId);
149 sdb_printf(
" VendorId : %08lx:%08lx\n", prodPtr->vendorId.high, prodPtr->vendorId.low);
150 sdb_printf(
" Date : %x\n", prodPtr->date);
151 sdb_printf(
" Version : %d\n", prodPtr->version);
153 sdb_printf(
" Name : %s\n", name);
156 static void sdbDisplayComponent(
const SdbComponent * compPtr)
159 sdb_printf(
" AddrFirst : %08lx:%08lx\n", compPtr->addrFirst.high, compPtr->addrFirst.low + _addrOffset);
160 sdb_printf(
" AddrLast : %08lx:%08lx\n", compPtr->addrLast.high, compPtr->addrLast.low + _addrOffset);
162 sdb_printf(
" AddrRange : %08lx-%08lx\n", compPtr->addrFirst.low + _addrOffset, compPtr->addrLast.low + _addrOffset);
164 sdbDisplayProduct(&(compPtr->product));
167 static void sdbDisplayDevice(
const SdbDevice * devPtr)
170 sdb_printf(
" ABI Class : %04x\n", devPtr->abiClass);
171 sdb_printf(
" ABI Version: %d.%d\n", devPtr->abiVerMajor, devPtr->abiVerMinor);
172 sdb_printf(
" Bus Spec. : %08lx\n", devPtr->busSpecific);
174 sdbDisplayComponent(&(devPtr->component));
177 static void sdbDisplayBridge(
const SdbBridge * brdgPtr)
180 sdb_printf(
" Child : %08x:%08x\n", brdgPtr->child.high, brdgPtr->child.low + _addrOffset);
182 sdbDisplayComponent(&(brdgPtr->component));
184 uint32_t icAddr = brdgPtr->child.low + _addrOffset;
185 uint32_t offset = brdgPtr->component.addrFirst.low;
187 sdb_printf(
"** icAddress: %08lx \n", icAddr);
190 _addrOffset += offset;
193 if (icAddr < _addrOffset)
200 sdb_printf(
"** Following interconnect at %08lx, offset at %08lx **\n", icAddr, _addrOffset);
204 _addrOffset -= offset;
212 sdb_printf(
" Magic : %08lx\n", ptr->magic);
213 sdb_printf(
" Version : %u\n", ptr->version);
214 sdb_printf(
" BusType : %u\n", ptr->busType);
216 sdb_printf(
" Records : %u\n", ptr->records);
218 sdbDisplayComponent(&(ptr->component));
221 static void sdbDisplaySdbEntry(
const SdbEntry * entryPtr)
224 sdb_printf(
"Device (addr = %08x, type = ", entryPtr);
225 switch (entryPtr->recordType)
227 case sdbTypeInterconnect:
228 puts(
"Interconnect):");
240 printf(
"Unknown/Unsupported #%d )\n", entryPtr->recordType);
248 if (!sdbIcPush(ic)) {
252 if (ic->magic != _SDB_MAGIC) {
254 puts(
"Can't display array, interconnect invalid!");
261 for (i = 0; i < ic->records; ++i, ++current)
263 sdbDisplaySdbEntry(current);
270 static void * sdbFindDeviceDeep(
const SdbInterconnect * ic, uint32_t
id,
int maxdepth)
278 for (i = 0; i < ic->records; ++i, ++current)
280 switch (current->recordType)
284 if (devPtr->component.product.deviceId ==
id)
286 return (
void *)(devPtr->component.addrFirst.low);
290 if (maxdepth == 0)
continue;
292 ptr = sdbFindDeviceDeep(ic2,
id, maxdepth - 1);
293 if (ptr != NULL)
return ptr;
307 return sdbFindDeviceDeep(_sdbRoot,
id, 2);
312 if (_sdbRoot->magic != _SDB_MAGIC)
325 sdbDisplaySdbArray(_sdbRoot);
Implements search functionality for the self-describing bus.
#define E_SDB_MAGIC
Magic number incorrect.
void * sdbFindDevice(uint32_t id)
Finds a device on the bus.
bool sdbInit()
Initializes the self-describing bus.
Manages the global system error.
void sdbDisplay()
Dumps the contents of the SDB records to standard out.
#define SDB
Self Describing Bus.
This file assigns all device structures to memory mapped structures.
bool errSet(uint32_t code, const char *error, const char *name)
Sets an error.
#define ERROR(CODE,...)
Expands an error code to an error code with a description (if ERROR_W_DESCR is declared).