Skip to content

Commit

Permalink
pongoOS 2.1.0
Browse files Browse the repository at this point in the history
Additions:
- device_clock_by_id/device_clock_by_name APIs
- USB support on Apple A10X devices (t8011)
  • Loading branch information
woachk committed Oct 27, 2020
1 parent 696c1ee commit 8354663
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ifeq ($(HOST_OS),Linux)
endif
endif

PONGO_VERSION := 2.0.0-$(shell git log -1 --pretty=format:"%H" | cut -c1-8)
PONGO_VERSION := 2.1.0-$(shell git log -1 --pretty=format:"%H" | cut -c1-8)
ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SRC := $(ROOT)/src
AUX := $(ROOT)/tools
Expand Down
14 changes: 7 additions & 7 deletions src/drivers/aes/aes_a9.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,23 @@ void aes_a9_init(void)
{
case 0x8000:
case 0x8003:
gAESPipeBase = gAESBase + 0x100;
gAESClockAddr = 0x20e080220;
gAESPipeBase = gAESBase + 0x100;
gAESClockAddr = gIOBase + 0x0e080220;
break;
case 0x8001:
gAESClockAddr = 0x20e080218;
gAESClockAddr = gIOBase + 0x0e080218;
break;
case 0x8010:
gAESClockAddr = 0x20e080230;
gAESClockAddr = gIOBase + 0x0e080230;
break;
case 0x8011:
gAESClockAddr = 0x20e080228;
gAESClockAddr = gIOBase + 0x0e080228;
break;
case 0x8012:
gAESClockAddr = 0x20e080238;
gAESClockAddr = gIOBase + 0x0e080238;
break;
case 0x8015:
gAESClockAddr = 0x232080240;
gAESClockAddr = gIOBase + 0x32080240;
break;
default:
panic("AES A9: counterfeit init call");
Expand Down
121 changes: 68 additions & 53 deletions src/drivers/usb/synopsys_otg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1723,16 +1723,17 @@ void usb_main() {
static uint64_t reg1=0, reg2=0, reg3=0;

void usb_bringup() {
uint64_t clockGateBase = dt_get_u32_prop("pmgr", "reg") + gIOBase;
clock_gate(clockGateBase + reg1, 0);
clock_gate(clockGateBase + reg2, 0);
clock_gate(clockGateBase + reg3, 0);
clock_gate(reg1, 0);
clock_gate(reg2, 0);
clock_gate(reg3, 0);
spin(1000);
clock_gate(clockGateBase + reg1, 1);
clock_gate(clockGateBase + reg2, 1);
clock_gate(clockGateBase + reg3, 1);
clock_gate(reg1, 1);
clock_gate(reg2, 1);
clock_gate(reg3, 1);
// t8011 is really just cursed...
if (socnum == 0x8011) {
*(volatile uint32_t*)(0x20C000024) = 0x3000088;
*(volatile uint32_t*)(gSynopsysComplexBase + 0x00) = 1;
*(volatile uint32_t*)(gSynopsysComplexBase + 0x24) = 0x3000088;
} else {
*(volatile uint32_t*)(gSynopsysComplexBase + 0x1c) = 0x108;
*(volatile uint32_t*)(gSynopsysComplexBase + 0x5c) = 0x108;
Expand Down Expand Up @@ -1771,49 +1772,66 @@ void usb_init() {
}
gSynopsysOTGBase += gIOBase;
gSynopsysComplexBase = gIOBase + dt_get_u32_prop("usb-complex", "reg");
// Can't trust "usb-device" dtre entry, because that can be USB3 and we want USB2
gSynopsysBase = (gSynopsysOTGBase & ~0xfffULL) + 0x00100000;
uint32_t otg_irq;

switch (socnum) {
case 0x8010:
case 0x8012:
reg1 = 0x80268;
reg2 = 0x80270;
reg3 = 0x80290;
break;
case 0x8011:
reg1 = 0x80288;
reg2 = 0x80290;
reg3 = 0x802a0;
break;
case 0x8015:
reg1 = 0x80270;
reg2 = 0x80278;
reg3 = 0x80270;
break;
// Would be nice to use device_clock_by_name() here, but the names are different across devices...
switch(socnum)
{
case 0x8960:
reg1 = gIOBase + 0x0e020158;
reg2 = gIOBase + 0x0e020160;
reg3 = gIOBase + 0x0e020188;
otg_irq = 162;
break;
case 0x7000:
case 0x7001:
reg1 = gIOBase + 0x0e020248;
reg2 = gIOBase + 0x0e020250;
reg3 = gIOBase + 0x0e020288;
otg_irq = 182;
break;
case 0x8000:
case 0x8003:
reg1 = 0x80250;
reg2 = 0x80258;
reg3 = 0x80290;
break;
reg1 = gIOBase + 0x0e080250;
reg2 = gIOBase + 0x0e080258;
reg3 = gIOBase + 0x0e080290;
otg_irq = 214;
break;
case 0x8001:
reg1 = 0x80278;
reg2 = 0x80280;
reg3 = 0x802B8;
break;
case 0x7000:
case 0x7001:
reg1 = 0x20248;
reg2 = 0x20250;
reg3 = 0x20288;
break;
case 0x8960:
reg1 = 0x20158;
reg2 = 0x20160;
reg3 = 0x20188;
break;
reg1 = gIOBase + 0x0e080278;
reg2 = gIOBase + 0x0e080280;
reg3 = gIOBase + 0x0e0802B8;
otg_irq = 241;
break;
case 0x8010:
reg1 = gIOBase + 0x0e080268;
reg2 = gIOBase + 0x0e080270;
reg3 = gIOBase + 0x0e080290;
otg_irq = 241;
break;
case 0x8011:
reg1 = gIOBase + 0x0e080288;
reg2 = gIOBase + 0x0e080290;
reg3 = gIOBase + 0x0e0802a0;
otg_irq = 243;
break;
case 0x8012:
reg1 = gIOBase + 0x0e080268;
reg2 = gIOBase + 0x0e080270;
reg3 = gIOBase + 0x0e080290;
otg_irq = 304;
break;
case 0x8015:
reg1 = gIOBase + 0x32080270;
reg2 = gIOBase + 0x32080278;
reg3 = gIOBase + 0x32080270;
otg_irq = 324;
break;
default:
USB_DEBUG(USB_DEBUG_STANDARD, "USB: unsupported platform: %x\nblame qwerty!\n", socnum);
break;
panic("USB: unsupported platform: %x\n - this one's on Siguza\n", socnum);
break;
}

uint64_t dma_page_v = (uint64_t) alloc_contig(4 * DMA_BUFFER_SIZE);
Expand All @@ -1824,8 +1842,6 @@ void usb_init() {
disable_interrupts();
usb_irq_mode = 1;
usb_usbtask_handoff_mode = 0;
gSynopsysBase = dt_get_u32_prop("usb-device", "reg");
gSynopsysBase += (gSynopsysOTGBase & (~0xfff));
usb_bringup();

gSynopsysCoreVersion = reg_read(rGSNPSID) & 0xffff;
Expand Down Expand Up @@ -1869,7 +1885,7 @@ void usb_init() {
}
usb_irq = 0;
if (usb_irq_mode) {
usb_irq = dt_get_u32_prop("usb-device", "interrupts");
usb_irq = otg_irq;
task_register_preempt_irq(&usb_task, usb_main, usb_irq);
}
else task_register(&usb_task, usb_main);
Expand All @@ -1879,9 +1895,8 @@ void usb_init() {
void usb_teardown() {
if (!gSynopsysOTGBase) return;
gSynopsysOTGBase = 0;
uint64_t clockGateBase = dt_get_u32_prop("pmgr", "reg") + gIOBase;
*(volatile uint32_t*)(gSynopsysOTGBase + 0x4) &= ~2;
clock_gate(clockGateBase + reg3, 0);
clock_gate(clockGateBase + reg2, 0);
clock_gate(clockGateBase + reg1, 0);
clock_gate(reg3, 0);
clock_gate(reg2, 0);
clock_gate(reg1, 0);
}
3 changes: 2 additions & 1 deletion src/dynamic/modload.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ struct pongo_exports public_api[] = {
EXPORT_SYMBOL(cache_invalidate),
EXPORT_SYMBOL(cache_clean_and_invalidate),
EXPORT_SYMBOL(register_irq_handler),
EXPORT_SYMBOL(device_clock_addr),
EXPORT_SYMBOL(device_clock_by_id),
EXPORT_SYMBOL(device_clock_by_name),
EXPORT_SYMBOL(clock_gate),
EXPORT_SYMBOL(disable_preemption),
EXPORT_SYMBOL(enable_preemption),
Expand Down
26 changes: 25 additions & 1 deletion src/kernel/lowlevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ void interrupt_teardown() {
task_irq_teardown();
}

uint64_t device_clock_addr(uint32_t id)
uint64_t device_clock_by_id(uint32_t id)
{
for(uint32_t i = 0; i < gPMGRdevlen; ++i)
{
Expand All @@ -486,6 +486,30 @@ uint64_t device_clock_addr(uint32_t id)
return 0;
}

uint64_t device_clock_by_name(const char *name)
{
for(uint32_t i = 0; i < gPMGRdevlen; ++i)
{
pmgr_dev_t *d = &gPMGRdev[i];
if(strncmp(name, d->name, sizeof(d->name)) != 0)
{
continue;
}
if((d->flg & 0x10) || d->map >= gPMGRmaplen)
{
break;
}
pmgr_map_t *m = &gPMGRmap[d->map];
pmgr_reg_t *r = &gPMGRreg[m->reg];
if(d->idx >= ((r->size - m->off) >> 3))
{
break;
}
return gIOBase + r->addr + m->off + (d->idx << 3);
}
return 0;
}

void clock_gate(uint64_t addr, char val)
{
if (val) {
Expand Down
3 changes: 2 additions & 1 deletion src/kernel/pongo.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ extern void cache_invalidate(void *address, size_t size);
extern void cache_clean_and_invalidate(void *address, size_t size);
extern void cache_clean(void *address, size_t size);
extern void register_irq_handler(uint16_t irq_v, struct task* irq_handler);
extern uint64_t device_clock_addr(uint32_t id);
extern uint64_t device_clock_by_id(uint32_t id);
extern uint64_t device_clock_by_name(const char *name);
extern void clock_gate(uint64_t addr, char val);
extern void disable_preemption();
extern void enable_preemption();
Expand Down

0 comments on commit 8354663

Please sign in to comment.