Commit b1ac9f9a authored by Wesley W. Terpstra's avatar Wesley W. Terpstra

Added SDB support to the firmware: no more hard-coded addresses!

parent 9e1372b2
...@@ -7,4 +7,5 @@ OBJS_DEV = dev/eeprom.o \ ...@@ -7,4 +7,5 @@ OBJS_DEV = dev/eeprom.o \
dev/syscon.o \ dev/syscon.o \
dev/uart.o \ dev/uart.o \
dev/sfp.o \ dev/sfp.o \
dev/persistent_mac.o dev/persistent_mac.o \
dev/sdb.o
...@@ -27,7 +27,7 @@ LGPL 2.1 ...@@ -27,7 +27,7 @@ LGPL 2.1
#define DMTD_AVG_SAMPLES 256 #define DMTD_AVG_SAMPLES 256
static int autoneg_enabled; static int autoneg_enabled;
static volatile struct EP_WB *EP = (volatile struct EP_WB *) BASE_EP; volatile struct EP_WB *EP;
/* functions for accessing PCS (MDIO) registers */ /* functions for accessing PCS (MDIO) registers */
uint16_t pcs_read(int location) uint16_t pcs_read(int location)
...@@ -72,6 +72,7 @@ void get_mac_addr(uint8_t dev_addr[]) ...@@ -72,6 +72,7 @@ void get_mac_addr(uint8_t dev_addr[])
/* Initializes the endpoint and sets its local MAC address */ /* Initializes the endpoint and sets its local MAC address */
void ep_init(uint8_t mac_addr[]) void ep_init(uint8_t mac_addr[])
{ {
EP = (volatile struct EP_WB *) BASE_EP;
set_mac_addr(mac_addr); set_mac_addr(mac_addr);
*(unsigned int *)(0x62000) = 0x2; // reset network stuff (cleanup required!) *(unsigned int *)(0x62000) = 0x2; // reset network stuff (cleanup required!)
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
#define pfilter_dbg #define pfilter_dbg
static volatile struct EP_WB *EP = (volatile struct EP_WB *) BASE_EP; extern volatile struct EP_WB *EP;
static const uint64_t PF_MODE_LOGIC = (1ULL<<34); static const uint64_t PF_MODE_LOGIC = (1ULL<<34);
static const uint64_t PF_MODE_CMP = 0ULL; static const uint64_t PF_MODE_CMP = 0ULL;
......
#include "hw/memlayout.h"
#define SDB_INTERCONNET 0x00
#define SDB_DEVICE 0x01
#define SDB_BRIDGE 0x02
#define SDB_EMPTY 0xFF
typedef struct pair64 {
uint32_t high;
uint32_t low;
} pair64_t;
struct sdb_empty {
int8_t reserved[63];
uint8_t record_type;
};
struct sdb_product {
pair64_t vendor_id;
uint32_t device_id;
uint32_t version;
uint32_t date;
int8_t name[19];
uint8_t record_type;
};
struct sdb_component {
pair64_t addr_first;
pair64_t addr_last;
struct sdb_product product;
};
struct sdb_device {
uint16_t abi_class;
uint8_t abi_ver_major;
uint8_t abi_ver_minor;
uint32_t bus_specific;
struct sdb_component sdb_component;
};
struct sdb_bridge {
pair64_t sdb_child;
struct sdb_component sdb_component;
};
struct sdb_interconnect {
uint32_t sdb_magic;
uint16_t sdb_records;
uint8_t sdb_version;
uint8_t sdb_bus_type;
struct sdb_component sdb_component;
};
typedef union sdb_record {
struct sdb_empty empty;
struct sdb_device device;
struct sdb_bridge bridge;
struct sdb_interconnect interconnect;
} sdb_record_t;
static unsigned char* find_device_deep(unsigned int base, unsigned int sdb, unsigned int devid) {
sdb_record_t* record = (sdb_record_t*)sdb;
int records = record->interconnect.sdb_records;
int i;
for (i = 0; i < records; ++i, ++record) {
if (record->empty.record_type == SDB_BRIDGE) {
unsigned char* out =
find_device_deep(
base + record->bridge.sdb_component.addr_first.low,
record->bridge.sdb_child.low,
devid);
if (out) return out;
}
if (record->empty.record_type == SDB_DEVICE &&
record->device.sdb_component.product.device_id == devid) {
break;
}
}
if (i == records) return 0;
return (unsigned char*)(base + record->device.sdb_component.addr_first.low);
}
static void print_devices_deep(unsigned int base, unsigned int sdb) {
sdb_record_t* record = (sdb_record_t*)sdb;
int records = record->interconnect.sdb_records;
int i;
char buf[20];
for (i = 0; i < records; ++i, ++record) {
if (record->empty.record_type == SDB_BRIDGE)
print_devices_deep(
base + record->bridge.sdb_component.addr_first.low,
record->bridge.sdb_child.low);
if (record->empty.record_type != SDB_DEVICE) continue;
memcpy(buf, record->device.sdb_component.product.name, 19);
buf[19] = 0;
mprintf("%8x:%8x 0x%8x %s\n",
record->device.sdb_component.product.vendor_id.low,
record->device.sdb_component.product.device_id,
base + record->device.sdb_component.addr_first.low,
buf);
}
}
static unsigned char* find_device(unsigned int devid) {
find_device_deep(0, SDB_ADDRESS, devid);
}
void sdb_print_devices(void) {
mprintf("SDB memory map:\n");
print_devices_deep(0, SDB_ADDRESS);
mprintf("---\n");
}
void sdb_find_devices(void) {
BASE_MINIC = find_device(0xab28633a);
BASE_EP = find_device(0x650c2d4f);
BASE_SOFTPLL = find_device(0x65158dc0);
BASE_PPS_GEN = find_device(0xde0d8ced);
BASE_SYSCON = find_device(0xff07fc47);
BASE_UART = find_device(0xe2d13d04);
BASE_ONEWIRE = find_device(0x779c5443);
BASE_ETHERBONE_CFG = (unsigned char*)0x20700; /* !!! fixme -- needs HW change */
}
...@@ -3,11 +3,15 @@ ...@@ -3,11 +3,15 @@
struct s_i2c_if i2c_if[2] = { {SYSC_GPSR_FMC_SCL, SYSC_GPSR_FMC_SDA}, struct s_i2c_if i2c_if[2] = { {SYSC_GPSR_FMC_SCL, SYSC_GPSR_FMC_SDA},
{SYSC_GPSR_SFP_SCL, SYSC_GPSR_SFP_SDA} }; {SYSC_GPSR_SFP_SCL, SYSC_GPSR_SFP_SDA} };
volatile struct SYSCON_WB *syscon;
/**************************** /****************************
* TIMER * TIMER
***************************/ ***************************/
void timer_init(uint32_t enable) void timer_init(uint32_t enable)
{ {
syscon = (volatile struct SYSCON_WB *) BASE_SYSCON;
if(enable) if(enable)
syscon->TCR |= SYSC_TCR_ENABLE; syscon->TCR |= SYSC_TCR_ENABLE;
else else
......
...@@ -9,10 +9,11 @@ ...@@ -9,10 +9,11 @@
( ((( (unsigned long long)baudrate * 8ULL) << (16 - 7)) + \ ( ((( (unsigned long long)baudrate * 8ULL) << (16 - 7)) + \
(CPU_CLOCK >> 8)) / (CPU_CLOCK >> 7) ) (CPU_CLOCK >> 8)) / (CPU_CLOCK >> 7) )
static volatile struct UART_WB *uart = (volatile struct UART_WB *) BASE_UART; volatile struct UART_WB *uart;
void uart_init() void uart_init()
{ {
uart = (volatile struct UART_WB *) BASE_UART;
uart->BCR = CALC_BAUD(UART_BAUDRATE); uart->BCR = CALC_BAUD(UART_BAUDRATE);
} }
......
#ifndef __REGS_H #ifndef __REGS_H
#define __REGS_H #define __REGS_H
#define BASE_MINIC 0x20000 #define SDB_ADDRESS 0x30000
#define BASE_EP 0x20100
#define BASE_SOFTPLL 0x20200 unsigned char* BASE_MINIC;
#define BASE_PPS_GEN 0x20300 unsigned char* BASE_EP;
#define BASE_SYSCON 0x20400 unsigned char* BASE_SOFTPLL;
#define BASE_UART 0x20500 unsigned char* BASE_PPS_GEN;
#define BASE_ONEWIRE 0x20600 unsigned char* BASE_SYSCON;
#define BASE_ETHERBONE_CFG 0x20700 unsigned char* BASE_UART;
unsigned char* BASE_ONEWIRE;
unsigned char* BASE_ETHERBONE_CFG;
#define FMC_EEPROM_ADR 0x50 #define FMC_EEPROM_ADR 0x50
void sdb_find_devices(void);
void sdb_print_devices(void);
#endif #endif
...@@ -38,7 +38,7 @@ void timer_init(uint32_t enable); ...@@ -38,7 +38,7 @@ void timer_init(uint32_t enable);
uint32_t timer_get_tics(); uint32_t timer_get_tics();
void timer_delay(uint32_t how_long); void timer_delay(uint32_t how_long);
static volatile struct SYSCON_WB *syscon = (volatile struct SYSCON_WB *) BASE_SYSCON; extern volatile struct SYSCON_WB *syscon;
/**************************** /****************************
* GPIO * GPIO
......
#include "shell.h"
#include "syscon.h"
#include "hw/memlayout.h"
extern const char *build_revision, *build_date;
int cmd_sdb(const char *args[])
{
sdb_print_devices();
return 0;
}
\ No newline at end of file
...@@ -49,6 +49,7 @@ static const struct shell_cmd cmds_list[] = { ...@@ -49,6 +49,7 @@ static const struct shell_cmd cmds_list[] = {
{ "ip", cmd_ip }, { "ip", cmd_ip },
#endif #endif
{ "mac", cmd_mac }, { "mac", cmd_mac },
{ "sdb", cmd_sdb },
{ NULL, NULL } { NULL, NULL }
}; };
......
...@@ -15,6 +15,7 @@ int cmd_mode(const char *args[]); ...@@ -15,6 +15,7 @@ int cmd_mode(const char *args[]);
int cmd_measure_t24p(const char *args[]); int cmd_measure_t24p(const char *args[]);
int cmd_time(const char *args[]); int cmd_time(const char *args[]);
int cmd_ip(const char *args[]); int cmd_ip(const char *args[]);
int cmd_sdb(const char *args[]);
int cmd_mac(const char *args[]); int cmd_mac(const char *args[]);
int cmd_env(const char *args[]); int cmd_env(const char *args[]);
......
...@@ -9,6 +9,7 @@ OBJS_SHELL = shell/shell.o \ ...@@ -9,6 +9,7 @@ OBJS_SHELL = shell/shell.o \
shell/cmd_measure_t24p.o \ shell/cmd_measure_t24p.o \
shell/cmd_time.o \ shell/cmd_time.o \
shell/cmd_gui.o \ shell/cmd_gui.o \
shell/cmd_sdb.o \
shell/cmd_mac.o shell/cmd_mac.o
ifneq ($(WITH_ETHERBONE), 0) ifneq ($(WITH_ETHERBONE), 0)
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
volatile int irq_count = 0; volatile int irq_count = 0;
static volatile struct SPLL_WB *SPLL = (volatile struct SPLL_WB *) BASE_SOFTPLL; static volatile struct SPLL_WB *SPLL;
static volatile struct PPSG_WB *PPSG = (volatile struct PPSG_WB *) BASE_PPS_GEN; static volatile struct PPSG_WB *PPSG;
#define TRACE(...) TRACE_DEV(__VA_ARGS__) #define TRACE(...) TRACE_DEV(__VA_ARGS__)
...@@ -233,6 +233,9 @@ void spll_init(int mode, int slave_ref_channel, int align_pps) ...@@ -233,6 +233,9 @@ void spll_init(int mode, int slave_ref_channel, int align_pps)
char mode_str[20]; char mode_str[20];
volatile int dummy; volatile int dummy;
int i; int i;
SPLL = (volatile struct SPLL_WB *) BASE_SOFTPLL;
PPSG = (volatile struct PPSG_WB *) BASE_PPS_GEN;
disable_irq(); disable_irq();
......
...@@ -34,9 +34,12 @@ void wrc_initialize() ...@@ -34,9 +34,12 @@ void wrc_initialize()
int ret, i; int ret, i;
uint8_t mac_addr[6], ds18_id[8] = {0,0,0,0,0,0,0,0}; uint8_t mac_addr[6], ds18_id[8] = {0,0,0,0,0,0,0,0};
char sfp_pn[17]; char sfp_pn[17];
sdb_find_devices();
uart_init(); uart_init();
mprintf("WR Core: starting up...\n"); mprintf("WR Core: starting up...\n");
timer_init(1); timer_init(1);
owInit(); owInit();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment