From 777670401585e7a7deb7b3d8baf17bbc43da7f0f Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Thu, 10 Jul 2025 00:00:00 +0000 Subject: [PATCH 001/123] Some fixes for the rpi5 and compatibility with 3, but still no uart output --- kernel/console/serial/uart.c | 15 +++++++++++++-- kernel/hw/hw.c | 36 +++++++++++++++++++++++------------- kernel/hw/hw.h | 6 ++++-- kernel/mailbox/mailbox.c | 1 + kernel/mailbox/mailbox.h | 2 -- 5 files changed, 41 insertions(+), 19 deletions(-) diff --git a/kernel/console/serial/uart.c b/kernel/console/serial/uart.c index 1427062d..2dfaa9a3 100644 --- a/kernel/console/serial/uart.c +++ b/kernel/console/serial/uart.c @@ -3,6 +3,7 @@ #include "exceptions/irq.h" #include "gpio.h" #include "hw/hw.h" +#include "mailbox/mailbox.h" #define UART0_DR (UART0_BASE + 0x00) #define UART0_FR (UART0_BASE + 0x18) @@ -15,14 +16,24 @@ uint64_t get_uart_base(){ return UART0_BASE; } +volatile uint32_t uart_mbox[9] __attribute__((aligned(16))) = { + 36, 0, 0x38002, 12, 8, 2, 3000000, 0, 0 +}; + void enable_uart() { write32(UART0_CR, 0x0); if (BOARD_TYPE == 2){ - enable_gpio_pin(14); - enable_gpio_pin(15); + if (RPI_BOARD != 5){ + enable_gpio_pin(14); + enable_gpio_pin(15); + } + if (RPI_BOARD >= 4) + if (!mailbox_call(uart_mbox,8)) + return; } + write32(UART0_IBRD, 1); write32(UART0_FBRD, 40); diff --git a/kernel/hw/hw.c b/kernel/hw/hw.c index 0067a6b6..a774d2e5 100644 --- a/kernel/hw/hw.c +++ b/kernel/hw/hw.c @@ -3,6 +3,7 @@ #include "gpio.h" uint8_t BOARD_TYPE; +uint8_t RPI_BOARD; uint8_t USE_DTB = 0; uint8_t USE_PCI = 0; uintptr_t RAM_START = 0; @@ -15,10 +16,9 @@ uintptr_t MMIO_BASE = 0; uintptr_t GICD_BASE = 0; uintptr_t GICC_BASE = 0; uintptr_t SDHCI_BASE = 0; - -uint8_t RPI_BOARD; -uint8_t GPIO_BASE; -uint8_t GPIO_PIN_BASE; +uintptr_t MAILBOX_BASE = 0; +uintptr_t GPIO_BASE; +uintptr_t GPIO_PIN_BASE; void detect_hardware(){ if (BOARD_TYPE == 1){ @@ -37,28 +37,38 @@ void detect_hardware(){ uint32_t raspi = (reg >> 4) & 0xFFF; switch (raspi) { case 0xD08: //4B. Cortex A72 - MMIO_BASE = 0xFE000000; - RPI_BOARD = 4; - GPIO_PIN_BASE = 0x50; + MMIO_BASE = 0xFE000000; + RPI_BOARD = 4; + GPIO_PIN_BASE = 0x50; break; case 0xD0B: //5. Cortex A76 - MMIO_BASE = 0x107C000000UL; - RPI_BOARD = 5; - GPIO_PIN_BASE = 0x50; + MMIO_BASE = 0x107C000000UL; + RPI_BOARD = 5; + GPIO_PIN_BASE = 0x50; + break; + default: + RPI_BOARD = 3; + MMIO_BASE = 0x3F000000; break; - default: MMIO_BASE = 0x3F000000; break; } GPIO_BASE = MMIO_BASE + 0x200000; GICD_BASE = MMIO_BASE + 0x1841000; GICC_BASE = MMIO_BASE + 0x1842000; - UART0_BASE = MMIO_BASE + 0x201000; + if (RPI_BOARD == 5){ + MAILBOX_BASE = MMIO_BASE + 0x13880; + //EMMC base becomes 0x1000FFF000UL + UART0_BASE = MMIO_BASE + 0x1001000; + } else { + MAILBOX_BASE = MMIO_BASE + 0xB880; + UART0_BASE = MMIO_BASE + 0x201000; + } SDHCI_BASE = MMIO_BASE + 0x300000; XHCI_BASE = MMIO_BASE + 0x9C0000; RAM_START = 0x10000000; CRAM_END = (MMIO_BASE - 0x10000000) & 0xF0000000; RAM_START = 0x10000000; CRAM_START = 0x13600000; - reset_gpio(); + if (RPI_BOARD != 5) reset_gpio(); } } diff --git a/kernel/hw/hw.h b/kernel/hw/hw.h index 7633c348..56809e8a 100644 --- a/kernel/hw/hw.h +++ b/kernel/hw/hw.h @@ -23,11 +23,13 @@ extern uintptr_t GICC_BASE; extern uintptr_t SDHCI_BASE; -extern uint8_t GPIO_BASE; +extern uintptr_t GPIO_BASE; -extern uint8_t GPIO_PIN_BASE; +extern uintptr_t GPIO_PIN_BASE; extern uint8_t RPI_BOARD; +extern uintptr_t MAILBOX_BASE; + void detect_hardware(); void print_hardware(); \ No newline at end of file diff --git a/kernel/mailbox/mailbox.c b/kernel/mailbox/mailbox.c index ac52f2e1..89772770 100644 --- a/kernel/mailbox/mailbox.c +++ b/kernel/mailbox/mailbox.c @@ -11,5 +11,6 @@ int mailbox_call(volatile uint32_t* mbox, uint8_t channel) { uint32_t resp = MBOX_READ; if ((resp & 0xF) == channel && (resp & ~0xF) == addr) return mbox[1] == 0x80000000; + else return false; } } \ No newline at end of file diff --git a/kernel/mailbox/mailbox.h b/kernel/mailbox/mailbox.h index bd28d6c7..025f4094 100644 --- a/kernel/mailbox/mailbox.h +++ b/kernel/mailbox/mailbox.h @@ -3,8 +3,6 @@ #include "types.h" #include "hw/hw.h" -#define MAILBOX_BASE (MMIO_BASE + 0xB880) - #define MBOX_READ (*(volatile uint32_t*)(MAILBOX_BASE + 0x00)) #define MBOX_STATUS (*(volatile uint32_t*)(MAILBOX_BASE + 0x18)) #define MBOX_WRITE (*(volatile uint32_t*)(MAILBOX_BASE + 0x20)) From 03e85e4c3d88c91be232baaa7f193f67f00e0c0e Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Fri, 11 Jul 2025 00:00:00 +0000 Subject: [PATCH 002/123] Fixes for 3b --- kernel/exceptions/irq.c | 40 +++++++++++++++++++++++++++------------- kernel/hw/hw.c | 12 +++++++++--- kernel/hw/hw.h | 2 ++ kernel/input/dwc2.cpp | 3 +-- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/kernel/exceptions/irq.c b/kernel/exceptions/irq.c index a1c0ea74..09bd22f9 100644 --- a/kernel/exceptions/irq.c +++ b/kernel/exceptions/irq.c @@ -7,6 +7,7 @@ #include "pci.h" #include "console/serial/uart.h" #include "networking/network.h" +#include "hw/hw.h" #define IRQ_TIMER 30 #define SLEEP_TIMER 27 @@ -14,6 +15,10 @@ extern void irq_el1_asm_handler(); static void gic_enable_irq(uint32_t irq, uint8_t priority, uint8_t cpu_target) { + if (RPI_BOARD == 3){ + write32(GICD_BASE + 0x210, 1 << irq); + return; + } uint32_t reg_offset = (irq / 32) * 4; uint32_t bit = 1 << (irq % 32); @@ -32,8 +37,10 @@ static void gic_enable_irq(uint32_t irq, uint8_t priority, uint8_t cpu_target) { } void irq_init() { - write8(GICD_BASE, 0); // Disable Distributor - write8(GICC_BASE, 0); // Disable CPU Interface + if (RPI_BOARD != 3){ + write8(GICD_BASE, 0); // Disable Distributor + write8(GICC_BASE, 0); // Disable CPU Interface + } gic_enable_irq(IRQ_TIMER, 0x80, 0); gic_enable_irq(MSI_OFFSET + XHCI_IRQ, 0x80, 0); @@ -41,12 +48,16 @@ void irq_init() { gic_enable_irq(MSI_OFFSET + NET_IRQ + 1, 0x80, 0); gic_enable_irq(SLEEP_TIMER, 0x80, 0); - write32(GICC_BASE + 0x004, 0xF0); //Priority + if (RPI_BOARD != 3){ + write32(GICC_BASE + 0x004, 0xF0); //Priority - write8(GICC_BASE, 1); // Enable CPU Interface - write8(GICD_BASE, 1); // Enable Distributor + write8(GICC_BASE, 1); // Enable CPU Interface + write8(GICD_BASE, 1); // Enable Distributor - kprintf("[GIC] GIC enabled\n"); + kprintf_l("[GIC] GIC enabled"); + } else { + kprintf_l("Interrupts initialized"); + } } void enable_interrupt() { @@ -65,30 +76,33 @@ void irq_el1_handler() { if (ksp != 0){ asm volatile ("mov sp, %0" :: "r"(ksp)); } - uint32_t irq = read32(GICC_BASE + 0xC); + uint32_t irq; + if (RPI_BOARD == 3){ + irq = 31 - __builtin_clz(read32(GICD_BASE + 0x204)); + } else irq = read32(GICC_BASE + 0xC); if (irq == IRQ_TIMER) { - write32(GICC_BASE + 0x10, irq); + if (RPI_BOARD != 3) write32(GICC_BASE + 0x10, irq); switch_proc(INTERRUPT); } else if (irq == MSI_OFFSET + XHCI_IRQ){ handle_input_interrupt(); - write32(GICC_BASE + 0x10, irq); + if (RPI_BOARD != 3) write32(GICC_BASE + 0x10, irq); process_restore(); } else if (irq == SLEEP_TIMER){ wake_processes(); - write32(GICC_BASE + 0x10, irq); + if (RPI_BOARD != 3) write32(GICC_BASE + 0x10, irq); process_restore(); } else if (irq == MSI_OFFSET + NET_IRQ){ network_handle_download_interrupt(); - write32(GICC_BASE + 0x10, irq); + if (RPI_BOARD != 3) write32(GICC_BASE + 0x10, irq); process_restore(); } else if (irq == MSI_OFFSET + NET_IRQ + 1){ network_handle_upload_interrupt(); - write32(GICC_BASE + 0x10, irq); + if (RPI_BOARD != 3) write32(GICC_BASE + 0x10, irq); process_restore(); } else { kprintf_raw("[GIC error] Received unknown interrupt"); - write32(GICC_BASE + 0x10, irq); + if (RPI_BOARD != 3) write32(GICC_BASE + 0x10, irq); process_restore(); } } diff --git a/kernel/hw/hw.c b/kernel/hw/hw.c index a774d2e5..a6891f18 100644 --- a/kernel/hw/hw.c +++ b/kernel/hw/hw.c @@ -19,6 +19,7 @@ uintptr_t SDHCI_BASE = 0; uintptr_t MAILBOX_BASE = 0; uintptr_t GPIO_BASE; uintptr_t GPIO_PIN_BASE; +uintptr_t DWC2_BASE; void detect_hardware(){ if (BOARD_TYPE == 1){ @@ -51,18 +52,23 @@ void detect_hardware(){ MMIO_BASE = 0x3F000000; break; } - GPIO_BASE = MMIO_BASE + 0x200000; - GICD_BASE = MMIO_BASE + 0x1841000; - GICC_BASE = MMIO_BASE + 0x1842000; + if (RPI_BOARD == 3){ + GICD_BASE = MMIO_BASE + 0xB200; + } else { + GICD_BASE = MMIO_BASE + 0x1841000; + GICC_BASE = MMIO_BASE + 0x1842000; + } if (RPI_BOARD == 5){ MAILBOX_BASE = MMIO_BASE + 0x13880; //EMMC base becomes 0x1000FFF000UL UART0_BASE = MMIO_BASE + 0x1001000; } else { + GPIO_BASE = MMIO_BASE + 0x200000; MAILBOX_BASE = MMIO_BASE + 0xB880; UART0_BASE = MMIO_BASE + 0x201000; } SDHCI_BASE = MMIO_BASE + 0x300000; + DWC2_BASE = MMIO_BASE + 0x980000; XHCI_BASE = MMIO_BASE + 0x9C0000; RAM_START = 0x10000000; CRAM_END = (MMIO_BASE - 0x10000000) & 0xF0000000; diff --git a/kernel/hw/hw.h b/kernel/hw/hw.h index 56809e8a..126ebd3c 100644 --- a/kernel/hw/hw.h +++ b/kernel/hw/hw.h @@ -31,5 +31,7 @@ extern uint8_t RPI_BOARD; extern uintptr_t MAILBOX_BASE; +extern uintptr_t DWC2_BASE; + void detect_hardware(); void print_hardware(); \ No newline at end of file diff --git a/kernel/input/dwc2.cpp b/kernel/input/dwc2.cpp index 5da780f6..69f1b854 100644 --- a/kernel/input/dwc2.cpp +++ b/kernel/input/dwc2.cpp @@ -4,8 +4,7 @@ #include "memory/page_allocator.h" #include "std/string.h" #include "memory/mmu.h" - -#define DWC2_BASE 0xFE980000 +#include "hw/hw.h" dwc2_host_channel* DWC2Driver::get_channel(uint16_t channel){ return (dwc2_host_channel *)(DWC2_BASE + 0x500 + (channel * 0x20)); From ae8033adc1441127286c8bb17c0e9d117c6d4462 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Fri, 11 Jul 2025 00:00:00 +0000 Subject: [PATCH 003/123] Don't crash if no usb device found --- kernel/input/dwc2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/input/dwc2.cpp b/kernel/input/dwc2.cpp index 69f1b854..a993aa53 100644 --- a/kernel/input/dwc2.cpp +++ b/kernel/input/dwc2.cpp @@ -58,7 +58,7 @@ bool DWC2Driver::init() { if (!wait(&host->port, 1, true, 2000)){ kprintf("[DWC2] No device connected %x",host->port); - return false; + return true; } if (!port_reset(&host->port)){ From 3010a1a547cfccd3a673f1b52736ffb59743208f Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sun, 13 Jul 2025 00:00:00 +0000 Subject: [PATCH 004/123] Added new commands for dump and install --- .gitignore | 2 ++ Makefile | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 24a9643d..e90a97b5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ libshared.a *.a dump.dtb fs +dump +*.cfg diff --git a/Makefile b/Makefile index 5cdc133f..dde5e406 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,23 @@ MODE ?= virt LOAD_ADDR ?= 0x41000000 -.PHONY: all kernel user shared clean raspi virt run debug +OS := $(shell uname) + +ifeq ($(OS),Darwin) +BOOTFS=/Volumes/bootfs +else +BOOTFS=/media/bootfs +endif + +.PHONY: all kernel user shared clean raspi virt run debug dump all: shared user kernel @echo "Build complete." ./createfs +dump: + aarch64-none-elf-objdump -D kernel.elf > dump + shared: $(MAKE) -C shared @@ -31,6 +42,11 @@ debug: $(MAKE) $(MODE) ./rundebug MODE=$(MODE) $(ARGS) +install: + $(MAKE) LOAD_ADDR=0x80000 all + cp kernel.img $(BOOTFS)/kernel8.img + cp kernel.img $(BOOTFS)/kernel_2712.img + run: $(MAKE) $(MODE) ./run_$(MODE) \ No newline at end of file From acfa8dd49e0627b1f81bf3707b337c50be015058 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sun, 13 Jul 2025 00:00:00 +0000 Subject: [PATCH 005/123] SDHCI address fi --- kernel/hw/hw.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/hw/hw.c b/kernel/hw/hw.c index a6891f18..5f8cd702 100644 --- a/kernel/hw/hw.c +++ b/kernel/hw/hw.c @@ -45,7 +45,6 @@ void detect_hardware(){ case 0xD0B: //5. Cortex A76 MMIO_BASE = 0x107C000000UL; RPI_BOARD = 5; - GPIO_PIN_BASE = 0x50; break; default: RPI_BOARD = 3; @@ -60,14 +59,14 @@ void detect_hardware(){ } if (RPI_BOARD == 5){ MAILBOX_BASE = MMIO_BASE + 0x13880; - //EMMC base becomes 0x1000FFF000UL + SDHCI_BASE = 0x1000FFF000UL; UART0_BASE = MMIO_BASE + 0x1001000; } else { GPIO_BASE = MMIO_BASE + 0x200000; MAILBOX_BASE = MMIO_BASE + 0xB880; UART0_BASE = MMIO_BASE + 0x201000; + SDHCI_BASE = MMIO_BASE + 0x300000; } - SDHCI_BASE = MMIO_BASE + 0x300000; DWC2_BASE = MMIO_BASE + 0x980000; XHCI_BASE = MMIO_BASE + 0x9C0000; RAM_START = 0x10000000; From 1ca0805cd539463051b7dabb01f46ee59758595a Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sun, 13 Jul 2025 00:00:00 +0000 Subject: [PATCH 006/123] UART fixes --- kernel/console/kio.c | 2 ++ kernel/console/serial/uart.c | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/kernel/console/kio.c b/kernel/console/kio.c index a046813d..9ce4a181 100644 --- a/kernel/console/kio.c +++ b/kernel/console/kio.c @@ -32,12 +32,14 @@ void kprintf_args(const char *fmt, const uint64_t *args, uint32_t arg_count){ void kprintf_args_raw(const char *fmt, const uint64_t *args, uint32_t arg_count){ kstring s = kstring_format_args(fmt, args, arg_count); puts(s.data); + putc('\r'); putc('\n'); temp_free(s.data,256); } void kprintf_l(const char *fmt){ puts(fmt); + putc('\r'); putc('\n'); } diff --git a/kernel/console/serial/uart.c b/kernel/console/serial/uart.c index 2dfaa9a3..279a796b 100644 --- a/kernel/console/serial/uart.c +++ b/kernel/console/serial/uart.c @@ -17,25 +17,33 @@ uint64_t get_uart_base(){ } volatile uint32_t uart_mbox[9] __attribute__((aligned(16))) = { - 36, 0, 0x38002, 12, 8, 2, 3000000, 0, 0 + 36, 0, 0x30002, 12, 8, 2, 0, 0, 0 }; void enable_uart() { write32(UART0_CR, 0x0); + uint32_t ibrd = 1; + uint32_t fbrd = 40; + uint32_t baud = 115200; + if (BOARD_TYPE == 2){ if (RPI_BOARD != 5){ enable_gpio_pin(14); enable_gpio_pin(15); } if (RPI_BOARD >= 4) - if (!mailbox_call(uart_mbox,8)) - return; + if (mailbox_call(uart_mbox,8)){ + uint32_t uart_clk = uart_mbox[6]; + ibrd = uart_clk / (16 * baud); + uint32_t rem = uart_clk % (16 * baud); + fbrd = (rem * 64 + baud/2) / baud; + } } + write32(UART0_IBRD, ibrd); + write32(UART0_FBRD, fbrd); - write32(UART0_IBRD, 1); - write32(UART0_FBRD, 40); write32(UART0_LCRH, (1 << 4) | (1 << 5) | (1 << 6)); From f22dd28bf73e6218587889fa0b3fa1216acc67a8 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sun, 13 Jul 2025 00:00:00 +0000 Subject: [PATCH 007/123] Fixed GIC address --- kernel/hw/hw.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kernel/hw/hw.c b/kernel/hw/hw.c index 5f8cd702..616b2266 100644 --- a/kernel/hw/hw.c +++ b/kernel/hw/hw.c @@ -41,22 +41,21 @@ void detect_hardware(){ MMIO_BASE = 0xFE000000; RPI_BOARD = 4; GPIO_PIN_BASE = 0x50; + GICD_BASE = MMIO_BASE + 0x1841000; + GICC_BASE = MMIO_BASE + 0x1842000; break; case 0xD0B: //5. Cortex A76 MMIO_BASE = 0x107C000000UL; RPI_BOARD = 5; + GICD_BASE = 0x20001000; + GICC_BASE = 0x20002000; break; default: RPI_BOARD = 3; MMIO_BASE = 0x3F000000; + GICD_BASE = MMIO_BASE + 0xB200; break; } - if (RPI_BOARD == 3){ - GICD_BASE = MMIO_BASE + 0xB200; - } else { - GICD_BASE = MMIO_BASE + 0x1841000; - GICC_BASE = MMIO_BASE + 0x1842000; - } if (RPI_BOARD == 5){ MAILBOX_BASE = MMIO_BASE + 0x13880; SDHCI_BASE = 0x1000FFF000UL; From f3ddb2012748de23f0a70784f3e102093ba03c16 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sun, 13 Jul 2025 00:00:00 +0000 Subject: [PATCH 008/123] timer fix --- Makefile | 1 + kernel/boot.S | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Makefile b/Makefile index dde5e406..3e320cf5 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,7 @@ debug: ./rundebug MODE=$(MODE) $(ARGS) install: + $(MAKE) clean $(MAKE) LOAD_ADDR=0x80000 all cp kernel.img $(BOOTFS)/kernel8.img cp kernel.img $(BOOTFS)/kernel_2712.img diff --git a/kernel/boot.S b/kernel/boot.S index cc4b195d..f71c6250 100644 --- a/kernel/boot.S +++ b/kernel/boot.S @@ -82,6 +82,12 @@ el2_entry: cmp x0, #2 b.ne el1_non_secure + mrs x0, cnthctl_el2 + orr x0, x0, #(1 << 0) | (1 << 1) //Disable trapping of timer calls on hypervisor level + msr cnthctl_el2, x0 + + msr cntvoff_el2, xzr + mov x0, #3 << 20 msr cpacr_el1, x0 From ee904cfa15a2b80d3ce7a2333837d55ebf7c3c43 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 14 Jul 2025 00:00:00 +0000 Subject: [PATCH 009/123] using carriage return in exception handlers --- kernel/exceptions/exception_handler.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/kernel/exceptions/exception_handler.c b/kernel/exceptions/exception_handler.c index 3f34039b..a2614eb4 100644 --- a/kernel/exceptions/exception_handler.c +++ b/kernel/exceptions/exception_handler.c @@ -24,7 +24,7 @@ void handle_exception(const char* type) { disable_visual();//Disable visual kprintf, since it has additional memory accesses that could be faulting - kstring s = kstring_format("%s \nESR_EL1: %x\nELR_EL1: %x\nFAR_EL1: %x",(uint64_t)kstring_l(type).data,esr,elr,far); + kstring s = kstring_format("%s \r\nESR_EL1: %x\r\nELR_EL1: %x\r\nFAR_EL1: %x",(uint64_t)kstring_l(type).data,esr,elr,far); panic(s.data); } @@ -36,13 +36,13 @@ void handle_exception_with_info(const char* type, uint64_t info) { disable_visual();//Disable visual kprintf, since it has additional memory accesses that could be faulting - kstring s = kstring_format("%s \nESR_EL1: %x\nELR_EL1: %x\nFAR_EL1: %x",(uint64_t)kstring_l(type).data,esr,elr,far); + kstring s = kstring_format("%s \r\nESR_EL1: %x\r\nELR_EL1: %x\r\nFAR_EL1: %x",(uint64_t)kstring_l(type).data,esr,elr,far); panic_with_info(s.data, info); } -void fiq_el1_handler(){ handle_exception("FIQ EXCEPTION\n"); } +void fiq_el1_handler(){ handle_exception("FIQ EXCEPTION\r\n"); } -void error_el1_handler(){ handle_exception("ERROR EXCEPTION\n"); } +void error_el1_handler(){ handle_exception("ERROR EXCEPTION\r\n"); } void draw_panic_screen(kstring s){ gpu_clear(0x0000FF); @@ -58,12 +58,12 @@ void panic(const char* panic_msg) { panic_triggered = true; uart_raw_puts("*** "); uart_raw_puts(PANIC_TEXT); - uart_raw_puts(" ***\n"); + uart_raw_puts(" ***\r\n"); uart_raw_puts(panic_msg); - uart_raw_putc('\n'); + uart_raw_puts("\r\n"); uart_raw_puts("System Halted"); if (!old_panic_triggered){ - kstring s = kstring_format("%s\n%s\nSystem Halted",(uint64_t)PANIC_TEXT,(uint64_t)panic_msg); + kstring s = kstring_format("%s\r\n%s\r\nSystem Halted",(uint64_t)PANIC_TEXT,(uint64_t)panic_msg); draw_panic_screen(s); } while (1);//TODO: OPT @@ -81,15 +81,15 @@ void panic_with_info(const char* msg, uint64_t info) { panic_triggered = true; uart_raw_puts("*** "); uart_raw_puts(PANIC_TEXT); - uart_raw_puts(" ***\n"); + uart_raw_puts(" ***\r\n"); uart_raw_puts(msg); - uart_raw_putc('\n'); + uart_raw_puts("\r\n"); uart_raw_puts("Additional info: "); uart_puthex(info); - uart_raw_putc('\n'); + uart_raw_puts("\r\n"); uart_raw_puts("System Halted"); if (!old_panic_triggered){ - kstring s = kstring_format("%s\n%s\nError code: %x\nSystem Halted",(uint64_t)PANIC_TEXT,(uint64_t)msg,info); + kstring s = kstring_format("%s\r\n%s\r\nError code: %x\r\nSystem Halted",(uint64_t)PANIC_TEXT,(uint64_t)msg,info); draw_panic_screen(s); } while (1);//TODO: OPT From a09c79dc6a6d533ed803a71ca7e6edd4f53a6683 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 14 Jul 2025 00:00:00 +0000 Subject: [PATCH 010/123] New GIC addresses for 5 --- kernel/hw/hw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/hw/hw.c b/kernel/hw/hw.c index 616b2266..2dc44e30 100644 --- a/kernel/hw/hw.c +++ b/kernel/hw/hw.c @@ -47,8 +47,8 @@ void detect_hardware(){ case 0xD0B: //5. Cortex A76 MMIO_BASE = 0x107C000000UL; RPI_BOARD = 5; - GICD_BASE = 0x20001000; - GICC_BASE = 0x20002000; + GICD_BASE = MMIO_BASE + 0x3FF9000; + GICC_BASE = MMIO_BASE + 0x3FFA000; break; default: RPI_BOARD = 3; From b3cf58092da813d74e281ba18ada8e0ebd8f8032 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 14 Jul 2025 00:00:00 +0000 Subject: [PATCH 011/123] fixed l0 addressing --- kernel/memory/mmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/memory/mmu.c b/kernel/memory/mmu.c index 046beb27..be5f9475 100644 --- a/kernel/memory/mmu.c +++ b/kernel/memory/mmu.c @@ -67,7 +67,7 @@ void mmu_map_2mb(uint64_t va, uint64_t pa, uint64_t attr_index) { //Level 0 = EL0, Level 1 = EL1, Level 2 = Shared void mmu_map_4kb(uint64_t va, uint64_t pa, uint64_t attr_index, uint64_t level) { - uint64_t l1_index = (va >> 37) & 0x1FF; + uint64_t l1_index = (va >> 39) & 0x1FF; uint64_t l2_index = (va >> 30) & 0x1FF; uint64_t l3_index = (va >> 21) & 0x1FF; uint64_t l4_index = (va >> 12) & 0x1FF; @@ -140,7 +140,7 @@ static inline void mmu_flush_icache() { void mmu_unmap(uint64_t va, uint64_t pa){ - uint64_t l1_index = (va >> 37) & 0x1FF; + uint64_t l1_index = (va >> 39) & 0x1FF; uint64_t l2_index = (va >> 30) & 0x1FF; uint64_t l3_index = (va >> 21) & 0x1FF; uint64_t l4_index = (va >> 12) & 0x1FF; @@ -246,7 +246,7 @@ void debug_mmu_address(uint64_t va){ uint64_t l3_index = (va >> 21) & 0x1FF; uint64_t l4_index = (va >> 12) & 0x1FF; - kprintf_raw("Address is meant to be mapped to [%i][%i][%i][%i]",l1_index,l2_index,l3_index,l4_index); + kprintf_raw("Address %x is meant to be mapped to [%i][%i][%i][%i]",va, l1_index,l2_index,l3_index,l4_index); if (!(page_table_l1[l1_index] & 1)) { kprintf_raw("L1 Table missing"); From 398330e9e4f1975c9f82b0fb9c311e289cdfb39b Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 14 Jul 2025 00:00:00 +0000 Subject: [PATCH 012/123] defined some mmu bits --- kernel/memory/mmu.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/kernel/memory/mmu.c b/kernel/memory/mmu.c index be5f9475..5708f272 100644 --- a/kernel/memory/mmu.c +++ b/kernel/memory/mmu.c @@ -16,7 +16,13 @@ #define PD_TABLE 0b11 #define PD_BLOCK 0b01 -#define PD_ACCESS (1 << 10) + +#define UXN_BIT 54 +#define PXN_BIT 53 +#define AF_BIT 10 +#define SH_BIT 8 +#define AP_BIT 6 +#define MAIR_BIT 2 #define PAGE_TABLE_ENTRIES 512 #define PAGE_SIZE PAGE_TABLE_ENTRIES * 8 @@ -61,7 +67,7 @@ void mmu_map_2mb(uint64_t va, uint64_t pa, uint64_t attr_index) { uint64_t* l3 = (uint64_t*)(l2[l2_index] & 0xFFFFFFFFF000ULL); //For now we make this not executable. We'll need to to separate read_write, read_only and executable sections - uint64_t attr = ((uint64_t)1 << 54) | ((uint64_t)0 << 53) | PD_ACCESS | (0b11 << 8) | (0b00 << 6) | (attr_index << 2) | PD_BLOCK; + uint64_t attr = ((uint64_t)1 << UXN_BIT) | ((uint64_t)0 << PXN_BIT) | (1 << AF_BIT) | (0b11 << SH_BIT) | (0b00 << AP_BIT) | (attr_index << MAIR_BIT) | PD_BLOCK; l3[l3_index] = (pa & 0xFFFFFFFFF000ULL) | attr; } @@ -103,7 +109,6 @@ void mmu_map_4kb(uint64_t va, uint64_t pa, uint64_t attr_index, uint64_t level) return; } - //54 = UXN level | 53 = PXN !level | 8 = share | 6 = Access permission uint8_t permission; switch (level) @@ -115,7 +120,7 @@ void mmu_map_4kb(uint64_t va, uint64_t pa, uint64_t attr_index, uint64_t level) default: break; } - uint64_t attr = ((uint64_t)(level == 1) << 54) | ((uint64_t)0 << 53) | PD_ACCESS | (0b11 << 8) | (permission << 6) | (attr_index << 2) | 0b11; + uint64_t attr = ((uint64_t)(level == 1) << UXN_BIT) | ((uint64_t)0 << PXN_BIT) | (1 << AF_BIT) | (0b01 << SH_BIT) | (permission << AP_BIT) | (attr_index << MAIR_BIT) | 0b11; kprintfv("[MMU] Mapping 4kb memory %x at [%i][%i][%i][%i] for EL%i = %x | %x permission: %i", va, l1_index,l2_index,l3_index,l4_index,level,pa,attr,permission); l4[l4_index] = (pa & 0xFFFFFFFFF000ULL) | attr; @@ -138,7 +143,6 @@ static inline void mmu_flush_icache() { } void mmu_unmap(uint64_t va, uint64_t pa){ - uint64_t l1_index = (va >> 39) & 0x1FF; uint64_t l2_index = (va >> 30) & 0x1FF; From 6af89bffd16e6b2782f7c7dd451708f76945fa2e Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 14 Jul 2025 00:00:00 +0000 Subject: [PATCH 013/123] cleaned up boot code with defined values --- kernel/boot.S | 12 ++++++------ kernel/sysregs.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 kernel/sysregs.h diff --git a/kernel/boot.S b/kernel/boot.S index f71c6250..a69db337 100644 --- a/kernel/boot.S +++ b/kernel/boot.S @@ -1,3 +1,5 @@ +#include "sysregs.h" + .global _start .section .text _start: @@ -80,7 +82,7 @@ el2_entry: mrs x0, CurrentEL lsr x0, x0, #2 cmp x0, #2 - b.ne el1_non_secure + b.ne stack_setup mrs x0, cnthctl_el2 orr x0, x0, #(1 << 0) | (1 << 1) //Disable trapping of timer calls on hypervisor level @@ -91,22 +93,20 @@ el2_entry: mov x0, #3 << 20 msr cpacr_el1, x0 - ldr x0, =0x30C00800 + ldr x0, =SCTLR_VALUE_MMU_DISABLED msr sctlr_el1, x0 - mrs x0, hcr_el2 - orr x0, x0, #(1<<31) + ldr x0, =HCR_RW msr hcr_el2, x0 mov x0, 0x1C5 msr spsr_el2, x0 - adr x0, el1_non_secure + adr x0, stack_setup msr elr_el2, x0 eret -el1_non_secure: stack_setup: ldr x1, =stack_top mov sp, x1 diff --git a/kernel/sysregs.h b/kernel/sysregs.h new file mode 100644 index 00000000..1e25344b --- /dev/null +++ b/kernel/sysregs.h @@ -0,0 +1,44 @@ +#ifndef SYSREGS_H +#define SYSREGS_H + +// *************************************** +// SCTLR_EL1, System Control Register (EL1), Page 2654 of AArch64-Reference-Manual. +// *************************************** + +#define SCTLR_RESERVED (3 << 28) | (3 << 22) | (1 << 20) | (1 << 11) +#define SCTLR_EE_LITTLE_ENDIAN (0 << 25) +#define SCTLR_EOE_LITTLE_ENDIAN (0 << 24) +#define SCTLR_I_CACHE_DISABLED (0 << 12) +#define SCTLR_D_CACHE_DISABLED (0 << 2) +#define SCTLR_I_CACHE_ENABLED (1 << 12) +#define SCTLR_D_CACHE_ENABLED (1 << 2) +#define SCTLR_MMU_DISABLED (0 << 0) +#define SCTLR_MMU_ENABLED (1 << 0) + +#define SCTLR_VALUE_MMU_DISABLED (SCTLR_RESERVED | SCTLR_EE_LITTLE_ENDIAN | SCTLR_I_CACHE_ENABLED | SCTLR_D_CACHE_ENABLED | SCTLR_MMU_DISABLED) + +// *************************************** +// HCR_EL2, Hypervisor Configuration Register (EL2), Page 2487 of AArch64-Reference-Manual. +// *************************************** + +#define HCR_RW (1 << 31) +#define HCR_VALUE HCR_RW + +// *************************************** +// SCR_EL3, Secure Configuration Register (EL3), Page 2648 of AArch64-Reference-Manual. +// *************************************** + +#define SCR_RESERVED (3 << 4) +#define SCR_RW (1 << 10) +#define SCR_NS (1 << 0) +#define SCR_VALUE (SCR_RESERVED | SCR_RW | SCR_NS) + +// *************************************** +// SPSR_EL3, Saved Program Status Register (EL3) Page 389 of AArch64-Reference-Manual. +// *************************************** + +#define SPSR_MASK_ALL (7 << 6) +#define SPSR_EL1h (5 << 0) +#define SPSR_VALUE (SPSR_MASK_ALL | SPSR_EL1h) + +#endif \ No newline at end of file From 177e8e8ed0daaf4a5f5b993bb47e371372a612aa Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 14 Jul 2025 00:00:00 +0000 Subject: [PATCH 014/123] Added hypervisor timer config to sysregs --- kernel/boot.S | 10 ++-------- kernel/sysregs.h | 8 ++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/kernel/boot.S b/kernel/boot.S index a69db337..d69217fc 100644 --- a/kernel/boot.S +++ b/kernel/boot.S @@ -62,13 +62,8 @@ drop_el3: b.ne el2_entry msr sctlr_el2, xzr - mrs x0, hcr_el2 - orr x0, x0, #(1<<19) - msr hcr_el2, x0 - mrs x0, scr_el3 - orr x0, x0, #(1<<10) - orr x0, x0, #(1<<0) + ldr x0, =SCR_VALUE msr scr_el3, x0 mov x0, #0b01001//DAIF 0000 @@ -84,8 +79,7 @@ el2_entry: cmp x0, #2 b.ne stack_setup - mrs x0, cnthctl_el2 - orr x0, x0, #(1 << 0) | (1 << 1) //Disable trapping of timer calls on hypervisor level + ldr x0, =CNTHCTL_VALUE msr cnthctl_el2, x0 msr cntvoff_el2, xzr diff --git a/kernel/sysregs.h b/kernel/sysregs.h index 1e25344b..70ba619c 100644 --- a/kernel/sysregs.h +++ b/kernel/sysregs.h @@ -41,4 +41,12 @@ #define SPSR_EL1h (5 << 0) #define SPSR_VALUE (SPSR_MASK_ALL | SPSR_EL1h) +// *************************************** +// CNTHCTL_EL2, Counter-timer Hypervisor Control Register (EL2) Page 9569 of AArch64-Reference-Manual. +// *************************************** + +#define TRAP_PHYS_TIMER_DISABLED (1 << 0) +#define TRAV_VIRT_TIMER_DISABLED (1 << 1) //Disable trapping of timer calls on hypervisor level +#define CNTHCTL_VALUE (TRAP_PHYS_TIMER_DISABLED | TRAV_VIRT_TIMER_DISABLED) + #endif \ No newline at end of file From 014d71893eee1c03d085bc763acb1968fdb6384b Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 14 Jul 2025 00:00:00 +0000 Subject: [PATCH 015/123] Newline after system halted, since double exceptions can still happen --- kernel/exceptions/exception_handler.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/exceptions/exception_handler.c b/kernel/exceptions/exception_handler.c index a2614eb4..945e286b 100644 --- a/kernel/exceptions/exception_handler.c +++ b/kernel/exceptions/exception_handler.c @@ -61,7 +61,7 @@ void panic(const char* panic_msg) { uart_raw_puts(" ***\r\n"); uart_raw_puts(panic_msg); uart_raw_puts("\r\n"); - uart_raw_puts("System Halted"); + uart_raw_puts("System Halted\r\n"); if (!old_panic_triggered){ kstring s = kstring_format("%s\r\n%s\r\nSystem Halted",(uint64_t)PANIC_TEXT,(uint64_t)panic_msg); draw_panic_screen(s); @@ -87,7 +87,7 @@ void panic_with_info(const char* msg, uint64_t info) { uart_raw_puts("Additional info: "); uart_puthex(info); uart_raw_puts("\r\n"); - uart_raw_puts("System Halted"); + uart_raw_puts("System Halted\r\n"); if (!old_panic_triggered){ kstring s = kstring_format("%s\r\n%s\r\nError code: %x\r\nSystem Halted",(uint64_t)PANIC_TEXT,(uint64_t)msg,info); draw_panic_screen(s); From 768651609d8c17a8fb74c80234dfdc990cd4a5cb Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 14 Jul 2025 00:00:00 +0000 Subject: [PATCH 016/123] Removing double disable interrupt --- kernel/kernel.c | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/kernel.c b/kernel/kernel.c index 189e4ac1..e27ee4af 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -81,7 +81,6 @@ void kernel_main() { kprintf_l("Starting scheduler"); - disable_interrupt(); start_scheduler(); panic("Kernel did not activate any process"); From 706497ddb5d9ead13326dfb75899a9bfdf2c595d Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 14 Jul 2025 00:00:00 +0000 Subject: [PATCH 017/123] SPSR on el3 --- kernel/boot.S | 2 +- kernel/sysregs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/boot.S b/kernel/boot.S index d69217fc..489f2c5b 100644 --- a/kernel/boot.S +++ b/kernel/boot.S @@ -66,7 +66,7 @@ drop_el3: ldr x0, =SCR_VALUE msr scr_el3, x0 - mov x0, #0b01001//DAIF 0000 + ldr x0, =SPSR3_VALUE msr spsr_el3, x0 adr x0, el2_entry diff --git a/kernel/sysregs.h b/kernel/sysregs.h index 70ba619c..d6b0712c 100644 --- a/kernel/sysregs.h +++ b/kernel/sysregs.h @@ -39,7 +39,7 @@ #define SPSR_MASK_ALL (7 << 6) #define SPSR_EL1h (5 << 0) -#define SPSR_VALUE (SPSR_MASK_ALL | SPSR_EL1h) +#define SPSR3_VALUE (SPSR_MASK_ALL | SPSR_EL1h) // *************************************** // CNTHCTL_EL2, Counter-timer Hypervisor Control Register (EL2) Page 9569 of AArch64-Reference-Manual. From 89995e16b9aea30e4b30c5c8d03c0a579048aa69 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 14 Jul 2025 00:00:00 +0000 Subject: [PATCH 018/123] write32 on irq to prevent a SErrror --- kernel/exceptions/irq.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/exceptions/irq.c b/kernel/exceptions/irq.c index 09bd22f9..8d280be0 100644 --- a/kernel/exceptions/irq.c +++ b/kernel/exceptions/irq.c @@ -25,8 +25,8 @@ static void gic_enable_irq(uint32_t irq, uint8_t priority, uint8_t cpu_target) { uint32_t flag = read32(GICD_BASE + 0x100 + reg_offset); write32(GICD_BASE + 0x100 + reg_offset, flag | bit); - write8(GICD_BASE + 0x800 + irq, cpu_target); - write8(GICD_BASE + 0x400 + irq, priority); + write32(GICD_BASE + 0x800 + irq, cpu_target); + write32(GICD_BASE + 0x400 + irq, priority); uint32_t config_offset = (irq / 16) * 4; uint32_t config_shift = (irq % 16) * 2; @@ -38,8 +38,8 @@ static void gic_enable_irq(uint32_t irq, uint8_t priority, uint8_t cpu_target) { void irq_init() { if (RPI_BOARD != 3){ - write8(GICD_BASE, 0); // Disable Distributor - write8(GICC_BASE, 0); // Disable CPU Interface + write32(GICD_BASE, 0); // Disable Distributor + write32(GICC_BASE, 0); // Disable CPU Interface } gic_enable_irq(IRQ_TIMER, 0x80, 0); @@ -51,8 +51,8 @@ void irq_init() { if (RPI_BOARD != 3){ write32(GICC_BASE + 0x004, 0xF0); //Priority - write8(GICC_BASE, 1); // Enable CPU Interface - write8(GICD_BASE, 1); // Enable Distributor + write32(GICC_BASE, 1); // Enable CPU Interface + write32(GICD_BASE, 1); // Enable Distributor kprintf_l("[GIC] GIC enabled"); } else { From 0fead96b58e20bc982ebb64d5140e8498a2d7a52 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Tue, 15 Jul 2025 00:00:00 +0000 Subject: [PATCH 019/123] Restored one write8 --- kernel/exceptions/irq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/exceptions/irq.c b/kernel/exceptions/irq.c index 8d280be0..fb9bad07 100644 --- a/kernel/exceptions/irq.c +++ b/kernel/exceptions/irq.c @@ -25,8 +25,8 @@ static void gic_enable_irq(uint32_t irq, uint8_t priority, uint8_t cpu_target) { uint32_t flag = read32(GICD_BASE + 0x100 + reg_offset); write32(GICD_BASE + 0x100 + reg_offset, flag | bit); - write32(GICD_BASE + 0x800 + irq, cpu_target); - write32(GICD_BASE + 0x400 + irq, priority); + write8(GICD_BASE + 0x800 + irq, cpu_target); + write8(GICD_BASE + 0x400 + irq, priority); uint32_t config_offset = (irq / 16) * 4; uint32_t config_shift = (irq % 16) * 2; From 49809d60b5fa808e7238045159910cb9c09ff6cf Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Tue, 15 Jul 2025 00:00:00 +0000 Subject: [PATCH 020/123] proper table naming --- kernel/memory/mmu.c | 131 +++++++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 68 deletions(-) diff --git a/kernel/memory/mmu.c b/kernel/memory/mmu.c index 5708f272..dc762486 100644 --- a/kernel/memory/mmu.c +++ b/kernel/memory/mmu.c @@ -27,7 +27,7 @@ #define PAGE_TABLE_ENTRIES 512 #define PAGE_SIZE PAGE_TABLE_ENTRIES * 8 -uint64_t page_table_l1[PAGE_TABLE_ENTRIES] __attribute__((aligned(PAGE_SIZE))); +uint64_t page_table_l0[PAGE_TABLE_ENTRIES] __attribute__((aligned(PAGE_SIZE))); static bool mmu_verbose; @@ -44,67 +44,62 @@ void mmu_enable_verbose(){ }) void mmu_map_2mb(uint64_t va, uint64_t pa, uint64_t attr_index) { - uint64_t l1_index = (va >> 37) & 0x1FF; - uint64_t l2_index = (va >> 30) & 0x1FF; - uint64_t l3_index = (va >> 21) & 0x1FF; + uint64_t l0_index = (va >> 39) & 0x1FF; + uint64_t l1_index = (va >> 30) & 0x1FF; + uint64_t l2_index = (va >> 21) & 0x1FF; - kprintfv("[MMU] Mapping 2mb memory %x at [%i][%i][%i] for EL1", va, l1_index,l2_index,l3_index); + kprintfv("[MMU] Mapping 2mb memory %x at [%i][%i][%i] for EL1", va, l0_index,l1_index,l2_index); - if (!(page_table_l1[l1_index] & 1)) { - uint64_t* l2 = (uint64_t*)talloc(PAGE_SIZE); - for (int i = 0; i < PAGE_TABLE_ENTRIES; i++) l2[i] = 0; - page_table_l1[l1_index] = ((uint64_t)l2 & 0xFFFFFFFFF000ULL) | PD_TABLE; + if (!(page_table_l0[l0_index] & 1)) { + uint64_t* l1 = (uint64_t*)talloc(PAGE_SIZE); + page_table_l0[l0_index] = ((uint64_t)l1 & 0xFFFFFFFFF000ULL) | PD_TABLE; } - uint64_t* l2 = (uint64_t*)(page_table_l1[l1_index] & 0xFFFFFFFFF000ULL); + uint64_t* l1 = (uint64_t*)(page_table_l0[l0_index] & 0xFFFFFFFFF000ULL); - if (!(l2[l2_index] & 1)) { - uint64_t* l3 = (uint64_t*)talloc(PAGE_SIZE); - for (int i = 0; i < PAGE_TABLE_ENTRIES; i++) l3[i] = 0; - l2[l2_index] = ((uint64_t)l3 & 0xFFFFFFFFF000ULL) | PD_TABLE; + if (!(l1[l1_index] & 1)) { + uint64_t* l2 = (uint64_t*)talloc(PAGE_SIZE); + l1[l1_index] = ((uint64_t)l2 & 0xFFFFFFFFF000ULL) | PD_TABLE; } - uint64_t* l3 = (uint64_t*)(l2[l2_index] & 0xFFFFFFFFF000ULL); + uint64_t* l2 = (uint64_t*)(l1[l1_index] & 0xFFFFFFFFF000ULL); //For now we make this not executable. We'll need to to separate read_write, read_only and executable sections uint64_t attr = ((uint64_t)1 << UXN_BIT) | ((uint64_t)0 << PXN_BIT) | (1 << AF_BIT) | (0b11 << SH_BIT) | (0b00 << AP_BIT) | (attr_index << MAIR_BIT) | PD_BLOCK; - l3[l3_index] = (pa & 0xFFFFFFFFF000ULL) | attr; + l2[l2_index] = (pa & 0xFFFFFFFFF000ULL) | attr; } //Level 0 = EL0, Level 1 = EL1, Level 2 = Shared void mmu_map_4kb(uint64_t va, uint64_t pa, uint64_t attr_index, uint64_t level) { - uint64_t l1_index = (va >> 39) & 0x1FF; - uint64_t l2_index = (va >> 30) & 0x1FF; - uint64_t l3_index = (va >> 21) & 0x1FF; - uint64_t l4_index = (va >> 12) & 0x1FF; - - if (!(page_table_l1[l1_index] & 1)) { + uint64_t l0_index = (va >> 39) & 0x1FF; + uint64_t l1_index = (va >> 30) & 0x1FF; + uint64_t l2_index = (va >> 21) & 0x1FF; + uint64_t l3_index = (va >> 12) & 0x1FF; + + if (!(page_table_l0[l0_index] & 1)) { + uint64_t* l1 = (uint64_t*)talloc(PAGE_SIZE); + page_table_l0[l0_index] = ((uint64_t)l1 & 0xFFFFFFFFF000ULL) | PD_TABLE; + } + + uint64_t* l1 = (uint64_t*)(page_table_l0[l0_index] & 0xFFFFFFFFF000ULL); + if (!(l1[l1_index] & 1)) { uint64_t* l2 = (uint64_t*)talloc(PAGE_SIZE); - for (int i = 0; i < PAGE_TABLE_ENTRIES; i++) l2[i] = 0; - page_table_l1[l1_index] = ((uint64_t)l2 & 0xFFFFFFFFF000ULL) | PD_TABLE; + l1[l1_index] = ((uint64_t)l2 & 0xFFFFFFFFF000ULL) | PD_TABLE; } - uint64_t* l2 = (uint64_t*)(page_table_l1[l1_index] & 0xFFFFFFFFF000ULL); - if (!(l2[l2_index] & 1)) { + uint64_t* l2 = (uint64_t*)(l1[l1_index] & 0xFFFFFFFFF000ULL); + uint64_t l2_val = l2[l2_index]; + if (!(l2_val & 1)) { uint64_t* l3 = (uint64_t*)talloc(PAGE_SIZE); - for (int i = 0; i < PAGE_TABLE_ENTRIES; i++) l3[i] = 0; l2[l2_index] = ((uint64_t)l3 & 0xFFFFFFFFF000ULL) | PD_TABLE; - } - - uint64_t* l3 = (uint64_t*)(l2[l2_index] & 0xFFFFFFFFF000ULL); - uint64_t l3_val = l3[l3_index]; - if (!(l3_val & 1)) { - uint64_t* l4 = (uint64_t*)talloc(PAGE_SIZE); - for (int i = 0; i < PAGE_TABLE_ENTRIES; i++) l4[i] = 0; - l3[l3_index] = ((uint64_t)l4 & 0xFFFFFFFFF000ULL) | PD_TABLE; - } else if ((l3_val & 0b11) == PD_BLOCK){ - kprintf_raw("[MMU error]: Region not mapped for address %x, already mapped at higher granularity [%i][%i][%i][%i]",va, l1_index,l2_index,l3_index,l4_index); + } else if ((l2_val & 0b11) == PD_BLOCK){ + kprintf_raw("[MMU error]: Region not mapped for address %x, already mapped at higher granularity [%i][%i][%i][%i]",va, l0_index,l1_index,l2_index,l3_index); return; } - uint64_t* l4 = (uint64_t*)(l3[l3_index] & 0xFFFFFFFFF000ULL); + uint64_t* l3 = (uint64_t*)(l2[l2_index] & 0xFFFFFFFFF000ULL); - if (l4[l4_index] & 1){ + if (l3[l3_index] & 1){ kprintf_raw("[MMU warning]: Section already mapped %x",va); return; } @@ -121,9 +116,9 @@ void mmu_map_4kb(uint64_t va, uint64_t pa, uint64_t attr_index, uint64_t level) break; } uint64_t attr = ((uint64_t)(level == 1) << UXN_BIT) | ((uint64_t)0 << PXN_BIT) | (1 << AF_BIT) | (0b01 << SH_BIT) | (permission << AP_BIT) | (attr_index << MAIR_BIT) | 0b11; - kprintfv("[MMU] Mapping 4kb memory %x at [%i][%i][%i][%i] for EL%i = %x | %x permission: %i", va, l1_index,l2_index,l3_index,l4_index,level,pa,attr,permission); + kprintfv("[MMU] Mapping 4kb memory %x at [%i][%i][%i][%i] for EL%i = %x | %x permission: %i", va, l0_index,l1_index,l2_index,l3_index,level,pa,attr,permission); - l4[l4_index] = (pa & 0xFFFFFFFFF000ULL) | attr; + l3[l3_index] = (pa & 0xFFFFFFFFF000ULL) | attr; } static inline void mmu_flush_all() { @@ -144,28 +139,28 @@ static inline void mmu_flush_icache() { void mmu_unmap(uint64_t va, uint64_t pa){ - uint64_t l1_index = (va >> 39) & 0x1FF; - uint64_t l2_index = (va >> 30) & 0x1FF; - uint64_t l3_index = (va >> 21) & 0x1FF; - uint64_t l4_index = (va >> 12) & 0x1FF; + uint64_t l0_index = (va >> 39) & 0x1FF; + uint64_t l1_index = (va >> 30) & 0x1FF; + uint64_t l2_index = (va >> 21) & 0x1FF; + uint64_t l3_index = (va >> 12) & 0x1FF; - kprintfv("[MMU] Unmapping 4kb memory %x at [%i][%i][%i][%i] for EL1", va, l1_index,l2_index,l3_index, l4_index); - if (!(page_table_l1[l1_index] & 1)) return; + kprintfv("[MMU] Unmapping 4kb memory %x at [%i][%i][%i][%i] for EL1", va, l0_index,l1_index,l2_index, l3_index); + if (!(page_table_l0[l0_index] & 1)) return; - uint64_t* l2 = (uint64_t*)(page_table_l1[l1_index] & 0xFFFFFFFFF000ULL); - if (!(l2[l2_index] & 1)) return; + uint64_t* l1 = (uint64_t*)(page_table_l0[l0_index] & 0xFFFFFFFFF000ULL); + if (!(l1[l1_index] & 1)) return; - uint64_t* l3 = (uint64_t*)(l2[l2_index] & 0xFFFFFFFFF000ULL); - uint64_t l3_val = l3[l3_index]; + uint64_t* l2 = (uint64_t*)(l1[l1_index] & 0xFFFFFFFFF000ULL); + uint64_t l3_val = l2[l2_index]; if (!(l3_val & 1)) return; else if ((l3_val & 0b11) == PD_BLOCK){ - l3[l3_index] = 0; + l2[l2_index] = 0; return; } - uint64_t* l4 = (uint64_t*)(l3[l3_index] & 0xFFFFFFFFF000ULL); + uint64_t* l3 = (uint64_t*)(l2[l2_index] & 0xFFFFFFFFF000ULL); - l4[l4_index] = 0; + l3[l3_index] = 0; mmu_flush_all(); mmu_flush_icache(); @@ -173,7 +168,7 @@ void mmu_unmap(uint64_t va, uint64_t pa){ void mmu_alloc(){ for (int i = 0; i < PAGE_TABLE_ENTRIES; i++) { - page_table_l1[i] = 0; + page_table_l0[i] = 0; } } @@ -210,7 +205,7 @@ void mmu_init() { asm volatile ("dsb ish"); asm volatile ("isb"); - asm volatile ("msr ttbr0_el1, %0" :: "r"(page_table_l1)); + asm volatile ("msr ttbr0_el1, %0" :: "r"(page_table_l0)); asm volatile ( "mrs x0, sctlr_el1\n" @@ -245,24 +240,24 @@ void register_proc_memory(uint64_t va, uint64_t pa, bool kernel){ } void debug_mmu_address(uint64_t va){ - uint64_t l1_index = (va >> 37) & 0x1FF; - uint64_t l2_index = (va >> 30) & 0x1FF; - uint64_t l3_index = (va >> 21) & 0x1FF; - uint64_t l4_index = (va >> 12) & 0x1FF; + uint64_t l0_index = (va >> 37) & 0x1FF; + uint64_t l1_index = (va >> 30) & 0x1FF; + uint64_t l2_index = (va >> 21) & 0x1FF; + uint64_t l3_index = (va >> 12) & 0x1FF; - kprintf_raw("Address %x is meant to be mapped to [%i][%i][%i][%i]",va, l1_index,l2_index,l3_index,l4_index); + kprintf_raw("Address %x is meant to be mapped to [%i][%i][%i][%i]",va, l0_index,l1_index,l2_index,l3_index); - if (!(page_table_l1[l1_index] & 1)) { + if (!(page_table_l0[l0_index] & 1)) { kprintf_raw("L1 Table missing"); return; } - uint64_t* l2 = (uint64_t*)(page_table_l1[l1_index] & 0xFFFFFFFFF000ULL); - if (!(l2[l2_index] & 1)) { + uint64_t* l1 = (uint64_t*)(page_table_l0[l0_index] & 0xFFFFFFFFF000ULL); + if (!(l1[l1_index] & 1)) { kprintf_raw("L2 Table missing"); return; } - uint64_t* l3 = (uint64_t*)(l2[l2_index] & 0xFFFFFFFFF000ULL); - uint64_t l3_val = l3[l3_index]; + uint64_t* l2 = (uint64_t*)(l1[l1_index] & 0xFFFFFFFFF000ULL); + uint64_t l3_val = l2[l2_index]; if (!(l3_val & 1)) { kprintf_raw("L3 Table missing"); return; @@ -274,8 +269,8 @@ void debug_mmu_address(uint64_t va){ return; } - uint64_t* l4 = (uint64_t*)(l3[l3_index] & 0xFFFFFFFFF000ULL); - uint64_t l4_val = l4[l4_index]; + uint64_t* l3 = (uint64_t*)(l2[l2_index] & 0xFFFFFFFFF000ULL); + uint64_t l4_val = l3[l3_index]; if (!(l4_val & 1)){ kprintf_raw("L4 Table entry missing"); return; From acd48f3bf2bd0da5e04a696302434c1719669082 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Tue, 15 Jul 2025 00:00:00 +0000 Subject: [PATCH 021/123] Made BootSM a pointer --- kernel/kernel_processes/boot/bootprocess.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/kernel_processes/boot/bootprocess.cpp b/kernel/kernel_processes/boot/bootprocess.cpp index 3860de55..b18528a6 100644 --- a/kernel/kernel_processes/boot/bootprocess.cpp +++ b/kernel/kernel_processes/boot/bootprocess.cpp @@ -3,15 +3,16 @@ #include "../kprocess_loader.h" #include "console/kio.h" -BootSM state_machine; +BootSM *state_machine; extern "C" __attribute__((section(".text.kcoreprocesses"))) void eval_bootscreen() { while (1){ - state_machine.eval_state(); + state_machine->eval_state(); } } extern "C" void init_bootprocess() { + state_machine = new BootSM(); create_kernel_process("bootsm",eval_bootscreen); - state_machine.initialize(); + state_machine->initialize(); } From 23ee3ff0d50db12764207b87e7af51e45c9a4cc9 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Tue, 15 Jul 2025 00:00:00 +0000 Subject: [PATCH 022/123] Using spsr for currentEL in syscalls --- kernel/process/syscall.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kernel/process/syscall.c b/kernel/process/syscall.c index 540f3e6a..20428fba 100644 --- a/kernel/process/syscall.c +++ b/kernel/process/syscall.c @@ -39,8 +39,7 @@ void sync_el0_handler_c(){ uint64_t spsr; asm volatile ("mrs %0, spsr_el1" : "=r"(spsr)); - uint64_t currentEL; - asm volatile ("mov %0, x18" : "=r"(currentEL)); + uint64_t currentEL = (spsr >> 2) & 3; uint64_t sp_el; asm volatile ("mov %0, x11" : "=r"(sp_el)); @@ -50,7 +49,6 @@ void sync_el0_handler_c(){ uint64_t ec = (esr >> 26) & 0x3F; uint64_t iss = esr & 0xFFFFFF; - uint64_t result = 0; if (ec == 0x15) { From e9c0aeb3fe26bca5cf63e2af725aea6ba12b980d Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Tue, 15 Jul 2025 00:00:00 +0000 Subject: [PATCH 023/123] input driver validity check --- kernel/input/input_dispatch.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/input/input_dispatch.cpp b/kernel/input/input_dispatch.cpp index 7f3993ec..cc28d2d2 100644 --- a/kernel/input/input_dispatch.cpp +++ b/kernel/input/input_dispatch.cpp @@ -20,7 +20,7 @@ uint16_t shortcut_count = 0; bool secure_mode = false; -USBDriver *input_driver; +USBDriver *input_driver = 0x0; void register_keypress(keypress kp) { if (!secure_mode){ @@ -88,7 +88,7 @@ bool is_new_keypress(keypress* current, keypress* previous) { } bool sys_read_input(int pid, keypress *out){ - if (BOARD_TYPE == 2) + if (BOARD_TYPE == 2 && input_driver) input_driver->poll_inputs(); process_t *process = get_proc_by_pid(pid); if (process->input_buffer.read_index == process->input_buffer.write_index) return false; From 0a0517d2a57b749998c7c3f5b9b9f3238bb5cf36 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Tue, 15 Jul 2025 00:00:00 +0000 Subject: [PATCH 024/123] Marking gpu framebuffer as reserved --- kernel/graph/drivers/videocore/videocore.cpp | 1 + kernel/memory/page_allocator.c | 22 +++++++++++++++++++- kernel/memory/page_allocator.h | 4 ++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/kernel/graph/drivers/videocore/videocore.cpp b/kernel/graph/drivers/videocore/videocore.cpp index 44c83cc2..df6e3585 100644 --- a/kernel/graph/drivers/videocore/videocore.cpp +++ b/kernel/graph/drivers/videocore/videocore.cpp @@ -64,6 +64,7 @@ bool VideoCoreGPUDriver::init(gpu_size preferred_screen_size){ page = alloc_page(0x1000, true, true, false); back_framebuffer = (uintptr_t)allocate_in_page(page, fb_size, ALIGN_16B, true, true); kprintf("Framebuffer allocated to %x. BPP %i. Stride %i",framebuffer, bpp, stride/bpp); + mark_used(framebuffer,count_pages(fb_size,PAGE_SIZE)); //TODO: Mark the fb memory as used in the page allocator manually for (size_t i = framebuffer; i < framebuffer + fb_size; i += GRANULE_4KB) register_device_memory(i,i); diff --git a/kernel/memory/page_allocator.c b/kernel/memory/page_allocator.c index be8d3325..553d52a6 100644 --- a/kernel/memory/page_allocator.c +++ b/kernel/memory/page_allocator.c @@ -13,7 +13,6 @@ #define BOOT_PUD_ATTR PD_TABLE #define PAGE_TABLE_ENTRIES 65536 -#define PAGE_SIZE 4096 uint64_t mem_bitmap[PAGE_TABLE_ENTRIES] __attribute__((aligned(PAGE_SIZE))); @@ -101,6 +100,27 @@ void* alloc_page(uint64_t size, bool kernel, bool device, bool full) { return 0; } +void mark_used(uintptr_t address, size_t pages) +{ + if ((address & (PAGE_SIZE - 1)) != 0) { + kprintf("[mark_used error] address %x not aligned", address); + return; + } + if (pages == 0) return; + + uint64_t start = count_pages(get_user_ram_start(),PAGE_SIZE); + + uint64_t page_index = (address / (PAGE_SIZE * 64)) - (start/64); + + for (size_t j = 0; j < pages; j++) { + uint64_t idx = page_index + j; + uint64_t i = idx / 64; + uint64_t bit = idx % 64; + + mem_bitmap[i] |= (1ULL << bit); + } +} + void* allocate_in_page(void *page, uint64_t size, uint16_t alignment, bool kernel, bool device){ size = (size + alignment - 1) & ~(alignment - 1); diff --git a/kernel/memory/page_allocator.h b/kernel/memory/page_allocator.h index 37bb79e3..7e6f93e3 100644 --- a/kernel/memory/page_allocator.h +++ b/kernel/memory/page_allocator.h @@ -6,6 +6,7 @@ #define ALIGN_4KB 0x1000 #define ALIGN_16B 0x10 #define ALIGN_64B 0x40 +#define PAGE_SIZE 4096 void page_alloc_enable_verbose(); void page_allocator_init(); @@ -15,10 +16,13 @@ extern "C" { #endif void* alloc_page(uint64_t size, bool kernel, bool device, bool full); void free_page(void* ptr, uint64_t size); +void mark_used(uintptr_t address, size_t pages); void* allocate_in_page(void *page, uint64_t size, uint16_t alignment, bool kernel, bool device); void free_from_page(void* ptr, uint64_t size); +int count_pages(uint64_t i1,uint64_t i2); + void free_sized(sizedptr ptr); #ifdef __cplusplus From daf5f9c5b2fdf271357e14f9c75848dbd5364808 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Tue, 15 Jul 2025 00:00:00 +0000 Subject: [PATCH 025/123] Made clear use a normal drawing as opposed to the 32bit version to avoid possible bpp issues --- kernel/graph/drivers/videocore/videocore.cpp | 6 ++++-- shared/ui/draw/draw.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/graph/drivers/videocore/videocore.cpp b/kernel/graph/drivers/videocore/videocore.cpp index df6e3585..6800a021 100644 --- a/kernel/graph/drivers/videocore/videocore.cpp +++ b/kernel/graph/drivers/videocore/videocore.cpp @@ -13,6 +13,8 @@ #define RGB_FORMAT_XRGB8888 ((uint32_t)('X') | ((uint32_t)('R') << 8) | ((uint32_t)('2') << 16) | ((uint32_t)('4') << 24)) +#define BUS_ADDRESS(addr) ((addr) & ~0xC0000000) + VideoCoreGPUDriver* VideoCoreGPUDriver::try_init(gpu_size preferred_screen_size){ VideoCoreGPUDriver* driver = new VideoCoreGPUDriver(); if (driver->init(preferred_screen_size)) @@ -59,11 +61,11 @@ bool VideoCoreGPUDriver::init(gpu_size preferred_screen_size){ kprintf("Error"); return false; } - framebuffer = fb_mbox[5]; + framebuffer = BUS_ADDRESS(fb_mbox[5]); size_t fb_size = fb_mbox[6]; page = alloc_page(0x1000, true, true, false); back_framebuffer = (uintptr_t)allocate_in_page(page, fb_size, ALIGN_16B, true, true); - kprintf("Framebuffer allocated to %x. BPP %i. Stride %i",framebuffer, bpp, stride/bpp); + kprintf("Framebuffer allocated to %x (%i). BPP %i. Stride %i",framebuffer, fb_size, bpp, stride/bpp); mark_used(framebuffer,count_pages(fb_size,PAGE_SIZE)); //TODO: Mark the fb memory as used in the page allocator manually for (size_t i = framebuffer; i < framebuffer + fb_size; i += GRANULE_4KB) diff --git a/shared/ui/draw/draw.c b/shared/ui/draw/draw.c index eb0680b2..a0ab4c1e 100644 --- a/shared/ui/draw/draw.c +++ b/shared/ui/draw/draw.c @@ -61,8 +61,10 @@ void mark_dirty(uint32_t x, uint32_t y, uint32_t w, uint32_t h) { } void fb_clear(uint32_t* fb, uint32_t color) { - for (uint32_t i = 0; i < max_width * max_height; i++) { - fb[i] = color; + for (uint32_t y = 0; y < max_height; y++){ + for (uint32_t x = 0; x < max_width; x++){ + fb[y * (stride / 4) + x] = color; + } } full_redraw = true; } From 6f2597d38d024ab76e10818b3818abfe1aebae5c Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Tue, 15 Jul 2025 00:00:00 +0000 Subject: [PATCH 026/123] Only overwrite x0 in syscall when there's a value to write, save sp before anything else in syscall early context-switch --- kernel/process/syscall.c | 3 ++- kernel/process/syscall_as.S | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/kernel/process/syscall.c b/kernel/process/syscall.c index 20428fba..a8e03ab6 100644 --- a/kernel/process/syscall.c +++ b/kernel/process/syscall.c @@ -165,7 +165,8 @@ void sync_el0_handler_c(){ stop_current_process(); } } - save_syscall_return(result); + if (result > 0) + save_syscall_return(result); process_restore(); } diff --git a/kernel/process/syscall_as.S b/kernel/process/syscall_as.S index e133a3b8..34fd59b2 100644 --- a/kernel/process/syscall_as.S +++ b/kernel/process/syscall_as.S @@ -2,13 +2,6 @@ //TODO: Rethink the registers used to be sequential both here and in context_switch and exception_vectors_as sync_el0_handler_as: - msr daifset, #2//Disable interrupts - mov x15, x0 - mov x14, x1 - mov x9, x2 - mov x16, x3 - mov x13, x29 - mov x12, x30 mrs x10, spsr_el1 lsr x18, x10, #2 and x18, x18, #0b11 @@ -26,5 +19,12 @@ sync_el0_handler_as: 2: mrs x11, sp_el0 3: + msr daifset, #2//Disable interrupts + mov x15, x0 + mov x14, x1 + mov x9, x2 + mov x16, x3 + mov x13, x29 + mov x12, x30 b sync_el0_handler_c eret \ No newline at end of file From 3d139c652ebfa9b1eac1f4751f6ed641f0ff73db Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Wed, 16 Jul 2025 00:00:00 +0000 Subject: [PATCH 027/123] extra safety check in bootsm --- kernel/kernel_processes/boot/bootprocess_sm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/kernel_processes/boot/bootprocess_sm.cpp b/kernel/kernel_processes/boot/bootprocess_sm.cpp index 761f337e..6a590036 100644 --- a/kernel/kernel_processes/boot/bootprocess_sm.cpp +++ b/kernel/kernel_processes/boot/bootprocess_sm.cpp @@ -13,7 +13,7 @@ void BootSM::initialize(){ } BootSM::BootStates BootSM::eval_state(){ - if (current_proc->state == process_t::process_state::STOPPED) + if (!current_proc || current_proc->state == process_t::process_state::STOPPED) AdvanceToState(GetNextState()); return current_state; From c12b7f42e926af0c20f765de5cd77763f9055d7f Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Wed, 16 Jul 2025 00:00:00 +0000 Subject: [PATCH 028/123] cleaned up videocore code --- kernel/graph/drivers/videocore/videocore.cpp | 93 +++++++++++--------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/kernel/graph/drivers/videocore/videocore.cpp b/kernel/graph/drivers/videocore/videocore.cpp index 6800a021..2989bc4a 100644 --- a/kernel/graph/drivers/videocore/videocore.cpp +++ b/kernel/graph/drivers/videocore/videocore.cpp @@ -23,56 +23,61 @@ VideoCoreGPUDriver* VideoCoreGPUDriver::try_init(gpu_size preferred_screen_size) return nullptr; } -volatile uint32_t rmbox[36] __attribute__((aligned(16))) = { - 25 * 4,// Buf size +#define VC_BASE 0x40000 +#define VC_FRAMEBUFFER_TAG (VC_BASE + 0x1) +#define VC_PHYS_SIZE_TAG (VC_BASE + 0x3) +#define VC_VIRT_SIZE_TAG (VC_BASE + 0x4) +#define VC_DEPTH_TAG (VC_BASE + 0x5) +#define VC_FORMAT_TAG (VC_BASE + 0x6) +#define VC_ALPHA_TAG (VC_BASE + 0x7) +#define VC_PITCH_TAG (VC_BASE + 0x8) +#define VC_OFFSET_TAG (VC_BASE + 0x9) + +#define VC_SET_VALUE 0x8000 + +volatile uint32_t rmbox[40] __attribute__((aligned(16))) = { + 30 * 4,// Buf size 0,// Request. Code 0 - 0x00048003, 8, 0, 640, 480,// Physical size - 0x00048004, 8, 0, 0, 0,// Virtual size - 0x00048005, 4, 0, 32,// Depth - 0x00040008, 4, 0, 0,//Pitch - 0x00048006, 4, 0, 0, //BGR + VC_PHYS_SIZE_TAG | VC_SET_VALUE, 8, 0, 640, 480,// Physical size + VC_VIRT_SIZE_TAG, 8, 0, 640, 480,// Virtual size + VC_DEPTH_TAG | VC_SET_VALUE, 4, 4, 32,// Depth + VC_PITCH_TAG, 4, 0, 0,//Pitch + VC_FORMAT_TAG | VC_SET_VALUE, 4, 0, 0, //BGR + VC_FRAMEBUFFER_TAG, 8, 0, 16, 0, 0,// End -};//TODO: Screen resolution seems fixed at 640x480 (on QEMU at least). Setting it to anything else hangs the system - -volatile uint32_t fb_mbox[36] __attribute__((aligned(16))) = { - 32, 0, - 0x00040001, 8, 0, 16, 0, - 0 }; bool VideoCoreGPUDriver::init(gpu_size preferred_screen_size){ kprintf("Initializing VideoCore GPU"); - if (mailbox_call(rmbox, 8)) { - uint32_t phys_w = rmbox[5]; - uint32_t phys_h = rmbox[6]; - uint32_t virt_w = rmbox[10]; - uint32_t virt_h = rmbox[11]; - uint32_t depth = rmbox[15]; - stride = rmbox[19]; - - bpp = depth/8; - - screen_size = (gpu_size){phys_w,phys_h}; - kprintf("Size %ix%i (%ix%i) (%ix%i) | %i (%i)",phys_w,phys_h,virt_w,virt_h,screen_size.width,screen_size.height,depth, stride); - - fb_set_stride(bpp * screen_size.width); - fb_set_bounds(screen_size.width,screen_size.height); - if (!mailbox_call(fb_mbox, 8)){ - kprintf("Error"); - return false; - } - framebuffer = BUS_ADDRESS(fb_mbox[5]); - size_t fb_size = fb_mbox[6]; - page = alloc_page(0x1000, true, true, false); - back_framebuffer = (uintptr_t)allocate_in_page(page, fb_size, ALIGN_16B, true, true); - kprintf("Framebuffer allocated to %x (%i). BPP %i. Stride %i",framebuffer, fb_size, bpp, stride/bpp); - mark_used(framebuffer,count_pages(fb_size,PAGE_SIZE)); - //TODO: Mark the fb memory as used in the page allocator manually - for (size_t i = framebuffer; i < framebuffer + fb_size; i += GRANULE_4KB) - register_device_memory(i,i); - return true; + + if (!mailbox_call(rmbox, 8)) { + kprintf("Failed videocore setup"); + return false; } - return false; + uint32_t phys_w = rmbox[5]; + uint32_t phys_h = rmbox[6]; + uint32_t virt_w = rmbox[10]; + uint32_t virt_h = rmbox[11]; + uint32_t depth = rmbox[15]; + stride = rmbox[19]; + + bpp = depth/8; + + screen_size = (gpu_size){phys_w,phys_h}; + kprintf("Size %ix%i (%ix%i) (%ix%i) | %i (%i)",phys_w,phys_h,virt_w,virt_h,screen_size.width,screen_size.height,depth, stride); + + fb_set_stride(stride); + fb_set_bounds(screen_size.width,screen_size.height); + + framebuffer = rmbox[27]; + size_t fb_size = rmbox[28]; + page = alloc_page(0x1000, true, true, false); + back_framebuffer = (uintptr_t)allocate_in_page(page, fb_size, ALIGN_16B, true, true); + kprintf("Framebuffer allocated to %x (%i). BPP %i. Stride %i",framebuffer, fb_size, bpp, stride/bpp); + mark_used(framebuffer,count_pages(fb_size,PAGE_SIZE)); + for (size_t i = framebuffer; i < framebuffer + fb_size; i += GRANULE_4KB) + register_device_memory(i,i); + return true; } void VideoCoreGPUDriver::flush(){ @@ -139,4 +144,4 @@ void VideoCoreGPUDriver::draw_string(string s, uint32_t x, uint32_t y, uint32_t uint32_t VideoCoreGPUDriver::get_char_size(uint32_t scale){ return fb_get_char_size(max(1,scale-1));//TODO: Screen resolution seems fixed at 640x480 (on QEMU at least). So we make the font smaller -} \ No newline at end of file +} From 06003011ad12c081f77abe64b9c5170d63fbefd6 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Wed, 16 Jul 2025 00:00:00 +0000 Subject: [PATCH 029/123] Tag fixes --- kernel/graph/drivers/videocore/videocore.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/graph/drivers/videocore/videocore.cpp b/kernel/graph/drivers/videocore/videocore.cpp index 2989bc4a..80f86bcc 100644 --- a/kernel/graph/drivers/videocore/videocore.cpp +++ b/kernel/graph/drivers/videocore/videocore.cpp @@ -38,11 +38,11 @@ VideoCoreGPUDriver* VideoCoreGPUDriver::try_init(gpu_size preferred_screen_size) volatile uint32_t rmbox[40] __attribute__((aligned(16))) = { 30 * 4,// Buf size 0,// Request. Code 0 - VC_PHYS_SIZE_TAG | VC_SET_VALUE, 8, 0, 640, 480,// Physical size - VC_VIRT_SIZE_TAG, 8, 0, 640, 480,// Virtual size + VC_PHYS_SIZE_TAG, 8, 0, 0, 0,// Physical size + VC_VIRT_SIZE_TAG, 8, 0, 0, 0,// Virtual size VC_DEPTH_TAG | VC_SET_VALUE, 4, 4, 32,// Depth VC_PITCH_TAG, 4, 0, 0,//Pitch - VC_FORMAT_TAG | VC_SET_VALUE, 4, 0, 0, //BGR + VC_FORMAT_TAG | VC_SET_VALUE, 4, 4, 0, //BGR VC_FRAMEBUFFER_TAG, 8, 0, 16, 0, 0,// End }; From 0db48a6c39170821a224be64368195d4c28b7646 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Wed, 16 Jul 2025 00:00:00 +0000 Subject: [PATCH 030/123] Color fixes --- kernel/kernel_processes/boot/bootscreen.c | 4 ++-- kernel/theme/RedactedOS.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/kernel_processes/boot/bootscreen.c b/kernel/kernel_processes/boot/bootscreen.c index fd648315..7d81a385 100644 --- a/kernel/kernel_processes/boot/bootscreen.c +++ b/kernel/kernel_processes/boot/bootscreen.c @@ -21,7 +21,7 @@ void boot_draw_name(gpu_point screen_middle,int xoffset, int yoffset){ int xo = screen_middle.x - mid_offset + xoffset; int yo = screen_middle.y + yoffset; gpu_fill_rect((gpu_rect){{xo,yo}, {char_size * (s.length/BOOTSCREEN_NUM_LINES), char_size * BOOTSCREEN_NUM_LINES}},BG_COLOR); - gpu_draw_string(s, (gpu_point){xo, yo}, scale, 0xFFFFFF); + gpu_draw_string(s, (gpu_point){xo, yo}, scale, 0xFFFFFFFF); free(s.data,s.mem_length); } @@ -76,7 +76,7 @@ void boot_draw_lines(gpu_point current_point, gpu_point next_point, gpu_size siz lerp(i, ccurrent.x, cnext.x, csteps), lerp(i, ccurrent.y, cnext.y, csteps) }; - gpu_draw_pixel(interpolated, 0xFFFFFF); + gpu_draw_pixel(interpolated, 0xFFFFFFFF); } } keypress kp; diff --git a/kernel/theme/RedactedOS.h b/kernel/theme/RedactedOS.h index 86f77718..1da14ffb 100644 --- a/kernel/theme/RedactedOS.h +++ b/kernel/theme/RedactedOS.h @@ -30,6 +30,6 @@ #define PANIC_TEXT "FATAL ERROR" -#define BG_COLOR 0x222233 +#define BG_COLOR 0xFF222233 #define default_pwd "hi" \ No newline at end of file From 8a7e19ddbf1949c4e20be63a0e19f0ec2bd7b084 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Thu, 17 Jul 2025 00:00:00 +0000 Subject: [PATCH 031/123] all mailbox calls use defined tags & fixed error screen colors --- kernel/console/serial/uart.c | 2 +- kernel/exceptions/exception_handler.c | 4 ++-- kernel/filesystem/sdhci.cpp | 2 +- kernel/graph/drivers/videocore/videocore.cpp | 24 +++++--------------- kernel/mailbox/mailbox.h | 14 ++++++++++++ 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/kernel/console/serial/uart.c b/kernel/console/serial/uart.c index 279a796b..cfa0e817 100644 --- a/kernel/console/serial/uart.c +++ b/kernel/console/serial/uart.c @@ -17,7 +17,7 @@ uint64_t get_uart_base(){ } volatile uint32_t uart_mbox[9] __attribute__((aligned(16))) = { - 36, 0, 0x30002, 12, 8, 2, 0, 0, 0 + 36, 0, MBOX_CLKRATE_TAG, 12, 8, 2, 0, 0, 0 }; void enable_uart() { diff --git a/kernel/exceptions/exception_handler.c b/kernel/exceptions/exception_handler.c index 945e286b..95fad8ea 100644 --- a/kernel/exceptions/exception_handler.c +++ b/kernel/exceptions/exception_handler.c @@ -45,9 +45,9 @@ void fiq_el1_handler(){ handle_exception("FIQ EXCEPTION\r\n"); } void error_el1_handler(){ handle_exception("ERROR EXCEPTION\r\n"); } void draw_panic_screen(kstring s){ - gpu_clear(0x0000FF); + gpu_clear(0xFF0000FF); uint32_t scale = 3; - gpu_draw_string(*(string *)&s, (gpu_point){20,20}, scale, 0xFFFFFF); + gpu_draw_string(*(string *)&s, (gpu_point){20,20}, scale, 0xFFFFFFFF); gpu_flush(); } diff --git a/kernel/filesystem/sdhci.cpp b/kernel/filesystem/sdhci.cpp index 917196ca..34fb1c80 100644 --- a/kernel/filesystem/sdhci.cpp +++ b/kernel/filesystem/sdhci.cpp @@ -105,7 +105,7 @@ bool SDHCI::switch_clock_rate(uint32_t target_rate) { volatile uint32_t mbox[8] __attribute__((aligned(16))) = { 32, 0, - 0x00030002, 8, 0, 1, 0,//Request clock rate for 1 (EMMC) + MBOX_CLKRATE_TAG, 8, 0, 1, 0,//Request clock rate for 1 (EMMC) 0 }; diff --git a/kernel/graph/drivers/videocore/videocore.cpp b/kernel/graph/drivers/videocore/videocore.cpp index 80f86bcc..77bc5d01 100644 --- a/kernel/graph/drivers/videocore/videocore.cpp +++ b/kernel/graph/drivers/videocore/videocore.cpp @@ -23,27 +23,15 @@ VideoCoreGPUDriver* VideoCoreGPUDriver::try_init(gpu_size preferred_screen_size) return nullptr; } -#define VC_BASE 0x40000 -#define VC_FRAMEBUFFER_TAG (VC_BASE + 0x1) -#define VC_PHYS_SIZE_TAG (VC_BASE + 0x3) -#define VC_VIRT_SIZE_TAG (VC_BASE + 0x4) -#define VC_DEPTH_TAG (VC_BASE + 0x5) -#define VC_FORMAT_TAG (VC_BASE + 0x6) -#define VC_ALPHA_TAG (VC_BASE + 0x7) -#define VC_PITCH_TAG (VC_BASE + 0x8) -#define VC_OFFSET_TAG (VC_BASE + 0x9) - -#define VC_SET_VALUE 0x8000 - volatile uint32_t rmbox[40] __attribute__((aligned(16))) = { 30 * 4,// Buf size 0,// Request. Code 0 - VC_PHYS_SIZE_TAG, 8, 0, 0, 0,// Physical size - VC_VIRT_SIZE_TAG, 8, 0, 0, 0,// Virtual size - VC_DEPTH_TAG | VC_SET_VALUE, 4, 4, 32,// Depth - VC_PITCH_TAG, 4, 0, 0,//Pitch - VC_FORMAT_TAG | VC_SET_VALUE, 4, 4, 0, //BGR - VC_FRAMEBUFFER_TAG, 8, 0, 16, 0, + MBOX_VC_PHYS_SIZE_TAG, 8, 0, 0, 0,// Physical size + MBOX_VC_VIRT_SIZE_TAG, 8, 0, 0, 0,// Virtual size + MBOX_VC_DEPTH_TAG | MBOX_SET_VALUE, 4, 4, 32,// Depth + MBOX_VC_PITCH_TAG, 4, 0, 0,//Pitch + MBOX_VC_FORMAT_TAG | MBOX_SET_VALUE, 4, 4, 0, //BGR + MBOX_VC_FRAMEBUFFER_TAG, 8, 0, 16, 0, 0,// End }; diff --git a/kernel/mailbox/mailbox.h b/kernel/mailbox/mailbox.h index 025f4094..ccf7924e 100644 --- a/kernel/mailbox/mailbox.h +++ b/kernel/mailbox/mailbox.h @@ -10,6 +10,20 @@ #define MBOX_FULL 0x80000000 #define MBOX_EMPTY 0x40000000 +#define MBOX_VC_BASE 0x40000 +#define MBOX_VC_FRAMEBUFFER_TAG (MBOX_VC_BASE + 0x1) +#define MBOX_VC_PHYS_SIZE_TAG (MBOX_VC_BASE + 0x3) +#define MBOX_VC_VIRT_SIZE_TAG (MBOX_VC_BASE + 0x4) +#define MBOX_VC_DEPTH_TAG (MBOX_VC_BASE + 0x5) +#define MBOX_VC_FORMAT_TAG (MBOX_VC_BASE + 0x6) +#define MBOX_VC_ALPHA_TAG (MBOX_VC_BASE + 0x7) +#define MBOX_VC_PITCH_TAG (MBOX_VC_BASE + 0x8) +#define MBOX_VC_OFFSET_TAG (MBOX_VC_BASE + 0x9) + +#define MBOX_CLKRATE_TAG 0x30002 + +#define MBOX_SET_VALUE 0x8000 + #ifdef __cplusplus extern "C" { #endif From 12efe76e753fa051b199915436ead3fe9b8a5a2f Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Thu, 17 Jul 2025 00:00:00 +0000 Subject: [PATCH 032/123] Moved more peripherals to PI5 switch --- kernel/hw/hw.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kernel/hw/hw.c b/kernel/hw/hw.c index 2dc44e30..7a42f20e 100644 --- a/kernel/hw/hw.c +++ b/kernel/hw/hw.c @@ -49,6 +49,9 @@ void detect_hardware(){ RPI_BOARD = 5; GICD_BASE = MMIO_BASE + 0x3FF9000; GICC_BASE = MMIO_BASE + 0x3FFA000; + MAILBOX_BASE = MMIO_BASE + 0x13880; + SDHCI_BASE = 0x1000FFF000UL; + UART0_BASE = MMIO_BASE + 0x1001000; break; default: RPI_BOARD = 3; @@ -56,11 +59,7 @@ void detect_hardware(){ GICD_BASE = MMIO_BASE + 0xB200; break; } - if (RPI_BOARD == 5){ - MAILBOX_BASE = MMIO_BASE + 0x13880; - SDHCI_BASE = 0x1000FFF000UL; - UART0_BASE = MMIO_BASE + 0x1001000; - } else { + if (RPI_BOARD != 5){ GPIO_BASE = MMIO_BASE + 0x200000; MAILBOX_BASE = MMIO_BASE + 0xB880; UART0_BASE = MMIO_BASE + 0x201000; From 5d047b15b9ae1daf894d2589cd9f19c9186dd9e5 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Thu, 17 Jul 2025 00:00:00 +0000 Subject: [PATCH 033/123] v2 sd card fix --- kernel/filesystem/sdhci.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/filesystem/sdhci.cpp b/kernel/filesystem/sdhci.cpp index 34fb1c80..3c72d6b9 100644 --- a/kernel/filesystem/sdhci.cpp +++ b/kernel/filesystem/sdhci.cpp @@ -152,7 +152,7 @@ bool SDHCI::init() { setup_clock(); - kprintf("[SDHCI] Controller ready"); + kprintf("[SDHCI] Controller ready CTL0 %x",regs->ctrl0); regs->interrupt = 0; regs->irpt_en = 0xFFFFFFFF; @@ -169,14 +169,14 @@ bool SDHCI::init() { switch_clock_rate(25000000); bool v2_card = 0; - if (!issue_command(IF_COND, 0)){ + if (!issue_command(IF_COND, 0x1AA)){ if (!(regs->interrupt & 0x10000)){ kprintf("[SDHCI error] IFCOND error"); return false; } kprintfv("[SDHCI] Timeout on IFCOND. Defaulting to V1"); } else { - if ((regs->resp0 & 0xFF) != 0xAA) { + if ((regs->resp0 & 0xFFF) != 0x1AA) { kprintf("[SDHCI error] IFCOND pattern mismatch"); return false; } From 8ebf0ca1cbb8dab961f51efecc7b6909bb47f30e Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Thu, 17 Jul 2025 00:00:00 +0000 Subject: [PATCH 034/123] Added uint32max --- shared/types.h | 1 + 1 file changed, 1 insertion(+) diff --git a/shared/types.h b/shared/types.h index 0b6dc865..a787599d 100644 --- a/shared/types.h +++ b/shared/types.h @@ -19,6 +19,7 @@ typedef unsigned char uint8_t; #define UINT64_MAX 0xFFFFFFFFFFFFFFFFULL #define UINT16_MAX 0xFFFF +#define UINT32_MAX 0xFFFFFFFF typedef int int32_t; typedef long int64_t; From 6f19ff33c2d2be1b0280dc46fb6016927617e8b3 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Thu, 17 Jul 2025 00:00:00 +0000 Subject: [PATCH 035/123] read 32 bit memory unaligned, mbr support for fat32 --- kernel/filesystem/disk.cpp | 12 +++-- kernel/filesystem/fat32.cpp | 94 +++++++++++++++++++---------------- kernel/filesystem/fat32.hpp | 3 +- kernel/filesystem/mbr.c | 27 ++++++++++ kernel/filesystem/mbr.h | 29 +++++++++++ kernel/filesystem/sdhci.cpp | 4 +- kernel/hw/hw.c | 13 ++--- kernel/memory/memory_access.c | 8 +++ kernel/memory/memory_access.h | 13 ++++- 9 files changed, 145 insertions(+), 58 deletions(-) create mode 100644 kernel/filesystem/mbr.c create mode 100644 kernel/filesystem/mbr.h diff --git a/kernel/filesystem/disk.cpp b/kernel/filesystem/disk.cpp index 39ba9067..232a3b4f 100644 --- a/kernel/filesystem/disk.cpp +++ b/kernel/filesystem/disk.cpp @@ -4,10 +4,12 @@ #include "virtio_blk_pci.h" #include "sdhci.hpp" #include "hw/hw.h" +#include "console/kio.h" +#include "mbr.h" static bool disk_enable_verbose; SDHCI sdhci_driver; -FAT32FS fs_driver; +FAT32FS *fs_driver; void disk_verbose(){ disk_enable_verbose = true; @@ -34,7 +36,9 @@ bool find_disk(){ } bool disk_init(){ - return fs_driver.init(); + uint32_t f32_partition = mbr_find_partition(0xC); + fs_driver = new FAT32FS(); + return fs_driver->init(f32_partition); } void disk_write(const void *buffer, uint32_t sector, uint32_t count){ @@ -49,9 +53,9 @@ void disk_read(void *buffer, uint32_t sector, uint32_t count){ } void* read_file(char *path){ - return fs_driver.read_file(path); + return fs_driver->read_file(path); } string_list* list_directory_contents(char *path){ - return fs_driver.list_contents(path); + return fs_driver->list_contents(path); } \ No newline at end of file diff --git a/kernel/filesystem/fat32.cpp b/kernel/filesystem/fat32.cpp index b51264c3..0eeaac57 100644 --- a/kernel/filesystem/fat32.cpp +++ b/kernel/filesystem/fat32.cpp @@ -2,6 +2,7 @@ #include "disk.h" #include "memory/page_allocator.h" #include "console/kio.h" +#include "memory/memory_access.h" #include "std/string.h" #include "std/memfunctions.h" #include "math/math.h" @@ -21,6 +22,53 @@ char* FAT32FS::advance_path(char *path){ return path; } +#define MBS_NUM_SECTORS read_unaligned16(mbs8 + 0x13) + +bool FAT32FS::init(uint32_t partition_sector){ + fs_page = alloc_page(0x1000, true, true, false); + + mbs = (fat32_mbs*)allocate_in_page(fs_page, 512, ALIGN_64B, true, true); + + partition_first_sector = partition_sector; + + disk_read((void*)mbs, partition_first_sector, 1); + + kprintf("[fat32] Reading fat32 mbs at %x. %x",partition_first_sector, mbs->jumpboot[0]); + + if (mbs->boot_signature != 0xAA55){ + kprintf("[fat32] Wrong boot signature %x",mbs->boot_signature); + uint8_t *bytes = ((uint8_t*)mbs); + for (int i = 0; i < 512; i++){ + uint64_t _args[] = { bytes[i] }; \ + kputf_args_raw("%x",_args,1); + } + kprintf("Failed to read"); + return false; + } + if (mbs->signature != 0x29 && mbs->signature != 0x28){ + kprintf("[fat32 error] Wrong signature %x",mbs->signature); + return false; + } + + uint8_t *mbs8 = (uint8_t*)mbs; + + cluster_count = (MBS_NUM_SECTORS == 0 ? mbs->large_num_sectors : MBS_NUM_SECTORS)/mbs->sectors_per_cluster; + data_start_sector = mbs->reserved_sectors + (mbs->sectors_per_fat * mbs->number_of_fats); + + if (mbs->first_cluster_of_root_directory > cluster_count){ + kprintf("[fat32 error] root directory cluster not found"); + return false; + } + + bytes_per_sector = read_unaligned16(mbs8 + 0xB); + + kprintf("FAT32 Volume uses %i cluster size", bytes_per_sector); + kprintf("Data start at %x",data_start_sector*512); + + read_FAT(mbs->reserved_sectors, mbs->sectors_per_fat, mbs->number_of_fats); + + return true;} + void* FAT32FS::read_cluster(uint32_t cluster_start, uint32_t cluster_size, uint32_t cluster_count, uint32_t root_index){ uint32_t lba = cluster_start + ((root_index - 2) * cluster_size); @@ -33,7 +81,7 @@ void* FAT32FS::read_cluster(uint32_t cluster_start, uint32_t cluster_size, uint3 uint32_t next_index = root_index; for (int i = 0; i < cluster_count; i++){ kprintfv("Cluster %i = %x (%x)",i,next_index,(cluster_start + ((next_index - 2) * cluster_size)) * 512); - disk_read(buffer + (i * cluster_size * 512), cluster_start + ((next_index - 2) * cluster_size), cluster_size); + disk_read(buffer + (i * cluster_size * 512), partition_first_sector + cluster_start + ((next_index - 2) * cluster_size), cluster_size); next_index = fat[next_index]; if (next_index >= 0x0FFFFFF8) return buffer; } @@ -177,7 +225,7 @@ void* FAT32FS::read_full_file(uint32_t cluster_start, uint32_t cluster_size, uin void FAT32FS::read_FAT(uint32_t location, uint32_t size, uint8_t count){ fat = (uint32_t*)allocate_in_page(fs_page, size * count * 512, ALIGN_64B, true, true); - disk_read((void*)fat, location, size); + disk_read((void*)fat, partition_first_sector + location, size); total_fat_entries = (size * count * 512) / 4; } @@ -191,48 +239,6 @@ uint32_t FAT32FS::count_FAT(uint32_t first){ return count; } -uint16_t read_unaligned16(const uint8_t *p) { - return (uint16_t)p[0] | ((uint16_t)p[1] << 8); -} - -#define MBS_NUM_SECTORS read_unaligned16(mbs8 + 0x13) - -bool FAT32FS::init(){ - fs_page = alloc_page(0x1000, true, true, false); - - mbs = (fat32_mbs*)allocate_in_page(fs_page, 512, ALIGN_64B, true, true); - - disk_read((void*)mbs, 0, 1); - - if (mbs->boot_signature != 0xAA55){ - kprintf("[fat32] Wrong boot signature %x",mbs->boot_signature); - return false; - } - if (mbs->signature != 0x29 && mbs->signature != 0x28){ - kprintf("[fat32 error] Wrong signature %x",mbs->signature); - return false; - } - - uint8_t *mbs8 = (uint8_t*)mbs; - - cluster_count = (MBS_NUM_SECTORS == 0 ? mbs->large_num_sectors : MBS_NUM_SECTORS)/mbs->sectors_per_cluster; - data_start_sector = mbs->reserved_sectors + (mbs->sectors_per_fat * mbs->number_of_fats); - - if (mbs->first_cluster_of_root_directory > cluster_count){ - kprintf("[fat32 error] root directory cluster not found"); - return false; - } - - bytes_per_sector = read_unaligned16(mbs8 + 0xB); - - kprintf("FAT32 Volume uses %i cluster size", bytes_per_sector); - kprintf("Data start at %x",data_start_sector*512); - - read_FAT(mbs->reserved_sectors, mbs->sectors_per_fat, mbs->number_of_fats); - - return true; -} - void* FAT32FS::read_entry_handler(FAT32FS *instance, f32file_entry *entry, char *filename, char *seek) { if (entry->flags.volume_id) return 0; diff --git a/kernel/filesystem/fat32.hpp b/kernel/filesystem/fat32.hpp index b142535e..e2aa7af8 100644 --- a/kernel/filesystem/fat32.hpp +++ b/kernel/filesystem/fat32.hpp @@ -79,7 +79,7 @@ typedef void* (*f32_entry_handler)(FAT32FS *instance, f32file_entry*, char *file class FAT32FS { public: - bool init(); + bool init(uint32_t partition_sector); void* read_file(char *path); string_list* list_contents(char *path); @@ -99,6 +99,7 @@ class FAT32FS { uint32_t* fat; uint32_t total_fat_entries; uint16_t bytes_per_sector; + uint32_t partition_first_sector; static void* read_entry_handler(FAT32FS *instance, f32file_entry *entry, char *filename, char *seek); static void* list_entries_handler(FAT32FS *instance, f32file_entry *entry, char *filename, char *seek); diff --git a/kernel/filesystem/mbr.c b/kernel/filesystem/mbr.c new file mode 100644 index 00000000..ee2c96da --- /dev/null +++ b/kernel/filesystem/mbr.c @@ -0,0 +1,27 @@ +#include "mbr.h" +#include "memory/page_allocator.h" +#include "memory/memory_access.h" +#include "disk.h" +#include "console/kio.h" + +void* mbr_page; + +uint32_t mbr_find_partition(uint8_t partition_type){ + mbr_page = alloc_page(0x1000, true, true, false); + + mbr *mbr_entry = (mbr*)allocate_in_page(mbr_page, 512, ALIGN_64B, true, true); + + disk_read((void*)mbr_entry, 0, 1); + + uint32_t offset = 0; + + for (uint8_t i = 0; i < 4; i++){ + partition_entry *entry = &mbr_entry->partitions[i]; + kprintf("MBR Partition %i = %x -> %x",i, entry->type, read_unaligned32((uint8_t*)&entry->first_sector)); + if (entry->type == partition_type){ + offset = read_unaligned32((uint8_t*)&entry->first_sector); + } + } + + return offset; +} \ No newline at end of file diff --git a/kernel/filesystem/mbr.h b/kernel/filesystem/mbr.h new file mode 100644 index 00000000..68c26cab --- /dev/null +++ b/kernel/filesystem/mbr.h @@ -0,0 +1,29 @@ +#pragma once + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct partition_entry +{ + uint8_t status; + uint8_t first_sector_chs[3]; + uint8_t type; + uint8_t last_sector_chs[3]; + uint32_t first_sector; + uint32_t num_sectors; +}__attribute__((packed)) partition_entry; + +typedef struct mbr { + uint8_t bootstrap[0x1BE]; + partition_entry partitions[4]; + uint16_t signature; +}__attribute__((packed, aligned(1))) mbr; + +uint32_t mbr_find_partition(uint8_t partition_type); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/kernel/filesystem/sdhci.cpp b/kernel/filesystem/sdhci.cpp index 3c72d6b9..9f9ab674 100644 --- a/kernel/filesystem/sdhci.cpp +++ b/kernel/filesystem/sdhci.cpp @@ -264,8 +264,8 @@ bool SDHCI::read(void *buffer, uint32_t sector, uint32_t count){ uint32_t command = multiple ? READ_MULTIPLE : READ_ONE; uint32_t flags = multiple ? 0b110110 : 0b010000; for (int i = 5; i >= 0; i--){ - //TODO: Byte addressing works here, instead of block addressing. Not sure that's normal or if it's card-specific - if (issue_command(command, sector * 512, flags)) break; + //TODO: This is now broken on qemu. On QEMU, we need to multiply sector by 512 + if (issue_command(command, sector, flags)) break; if (i == 0) { kprintf("[SDHCI error] read request timeout"); return false; } delay(500); } diff --git a/kernel/hw/hw.c b/kernel/hw/hw.c index 7a42f20e..6055b2fc 100644 --- a/kernel/hw/hw.c +++ b/kernel/hw/hw.c @@ -47,11 +47,12 @@ void detect_hardware(){ case 0xD0B: //5. Cortex A76 MMIO_BASE = 0x107C000000UL; RPI_BOARD = 5; - GICD_BASE = MMIO_BASE + 0x3FF9000; - GICC_BASE = MMIO_BASE + 0x3FFA000; - MAILBOX_BASE = MMIO_BASE + 0x13880; - SDHCI_BASE = 0x1000FFF000UL; - UART0_BASE = MMIO_BASE + 0x1001000; + GICD_BASE = MMIO_BASE + 0x3FF9000; + GICC_BASE = MMIO_BASE + 0x3FFA000; + MAILBOX_BASE = MMIO_BASE + 0x13880; + SDHCI_BASE = MMIO_BASE + 0xFFF000UL; + UART0_BASE = MMIO_BASE + 0x1001000; + XHCI_BASE = 0x1000300000UL; break; default: RPI_BOARD = 3; @@ -64,9 +65,9 @@ void detect_hardware(){ MAILBOX_BASE = MMIO_BASE + 0xB880; UART0_BASE = MMIO_BASE + 0x201000; SDHCI_BASE = MMIO_BASE + 0x300000; + XHCI_BASE = MMIO_BASE + 0x9C0000; } DWC2_BASE = MMIO_BASE + 0x980000; - XHCI_BASE = MMIO_BASE + 0x9C0000; RAM_START = 0x10000000; CRAM_END = (MMIO_BASE - 0x10000000) & 0xF0000000; RAM_START = 0x10000000; diff --git a/kernel/memory/memory_access.c b/kernel/memory/memory_access.c index 8c97971d..6b224967 100644 --- a/kernel/memory/memory_access.c +++ b/kernel/memory/memory_access.c @@ -38,4 +38,12 @@ void write(uint64_t addr, uint64_t value) { uint64_t read(uint64_t addr) { return read64(addr); +} + +uint16_t read_unaligned16(const uint8_t *p) { + return (uint16_t)p[0] | ((uint16_t)p[1] << 8); +} + +uint32_t read_unaligned32(const uint8_t *p) { + return (uint32_t)p[0] | ((uint32_t)p[1] << 8) | ((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24); } \ No newline at end of file diff --git a/kernel/memory/memory_access.h b/kernel/memory/memory_access.h index cb17e1af..6e31ccf8 100644 --- a/kernel/memory/memory_access.h +++ b/kernel/memory/memory_access.h @@ -12,4 +12,15 @@ uint64_t read64(uintptr_t addr); void write64(uintptr_t addr, uint64_t value); void write(uint64_t addr, uint64_t value); uint64_t read(uint64_t addr); -void write_barrier(); \ No newline at end of file +void write_barrier(); + +#ifdef __cplusplus +extern "C" { +#endif + +uint16_t read_unaligned16(const uint8_t *p); +uint32_t read_unaligned32(const uint8_t *p); + +#ifdef __cplusplus +} +#endif \ No newline at end of file From 6372e6eaf3fdaaf99cee2137598e8fdddaf752a2 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Thu, 17 Jul 2025 00:00:00 +0000 Subject: [PATCH 036/123] [UNTESTED] ExFat support for partition offset --- kernel/filesystem/exfat.cpp | 10 ++++++---- kernel/filesystem/exfat.hpp | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/kernel/filesystem/exfat.cpp b/kernel/filesystem/exfat.cpp index d9c8f7ea..d0429884 100644 --- a/kernel/filesystem/exfat.cpp +++ b/kernel/filesystem/exfat.cpp @@ -21,7 +21,7 @@ void* ExFATFS::read_cluster(uint32_t cluster_start, uint32_t cluster_size, uint3 void* buffer = (char*)allocate_in_page(fs_page, cluster_count * cluster_size * 512, ALIGN_64B, true, true); - disk_read(buffer, lba, count); + disk_read(buffer, partition_first_sector + lba, count); return buffer; } @@ -107,19 +107,21 @@ void* ExFATFS::read_full_file(uint32_t cluster_start, uint32_t cluster_size, uin void ExFATFS::read_FAT(uint32_t location, uint32_t size, uint8_t count){ uint32_t* fat = (uint32_t*)allocate_in_page(fs_page, size * count * 512, ALIGN_64B, true, true); - disk_read((void*)fat, location, size); + disk_read((void*)fat, partition_first_sector + location, size); kprintf("FAT: %x (%x)",location*512,size * count * 512); uint32_t total_entries = (size * count * 512) / 4; // for (uint32_t i = 0; i < total_entries; i++) // if (fat[i] != 0) kprintf("[%i] = %x", i, fat[i]); } -bool ExFATFS::init(){ +bool ExFATFS::init(uint32_t partition_sector){ fs_page = alloc_page(0x1000, true, true, false); mbs = (exfat_mbs*)allocate_in_page(fs_page, 512, ALIGN_64B, true, true); + + partition_first_sector = partition_sector; - disk_read((void*)mbs, 0, 1); + disk_read((void*)mbs, partition_first_sector, 1); if (mbs->bootsignature != 0xAA55){ kprintf("[exfat] Wrong boot signature %x",mbs->bootsignature); diff --git a/kernel/filesystem/exfat.hpp b/kernel/filesystem/exfat.hpp index b044bf39..eab9f18c 100644 --- a/kernel/filesystem/exfat.hpp +++ b/kernel/filesystem/exfat.hpp @@ -77,9 +77,10 @@ class ExFATFS; typedef void* (*ef_entry_handler)(ExFATFS *instance, file_entry*, fileinfo_entry*, filename_entry*, char *seek); +//TODO: Unify fs classes under parent class, including the identifier for the partition so it can be found on mbr class ExFATFS { public: - bool init(); + bool init(uint32_t partition_sector); void* read_full_file(uint32_t cluster_start, uint32_t cluster_size, uint32_t cluster_count, uint64_t file_size, uint32_t root_index); void* read_file(char *path); string_list* list_contents(char *path); @@ -93,6 +94,7 @@ class ExFATFS { exfat_mbs* mbs; void *fs_page; + uint32_t partition_first_sector; static void* read_entry_handler(ExFATFS *instance, file_entry *entry, fileinfo_entry *info, filename_entry *name, char *seek); static void* list_entries_handler(ExFATFS *instance, file_entry *entry, fileinfo_entry *info, filename_entry *name, char *seek); From 49bb49889cdeb4fc70e8a31fdb6ff435ce24b546 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Fri, 18 Jul 2025 00:00:00 +0000 Subject: [PATCH 037/123] Using PCI Base instead of USE_PCI --- kernel/hw/hw.c | 5 ++--- kernel/hw/hw.h | 2 +- kernel/input/xhci.cpp | 4 ++-- kernel/pci.c | 26 +++++++++++++------------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/kernel/hw/hw.c b/kernel/hw/hw.c index 6055b2fc..167c1397 100644 --- a/kernel/hw/hw.c +++ b/kernel/hw/hw.c @@ -5,7 +5,7 @@ uint8_t BOARD_TYPE; uint8_t RPI_BOARD; uint8_t USE_DTB = 0; -uint8_t USE_PCI = 0; +uintptr_t PCI_BASE = 0; uintptr_t RAM_START = 0; uintptr_t RAM_SIZE = 0; uintptr_t CRAM_START = 0; @@ -28,10 +28,9 @@ void detect_hardware(){ CRAM_END = 0x60000000; RAM_START = 0x40000000; CRAM_START = 0x43600000; - USE_PCI = 1; + PCI_BASE = 0x4010000000; GICD_BASE = 0x08000000; GICC_BASE = 0x08010000; - } else { uint32_t reg; asm volatile ("mrs %x0, midr_el1" : "=r" (reg)); diff --git a/kernel/hw/hw.h b/kernel/hw/hw.h index 126ebd3c..38ee5f44 100644 --- a/kernel/hw/hw.h +++ b/kernel/hw/hw.h @@ -6,7 +6,7 @@ extern uint8_t BOARD_TYPE; extern uint8_t USE_DTB; -extern uint8_t USE_PCI; +extern uintptr_t PCI_BASE; extern uintptr_t RAM_START; extern uintptr_t RAM_SIZE; diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index a86d25d4..7611bf41 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -44,7 +44,7 @@ bool XHCIDriver::init(){ if (XHCI_BASE){ addr = XHCI_BASE; mmio = addr; - } else if (USE_PCI) { + } else if (PCI_BASE) { addr = find_pci_device(0x1B36, 0xD); } if (!addr){ @@ -53,7 +53,7 @@ bool XHCIDriver::init(){ } kprintfv("[xHCI] init"); - if (USE_PCI){ + if (PCI_BASE){ if (!(*(uint16_t*)(addr + 0x06) & (1 << 4))){ kprintfv("[xHCI] Wrong capabilities list"); return false; diff --git a/kernel/pci.c b/kernel/pci.c index b2e0ba19..65b3801e 100644 --- a/kernel/pci.c +++ b/kernel/pci.c @@ -25,10 +25,6 @@ #define PCI_CAPABILITY_PCIE 0x10 #define PCI_CAPABILITY_MSIX 0x11 -static uint64_t pci_base; - -#define NINIT pci_base == 0x0 - static bool pci_verbose = false; void pci_enable_verbose(){ @@ -92,6 +88,8 @@ struct acpi_mcfg_t { #define RSDP_SEARCH_START 0x000E0000 #define RSDP_SEARCH_END 0x00100000 +bool initialized; + void* find_rsdp() { for (uint64_t addr = RSDP_SEARCH_START; addr < RSDP_SEARCH_END; addr += 16) { const char* sig = (const char*)(uintptr_t)addr; @@ -119,13 +117,15 @@ void* find_rsdp() { } void find_pci(){ - pci_base = 0x4010000000; - for (uint64_t addr = pci_base; addr < pci_base + 0x10000000; addr += GRANULE_2MB) - register_device_memory_2mb(addr, addr); + if (!initialized){ + initialized = true; + for (uint64_t addr = PCI_BASE; addr < PCI_BASE + 0x10000000; addr += GRANULE_2MB) + register_device_memory_2mb(addr, addr); + } } uint64_t pci_make_addr(uint32_t bus, uint32_t slot, uint32_t func, uint32_t offset){ - return pci_base + return PCI_BASE | (((uint64_t)bus) << 20) | (((uint64_t)slot) << 15) | (((uint64_t)func) << 12) @@ -133,8 +133,8 @@ uint64_t pci_make_addr(uint32_t bus, uint32_t slot, uint32_t func, uint32_t offs } uint64_t pci_get_bar_address(uint64_t base, uint8_t offset, uint8_t index){ - if (NINIT) - find_pci(); + if (!PCI_BASE) + return 0; return base + offset + (index * 4); } @@ -214,10 +214,10 @@ uint64_t pci_setup_bar(uint64_t pci_addr, uint32_t bar_index, uint64_t *mmio_sta uint64_t find_pci_device(uint32_t vendor_id, uint32_t device_id) { - if (!USE_PCI) + if (!PCI_BASE) return 0; - - if (NINIT) + + if (!initialized) find_pci(); for (uint32_t bus = 0; bus < PCI_BUS_MAX; bus++) { From 696be09b9314882c0d60577b73186c0a59943db7 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Fri, 18 Jul 2025 00:00:00 +0000 Subject: [PATCH 038/123] unaligned access improvements --- kernel/filesystem/fat32.cpp | 8 +++----- kernel/filesystem/mbr.c | 4 ++-- kernel/memory/memory_access.c | 14 ++++++++++++-- kernel/memory/memory_access.h | 5 +++-- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/kernel/filesystem/fat32.cpp b/kernel/filesystem/fat32.cpp index 0eeaac57..a88fe553 100644 --- a/kernel/filesystem/fat32.cpp +++ b/kernel/filesystem/fat32.cpp @@ -22,8 +22,6 @@ char* FAT32FS::advance_path(char *path){ return path; } -#define MBS_NUM_SECTORS read_unaligned16(mbs8 + 0x13) - bool FAT32FS::init(uint32_t partition_sector){ fs_page = alloc_page(0x1000, true, true, false); @@ -50,9 +48,9 @@ bool FAT32FS::init(uint32_t partition_sector){ return false; } - uint8_t *mbs8 = (uint8_t*)mbs; + uint16_t num_sectors = read_unaligned16(&mbs->num_sectors); - cluster_count = (MBS_NUM_SECTORS == 0 ? mbs->large_num_sectors : MBS_NUM_SECTORS)/mbs->sectors_per_cluster; + cluster_count = (num_sectors == 0 ? mbs->large_num_sectors : num_sectors)/mbs->sectors_per_cluster; data_start_sector = mbs->reserved_sectors + (mbs->sectors_per_fat * mbs->number_of_fats); if (mbs->first_cluster_of_root_directory > cluster_count){ @@ -60,7 +58,7 @@ bool FAT32FS::init(uint32_t partition_sector){ return false; } - bytes_per_sector = read_unaligned16(mbs8 + 0xB); + bytes_per_sector = read_unaligned16(&mbs->bytes_per_sector); kprintf("FAT32 Volume uses %i cluster size", bytes_per_sector); kprintf("Data start at %x",data_start_sector*512); diff --git a/kernel/filesystem/mbr.c b/kernel/filesystem/mbr.c index ee2c96da..6a8da58a 100644 --- a/kernel/filesystem/mbr.c +++ b/kernel/filesystem/mbr.c @@ -17,9 +17,9 @@ uint32_t mbr_find_partition(uint8_t partition_type){ for (uint8_t i = 0; i < 4; i++){ partition_entry *entry = &mbr_entry->partitions[i]; - kprintf("MBR Partition %i = %x -> %x",i, entry->type, read_unaligned32((uint8_t*)&entry->first_sector)); + kprintf("MBR Partition %i = %x -> %x",i, entry->type, read_unaligned32(&entry->first_sector)); if (entry->type == partition_type){ - offset = read_unaligned32((uint8_t*)&entry->first_sector); + offset = read_unaligned32(&entry->first_sector); } } diff --git a/kernel/memory/memory_access.c b/kernel/memory/memory_access.c index 6b224967..7d238272 100644 --- a/kernel/memory/memory_access.c +++ b/kernel/memory/memory_access.c @@ -40,10 +40,20 @@ uint64_t read(uint64_t addr) { return read64(addr); } -uint16_t read_unaligned16(const uint8_t *p) { +uint16_t read_unaligned16(const uint16_t *up) { + uint8_t *p = (uint8_t*)up; return (uint16_t)p[0] | ((uint16_t)p[1] << 8); } -uint32_t read_unaligned32(const uint8_t *p) { +uint32_t read_unaligned32(const uint32_t *up) { + uint8_t *p = (uint8_t*)up; return (uint32_t)p[0] | ((uint32_t)p[1] << 8) | ((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24); +} + +void write_unaligned32(uint32_t *up, uint32_t value) { + uint8_t *p = (uint8_t*)up; + p[0] = (uint8_t)(value & 0xFF); + p[1] = (uint8_t)((value >> 8) & 0xFF); + p[2] = (uint8_t)((value >> 16) & 0xFF); + p[3] = (uint8_t)((value >> 24) & 0xFF); } \ No newline at end of file diff --git a/kernel/memory/memory_access.h b/kernel/memory/memory_access.h index 6e31ccf8..abd0533d 100644 --- a/kernel/memory/memory_access.h +++ b/kernel/memory/memory_access.h @@ -18,8 +18,9 @@ void write_barrier(); extern "C" { #endif -uint16_t read_unaligned16(const uint8_t *p); -uint32_t read_unaligned32(const uint8_t *p); +uint16_t read_unaligned16(const uint16_t *p); +uint32_t read_unaligned32(const uint32_t *p); +void write_unaligned32(uint32_t *p, uint32_t value); #ifdef __cplusplus } From 38a30e9db7b0c687a35c71bb2630f1db30c5484c Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Fri, 18 Jul 2025 00:00:00 +0000 Subject: [PATCH 039/123] First iteration xhci improvements for pi compatibility --- kernel/hw/hw.c | 2 +- kernel/input/input_dispatch.cpp | 2 +- kernel/input/xhci.cpp | 15 +++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/kernel/hw/hw.c b/kernel/hw/hw.c index 167c1397..e9707253 100644 --- a/kernel/hw/hw.c +++ b/kernel/hw/hw.c @@ -51,7 +51,7 @@ void detect_hardware(){ MAILBOX_BASE = MMIO_BASE + 0x13880; SDHCI_BASE = MMIO_BASE + 0xFFF000UL; UART0_BASE = MMIO_BASE + 0x1001000; - XHCI_BASE = 0x1000300000UL; + XHCI_BASE = 0x1F00300000UL; break; default: RPI_BOARD = 3; diff --git a/kernel/input/input_dispatch.cpp b/kernel/input/input_dispatch.cpp index cc28d2d2..678381a5 100644 --- a/kernel/input/input_dispatch.cpp +++ b/kernel/input/input_dispatch.cpp @@ -111,7 +111,7 @@ bool sys_shortcut_triggered(uint16_t pid, uint16_t sid){ } bool input_init(){ - if (BOARD_TYPE == 2){ + if (BOARD_TYPE == 2 && RPI_BOARD != 5){ input_driver = new DWC2Driver();//TODO: QEMU & 3 Only return input_driver->init(); } else { diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index 7611bf41..5d59379a 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -7,6 +7,8 @@ #include "hw/hw.h" #include "memory/memory_access.h" #include "std/memfunctions.h" +#include "async.h" +#include "memory/memory_access.h" uint64_t awaited_addr; uint32_t awaited_type; @@ -84,23 +86,24 @@ bool XHCIDriver::init(){ kprintfv("[xHCI] BARs set up @ %x (%x)",mmio,mmio_size); } - cap = (xhci_cap_regs*)(uintptr_t)mmio; + cap = (xhci_cap_regs*)mmio; kprintfv("[xHCI] caplength %x",cap->caplength); - uint64_t op_base = mmio + cap->caplength; - op = (xhci_op_regs*)(uintptr_t)op_base; - ports = (xhci_port_regs*)((uintptr_t)op_base + 0x400); + uintptr_t op_base = mmio + cap->caplength; + op = (xhci_op_regs*)op_base; + ports = (xhci_port_regs*)(op_base + 0x400); db_base = mmio + (cap->dboff & ~0x1F); rt_base = mmio + (cap->rtsoff & ~0x1F); kprintfv("[xHCI] Resetting controller"); op->usbcmd &= ~1; - while (op->usbcmd & 1); + wait(&op->usbcmd, 1, false, 16); kprintfv("[xHCI] Clear complete"); op->usbcmd |= (1 << 1); - while (op->usbcmd & 1); + wait(&op->usbcmd, 1 << 1, false, 1000); kprintfv("[xHCI] Reset complete"); + wait(&op->usbsts, 1 << 11, false, 1000); while (op->usbsts & (1 << 11)); kprintfv("[xHCI] Device ready"); From 09497c154fc8e8309990906044f53ce57d5da9b4 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Fri, 18 Jul 2025 00:00:00 +0000 Subject: [PATCH 040/123] removed extra wait --- kernel/input/xhci.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index 5d59379a..5bb1ad2e 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -104,7 +104,6 @@ bool XHCIDriver::init(){ kprintfv("[xHCI] Reset complete"); wait(&op->usbsts, 1 << 11, false, 1000); - while (op->usbsts & (1 << 11)); kprintfv("[xHCI] Device ready"); if (!CHECK_XHCI_FIELD(usbcmd)) return false; From 023918b6be204449b2253bcb57976aa701dfb27e Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Fri, 18 Jul 2025 00:00:00 +0000 Subject: [PATCH 041/123] renamed xhci types to usb types and changed interrupt for xhci to 36 --- kernel/exceptions/irq.c | 2 +- kernel/hw/hw.c | 3 +++ kernel/hw/hw.h | 2 ++ kernel/input/USBDevice.cpp | 2 +- kernel/input/USBDevice.hpp | 2 +- kernel/input/USBKeyboard.hpp | 2 +- kernel/input/USBManager.hpp | 2 +- kernel/input/dwc2.hpp | 2 +- kernel/input/usb.cpp | 2 +- kernel/input/usb.hpp | 2 +- kernel/input/{xhci_types.h => usb_types.h} | 2 +- kernel/input/xhci.cpp | 4 ++-- kernel/input/xhci.hpp | 2 +- kernel/pci.h | 2 -- 14 files changed, 17 insertions(+), 14 deletions(-) rename kernel/input/{xhci_types.h => usb_types.h} (99%) diff --git a/kernel/exceptions/irq.c b/kernel/exceptions/irq.c index fb9bad07..13be9be1 100644 --- a/kernel/exceptions/irq.c +++ b/kernel/exceptions/irq.c @@ -3,7 +3,7 @@ #include "memory/memory_access.h" #include "process/scheduler.h" #include "input/input_dispatch.h" -#include "input/xhci_types.h" +#include "input/usb_types.h" #include "pci.h" #include "console/serial/uart.h" #include "networking/network.h" diff --git a/kernel/hw/hw.c b/kernel/hw/hw.c index e9707253..e9636a33 100644 --- a/kernel/hw/hw.c +++ b/kernel/hw/hw.c @@ -20,6 +20,7 @@ uintptr_t MAILBOX_BASE = 0; uintptr_t GPIO_BASE; uintptr_t GPIO_PIN_BASE; uintptr_t DWC2_BASE; +uint32_t MSI_OFFSET; void detect_hardware(){ if (BOARD_TYPE == 1){ @@ -31,6 +32,7 @@ void detect_hardware(){ PCI_BASE = 0x4010000000; GICD_BASE = 0x08000000; GICC_BASE = 0x08010000; + MSI_OFFSET = 50; } else { uint32_t reg; asm volatile ("mrs %x0, midr_el1" : "=r" (reg)); @@ -71,6 +73,7 @@ void detect_hardware(){ CRAM_END = (MMIO_BASE - 0x10000000) & 0xF0000000; RAM_START = 0x10000000; CRAM_START = 0x13600000; + MSI_OFFSET = 0; if (RPI_BOARD != 5) reset_gpio(); } } diff --git a/kernel/hw/hw.h b/kernel/hw/hw.h index 38ee5f44..acb6ea2a 100644 --- a/kernel/hw/hw.h +++ b/kernel/hw/hw.h @@ -33,5 +33,7 @@ extern uintptr_t MAILBOX_BASE; extern uintptr_t DWC2_BASE; +extern uint32_t MSI_OFFSET; + void detect_hardware(); void print_hardware(); \ No newline at end of file diff --git a/kernel/input/USBDevice.cpp b/kernel/input/USBDevice.cpp index 0a65e9ca..b9bbc30f 100644 --- a/kernel/input/USBDevice.cpp +++ b/kernel/input/USBDevice.cpp @@ -1,6 +1,6 @@ #include "USBDevice.hpp" #include "USBKeyboard.hpp" -#include "xhci_types.h" +#include "usb_types.h" #include "console/kio.h" USBDevice::USBDevice(uint32_t capacity, uint8_t address) : address(address) { diff --git a/kernel/input/USBDevice.hpp b/kernel/input/USBDevice.hpp index a3e4a4e2..ac504c21 100644 --- a/kernel/input/USBDevice.hpp +++ b/kernel/input/USBDevice.hpp @@ -1,6 +1,6 @@ #pragma once #include "types.h" -#include "xhci_types.h" +#include "usb_types.h" #include "std/std.hpp" #include "console/kio.h" diff --git a/kernel/input/USBKeyboard.hpp b/kernel/input/USBKeyboard.hpp index 1d0b7883..286700a8 100644 --- a/kernel/input/USBKeyboard.hpp +++ b/kernel/input/USBKeyboard.hpp @@ -3,7 +3,7 @@ #include "types.h" #include "USBDevice.hpp" #include "keypress.h" -#include "xhci_types.h" +#include "usb_types.h" class USBKeyboard: public USBEndpoint { public: diff --git a/kernel/input/USBManager.hpp b/kernel/input/USBManager.hpp index efcb9830..da840b87 100644 --- a/kernel/input/USBManager.hpp +++ b/kernel/input/USBManager.hpp @@ -1,6 +1,6 @@ #pragma once #include "types.h" -#include "xhci_types.h" +#include "usb_types.h" #include "std/std.hpp" #include "USBDevice.hpp" diff --git a/kernel/input/dwc2.hpp b/kernel/input/dwc2.hpp index adabfe50..130ee075 100644 --- a/kernel/input/dwc2.hpp +++ b/kernel/input/dwc2.hpp @@ -2,7 +2,7 @@ #include "usb.hpp" #include "std/indexmap.hpp" -#include "xhci_types.h" +#include "usb_types.h" typedef struct { uint32_t gotgctl; diff --git a/kernel/input/usb.cpp b/kernel/input/usb.cpp index 1c7d658f..b7298279 100644 --- a/kernel/input/usb.cpp +++ b/kernel/input/usb.cpp @@ -3,7 +3,7 @@ #include "async.h" #include "std/string.h" #include "memory/page_allocator.h" -#include "xhci_types.h" +#include "usb_types.h" uint16_t USBDriver::packet_size(uint16_t speed){ switch (speed) { diff --git a/kernel/input/usb.hpp b/kernel/input/usb.hpp index 7fbf1c4b..a6f92f07 100644 --- a/kernel/input/usb.hpp +++ b/kernel/input/usb.hpp @@ -2,7 +2,7 @@ #include "types.h" #include "keypress.h" -#include "xhci_types.h" +#include "usb_types.h" #include "USBManager.hpp" class USBDriver { diff --git a/kernel/input/xhci_types.h b/kernel/input/usb_types.h similarity index 99% rename from kernel/input/xhci_types.h rename to kernel/input/usb_types.h index 34484fac..8386b818 100644 --- a/kernel/input/xhci_types.h +++ b/kernel/input/usb_types.h @@ -34,7 +34,7 @@ extern "C" { #define XHCI_USBSTS_HSE (1 << 2) #define XHCI_USBSTS_CE (1 << 12) -#define XHCI_IRQ 31 +#define XHCI_IRQ 36 typedef struct { uint64_t parameter; diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index 5bb1ad2e..8e325676 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -3,7 +3,7 @@ #include "async.h" #include "usb.hpp" #include "pci.h" -#include "xhci_types.h" +#include "usb_types.h" #include "hw/hw.h" #include "memory/memory_access.h" #include "std/memfunctions.h" @@ -162,7 +162,7 @@ bool XHCIDriver::init(){ op->usbcmd |= (1 << 2);//Interrupt enable op->usbcmd |= 1;//Run - while ((op->usbsts & 0x1)); + wait (&op->usbsts, 0x1, false, 1000); endpoint_map = IndexMap(255 * 5); context_map = IndexMap(255 * 5); diff --git a/kernel/input/xhci.hpp b/kernel/input/xhci.hpp index 234bb97a..0722cc22 100644 --- a/kernel/input/xhci.hpp +++ b/kernel/input/xhci.hpp @@ -1,7 +1,7 @@ #pragma once #include "usb.hpp" -#include "xhci_types.h" +#include "usb_types.h" typedef struct xhci_ring { trb* ring; diff --git a/kernel/pci.h b/kernel/pci.h index f2b17652..128aeacd 100644 --- a/kernel/pci.h +++ b/kernel/pci.h @@ -6,8 +6,6 @@ extern "C" { #endif -#define MSI_OFFSET 50 - typedef struct { uint64_t base_addr; uint64_t size; From 14dcd94b4e61aeaf3ea369223e71856107dd47c8 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Fri, 18 Jul 2025 00:00:00 +0000 Subject: [PATCH 042/123] Fail setup of device if addressing fails --- kernel/input/usb.cpp | 4 ++++ kernel/input/xhci.cpp | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/input/usb.cpp b/kernel/input/usb.cpp index b7298279..ff89eb23 100644 --- a/kernel/input/usb.cpp +++ b/kernel/input/usb.cpp @@ -19,6 +19,10 @@ uint16_t USBDriver::packet_size(uint16_t speed){ bool USBDriver::setup_device(uint8_t address, uint16_t port){ address = address_device(address); + if (address == 0){ + kprintf("[USB error] failed to address device"); + return false; + } usb_device_descriptor* descriptor = (usb_device_descriptor*)allocate_in_page(mem_page, sizeof(usb_device_descriptor), ALIGN_64B, true, true); if (!request_descriptor(address, 0, 0x80, 6, USB_DEVICE_DESCRIPTOR, 0, 0, descriptor)){ diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index 8e325676..309f506b 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -18,8 +18,9 @@ uint32_t awaited_type; awaited_type = (type); \ interrupter->iman &= ~1; \ action; \ - await_response((uintptr_t)(addr), (type)); \ + bool response = await_response((uintptr_t)(addr), (type)); \ interrupter->iman |= 1; \ + response; \ }) #define kprintfv(fmt, ...) \ From c15197585c12bf1df7e909888a9f4a41dad31b82 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Fri, 18 Jul 2025 00:00:00 +0000 Subject: [PATCH 043/123] Port reset fixes --- kernel/input/xhci.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index 309f506b..afa9cb11 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -176,11 +176,10 @@ bool XHCIDriver::init(){ if (ports[i].portsc.ccs && ports[i].portsc.csc){ if (!port_reset(i)){ kprintf("[xHCI] Failed to reset port %i",i); - return false; + continue; } if (!setup_device(0,i)){ kprintf_raw("[xHCI] Failed to configure device at port %i",i); - return false; } } @@ -195,11 +194,13 @@ bool XHCIDriver::port_reset(uint16_t port){ if (port_info->portsc.pp == 0){ port_info->portsc.pp = 1; + delay(20); + //Read back after delay to ensure - // if (port_info->portsc.pp == 0){ - // kprintf_raw("[xHCI error] failed to power on port %i",port); - // return false; - // } + if (port_info->portsc.pp == 0){ + kprintf_raw("[xHCI error] failed to power on port %i",port); + return false; + } } port_info->portsc.csc = 1; @@ -207,12 +208,23 @@ bool XHCIDriver::port_reset(uint16_t port){ port_info->portsc.prc = 1; //TODO: if usb3 - //portsc.wpr = 1; + // port_info->portsc.wpr = 1; //else - return AWAIT(0, { - port_info->portsc.pr = 1; - },TRB_TYPE_PORT_STATUS_CHANGE); + if (!AWAIT(0, { port_info->portsc.pr = 1; },TRB_TYPE_PORT_STATUS_CHANGE)){ + kprintf("[xHCI error] failed port reset"); + return false; + } + + port_info->portsc.prc = 1; + port_info->portsc.wrc = 1; + port_info->portsc.csc = 1; + port_info->portsc.pec = 1; + port_info->portsc.ped = 0; + + delay(300); + + return port_info->portsc.ped != 0; } bool XHCIDriver::enable_events(){ From 603a3f37027141773f72a1a63cfe647aeebaceaa Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 18 Jul 2025 16:51:56 +0200 Subject: [PATCH 044/123] updated make, string and kstring centralized makefile vars, added helper target, improved fs directory management updated kstring and string to be null-safe. --- Makefile | 75 +++++++++++++++++++++------ kernel/Makefile | 31 +++++------- kernel/kstring.c | 121 +++++++++++++++++++++++++++++++------------- shared/Makefile | 22 ++++---- shared/std/string.c | 85 +++++++++++++++++++++---------- user/Makefile | 34 ++++++------- 6 files changed, 245 insertions(+), 123 deletions(-) diff --git a/Makefile b/Makefile index 3e320cf5..18ab8921 100644 --- a/Makefile +++ b/Makefile @@ -1,36 +1,60 @@ +#top mk +#toolchain +ARCH ?= aarch64-none-elf +CC := $(ARCH)-gcc +LD := $(ARCH)-ld +AR := $(ARCH)-ar +OBJCOPY := $(ARCH)-objcopy + +#common flags +CFLAGS_BASE ?= -g -O0 -std=c17 -nostdlib -ffreestanding \ + -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables \ + -Wall -Wextra -mcpu=cortex-a72 + +LDFLAGS_BASE ?= +#build var +LOAD_ADDR ?= 0x41000000 MODE ?= virt -LOAD_ADDR ?= 0x41000000 -OS := $(shell uname) + +#export +export ARCH CC LD AR OBJCOPY CFLAGS_BASE LDFLAGS_BASE LOAD_ADDR + +#config fs +OS := $(shell uname) +FS_DIRS := fs/redos/user ifeq ($(OS),Darwin) -BOOTFS=/Volumes/bootfs +BOOTFS := /Volumes/bootfs else -BOOTFS=/media/bootfs +BOOTFS := /media/bootfs endif -.PHONY: all kernel user shared clean raspi virt run debug dump +#targets +.PHONY: all shared user kernel clean raspi virt run debug dump prepare-fs help install all: shared user kernel @echo "Build complete." ./createfs -dump: - aarch64-none-elf-objdump -D kernel.elf > dump - shared: $(MAKE) -C shared user: + $(MAKE) prepare-fs $(MAKE) -C user kernel: - $(MAKE) -C kernel LOAD_ADDR=$(LOAD_ADDR) + $(MAKE) -C kernel clean: $(MAKE) -C shared clean + $(MAKE) -C user clean $(MAKE) -C kernel clean - $(MAKE) -C user clean + @echo "removing fs dirs" + rm -rf $(FS_DIRS) + @echo "removing images" + rm -f kernel.img kernel.elf disk.img dump raspi: $(MAKE) LOAD_ADDR=0x80000 all @@ -38,16 +62,35 @@ raspi: virt: $(MAKE) LOAD_ADDR=0x41000000 all +run: + $(MAKE) $(MODE) + ./run_$(MODE) + debug: $(MAKE) $(MODE) ./rundebug MODE=$(MODE) $(ARGS) -install: - $(MAKE) clean - $(MAKE) LOAD_ADDR=0x80000 all +dump: + $(OBJCOPY) -O binary kernel.elf kernel.img + aarch64-none-elf-objdump -D kernel.elf > dump + +install: clean raspi cp kernel.img $(BOOTFS)/kernel8.img cp kernel.img $(BOOTFS)/kernel_2712.img -run: - $(MAKE) $(MODE) - ./run_$(MODE) \ No newline at end of file +prepare-fs: + @echo "creating dirs" + @mkdir -p $(FS_DIRS) + +help: + @printf "usage:\n\ + make all build the os, accepts MODE parameter\n\ + make clean remove all build artifacts\n\ + make raspi build for raspberry\n\ + make virt build for qemu virt board\n\ + make run build and run in virt mode(accepts MODE parameter)\n\ + make debug build and run with debugger(accepts MODE parameter)\n\ + make dump disassemble kernel.elf\n\ + make install create raspi kernel and mount it on a bootable partition\n\ + make prepare-fs create directories for the filesystem\n\ +\n" \ No newline at end of file diff --git a/kernel/Makefile b/kernel/Makefile index cf9780d7..9c498543 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,26 +1,23 @@ -ARCH= aarch64-none-elf -CC = $(ARCH)-gcc -LD = $(ARCH)-ld -OBJCOPY = $(ARCH)-objcopy +#kernel +CFLAGS := $(CFLAGS_BASE) -I. -I../shared -I../user +LDFLAGS := $(LDFLAGS_BASE) -T $(shell ls *.ld) --defsym=LOAD_ADDR=$(LOAD_ADDR) -CFLAGS = -g -O0 -std=c17 -nostdlib -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wall -Wextra -mcpu=cortex-a72 -I. -I../shared -I../user +C_SRC := $(shell find . -name '*.c') +ASM_SRC := $(shell find . -name '*.S') +CPP_SRC := $(shell find . -name '*.cpp') +OBJ := $(C_SRC:.c=.o) $(ASM_SRC:.S=.o) $(CPP_SRC:.cpp=.o) +OBJL := $(filter-out ./boot.o, $(OBJ)) -LDFLAGS = -T $(shell ls *.ld) --defsym=LOAD_ADDR=$(LOAD_ADDR) +ELF := ../kernel.elf +TARGET := kernel.img -C_SRC = $(shell find . -name '*.c') -ASM_SRC = $(shell find . -name '*.S') -CPP_SRC = $(shell find . -name '*.cpp') -OBJ = $(C_SRC:.c=.o) $(CPP_SRC:.cpp=.o) $(ASM_SRC:.S=.o) -OBJL = $(filter-out ./boot.o, $(OBJ)) - -TARGET = kernel.img -ELF = kernel.elf +.PHONY: all clean all: $(TARGET) $(TARGET): ../shared/libshared.a $(OBJ) - $(LD) $(LDFLAGS) -o ../$(ELF) $(OBJL) ../shared/libshared.a - $(OBJCOPY) -O binary ../$(ELF) ../$(TARGET) + $(LD) $(LDFLAGS) -o $(ELF) $(OBJL) ../shared/libshared.a + $(OBJCOPY) -O binary $(ELF) $@ %.o: %.S $(CC) $(CFLAGS) -c $< -o $@ @@ -32,4 +29,4 @@ $(TARGET): ../shared/libshared.a $(OBJ) $(CC) $(CFLAGS) -fno-rtti -c $< -o $@ clean: - rm -f $(shell find . -name '*.o') ../$(ELF) ../$(TARGET) $(TARGET) \ No newline at end of file + rm -f $(OBJ) $(ELF) $(TARGET) diff --git a/kernel/kstring.c b/kernel/kstring.c index 3cfe197b..f12b266e 100644 --- a/kernel/kstring.c +++ b/kernel/kstring.c @@ -6,6 +6,9 @@ //TODO: we can most likely get rid of this class now and use string entirely static uint32_t compute_length(const char *s, uint32_t max_length) { + if (s == NULL) { + return 0; + } uint32_t len = 0; while ((max_length == 0 || len < max_length) && s[len] != '\0') { len++; @@ -14,47 +17,73 @@ static uint32_t compute_length(const char *s, uint32_t max_length) { } kstring kstring_l(const char *literal) { + if (literal == NULL) { + return (kstring){ .data = NULL, .length = 0 }; + } uint32_t len = compute_length(literal, 0); - char *buf = (char*)talloc(len+1); - for (uint32_t i = 0; i < len; i++) + char *buf = (char*)talloc(len + 1); + if (!buf) { + return (kstring){ .data = NULL, .length = 0 }; + } + for (uint32_t i = 0; i < len; i++) { buf[i] = literal[i]; - buf[len] = 0; + } + buf[len] = '\0'; return (kstring){ .data = buf, .length = len }; } kstring kstring_repeat(char symbol, uint32_t amount){ char *buf = (char*)talloc(amount + 1); + if (!buf) { + return (kstring){ .data = NULL, .length = 0 }; + } memset(buf, symbol, amount); - buf[amount] = 0; + buf[amount] = '\0'; return (kstring){ .data = buf, .length = amount }; } kstring kstring_tail(const char *array, uint32_t max_length){ + if (array == NULL) { + return (kstring){ .data = NULL, .length = 0 }; + } uint32_t len = compute_length(array, 0); - int offset = len-max_length; - if (offset < 0) - offset = 0; + int offset = (int)len - (int)max_length; + if (offset < 0) offset = 0; uint32_t adjusted_len = len - offset; char *buf = (char*)talloc(adjusted_len + 1); - for (uint32_t i = offset; i < len; i++) - buf[i-offset] = array[i]; - buf[len-offset] = 0; + if (!buf) { + return (kstring){ .data = NULL, .length = 0 }; + } + for (uint32_t i = 0; i < adjusted_len; i++) { + buf[i] = array[offset + i]; + } + buf[adjusted_len] = '\0'; return (kstring){ .data = buf, .length = adjusted_len }; } kstring kstring_ca_max(const char *array, uint32_t max_length) { + if (array == NULL) { + return (kstring){ .data = NULL, .length = 0 }; + } uint32_t len = compute_length(array, max_length); char *buf = (char*)talloc(len + 1); - for (uint32_t i = 0; i < len; i++) + if (!buf) { + return (kstring){ .data = NULL, .length = 0 }; + } + for (uint32_t i = 0; i < len; i++) { buf[i] = array[i]; - buf[len] = 0; + } + buf[len] = '\0'; return (kstring){ .data = buf, .length = len }; } kstring kstring_c(const char c){ char *buf = (char*)talloc(2); + if (!buf) { + return (kstring){ .data = NULL, .length = 0 }; + } buf[0] = c; - buf[1] = 0; + buf[1] = '\0'; return (kstring){ .data = buf, .length = 1 }; } @@ -104,54 +133,79 @@ bool kstring_equals(kstring a, kstring b) { } kstring kstring_format_args(const char *fmt, const uint64_t *args, uint32_t arg_count) { + if (fmt == NULL) { + return (kstring){ .data = NULL, .length = 0 }; + } + // args può essere NULL se arg_count==0, altrimenti va validato + if (arg_count > 0 && args == NULL) { + return (kstring){ .data = NULL, .length = 0 }; + } + char *buf = (char*)talloc(256); + if (!buf) { + return (kstring){ .data = NULL, .length = 0 }; + } + uint32_t len = 0; uint32_t arg_index = 0; - for (uint32_t i = 0; fmt[i] && len < 255; i++) { if (fmt[i] == '%' && fmt[i+1]) { i++; - if (arg_index >= arg_count) break; - if (fmt[i] == 'x') { + if (arg_index >= arg_count) { + // troppi placeholder, copio il resto letterale + buf[len++] = '%'; + buf[len++] = fmt[i]; + continue; + } + switch (fmt[i]) { + case 'x': { uint64_t val = args[arg_index++]; kstring hex = kstring_from_hex(val); for (uint32_t j = 0; j < hex.length && len < 255; j++) buf[len++] = hex.data[j]; - temp_free(hex.data,hex.length); - } else if (fmt[i] == 'b') { + temp_free(hex.data, hex.length); + break; + } + case 'b': { uint64_t val = args[arg_index++]; kstring bin = kstring_from_bin(val); for (uint32_t j = 0; j < bin.length && len < 255; j++) buf[len++] = bin.data[j]; - temp_free(bin.data,bin.length); - } else if (fmt[i] == 'c') { + temp_free(bin.data, bin.length); + break; + } + case 'c': { uint64_t val = args[arg_index++]; buf[len++] = (char)val; - } else if (fmt[i] == 's') { + break; + } + case 's': { const char *str = (const char *)(uintptr_t)args[arg_index++]; - for (uint32_t j = 0; str[j] && len < 255; j++) buf[len++] = str[j]; - } else if (fmt[i] == 'i') { + if (str) { + for (uint32_t j = 0; str[j] && len < 255; j++) buf[len++] = str[j]; + } + break; + } + case 'i': { uint64_t val = args[arg_index++]; char temp[21]; uint32_t temp_len = 0; bool negative = false; - - if ((int)val < 0) { + if ((int64_t)val < 0) { negative = true; - val = (uint64_t)(-(int)val); + val = (uint64_t)(-(int64_t)val); } - do { temp[temp_len++] = '0' + (val % 10); val /= 10; - } while (val && temp_len < 20); - - if (negative && temp_len < 20) { + } while (val && temp_len < sizeof(temp)-1); + if (negative && temp_len < sizeof(temp)-1) { temp[temp_len++] = '-'; } - for (int j = temp_len - 1; j >= 0 && len < 255; j--) { buf[len++] = temp[j]; } - } else { + break; + } + default: buf[len++] = '%'; buf[len++] = fmt[i]; } @@ -159,7 +213,6 @@ kstring kstring_format_args(const char *fmt, const uint64_t *args, uint32_t arg_ buf[len++] = fmt[i]; } } - - buf[len] = 0; + buf[len] = '\0'; return (kstring){ .data = buf, .length = len }; } \ No newline at end of file diff --git a/shared/Makefile b/shared/Makefile index fb7390db..8fe0d3d0 100644 --- a/shared/Makefile +++ b/shared/Makefile @@ -1,21 +1,19 @@ -ARCH= aarch64-none-elf -CC = $(ARCH)-gcc -AR = $(ARCH)-ar -OBJCOPY = $(ARCH)-objcopy +#shared +CFLAGS := $(CFLAGS_BASE) -I. -I../kernel -Wno-unused-parameter -CFLAGS = -g -O0 -std=c17 -nostdlib -nolibc -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wall -Wextra -mcpu=cortex-a72 -I. -I../kernel -Wno-unused-parameter +C_SRC := $(shell find . -name '*.c') +CPP_SRC := $(shell find . -name '*.cpp') +ASM_SRC := $(shell find . -name '*.S') +OBJ := $(C_SRC:.c=.o) $(ASM_SRC:.S=.o) $(CPP_SRC:.cpp=.o) -C_SRC = $(shell find . -name '*.c') -CPP_SRC = $(shell find . -name '*.cpp') -ASM_SRC = $(shell find . -name '*.S') -OBJ = $(C_SRC:.c=.o) $(ASM_SRC:.S=.o) $(CPP_SRC:.cpp=.o) +TARGET := libshared.a -TARGET = libshared.a +.PHONY: all clean all: $(TARGET) $(TARGET): $(OBJ) - $(AR) rcs $(TARGET) $(OBJ) + $(AR) rcs $@ $^ %.o: %.S $(CC) $(CFLAGS) -c $< -o $@ @@ -27,4 +25,4 @@ $(TARGET): $(OBJ) $(CC) $(CFLAGS) -fno-rtti -c $< -o $@ clean: - rm -f $(shell find . -name '*.o') $(TARGET) \ No newline at end of file + rm -f $(OBJ) $(TARGET) diff --git a/shared/std/string.c b/shared/std/string.c index b0ee1623..8b134769 100644 --- a/shared/std/string.c +++ b/shared/std/string.c @@ -3,7 +3,10 @@ #include "memory/memory_access.h" #include "std/memfunctions.h" -static uint32_t compute_length( char *s, uint32_t max_length) { +static uint32_t compute_length(char *s, uint32_t max_length) { + if (s == NULL) { + return 0; + } uint32_t len = 0; while ((max_length == 0 || len < max_length) && s[len] != '\0') { len++; @@ -11,13 +14,22 @@ static uint32_t compute_length( char *s, uint32_t max_length) { return len; } -string string_l( char *literal) { +string string_l(char *literal) { + if (literal == NULL) { + // ritorna stringa vuota + return (string){ .data = NULL, .length = 0, .mem_length = 0 }; + } uint32_t len = compute_length(literal, 0); - char *buf = (char*)malloc(len+1); - for (uint32_t i = 0; i < len; i++) + char *buf = (char*)malloc(len + 1); + if (!buf) { + //manage malloc + return (string){ .data = NULL, .length = 0, .mem_length = 0 }; + } + for (uint32_t i = 0; i < len; i++) { buf[i] = literal[i]; - buf[len] = 0; - return (string){ .data = buf, .length = len, .mem_length = len+1 }; + } + buf[len] = '\0'; + return (string){ .data = buf, .length = len, .mem_length = len + 1 }; } string string_repeat(char symbol, uint32_t amount){ @@ -27,26 +39,41 @@ string string_repeat(char symbol, uint32_t amount){ return (string){ .data = buf, .length = amount, .mem_length = amount+1 }; } -string string_tail( char *array, uint32_t max_length){ +string string_tail(char *array, uint32_t max_length) { + if (array == NULL) { + return (string){ .data = NULL, .length = 0, .mem_length = 0 }; + } uint32_t len = compute_length(array, 0); - int offset = len-max_length; - if (offset < 0) - offset = 0; + int offset = (int)len - (int)max_length; + if (offset < 0) { + offset = 0; + } uint32_t adjusted_len = len - offset; char *buf = (char*)malloc(adjusted_len + 1); - for (uint32_t i = offset; i < len; i++) - buf[i-offset] = array[i]; - buf[len-offset] = 0; - return (string){ .data = buf, .length = adjusted_len }; + if (!buf) { + return (string){ .data = NULL, .length = 0, .mem_length = 0 }; + } + for (uint32_t i = 0; i < adjusted_len; i++) { + buf[i] = array[offset + i]; + } + buf[adjusted_len] = '\0'; + return (string){ .data = buf, .length = adjusted_len, .mem_length = adjusted_len + 1 }; } -string string_ca_max( char *array, uint32_t max_length) { +string string_ca_max(char *array, uint32_t max_length) { + if (array == NULL) { + return (string){ .data = NULL, .length = 0, .mem_length = 0 }; + } uint32_t len = compute_length(array, max_length); char *buf = (char*)malloc(len + 1); - for (uint32_t i = 0; i < len; i++) + if (!buf) { + return (string){ .data = NULL, .length = 0, .mem_length = 0 }; + } + for (uint32_t i = 0; i < len; i++) { buf[i] = array[i]; - buf[len] = 0; - return (string){ .data = buf, .length = len }; + } + buf[len] = '\0'; + return (string){ .data = buf, .length = len, .mem_length = len + 1 }; } string string_c( char c){ @@ -109,11 +136,15 @@ bool string_equals(string a, string b) { return strcmp(a.data,b.data, false) == 0; } -string string_format( char *fmt, ...) { +string string_format(char *fmt, ...) { + if (fmt == NULL) { + return (string){ .data = NULL, .length = 0, .mem_length = 0 }; + } va_list args; va_start(args, fmt); - string_format_va(fmt, args); + string result = string_format_va(fmt, args); va_end(args); + return result; } string string_format_va( char *fmt, va_list args){ @@ -206,21 +237,23 @@ char tolower(char c){ } int strcmp(char *a, char *b, bool case_insensitive) { + if (a == NULL && b == NULL) return 0; //i guess + if (a == NULL) return -1; + if (b == NULL) return 1; + while (*a && *b) { char ca = *a; char cb = *b; - if (case_insensitive) { ca = tolower((unsigned char)ca); cb = tolower((unsigned char)cb); } - - if (ca != cb) return ca - cb; - + if (ca != cb) return ca - cb; a++; b++; } - if (case_insensitive) return tolower(*a) - tolower(*b); - return *a - *b; + if (case_insensitive) + return tolower((unsigned char)*a) - tolower((unsigned char)*b); + return (unsigned char)*a - (unsigned char)*b; } int strstart(char *a, char *b, bool case_insensitive) { diff --git a/user/Makefile b/user/Makefile index fb6b8328..e85c133e 100644 --- a/user/Makefile +++ b/user/Makefile @@ -1,25 +1,23 @@ -ARCH= aarch64-none-elf -CC = $(ARCH)-gcc -LD = $(ARCH)-ld -OBJCOPY = $(ARCH)-objcopy +#user +CFLAGS := $(CFLAGS_BASE) -I. -I../shared -Wno-unused-parameter +LDFLAGS := -T $(shell ls *.ld) -CFLAGS = -g -O0 -std=c17 -nostdlib -ffreestanding -Wall -Wextra -mcpu=cortex-a72 -I. -I../shared -Wno-unused-parameter -LDFLAGS = -T $(shell ls *.ld) +C_SRC := $(shell find . -name '*.c') +CPP_SRC := $(shell find . -name '*.cpp') +OBJ := $(C_SRC:.c=.o) $(CPP_SRC:.cpp=.o) -C_SRC = $(shell find . -name '*.c') -CPP_SRC = $(shell find . -name '*.cpp') -OBJ = $(C_SRC:.c=.o) $(CPP_SRC:.cpp=.o) +NAME := $(notdir $(CURDIR)) +ELF := $(NAME).elf +TARGET := $(NAME).bin +LOCATION := ../fs/redos/user/ -NAME = $(shell basename "$$PWD") -TARGET = $(NAME).bin -ELF = $(NAME).elf -LOCATION = ../fs/redos/user/ +.PHONY: all clean -all: $(TARGET) +all: $(LOCATION)$(TARGET) -$(TARGET): $(OBJ) +$(LOCATION)$(TARGET): $(OBJ) $(LD) $(LDFLAGS) -o $(LOCATION)$(ELF) $(OBJ) ../shared/libshared.a - $(OBJCOPY) -O binary $(LOCATION)$(ELF) $(LOCATION)$(TARGET) + $(OBJCOPY) -O binary $(LOCATION)$(ELF) $@ %.o: %.S $(CC) $(CFLAGS) -c $< -o $@ @@ -28,7 +26,7 @@ $(TARGET): $(OBJ) $(CC) $(CFLAGS) -c $< -o $@ %.o: %.cpp - $(CC) $(CFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) -fno-rtti -c $< -o $@ clean: - rm -f $(shell find . -name '*.o') $(TARGET) \ No newline at end of file + rm -f $(OBJ) $(TARGET) From 8a709183b49162c61a29f5a0a4117ffebbcf0d06 Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 18 Jul 2025 17:02:50 +0200 Subject: [PATCH 045/123] Update kstring.c --- kernel/kstring.c | 105 ++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 55 deletions(-) diff --git a/kernel/kstring.c b/kernel/kstring.c index f12b266e..3e5d99a5 100644 --- a/kernel/kstring.c +++ b/kernel/kstring.c @@ -5,99 +5,97 @@ #include "std/memfunctions.h" //TODO: we can most likely get rid of this class now and use string entirely -static uint32_t compute_length(const char *s, uint32_t max_length) { - if (s == NULL) { - return 0; - } +static uint32_t compute_length(const char *s, uint32_t max_length){ + if (s == NULL){return 0;} uint32_t len = 0; - while ((max_length == 0 || len < max_length) && s[len] != '\0') { + while((max_length == 0 || len < max_length) && s[len] != '\0'){ len++; } return len; } -kstring kstring_l(const char *literal) { +kstring kstring_l(const char *literal){ if (literal == NULL) { - return (kstring){ .data = NULL, .length = 0 }; + return (kstring){.data = NULL, .length = 0}; } uint32_t len = compute_length(literal, 0); - char *buf = (char*)talloc(len + 1); - if (!buf) { - return (kstring){ .data = NULL, .length = 0 }; + char *buf = (char*)talloc(len+1); + if (!buf){ + return (kstring){ .data = NULL, .length = 0}; } - for (uint32_t i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++){ buf[i] = literal[i]; } buf[len] = '\0'; - return (kstring){ .data = buf, .length = len }; + return (kstring){.data = buf, .length = len}; } kstring kstring_repeat(char symbol, uint32_t amount){ - char *buf = (char*)talloc(amount + 1); + char *buf = (char*)talloc(amount+ 1); if (!buf) { - return (kstring){ .data = NULL, .length = 0 }; + return (kstring){ .data = NULL, .length = 0}; } memset(buf, symbol, amount); buf[amount] = '\0'; - return (kstring){ .data = buf, .length = amount }; + return (kstring){.data = buf, .length = amount}; } kstring kstring_tail(const char *array, uint32_t max_length){ - if (array == NULL) { - return (kstring){ .data = NULL, .length = 0 }; + if (array == NULL){ + return (kstring){.data = NULL, .length = 0}; } uint32_t len = compute_length(array, 0); - int offset = (int)len - (int)max_length; - if (offset < 0) offset = 0; + int offset = (int)len-(int)max_length; + if (offset < 0) offset=0; uint32_t adjusted_len = len - offset; - char *buf = (char*)talloc(adjusted_len + 1); - if (!buf) { - return (kstring){ .data = NULL, .length = 0 }; + char *buf = (char*)talloc(adjusted_len+1); + if (!buf){ + return (kstring){.data = NULL, .length = 0}; } - for (uint32_t i = 0; i < adjusted_len; i++) { + for (uint32_t i = 0; i < adjusted_len; i++){ buf[i] = array[offset + i]; } buf[adjusted_len] = '\0'; - return (kstring){ .data = buf, .length = adjusted_len }; + return (kstring){ .data = buf, .length = adjusted_len}; } -kstring kstring_ca_max(const char *array, uint32_t max_length) { - if (array == NULL) { +kstring kstring_ca_max(const char *array, uint32_t max_length){ + if (array == NULL){ return (kstring){ .data = NULL, .length = 0 }; } - uint32_t len = compute_length(array, max_length); - char *buf = (char*)talloc(len + 1); + uint32_t len=compute_length(array, max_length); + char *buf = (char*)talloc(len+1); if (!buf) { - return (kstring){ .data = NULL, .length = 0 }; + return (kstring){.data = NULL, .length = 0}; } - for (uint32_t i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++){ buf[i] = array[i]; } buf[len] = '\0'; - return (kstring){ .data = buf, .length = len }; + return (kstring){.data = buf, .length = len}; } kstring kstring_c(const char c){ - char *buf = (char*)talloc(2); - if (!buf) { + char *buf=(char*)talloc(2); + if (!buf){ return (kstring){ .data = NULL, .length = 0 }; } buf[0] = c; buf[1] = '\0'; - return (kstring){ .data = buf, .length = 1 }; + return (kstring){.data = buf, .length = 1}; } -kstring kstring_from_hex(uint64_t value) { +kstring kstring_from_hex(uint64_t value){ char *buf = (char*)talloc(18); uint32_t len = 0; buf[len++] = '0'; buf[len++] = 'x'; bool started = false; - for (uint32_t i = 60;; i -= 4) { - uint8_t nibble = (value >> i) & 0xF; - char curr_char = nibble < 10 ? '0' + nibble : 'A' + (nibble - 10); - if (started || curr_char != '0' || i == 0) { + for (uint32_t i = 60;; i -= 4){ + uint8_t nibble = (value>>i)&0xF; + char curr_char=nibble<10?'0' + nibble : 'A'+(nibble - 10); + if (started||curr_char != '0'||i == 0) { started = true; buf[len++] = curr_char; } @@ -105,59 +103,56 @@ kstring kstring_from_hex(uint64_t value) { } buf[len] = 0; - return (kstring){ .data = buf, .length = len }; + return (kstring){.data = buf, .length = len}; } -kstring kstring_from_bin(uint64_t value) { +kstring kstring_from_bin(uint64_t value){ char *buf = (char*)talloc(67); uint32_t len = 0; buf[len++] = '0'; buf[len++] = 'b'; bool started = false; - for (uint32_t i = 60;; i --) { + for (uint32_t i = 60;; i --){ char bit = (value >> i) & 1 ? '1' : '0'; - if (started || bit != '0' || i == 0) { + if (started || bit != '0' || i == 0){ started = true; buf[len++] = bit; } if (i == 0) break; } - buf[len] = 0; return (kstring){ .data = buf, .length = len }; } -bool kstring_equals(kstring a, kstring b) { +bool kstring_equals(kstring a, kstring b){ return strcmp(a.data,b.data, false) == 0; } -kstring kstring_format_args(const char *fmt, const uint64_t *args, uint32_t arg_count) { - if (fmt == NULL) { +kstring kstring_format_args(const char *fmt, const uint64_t *args, uint32_t arg_count){ + if (fmt == NULL){ return (kstring){ .data = NULL, .length = 0 }; } - // args può essere NULL se arg_count==0, altrimenti va validato - if (arg_count > 0 && args == NULL) { + if (arg_count > 0 && args == NULL){ return (kstring){ .data = NULL, .length = 0 }; } char *buf = (char*)talloc(256); - if (!buf) { + if (!buf){ return (kstring){ .data = NULL, .length = 0 }; } uint32_t len = 0; uint32_t arg_index = 0; - for (uint32_t i = 0; fmt[i] && len < 255; i++) { + for (uint32_t i = 0; fmt[i] && len < 255; i++){ if (fmt[i] == '%' && fmt[i+1]) { i++; - if (arg_index >= arg_count) { - // troppi placeholder, copio il resto letterale + if (arg_index >= arg_count){ buf[len++] = '%'; buf[len++] = fmt[i]; continue; } - switch (fmt[i]) { + switch (fmt[i]){ case 'x': { uint64_t val = args[arg_index++]; kstring hex = kstring_from_hex(val); @@ -215,4 +210,4 @@ kstring kstring_format_args(const char *fmt, const uint64_t *args, uint32_t arg_ } buf[len] = '\0'; return (kstring){ .data = buf, .length = len }; -} \ No newline at end of file +} From 5578ed5f90502853e3181b0ee7e45a900b792e3a Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 18 Jul 2025 17:07:57 +0200 Subject: [PATCH 046/123] Update string.c --- shared/std/string.c | 166 +++++++++++++++++++++----------------------- 1 file changed, 80 insertions(+), 86 deletions(-) diff --git a/shared/std/string.c b/shared/std/string.c index 8b134769..d906302e 100644 --- a/shared/std/string.c +++ b/shared/std/string.c @@ -3,21 +3,20 @@ #include "memory/memory_access.h" #include "std/memfunctions.h" -static uint32_t compute_length(char *s, uint32_t max_length) { - if (s == NULL) { +static uint32_t compute_length(char *s, uint32_t max_length){ + if (s == NULL){ return 0; } uint32_t len = 0; - while ((max_length == 0 || len < max_length) && s[len] != '\0') { + while ((max_length == 0 || len < max_length) && s[len] != '\0'){ len++; } return len; } -string string_l(char *literal) { - if (literal == NULL) { - // ritorna stringa vuota - return (string){ .data = NULL, .length = 0, .mem_length = 0 }; +string string_l(char *literal){ + if (literal == NULL){ + return (string){ .data = NULL, .length = 0, .mem_length = 0}; } uint32_t len = compute_length(literal, 0); char *buf = (char*)malloc(len + 1); @@ -25,7 +24,7 @@ string string_l(char *literal) { //manage malloc return (string){ .data = NULL, .length = 0, .mem_length = 0 }; } - for (uint32_t i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++){ buf[i] = literal[i]; } buf[len] = '\0'; @@ -39,48 +38,48 @@ string string_repeat(char symbol, uint32_t amount){ return (string){ .data = buf, .length = amount, .mem_length = amount+1 }; } -string string_tail(char *array, uint32_t max_length) { - if (array == NULL) { +string string_tail(char *array, uint32_t max_length){ + if (array == NULL){ return (string){ .data = NULL, .length = 0, .mem_length = 0 }; } uint32_t len = compute_length(array, 0); int offset = (int)len - (int)max_length; - if (offset < 0) { + if(offset < 0){ offset = 0; } uint32_t adjusted_len = len - offset; char *buf = (char*)malloc(adjusted_len + 1); - if (!buf) { + if(!buf){ return (string){ .data = NULL, .length = 0, .mem_length = 0 }; } - for (uint32_t i = 0; i < adjusted_len; i++) { + for (uint32_t i = 0; i < adjusted_len; i++){ buf[i] = array[offset + i]; } buf[adjusted_len] = '\0'; - return (string){ .data = buf, .length = adjusted_len, .mem_length = adjusted_len + 1 }; + return (string){.data = buf, .length = adjusted_len, .mem_length = adjusted_len + 1 }; } -string string_ca_max(char *array, uint32_t max_length) { - if (array == NULL) { - return (string){ .data = NULL, .length = 0, .mem_length = 0 }; +string string_ca_max(char *array, uint32_t max_length){ + if(array == NULL){ + return (string){.data = NULL, .length = 0, .mem_length= 0 }; } uint32_t len = compute_length(array, max_length); char *buf = (char*)malloc(len + 1); - if (!buf) { - return (string){ .data = NULL, .length = 0, .mem_length = 0 }; + if(!buf){ + return (string){ .data = NULL, .length = 0, .mem_length=0 }; } - for (uint32_t i = 0; i < len; i++) { + for(uint32_t i = 0; i < len; i++){ buf[i] = array[i]; } buf[len] = '\0'; - return (string){ .data = buf, .length = len, .mem_length = len + 1 }; + return (string){ .data = buf, .length = len, .mem_length = len+1}; } string string_c( char c){ char *buf = (char*)malloc(2); buf[0] = c; buf[1] = 0; - return (string){ .data = buf, .length = 1, .mem_length = 2 }; + return (string){.data = buf, .length = 1, .mem_length = 2}; } uint32_t parse_hex(uint64_t value, char* buf){ @@ -102,7 +101,7 @@ uint32_t parse_hex(uint64_t value, char* buf){ return len; } -string string_from_hex(uint64_t value) { +string string_from_hex(uint64_t value){ char *buf = (char*)malloc(18); uint32_t len = parse_hex(value, buf); return (string){ .data = buf, .length = len, .mem_length = 18 }; @@ -113,9 +112,9 @@ uint32_t parse_bin(uint64_t value, char* buf){ buf[len++] = '0'; buf[len++] = 'b'; bool started = false; - for (uint32_t i = 63;; i --) { + for (uint32_t i = 63;; i --){ char bit = (value >> i) & 1 ? '1' : '0'; - if (started || bit != '0' || i == 0) { + if (started || bit != '0' || i == 0){ started = true; buf[len++] = bit; } @@ -126,19 +125,19 @@ uint32_t parse_bin(uint64_t value, char* buf){ return len; } -string string_from_bin(uint64_t value) { +string string_from_bin(uint64_t value){ char *buf = (char*)malloc(66); uint32_t len = parse_bin(value, buf); return (string){ .data = buf, .length = len, .mem_length = 66 }; } -bool string_equals(string a, string b) { +bool string_equals(string a, string b){ return strcmp(a.data,b.data, false) == 0; } -string string_format(char *fmt, ...) { - if (fmt == NULL) { - return (string){ .data = NULL, .length = 0, .mem_length = 0 }; +string string_format(char *fmt, ...){ + if(fmt == NULL){ + return (string){ .data = NULL, .length = 0, .mem_length = 0}; } va_list args; va_start(args, fmt); @@ -147,134 +146,129 @@ string string_format(char *fmt, ...) { return result; } -string string_format_va( char *fmt, va_list args){ +string string_format_va(char *fmt, va_list args){ char *buf = (char*)malloc(256); uint32_t len = 0; uint32_t arg_index = 0; - - for (uint32_t i = 0; fmt[i] && len < 255; i++) { - if (fmt[i] == '%' && fmt[i+1]) { + for(uint32_t i = 0; fmt[i] && len < 255; i++){ + if(fmt[i] == '%' && fmt[i+1]){ i++; - if (fmt[i] == 'x') { + if(fmt[i] == 'x'){ uint64_t val = va_arg(args, uint64_t); len += parse_hex(val,(char*)(buf + len)); - } else if (fmt[i] == 'b') { + }else if(fmt[i] == 'b') { uint64_t val = va_arg(args, uint64_t); string bin = string_from_bin(val); - for (uint32_t j = 0; j < bin.length && len < 255; j++) buf[len++] = bin.data[j]; + for(uint32_t j = 0; j < bin.length && len < 255; j++) buf[len++] = bin.data[j]; free(bin.data,bin.mem_length); - } else if (fmt[i] == 'c') { + }else if(fmt[i] == 'c') { uint64_t val = va_arg(args, uint64_t); buf[len++] = (char)val; - } else if (fmt[i] == 's') { + }else if(fmt[i] == 's') { char *str = ( char *)va_arg(args, uintptr_t); for (uint32_t j = 0; str[j] && len < 255; j++) buf[len++] = str[j]; - } else if (fmt[i] == 'i') { + }else if(fmt[i] == 'i') { uint64_t val = va_arg(args, long int); char temp[21]; uint32_t temp_len = 0; bool negative = false; - if ((int)val < 0) { + if((int)val < 0) { negative = true; buf[len++] = '-'; val = (uint64_t)(-(int)val); } - - do { + do{ temp[temp_len++] = '0' + (val % 10); val /= 10; - } while (val && temp_len < 20); + }while(val && temp_len < 20); - for (int j = temp_len - 1; j >= 0 && len < 255; j--) { + for(int j = temp_len - 1; j >= 0 && len < 255; j--){ buf[len++] = temp[j]; } - }else if (fmt[i] == 'f' || fmt[i] == 'd') { + }else if(fmt[i] == 'f' || fmt[i] == 'd') { double val = va_arg(args, double); - if (val < 0) { + if(val < 0){ buf[len++] = '-'; val = -val; } - uint64_t whole = (uint64_t)val; double frac = val - (double)whole; char temp[21]; uint32_t temp_len = 0; - do { - temp[temp_len++] = '0' + (whole % 10); + do{ + temp[temp_len++] = '0' +(whole % 10); whole /= 10; - } while (whole && temp_len < 20); + }while(whole && temp_len < 20); - for (int j = temp_len - 1; j >= 0 && len < 255; j--) { + for(int j = temp_len - 1; j >= 0 && len < 255; j--){ buf[len++] = temp[j]; } - - if (len < 255) buf[len++] = '.'; - + if(len < 255) buf[len++] = '.'; for (int d = 0; d < 6 && len < 255; d++) { frac *= 10; int digit = (int)frac; buf[len++] = '0' + digit; frac -= digit; } - } else { + }else{ buf[len++] = '%'; buf[len++] = fmt[i]; } - } else { + }else{ buf[len++] = fmt[i]; } } - buf[len] = 0; + buf[len]=0; return (string){ .data = buf, .length = len, .mem_length = 256 }; } char tolower(char c){ - if (c >= 'A' && c <= 'Z') return c + 'a' - 'A'; + if(c >= 'A' && c <= 'Z') return c + 'a' - 'A'; return c; } -int strcmp(char *a, char *b, bool case_insensitive) { - if (a == NULL && b == NULL) return 0; //i guess - if (a == NULL) return -1; - if (b == NULL) return 1; +int strcmp(char *a, char *b, bool case_insensitive){ + if(a == NULL && b == NULL)return 0; //i guess + if(a == NULL) return -1; + if(b == NULL) return 1; - while (*a && *b) { + while(*a && *b){ char ca = *a; char cb = *b; - if (case_insensitive) { + if(case_insensitive){ ca = tolower((unsigned char)ca); cb = tolower((unsigned char)cb); } - if (ca != cb) return ca - cb; + if(ca != cb) return ca - cb; a++; b++; } - if (case_insensitive) + if(case_insensitive) return tolower((unsigned char)*a) - tolower((unsigned char)*b); return (unsigned char)*a - (unsigned char)*b; } -int strstart(char *a, char *b, bool case_insensitive) { +int strstart(char *a, char *b, bool case_insensitive){ int index = 0; - while (*a && *b) { + while(*a && *b){ char ca = *a; char cb = *b; - if (case_insensitive) { + if (case_insensitive){ ca = tolower(ca); cb = tolower(cb); } - if (ca != cb) return index; + if(ca != cb) return index; a++; b++; index++; } return 0; } -int strindex( char *a, char *b) { - for (int i = 0; a[i]; i++) { +int strindex( char *a, char *b){ + for(int i = 0; a[i]; i++){ int j = 0; while (b[j] && a[i + j] == b[j]) j++; if (!b[j]) return i; @@ -282,14 +276,14 @@ int strindex( char *a, char *b) { return -1; } -int strend(char *a, char *b, bool case_insensitive) { - while (*a && *b) { +int strend(char *a, char *b, bool case_insensitive){ + while(*a && *b){ char ca = case_insensitive ? tolower((unsigned char)*a) : *a; char cb = case_insensitive ? tolower((unsigned char)*b) : *b; - if (ca == cb) { + if(ca == cb){ char *pa = a, *pb = b; - while (1) { + while(1){ char cpa = case_insensitive ? tolower((unsigned char)*pa) : *pa; char cpb = case_insensitive ? tolower((unsigned char)*pb) : *pb; @@ -304,21 +298,21 @@ int strend(char *a, char *b, bool case_insensitive) { return 1; } -bool strcont( char *a, char *b) { - while (*a) { +bool strcont( char *a, char *b){ + while(*a){ char *p = a, *q = b; - while (*p && *q && *p == *q) { + while(*p && *q && *p == *q){ p++; q++; } - if (*q == 0) return 1; + if(*q == 0) return 1; a++; } return 0; } -bool utf16tochar( uint16_t* str_in, char* out_str, size_t max_len) { +bool utf16tochar(uint16_t* str_in, char* out_str, size_t max_len){ size_t out_i = 0; - for (int i = 0; i < max_len && str_in[i]; i++){ + for(int i = 0; i < max_len && str_in[i]; i++){ uint16_t wc = str_in[i]; out_str[out_i++] = (wc <= 0x7F) ? (char)(wc & 0xFF) : '?'; } @@ -326,9 +320,9 @@ bool utf16tochar( uint16_t* str_in, char* out_str, size_t max_len) { return true; } -uint64_t parse_hex_u64(char* str, size_t size) { +uint64_t parse_hex_u64(char* str, size_t size){ uint64_t result = 0; - for (uint32_t i = 0; i < size; i++) { + for(uint32_t i = 0; i < size; i++){ char c = str[i]; uint8_t digit = 0; if (c >= '0' && c <= '9') digit = c - '0'; @@ -338,4 +332,4 @@ uint64_t parse_hex_u64(char* str, size_t size) { result = (result << 4) | digit; } return result; -} \ No newline at end of file +} From 4cb955758a626a5856491a212765355435cd1255 Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 18 Jul 2025 17:11:19 +0200 Subject: [PATCH 047/123] Update kstring.c --- kernel/kstring.c | 66 ++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/kernel/kstring.c b/kernel/kstring.c index 3e5d99a5..6cce742a 100644 --- a/kernel/kstring.c +++ b/kernel/kstring.c @@ -6,7 +6,7 @@ //TODO: we can most likely get rid of this class now and use string entirely static uint32_t compute_length(const char *s, uint32_t max_length){ - if (s == NULL){return 0;} + if(s == NULL){return 0;} uint32_t len = 0; while((max_length == 0 || len < max_length) && s[len] != '\0'){ len++; @@ -15,15 +15,15 @@ static uint32_t compute_length(const char *s, uint32_t max_length){ } kstring kstring_l(const char *literal){ - if (literal == NULL) { + if(literal == NULL){ return (kstring){.data = NULL, .length = 0}; } uint32_t len = compute_length(literal, 0); char *buf = (char*)talloc(len+1); - if (!buf){ + if(!buf){ return (kstring){ .data = NULL, .length = 0}; } - for (uint32_t i = 0; i < len; i++){ + for(uint32_t i = 0; i < len; i++){ buf[i] = literal[i]; } buf[len] = '\0'; @@ -32,7 +32,7 @@ kstring kstring_l(const char *literal){ kstring kstring_repeat(char symbol, uint32_t amount){ char *buf = (char*)talloc(amount+ 1); - if (!buf) { + if(!buf){ return (kstring){ .data = NULL, .length = 0}; } memset(buf, symbol, amount); @@ -41,7 +41,7 @@ kstring kstring_repeat(char symbol, uint32_t amount){ } kstring kstring_tail(const char *array, uint32_t max_length){ - if (array == NULL){ + if(array == NULL){ return (kstring){.data = NULL, .length = 0}; } uint32_t len = compute_length(array, 0); @@ -49,10 +49,10 @@ kstring kstring_tail(const char *array, uint32_t max_length){ if (offset < 0) offset=0; uint32_t adjusted_len = len - offset; char *buf = (char*)talloc(adjusted_len+1); - if (!buf){ + if(!buf){ return (kstring){.data = NULL, .length = 0}; } - for (uint32_t i = 0; i < adjusted_len; i++){ + for(uint32_t i = 0; i < adjusted_len; i++){ buf[i] = array[offset + i]; } buf[adjusted_len] = '\0'; @@ -60,15 +60,15 @@ kstring kstring_tail(const char *array, uint32_t max_length){ } kstring kstring_ca_max(const char *array, uint32_t max_length){ - if (array == NULL){ + if(array == NULL){ return (kstring){ .data = NULL, .length = 0 }; } uint32_t len=compute_length(array, max_length); char *buf = (char*)talloc(len+1); - if (!buf) { + if(!buf) { return (kstring){.data = NULL, .length = 0}; } - for (uint32_t i = 0; i < len; i++){ + for(uint32_t i = 0; i < len; i++){ buf[i] = array[i]; } buf[len] = '\0'; @@ -77,7 +77,7 @@ kstring kstring_ca_max(const char *array, uint32_t max_length){ kstring kstring_c(const char c){ char *buf=(char*)talloc(2); - if (!buf){ + if(!buf){ return (kstring){ .data = NULL, .length = 0 }; } buf[0] = c; @@ -92,14 +92,14 @@ kstring kstring_from_hex(uint64_t value){ buf[len++] = 'x'; bool started = false; - for (uint32_t i = 60;; i -= 4){ + for(uint32_t i = 60;; i -= 4){ uint8_t nibble = (value>>i)&0xF; char curr_char=nibble<10?'0' + nibble : 'A'+(nibble - 10); - if (started||curr_char != '0'||i == 0) { + if(started||curr_char != '0'||i == 0) { started = true; buf[len++] = curr_char; } - if (i == 0) break; + if(i == 0) break; } buf[len] = 0; @@ -113,13 +113,13 @@ kstring kstring_from_bin(uint64_t value){ buf[len++] = 'b'; bool started = false; - for (uint32_t i = 60;; i --){ + for(uint32_t i = 60;; i --){ char bit = (value >> i) & 1 ? '1' : '0'; - if (started || bit != '0' || i == 0){ + if(started || bit != '0' || i == 0){ started = true; buf[len++] = bit; } - if (i == 0) break; + if(i == 0) break; } buf[len] = 0; return (kstring){ .data = buf, .length = len }; @@ -130,29 +130,29 @@ bool kstring_equals(kstring a, kstring b){ } kstring kstring_format_args(const char *fmt, const uint64_t *args, uint32_t arg_count){ - if (fmt == NULL){ + if(fmt == NULL){ return (kstring){ .data = NULL, .length = 0 }; } - if (arg_count > 0 && args == NULL){ + if(arg_count > 0 && args == NULL){ return (kstring){ .data = NULL, .length = 0 }; } char *buf = (char*)talloc(256); - if (!buf){ + if(!buf){ return (kstring){ .data = NULL, .length = 0 }; } uint32_t len = 0; uint32_t arg_index = 0; - for (uint32_t i = 0; fmt[i] && len < 255; i++){ - if (fmt[i] == '%' && fmt[i+1]) { + for(uint32_t i = 0; fmt[i] && len < 255; i++){ + if(fmt[i] == '%' && fmt[i+1]) { i++; - if (arg_index >= arg_count){ + if(arg_index >= arg_count){ buf[len++] = '%'; buf[len++] = fmt[i]; continue; } - switch (fmt[i]){ + switch(fmt[i]){ case 'x': { uint64_t val = args[arg_index++]; kstring hex = kstring_from_hex(val); @@ -174,8 +174,8 @@ kstring kstring_format_args(const char *fmt, const uint64_t *args, uint32_t arg_ } case 's': { const char *str = (const char *)(uintptr_t)args[arg_index++]; - if (str) { - for (uint32_t j = 0; str[j] && len < 255; j++) buf[len++] = str[j]; + if(str){ + for(uint32_t j = 0; str[j] && len < 255; j++) buf[len++] = str[j]; } break; } @@ -184,18 +184,18 @@ kstring kstring_format_args(const char *fmt, const uint64_t *args, uint32_t arg_ char temp[21]; uint32_t temp_len = 0; bool negative = false; - if ((int64_t)val < 0) { + if((int64_t)val < 0){ negative = true; val = (uint64_t)(-(int64_t)val); } - do { + do{ temp[temp_len++] = '0' + (val % 10); val /= 10; - } while (val && temp_len < sizeof(temp)-1); - if (negative && temp_len < sizeof(temp)-1) { + }while(val && temp_len < sizeof(temp)-1); + if(negative && temp_len < sizeof(temp)-1){ temp[temp_len++] = '-'; } - for (int j = temp_len - 1; j >= 0 && len < 255; j--) { + for(int j = temp_len - 1; j >= 0 && len < 255; j--){ buf[len++] = temp[j]; } break; @@ -204,7 +204,7 @@ kstring kstring_format_args(const char *fmt, const uint64_t *args, uint32_t arg_ buf[len++] = '%'; buf[len++] = fmt[i]; } - } else { + }else{ buf[len++] = fmt[i]; } } From e5e1e1548debee9c18905fae4884fd4fc9c4b061 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sat, 19 Jul 2025 00:00:00 +0000 Subject: [PATCH 048/123] renamed port_status_control --- kernel/input/usb_types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/input/usb_types.h b/kernel/input/usb_types.h index 8386b818..58fa9ad9 100644 --- a/kernel/input/usb_types.h +++ b/kernel/input/usb_types.h @@ -95,10 +95,10 @@ typedef union { uint32_t wpr : 1; }; uint32_t value; -} portstatuscontrol; +} port_status_control; typedef struct { - portstatuscontrol portsc; + port_status_control portsc; uint32_t portpmsc; uint32_t portli; uint32_t rsvd; From 749f2e3f8f252d95ac2f913147f5eea27a1d74c0 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sat, 19 Jul 2025 00:00:00 +0000 Subject: [PATCH 049/123] Removed wrong TODOs --- kernel/exceptions/exception_handler.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/exceptions/exception_handler.c b/kernel/exceptions/exception_handler.c index 95fad8ea..a7e38c1c 100644 --- a/kernel/exceptions/exception_handler.c +++ b/kernel/exceptions/exception_handler.c @@ -66,7 +66,7 @@ void panic(const char* panic_msg) { kstring s = kstring_format("%s\r\n%s\r\nSystem Halted",(uint64_t)PANIC_TEXT,(uint64_t)panic_msg); draw_panic_screen(s); } - while (1);//TODO: OPT + while (1); } void panic_with_info(const char* msg, uint64_t info) { @@ -92,5 +92,5 @@ void panic_with_info(const char* msg, uint64_t info) { kstring s = kstring_format("%s\r\n%s\r\nError code: %x\r\nSystem Halted",(uint64_t)PANIC_TEXT,(uint64_t)msg,info); draw_panic_screen(s); } - while (1);//TODO: OPT + while (1); } \ No newline at end of file From 0c0ea4cd59cf829e2800f7320269838ea39a9f58 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sat, 19 Jul 2025 00:00:00 +0000 Subject: [PATCH 050/123] Renamed XHCI IRQ to input IRQ --- kernel/exceptions/irq.c | 4 ++-- kernel/input/usb_types.h | 2 +- kernel/input/xhci.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/exceptions/irq.c b/kernel/exceptions/irq.c index 13be9be1..c39159c8 100644 --- a/kernel/exceptions/irq.c +++ b/kernel/exceptions/irq.c @@ -43,7 +43,7 @@ void irq_init() { } gic_enable_irq(IRQ_TIMER, 0x80, 0); - gic_enable_irq(MSI_OFFSET + XHCI_IRQ, 0x80, 0); + gic_enable_irq(MSI_OFFSET + INPUT_IRQ, 0x80, 0); gic_enable_irq(MSI_OFFSET + NET_IRQ, 0x80, 0); gic_enable_irq(MSI_OFFSET + NET_IRQ + 1, 0x80, 0); gic_enable_irq(SLEEP_TIMER, 0x80, 0); @@ -84,7 +84,7 @@ void irq_el1_handler() { if (irq == IRQ_TIMER) { if (RPI_BOARD != 3) write32(GICC_BASE + 0x10, irq); switch_proc(INTERRUPT); - } else if (irq == MSI_OFFSET + XHCI_IRQ){ + } else if (irq == MSI_OFFSET + INPUT_IRQ){ handle_input_interrupt(); if (RPI_BOARD != 3) write32(GICC_BASE + 0x10, irq); process_restore(); diff --git a/kernel/input/usb_types.h b/kernel/input/usb_types.h index 58fa9ad9..1dbefd77 100644 --- a/kernel/input/usb_types.h +++ b/kernel/input/usb_types.h @@ -34,7 +34,7 @@ extern "C" { #define XHCI_USBSTS_HSE (1 << 2) #define XHCI_USBSTS_CE (1 << 12) -#define XHCI_IRQ 36 +#define INPUT_IRQ 36 typedef struct { uint64_t parameter; diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index afa9cb11..19119881 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -71,16 +71,16 @@ bool XHCIDriver::init(){ pci_register(mmio, mmio_size); - uint8_t interrupts_ok = pci_setup_interrupts(addr, XHCI_IRQ, 1); + uint8_t interrupts_ok = pci_setup_interrupts(addr, INPUT_IRQ, 1); switch(interrupts_ok){ case 0: kprintf_raw("[xHCI] Failed to setup interrupts"); return false; case 1: - kprintf_raw("[xHCI] Interrupts setup with MSI-X %i",XHCI_IRQ); + kprintf_raw("[xHCI] Interrupts setup with MSI-X %i",INPUT_IRQ); break; default: - kprintf_raw("[xHCI] Interrupts setup with MSI %i",XHCI_IRQ); + kprintf_raw("[xHCI] Interrupts setup with MSI %i",INPUT_IRQ); break; } From 1336a99e9441404792801cbb360e3e31f8fbebf1 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sat, 19 Jul 2025 00:00:00 +0000 Subject: [PATCH 051/123] Moved xhci structs to own file --- kernel/input/usb_types.h | 273 ----------------------------------- kernel/input/xhci.hpp | 1 + kernel/input/xhci_types.hpp | 276 ++++++++++++++++++++++++++++++++++++ 3 files changed, 277 insertions(+), 273 deletions(-) create mode 100644 kernel/input/xhci_types.hpp diff --git a/kernel/input/usb_types.h b/kernel/input/usb_types.h index 1dbefd77..5b345029 100644 --- a/kernel/input/usb_types.h +++ b/kernel/input/usb_types.h @@ -6,261 +6,8 @@ extern "C" { #include "types.h" -#define TRB_TYPE_NORMAL 1 -#define TRB_TYPE_LINK 6 -#define TRB_TYPE_EVENT_DATA 3 -#define TRB_TYPE_ENABLE_SLOT 9 -#define TRB_TYPE_ADDRESS_DEV 11 -#define TRB_TYPE_CONFIG_EP 12 -#define TRB_TYPE_SETUP 2 -#define TRB_TYPE_STATUS 4 -#define TRB_TYPE_INPUT 8 - -#define MAX_TRB_AMOUNT 256 -#define MAX_ERST_AMOUNT 1 - -#define TRB_TYPE_MASK 0xFC00 -#define TRB_ENDPOINT_MASK 0xF0000 -#define TRB_SLOT_MASK 0xF000000 - -#define TRB_TYPE_TRANSFER 0x20 -#define TRB_TYPE_COMMAND_COMPLETION 0x21 -#define TRB_TYPE_PORT_STATUS_CHANGE 0x22 - -#define TRB_TYPE_SETUP_STAGE 0x2 -#define TRB_TYPE_DATA_STAGE 0x3 -#define TRB_TYPE_STATUS_STAGE 0x4 - -#define XHCI_USBSTS_HSE (1 << 2) -#define XHCI_USBSTS_CE (1 << 12) - #define INPUT_IRQ 36 -typedef struct { - uint64_t parameter; - uint32_t status; - uint32_t control; -}__attribute__((packed)) trb; - -typedef struct { - uint8_t caplength; - uint8_t reserved; - uint16_t hciversion; - uint32_t hcsparams1; - uint32_t hcsparams2; - uint32_t hcsparams3; - uint32_t hccparams1; - uint32_t dboff; - uint32_t rtsoff; - uint32_t hccparams2; -}__attribute__((packed)) xhci_cap_regs; - -typedef struct { - uint32_t usbcmd; - uint32_t usbsts; - uint32_t pagesize; - uint64_t reserved0; - uint32_t dnctrl; - uint64_t crcr; - uint32_t reserved1[4]; - uint64_t dcbaap; - uint32_t config; -}__attribute__((packed)) xhci_op_regs; - -typedef union { - struct { - uint32_t ccs : 1; - uint32_t ped : 1; - uint32_t rsvd0 : 1; - uint32_t oca : 1; - uint32_t pr : 1; - uint32_t pls : 4; - uint32_t pp : 1; - uint32_t port_speed : 4; - uint32_t pic : 2; - uint32_t lws : 1; - uint32_t csc : 1; - uint32_t pec : 1; - uint32_t wrc : 1; - uint32_t occ : 1; - uint32_t prc : 1; - uint32_t plc : 1; - uint32_t cec : 1; - uint32_t cas : 1; - uint32_t wce : 1; - uint32_t wde : 1; - uint32_t woe : 1; - uint32_t rsvd1 : 2; - uint32_t dr : 1; - uint32_t wpr : 1; - }; - uint32_t value; -} port_status_control; - -typedef struct { - port_status_control portsc; - uint32_t portpmsc; - uint32_t portli; - uint32_t rsvd; -}__attribute__((packed, aligned(4))) xhci_port_regs; - -typedef struct { - uint32_t iman; - uint32_t imod; - uint32_t erstsz; - uint32_t reserved; - uint64_t erstba; - uint64_t erdp; -}__attribute__((packed)) xhci_interrupter; - -typedef struct { - uint64_t mmio; - uint64_t mmio_size; - xhci_cap_regs* cap; - xhci_op_regs* op; - xhci_port_regs* ports; - uint64_t db_base; - uint64_t rt_base; - trb* cmd_ring; - uint32_t cmd_index; - uint32_t event_index; - bool command_cycle_bit; - bool event_cycle_bit; - trb* event_ring; - uint8_t* key_buffer; - xhci_interrupter* interrupter; - uint64_t* dcbaa; - uint16_t max_device_slots; - uint16_t max_ports; -} xhci_device; - -typedef struct { - uint64_t ring_base; - uint32_t ring_size; - uint32_t reserved; -}__attribute__((packed)) erst_entry; - -typedef struct { - uint32_t drop_flags; - uint32_t add_flags; - uint64_t reserved[3]; -}__attribute__((packed)) xhci_input_control_context; - -typedef union -{ - struct - { - uint32_t route_string: 20; - uint32_t speed: 4; - uint32_t rsvd : 1; - uint32_t mtt : 1; - uint32_t hub : 1; - uint32_t context_entries : 5; - }; - uint32_t value; -} slot_field0; - -typedef union -{ - struct - { - uint16_t max_exit_latency; - uint8_t root_hub_port_num; - uint8_t port_count; - }; - uint32_t value; -} slot_field1; - -typedef union -{ - struct - { - uint32_t parent_hub_slot_id : 8; - uint32_t parent_port_number : 8; - uint32_t think_time : 2; - uint32_t rsvd : 4; - uint32_t interrupt_target : 10; - }; - uint32_t value; -} slot_field2; - -typedef union -{ - struct - { - uint32_t device_address : 8; - uint32_t rsvd : 19; - uint32_t state : 5;//0 disabled, 1 default, 2 addressed, 3 configured - }; - uint32_t value; -} slot_field3; - -typedef union -{ - struct { - uint32_t endpoint_state : 3; - uint32_t rsvd0 : 5; - uint32_t mult : 2; - uint32_t max_primary_streams : 5; - uint32_t linear_stream_array : 1; - uint32_t interval : 8; - uint32_t max_esit_payload_hi : 8; - }; - uint32_t value; -} endpoint_field0; - -typedef union -{ - struct { - uint32_t rsvd1 : 1; - uint32_t error_count : 2; - uint32_t endpoint_type : 3; - uint32_t rsvd2 : 1; - uint32_t host_initiate_disable : 1; - uint32_t max_burst_size : 8; - uint32_t max_packet_size : 16; - }; - uint32_t value; -} endpoint_field1; - -typedef union { - struct { - uint64_t dcs : 1; - uint64_t rsvd0 : 3; - uint64_t ring_ptr : 60; - }; - uint64_t value; -} endpoint_field23; - -typedef union -{ - struct { - uint16_t average_trb_length; - uint16_t max_esit_payload_lo; - }; - uint32_t value; -} endpoint_field4; - -typedef struct { - slot_field0 slot_f0; - slot_field1 slot_f1; - slot_field2 slot_f2; - slot_field3 slot_f3; - uint32_t slot_rsvd[4]; - struct { - endpoint_field0 endpoint_f0; - endpoint_field1 endpoint_f1; - endpoint_field23 endpoint_f23; - endpoint_field4 endpoint_f4; - uint32_t ep_rsvd[3]; - } endpoints[31]; -} xhci_device_context; - -typedef struct { - xhci_input_control_context control_context; - xhci_device_context device_context; -} xhci_input_context; - typedef struct __attribute__((packed)) { uint8_t bmRequestType; uint8_t bRequest; @@ -349,26 +96,6 @@ typedef enum { MOUSE } xhci_device_types; -typedef struct { - uint8_t transfer_cycle_bit; - uint32_t transfer_index; - trb* transfer_ring; - uint32_t slot_id; - xhci_input_context* ctx; -} xhci_usb_device; - -typedef struct { - xhci_device_types type; - trb* endpoint_transfer_ring; - uint32_t endpoint_transfer_index; - uint8_t endpoint_transfer_cycle_bit; - uint8_t poll_packetSize; - uint8_t *input_buffer; - uint8_t poll_endpoint; - uint16_t report_length; - uint8_t *report_descriptor; - } xhci_usb_device_endpoint; - #define USB_DEVICE_DESCRIPTOR 1 #define USB_CONFIGURATION_DESCRIPTOR 2 #define USB_STRING_DESCRIPTOR 3 diff --git a/kernel/input/xhci.hpp b/kernel/input/xhci.hpp index 0722cc22..7423e638 100644 --- a/kernel/input/xhci.hpp +++ b/kernel/input/xhci.hpp @@ -2,6 +2,7 @@ #include "usb.hpp" #include "usb_types.h" +#include "xhci_types.hpp" typedef struct xhci_ring { trb* ring; diff --git a/kernel/input/xhci_types.hpp b/kernel/input/xhci_types.hpp new file mode 100644 index 00000000..f0036253 --- /dev/null +++ b/kernel/input/xhci_types.hpp @@ -0,0 +1,276 @@ +#pragma once + +#include "types.h" + +#define TRB_TYPE_NORMAL 1 +#define TRB_TYPE_LINK 6 +#define TRB_TYPE_EVENT_DATA 3 +#define TRB_TYPE_ENABLE_SLOT 9 +#define TRB_TYPE_ADDRESS_DEV 11 +#define TRB_TYPE_CONFIG_EP 12 +#define TRB_TYPE_SETUP 2 +#define TRB_TYPE_STATUS 4 +#define TRB_TYPE_INPUT 8 + +#define MAX_TRB_AMOUNT 256 +#define MAX_ERST_AMOUNT 1 + +#define TRB_TYPE_MASK 0xFC00 +#define TRB_ENDPOINT_MASK 0xF0000 +#define TRB_SLOT_MASK 0xF000000 + +#define TRB_TYPE_TRANSFER 0x20 +#define TRB_TYPE_COMMAND_COMPLETION 0x21 +#define TRB_TYPE_PORT_STATUS_CHANGE 0x22 + +#define TRB_TYPE_SETUP_STAGE 0x2 +#define TRB_TYPE_DATA_STAGE 0x3 +#define TRB_TYPE_STATUS_STAGE 0x4 + +#define XHCI_USBSTS_HSE (1 << 2) +#define XHCI_USBSTS_CE (1 << 12) + +typedef struct { + uint64_t parameter; + uint32_t status; + uint32_t control; +}__attribute__((packed)) trb; + +typedef struct { + uint8_t caplength; + uint8_t reserved; + uint16_t hciversion; + uint32_t hcsparams1; + uint32_t hcsparams2; + uint32_t hcsparams3; + uint32_t hccparams1; + uint32_t dboff; + uint32_t rtsoff; + uint32_t hccparams2; +}__attribute__((packed)) xhci_cap_regs; + +typedef struct { + uint32_t usbcmd; + uint32_t usbsts; + uint32_t pagesize; + uint64_t reserved0; + uint32_t dnctrl; + uint64_t crcr; + uint32_t reserved1[4]; + uint64_t dcbaap; + uint32_t config; +}__attribute__((packed)) xhci_op_regs; + +typedef union { + struct { + uint32_t ccs : 1; + uint32_t ped : 1; + uint32_t rsvd0 : 1; + uint32_t oca : 1; + uint32_t pr : 1; + uint32_t pls : 4; + uint32_t pp : 1; + uint32_t port_speed : 4; + uint32_t pic : 2; + uint32_t lws : 1; + uint32_t csc : 1; + uint32_t pec : 1; + uint32_t wrc : 1; + uint32_t occ : 1; + uint32_t prc : 1; + uint32_t plc : 1; + uint32_t cec : 1; + uint32_t cas : 1; + uint32_t wce : 1; + uint32_t wde : 1; + uint32_t woe : 1; + uint32_t rsvd1 : 2; + uint32_t dr : 1; + uint32_t wpr : 1; + }; + uint32_t value; +} port_status_control; + +typedef struct { + port_status_control portsc; + uint32_t portpmsc; + uint32_t portli; + uint32_t rsvd; +}__attribute__((packed, aligned(4))) xhci_port_regs; + +typedef struct { + uint32_t iman; + uint32_t imod; + uint32_t erstsz; + uint32_t reserved; + uint64_t erstba; + uint64_t erdp; +}__attribute__((packed)) xhci_interrupter; + +typedef struct { + uint64_t mmio; + uint64_t mmio_size; + xhci_cap_regs* cap; + xhci_op_regs* op; + xhci_port_regs* ports; + uint64_t db_base; + uint64_t rt_base; + trb* cmd_ring; + uint32_t cmd_index; + uint32_t event_index; + bool command_cycle_bit; + bool event_cycle_bit; + trb* event_ring; + uint8_t* key_buffer; + xhci_interrupter* interrupter; + uint64_t* dcbaa; + uint16_t max_device_slots; + uint16_t max_ports; +} xhci_device; + +typedef struct { + uint64_t ring_base; + uint32_t ring_size; + uint32_t reserved; +}__attribute__((packed)) erst_entry; + +typedef struct { + uint32_t drop_flags; + uint32_t add_flags; + uint64_t reserved[3]; +}__attribute__((packed)) xhci_input_control_context; + +typedef union +{ + struct + { + uint32_t route_string: 20; + uint32_t speed: 4; + uint32_t rsvd : 1; + uint32_t mtt : 1; + uint32_t hub : 1; + uint32_t context_entries : 5; + }; + uint32_t value; +} slot_field0; + +typedef union +{ + struct + { + uint16_t max_exit_latency; + uint8_t root_hub_port_num; + uint8_t port_count; + }; + uint32_t value; +} slot_field1; + +typedef union +{ + struct + { + uint32_t parent_hub_slot_id : 8; + uint32_t parent_port_number : 8; + uint32_t think_time : 2; + uint32_t rsvd : 4; + uint32_t interrupt_target : 10; + }; + uint32_t value; +} slot_field2; + +typedef union +{ + struct + { + uint32_t device_address : 8; + uint32_t rsvd : 19; + uint32_t state : 5;//0 disabled, 1 default, 2 addressed, 3 configured + }; + uint32_t value; +} slot_field3; + +typedef union +{ + struct { + uint32_t endpoint_state : 3; + uint32_t rsvd0 : 5; + uint32_t mult : 2; + uint32_t max_primary_streams : 5; + uint32_t linear_stream_array : 1; + uint32_t interval : 8; + uint32_t max_esit_payload_hi : 8; + }; + uint32_t value; +} endpoint_field0; + +typedef union +{ + struct { + uint32_t rsvd1 : 1; + uint32_t error_count : 2; + uint32_t endpoint_type : 3; + uint32_t rsvd2 : 1; + uint32_t host_initiate_disable : 1; + uint32_t max_burst_size : 8; + uint32_t max_packet_size : 16; + }; + uint32_t value; +} endpoint_field1; + +typedef union { + struct { + uint64_t dcs : 1; + uint64_t rsvd0 : 3; + uint64_t ring_ptr : 60; + }; + uint64_t value; +} endpoint_field23; + +typedef union +{ + struct { + uint16_t average_trb_length; + uint16_t max_esit_payload_lo; + }; + uint32_t value; +} endpoint_field4; + +typedef struct { + slot_field0 slot_f0; + slot_field1 slot_f1; + slot_field2 slot_f2; + slot_field3 slot_f3; + uint32_t slot_rsvd[4]; + struct { + endpoint_field0 endpoint_f0; + endpoint_field1 endpoint_f1; + endpoint_field23 endpoint_f23; + endpoint_field4 endpoint_f4; + uint32_t ep_rsvd[3]; + } endpoints[31]; +} xhci_device_context; + +typedef struct { + xhci_input_control_context control_context; + xhci_device_context device_context; +} xhci_input_context; + +typedef struct { + uint8_t transfer_cycle_bit; + uint32_t transfer_index; + trb* transfer_ring; + uint32_t slot_id; + xhci_input_context* ctx; +} xhci_usb_device; + +typedef struct { + xhci_device_types type; + trb* endpoint_transfer_ring; + uint32_t endpoint_transfer_index; + uint8_t endpoint_transfer_cycle_bit; + uint8_t poll_packetSize; + uint8_t *input_buffer; + uint8_t poll_endpoint; + uint16_t report_length; + uint8_t *report_descriptor; + } xhci_usb_device_endpoint; \ No newline at end of file From 7c70c135a367ab727622c3c0bf1d1eb55b1f5d40 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sat, 19 Jul 2025 00:00:00 +0000 Subject: [PATCH 052/123] renamed xhci_device_types to usb_device_types --- kernel/input/USBDevice.cpp | 2 +- kernel/input/USBDevice.hpp | 6 +++--- kernel/input/USBManager.cpp | 2 +- kernel/input/USBManager.hpp | 2 +- kernel/input/dwc2.cpp | 2 +- kernel/input/dwc2.hpp | 2 +- kernel/input/usb.cpp | 2 +- kernel/input/usb.hpp | 2 +- kernel/input/usb_types.h | 2 +- kernel/input/xhci.cpp | 2 +- kernel/input/xhci.hpp | 2 +- kernel/input/xhci_types.hpp | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/kernel/input/USBDevice.cpp b/kernel/input/USBDevice.cpp index b9bbc30f..35650988 100644 --- a/kernel/input/USBDevice.cpp +++ b/kernel/input/USBDevice.cpp @@ -21,7 +21,7 @@ void USBDevice::process_data(uint8_t endpoint_id, USBDriver *driver){ ep->process_data(driver); } -void USBDevice::register_endpoint(uint8_t endpoint, xhci_device_types type, uint16_t packet_size){ +void USBDevice::register_endpoint(uint8_t endpoint, usb_device_types type, uint16_t packet_size){ if (endpoint >= endpoints.max_size()) return; USBEndpoint *newendpoint; switch (type){ diff --git a/kernel/input/USBDevice.hpp b/kernel/input/USBDevice.hpp index ac504c21..61b80f16 100644 --- a/kernel/input/USBDevice.hpp +++ b/kernel/input/USBDevice.hpp @@ -8,13 +8,13 @@ class USBDriver; class USBEndpoint { public: - USBEndpoint(uint8_t endpoint, xhci_device_types type, uint16_t packet_size): endpoint(endpoint), type(type), packet_size(packet_size) { } + USBEndpoint(uint8_t endpoint, usb_device_types type, uint16_t packet_size): endpoint(endpoint), type(type), packet_size(packet_size) { } virtual void request_data(USBDriver *driver) = 0; virtual void process_data(USBDriver *driver) = 0; uint8_t endpoint; - xhci_device_types type; + usb_device_types type; uint16_t packet_size; }; @@ -25,7 +25,7 @@ class USBDevice { void process_data(uint8_t endpoint_id, USBDriver *driver); - void register_endpoint(uint8_t endpoint, xhci_device_types type, uint16_t packet_size); + void register_endpoint(uint8_t endpoint, usb_device_types type, uint16_t packet_size); void poll_inputs(USBDriver *driver); diff --git a/kernel/input/USBManager.cpp b/kernel/input/USBManager.cpp index 3efd8f75..6b1827c9 100644 --- a/kernel/input/USBManager.cpp +++ b/kernel/input/USBManager.cpp @@ -14,7 +14,7 @@ void USBManager::register_device(uint8_t address){ devices.add(address,newdevice); } -void USBManager::register_endpoint(uint8_t slot_id, uint8_t endpoint, xhci_device_types type, uint16_t packet_size){ +void USBManager::register_endpoint(uint8_t slot_id, uint8_t endpoint, usb_device_types type, uint16_t packet_size){ if (slot_id >= devices.max_size()) return; USBDevice *dev = devices[slot_id]; if (dev) diff --git a/kernel/input/USBManager.hpp b/kernel/input/USBManager.hpp index da840b87..1cf0d013 100644 --- a/kernel/input/USBManager.hpp +++ b/kernel/input/USBManager.hpp @@ -12,7 +12,7 @@ class USBManager { IndexMap devices; void register_device(uint8_t address); - void register_endpoint(uint8_t slot_id, uint8_t endpoint, xhci_device_types type, uint16_t packet_size); + void register_endpoint(uint8_t slot_id, uint8_t endpoint, usb_device_types type, uint16_t packet_size); void request_data(uint8_t slot_id, uint8_t endpoint_id, USBDriver *driver); void process_data(uint8_t slot_id, uint8_t endpoint_id, USBDriver *driver); void poll_inputs(USBDriver *driver); diff --git a/kernel/input/dwc2.cpp b/kernel/input/dwc2.cpp index a993aa53..e556d706 100644 --- a/kernel/input/dwc2.cpp +++ b/kernel/input/dwc2.cpp @@ -153,7 +153,7 @@ bool DWC2Driver::request_sized_descriptor(uint8_t address, uint8_t endpoint, uin return true; } -bool DWC2Driver::configure_endpoint(uint8_t address, usb_endpoint_descriptor *endpoint, uint8_t configuration_value, xhci_device_types type){ +bool DWC2Driver::configure_endpoint(uint8_t address, usb_endpoint_descriptor *endpoint, uint8_t configuration_value, usb_device_types type){ uint8_t ep_address = endpoint->bEndpointAddress; uint8_t ep_num = ep_address & 0x0F; diff --git a/kernel/input/dwc2.hpp b/kernel/input/dwc2.hpp index 130ee075..2b268076 100644 --- a/kernel/input/dwc2.hpp +++ b/kernel/input/dwc2.hpp @@ -49,7 +49,7 @@ class DWC2Driver: public USBDriver { bool init() override; bool request_sized_descriptor(uint8_t address, uint8_t endpoint, uint8_t rType, uint8_t request, uint8_t type, uint16_t descriptor_index, uint16_t wIndex, uint16_t descriptor_size, void *out_descriptor) override; uint8_t address_device(uint8_t address) override; - bool configure_endpoint(uint8_t address, usb_endpoint_descriptor *endpoint, uint8_t configuration_value, xhci_device_types type) override; + bool configure_endpoint(uint8_t address, usb_endpoint_descriptor *endpoint, uint8_t configuration_value, usb_device_types type) override; void handle_hub_routing(uint8_t hub, uint8_t port) override; bool poll(uint8_t address, uint8_t endpoint, void *out_buf, uint16_t size) override; void handle_interrupt() override; diff --git a/kernel/input/usb.cpp b/kernel/input/usb.cpp index ff89eb23..1af98b0c 100644 --- a/kernel/input/usb.cpp +++ b/kernel/input/usb.cpp @@ -106,7 +106,7 @@ bool USBDriver::get_configuration(uint8_t address){ uint8_t* report_descriptor; uint16_t report_length; - xhci_device_types dev_type; + usb_device_types dev_type; for (uint16_t i = 0; i < total_length;){ usb_descriptor_header* header = (usb_descriptor_header*)&config->data[i]; diff --git a/kernel/input/usb.hpp b/kernel/input/usb.hpp index a6f92f07..9340f7d5 100644 --- a/kernel/input/usb.hpp +++ b/kernel/input/usb.hpp @@ -16,7 +16,7 @@ class USBDriver { void hub_enumerate(uint8_t address); virtual bool setup_device(uint8_t address, uint16_t port); virtual uint8_t address_device(uint8_t address) = 0; - virtual bool configure_endpoint(uint8_t address, usb_endpoint_descriptor *endpoint, uint8_t configuration_value, xhci_device_types type) = 0; + virtual bool configure_endpoint(uint8_t address, usb_endpoint_descriptor *endpoint, uint8_t configuration_value, usb_device_types type) = 0; virtual void handle_hub_routing(uint8_t hub, uint8_t port) = 0; virtual bool poll(uint8_t address, uint8_t endpoint, void *out_buf, uint16_t size) = 0; void poll_inputs(); diff --git a/kernel/input/usb_types.h b/kernel/input/usb_types.h index 5b345029..fadef21a 100644 --- a/kernel/input/usb_types.h +++ b/kernel/input/usb_types.h @@ -94,7 +94,7 @@ typedef enum { NONE, KEYBOARD, MOUSE -} xhci_device_types; +} usb_device_types; #define USB_DEVICE_DESCRIPTOR 1 #define USB_CONFIGURATION_DESCRIPTOR 2 diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index 19119881..247fefc6 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -442,7 +442,7 @@ uint8_t XHCIDriver::get_ep_type(usb_endpoint_descriptor* descriptor) { return (descriptor->bEndpointAddress & 0x80 ? 1 << 2 : 0) | (descriptor->bmAttributes & 0x3); } -bool XHCIDriver::configure_endpoint(uint8_t address, usb_endpoint_descriptor *endpoint, uint8_t configuration_value, xhci_device_types type){ +bool XHCIDriver::configure_endpoint(uint8_t address, usb_endpoint_descriptor *endpoint, uint8_t configuration_value, usb_device_types type){ kprintfv("[xHCI] endpoint address %x",endpoint->bEndpointAddress); uint8_t ep_address = endpoint->bEndpointAddress; uint8_t ep_dir = (ep_address & 0x80) ? 1 : 0; // 1 IN, 0 OUT diff --git a/kernel/input/xhci.hpp b/kernel/input/xhci.hpp index 7423e638..6a7706af 100644 --- a/kernel/input/xhci.hpp +++ b/kernel/input/xhci.hpp @@ -16,7 +16,7 @@ class XHCIDriver : public USBDriver { bool init() override; bool request_sized_descriptor(uint8_t address, uint8_t endpoint, uint8_t rType, uint8_t request, uint8_t type, uint16_t descriptor_index, uint16_t wIndex, uint16_t descriptor_size, void *out_descriptor) override; uint8_t address_device(uint8_t address) override; - bool configure_endpoint(uint8_t address, usb_endpoint_descriptor *endpoint, uint8_t configuration_value, xhci_device_types type) override; + bool configure_endpoint(uint8_t address, usb_endpoint_descriptor *endpoint, uint8_t configuration_value, usb_device_types type) override; void handle_hub_routing(uint8_t hub, uint8_t port) override; bool poll(uint8_t address, uint8_t endpoint, void *out_buf, uint16_t size) override; bool setup_device(uint8_t address, uint16_t port) override; diff --git a/kernel/input/xhci_types.hpp b/kernel/input/xhci_types.hpp index f0036253..c719ea0f 100644 --- a/kernel/input/xhci_types.hpp +++ b/kernel/input/xhci_types.hpp @@ -264,7 +264,7 @@ typedef struct { } xhci_usb_device; typedef struct { - xhci_device_types type; + usb_device_types type; trb* endpoint_transfer_ring; uint32_t endpoint_transfer_index; uint8_t endpoint_transfer_cycle_bit; From 3af599a295bc0a514f434fd7ad2c544964cac5f2 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sat, 19 Jul 2025 00:00:00 +0000 Subject: [PATCH 053/123] defines in UART for legibility --- kernel/console/serial/uart.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/console/serial/uart.c b/kernel/console/serial/uart.c index cfa0e817..f81cf570 100644 --- a/kernel/console/serial/uart.c +++ b/kernel/console/serial/uart.c @@ -12,6 +12,15 @@ #define UART0_LCRH (UART0_BASE + 0x2C) #define UART0_CR (UART0_BASE + 0x30) +#define UART_FIFO 4 +#define UART_WLEN 5 + +#define UART_EN 0 +#define UART_TXE 8 +#define UART_RXE 9 + +#define UART_8B_WLEN 0b11 + uint64_t get_uart_base(){ return UART0_BASE; } @@ -45,9 +54,9 @@ void enable_uart() { write32(UART0_FBRD, fbrd); - write32(UART0_LCRH, (1 << 4) | (1 << 5) | (1 << 6)); + write32(UART0_LCRH, (1 << UART_FIFO) | (UART_8B_WLEN << UART_WLEN)); - write32(UART0_CR, (1 << 0) | (1 << 8) | (1 << 9)); + write32(UART0_CR, (1 << UART_EN) | (1 << UART_TXE) | (1 << UART_RXE)); } void uart_raw_putc(const char c) { From c6c4b5a507ee36dc7a270093d68ccf9a3daf5d82 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sat, 19 Jul 2025 00:00:00 +0000 Subject: [PATCH 054/123] removed unused property --- kernel/input/USBKeyboard.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/input/USBKeyboard.hpp b/kernel/input/USBKeyboard.hpp index 286700a8..1f11f7a9 100644 --- a/kernel/input/USBKeyboard.hpp +++ b/kernel/input/USBKeyboard.hpp @@ -12,7 +12,6 @@ class USBKeyboard: public USBEndpoint { void process_data(USBDriver *driver) override; private: void process_keypress(keypress *rkp); - trb* latest_ring; bool requesting = false; uint8_t slot_id; From da280a9e7393d32d92e8b744f80b35dcd374ca3d Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sat, 19 Jul 2025 00:00:00 +0000 Subject: [PATCH 055/123] [xHCI] padding for context, currently compile-time defined --- Makefile | 7 ++++--- kernel/Makefile | 2 +- kernel/input/xhci_types.hpp | 9 +++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 3e320cf5..beea941a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ MODE ?= virt LOAD_ADDR ?= 0x41000000 +XHCI_CTX_SIZE ?= 32 OS := $(shell uname) @@ -25,7 +26,7 @@ user: $(MAKE) -C user kernel: - $(MAKE) -C kernel LOAD_ADDR=$(LOAD_ADDR) + $(MAKE) -C kernel LOAD_ADDR=$(LOAD_ADDR) XHCI_CTX_SIZE=$(XHCI_CTX_SIZE) clean: $(MAKE) -C shared clean @@ -33,10 +34,10 @@ clean: $(MAKE) -C user clean raspi: - $(MAKE) LOAD_ADDR=0x80000 all + $(MAKE) LOAD_ADDR=0x80000 XHCI_CTX_SIZE=64 all virt: - $(MAKE) LOAD_ADDR=0x41000000 all + $(MAKE) LOAD_ADDR=0x41000000 XHCI_CTX_SIZE=32 all debug: $(MAKE) $(MODE) diff --git a/kernel/Makefile b/kernel/Makefile index cf9780d7..b3f98ce8 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -3,7 +3,7 @@ CC = $(ARCH)-gcc LD = $(ARCH)-ld OBJCOPY = $(ARCH)-objcopy -CFLAGS = -g -O0 -std=c17 -nostdlib -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wall -Wextra -mcpu=cortex-a72 -I. -I../shared -I../user +CFLAGS = -g -O0 -std=c17 -nostdlib -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wall -Wextra -DXHCI_CTX_SIZE=XHCI_CTX_SIZE -mcpu=cortex-a72 -I. -I../shared -I../user LDFLAGS = -T $(shell ls *.ld) --defsym=LOAD_ADDR=$(LOAD_ADDR) diff --git a/kernel/input/xhci_types.hpp b/kernel/input/xhci_types.hpp index c719ea0f..88e343a9 100644 --- a/kernel/input/xhci_types.hpp +++ b/kernel/input/xhci_types.hpp @@ -138,6 +138,9 @@ typedef struct { uint32_t drop_flags; uint32_t add_flags; uint64_t reserved[3]; +#if XHCI_CTX_SIZE == 64 + uint32_t pad[8]; +#endif }__attribute__((packed)) xhci_input_control_context; typedef union @@ -241,12 +244,18 @@ typedef struct { slot_field2 slot_f2; slot_field3 slot_f3; uint32_t slot_rsvd[4]; +#if XHCI_CTX_SIZE == 64 + uint32_t pad[8]; +#endif struct { endpoint_field0 endpoint_f0; endpoint_field1 endpoint_f1; endpoint_field23 endpoint_f23; endpoint_field4 endpoint_f4; uint32_t ep_rsvd[3]; +#if XHCI_CTX_SIZE == 64 + uint32_t pad[8]; +#endif } endpoints[31]; } xhci_device_context; From 38d4e8a0f807d7f064089c317e440666160291ed Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sat, 19 Jul 2025 00:00:00 +0000 Subject: [PATCH 056/123] [xHCI] fixed variable value --- Makefile | 2 +- kernel/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index beea941a..7529411b 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ debug: install: $(MAKE) clean - $(MAKE) LOAD_ADDR=0x80000 all + $(MAKE) LOAD_ADDR=0x80000 XHCI_CTX_SIZE=64 all cp kernel.img $(BOOTFS)/kernel8.img cp kernel.img $(BOOTFS)/kernel_2712.img diff --git a/kernel/Makefile b/kernel/Makefile index b3f98ce8..97ebfb3b 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -3,7 +3,7 @@ CC = $(ARCH)-gcc LD = $(ARCH)-ld OBJCOPY = $(ARCH)-objcopy -CFLAGS = -g -O0 -std=c17 -nostdlib -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wall -Wextra -DXHCI_CTX_SIZE=XHCI_CTX_SIZE -mcpu=cortex-a72 -I. -I../shared -I../user +CFLAGS = -g -O0 -std=c17 -nostdlib -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wall -Wextra -DXHCI_CTX_SIZE=$(XHCI_CTX_SIZE) -mcpu=cortex-a72 -I. -I../shared -I../user LDFLAGS = -T $(shell ls *.ld) --defsym=LOAD_ADDR=$(LOAD_ADDR) From 649e0a00e67e2830a529d8de5fcf557c7b48cff6 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sun, 20 Jul 2025 00:00:00 +0000 Subject: [PATCH 057/123] Fixes for configure endpoints --- kernel/input/xhci.cpp | 60 +++++++++++++++++++++++++++++++------ kernel/input/xhci.hpp | 1 + kernel/input/xhci_types.hpp | 8 +++-- kernel/memory/mmu.c | 4 +++ 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index 247fefc6..3c8dda82 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -42,6 +42,21 @@ bool XHCIDriver::check_fatal_error() { #define CHECK_XHCI_FIELD(field) (op->field != 0 ? (kprintf_raw("[xHCI Error] wrong " #field " %x", op->field), false) : (kprintfv("[xHCI] Correct " #field " value"), true)) +#define XHCI_EP_TYPE_INT_IN 7 +#define XHCI_EP_TYPE_INT_OUT 3 +#define XHCI_EP_TYPE_ISO_IN 5 +#define XHCI_EP_TYPE_ISO_OUT 1 + +#define XHCI_SPEED_UNDEFINED 0 +#define XHCI_SPEED_FULL_SPEED 1 +#define XHCI_SPEED_LOW_SPEED 2 +#define XHCI_SPEED_HIGH_SPEED 3 +#define XHCI_SPEED_SUPER_SPEED 4 +#define XHCI_SPEED_SUPER_SPEED_PLUS 5 + +#define XHCI_EP_DISABLED 0 +#define XHCI_EP_CONTROL 4 + bool XHCIDriver::init(){ uint64_t addr, mmio, mmio_size; if (XHCI_BASE){ @@ -292,7 +307,8 @@ bool XHCIDriver::await_response(uint64_t command, uint32_t type){ } for (; event_ring.index < MAX_TRB_AMOUNT; event_ring.index++){ last_event = &event_ring.ring[event_ring.index]; - if (!wait(&last_event->control, event_ring.cycle_bit, true, 2000)){ + if (!wait(&last_event->control, event_ring.cycle_bit, true, 20000)){ + kprintf("[xHCI error] Timeout awaiting response to %x command of type %x", command, type); awaited_type = 0; return false; } @@ -366,11 +382,11 @@ bool XHCIDriver::setup_device(uint8_t address, uint16_t port){ ctx->device_context.slot_f0.context_entries = 1; ctx->device_context.slot_f1.root_hub_port_num = port + 1; - ctx->device_context.endpoints[0].endpoint_f0.endpoint_state = 0;//Disabled - ctx->device_context.endpoints[0].endpoint_f1.endpoint_type = 4;//Type = control + ctx->device_context.endpoints[0].endpoint_f0.endpoint_state = XHCI_EP_DISABLED; + ctx->device_context.endpoints[0].endpoint_f1.endpoint_type = XHCI_EP_CONTROL; ctx->device_context.endpoints[0].endpoint_f0.interval = 0; ctx->device_context.endpoints[0].endpoint_f1.error_count = 3; - ctx->device_context.endpoints[0].endpoint_f1.max_packet_size = packet_size(ctx->device_context.slot_f0.speed);//Packet size. Guessed from port speed + ctx->device_context.endpoints[0].endpoint_f1.max_packet_size = packet_size(ctx->device_context.slot_f0.speed); transfer_ring->ring = (trb*)allocate_in_page(mem_page, MAX_TRB_AMOUNT * sizeof(trb), ALIGN_64B, true, true); kprintfv("Transfer ring at %x %i",(uintptr_t)transfer_ring->ring, address << 8); @@ -442,6 +458,25 @@ uint8_t XHCIDriver::get_ep_type(usb_endpoint_descriptor* descriptor) { return (descriptor->bEndpointAddress & 0x80 ? 1 << 2 : 0) | (descriptor->bmAttributes & 0x3); } +uint32_t XHCIDriver::calculate_interval(uint32_t speed, uint32_t received_interval){ + if (speed >= XHCI_SPEED_HIGH_SPEED) + { + if (received_interval < 1) + received_interval = 1; + + if (received_interval > 16) + received_interval = 16; + + return received_interval-1; + } + + uint32_t i; + for (i = 3; i < 11; i++) + if (125 * (1 << i) >= 1000 * received_interval) break; + + return i; +} + bool XHCIDriver::configure_endpoint(uint8_t address, usb_endpoint_descriptor *endpoint, uint8_t configuration_value, usb_device_types type){ kprintfv("[xHCI] endpoint address %x",endpoint->bEndpointAddress); uint8_t ep_address = endpoint->bEndpointAddress; @@ -449,16 +484,23 @@ bool XHCIDriver::configure_endpoint(uint8_t address, usb_endpoint_descriptor *en uint8_t ep_num = ((ep_address & 0x0F) * 2) + ep_dir; uint8_t ep_type = endpoint->bmAttributes & 0x03; // 0 = Control, 1 = Iso, 2 = Bulk, 3 = Interrupt + + if (ep_type != 3){ + kprintf("[xHCI implementation warning] Endpoint type %i not supported. Ignored",ep_type); + return true; + } kprintf_raw("[xHCI] endpoint %i info. Direction %i type %i",ep_num, ep_dir, ep_type); xhci_input_context* ctx = context_map[address << 8]; + xhci_device_context* context = (xhci_device_context*)dcbaap[address]; - ctx->control_context.add_flags = (1 << 0) | (1 << ep_num); - ctx->device_context.slot_f0.context_entries = 2; //2 entries: EP0 + EP1 - ctx->device_context.endpoints[ep_num-1].endpoint_f0.interval = endpoint->bInterval; + if (ep_num > ctx->device_context.slot_f0.context_entries) + ctx->device_context.slot_f0.context_entries = ep_num; + ctx->device_context.slot_f0.speed = context->slot_f0.speed; + ctx->device_context.endpoints[ep_num-1].endpoint_f0.interval = calculate_interval(context->slot_f0.speed, endpoint->bInterval); - ctx->device_context.endpoints[ep_num-1].endpoint_f0.endpoint_state = 0; + ctx->device_context.endpoints[ep_num-1].endpoint_f0.endpoint_state = XHCI_EP_DISABLED; ctx->device_context.endpoints[ep_num-1].endpoint_f1.endpoint_type = get_ep_type(endpoint); ctx->device_context.endpoints[ep_num-1].endpoint_f1.max_packet_size = endpoint->wMaxPacketSize; ctx->device_context.endpoints[ep_num-1].endpoint_f4.max_esit_payload_lo = endpoint->wMaxPacketSize; @@ -471,7 +513,7 @@ bool XHCIDriver::configure_endpoint(uint8_t address, usb_endpoint_descriptor *en make_ring_link(ep_ring->ring, ep_ring->cycle_bit); ctx->device_context.endpoints[ep_num-1].endpoint_f23.dcs = ep_ring->cycle_bit; ctx->device_context.endpoints[ep_num-1].endpoint_f23.ring_ptr = ((uintptr_t)ep_ring->ring) >> 4; - ctx->device_context.endpoints[ep_num-1].endpoint_f4.average_trb_length = 8; + ctx->device_context.endpoints[ep_num-1].endpoint_f4.average_trb_length = sizeof(trb); if (!issue_command((uintptr_t)ctx, 0, (address << 24) | (TRB_TYPE_CONFIG_EP << 10))){ kprintf_raw("[xHCI] Failed to configure endpoint %i for address %i",ep_num,address); diff --git a/kernel/input/xhci.hpp b/kernel/input/xhci.hpp index 6a7706af..862f195d 100644 --- a/kernel/input/xhci.hpp +++ b/kernel/input/xhci.hpp @@ -32,6 +32,7 @@ class XHCIDriver : public USBDriver { void ring_doorbell(uint32_t slot, uint32_t endpoint); bool await_response(uint64_t command, uint32_t type); uint8_t get_ep_type(usb_endpoint_descriptor* descriptor); + uint32_t calculate_interval(uint32_t speed, uint32_t received_interval); void make_ring_link_control(trb* ring, bool cycle); void make_ring_link(trb* ring, bool cycle); diff --git a/kernel/input/xhci_types.hpp b/kernel/input/xhci_types.hpp index 88e343a9..b291d81b 100644 --- a/kernel/input/xhci_types.hpp +++ b/kernel/input/xhci_types.hpp @@ -142,6 +142,7 @@ typedef struct { uint32_t pad[8]; #endif }__attribute__((packed)) xhci_input_control_context; +static_assert(sizeof(xhci_input_control_context) == XHCI_CTX_SIZE); typedef union { @@ -254,10 +255,11 @@ typedef struct { endpoint_field4 endpoint_f4; uint32_t ep_rsvd[3]; #if XHCI_CTX_SIZE == 64 - uint32_t pad[8]; + uint32_t pad[8]; #endif - } endpoints[31]; -} xhci_device_context; + }__attribute__((packed)) endpoints[31]; +}__attribute__((packed)) xhci_device_context; +static_assert(sizeof(xhci_device_context) == XHCI_CTX_SIZE * 32); typedef struct { xhci_input_control_context control_context; diff --git a/kernel/memory/mmu.c b/kernel/memory/mmu.c index dc762486..1ecb6fdc 100644 --- a/kernel/memory/mmu.c +++ b/kernel/memory/mmu.c @@ -188,6 +188,10 @@ void mmu_init() { for (uint64_t addr = get_shared_start(); addr <= get_shared_end(); addr += GRANULE_4KB) mmu_map_4kb(addr, addr, MAIR_IDX_NORMAL, 2); + if (XHCI_BASE) + for (uint64_t addr = XHCI_BASE; addr <= XHCI_BASE + 0x1000; addr += GRANULE_4KB) + mmu_map_4kb(addr, addr, MAIR_IDX_DEVICE, 1); + uint64_t dstart; uint64_t dsize; if (dtb_addresses(&dstart,&dsize)){ From 5d94bbdb8028d2bfdcf1e6303253f9b225adfb5b Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sun, 20 Jul 2025 00:00:00 +0000 Subject: [PATCH 058/123] v2 card addressing --- kernel/filesystem/sdhci.cpp | 5 +++-- kernel/filesystem/sdhci.hpp | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/filesystem/sdhci.cpp b/kernel/filesystem/sdhci.cpp index 9f9ab674..e979c961 100644 --- a/kernel/filesystem/sdhci.cpp +++ b/kernel/filesystem/sdhci.cpp @@ -168,7 +168,7 @@ bool SDHCI::init() { switch_clock_rate(25000000); - bool v2_card = 0; + v2_card = 0; if (!issue_command(IF_COND, 0x1AA)){ if (!(regs->interrupt & 0x10000)){ kprintf("[SDHCI error] IFCOND error"); @@ -264,7 +264,8 @@ bool SDHCI::read(void *buffer, uint32_t sector, uint32_t count){ uint32_t command = multiple ? READ_MULTIPLE : READ_ONE; uint32_t flags = multiple ? 0b110110 : 0b010000; for (int i = 5; i >= 0; i--){ - //TODO: This is now broken on qemu. On QEMU, we need to multiply sector by 512 + if (!v2_card) + sector *= 512; if (issue_command(command, sector, flags)) break; if (i == 0) { kprintf("[SDHCI error] read request timeout"); return false; } delay(500); diff --git a/kernel/filesystem/sdhci.hpp b/kernel/filesystem/sdhci.hpp index c2ba2037..21ebf979 100644 --- a/kernel/filesystem/sdhci.hpp +++ b/kernel/filesystem/sdhci.hpp @@ -38,5 +38,6 @@ class SDHCI { bool switch_clock_rate(uint32_t target_rate); uint32_t clock_rate; uint32_t rca; + bool v2_card; bool verbose; }; \ No newline at end of file From 82113811687af0dff243e39fe135d33774fd7a3a Mon Sep 17 00:00:00 2001 From: CodeAnarchist Date: Sun, 20 Jul 2025 18:25:50 +0200 Subject: [PATCH 059/123] implemented linked list, chunked list, ring buffer --- kernel/console/kconsole/kconsole.cpp | 168 +++++++-------- kernel/console/kconsole/kconsole.h | 2 +- kernel/console/kconsole/kconsole.hpp | 32 +-- kernel/filesystem/fat32.cpp | 2 +- kernel/input/xhci.cpp | 1 - .../drivers/virtio_net_pci/virtio_net_pci.cpp | 7 +- kernel/networking/processes/net_proc.c | 5 +- shared/data_struct/chunked_list.cpp | 173 +++++++++++++++ shared/data_struct/chunked_list.hpp | 202 ++++++++++++++++++ shared/data_struct/circular_linked_list.cpp | 0 shared/data_struct/circular_linked_list.hpp | 0 shared/data_struct/doubly_linked_list.cpp | 0 shared/data_struct/doubly_linked_list.hpp | 0 shared/data_struct/linked_list.cpp | 138 ++++++++++++ shared/data_struct/linked_list.hpp | 157 ++++++++++++++ shared/data_struct/queue.cpp | 0 shared/data_struct/queue.hpp | 0 shared/data_struct/ring_buffer.cpp | 58 +++++ shared/data_struct/ring_buffer.hpp | 78 +++++++ 19 files changed, 910 insertions(+), 113 deletions(-) create mode 100644 shared/data_struct/chunked_list.cpp create mode 100644 shared/data_struct/chunked_list.hpp create mode 100644 shared/data_struct/circular_linked_list.cpp create mode 100644 shared/data_struct/circular_linked_list.hpp create mode 100644 shared/data_struct/doubly_linked_list.cpp create mode 100644 shared/data_struct/doubly_linked_list.hpp create mode 100644 shared/data_struct/linked_list.cpp create mode 100644 shared/data_struct/linked_list.hpp create mode 100644 shared/data_struct/queue.cpp create mode 100644 shared/data_struct/queue.hpp create mode 100644 shared/data_struct/ring_buffer.cpp create mode 100644 shared/data_struct/ring_buffer.hpp diff --git a/kernel/console/kconsole/kconsole.cpp b/kernel/console/kconsole/kconsole.cpp index 948ddf4c..e8975005 100644 --- a/kernel/console/kconsole/kconsole.cpp +++ b/kernel/console/kconsole/kconsole.cpp @@ -1,123 +1,117 @@ #include "kconsole.hpp" -#include "memory/kalloc.h" -#include "graph/graphics.h" #include "console/serial/uart.h" -KernelConsole::KernelConsole() - : cursor_x(0), cursor_y(0), scroll_row_offset(0) -{ +KernelConsole::KernelConsole():cursor_x(0),cursor_y(0),is_initialized(false){ resize(); clear(); } bool KernelConsole::check_ready(){ - if (!gpu_ready()) return false; - if (!is_initialized){ - is_initialized = true; + if(!gpu_ready()) return false; + if(!is_initialized){ + is_initialized= true; resize(); clear(); } return true; } -void KernelConsole::resize() { - gpu_size screen = gpu_get_screen_size(); - columns = screen.width / char_width; - rows = screen.height / char_height; - - if (buffer_header_size > 0) - temp_free(buffer,buffer_header_size); - if (buffer_data_size > 0) - temp_free(row_data,buffer_data_size); - - buffer_header_size = rows * sizeof(char*); - buffer = (char**)talloc(rows * sizeof(char*)); - buffer_data_size = rows * columns * sizeof(char); - row_data = (char*)talloc(buffer_data_size); - - for (unsigned int i = 0; i < rows; i++) { - buffer[i] = row_data + (i * columns); - } -} - -void KernelConsole::put_char(char c) { - if (!check_ready()) - return; - - if (c == '\n') { - newline(); +void KernelConsole::resize(){ + gpu_size s=gpu_get_screen_size(); + columns=s.width/char_width; + rows=s.height/ char_height; + + if(row_data) temp_free(row_data,buffer_data_size); + buffer_data_size = rows*columns; + row_data= (char*)talloc(buffer_data_size); + if(!row_data){ + rows=columns=0; + row_ring.clear(); return; } - if (cursor_x >= columns) - newline(); - - buffer[(scroll_row_offset + cursor_y) % rows][cursor_x] = c; - gpu_draw_char({cursor_x * char_width, cursor_y * char_height}, c, 1, 0xFFFFFFFF); - cursor_x++; + row_ring.clear(); + for(uint32_t i=0;i=columns) newline(); + + uint32_t ri; + if(row_ring.pop(ri)){ + row_ring.push(ri); + char* line=row_data+ri*columns; + line[cursor_x]=c; + gpu_draw_char({cursor_x*char_width,cursor_y*char_height},c,1,0xFFFFFFFF); + cursor_x++; } +} + +void KernelConsole::put_string(const char* s){ + if(!check_ready()) return; + for(uint32_t i=0;s[i];i++) + put_char(s[i]); gpu_flush(); } -void KernelConsole::put_hex(uint64_t value) { - if (!check_ready()) - return; +void KernelConsole::put_hex(uint64_t v){ + if(!check_ready()) return; put_char('0'); put_char('x'); - bool started = false; - for (uint32_t i = 60;; i -= 4) { - uint8_t nibble = (value >> i) & 0xF; - char curr_char = nibble < 10 ? '0' + nibble : 'A' + (nibble - 10); - if (started || curr_char != '0' || i == 0) { - started = true; - put_char(curr_char); + bool started=false; + for(uint32_t i=60;;i-=4){ + uint8_t n=(v>>i)&0xF; + char c=n<10?'0'+n:'A'+(n-10); + if(started||c!='0' ||i==0){ + started=true; + put_char(c); } - if (i == 0) break; + if(i==0) break; } - gpu_flush(); } -void KernelConsole::newline() { - if (!check_ready()) - return; - for (unsigned x = cursor_x; x < columns; x++){ - buffer[(scroll_row_offset + cursor_y) % rows][x] = 0; +void KernelConsole::newline(){ + if(!check_ready()) return; + uint32_t ri; + if(row_ring.pop(ri)){ + char* line=row_data+ri*columns; + for(uint32_t x=cursor_x;x= rows) { + if(cursor_y>=rows){ scroll(); - cursor_y = rows - 1; + cursor_y= rows -1; } } -void KernelConsole::scroll() { - if (!check_ready()) - return; - - scroll_row_offset = (scroll_row_offset + 1) % rows; - - for (unsigned int x = 0; x < columns; x++) { - buffer[(scroll_row_offset + rows - 1) % rows][x] = 0; +void KernelConsole::scroll(){ + if(!check_ready()) return; + uint32_t ri; + if(row_ring.pop(ri)){ + char* line=row_data+ri*columns; + for(uint32_t x=0;x row_ring; + char* row_data; + uint32_t buffer_data_size; }; + extern KernelConsole kconsole; \ No newline at end of file diff --git a/kernel/filesystem/fat32.cpp b/kernel/filesystem/fat32.cpp index 0eeaac57..456750a9 100644 --- a/kernel/filesystem/fat32.cpp +++ b/kernel/filesystem/fat32.cpp @@ -6,6 +6,7 @@ #include "std/string.h" #include "std/memfunctions.h" #include "math/math.h" +#include "data_struct/linked_list.hpp" #define kprintfv(fmt, ...) \ ({ \ @@ -64,7 +65,6 @@ bool FAT32FS::init(uint32_t partition_sector){ kprintf("FAT32 Volume uses %i cluster size", bytes_per_sector); kprintf("Data start at %x",data_start_sector*512); - read_FAT(mbs->reserved_sectors, mbs->sectors_per_fat, mbs->number_of_fats); return true;} diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index a86d25d4..0cde8116 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -180,7 +180,6 @@ bool XHCIDriver::init(){ return false; } } - return true; } diff --git a/kernel/networking/drivers/virtio_net_pci/virtio_net_pci.cpp b/kernel/networking/drivers/virtio_net_pci/virtio_net_pci.cpp index 4011d439..66f63bb8 100644 --- a/kernel/networking/drivers/virtio_net_pci/virtio_net_pci.cpp +++ b/kernel/networking/drivers/virtio_net_pci/virtio_net_pci.cpp @@ -47,6 +47,8 @@ VirtioNetDriver* VirtioNetDriver::try_init(){ return nullptr; } + + bool VirtioNetDriver::init(){ uint64_t addr = find_pci_device(0x1AF4, 0x1000); if (!addr){ @@ -73,14 +75,12 @@ bool VirtioNetDriver::init(){ kprintf_raw("[VIRTIO_NET] Interrupts setup with MSI %i,%i",NET_IRQ,NET_IRQ+1); break; } - pci_enable_device(addr); if (!virtio_init_device(&vnp_net_dev)) { kprintf("[VIRTIO_NET error] Failed network initialization"); return false; } - kprintf("[VIRTIO_NET] Device set up at %x",(uintptr_t)vnp_net_dev.device_cfg); select_queue(&vnp_net_dev, RECEIVE_QUEUE); @@ -109,6 +109,7 @@ bool VirtioNetDriver::init(){ return true; } + void VirtioNetDriver::get_mac(network_connection_ctx *context){ virtio_net_config* net_config = (virtio_net_config*)vnp_net_dev.device_cfg; kprintfv("[VIRTIO_NET] %x:%x:%x:%x:%x:%x", net_config->mac[0], net_config->mac[1], net_config->mac[2], net_config->mac[3], net_config->mac[4], net_config->mac[5]); @@ -184,4 +185,4 @@ void VirtioNetDriver::send_packet(sizedptr packet){ void VirtioNetDriver::enable_verbose(){ verbose = true; -} \ No newline at end of file +} diff --git a/kernel/networking/processes/net_proc.c b/kernel/networking/processes/net_proc.c index 84b7bfdc..81122989 100644 --- a/kernel/networking/processes/net_proc.c +++ b/kernel/networking/processes/net_proc.c @@ -68,7 +68,6 @@ void test_network(){ unbind_port(8888); } - uint32_t negotiate_dhcp(){ kprintf("Sending DHCP request"); network_connection_ctx *ctx = network_get_context(); @@ -130,9 +129,7 @@ uint32_t negotiate_dhcp(){ //DNS (8 bytes) (6) //TODO: Make subsequent DHCP requests (renewals and requests) directed to the server ctx->ip = local_ip; - test_network(); - return lease_time; } @@ -150,4 +147,4 @@ void dhcp_daemon(){ process_t* launch_net_process(){ return create_kernel_process("dhcp_daemon",dhcp_daemon); -} \ No newline at end of file +} diff --git a/shared/data_struct/chunked_list.cpp b/shared/data_struct/chunked_list.cpp new file mode 100644 index 00000000..96ceaa02 --- /dev/null +++ b/shared/data_struct/chunked_list.cpp @@ -0,0 +1,173 @@ +#include "chunked_list.hpp" +#include "console/kio.h" + +extern "C" { + +cchunked_list_t* cchunked_list_create(uint64_t chunkSize){ + uintptr_t raw=malloc(sizeof(cchunked_node_t)+chunkSize*sizeof(void*)); + if(!raw) return NULL; + cchunked_list_t* list=(cchunked_list_t*)malloc(sizeof(cchunked_list_t)); + if(!list){ + free((void*)raw,sizeof(cchunked_node_t)+chunkSize*sizeof(void*)); + return NULL;} + list->chunkSize=chunkSize; + list->length=0; + list->head=(cchunked_node_t*)raw; + list->head->count=0; + list->head->next=NULL; + list->tail=list->head; + return list; +} + +void cchunked_list_destroy(cchunked_list_t* list){ + if(!list) return; + cchunked_node_t* node=list->head; + while(node){ + cchunked_node_t* next=node->next; + free(node,sizeof(cchunked_node_t)+list->chunkSize*sizeof(void*)); + node=next; + } + free(list,sizeof(cchunked_list_t)); +} +cchunked_list_t* cchunked_list_clone(const cchunked_list_t* list){ + if(!list) return NULL; + cchunked_list_t* clone=cchunked_list_create(list->chunkSize); + if(!clone) return NULL; + for(cchunked_node_t* it=list->head;it;it=it->next){ + for(uint64_t i=0;icount;i++) + cchunked_list_push_back(clone,it->data[i]); + } + return clone; +} + +void cchunked_list_push_back(cchunked_list_t* list, void* data){ + if(!list) return; + //first mnode + if(list->tail == NULL){ + uintptr_t m = malloc(sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); + if(!m) return; + cchunked_node_t* node = (cchunked_node_t*)m; + node->count = 0; + node->next = NULL; + list->head=list->tail = node; + } + if(list->tail->count == list->chunkSize){ //last chunk + uintptr_t m = malloc(sizeof(cchunked_node_t)+list->chunkSize * sizeof(void*)); + if(!m) return; + cchunked_node_t* node=(cchunked_node_t*)m; + node->count = 0; + node->next = NULL; + list->tail->next = node; + list->tail = node; + } + list->tail->data[list->tail->count++]=data; + list->length++; +} + +cchunked_node_t* cchunked_list_insert_after(cchunked_list_t* list,cchunked_node_t* node, void* data){ + if(!list) + return NULL; + if(!node){ + cchunked_list_push_back(list, data); + return list->tail; + } + if(node->count < list->chunkSize){//chunk isnt completrly full + node->data[node->count++]=data; + list->length++; + return node; + } + //new node + uintptr_t m = malloc(sizeof(cchunked_node_t) + list->chunkSize*sizeof(void*)); + if(!m) return NULL; + cchunked_node_t* new_node = (cchunked_node_t*)m; + new_node->count =1; + new_node->next = node->next; + new_node->data[0] = data; + + //linking new node + node->next = new_node; + if (list->tail == node) + list->tail = new_node; + list->length++; + return new_node; +} +void* cchunked_list_pop_front(cchunked_list_t* list){ + if(!list || list->length == 0 || list->head == NULL) + return NULL; + void* data = list->head->data[0]; + if(list->head->count > 1){ + for(uint64_t i = 1; i < list->head->count; ++i) + list->head->data[i-1] = list->head->data[i]; + list->head->count--; + }else{ + //uniq element + cchunked_node_t* old =list->head; + list->head = old->next; + if(list->head == NULL){ + list->tail = NULL; + } + free(old, sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); + } + list->length--; + return data; +} + + + +void* cchunked_list_remove_node(cchunked_list_t* list, cchunked_node_t* node){ + if(!list||!node|| !list->head) return NULL; + + //delegate to pop_front + if(node == list->head) + return cchunked_list_pop_front(list); + + cchunked_node_t* prev = list->head; + while(prev->next && prev->next != node) prev= prev->next; + if(prev->next != node) return NULL; + + void* data = node->data[0]; + for(uint64_t i = 1; i < node->count; ++i) + node->data[i-1] = node->data[i]; + node->count--; + list->length--; + if(node->count == 0){ + prev->next = node->next; + if(list->tail == node) list->tail = prev; + free(node, sizeof(cchunked_node_t)+list->chunkSize * sizeof(void*)); + } + + return data; +} + +void cchunked_list_update(cchunked_list_t* list, cchunked_node_t* node, void* new_data){ + (void)list; + if(node&&node->count) node->data[0] = new_data; +} + +uint64_t cchunked_list_length(const cchunked_list_t* list){ + return list ? list->length : 0; +} + +uint64_t cchunked_list_size_bytes(const cchunked_list_t* list){ + if(!list) return 0; + uint64_t nodes = 0; + for(cchunked_node_t* it = list->head; it; it = it->next) nodes++; + return nodes * (sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); +} + +void cchunked_list_for_each(const cchunked_list_t* list, void (*func)(void*)){ + if(!list||!func) return; + for(cchunked_node_t* it = list->head; it; it = it->next) + for(uint64_t i = 0; i < it->count; ++i) + func(it->data[i]); +} +void cchunked_list_update_at(cchunked_list_t* list, cchunked_node_t* node,uint64_t offset,void* new_data){ + if(!list || !node || offset >= node->count)//{ + return; + node->data[offset] = new_data; +} + +int cchunked_list_is_empty(const cchunked_list_t* list){ + return (!list ||list->length == 0) ? 1 : 0; +} +} diff --git a/shared/data_struct/chunked_list.hpp b/shared/data_struct/chunked_list.hpp new file mode 100644 index 00000000..d20c3142 --- /dev/null +++ b/shared/data_struct/chunked_list.hpp @@ -0,0 +1,202 @@ +#pragma once + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern uintptr_t malloc(uint64_t size); +extern void free(void *ptr, uint64_t size); + +typedef struct cchunked_node{ + uint64_t count; + struct cchunked_node* next; + void* data[]; +}cchunked_node_t; + +typedef struct cchunked_list{ + uint64_t chunkSize; + uint64_t length; + cchunked_node_t* head; + cchunked_node_t* tail; +}cchunked_list_t; + +cchunked_list_t* cchunked_list_create(uint64_t chunkSize); +void cchunked_list_destroy(cchunked_list_t* list); +cchunked_list_t* cchunked_list_clone(const cchunked_list_t* list); +void cchunked_list_push_back(cchunked_list_t* list, void* data); +void* cchunked_list_pop_front(cchunked_list_t* list); +cchunked_node_t* cchunked_list_insert_after(cchunked_list_t* list, cchunked_node_t* node, void* data); +void* cchunked_list_remove_node(cchunked_list_t* list, cchunked_node_t* node); +void cchunked_list_update(cchunked_list_t* list, cchunked_node_t* node, void* new_data); +void cchunked_list_update_at(cchunked_list_t* list, cchunked_node_t* node,uint64_t offset, void* new_data); +uint64_t cchunked_list_length(const cchunked_list_t* list); +uint64_t cchunked_list_size_bytes(const cchunked_list_t* list); +void cchunked_list_for_each(const cchunked_list_t* list, void (*func)(void*)); +int cchunked_list_is_empty(const cchunked_list_t* list); + +#ifdef __cplusplus +} +template +class ChunkedList{ +public: + struct Node{ + uint64_t count; + Node* next; + T data[]; + }; + + explicit ChunkedList(uint64_t cs): head(nullptr), tail(nullptr), length_(0), chunkSize(cs){} + ~ChunkedList(){ + while(head){ + Node* nx = head->next; + ::free(head, sizeof(Node) + chunkSize * sizeof(T)); + head = nx; + } + } + + ChunkedList(const ChunkedList& other): head(nullptr), tail(nullptr), length_(0), chunkSize(other.chunkSize){ + for(Node* c = other.head; c; c = c->next) + for(uint64_t i = 0; i < c->count; ++i) + push_back(c->data[i]); + } + + ChunkedList& operator=(const ChunkedList& other){ + if(this != &other){ + clear(); + chunkSize = other.chunkSize; + for(Node* c = other.head; c; c = c->next) + for(uint64_t i = 0; i < c->count; ++i) + push_back(c->data[i]); + } + return *this; + } + + void push_back(const T& value){ + if(!tail) allocFirst(); + if(tail->count == chunkSize) allocChunk(); + tail->data[tail->count++] = value; + ++length_; + } + + T pop_front(){ + if(!head) return T(); + T val = head->data[0]; + if(head->count > 1){ + for(uint64_t i = 1; i < head->count; ++i) + head->data[i-1] = head->data[i]; + --head->count; + }else{ + Node* old = head; + head = head->next; + ::free(old, sizeof(Node) + chunkSize * sizeof(T)); + if(!head) tail = nullptr; + } + --length_; + return val; + } + + Node* insert_after(Node* node, const T& value){ + if(!node){ + push_back(value); + return tail; + } + if(node->count < chunkSize){ + node->data[node->count++] = value; + ++length_; + return node; + } + Node* n=allocNode(value); + n->next = node->next; + node->next = n; + if(tail ==node) tail = n; + ++length_; + return n; + } + +T remove_node(Node* node){ + if(!node|| !head) return T(); + if(node == head){ + T val = head->data[0]; + uint64_t removed = head->count; + Node* nxt = head->next; + ::free(head, sizeof(Node) + chunkSize * sizeof(T)); + head = nxt; + if(!head) tail = nullptr; + length_ -= removed; + return val; + } + Node* prev = head; + while(prev->next && prev->next != node) prev = prev->next; + if(prev->next != node) return T(); + T val = node->data[0]; + uint64_t removed = node->count; + prev->next= node->next; + if(tail==node) tail = prev; + ::free(node, sizeof(Node) + chunkSize * sizeof(T)); + length_ -= removed; + return val; +} + + void update(Node* node, const T& value){ + if (node && node->count) node->data[0] = value; + } + + void update_at(Node* node, uint64_t offset, const T& value){ + if (node && offset < node->count) node->data[offset] = value; + } + + uint64_t size() const noexcept{return length_;} + + uint64_t size_bytes() const noexcept{ + uint64_t nodes = 0; + for (Node* it = head; it; it = it->next) ++nodes; + return nodes * (sizeof(Node) + chunkSize * sizeof(T)); + } + + bool empty() const noexcept{return length_ == 0; } + + template + void for_each(Func f) const{ + for(Node* it = head; it; it = it->next) + for(uint64_t i = 0; i < it->count; ++i) + f(it->data[i]); + } + +private: + Node* head = nullptr; + Node* tail = nullptr; + uint64_t length_ = 0; + uint64_t chunkSize; + + Node* allocNode(const T& value){ + uintptr_t raw= ::malloc(sizeof(Node) + chunkSize * sizeof(T)); + Node* n = reinterpret_cast(raw); + n->count = 1; + n->next = nullptr; + n->data[0] = value; + return n; + } + + void allocFirst(){ + uintptr_t raw = ::malloc(sizeof(Node) +chunkSize*sizeof(T)); + head = tail =reinterpret_cast(raw); + head->count = 0; + head->next = nullptr; + } + + void allocChunk(){ + uintptr_t raw = ::malloc(sizeof(Node)+ chunkSize * sizeof(T)); + Node* n=reinterpret_cast(raw); + n->count = 0; + n->next = nullptr; + tail->next = n; + tail = n; + } + + void clear(){ + while(head) pop_front(); + } +}; +#endif \ No newline at end of file diff --git a/shared/data_struct/circular_linked_list.cpp b/shared/data_struct/circular_linked_list.cpp new file mode 100644 index 00000000..e69de29b diff --git a/shared/data_struct/circular_linked_list.hpp b/shared/data_struct/circular_linked_list.hpp new file mode 100644 index 00000000..e69de29b diff --git a/shared/data_struct/doubly_linked_list.cpp b/shared/data_struct/doubly_linked_list.cpp new file mode 100644 index 00000000..e69de29b diff --git a/shared/data_struct/doubly_linked_list.hpp b/shared/data_struct/doubly_linked_list.hpp new file mode 100644 index 00000000..e69de29b diff --git a/shared/data_struct/linked_list.cpp b/shared/data_struct/linked_list.cpp new file mode 100644 index 00000000..83c6b307 --- /dev/null +++ b/shared/data_struct/linked_list.cpp @@ -0,0 +1,138 @@ +#include "linked_list.hpp" +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +clinkedlist_t *clinkedlist_create(void){ + uintptr_t mem = malloc(sizeof(clinkedlist_t)); + if((void *)mem == NULL) return NULL; + clinkedlist_t *list = (clinkedlist_t *)mem; + list->head = NULL; + list->tail = NULL; + list->length = 0; + return list; +} + +void clinkedlist_destroy(clinkedlist_t *list){ + if(list == NULL) return; + clinkedlist_node_t *node = list->head; + while(node){ + clinkedlist_node_t *next = node->next; + free(node, sizeof(clinkedlist_node_t)); + node = next; + } + free(list, sizeof(clinkedlist_t)); +} + +clinkedlist_t *clinkedlist_clone(const clinkedlist_t *list){ + if(list == NULL) return NULL; + clinkedlist_t *clone = clinkedlist_create(); + if(clone == NULL) return NULL; + clinkedlist_node_t *it = list->head; + while(it){ + if(clone->tail){ + clinkedlist_node_t *new_node = (clinkedlist_node_t *)malloc(sizeof(clinkedlist_node_t)); + new_node->data = it->data; + new_node->next = NULL; + clone->tail->next = new_node; + clone->tail = new_node; + clone->length++; + }else{ + clinkedlist_push_front(clone, it->data); + } + it = it->next; + } + return clone; +} + +void clinkedlist_push_front(clinkedlist_t *list, void *data){ + if(list == NULL) return; + clinkedlist_node_t *node = (clinkedlist_node_t *)malloc(sizeof(clinkedlist_node_t)); + node->data = data; + node->next = list->head; + list->head = node; + if(list->tail == NULL) list->tail = node; + list->length++; +} + +void *clinkedlist_pop_front(clinkedlist_t *list){ + if(list == NULL || list->head== NULL) return NULL; + clinkedlist_node_t *node = list->head; + void *data = node->data; + list->head = node->next; + if (list->head == NULL) list->tail = NULL; + list->length--; + free(node, sizeof(clinkedlist_node_t)); + return data; +} + +clinkedlist_node_t *clinkedlist_insert_after(clinkedlist_t *list, clinkedlist_node_t *node, void *data) { + if(list == NULL) return NULL; + if(node == NULL){ + clinkedlist_push_front(list, data); + return list->head; + } + clinkedlist_node_t *new_node = (clinkedlist_node_t *)malloc(sizeof(clinkedlist_node_t)); + new_node->data = data; + new_node->next = node->next; + node->next = new_node; + if(list->tail == node) list->tail = new_node; + list->length++; + return new_node; +} + +void *clinkedlist_remove(clinkedlist_t *list, clinkedlist_node_t *node){ + if(list == NULL || node == NULL || list->head == NULL) return NULL; + if(node == list->head){ + return clinkedlist_pop_front(list); + } + clinkedlist_node_t *prev = list->head; + while(prev->next && prev->next != node){ + prev = prev->next; + } + if(prev->next != node) return NULL; + prev->next = node->next; + if(node == list->tail) list->tail = prev; + void *data = node->data; + list->length--; + free(node, sizeof(clinkedlist_node_t)); + return data; +} + +void clinkedlist_update(clinkedlist_t *list, clinkedlist_node_t *node, void *new_data){ + (void)list; + if(node) node->data = new_data; +} + +uint64_t clinkedlist_length(const clinkedlist_t *list){ + return list ? list->length : 0; +} + +uint64_t clinkedlist_size_bytes(const clinkedlist_t *list){ + return list ? list->length * sizeof(clinkedlist_node_t) : 0; +} + +clinkedlist_node_t *clinkedlist_find(clinkedlist_t *list, void *key, int (*cmp)(void *, void *)){ + if(list == NULL || cmp == NULL) return NULL; + clinkedlist_node_t *it = list->head; + while(it){ + if(cmp(it->data, key) == 0) return it; + it = it->next; + } + return NULL; +} + +void clinkedlist_for_each(const clinkedlist_t *list, void (*func)(void *)){ + if(list == NULL || func == NULL) return; + clinkedlist_node_t *it = list->head; + while(it){ + func(it->data); + it = it->next; + } +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/shared/data_struct/linked_list.hpp b/shared/data_struct/linked_list.hpp new file mode 100644 index 00000000..0387e237 --- /dev/null +++ b/shared/data_struct/linked_list.hpp @@ -0,0 +1,157 @@ +#pragma once +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif +typedef struct clinkedlist_node{ + void *data; + struct clinkedlist_node *next; +}clinkedlist_node_t; + +typedef struct clinkedlist{ + clinkedlist_node_t *head; + clinkedlist_node_t *tail; + uint64_t length; +}clinkedlist_t; + +extern uintptr_t malloc(uint64_t size); +extern void free(void *ptr, uint64_t size); + +clinkedlist_t *clinkedlist_create(void); +void clinkedlist_destroy(clinkedlist_t *list); +clinkedlist_t *clinkedlist_clone(const clinkedlist_t *list); +void clinkedlist_push_front(clinkedlist_t *list,void *data); +void *clinkedlist_pop_front(clinkedlist_t *list); +clinkedlist_node_t *clinkedlist_insert_after(clinkedlist_t *list, clinkedlist_node_t *node, void *data); +void *clinkedlist_remove(clinkedlist_t *list, clinkedlist_node_t *node); +void clinkedlist_update(clinkedlist_t *list, clinkedlist_node_t *node, void *new_data); +uint64_t clinkedlist_length(const clinkedlist_t *list); +uint64_t clinkedlist_size_bytes(const clinkedlist_t *list); +clinkedlist_node_t *clinkedlist_find(clinkedlist_t *list, void *key,int (*cmp)(void *, void *)); +void clinkedlist_for_each(const clinkedlist_t *list, void (*func)(void *)); + +#ifdef __cplusplus +} + +template class LinkedList{ +private: + struct Node{ + T data; + Node *next; + }; + Node *head = nullptr; + Node *tail = nullptr; + uint64_t length = 0; + + Node *alloc_node(const T &value){ + uintptr_t mem = malloc(sizeof(Node)); + Node *n = reinterpret_cast(mem); + n->data = value; + n->next = nullptr; + return n; + } + void free_node(Node *n){ + free(n, sizeof(Node)); + } + +public: + LinkedList() = default; + + LinkedList(const LinkedList &other){ + for(Node *it = other.head; it; it = it->next){ + push_front(it->data); + } + LinkedList tmp; + while(!empty()){ + tmp.push_front(pop_front()); + } + *this = tmp; + } + + ~LinkedList(){ + while(!empty()) pop_front(); + } + + LinkedList &operator=(const LinkedList &other){ + if(this != &other){ + while(!empty()) pop_front(); + for(Node *it = other.head; it; it = it->next){ + push_front(it->data); + } + LinkedList tmp; + while(!empty()){ + tmp.push_front(pop_front()); + } + head = tmp.head; + tail = tmp.tail; + length = tmp.length; + tmp.head = tmp.tail = nullptr; + tmp.length = 0; + } + return *this; + } + + void push_front(const T &value){ + Node *n = alloc_node(value); + n->next = head; + head = n; + if (tail == nullptr) tail = n; + ++length; + } + + T pop_front(){ + Node *n = head; + head = head->next; + if (head == nullptr) tail = nullptr; + T val = n->data; + free_node(n); + --length; + return val; + } + + Node *insert_after(Node *node, const T &value){ + if(node == nullptr){ + push_front(value); + return head; + } + Node *n = alloc_node(value); + n->next = node->next; + node->next = n; + if(tail == node) tail = n; + ++length; + return n; + } + + T remove(Node *node){ + if(node == nullptr) return T(); + if(node == head) return pop_front(); + Node *prev = head; + while(prev && prev->next != node) prev = prev->next; + if(prev == nullptr) return T(); + prev->next = node->next; + if(node == tail) tail = prev; + T val = node->data; + free_node(node); + --length; + return val; + } + + void update(Node *node, const T &value){ + if(node) node->data = value; + } + + uint64_t size() const{return length;} + bool empty() const{return length == 0; } + Node *begin() const{ return head; } + Node *end() const{ return nullptr;} + template + Node *find(Predicate pred) const{ + for(Node *it = head; it; it = it->next){ + if(pred(it->data)) return it; + } + return nullptr; + } +}; + +#endif diff --git a/shared/data_struct/queue.cpp b/shared/data_struct/queue.cpp new file mode 100644 index 00000000..e69de29b diff --git a/shared/data_struct/queue.hpp b/shared/data_struct/queue.hpp new file mode 100644 index 00000000..e69de29b diff --git a/shared/data_struct/ring_buffer.cpp b/shared/data_struct/ring_buffer.cpp new file mode 100644 index 00000000..281117f6 --- /dev/null +++ b/shared/data_struct/ring_buffer.cpp @@ -0,0 +1,58 @@ +#include "types.h" +#include "ring_buffer.hpp" +#include "std/memfunctions.h" + +void cring_init(struct CRingBuffer* rb, void* storage, uint64_t capacity, uint64_t elem_size){ + rb->buffer = storage; + rb->capacity = capacity; + rb->element_size = elem_size; + rb->head = 0; + rb->tail = 0; + rb->full = 0; +} +uint64_t cring_capacity(const struct CRingBuffer* rb){ + return rb->capacity; +} +int32_t cring_push(struct CRingBuffer* rb, const void* item){ + if (rb->full) return 0; + + uint8_t* base = (uint8_t*)rb->buffer; + void* dest = base + (rb->head * rb->element_size); + + for(uint32_t i = 0; i < rb->element_size; ++i){ + ((uint8_t*)dest)[i] =((const uint8_t*)item)[i]; + } + + rb->head = (rb->head + 1) % rb->capacity; + rb->full = (rb->head == rb->tail); + return 1; +} + +int32_t cring_pop(struct CRingBuffer* rb, void* out){ + if(!rb->full && (rb->head == rb->tail)) return 0; + + uint8_t* base = (uint8_t*)rb->buffer; + void* src = base + (rb->tail * rb->element_size); + + for(uint64_t i = 0; i < rb->element_size; ++i){ + ((uint8_t*)out)[i] = ((uint8_t*)src)[i]; + } + + rb->tail =(rb->tail + 1) % rb->capacity; + rb->full =0; + return 1; +} + +int32_t cring_is_empty(const struct CRingBuffer* rb){ + return (!rb->full && (rb->head == rb->tail)); +} + +int32_t cring_is_full(const struct CRingBuffer* rb){ + return rb->full; +} + +void cring_clear(struct CRingBuffer* rb){ + rb->head = 0; + rb->tail = 0; + rb->full = 0; +} diff --git a/shared/data_struct/ring_buffer.hpp b/shared/data_struct/ring_buffer.hpp new file mode 100644 index 00000000..73b09d5b --- /dev/null +++ b/shared/data_struct/ring_buffer.hpp @@ -0,0 +1,78 @@ +#pragma once +#include "types.h" + +extern "C" { +struct CRingBuffer{ + void* buffer; + uint64_t capacity; //TODO: define size_t as the same size of os architecture + uint64_t element_size; + uint64_t head; + uint64_t tail; + int32_t full; +}; + +void cring_init(struct CRingBuffer* rb, void* storage, uint64_t capacity, uint64_t elem_size); +int32_t cring_push(struct CRingBuffer* rb, const void* item); +int32_t cring_pop(struct CRingBuffer* rb, void* out); +int32_t cring_is_empty(const struct CRingBuffer* rb); +int32_t cring_is_full(const struct CRingBuffer* rb); +void cring_clear(struct CRingBuffer* rb); +uint64_t cring_capacity(const struct CRingBuffer* rb); +} + +template class RingBuffer{ +private: + T data[Capacity]; + uint64_t head = 0; + uint64_t tail = 0; + int32_t full = 0; + +public: + int32_t push(const T& item){ + if(full) return 0; + data[head] = item; + head = (head + 1) % Capacity; + full =(head == tail); + return 1; + } + + int32_t pop(T& out){ + if(is_empty()) return 0; + out = data[tail]; + tail = (tail + 1)% Capacity; + full = 0; + return 1; + } + + int32_t is_empty() const{ + return (!full && (head == tail)); + } + + int32_t is_full() const{ + return full; + } + + void clear(){ + head = tail= 0; + full = 0; + } + + uint64_t size() const{ + if(full) return Capacity; + if(head >= tail) return head - tail; + return Capacity + head - tail; + } + + const T& peek() const{ + return data[tail]; + } + + const T& at(uint32_t index) const{ + return data[(tail + index) % Capacity]; + } + + T& at(uint32_t index){ + return data[(tail + index)% Capacity]; + } + static constexpr uint64_t capacity(){return Capacity;} +}; From 28c285f491f1d11453e5444298b38dad01f6e6f7 Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Sun, 20 Jul 2025 18:58:21 +0200 Subject: [PATCH 060/123] Update Makefile --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 321e3d47..09ca7548 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ user: $(MAKE) -C user kernel: - $(MAKE) -C kernel LOAD_ADDR=$(LOAD_ADDR) XHCI_CTX_SIZE=$(XHCI_CTX_SIZE) + $(MAKE) -C kernel LOAD_ADDR=$(LOAD_ADDR) XHCI_CTX_SIZE=$(XHCI_CTX_SIZE) clean: $(MAKE) -C shared clean @@ -96,4 +96,4 @@ help: make dump disassemble kernel.elf\n\ make install create raspi kernel and mount it on a bootable partition\n\ make prepare-fs create directories for the filesystem\n\ -\n" \ No newline at end of file +\n" From ed32adab074adf6af83f1ccf8643c708ab7de0b3 Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Sun, 20 Jul 2025 19:04:53 +0200 Subject: [PATCH 061/123] Update Makefile --- kernel/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index 1c47cf4a..68ffc091 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -5,7 +5,7 @@ LDFLAGS := $(LDFLAGS_BASE) -T $(shell ls *.ld) --defsym=LOAD_ADDR=$(LOAD_ADDR) C_SRC := $(shell find . -name '*.c') ASM_SRC := $(shell find . -name '*.S') CPP_SRC := $(shell find . -name '*.cpp') -OBJ := $(C_SRC:.c=.o) $(ASM_SRC:.S=.o) $(CPP_SRC:.cpp:.o) +OBJ := $(C_SRC:.c=.o) $(ASM_SRC:.S=.o) $(CPP_SRC:.cpp=.o) OBJL := $(filter-out ./boot.o,$(OBJ)) ELF := ../kernel.elf @@ -26,4 +26,4 @@ $(TARGET): ../shared/libshared.a $(OBJ) $(CC) $(CFLAGS) -fno-rtti -c $< -o $@ clean: - rm -f $(OBJ) $(ELF) $(TARGET) \ No newline at end of file + rm -f $(OBJ) $(ELF) $(TARGET) From f69363cdca8b54e6b3ef6dd6e97758ee94efa803 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 21 Jul 2025 00:00:00 +0000 Subject: [PATCH 062/123] Read correct register size in pci --- kernel/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/pci.c b/kernel/pci.c index 65b3801e..eca816d8 100644 --- a/kernel/pci.c +++ b/kernel/pci.c @@ -224,7 +224,7 @@ uint64_t find_pci_device(uint32_t vendor_id, uint32_t device_id) { for (uint32_t slot = 0; slot < PCI_SLOT_MAX; slot++) { for (uint32_t func = 0; func < PCI_FUNC_MAX; func++) { uint64_t device_address = pci_make_addr(bus, slot, func, 0x00); - uint64_t vendor_device = read(device_address); + uint64_t vendor_device = read32(device_address); if ((vendor_device & 0xFFFF) == vendor_id && ((vendor_device >> 16) & 0xFFFF) == device_id) { kprintf("[PCI] Found device at bus %i, slot %i, func %i", bus, slot, func); From 6a70547e503df22ba2a2df6578c9d5d9045f829a Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 21 Jul 2025 00:00:00 +0000 Subject: [PATCH 063/123] Don't try to enable other GPUs for RPI --- kernel/graph/graphics.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/graph/graphics.cpp b/kernel/graph/graphics.cpp index c59fa1ac..ba3e632a 100644 --- a/kernel/graph/graphics.cpp +++ b/kernel/graph/graphics.cpp @@ -14,10 +14,12 @@ static bool _gpu_ready; GPUDriver *gpu_driver; void gpu_init(gpu_size preferred_screen_size){ - if (VirtioGPUDriver *vgd = VirtioGPUDriver::try_init(preferred_screen_size)){ - gpu_driver = vgd; - } else if (RamFBGPUDriver *rfb = RamFBGPUDriver::try_init(preferred_screen_size)){ - gpu_driver = rfb; + if (BOARD_TYPE == 1){ + if (VirtioGPUDriver *vgd = VirtioGPUDriver::try_init(preferred_screen_size)){ + gpu_driver = vgd; + } else if (RamFBGPUDriver *rfb = RamFBGPUDriver::try_init(preferred_screen_size)){ + gpu_driver = rfb; + } } else if (BOARD_TYPE == 2){ gpu_driver = VideoCoreGPUDriver::try_init(preferred_screen_size); } From 40b6cfed233b87d29d336bd43929c735a6db4fe3 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 21 Jul 2025 00:00:00 +0000 Subject: [PATCH 064/123] Do not attempt to enable virtio net on rpi --- kernel/networking/network_dispatch.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/networking/network_dispatch.cpp b/kernel/networking/network_dispatch.cpp index 01066c65..f1a1ba8c 100644 --- a/kernel/networking/network_dispatch.cpp +++ b/kernel/networking/network_dispatch.cpp @@ -12,6 +12,7 @@ #include "net/icmp.h" #include "memory/page_allocator.h" #include "std/memfunctions.h" +#include "hw/hw.h" NetworkDispatch::NetworkDispatch(){ ports = IndexMap(UINT16_MAX); @@ -21,7 +22,7 @@ NetworkDispatch::NetworkDispatch(){ } NetDriver* NetworkDispatch::select_driver(){ - return VirtioNetDriver::try_init(); + return BOARD_TYPE == 1 ? VirtioNetDriver::try_init() : 0x0; } bool NetworkDispatch::init(){ From c9cf5b3e82ad4e6eb682414d3b8a893416941f52 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 21 Jul 2025 00:00:00 +0000 Subject: [PATCH 065/123] [xHCI] Check if driver uses interrupts rather than hardcoding device type checks --- kernel/input/input_dispatch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/input/input_dispatch.cpp b/kernel/input/input_dispatch.cpp index 678381a5..305c9c09 100644 --- a/kernel/input/input_dispatch.cpp +++ b/kernel/input/input_dispatch.cpp @@ -88,7 +88,7 @@ bool is_new_keypress(keypress* current, keypress* previous) { } bool sys_read_input(int pid, keypress *out){ - if (BOARD_TYPE == 2 && input_driver) + if (!input_driver->use_interrupts) input_driver->poll_inputs(); process_t *process = get_proc_by_pid(pid); if (process->input_buffer.read_index == process->input_buffer.write_index) return false; From b95807982652391a17b16e3db9b29c9f2cdd89f4 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 21 Jul 2025 00:00:00 +0000 Subject: [PATCH 066/123] [xHCI] restored old timeout of 2 seconds for events --- kernel/input/xhci.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index 3c8dda82..fce54b66 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -307,7 +307,7 @@ bool XHCIDriver::await_response(uint64_t command, uint32_t type){ } for (; event_ring.index < MAX_TRB_AMOUNT; event_ring.index++){ last_event = &event_ring.ring[event_ring.index]; - if (!wait(&last_event->control, event_ring.cycle_bit, true, 20000)){ + if (!wait(&last_event->control, event_ring.cycle_bit, true, 2000)){ kprintf("[xHCI error] Timeout awaiting response to %x command of type %x", command, type); awaited_type = 0; return false; From 34930ee30773705c325c183c01cccba6799a41f4 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 21 Jul 2025 00:00:00 +0000 Subject: [PATCH 067/123] [xHCI] more fail condition logs --- kernel/input/xhci.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index fce54b66..9d361081 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -171,8 +171,10 @@ bool XHCIDriver::init(){ kprintfv("[xHCI] command ring allocated at %x. crcr now %x",(uintptr_t)command_ring.ring, op->crcr); - if (!enable_events()) + if (!enable_events()){ + kprintf("[xHCI error] failed to enable events"); return false; + } kprintfv("[xHCI] event configuration finished"); From cc34c72abaf9d4159fa2afb1131453727949b924 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 21 Jul 2025 00:00:00 +0000 Subject: [PATCH 068/123] [xHCI] Fixes for PCI --- kernel/input/USBKeyboard.cpp | 1 - kernel/input/xhci.cpp | 16 +++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/kernel/input/USBKeyboard.cpp b/kernel/input/USBKeyboard.cpp index a37d5760..dd98cc39 100644 --- a/kernel/input/USBKeyboard.cpp +++ b/kernel/input/USBKeyboard.cpp @@ -12,7 +12,6 @@ void USBKeyboard::request_data(USBDriver *driver){ } if (!driver->poll(slot_id, endpoint, buffer, packet_size)){ - return; } diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index 9d361081..c1cefb54 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -59,11 +59,13 @@ bool XHCIDriver::check_fatal_error() { bool XHCIDriver::init(){ uint64_t addr, mmio, mmio_size; + bool use_pci = false; if (XHCI_BASE){ addr = XHCI_BASE; mmio = addr; } else if (PCI_BASE) { addr = find_pci_device(0x1B36, 0xD); + use_pci = true; } if (!addr){ kprintf_raw("[PCI] xHCI device not found"); @@ -71,16 +73,16 @@ bool XHCIDriver::init(){ } kprintfv("[xHCI] init"); - if (PCI_BASE){ + if (use_pci){ if (!(*(uint16_t*)(addr + 0x06) & (1 << 4))){ - kprintfv("[xHCI] Wrong capabilities list"); + kprintf("[xHCI] Wrong capabilities list"); return false; } pci_enable_device(addr); if (!pci_setup_bar(addr, 0, &mmio, &mmio_size)){ - kprintfv("[xHCI] BARs not set up"); + kprintf("[xHCI] BARs not set up"); return false; } @@ -89,13 +91,13 @@ bool XHCIDriver::init(){ uint8_t interrupts_ok = pci_setup_interrupts(addr, INPUT_IRQ, 1); switch(interrupts_ok){ case 0: - kprintf_raw("[xHCI] Failed to setup interrupts"); + kprintf("[xHCI] Failed to setup interrupts"); return false; case 1: - kprintf_raw("[xHCI] Interrupts setup with MSI-X %i",INPUT_IRQ); + kprintf("[xHCI] Interrupts setup with MSI-X %i",INPUT_IRQ); break; default: - kprintf_raw("[xHCI] Interrupts setup with MSI %i",INPUT_IRQ); + kprintf("[xHCI] Interrupts setup with MSI %i",INPUT_IRQ); break; } @@ -196,7 +198,7 @@ bool XHCIDriver::init(){ continue; } if (!setup_device(0,i)){ - kprintf_raw("[xHCI] Failed to configure device at port %i",i); + kprintf("[xHCI] Failed to configure device at port %i",i); } } From 691e25a89ea33de62d38671fd7b5fe6d718ddcf8 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 21 Jul 2025 00:00:00 +0000 Subject: [PATCH 069/123] [PCI] enable for PI 5 --- kernel/hw/hw.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/hw/hw.c b/kernel/hw/hw.c index e9636a33..847d7f0d 100644 --- a/kernel/hw/hw.c +++ b/kernel/hw/hw.c @@ -54,6 +54,7 @@ void detect_hardware(){ SDHCI_BASE = MMIO_BASE + 0xFFF000UL; UART0_BASE = MMIO_BASE + 0x1001000; XHCI_BASE = 0x1F00300000UL; + PCI_BASE = 0x1000120000UL; break; default: RPI_BOARD = 3; From 79b79a7c6402cc33fdfc80728e66da5a20275bca Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Mon, 21 Jul 2025 00:00:00 +0000 Subject: [PATCH 070/123] [PCI, FAIL] Setup MSIX for RP1 --- kernel/input/xhci.cpp | 9 ++-- kernel/kernel.c | 3 ++ kernel/pci.c | 98 +++++++++++++++++++++++++++++++++++++++++++ kernel/pci.h | 3 ++ 4 files changed, 110 insertions(+), 3 deletions(-) diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index c1cefb54..3e1ef135 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -63,6 +63,8 @@ bool XHCIDriver::init(){ if (XHCI_BASE){ addr = XHCI_BASE; mmio = addr; + if (BOARD_TYPE == 2 && RPI_BOARD >= 5) + use_interrupts = pci_setup_msi_rp1(36, true); } else if (PCI_BASE) { addr = find_pci_device(0x1B36, 0xD); use_pci = true; @@ -92,12 +94,15 @@ bool XHCIDriver::init(){ switch(interrupts_ok){ case 0: kprintf("[xHCI] Failed to setup interrupts"); - return false; + use_interrupts = false; + break; case 1: kprintf("[xHCI] Interrupts setup with MSI-X %i",INPUT_IRQ); + use_interrupts = true; break; default: kprintf("[xHCI] Interrupts setup with MSI %i",INPUT_IRQ); + use_interrupts = true; break; } @@ -278,8 +283,6 @@ bool XHCIDriver::enable_events(){ op->usbsts = 1 << 3;//Enable interrupts interrupter->iman |= 1;//Clear pending interrupts - use_interrupts = true; - return !check_fatal_error(); } diff --git a/kernel/kernel.c b/kernel/kernel.c index e27ee4af..101d43e7 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -54,6 +54,9 @@ void kernel_main() { kprintf("GPU initialized"); kprintf("Initializing disk..."); + + if (BOARD_TYPE == 2 && RPI_BOARD >= 5) + pci_setup_rp1(); // disk_verbose(); if (!find_disk()) diff --git a/kernel/pci.c b/kernel/pci.c index eca816d8..2eebd9da 100644 --- a/kernel/pci.c +++ b/kernel/pci.c @@ -258,6 +258,104 @@ void pci_register(uint64_t mmio_addr, uint64_t mmio_size){ register_device_memory(addr,addr); } +#pragma region Interrupts + +#define RP1_INT_PCI_MASK_CLR 0x4514 +#define RP1_INT_PCI_BAR_L 0x4044 +#define RP1_INT_PCI_BAR_H 0x4048 +#define RP1_INT_PCI_CONFIG 0x404c + +#define RP1_MSI_BAR_TRANSL_VIRT_L 0x402c +#define RP1_MSI_BAR_TRANSL_VIRT_H 0x4030 +#define RP1_MSI_BAR_TRANSL_PHYS_L 0x40ac +#define RP1_MSI_BAR_TRANSL_PHYS_H 0x40b0 + +#define RP1_INT_BASE 0x1F00108000UL + +#define IRQ_NUMBER__MASK 0x3FF +#define IRQ_EDGE_TRIG__MASK 0x400 +#define IRQ_FROM_RP1__MASK 0x800 + +#define MSIX_CFG(irq) (0x008 + (irq)*4) +#define MSIX_CFG_ENABLE (1ULL << 0) +#define MSIX_CFG_TEST (1ULL << 1) +#define MSIX_CFG_IACK (1ULL << 2) +#define MSIX_CFG_IACK_ENABLE (1ULL << 3) + +#define RP1_INT_SET (RP1_INT_BASE + 0x800) +#define RP1_INT_CLR (RP1_INT_BASE + 0xC00) +#define RP1_INT_STAT_LOW (RP1_INT_BASE + 0x108) +#define RP1_INT_STAT_HIGH (RP1_INT_BASE + 0x10C) + +bool pci_setup_rp1() { + uint64_t pci_addr = find_pci_device(0x1de4,1); + // dump_pci_config(pci_addr); + kprintf("RP1 %x",pci_addr); + uint8_t cap_ptr = read8(pci_addr + 0x34); + while (cap_ptr) { + uint8_t cap_id = read8(pci_addr + cap_ptr); + if (cap_id == PCI_CAPABILITY_MSIX){ + uint16_t msg_ctrl = read16(pci_addr + cap_ptr + 0x2); + kprintf("Enabled? %x",(msg_ctrl >> 15) & 1); + msg_ctrl |= (1 << 15); // Clear MSI-X Enable bit + write16(pci_addr + cap_ptr + 0x2, msg_ctrl); + msg_ctrl = read16(pci_addr + cap_ptr + 0x2); + kprintf("Enabled? %x",(msg_ctrl >> 15) & 1); + } + cap_ptr = read8(pci_addr + cap_ptr + 1); + } + uint64_t bar_addr = pci_get_bar_address(pci_addr, PCI_BAR_BASE_OFFSET, 1); + uint64_t bar_addr2 = pci_get_bar_address(pci_addr, PCI_BAR_BASE_OFFSET, 2); + + uintptr_t msi_pci_addr = 0xFFFFFFF000UL; + uintptr_t msi_phys_addr = 0x1000130000UL; + + //Translate pci address to phys address + + write32(pci_addr + RP1_MSI_BAR_TRANSL_VIRT_L, (msi_pci_addr & 0xFFFFFFFF) | 0x1C); + write32(pci_addr + RP1_MSI_BAR_TRANSL_VIRT_H, (msi_pci_addr >> 32) & 0xFFFFFFFF); + write32(pci_addr + RP1_MSI_BAR_TRANSL_PHYS_L, (msi_phys_addr & 0xFFFFFFFF) | 1); + write32(pci_addr + RP1_MSI_BAR_TRANSL_PHYS_H, (msi_phys_addr >> 32) & 0xFFFFFFFF); + + write32(pci_addr + RP1_INT_PCI_MASK_CLR, UINT32_MAX);//Unmask all interrupts + write32(pci_addr + RP1_INT_PCI_BAR_L, (msi_pci_addr & UINT32_MAX) | 1);//Set address and enable + write32(pci_addr + RP1_INT_PCI_BAR_H, (msi_pci_addr >> 32) & UINT32_MAX); + write32(pci_addr + RP1_INT_PCI_CONFIG, 0xffe03210);//ffe0 32 messages, 3210 arbitrary unique value + + for (int i = 0; i < 6; i++) + kprintf("BAR %i = %x",i,pci_read_address_bar(pci_addr, i)); + kprintf("INTa? %i",read8 (pci_addr + 0x3D)); + kprintf("CMD %b",read16(pci_addr + PCI_COMMAND_REGISTER)); + + return true; + +} + +bool pci_setup_msi_rp1(uint8_t irq_line, bool edge_triggered) { + + kprintf("Sanity 1 %i",read32(0x1F00108000)); + + if (edge_triggered) + write32(RP1_INT_CLR + MSIX_CFG(irq_line), MSIX_CFG_IACK_ENABLE); + else + write32(RP1_INT_SET + MSIX_CFG(irq_line), MSIX_CFG_IACK_ENABLE); + + kprintf("Sanity 2 %i",read32(RP1_INT_SET + MSIX_CFG(irq_line))); + kprintf("Sanity 3 %i",read32(RP1_INT_CLR + MSIX_CFG(irq_line))); + + write32(RP1_INT_SET + MSIX_CFG(irq_line), MSIX_CFG_ENABLE); + + kprintf("Sanity 4 %i",read32(RP1_INT_SET + MSIX_CFG(irq_line))); + + write32(RP1_INT_SET + MSIX_CFG(irq_line), MSIX_CFG_TEST); + + kprintf("Sanity 5 %i",read32(RP1_INT_SET + MSIX_CFG(irq_line))); + + kprintf("Fired? %b", read32(RP1_INT_STAT_HIGH) << 32 | read32(RP1_INT_STAT_LOW)); + + return true; +} + bool pci_setup_msi(uint64_t pci_addr, uint8_t irq_line) { uint8_t cap_ptr = read8(pci_addr + 0x34); while (cap_ptr) { diff --git a/kernel/pci.h b/kernel/pci.h index 128aeacd..3c800afc 100644 --- a/kernel/pci.h +++ b/kernel/pci.h @@ -24,6 +24,9 @@ bool pci_setup_msi(uint64_t pci_addr, uint8_t irq_vector); uint8_t pci_setup_interrupts(uint64_t pci_addr, uint8_t irq_line, uint8_t amount); +bool pci_setup_rp1(); +bool pci_setup_msi_rp1(uint8_t irq_line, bool edge_triggered); + typedef struct { uint32_t addr_offset; uint8_t irq_num; From 9a229f028ce954367977c59ae2d48dfe2163da7d Mon Sep 17 00:00:00 2001 From: CodeAnarchist Date: Tue, 22 Jul 2025 01:04:03 +0200 Subject: [PATCH 071/123] queues and double linkedlist --- shared/data_struct/circular_linked_list.cpp | 0 shared/data_struct/circular_linked_list.hpp | 0 shared/data_struct/doubly_linked_list.cpp | 181 +++++++++++++++ shared/data_struct/doubly_linked_list.hpp | 234 ++++++++++++++++++++ shared/data_struct/linked_list.hpp | 2 +- shared/data_struct/queue.cpp | 70 ++++++ shared/data_struct/queue.hpp | 45 ++++ 7 files changed, 531 insertions(+), 1 deletion(-) delete mode 100644 shared/data_struct/circular_linked_list.cpp delete mode 100644 shared/data_struct/circular_linked_list.hpp diff --git a/shared/data_struct/circular_linked_list.cpp b/shared/data_struct/circular_linked_list.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/shared/data_struct/circular_linked_list.hpp b/shared/data_struct/circular_linked_list.hpp deleted file mode 100644 index e69de29b..00000000 diff --git a/shared/data_struct/doubly_linked_list.cpp b/shared/data_struct/doubly_linked_list.cpp index e69de29b..8623c6bd 100644 --- a/shared/data_struct/doubly_linked_list.cpp +++ b/shared/data_struct/doubly_linked_list.cpp @@ -0,0 +1,181 @@ +#include "doubly_linked_list.hpp" + +cdouble_linked_list_t* cdouble_linked_list_create(void){ + uintptr_t raw= malloc((uint64_t)sizeof(cdouble_linked_list_t));//i believe that casting sizeof is better until size_t is defined correctly + if(raw == 0) return NULL; + cdouble_linked_list_t *list=(cdouble_linked_list_t*)raw; + list->head = list->tail =NULL; + list->length = 0; + return list; +} + +void cdouble_linked_list_destroy(cdouble_linked_list_t *list){ + if(!list) return; + cdouble_linked_list_node_t *node=list->head; + for(uint64_t i = 0; i < list->length; ++i){ + cdouble_linked_list_node_t *next = node->next; + free(node,(uint64_t)sizeof(cdouble_linked_list_node_t)); + node = next; + } + free(list, (uint64_t)sizeof(cdouble_linked_list_t)); +} + +cdouble_linked_list_t* cdouble_linked_list_clone(const cdouble_linked_list_t *list){ //could create data aliasing. be careful. TODO + if(!list) return NULL; + cdouble_linked_list_t *clone=cdouble_linked_list_create(); + if(!clone) return NULL; + cdouble_linked_list_node_t *it =list->head; + for(uint64_t i = 0; ilength; ++i){ + uintptr_t raw =malloc((uint64_t)sizeof(cdouble_linked_list_node_t)); + if(raw) { + cdouble_linked_list_node_t *node =(cdouble_linked_list_node_t*)raw; + node->data = it->data; + if(clone->length == 0){ + node->next=node->prev = node; + clone->head=clone->tail = node; + }else{ + node->prev=clone->tail; + node->next=clone->head; + clone->tail->next=node; + clone->head->prev= node; + clone->tail =node; + } + ++clone->length; + } + it = it->next; + } + return clone; +} + +void cdouble_linked_list_push_front(cdouble_linked_list_t *list, void *data){ + if(!list) return; + uintptr_t raw= malloc((uint64_t)sizeof(cdouble_linked_list_node_t)); + if(raw == 0) return; + cdouble_linked_list_node_t *node=(cdouble_linked_list_node_t*)raw; + node->data = data; + if(list->length == 0){ + node->next=node->prev = node; + list->head=list->tail = node; + }else{ + node->next=list->head; + node->prev=list->tail; + list->head->prev= node; + list->tail->next= node; + list->head= node; + } + ++list->length; +} + +void cdouble_linked_list_push_back(cdouble_linked_list_t* list, void* data){ + if(!list) return; + uintptr_t raw=malloc((uint64_t)sizeof(cdouble_linked_list_node_t)); + if(raw ==0) return; + cdouble_linked_list_node_t* node=(cdouble_linked_list_node_t*)raw; + node->data=data; + if(list->length==0){ + node->next=node->prev=node; + list->head=list->tail = node; + }else{ + node->prev= list->tail; + node->next=list->head; + list->tail->next=node; + list->head->prev=node; + list->tail =node; + } + ++list->length; +} + +void* cdouble_linked_list_pop_front(cdouble_linked_list_t* list){ + if(!list||list->length==0) return NULL; + cdouble_linked_list_node_t* node=list->head; + void* data=node->data; + if(list->length == 1){ + list->head=list->tail=NULL; + }else{ + list->head=node->next; + list->head->prev =list->tail; + list->tail->next=list->head; + } + --list->length; + free(node,(uint64_t)sizeof(cdouble_linked_list_node_t)); + return data; +} + +void* cdouble_linked_list_pop_back(cdouble_linked_list_t* list){ + if(!list||list->length==0) return NULL; + cdouble_linked_list_node_t* node=list->tail; + void* data=node->data; + if(list->length==1){ + list->head = list->tail=NULL; + }else{ + list->tail=node->prev; + list->tail->next=list->head; + list->head->prev=list->tail; + } + --list->length; + free(node, (uint64_t)sizeof(cdouble_linked_list_node_t)); + return data; +} + +cdouble_linked_list_node_t* cdouble_linked_list_insert_after(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* data){ + if(!list) return NULL; + if(!node){ + cdouble_linked_list_push_front(list, data); + return list->head; + } + uintptr_t raw=malloc((uint64_t)sizeof(cdouble_linked_list_node_t)); + if(raw==0) return NULL; + cdouble_linked_list_node_t* new_node=(cdouble_linked_list_node_t*)raw; + new_node->data=data; + new_node->next= node->next; + new_node->prev=node; + node->next->prev= new_node; + node->next= new_node; + if(list->tail == node) list->tail=new_node; + ++list->length; + return new_node; +} + +cdouble_linked_list_node_t* cdouble_linked_list_insert_before(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* data){ + if(!list) return NULL; + if(!node){ + cdouble_linked_list_push_back(list, data); + return list->tail; + } + return cdouble_linked_list_insert_after(list, node->prev, data); +} + +void* cdouble_linked_list_remove(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node){ + if(!list|| !node|| list->length==0) return NULL; + if(node==list->head) return cdouble_linked_list_pop_front(list); + if(node==list->tail) return cdouble_linked_list_pop_back(list); + node->prev->next=node->next; + node->next->prev=node->prev; + void* data=node->data; + --list->length; + free(node,(uint64_t)sizeof(cdouble_linked_list_node_t)); + return data; +} + +void cdouble_linked_list_update(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* new_data){ + (void)list; + if(node) node->data=new_data; +} + +uint64_t cdouble_linked_list_length(const cdouble_linked_list_t* list){ + return list?list-> length:0; +} + +uint64_t cdouble_linked_list_size_bytes(const cdouble_linked_list_t* list){ + return list?list-> length*sizeof(cdouble_linked_list_node_t):0; +} + +cdouble_linked_list_node_t* cdouble_linked_list_find(cdouble_linked_list_t* list, void* key, int (*cmp)(void*,void*)){ + if(!list||!cmp|| list->length==0) return NULL; + cdouble_linked_list_node_t* it=list->head; + for(uint64_t i=0; ilength; ++i){ + if(cmp(it->data,key)==0) return it; + it=it->next; + } + return NULL; +} diff --git a/shared/data_struct/doubly_linked_list.hpp b/shared/data_struct/doubly_linked_list.hpp index e69de29b..1c6d045e 100644 --- a/shared/data_struct/doubly_linked_list.hpp +++ b/shared/data_struct/doubly_linked_list.hpp @@ -0,0 +1,234 @@ +#pragma once +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct cdouble_linked_list_node{ + void *data; + struct cdouble_linked_list_node *next; + struct cdouble_linked_list_node *prev; +}cdouble_linked_list_node_t; + +typedef struct cdouble_linked_list{ + cdouble_linked_list_node_t *head; + cdouble_linked_list_node_t *tail; + uint64_t length; +}cdouble_linked_list_t; + +extern uintptr_t malloc(uint64_t size); +extern void free(void *ptr, uint64_t size); + +cdouble_linked_list_t *cdouble_linked_list_create(void); +void cdouble_linked_list_destroy(cdouble_linked_list_t *list); +cdouble_linked_list_t *cdouble_linked_list_clone(const cdouble_linked_list_t *list); +void cdouble_linked_list_push_front(cdouble_linked_list_t *list, void *data); +void cdouble_linked_list_push_back(cdouble_linked_list_t *list, void *data); +void *cdouble_linked_list_pop_front(cdouble_linked_list_t *list); +void *cdouble_linked_list_pop_back(cdouble_linked_list_t *list); +cdouble_linked_list_node_t *cdouble_linked_list_insert_after(cdouble_linked_list_t *list, cdouble_linked_list_node_t *node, void *data); +cdouble_linked_list_node_t *cdouble_linked_list_insert_before(cdouble_linked_list_t *list, cdouble_linked_list_node_t *node, void *data); +void *cdouble_linked_list_remove(cdouble_linked_list_t *list, cdouble_linked_list_node_t *node); +void cdouble_linked_list_update(cdouble_linked_list_t *list, cdouble_linked_list_node_t *node, void *new_data); +uint64_t cdouble_linked_list_length(const cdouble_linked_list_t *list); +uint64_t cdouble_linked_list_size_bytes(const cdouble_linked_list_t *list); +cdouble_linked_list_node_t* cdouble_linked_list_find(cdouble_linked_list_t *list, void *key, int (*cmp)(void *, void *)); +#ifdef __cplusplus +} + +template +class LinkedList{ +private: + struct Node{ + T data; + Node *next; + Node *prev; + }; + + Node *head; + Node *tail; + uint64_t length; + + Node* alloc_node(const T& value){ + uintptr_t raw= malloc((uint64_t)sizeof(Node)); + if(raw == 0) return nullptr; + Node* n =(Node*)raw; + n->data=value; + n->next=n->prev=nullptr; + return n; + } + void free_node(Node* n){ + if(!n) return; + free(n,(uint64_t)sizeof(Node)); + } + + static void swap(LinkedList& a, LinkedList& b) noexcept{ + Node* tmp_head = a.head; + a.head= b.head; + b.head= tmp_head; + Node* tmp_tail =a.tail; + a.tail= b.tail; + b.tail= tmp_tail; + uint64_t tmp_length = a.length; + a.length = b.length; + b.length = tmp_length; + } + +public: + LinkedList():head(nullptr), tail(nullptr), length(0){} + + LinkedList(const LinkedList& other):head(nullptr), tail(nullptr), length(0){ + if(other.head){ + Node* it = other.head; + do{ + push_back(it->data); + it = it->next; + }while(it != other.head); + } + } + + ~LinkedList(){ + while(!empty()) pop_front(); + } + + LinkedList& operator=(const LinkedList& other){ + if(this != &other){ + LinkedList tmp(other); + swap(*this, tmp); + } + return *this; + } + + void push_front(const T& value){ + Node* n = alloc_node(value); + if(!n) return; + if(!head){ + head = tail = n; + n->next = n->prev = n; + }else{ + n->next= head; + n->prev= tail; + head->prev=n; + tail->next= n; + head= n; + } + ++length; + } + + void push_back(const T& value){ + Node* n =alloc_node(value); + if(!n) return; + if(!tail){ + head = tail = n; + n->next = n->prev = n; + }else{ + n->prev = tail; + n->next = head; + tail->next = n; + head->prev = n; + tail = n; + } + ++length; + } + + T pop_front(){ + if(!head) return T(); + Node* n = head; + T val = n->data; + if(head == tail){ + head =tail=nullptr; + }else{ + head = head->next; + head->prev = tail; + tail->next = head; + } + --length; + free_node(n); + return val; + } + + T pop_back(){ + if(!tail) return T(); + Node* n = tail; + T val = n->data; + if(head == tail){ + head = tail = nullptr; + }else{ + tail = tail->prev; + tail->next = head; + head->prev = tail; + } + --length; + free_node(n); + return val; + } + + Node* insert_after(Node* node, const T& value){ + if(!node){ + push_front(value); + return head; + } + Node* n= alloc_node(value); + if(!n) return nullptr; + n->next=node->next; + n->prev=node; + node->next->prev = n; + node->next= n; + if(tail==node) tail = n; + ++length; + return n; + } + + Node* insert_before(Node* node, const T& value){ + if(!node){ + push_back(value); + return tail; + } + return insert_after(node->prev, value); + } + + T remove(Node* node){ + if(!node) return T(); + if(node == head) return pop_front(); + if(node == tail) return pop_back(); + node->prev->next=node->next; + node->next->prev=node->prev; + T val=node->data; + --length; + free_node(node); + return val; + } + + void update(Node* node, const T& value){ + if(!node) return; + node->data = value; + } + + uint64_t size()const{return length;} + bool empty() const{return length==0;} + Node* begin() const{return head;} + Node* end() const{return nullptr;} + + template + Node* find(Predicate pred) const{ + if(!head) return nullptr; + Node* it=head; + do{ + if(pred(it->data)) return it; + it=it->next; + }while(it != head); + return nullptr; + } + + template + void for_each(Func func) const{ + if(!head) return; + Node* it = head; + do{ + func(it->data); + it = it->next; + }while(it != head); + } +}; +#endif diff --git a/shared/data_struct/linked_list.hpp b/shared/data_struct/linked_list.hpp index 0387e237..c865d37a 100644 --- a/shared/data_struct/linked_list.hpp +++ b/shared/data_struct/linked_list.hpp @@ -28,7 +28,7 @@ void *clinkedlist_remove(clinkedlist_t *list, clinkedlist_node_t *node); void clinkedlist_update(clinkedlist_t *list, clinkedlist_node_t *node, void *new_data); uint64_t clinkedlist_length(const clinkedlist_t *list); uint64_t clinkedlist_size_bytes(const clinkedlist_t *list); -clinkedlist_node_t *clinkedlist_find(clinkedlist_t *list, void *key,int (*cmp)(void *, void *)); +clinkedlist_node_t *clinkedlist_find(clinkedlist_t *list, void *key,int (*cmp)(void *, void *));//so not const function doesnt rise an annoyng warning void clinkedlist_for_each(const clinkedlist_t *list, void (*func)(void *)); #ifdef __cplusplus diff --git a/shared/data_struct/queue.cpp b/shared/data_struct/queue.cpp index e69de29b..d5a9fa58 100644 --- a/shared/data_struct/queue.cpp +++ b/shared/data_struct/queue.cpp @@ -0,0 +1,70 @@ +#include "queue.hpp" +#include "std/memfunctions.h" + +void cqueue_init(CQueue* q,uint64_t max_capacity,uint64_t elem_size){ + q->buffer = NULL; + q->capacity = max_capacity; + q->max_capacity = max_capacity; + q->elem_size = elem_size; + q->head = q->tail = q->length = 0; + if(max_capacity>0){ + uintptr_t b = malloc(max_capacity*elem_size); + if(b) q->buffer = (void*)b; + } +} + +int32_t cqueue_enqueue(CQueue* q,const void* item){ + if(!q) return 0; + if(q->max_capacity>0){ + if(q->length==q->capacity) return 0; + } else { + if(q->length==q->capacity){ + uint64_t nc = q->capacity>0 ? q->capacity*2 : 4; + uintptr_t nb = malloc(nc*q->elem_size); + if(!nb) return 0; + void* newb = (void*)nb; + for(uint64_t i=0;ilength;++i){ + uint64_t idx = (q->tail + i)%q->capacity; + memcpy((uint8_t*)newb + i*q->elem_size, + (uint8_t*)q->buffer + idx*q->elem_size, + q->elem_size); + } + if(q->buffer) free(q->buffer,q->capacity*q->elem_size); + q->buffer=newb; + q->capacity=nc; + q->head=q->length; + q->tail=0; + } + } + memcpy((uint8_t*)q->buffer + q->head*q->elem_size, + item,q->elem_size); + q->head = (q->head+1)%q->capacity; + q->length++; + return 1; +} + +int32_t cqueue_dequeue(CQueue* q,void* out){ + if(!q||q->length==0) return 0; + memcpy(out,(uint8_t*)q->buffer + q->tail*q->elem_size,q->elem_size); + q->tail = (q->tail+1)%q->capacity; + q->length--; + return 1; +} + +int32_t cqueue_is_empty(const CQueue* q){ + return (!q || q->length==0) ? 1 : 0; +} + +uint64_t cqueue_size(const CQueue* q){ + return q ? q->length : 0; +} + +void cqueue_clear(CQueue* q){ + if(!q) return; + q->head=q->tail=q->length=0; +} + +void cqueue_destroy(CQueue* q){ + if(!q) return; + if(q->buffer) free(q->buffer,q->capacity*q->elem_size); +} diff --git a/shared/data_struct/queue.hpp b/shared/data_struct/queue.hpp index e69de29b..d31dcda8 100644 --- a/shared/data_struct/queue.hpp +++ b/shared/data_struct/queue.hpp @@ -0,0 +1,45 @@ +#pragma once +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct CQueue{ + void* buffer; + uint64_t capacity; //curremt queue size + uint64_t max_capacity; //0 is infinite + uint64_t elem_size; + uint64_t head; + uint64_t tail; + uint64_t length; +}CQueue; + +extern uintptr_t malloc(uint64_t); +extern void free(void*,uint64_t); + +void cqueue_init(CQueue* q,uint64_t max_capacity,uint64_t elem_size); +int32_t cqueue_enqueue(CQueue* q,const void* item); +int32_t cqueue_dequeue(CQueue* q,void* out); +int32_t cqueue_is_empty(const CQueue* q); +uint64_t cqueue_size(const CQueue* q); +void cqueue_clear(CQueue* q); +void cqueue_destroy(CQueue* q); + +#ifdef __cplusplus +} + +template +class Queue{ + CQueue q_; +public: + explicit Queue(uint64_t cap=0){cqueue_init(&q_,cap,sizeof(T));} + ~Queue(){ cqueue_destroy(&q_); } + bool enqueue(const T& v){return cqueue_enqueue(&q_,&v);} + bool dequeue(T& out){return cqueue_dequeue(&q_,&out);} + bool isEmpty() const{return cqueue_is_empty(&q_);} + uint64_t size() const{return cqueue_size(&q_);} + void clear(){cqueue_clear(&q_);} +}; + +#endif From 888d18171c0214875318094c7227e111c0dc72e5 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Tue, 22 Jul 2025 00:00:00 +0000 Subject: [PATCH 072/123] Fix for 0-timeout wait --- kernel/async.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/async.c b/kernel/async.c index c057563f..8fc6cb42 100644 --- a/kernel/async.c +++ b/kernel/async.c @@ -20,11 +20,13 @@ void delay(uint32_t ms) { bool wait(uint32_t *reg, uint32_t expected_value, bool match, uint32_t timeout){ bool condition; do { - delay(1); - timeout--; - if (timeout == 0) - return false; + if (timeout != 0){ + timeout--; + delay(1); + } condition = (*reg & expected_value) == expected_value; + if (timeout == 0) + return (match > 0) ^ condition; } while ((match > 0) ^ condition); return true; From e2609cc33ac69b1853d6402edaa641a5645c15cd Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Tue, 22 Jul 2025 00:00:00 +0000 Subject: [PATCH 073/123] return false on interrupt set since it's not working --- kernel/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/pci.c b/kernel/pci.c index 2eebd9da..f194cd48 100644 --- a/kernel/pci.c +++ b/kernel/pci.c @@ -353,7 +353,7 @@ bool pci_setup_msi_rp1(uint8_t irq_line, bool edge_triggered) { kprintf("Fired? %b", read32(RP1_INT_STAT_HIGH) << 32 | read32(RP1_INT_STAT_LOW)); - return true; + return false; } bool pci_setup_msi(uint64_t pci_addr, uint8_t irq_line) { From 76d3efde27f024d5c2090297ce07f4ad33ffa225 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Tue, 22 Jul 2025 00:00:00 +0000 Subject: [PATCH 074/123] [xHCI] allowing for simulating interrupts --- kernel/input/USBKeyboard.cpp | 8 +++++--- kernel/input/input_dispatch.cpp | 2 ++ kernel/input/usb.hpp | 3 ++- kernel/input/xhci.cpp | 11 +++++------ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/kernel/input/USBKeyboard.cpp b/kernel/input/USBKeyboard.cpp index dd98cc39..671bd3b7 100644 --- a/kernel/input/USBKeyboard.cpp +++ b/kernel/input/USBKeyboard.cpp @@ -22,13 +22,13 @@ void USBKeyboard::request_data(USBDriver *driver){ } void USBKeyboard::process_data(USBDriver *driver){ - if (!requesting){ + if (!requesting) return; - } process_keypress((keypress*)buffer); - request_data(driver); + if (driver->use_interrupts) + request_data(driver); } void USBKeyboard::process_keypress(keypress *rkp){ @@ -46,4 +46,6 @@ void USBKeyboard::process_keypress(keypress *rkp){ register_keypress(kp); } else repeated_keypresses++; + + requesting = false; } \ No newline at end of file diff --git a/kernel/input/input_dispatch.cpp b/kernel/input/input_dispatch.cpp index 305c9c09..744c6cd9 100644 --- a/kernel/input/input_dispatch.cpp +++ b/kernel/input/input_dispatch.cpp @@ -90,6 +90,8 @@ bool is_new_keypress(keypress* current, keypress* previous) { bool sys_read_input(int pid, keypress *out){ if (!input_driver->use_interrupts) input_driver->poll_inputs(); + if (input_driver->quirk_simulate_interrupts) + input_driver->handle_interrupt(); process_t *process = get_proc_by_pid(pid); if (process->input_buffer.read_index == process->input_buffer.write_index) return false; diff --git a/kernel/input/usb.hpp b/kernel/input/usb.hpp index 9340f7d5..4f562665 100644 --- a/kernel/input/usb.hpp +++ b/kernel/input/usb.hpp @@ -21,7 +21,8 @@ class USBDriver { virtual bool poll(uint8_t address, uint8_t endpoint, void *out_buf, uint16_t size) = 0; void poll_inputs(); virtual void handle_interrupt() = 0; - bool use_interrupts; + bool use_interrupts = false; + bool quirk_simulate_interrupts = false; ~USBDriver() = default; protected: void *mem_page; diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index 3e1ef135..93413f1c 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -60,11 +60,12 @@ bool XHCIDriver::check_fatal_error() { bool XHCIDriver::init(){ uint64_t addr, mmio, mmio_size; bool use_pci = false; + use_interrupts = true; if (XHCI_BASE){ addr = XHCI_BASE; mmio = addr; if (BOARD_TYPE == 2 && RPI_BOARD >= 5) - use_interrupts = pci_setup_msi_rp1(36, true); + quirk_simulate_interrupts = !pci_setup_msi_rp1(36, true); } else if (PCI_BASE) { addr = find_pci_device(0x1B36, 0xD); use_pci = true; @@ -94,15 +95,13 @@ bool XHCIDriver::init(){ switch(interrupts_ok){ case 0: kprintf("[xHCI] Failed to setup interrupts"); - use_interrupts = false; + quirk_simulate_interrupts = true; break; case 1: - kprintf("[xHCI] Interrupts setup with MSI-X %i",INPUT_IRQ); - use_interrupts = true; + kprintfv("[xHCI] Interrupts setup with MSI-X %i",INPUT_IRQ); break; default: - kprintf("[xHCI] Interrupts setup with MSI %i",INPUT_IRQ); - use_interrupts = true; + kprintfv("[xHCI] Interrupts setup with MSI %i",INPUT_IRQ); break; } From 5a7d58b2733cdc0f3b135cdd969dcb40bdaff236 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Tue, 22 Jul 2025 00:00:00 +0000 Subject: [PATCH 075/123] [UI] login color fixes --- kernel/kernel_processes/boot/login_screen.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/kernel_processes/boot/login_screen.c b/kernel/kernel_processes/boot/login_screen.c index 45f842eb..7f1a0aa7 100644 --- a/kernel/kernel_processes/boot/login_screen.c +++ b/kernel/kernel_processes/boot/login_screen.c @@ -58,11 +58,11 @@ void login_screen(){ int yo = screen_middle.y; int height = char_size * 2; - gpu_draw_string(title, (gpu_point){screen_middle.x - ((title.length/2) * char_size), yo - char_size*9}, scale, 0xFFFFFF); - gpu_draw_string(subtitle, (gpu_point){screen_middle.x - ((subtitle.length/2) * char_size), yo - char_size*6}, scale, 0xFFFFFF); + gpu_draw_string(title, (gpu_point){screen_middle.x - ((title.length/2) * char_size), yo - char_size*9}, scale, 0xFFFFFFFF); + gpu_draw_string(subtitle, (gpu_point){screen_middle.x - ((subtitle.length/2) * char_size), yo - char_size*6}, scale, 0xFFFFFFFF); gpu_fill_rect((gpu_rect){{xo,yo - char_size/2}, {screen_size.width / 3, height}},BG_COLOR+0x111111); - gpu_draw_string(s, (gpu_point){xo, yo}, scale, 0xFFFFFF); + gpu_draw_string(s, (gpu_point){xo, yo}, scale, 0xFFFFFFFF); keypress kp; if (sys_read_input_current(&kp)){ for (int i = 0; i < 6; i++){ From 84e3611a60a553618c034c413458e73c21f6ec1a Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Tue, 22 Jul 2025 00:00:00 +0000 Subject: [PATCH 076/123] [xHCI] do not pass on error events --- kernel/input/xhci.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index 93413f1c..6f82d5e0 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -564,19 +564,24 @@ void XHCIDriver::handle_interrupt(){ if (type == awaited_type && (awaited_addr == 0 || (awaited_addr & 0xFFFFFFFFFFFFFFFF) == addr)) return; kprintfv("[xHCI] >>> Unhandled interrupt %i %x",event_ring.index,type); - switch (type){ - case TRB_TYPE_TRANSFER: { - uint8_t slot_id = (ev->control & TRB_SLOT_MASK) >> 24; - uint8_t endpoint_id = (ev->control & TRB_ENDPOINT_MASK) >> 16; - kprintfv("Received input from slot %i endpoint %i",slot_id, endpoint_id); - - usb_manager->process_data(slot_id,endpoint_id, this); - break; - } - case TRB_TYPE_PORT_STATUS_CHANGE: { - kprintfv("[xHCI] Port status change. Ignored for now"); - break; + uint8_t completion_code = (ev->status >> 24) & 0xFF; + if (completion_code == 1){ + switch (type){ + case TRB_TYPE_TRANSFER: { + uint8_t slot_id = (ev->control & TRB_SLOT_MASK) >> 24; + uint8_t endpoint_id = (ev->control & TRB_ENDPOINT_MASK) >> 16; + kprintfv("Received input from slot %i endpoint %i",slot_id, endpoint_id); + + usb_manager->process_data(slot_id,endpoint_id, this); + break; + } + case TRB_TYPE_PORT_STATUS_CHANGE: { + kprintfv("[xHCI] Port status change. Ignored for now"); + break; + } } + } else { + kprintf("[xHCI error] wrong status %i on command type %x", completion_code, ((ev->control & TRB_TYPE_MASK) >> 10)); } event_ring.index++; if (event_ring.index == MAX_TRB_AMOUNT - 1){ From b65a56aa5fc50711d529d599c7dd8571433a4b93 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Tue, 22 Jul 2025 00:00:00 +0000 Subject: [PATCH 077/123] [xHCI] repeat request on timeout and set configuration to activate device --- kernel/input/input_dispatch.cpp | 2 +- kernel/input/usb.cpp | 23 ++++++++++++++-------- kernel/input/usb_types.h | 2 +- kernel/input/xhci.cpp | 35 +++++++++++++++++++++------------ 4 files changed, 39 insertions(+), 23 deletions(-) diff --git a/kernel/input/input_dispatch.cpp b/kernel/input/input_dispatch.cpp index 744c6cd9..48c196ee 100644 --- a/kernel/input/input_dispatch.cpp +++ b/kernel/input/input_dispatch.cpp @@ -90,7 +90,7 @@ bool is_new_keypress(keypress* current, keypress* previous) { bool sys_read_input(int pid, keypress *out){ if (!input_driver->use_interrupts) input_driver->poll_inputs(); - if (input_driver->quirk_simulate_interrupts) + else if (input_driver->quirk_simulate_interrupts) input_driver->handle_interrupt(); process_t *process = get_proc_by_pid(pid); if (process->input_buffer.read_index == process->input_buffer.write_index) return false; diff --git a/kernel/input/usb.cpp b/kernel/input/usb.cpp index 1af98b0c..291f7851 100644 --- a/kernel/input/usb.cpp +++ b/kernel/input/usb.cpp @@ -108,6 +108,9 @@ bool USBDriver::get_configuration(uint8_t address){ usb_device_types dev_type; + kprintf("[USB] set configuration %i for device %i", config->bConfigurationValue, address); + request_sized_descriptor(address, 0, 0, 9, 0, config->bConfigurationValue, 0, 0, 0); + for (uint16_t i = 0; i < total_length;){ usb_descriptor_header* header = (usb_descriptor_header*)&config->data[i]; if (header->bLength == 0){ @@ -137,19 +140,22 @@ bool USBDriver::get_configuration(uint8_t address){ break; default: + dev_type = UNKNOWN; break; } interface_index++; break; } case 0x21: { //HID - usb_hid_descriptor *hid = (usb_hid_descriptor *)&config->data[i]; - for (uint8_t j = 0; j < hid->bNumDescriptors; j++){ - if (hid->descriptors[j].bDescriptorType == 0x22){//REPORT HID - report_length = hid->descriptors[j].wDescriptorLength; - report_descriptor = (uint8_t*)allocate_in_page(mem_page, report_length, ALIGN_64B, true, true); - request_descriptor(address, 0, 0x81, 6, 0x22, 0, interface_index-1, report_descriptor); - kprintf("[USB] retrieved report descriptor of length %i at %x", report_length, (uintptr_t)report_descriptor); + if (dev_type != UNKNOWN){ + usb_hid_descriptor *hid = (usb_hid_descriptor *)&config->data[i]; + for (uint8_t j = 0; j < hid->bNumDescriptors; j++){ + if (hid->descriptors[j].bDescriptorType == 0x22){//REPORT HID + report_length = hid->descriptors[j].wDescriptorLength; + report_descriptor = (uint8_t*)allocate_in_page(mem_page, report_length, ALIGN_64B, true, true); + request_descriptor(address, 0, 0x81, 6, 0x22, 0, interface_index-1, report_descriptor); + kprintf("[USB] retrieved report descriptor of length %i at %x", report_length, (uintptr_t)report_descriptor); + } } } break; @@ -157,7 +163,8 @@ bool USBDriver::get_configuration(uint8_t address){ case 0x5: {//Endpoint usb_endpoint_descriptor *endpoint = (usb_endpoint_descriptor*)&config->data[i]; - if (!configure_endpoint(address, endpoint, config->bConfigurationValue, dev_type)) return false; + if (dev_type != UNKNOWN) + configure_endpoint(address, endpoint, config->bConfigurationValue, dev_type); need_new_endpoint = true; break; diff --git a/kernel/input/usb_types.h b/kernel/input/usb_types.h index fadef21a..02fded37 100644 --- a/kernel/input/usb_types.h +++ b/kernel/input/usb_types.h @@ -91,7 +91,7 @@ typedef struct __attribute__((packed)){ } usb_string_descriptor; typedef enum { - NONE, + UNKNOWN, KEYBOARD, MOUSE } usb_device_types; diff --git a/kernel/input/xhci.cpp b/kernel/input/xhci.cpp index 6f82d5e0..de5154bb 100644 --- a/kernel/input/xhci.cpp +++ b/kernel/input/xhci.cpp @@ -212,6 +212,8 @@ bool XHCIDriver::init(){ bool XHCIDriver::port_reset(uint16_t port){ + kprintf("[xHCI] port %i",port); + xhci_port_regs* port_info = &ports[port]; if (port_info->portsc.pp == 0){ @@ -307,7 +309,7 @@ void XHCIDriver::ring_doorbell(uint32_t slot, uint32_t endpoint) { bool XHCIDriver::await_response(uint64_t command, uint32_t type){ while (1){ if (check_fatal_error()){ - kprintf_raw("[xHCI error] USBSTS value %x",op->usbsts); + kprintf("[xHCI error] USBSTS value %x",op->usbsts); awaited_type = 0; return false; } @@ -318,8 +320,8 @@ bool XHCIDriver::await_response(uint64_t command, uint32_t type){ awaited_type = 0; return false; } - // kprintf_raw("[xHCI] A response at %i of type %x as a response to %x",event_ring.index, (last_event->control & TRB_TYPE_MASK) >> 10, last_event->parameter); - // kprintf_raw("[xHCI] %x vs %x = %i and %x vs %x = %i", (ev->control & TRB_TYPE_MASK) >> 10, type, (ev->control & TRB_TYPE_MASK) >> 10 == type, ev->parameter, command, command == 0 || ev->parameter == command); + // kprintf("[xHCI] A response at %i of type %x as a response to %x",event_ring.index, (last_event->control & TRB_TYPE_MASK) >> 10, last_event->parameter); + // kprintf("[xHCI] %x vs %x = %i and %x vs %x = %i", (ev->control & TRB_TYPE_MASK) >> 10, type, (ev->control & TRB_TYPE_MASK) >> 10 == type, ev->parameter, command, command == 0 || ev->parameter == command); if (event_ring.index == MAX_TRB_AMOUNT - 1){ event_ring.index = 0; event_ring.cycle_bit = !event_ring.cycle_bit; @@ -416,6 +418,8 @@ bool XHCIDriver::request_sized_descriptor(uint8_t address, uint8_t endpoint, uin .wLength = descriptor_size }; + // kprintf("RT: %x R: %x V: %x I: %x L: %x",packet.bmRequestType,packet.bRequest,packet.wValue,packet.wIndex,packet.wLength); + bool is_in = (rType & 0x80) != 0; xhci_ring *transfer_ring = &endpoint_map[address << 8 | endpoint]; @@ -424,13 +428,15 @@ bool XHCIDriver::request_sized_descriptor(uint8_t address, uint8_t endpoint, uin memcpy(&setup_trb->parameter, &packet, sizeof(packet)); setup_trb->status = sizeof(usb_setup_packet); //bit 4 = chain. Bit 16 direction (3 = IN, 2 = OUT, 0 = NO DATA) - setup_trb->control = (3 << 16) | (TRB_TYPE_SETUP_STAGE << 10) | (1 << 6) | (1 << 4) | transfer_ring->cycle_bit; - - trb* data = &transfer_ring->ring[transfer_ring->index++]; - data->parameter = (uintptr_t)out_descriptor; - data->status = packet.wLength; - //bit 16 = direction - data->control = (1 << 16) | (TRB_TYPE_DATA_STAGE << 10) | (0 << 4) | transfer_ring->cycle_bit; + setup_trb->control = (3 << 16) | (TRB_TYPE_SETUP_STAGE << 10) | (1 << 6) | ((descriptor_size > 0) << 4) | transfer_ring->cycle_bit; + + if (descriptor_size > 0){ + trb* data = &transfer_ring->ring[transfer_ring->index++]; + data->parameter = (uintptr_t)out_descriptor; + data->status = packet.wLength; + //bit 16 = direction + data->control = (1 << 16) | (TRB_TYPE_DATA_STAGE << 10) | (0 << 4) | transfer_ring->cycle_bit; + } trb* status_trb = &transfer_ring->ring[transfer_ring->index++]; status_trb->parameter = 0; @@ -444,7 +450,7 @@ bool XHCIDriver::request_sized_descriptor(uint8_t address, uint8_t endpoint, uin transfer_ring->index = 0; } - return AWAIT((uintptr_t)status_trb, {ring_doorbell(address, 1);}, TRB_TYPE_TRANSFER); + return AWAIT(0, {ring_doorbell(address, 1);}, TRB_TYPE_TRANSFER);//TODO: Devices can respond with an error to any of the 3 stages } uint8_t XHCIDriver::address_device(uint8_t address){ @@ -565,14 +571,17 @@ void XHCIDriver::handle_interrupt(){ return; kprintfv("[xHCI] >>> Unhandled interrupt %i %x",event_ring.index,type); uint8_t completion_code = (ev->status >> 24) & 0xFF; - if (completion_code == 1){ + if (completion_code == 1 || completion_code == 4){ switch (type){ case TRB_TYPE_TRANSFER: { uint8_t slot_id = (ev->control & TRB_SLOT_MASK) >> 24; uint8_t endpoint_id = (ev->control & TRB_ENDPOINT_MASK) >> 16; kprintfv("Received input from slot %i endpoint %i",slot_id, endpoint_id); - usb_manager->process_data(slot_id,endpoint_id, this); + if (completion_code == 4) + usb_manager->request_data(slot_id,endpoint_id,this); + else + usb_manager->process_data(slot_id,endpoint_id, this); break; } case TRB_TYPE_PORT_STATUS_CHANGE: { From 6c661ef3621d24db8df81bc124a64f0ac51a89d3 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Wed, 23 Jul 2025 00:00:00 +0000 Subject: [PATCH 078/123] [PROJ] added dtbs and updated README --- Makefile | 1 + README.md | 6 +- config.txt | 55 + dtbs/rpi4b.dts | 2728 ++++++++++++++++++++++++++++++ dtbs/rpi5b.dts | 3292 ++++++++++++++++++++++++++++++++++++ dtbs/rpi5b2.dts | 3292 ++++++++++++++++++++++++++++++++++++ dtbs/rpicm5lio.dts | 3324 +++++++++++++++++++++++++++++++++++++ virt.dts => dtbs/virt.dts | 0 8 files changed, 12696 insertions(+), 2 deletions(-) create mode 100755 config.txt create mode 100644 dtbs/rpi4b.dts create mode 100644 dtbs/rpi5b.dts create mode 100644 dtbs/rpi5b2.dts create mode 100644 dtbs/rpicm5lio.dts rename virt.dts => dtbs/virt.dts (100%) diff --git a/Makefile b/Makefile index 7529411b..5f4453fc 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,7 @@ install: $(MAKE) LOAD_ADDR=0x80000 XHCI_CTX_SIZE=64 all cp kernel.img $(BOOTFS)/kernel8.img cp kernel.img $(BOOTFS)/kernel_2712.img + cp config.txt $(BOOTFS)/config.txt run: $(MAKE) $(MODE) diff --git a/README.md b/README.md index e4a39eb0..d8408208 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ ## Summary The REDACTED Operating System is a 64 bit operating system meant to run on ARM processors. -It currently runs entirely in QEMU, either in an entirely virtual machine using QEMU's `virt` board, or emulating a Raspberry Pi 4B. It currently most likely will not work on real hardware (not on the raspi 5 anyway, haven't tested on a 4B) +It can run entirely in QEMU, either in an entirely virtual machine using QEMU's `virt` board, or emulating a Raspberry Pi 4B. +It also has preliminary support for the Raspberry Pi 5, and possibly 4B and 3B, though these last two are largely untested. Its GUI is heavily inspired by video game consoles, and the OS is entirely controllable via keyboard (with future mouse and possibly gamepad support) It has limited support for third party processes, currently limited to entirely self-contained programs. The `shared` library is provided for syscalls and common functions but it should be used as a static library embedded into the final executable `.elf` file. @@ -53,7 +54,7 @@ In addition to the code located in the system's 3 main folders, a few other file - debug: attaches gdb to an instance of QEMU running REDACTED OS. The instance must be run with the `debug` argument as `./run debug` in order for gdb to attach and control its execution. It can support automatically running a command inside gdb such as adding a breakpoint by passing it as an argument as `./debug b kernel_main` - rundebug: a shortcut for running both the `run` and `debug` commands. It can pass arguments for the debug command, which in turn will pass them to gdb - createfs: creates a filesystem image for the system to read. The image does not contain kernel code and is not used to boot the system, but is still required to boot the system, and contains user processes. The script is written specifically for macOS, as it relies on the diskutil commands to create the image. There isn't a linux or windows version for it, but a filesystem image can be created manually and placed in the root directory with the name disk.img -- Makefile: can compile and run the system. `make run` compiles the system for the virt board, passing MODE=virt/raspi specifies which board to compile for. It creates the filesystem image and executes the correct `./run` command. `make debug` compiles the system, creates the filesystem and executes the OS and gdb, through the `./rundebug` command. `make all` simply compiles and creates the filesystem image. `make clean` cleans compiled files. +- Makefile: can compile and run the system. `make run` compiles the system for the virt board, passing MODE=virt/raspi specifies which board to compile for, default is virt. It creates the filesystem image and executes the correct `./run` command. `make debug` compiles the system, creates the filesystem and executes the OS and gdb, through the `./rundebug` command. `make all` simply compiles and creates the filesystem image. `make clean` cleans compiled files. The `make install` command performs a clean build and attempts to install onto a raspberry-pi-formatted sd card in its `bootfs` partition. ## Compiling @@ -62,6 +63,7 @@ The OS currently only runs on QEMU, so QEMU needs to be installed as well. The s Running `make run` or `make all` followed by `./run` is the fastest way to run the system, using the default configuration (virt board for QEMU). Further explanations on these commands and their options provided in the Supporting Files section. Running `make run MODE=virt/raspi` can select which board to compile the code for. In order to run the OS, you'll need to create a folder called fs inside the project's root directory. This folder will contain user processes. It must have the following subfolders: /redos/user/, with user processes placed inside with the .elf extension. The `user` process will automatically be placed in that folder when compiling. A script called `createfs` will run automatically to create an image from the fs folder. This script currently only works on MacOS and Linux host systems, it will need to be adapted to run on Windows systems. Since my main host system is Mac, there's a chance the linux version won't be up to date if any changes need to be made. +Running `make install` will perform a clean build for the raspberry pi and copy the resulting kernel image and the provided `config.txt` file to a partition called `bootfs`, which should be created using Raspberry Pi Imager on an SD card. It should be possible to then boot the system onto a Raspberry Pi 5, 4B or 3B, although support may be limited. It is recommended to use a UART debug probe along with the `screen` command running on the development machine to see the system's console output and debug potential issues. Github Actions should automatically compile changes made to the `main` branch using Mac, so a compiled version of the system with all the files needed to run it should be found there. This includes the fs folder, containing the filesystem, but you'll need to recompile the `disk.img` filesystem with `createfs` for any changes made to this folder to be reflected. Currently it only builds a version for the virt board. diff --git a/config.txt b/config.txt new file mode 100755 index 00000000..114b8016 --- /dev/null +++ b/config.txt @@ -0,0 +1,55 @@ +# For more options and information see +# http://rptl.io/configtxt +# Some settings may impact device functionality. See link above for details + +# Uncomment some or all of these to enable the optional hardware interfaces +#dtparam=i2c_arm=on +#dtparam=i2s=on +#dtparam=spi=on + +# Enable audio (loads snd_bcm2835) +dtparam=audio=on + +# Additional overlays and parameters are documented +# /boot/firmware/overlays/README + +# Automatically load overlays for detected cameras +camera_auto_detect=1 + +# Automatically load overlays for detected DSI displays +display_auto_detect=1 + +# Automatically load initramfs files, if found +auto_initramfs=1 + +# Enable DRM VC4 V3D driver +dtoverlay=vc4-kms-v3d +max_framebuffers=2 + +# Don't have the firmware create an initial video= setting in cmdline.txt. +# Use the kernel's default instead. +disable_fw_kms_setup=1 + +# Run in 64-bit mode +arm_64bit=1 + +# Disable compensation for displays with overscan +disable_overscan=1 + +# Run as fast as firmware / board allows +arm_boost=1 + +pciex4_reset=0 + +[cm4] +# Enable host mode on the 2711 built-in XHCI USB controller. +# This line should be removed if the legacy DWC2 controller is required +# (e.g. for USB device mode) or if USB support is not required. +otg_mode=1 + +[cm5] +#dtoverlay=dwc2,dr_mode=host + +[all] +gpu_mem=512 +framebuffer_depth=32 \ No newline at end of file diff --git a/dtbs/rpi4b.dts b/dtbs/rpi4b.dts new file mode 100644 index 00000000..dd52906a --- /dev/null +++ b/dtbs/rpi4b.dts @@ -0,0 +1,2728 @@ +/dts-v1/; + +/memreserve/ 0x0000000000000000 0x0000000000001000; +/ { + compatible = "raspberrypi,4-model-b", "brcm,bcm2711"; + model = "Raspberry Pi 4 Model B"; + #address-cells = <0x02>; + #size-cells = <0x01>; + interrupt-parent = <0x01>; + + aliases { + serial0 = "/soc/serial@7e215040"; + serial1 = "/soc/serial@7e201000"; + emmc2bus = "/emmc2bus"; + ethernet0 = "/scb/ethernet@7d580000"; + pcie0 = "/scb/pcie@7d500000"; + blconfig = "/reserved-memory/nvram@0"; + blpubkey = "/reserved-memory/nvram@1"; + bluetooth = "/soc/serial@7e201000/bluetooth"; + aux = "/soc/aux@7e215000"; + sound = "/soc/sound"; + soc = "/soc"; + dma = "/soc/dma-controller@7e007000"; + watchdog = "/soc/watchdog@7e100000"; + random = "/soc/rng@7e104000"; + mailbox = "/soc/mailbox@7e00b880"; + gpio = "/soc/gpio@7e200000"; + uart0 = "/soc/serial@7e201000"; + uart1 = "/soc/serial@7e215040"; + sdhost = "/soc/mmc@7e202000"; + mmc = "/soc/mmc@7e300000"; + mmc1 = "/soc/mmcnr@7e300000"; + mmc0 = "/emmc2bus/mmc@7e340000"; + i2s = "/soc/i2s@7e203000"; + i2c0 = "/soc/i2c0mux/i2c@0"; + i2c1 = "/soc/i2c@7e804000"; + i2c10 = "/soc/i2c0mux/i2c@1"; + i2c = "/soc/i2c@7e804000"; + spi0 = "/soc/spi@7e204000"; + spi1 = "/soc/spi@7e215080"; + spi2 = "/soc/spi@7e2150c0"; + usb = "/soc/usb@7e980000"; + leds = "/leds"; + fb = "/soc/fb"; + thermal = "/soc/avs-monitor@7d5d2000/thermal"; + axiperf = "/soc/axiperf"; + uart2 = "/soc/serial@7e201400"; + uart3 = "/soc/serial@7e201600"; + uart4 = "/soc/serial@7e201800"; + uart5 = "/soc/serial@7e201a00"; + serial2 = "/soc/serial@7e201400"; + serial3 = "/soc/serial@7e201600"; + serial4 = "/soc/serial@7e201800"; + serial5 = "/soc/serial@7e201a00"; + mmc2 = "/soc/mmc@7e202000"; + i2c3 = "/soc/i2c@7e205600"; + i2c4 = "/soc/i2c@7e205800"; + i2c5 = "/soc/i2c@7e205a00"; + i2c6 = "/soc/i2c@7e205c00"; + i2c20 = "/soc/i2c@7ef04500"; + i2c21 = "/soc/i2c@7ef09500"; + spi3 = "/soc/spi@7e204600"; + spi4 = "/soc/spi@7e204800"; + spi5 = "/soc/spi@7e204a00"; + spi6 = "/soc/spi@7e204c00"; + phandle = <0x4f>; + }; + + chosen { + stdout-path = "serial0:115200n8"; + bootargs = "coherent_pool=1M 8250.nr_uarts=1 snd_bcm2835.enable_headphones=0 cgroup_disable=memory numa_policy=interleave nvme.max_host_mem_size_mb=0"; + phandle = <0x54>; + }; + + reserved-memory { + #address-cells = <0x02>; + #size-cells = <0x01>; + ranges; + phandle = <0x5c>; + + linux,cma { + compatible = "shared-dma-pool"; + size = <0x4000000>; + reusable; + linux,cma-default; + alloc-ranges = <0x00 0x00 0x30000000>; + phandle = <0x5d>; + }; + + nvram@0 { + compatible = "raspberrypi,bootloader-config", "nvmem-rmem"; + #address-cells = <0x01>; + #size-cells = <0x01>; + reg = <0x00 0x00 0x00>; + no-map; + status = "disabled"; + phandle = <0x5e>; + }; + + nvram@1 { + compatible = "raspberrypi,bootloader-public-key", "nvmem-rmem"; + #address-cells = <0x01>; + #size-cells = <0x01>; + reg = <0x00 0x00 0x00>; + no-map; + status = "disabled"; + phandle = <0x5f>; + }; + }; + + thermal-zones { + + cpu-thermal { + polling-delay-passive = <0x00>; + polling-delay = <0x3e8>; + coefficients = <0xfffffe19 0x641b8>; + thermal-sensors = <0x02>; + phandle = <0x60>; + + trips { + phandle = <0x61>; + + cpu-crit { + temperature = <0x1adb0>; + hysteresis = <0x00>; + type = "critical"; + }; + }; + + cooling-maps { + phandle = <0x62>; + }; + }; + }; + + soc { + compatible = "simple-bus"; + #address-cells = <0x01>; + #size-cells = <0x01>; + ranges = <0x7e000000 0x00 0xfe000000 0x1800000 0x7c000000 0x00 0xfc000000 0x2000000 0x40000000 0x00 0xff800000 0x800000>; + dma-ranges = <0xc0000000 0x00 0x00 0x40000000 0x7c000000 0x00 0xfc000000 0x3800000>; + phandle = <0x63>; + + timer@7e003000 { + compatible = "brcm,bcm2835-system-timer"; + reg = <0x7e003000 0x1000>; + interrupts = <0x00 0x40 0x04 0x00 0x41 0x04 0x00 0x42 0x04 0x00 0x43 0x04>; + clock-frequency = <0xf4240>; + status = "disabled"; + phandle = <0x64>; + }; + + txp@7e004000 { + compatible = "brcm,bcm2835-txp"; + reg = <0x7e004000 0x20>; + interrupts = <0x00 0x4b 0x04>; + status = "disabled"; + phandle = <0x65>; + }; + + cprman@7e101000 { + compatible = "brcm,bcm2711-cprman"; + #clock-cells = <0x01>; + reg = <0x7e101000 0x2000>; + clocks = <0x03 0x04 0x00 0x04 0x01 0x04 0x02 0x05 0x00 0x05 0x01 0x05 0x02>; + firmware = <0x06>; + phandle = <0x08>; + }; + + mailbox@7e00b880 { + compatible = "brcm,bcm2835-mbox"; + reg = <0x7e00b880 0x40>; + interrupts = <0x00 0x21 0x04>; + #mbox-cells = <0x00>; + phandle = <0x31>; + }; + + gpio@7e200000 { + compatible = "brcm,bcm2711-gpio"; + reg = <0x7e200000 0xb4>; + interrupts = <0x00 0x71 0x04 0x00 0x72 0x04>; + gpio-controller; + #gpio-cells = <0x02>; + interrupt-controller; + #interrupt-cells = <0x02>; + gpio-ranges = <0x07 0x00 0x00 0x3a>; + gpio-line-names = "ID_SDA", "ID_SCL", "GPIO2", "GPIO3", "GPIO4", "GPIO5", "GPIO6", "GPIO7", "GPIO8", "GPIO9", "GPIO10", "GPIO11", "GPIO12", "GPIO13", "GPIO14", "GPIO15", "GPIO16", "GPIO17", "GPIO18", "GPIO19", "GPIO20", "GPIO21", "GPIO22", "GPIO23", "GPIO24", "GPIO25", "GPIO26", "GPIO27", "RGMII_MDIO", "RGMIO_MDC", "CTS0", "RTS0", "TXD0", "RXD0", "SD1_CLK", "SD1_CMD", "SD1_DATA0", "SD1_DATA1", "SD1_DATA2", "SD1_DATA3", "PWM0_MISO", "PWM1_MOSI", "STATUS_LED_G_CLK", "SPIFLASH_CE_N", "SDA0", "SCL0", "RGMII_RXCLK", "RGMII_RXCTL", "RGMII_RXD0", "RGMII_RXD1", "RGMII_RXD2", "RGMII_RXD3", "RGMII_TXCLK", "RGMII_TXCTL", "RGMII_TXD0", "RGMII_TXD1", "RGMII_TXD2", "RGMII_TXD3"; + phandle = <0x07>; + + dpi-gpio0 { + brcm,pins = <0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b>; + brcm,function = <0x06>; + phandle = <0x66>; + }; + + emmc-gpio22 { + brcm,pins = <0x16 0x17 0x18 0x19 0x1a 0x1b>; + brcm,function = <0x07>; + phandle = <0x67>; + }; + + emmc-gpio34 { + brcm,pins = <0x22 0x23 0x24 0x25 0x26 0x27>; + brcm,function = <0x07>; + brcm,pull = <0x00 0x02 0x02 0x02 0x02 0x02>; + phandle = <0x68>; + }; + + emmc-gpio48 { + brcm,pins = <0x30 0x31 0x32 0x33 0x34 0x35>; + brcm,function = <0x07>; + phandle = <0x13>; + }; + + gpclk0-gpio4 { + brcm,pins = <0x04>; + brcm,function = <0x04>; + phandle = <0x69>; + }; + + gpclk1-gpio5 { + brcm,pins = <0x05>; + brcm,function = <0x04>; + phandle = <0x6a>; + }; + + gpclk1-gpio42 { + brcm,pins = <0x2a>; + brcm,function = <0x04>; + phandle = <0x6b>; + }; + + gpclk1-gpio44 { + brcm,pins = <0x2c>; + brcm,function = <0x04>; + phandle = <0x6c>; + }; + + gpclk2-gpio6 { + brcm,pins = <0x06>; + brcm,function = <0x04>; + phandle = <0x6d>; + }; + + gpclk2-gpio43 { + brcm,pins = <0x2b>; + brcm,function = <0x04>; + brcm,pull = <0x00>; + phandle = <0x6e>; + }; + + i2c0if-gpio0 { + brcm,pins = <0x00 0x01>; + brcm,function = <0x04>; + phandle = <0x35>; + }; + + i2c0if-gpio28 { + brcm,pins = <0x1c 0x1d>; + brcm,function = <0x04>; + phandle = <0x6f>; + }; + + i2c0if-gpio44 { + brcm,pins = <0x2c 0x2d>; + brcm,function = <0x05>; + phandle = <0x36>; + }; + + i2c1-gpio2 { + brcm,pins = <0x02 0x03>; + brcm,function = <0x04>; + phandle = <0x70>; + }; + + i2c1-gpio44 { + brcm,pins = <0x2c 0x2d>; + brcm,function = <0x06>; + phandle = <0x71>; + }; + + jtag-gpio22 { + brcm,pins = <0x16 0x17 0x18 0x19 0x1a 0x1b>; + brcm,function = <0x03>; + phandle = <0x72>; + }; + + pcm-gpio18 { + brcm,pins = <0x12 0x13 0x14 0x15>; + brcm,function = <0x04>; + phandle = <0x73>; + }; + + pcm-gpio28 { + brcm,pins = <0x1c 0x1d 0x1e 0x1f>; + brcm,function = <0x06>; + phandle = <0x74>; + }; + + sdhost-gpio48 { + brcm,pins = <0x30 0x31 0x32 0x33 0x34 0x35>; + brcm,function = <0x04>; + phandle = <0x75>; + }; + + spi0-gpio7 { + brcm,pins = <0x07 0x08 0x09 0x0a 0x0b>; + brcm,function = <0x04>; + phandle = <0x76>; + }; + + spi0-gpio35 { + brcm,pins = <0x23 0x24 0x25 0x26 0x27>; + brcm,function = <0x04>; + phandle = <0x77>; + }; + + spi1-gpio16 { + brcm,pins = <0x10 0x11 0x12 0x13 0x14 0x15>; + brcm,function = <0x03>; + phandle = <0x78>; + }; + + spi2-gpio40 { + brcm,pins = <0x28 0x29 0x2a 0x2b 0x2c 0x2d>; + brcm,function = <0x03>; + phandle = <0x79>; + }; + + uart0-gpio14 { + brcm,pins = <0x0e 0x0f>; + brcm,function = <0x04>; + phandle = <0x7a>; + }; + + uart0-ctsrts-gpio16 { + brcm,pins = <0x10 0x11>; + brcm,function = <0x07>; + phandle = <0x7b>; + }; + + uart0-ctsrts-gpio30 { + brcm,pins = <0x1e 0x1f>; + brcm,function = <0x07>; + brcm,pull = <0x02 0x00>; + phandle = <0x7c>; + }; + + uart0-gpio32 { + brcm,pins = <0x20 0x21>; + brcm,function = <0x07>; + brcm,pull = <0x00 0x02>; + phandle = <0x7d>; + }; + + uart0-gpio36 { + brcm,pins = <0x24 0x25>; + brcm,function = <0x06>; + phandle = <0x7e>; + }; + + uart0-ctsrts-gpio38 { + brcm,pins = <0x26 0x27>; + brcm,function = <0x06>; + phandle = <0x7f>; + }; + + uart1-gpio14 { + brcm,pins = <0x0e 0x0f>; + brcm,function = <0x02>; + phandle = <0x80>; + }; + + uart1-ctsrts-gpio16 { + brcm,pins = <0x10 0x11>; + brcm,function = <0x02>; + phandle = <0x81>; + }; + + uart1-gpio32 { + brcm,pins = <0x20 0x21>; + brcm,function = <0x02>; + phandle = <0x82>; + }; + + uart1-ctsrts-gpio30 { + brcm,pins = <0x1e 0x1f>; + brcm,function = <0x02>; + phandle = <0x83>; + }; + + uart1-gpio40 { + brcm,pins = <0x28 0x29>; + brcm,function = <0x02>; + phandle = <0x84>; + }; + + uart1-ctsrts-gpio42 { + brcm,pins = <0x2a 0x2b>; + brcm,function = <0x02>; + phandle = <0x85>; + }; + + gpclk0-gpio49 { + phandle = <0x86>; + + pin-gpclk { + pins = "gpio49"; + function = "alt1"; + bias-disable; + }; + }; + + gpclk1-gpio50 { + phandle = <0x87>; + + pin-gpclk { + pins = "gpio50"; + function = "alt1"; + bias-disable; + }; + }; + + gpclk2-gpio51 { + phandle = <0x88>; + + pin-gpclk { + pins = "gpio51"; + function = "alt1"; + bias-disable; + }; + }; + + i2c0if-gpio46 { + phandle = <0x89>; + + pin-sda { + function = "alt0"; + pins = "gpio46"; + bias-pull-up; + }; + + pin-scl { + function = "alt0"; + pins = "gpio47"; + bias-disable; + }; + }; + + i2c1-gpio46 { + phandle = <0x8a>; + + pin-sda { + function = "alt1"; + pins = "gpio46"; + bias-pull-up; + }; + + pin-scl { + function = "alt1"; + pins = "gpio47"; + bias-disable; + }; + }; + + i2c3-gpio2 { + phandle = <0x8b>; + + pin-sda { + function = "alt5"; + pins = "gpio2"; + bias-pull-up; + }; + + pin-scl { + function = "alt5"; + pins = "gpio3"; + bias-disable; + }; + }; + + i2c3-gpio4 { + phandle = <0x8c>; + + pin-sda { + function = "alt5"; + pins = "gpio4"; + bias-pull-up; + }; + + pin-scl { + function = "alt5"; + pins = "gpio5"; + bias-disable; + }; + }; + + i2c4-gpio6 { + phandle = <0x8d>; + + pin-sda { + function = "alt5"; + pins = "gpio6"; + bias-pull-up; + }; + + pin-scl { + function = "alt5"; + pins = "gpio7"; + bias-disable; + }; + }; + + i2c4-gpio8 { + phandle = <0x8e>; + + pin-sda { + function = "alt5"; + pins = "gpio8"; + bias-pull-up; + }; + + pin-scl { + function = "alt5"; + pins = "gpio9"; + bias-disable; + }; + }; + + i2c5-gpio10 { + phandle = <0x8f>; + + pin-sda { + function = "alt5"; + pins = "gpio10"; + bias-pull-up; + }; + + pin-scl { + function = "alt5"; + pins = "gpio11"; + bias-disable; + }; + }; + + i2c5-gpio12 { + phandle = <0x90>; + + pin-sda { + function = "alt5"; + pins = "gpio12"; + bias-pull-up; + }; + + pin-scl { + function = "alt5"; + pins = "gpio13"; + bias-disable; + }; + }; + + i2c6-gpio0 { + phandle = <0x91>; + + pin-sda { + function = "alt5"; + pins = "gpio0"; + bias-pull-up; + }; + + pin-scl { + function = "alt5"; + pins = "gpio1"; + bias-disable; + }; + }; + + i2c6-gpio22 { + phandle = <0x92>; + + pin-sda { + function = "alt5"; + pins = "gpio22"; + bias-pull-up; + }; + + pin-scl { + function = "alt5"; + pins = "gpio23"; + bias-disable; + }; + }; + + i2c-slave-gpio8 { + phandle = <0x93>; + + pins-i2c-slave { + pins = "gpio8", "gpio9", "gpio10", "gpio11"; + function = "alt3"; + }; + }; + + jtag-gpio48 { + phandle = <0x94>; + + pins-jtag { + pins = "gpio48", "gpio49", "gpio50", "gpio51", "gpio52", "gpio53"; + function = "alt4"; + }; + }; + + mii-gpio28 { + phandle = <0x95>; + + pins-mii { + pins = "gpio28", "gpio29", "gpio30", "gpio31"; + function = "alt4"; + }; + }; + + mii-gpio36 { + phandle = <0x96>; + + pins-mii { + pins = "gpio36", "gpio37", "gpio38", "gpio39"; + function = "alt5"; + }; + }; + + pcm-gpio50 { + phandle = <0x97>; + + pins-pcm { + pins = "gpio50", "gpio51", "gpio52", "gpio53"; + function = "alt2"; + }; + }; + + pwm0-0-gpio12 { + phandle = <0x98>; + + pin-pwm { + pins = "gpio12"; + function = "alt0"; + bias-disable; + }; + }; + + pwm0-0-gpio18 { + phandle = <0x99>; + + pin-pwm { + pins = "gpio18"; + function = "alt5"; + bias-disable; + }; + }; + + pwm1-0-gpio40 { + phandle = <0x28>; + + pin-pwm { + pins = "gpio40"; + function = "alt0"; + bias-disable; + }; + }; + + pwm0-1-gpio13 { + phandle = <0x9a>; + + pin-pwm { + pins = "gpio13"; + function = "alt0"; + bias-disable; + }; + }; + + pwm0-1-gpio19 { + phandle = <0x9b>; + + pin-pwm { + pins = "gpio19"; + function = "alt5"; + bias-disable; + }; + }; + + pwm1-1-gpio41 { + phandle = <0x29>; + + pin-pwm { + pins = "gpio41"; + function = "alt0"; + bias-disable; + }; + }; + + pwm0-1-gpio45 { + phandle = <0x9c>; + + pin-pwm { + pins = "gpio45"; + function = "alt0"; + bias-disable; + }; + }; + + pwm0-0-gpio52 { + phandle = <0x9d>; + + pin-pwm { + pins = "gpio52"; + function = "alt1"; + bias-disable; + }; + }; + + pwm0-1-gpio53 { + phandle = <0x9e>; + + pin-pwm { + pins = "gpio53"; + function = "alt1"; + bias-disable; + }; + }; + + rgmii-gpio35 { + phandle = <0x9f>; + + pin-start-stop { + pins = "gpio35"; + function = "alt4"; + }; + + pin-rx-ok { + pins = "gpio36"; + function = "alt4"; + }; + }; + + rgmii-irq-gpio34 { + phandle = <0xa0>; + + pin-irq { + pins = "gpio34"; + function = "alt5"; + }; + }; + + rgmii-irq-gpio39 { + phandle = <0xa1>; + + pin-irq { + pins = "gpio39"; + function = "alt4"; + }; + }; + + rgmii-mdio-gpio28 { + phandle = <0xa2>; + + pins-mdio { + pins = "gpio28", "gpio29"; + function = "alt5"; + }; + }; + + rgmii-mdio-gpio37 { + phandle = <0xa3>; + + pins-mdio { + pins = "gpio37", "gpio38"; + function = "alt4"; + }; + }; + + spi0-gpio46 { + phandle = <0xa4>; + + pins-spi { + pins = "gpio46", "gpio47", "gpio48", "gpio49"; + function = "alt2"; + }; + }; + + spi2-gpio46 { + phandle = <0xa5>; + + pins-spi { + pins = "gpio46", "gpio47", "gpio48", "gpio49", "gpio50"; + function = "alt5"; + }; + }; + + spi3-gpio0 { + phandle = <0xa6>; + + pins-spi { + pins = "gpio0", "gpio1", "gpio2", "gpio3"; + function = "alt3"; + }; + }; + + spi4-gpio4 { + phandle = <0xa7>; + + pins-spi { + pins = "gpio4", "gpio5", "gpio6", "gpio7"; + function = "alt3"; + }; + }; + + spi5-gpio12 { + phandle = <0xa8>; + + pins-spi { + pins = "gpio12", "gpio13", "gpio14", "gpio15"; + function = "alt3"; + }; + }; + + spi6-gpio18 { + phandle = <0xa9>; + + pins-spi { + pins = "gpio18", "gpio19", "gpio20", "gpio21"; + function = "alt3"; + }; + }; + + uart2-gpio0 { + phandle = <0xaa>; + + pin-tx { + pins = "gpio0"; + function = "alt4"; + bias-disable; + }; + + pin-rx { + pins = "gpio1"; + function = "alt4"; + bias-pull-up; + }; + }; + + uart2-ctsrts-gpio2 { + phandle = <0xab>; + + pin-cts { + pins = "gpio2"; + function = "alt4"; + bias-pull-up; + }; + + pin-rts { + pins = "gpio3"; + function = "alt4"; + bias-disable; + }; + }; + + uart3-gpio4 { + phandle = <0xac>; + + pin-tx { + pins = "gpio4"; + function = "alt4"; + bias-disable; + }; + + pin-rx { + pins = "gpio5"; + function = "alt4"; + bias-pull-up; + }; + }; + + uart3-ctsrts-gpio6 { + phandle = <0xad>; + + pin-cts { + pins = "gpio6"; + function = "alt4"; + bias-pull-up; + }; + + pin-rts { + pins = "gpio7"; + function = "alt4"; + bias-disable; + }; + }; + + uart4-gpio8 { + phandle = <0xae>; + + pin-tx { + pins = "gpio8"; + function = "alt4"; + bias-disable; + }; + + pin-rx { + pins = "gpio9"; + function = "alt4"; + bias-pull-up; + }; + }; + + uart4-ctsrts-gpio10 { + phandle = <0xaf>; + + pin-cts { + pins = "gpio10"; + function = "alt4"; + bias-pull-up; + }; + + pin-rts { + pins = "gpio11"; + function = "alt4"; + bias-disable; + }; + }; + + uart5-gpio12 { + phandle = <0xb0>; + + pin-tx { + pins = "gpio12"; + function = "alt4"; + bias-disable; + }; + + pin-rx { + pins = "gpio13"; + function = "alt4"; + bias-pull-up; + }; + }; + + uart5-ctsrts-gpio14 { + phandle = <0xb1>; + + pin-cts { + pins = "gpio14"; + function = "alt4"; + bias-pull-up; + }; + + pin-rts { + pins = "gpio15"; + function = "alt4"; + bias-disable; + }; + }; + + gpioout { + brcm,pins = <0x06>; + brcm,function = <0x01>; + phandle = <0xb2>; + }; + + alt0 { + brcm,pins = <0x04 0x05 0x07 0x08 0x09 0x0a 0x0b>; + brcm,function = <0x04>; + phandle = <0xb3>; + }; + + dpi_18bit_cpadhi_gpio0 { + brcm,pins = <0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x14 0x15 0x16 0x17 0x18 0x19>; + brcm,function = <0x06>; + brcm,pull = <0x00>; + phandle = <0xb4>; + }; + + dpi_18bit_cpadhi_gpio2 { + brcm,pins = <0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x14 0x15 0x16 0x17 0x18 0x19>; + brcm,function = <0x06>; + phandle = <0xb5>; + }; + + dpi_18bit_gpio0 { + brcm,pins = <0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x12 0x13 0x14 0x15>; + brcm,function = <0x06>; + phandle = <0xb6>; + }; + + dpi_18bit_gpio2 { + brcm,pins = <0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x12 0x13 0x14 0x15>; + brcm,function = <0x06>; + phandle = <0xb7>; + }; + + dpi_16bit_gpio0 { + brcm,pins = <0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x12 0x13>; + brcm,function = <0x06>; + phandle = <0xb8>; + }; + + dpi_16bit_gpio2 { + brcm,pins = <0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x12 0x13>; + brcm,function = <0x06>; + phandle = <0xb9>; + }; + + dpi_16bit_cpadhi_gpio0 { + brcm,pins = <0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x14 0x15 0x16 0x17 0x18>; + brcm,function = <0x06>; + phandle = <0xba>; + }; + + dpi_16bit_cpadhi_gpio2 { + brcm,pins = <0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x14 0x15 0x16 0x17 0x18>; + brcm,function = <0x06>; + phandle = <0xbb>; + }; + + spi0_pins { + brcm,pins = <0x09 0x0a 0x0b>; + brcm,function = <0x04>; + phandle = <0x0e>; + }; + + spi0_cs_pins { + brcm,pins = <0x08 0x07>; + brcm,function = <0x01>; + phandle = <0x0f>; + }; + + spi3_pins { + brcm,pins = <0x01 0x02 0x03>; + brcm,function = <0x07>; + phandle = <0x1c>; + }; + + spi3_cs_pins { + brcm,pins = <0x00 0x18>; + brcm,function = <0x01>; + phandle = <0x1d>; + }; + + spi4_pins { + brcm,pins = <0x05 0x06 0x07>; + brcm,function = <0x07>; + phandle = <0x1e>; + }; + + spi4_cs_pins { + brcm,pins = <0x04 0x19>; + brcm,function = <0x01>; + phandle = <0x1f>; + }; + + spi5_pins { + brcm,pins = <0x0d 0x0e 0x0f>; + brcm,function = <0x07>; + phandle = <0x20>; + }; + + spi5_cs_pins { + brcm,pins = <0x0c 0x1a>; + brcm,function = <0x01>; + phandle = <0x21>; + }; + + spi6_pins { + brcm,pins = <0x13 0x14 0x15>; + brcm,function = <0x07>; + phandle = <0x22>; + }; + + spi6_cs_pins { + brcm,pins = <0x12 0x1b>; + brcm,function = <0x01>; + phandle = <0x23>; + }; + + i2c0 { + brcm,pins = <0x00 0x01>; + brcm,function = <0x04>; + brcm,pull = <0x02>; + phandle = <0xbc>; + }; + + i2c1 { + brcm,pins = <0x02 0x03>; + brcm,function = <0x04>; + brcm,pull = <0x02>; + phandle = <0x15>; + }; + + i2c3 { + brcm,pins = <0x04 0x05>; + brcm,function = <0x02>; + brcm,pull = <0x02>; + phandle = <0x24>; + }; + + i2c4 { + brcm,pins = <0x08 0x09>; + brcm,function = <0x02>; + brcm,pull = <0x02>; + phandle = <0x25>; + }; + + i2c5 { + brcm,pins = <0x0c 0x0d>; + brcm,function = <0x02>; + brcm,pull = <0x02>; + phandle = <0x26>; + }; + + i2c6 { + brcm,pins = <0x16 0x17>; + brcm,function = <0x02>; + brcm,pull = <0x02>; + phandle = <0x27>; + }; + + i2s { + brcm,pins = <0x12 0x13 0x14 0x15>; + brcm,function = <0x04>; + phandle = <0x0d>; + }; + + sdio_pins { + brcm,pins = <0x22 0x23 0x24 0x25 0x26 0x27>; + brcm,function = <0x07>; + brcm,pull = <0x00 0x02 0x02 0x02 0x02 0x02>; + phandle = <0x33>; + }; + + uart2_pins { + brcm,pins = <0x00 0x01>; + brcm,function = <0x03>; + brcm,pull = <0x00 0x02>; + phandle = <0x18>; + }; + + uart3_pins { + brcm,pins = <0x04 0x05>; + brcm,function = <0x03>; + brcm,pull = <0x00 0x02>; + phandle = <0x19>; + }; + + uart4_pins { + brcm,pins = <0x08 0x09>; + brcm,function = <0x03>; + brcm,pull = <0x00 0x02>; + phandle = <0x1a>; + }; + + uart5_pins { + brcm,pins = <0x0c 0x0d>; + brcm,function = <0x03>; + brcm,pull = <0x00 0x02>; + phandle = <0x1b>; + }; + + bt_pins { + brcm,pins = "-"; + brcm,function = <0x00>; + brcm,pull = <0x02>; + phandle = <0x0a>; + }; + + uart0_pins { + brcm,pins = <0x20 0x21>; + brcm,function = <0x07>; + brcm,pull = <0x00 0x02>; + phandle = <0x09>; + }; + + uart1_pins { + brcm,pins; + brcm,function; + brcm,pull; + phandle = <0x12>; + }; + + uart1_bt_pins { + brcm,pins = <0x20 0x21 0x1e 0x1f>; + brcm,function = <0x02>; + brcm,pull = <0x00 0x02 0x02 0x00>; + phandle = <0xbd>; + }; + + audio_pins { + brcm,pins = <0x28 0x29>; + brcm,function = <0x04>; + brcm,pull = <0x00>; + phandle = <0x32>; + }; + }; + + serial@7e201000 { + compatible = "arm,pl011", "arm,primecell"; + reg = <0x7e201000 0x200>; + interrupts = <0x00 0x79 0x04>; + clocks = <0x08 0x13 0x08 0x14>; + clock-names = "uartclk", "apb_pclk"; + arm,primecell-periphid = <0x341011>; + status = "okay"; + cts-event-workaround; + pinctrl-names = "default"; + pinctrl-0 = <0x09 0x0a>; + uart-has-rtscts; + skip-init; + phandle = <0x43>; + + bluetooth { + compatible = "brcm,bcm43438-bt"; + max-speed = <0x2dc6c0>; + shutdown-gpios = <0x0b 0x00 0x00>; + local-bd-address = [00 00 00 00 00 00]; + fallback-bd-address; + status = "okay"; + phandle = <0x41>; + }; + }; + + mmc@7e202000 { + compatible = "brcm,bcm2835-sdhost"; + reg = <0x7e202000 0x100>; + interrupts = <0x00 0x78 0x04>; + clocks = <0x08 0x14>; + status = "disabled"; + dmas = <0x0c 0x2000000d>; + dma-names = "rx-tx"; + bus-width = <0x04>; + brcm,overclock-50 = <0x00>; + brcm,pio-limit = <0x01>; + firmware = <0x06>; + phandle = <0x4b>; + }; + + i2s@7e203000 { + compatible = "brcm,bcm2835-i2s"; + reg = <0x7e203000 0x24>; + clocks = <0x08 0x1f>; + status = "disabled"; + #sound-dai-cells = <0x00>; + dmas = <0x0c 0x02 0x0c 0x03>; + dma-names = "tx", "rx"; + pinctrl-names = "default"; + pinctrl-0 = <0x0d>; + phandle = <0x45>; + }; + + spi@7e204000 { + compatible = "brcm,bcm2835-spi"; + reg = <0x7e204000 0x200>; + interrupts = <0x00 0x76 0x04>; + clocks = <0x08 0x14>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + dmas = <0x0c 0x06 0x0c 0x07>; + dma-names = "tx", "rx"; + pinctrl-names = "default"; + pinctrl-0 = <0x0e 0x0f>; + cs-gpios = <0x07 0x08 0x01 0x07 0x07 0x01>; + phandle = <0x46>; + + spidev@0 { + compatible = "spidev"; + reg = <0x00>; + #address-cells = <0x01>; + #size-cells = <0x00>; + spi-max-frequency = <0x7735940>; + phandle = <0xbe>; + }; + + spidev@1 { + compatible = "spidev"; + reg = <0x01>; + #address-cells = <0x01>; + #size-cells = <0x00>; + spi-max-frequency = <0x7735940>; + phandle = <0xbf>; + }; + }; + + i2c@7e205000 { + compatible = "brcm,bcm2711-i2c", "brcm,bcm2835-i2c"; + reg = <0x7e205000 0x200>; + interrupts = <0x00 0x75 0x04>; + clocks = <0x08 0x14>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + clock-frequency = <0x186a0>; + phandle = <0x34>; + }; + + dpi@7e208000 { + compatible = "brcm,bcm2835-dpi"; + reg = <0x7e208000 0x8c>; + clocks = <0x08 0x14 0x08 0x2c>; + clock-names = "core", "pixel"; + status = "disabled"; + phandle = <0xc0>; + }; + + dsi@7e209000 { + compatible = "brcm,bcm2835-dsi0"; + reg = <0x7e209000 0x78>; + interrupts = <0x00 0x64 0x04>; + #address-cells = <0x01>; + #size-cells = <0x00>; + #clock-cells = <0x01>; + clocks = <0x08 0x22 0x08 0x2f 0x08 0x31>; + clock-names = "phy", "escape", "pixel"; + clock-output-names = "dsi0_byte", "dsi0_ddr2", "dsi0_ddr"; + status = "disabled"; + power-domains = <0x10 0x11>; + phandle = <0x04>; + }; + + aux@7e215000 { + compatible = "brcm,bcm2835-aux"; + #clock-cells = <0x01>; + reg = <0x7e215000 0x08>; + clocks = <0x08 0x14>; + phandle = <0x11>; + }; + + serial@7e215040 { + compatible = "brcm,bcm2835-aux-uart"; + reg = <0x7e215040 0x40>; + interrupts = <0x00 0x5d 0x04>; + clocks = <0x11 0x00>; + status = "okay"; + pinctrl-names = "default"; + pinctrl-0 = <0x12>; + skip-init; + phandle = <0x44>; + + bluetooth { + compatible = "brcm,bcm43438-bt"; + max-speed = <0x38400>; + shutdown-gpios = <0x0b 0x00 0x00>; + local-bd-address = [00 00 00 00 00 00]; + fallback-bd-address; + status = "disabled"; + phandle = <0x42>; + }; + }; + + spi@7e215080 { + compatible = "brcm,bcm2835-aux-spi"; + reg = <0x7e215080 0x40>; + interrupts = <0x00 0x5d 0x04>; + clocks = <0x11 0x01>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + phandle = <0xc1>; + }; + + spi@7e2150c0 { + compatible = "brcm,bcm2835-aux-spi"; + reg = <0x7e2150c0 0x40>; + interrupts = <0x00 0x5d 0x04>; + clocks = <0x11 0x02>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + phandle = <0xc2>; + }; + + pwm@7e20c000 { + compatible = "brcm,bcm2835-pwm"; + reg = <0x7e20c000 0x28>; + clocks = <0x08 0x1e>; + assigned-clocks = <0x08 0x1e>; + assigned-clock-rates = <0x2faf080>; + #pwm-cells = <0x03>; + status = "disabled"; + phandle = <0xc3>; + }; + + mmc@7e300000 { + compatible = "brcm,bcm2835-mmc", "brcm,bcm2835-sdhci"; + reg = <0x7e300000 0x100>; + interrupts = <0x00 0x7e 0x04>; + clocks = <0x08 0x1c>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x13>; + bus-width = <0x04>; + dmas = <0x0c 0x0b>; + dma-names = "rx-tx"; + brcm,overclock-50 = <0x00>; + phandle = <0x4c>; + }; + + hvs@7e400000 { + compatible = "brcm,bcm2711-hvs"; + reg = <0x7e400000 0x8000>; + interrupts = <0x00 0x61 0x04>; + clocks = <0x14 0x04>; + status = "disabled"; + phandle = <0xc4>; + }; + + dsi@7e700000 { + compatible = "brcm,bcm2711-dsi1"; + reg = <0x7e700000 0x8c>; + interrupts = <0x00 0x6c 0x04>; + #address-cells = <0x01>; + #size-cells = <0x00>; + #clock-cells = <0x01>; + clocks = <0x08 0x23 0x08 0x30 0x08 0x32>; + clock-names = "phy", "escape", "pixel"; + clock-output-names = "dsi1_byte", "dsi1_ddr2", "dsi1_ddr"; + status = "disabled"; + power-domains = <0x10 0x12>; + phandle = <0x05>; + }; + + csi@7e800000 { + compatible = "brcm,bcm2835-unicam"; + reg = <0x7e800000 0x800 0x7e802000 0x04>; + reg-names = "unicam", "cmi"; + interrupts = <0x00 0x66 0x04>; + brcm,num-data-lanes = <0x02>; + status = "disabled"; + clocks = <0x08 0x2d 0x14 0x04>; + clock-names = "lp", "vpu"; + power-domains = <0x10 0x0c>; + phandle = <0x51>; + + port { + }; + }; + + csi@7e801000 { + compatible = "brcm,bcm2835-unicam"; + reg = <0x7e801000 0x800 0x7e802004 0x04>; + reg-names = "unicam", "cmi"; + interrupts = <0x00 0x67 0x04>; + brcm,num-data-lanes = <0x02>; + status = "disabled"; + clocks = <0x08 0x2e 0x14 0x04>; + clock-names = "lp", "vpu"; + power-domains = <0x10 0x0d>; + phandle = <0x50>; + + port { + }; + }; + + i2c@7e804000 { + compatible = "brcm,bcm2711-i2c", "brcm,bcm2835-i2c"; + reg = <0x7e804000 0x1000>; + interrupts = <0x00 0x75 0x04>; + clocks = <0x08 0x14>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x15>; + clock-frequency = <0x186a0>; + phandle = <0x48>; + }; + + usb@7e980000 { + compatible = "brcm,bcm2708-usb"; + reg = <0x7e980000 0x10000 0x7e00b200 0x200>; + interrupts = <0x00 0x49 0x04 0x00 0x28 0x04>; + #address-cells = <0x01>; + #size-cells = <0x00>; + clocks = <0x16>; + clock-names = "otg"; + phys = <0x17>; + phy-names = "usb2-phy"; + power-domains = <0x10 0x06>; + interrupt-names = "usb", "soft"; + status = "disabled"; + phandle = <0xc5>; + }; + + interrupt-controller@40000000 { + compatible = "brcm,bcm2836-l1-intc"; + reg = <0x40000000 0x100>; + phandle = <0xc6>; + }; + + interrupt-controller@40041000 { + interrupt-controller; + #interrupt-cells = <0x03>; + compatible = "arm,gic-400"; + reg = <0x40041000 0x1000 0x40042000 0x2000 0x40044000 0x2000 0x40046000 0x2000>; + interrupts = <0x01 0x09 0xf04>; + phandle = <0x01>; + }; + + avs-monitor@7d5d2000 { + compatible = "brcm,bcm2711-avs-monitor", "syscon", "simple-mfd"; + reg = <0x7d5d2000 0xf00>; + phandle = <0xc7>; + + thermal { + compatible = "brcm,bcm2711-thermal"; + #thermal-sensor-cells = <0x00>; + phandle = <0x02>; + }; + }; + + dma-controller@7e007000 { + compatible = "brcm,bcm2835-dma"; + reg = <0x7e007000 0xb00>; + interrupts = <0x00 0x50 0x04 0x00 0x51 0x04 0x00 0x52 0x04 0x00 0x53 0x04 0x00 0x54 0x04 0x00 0x55 0x04 0x00 0x56 0x04 0x00 0x57 0x04 0x00 0x57 0x04 0x00 0x58 0x04 0x00 0x58 0x04>; + interrupt-names = "dma0", "dma1", "dma2", "dma3", "dma4", "dma5", "dma6", "dma7", "dma8", "dma9", "dma10"; + #dma-cells = <0x01>; + brcm,dma-channel-mask = <0x7f5>; + phandle = <0x0c>; + }; + + watchdog@7e100000 { + compatible = "brcm,bcm2711-pm", "brcm,bcm2835-pm-wdt"; + #power-domain-cells = <0x01>; + #reset-cells = <0x01>; + reg = <0x7e100000 0x114 0x7e00a000 0x24 0x7ec11000 0x20>; + reg-names = "pm", "asb", "rpivid_asb"; + clocks = <0x08 0x15 0x08 0x1d 0x08 0x17 0x08 0x16>; + clock-names = "v3d", "peri_image", "h264", "isp"; + system-power-controller; + phandle = <0x49>; + }; + + rng@7e104000 { + compatible = "brcm,bcm2711-rng200"; + reg = <0x7e104000 0x28>; + status = "okay"; + phandle = <0x4a>; + }; + + serial@7e201400 { + compatible = "arm,pl011", "arm,primecell"; + reg = <0x7e201400 0x200>; + interrupts = <0x00 0x79 0x04>; + clocks = <0x08 0x13 0x08 0x14>; + clock-names = "uartclk", "apb_pclk"; + arm,primecell-periphid = <0x341011>; + status = "disabled"; + pinctrl-0 = <0x18>; + pinctrl-names = "default"; + phandle = <0xc8>; + }; + + serial@7e201600 { + compatible = "arm,pl011", "arm,primecell"; + reg = <0x7e201600 0x200>; + interrupts = <0x00 0x79 0x04>; + clocks = <0x08 0x13 0x08 0x14>; + clock-names = "uartclk", "apb_pclk"; + arm,primecell-periphid = <0x341011>; + status = "disabled"; + pinctrl-0 = <0x19>; + pinctrl-names = "default"; + phandle = <0xc9>; + }; + + serial@7e201800 { + compatible = "arm,pl011", "arm,primecell"; + reg = <0x7e201800 0x200>; + interrupts = <0x00 0x79 0x04>; + clocks = <0x08 0x13 0x08 0x14>; + clock-names = "uartclk", "apb_pclk"; + arm,primecell-periphid = <0x341011>; + status = "disabled"; + pinctrl-0 = <0x1a>; + pinctrl-names = "default"; + phandle = <0xca>; + }; + + serial@7e201a00 { + compatible = "arm,pl011", "arm,primecell"; + reg = <0x7e201a00 0x200>; + interrupts = <0x00 0x79 0x04>; + clocks = <0x08 0x13 0x08 0x14>; + clock-names = "uartclk", "apb_pclk"; + arm,primecell-periphid = <0x341011>; + status = "disabled"; + pinctrl-0 = <0x1b>; + pinctrl-names = "default"; + phandle = <0xcb>; + }; + + spi@7e204600 { + compatible = "brcm,bcm2835-spi"; + reg = <0x7e204600 0x200>; + interrupts = <0x00 0x76 0x04>; + clocks = <0x08 0x14>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + pinctrl-0 = <0x1c 0x1d>; + pinctrl-names = "default"; + phandle = <0xcc>; + }; + + spi@7e204800 { + compatible = "brcm,bcm2835-spi"; + reg = <0x7e204800 0x200>; + interrupts = <0x00 0x76 0x04>; + clocks = <0x08 0x14>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + pinctrl-0 = <0x1e 0x1f>; + pinctrl-names = "default"; + phandle = <0xcd>; + }; + + spi@7e204a00 { + compatible = "brcm,bcm2835-spi"; + reg = <0x7e204a00 0x200>; + interrupts = <0x00 0x76 0x04>; + clocks = <0x08 0x14>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + pinctrl-0 = <0x20 0x21>; + pinctrl-names = "default"; + phandle = <0xce>; + }; + + spi@7e204c00 { + compatible = "brcm,bcm2835-spi"; + reg = <0x7e204c00 0x200>; + interrupts = <0x00 0x76 0x04>; + clocks = <0x08 0x14>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + pinctrl-0 = <0x22 0x23>; + pinctrl-names = "default"; + phandle = <0xcf>; + }; + + i2c@7e205600 { + compatible = "brcm,bcm2711-i2c", "brcm,bcm2835-i2c"; + reg = <0x7e205600 0x200>; + interrupts = <0x00 0x75 0x04>; + clocks = <0x08 0x14>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + pinctrl-0 = <0x24>; + pinctrl-names = "default"; + phandle = <0xd0>; + }; + + i2c@7e205800 { + compatible = "brcm,bcm2711-i2c", "brcm,bcm2835-i2c"; + reg = <0x7e205800 0x200>; + interrupts = <0x00 0x75 0x04>; + clocks = <0x08 0x14>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + pinctrl-0 = <0x25>; + pinctrl-names = "default"; + phandle = <0xd1>; + }; + + i2c@7e205a00 { + compatible = "brcm,bcm2711-i2c", "brcm,bcm2835-i2c"; + reg = <0x7e205a00 0x200>; + interrupts = <0x00 0x75 0x04>; + clocks = <0x08 0x14>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + pinctrl-0 = <0x26>; + pinctrl-names = "default"; + phandle = <0xd2>; + }; + + i2c@7e205c00 { + compatible = "brcm,bcm2711-i2c", "brcm,bcm2835-i2c"; + reg = <0x7e205c00 0x200>; + interrupts = <0x00 0x75 0x04>; + clocks = <0x08 0x14>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + pinctrl-0 = <0x27>; + pinctrl-names = "default"; + phandle = <0xd3>; + }; + + pixelvalve@7e206000 { + compatible = "brcm,bcm2711-pixelvalve0"; + reg = <0x7e206000 0x100>; + interrupts = <0x00 0x6d 0x04>; + status = "disabled"; + phandle = <0xd4>; + }; + + pixelvalve@7e207000 { + compatible = "brcm,bcm2711-pixelvalve1"; + reg = <0x7e207000 0x100>; + interrupts = <0x00 0x6e 0x04>; + status = "disabled"; + phandle = <0xd5>; + }; + + pixelvalve@7e20a000 { + compatible = "brcm,bcm2711-pixelvalve2"; + reg = <0x7e20a000 0x100>; + interrupts = <0x00 0x65 0x04>; + status = "disabled"; + phandle = <0xd6>; + }; + + pwm@7e20c800 { + compatible = "brcm,bcm2835-pwm"; + reg = <0x7e20c800 0x28>; + clocks = <0x08 0x1e>; + assigned-clocks = <0x08 0x1e>; + assigned-clock-rates = <0x2faf080>; + #pwm-cells = <0x03>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x28 0x29>; + phandle = <0xd7>; + }; + + pixelvalve@7e216000 { + compatible = "brcm,bcm2711-pixelvalve4"; + reg = <0x7e216000 0x100>; + interrupts = <0x00 0x6e 0x04>; + status = "disabled"; + phandle = <0xd8>; + }; + + pixelvalve@7ec12000 { + compatible = "brcm,bcm2711-pixelvalve3"; + reg = <0x7ec12000 0x100>; + interrupts = <0x00 0x6a 0x04>; + status = "disabled"; + phandle = <0xd9>; + }; + + vec@7ec13000 { + compatible = "brcm,bcm2711-vec"; + reg = <0x7ec13000 0x1000>; + clocks = <0x14 0x0f>; + interrupts = <0x00 0x7b 0x04>; + status = "disabled"; + power-domains = <0x10 0x07>; + phandle = <0xda>; + }; + + clock@7ef00000 { + compatible = "brcm,brcm2711-dvp"; + reg = <0x7ef00000 0x10>; + clocks = <0x2a>; + #clock-cells = <0x01>; + #reset-cells = <0x01>; + status = "disabled"; + phandle = <0x2b>; + }; + + interrupt-controller@7ef00100 { + compatible = "brcm,bcm2711-l2-intc", "brcm,l2-intc"; + reg = <0x7ef00100 0x30>; + interrupts = <0x00 0x60 0x01>; + interrupt-controller; + #interrupt-cells = <0x01>; + status = "disabled"; + phandle = <0x2c>; + }; + + hdmi@7ef00700 { + compatible = "brcm,bcm2711-hdmi0"; + reg = <0x7ef00700 0x300 0x7ef00300 0x200 0x7ef00f00 0x80 0x7ef00f80 0x80 0x7ef01b00 0x200 0x7ef01f00 0x400 0x7ef00200 0x80 0x7ef04300 0x100 0x7ef20000 0x100 0x7ef00100 0x30>; + reg-names = "hdmi", "dvp", "phy", "rm", "packet", "metadata", "csc", "cec", "hd", "intr2"; + clock-names = "hdmi", "bvb", "audio", "cec"; + resets = <0x2b 0x00>; + interrupt-parent = <0x2c>; + interrupts = <0x00 0x01 0x02 0x03 0x04 0x05>; + interrupt-names = "cec-tx", "cec-rx", "cec-low", "wakeup", "hpd-connected", "hpd-removed"; + ddc = <0x2d>; + dmas = <0x2e 0x41fa000a>; + dma-names = "audio-rx"; + status = "disabled"; + clocks = <0x14 0x0d 0x14 0x0e 0x2b 0x00 0x2f>; + wifi-2.4ghz-coexistence; + phandle = <0x55>; + }; + + i2c@7ef04500 { + compatible = "brcm,bcm2711-hdmi-i2c"; + reg = <0x7ef04500 0x100 0x7ef00b00 0x300>; + reg-names = "bsc", "auto-i2c"; + clock-frequency = <0x17cdc>; + status = "disabled"; + phandle = <0x2d>; + }; + + hdmi@7ef05700 { + compatible = "brcm,bcm2711-hdmi1"; + reg = <0x7ef05700 0x300 0x7ef05300 0x200 0x7ef05f00 0x80 0x7ef05f80 0x80 0x7ef06b00 0x200 0x7ef06f00 0x400 0x7ef00280 0x80 0x7ef09300 0x100 0x7ef20000 0x100 0x7ef00100 0x30>; + reg-names = "hdmi", "dvp", "phy", "rm", "packet", "metadata", "csc", "cec", "hd", "intr2"; + ddc = <0x30>; + clock-names = "hdmi", "bvb", "audio", "cec"; + resets = <0x2b 0x01>; + interrupt-parent = <0x2c>; + interrupts = <0x08 0x07 0x06 0x09 0x0a 0x0b>; + interrupt-names = "cec-tx", "cec-rx", "cec-low", "wakeup", "hpd-connected", "hpd-removed"; + dmas = <0x2e 0x41fa0011>; + dma-names = "audio-rx"; + status = "disabled"; + clocks = <0x14 0x0d 0x14 0x0e 0x2b 0x01 0x2f>; + wifi-2.4ghz-coexistence; + phandle = <0x56>; + }; + + i2c@7ef09500 { + compatible = "brcm,bcm2711-hdmi-i2c"; + reg = <0x7ef09500 0x100 0x7ef05b00 0x300>; + reg-names = "bsc", "auto-i2c"; + clock-frequency = <0x17cdc>; + status = "disabled"; + phandle = <0x30>; + }; + + firmware { + compatible = "raspberrypi,bcm2835-firmware", "simple-mfd"; + mboxes = <0x31>; + phandle = <0x06>; + + clocks { + compatible = "raspberrypi,firmware-clocks"; + #clock-cells = <0x01>; + phandle = <0x14>; + }; + + gpio { + compatible = "raspberrypi,firmware-gpio"; + gpio-controller; + #gpio-cells = <0x02>; + status = "okay"; + gpio-line-names = "BT_ON", "WL_ON", "PWR_LED_OFF", "GLOBAL_RESET", "VDD_SD_IO_SEL", "CAM_GPIO", "SD_PWR_ON", "SD_OC_N"; + phandle = <0x0b>; + }; + + reset { + compatible = "raspberrypi,firmware-reset"; + #reset-cells = <0x01>; + phandle = <0x3f>; + }; + + vcio { + compatible = "raspberrypi,vcio"; + phandle = <0xdb>; + }; + }; + + power { + compatible = "raspberrypi,bcm2835-power"; + firmware = <0x06>; + #power-domain-cells = <0x01>; + phandle = <0x10>; + }; + + mailbox@7e00b840 { + compatible = "brcm,bcm2711-vchiq"; + reg = <0x7e00b840 0x3c>; + interrupts = <0x00 0x22 0x04>; + pinctrl-names = "default"; + pinctrl-0 = <0x32>; + phandle = <0xdc>; + }; + + mmcnr@7e300000 { + compatible = "brcm,bcm2835-mmc", "brcm,bcm2835-sdhci"; + reg = <0x7e300000 0x100>; + interrupts = <0x00 0x7e 0x04>; + clocks = <0x08 0x1c>; + dmas = <0x0c 0x0b>; + dma-names = "rx-tx"; + brcm,overclock-50 = <0x00>; + non-removable; + status = "okay"; + #address-cells = <0x01>; + #size-cells = <0x00>; + pinctrl-names = "default"; + pinctrl-0 = <0x33>; + bus-width = <0x04>; + phandle = <0x4d>; + + wifi@1 { + reg = <0x01>; + compatible = "brcm,bcm4329-fmac"; + phandle = <0xdd>; + }; + }; + + firmwarekms@7e600000 { + compatible = "raspberrypi,rpi-firmware-kms-2711"; + reg = <0x7e600000 0x100>; + interrupts = <0x00 0x70 0x04>; + brcm,firmware = <0x06>; + status = "disabled"; + phandle = <0xde>; + }; + + smi@7e600000 { + compatible = "brcm,bcm2835-smi"; + reg = <0x7e600000 0x100>; + interrupts = <0x00 0x70 0x04>; + clocks = <0x08 0x2a>; + assigned-clocks = <0x08 0x2a>; + assigned-clock-rates = <0x7735940>; + dmas = <0x0c 0x04>; + dma-names = "rx-tx"; + status = "disabled"; + phandle = <0xdf>; + }; + + axiperf { + compatible = "brcm,bcm2711-axiperf"; + reg = <0x7e009800 0x100 0x7ee08000 0x100>; + firmware = <0x06>; + status = "disabled"; + phandle = <0x4e>; + }; + + i2c0mux { + compatible = "i2c-mux-pinctrl"; + #address-cells = <0x01>; + #size-cells = <0x00>; + i2c-parent = <0x34>; + status = "disabled"; + pinctrl-names = "i2c0", "i2c_csi_dsi"; + pinctrl-0 = <0x35>; + pinctrl-1 = <0x36>; + phandle = <0x47>; + + i2c@0 { + reg = <0x00>; + #address-cells = <0x01>; + #size-cells = <0x00>; + phandle = <0xe0>; + }; + + i2c@1 { + reg = <0x01>; + #address-cells = <0x01>; + #size-cells = <0x00>; + phandle = <0xe1>; + }; + }; + + gpiomem { + compatible = "brcm,bcm2835-gpiomem"; + reg = <0x7e200000 0x1000>; + }; + + fb { + compatible = "brcm,bcm2708-fb"; + firmware = <0x06>; + status = "okay"; + phandle = <0xe2>; + }; + + sound { + status = "disabled"; + phandle = <0xe3>; + }; + + nvmem { + compatible = "simple-bus"; + #address-cells = <0x01>; + #size-cells = <0x01>; + + nvmem_otp { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x06>; + reg = <0x00 0xa6>; + status = "okay"; + phandle = <0xe4>; + }; + + nvmem_cust { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x06>; + reg = <0x01 0x08>; + status = "okay"; + phandle = <0x57>; + }; + + nvmem_priv { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x06>; + reg = <0x03 0x08>; + status = "okay"; + phandle = <0x58>; + }; + }; + }; + + clocks { + compatible = "simple-bus"; + #address-cells = <0x01>; + #size-cells = <0x00>; + + clk-osc { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "osc"; + clock-frequency = <0x337f980>; + phandle = <0x03>; + }; + + clk-usb { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "otg"; + clock-frequency = <0x1c9c3800>; + phandle = <0x16>; + }; + }; + + phy { + compatible = "usb-nop-xceiv"; + #phy-cells = <0x00>; + phandle = <0x17>; + }; + + gpu { + compatible = "brcm,bcm2711-vc5"; + status = "disabled"; + raspberrypi,firmware = <0x06>; + phandle = <0xe5>; + }; + + clk-27M { + #clock-cells = <0x00>; + compatible = "fixed-clock"; + clock-frequency = <0x19bfcc0>; + clock-output-names = "27MHz-clock"; + phandle = <0x2f>; + }; + + clk-108M { + #clock-cells = <0x00>; + compatible = "fixed-clock"; + clock-frequency = <0x66ff300>; + clock-output-names = "108MHz-clock"; + phandle = <0x2a>; + }; + + emmc2bus { + compatible = "simple-bus"; + #address-cells = <0x02>; + #size-cells = <0x01>; + ranges = <0x00 0x7e000000 0x00 0xfe000000 0x1800000>; + dma-ranges = <0x00 0xc0000000 0x00 0x00 0x40000000>; + phandle = <0xe6>; + + mmc@7e340000 { + compatible = "brcm,bcm2711-emmc2"; + reg = <0x00 0x7e340000 0x100>; + interrupts = <0x00 0x7e 0x04>; + clocks = <0x08 0x33>; + status = "okay"; + vqmmc-supply = <0x37>; + vmmc-supply = <0x38>; + broken-cd; + mmc-ddr-3_3v; + phandle = <0x59>; + }; + }; + + pmu { + compatible = "arm,cortex-a72-pmu"; + interrupts = <0x00 0x10 0x04 0x00 0x11 0x04 0x00 0x12 0x04 0x00 0x13 0x04>; + interrupt-affinity = <0x39 0x3a 0x3b 0x3c>; + }; + + timer { + compatible = "arm,armv8-timer"; + interrupts = <0x01 0x0d 0xf08 0x01 0x0e 0xf08 0x01 0x0b 0xf08 0x01 0x0a 0xf08>; + }; + + cpus { + #address-cells = <0x01>; + #size-cells = <0x00>; + enable-method = "brcm,bcm2836-smp"; + phandle = <0xe7>; + + cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a72"; + reg = <0x00>; + enable-method = "spin-table"; + cpu-release-addr = <0x00 0xd8>; + d-cache-size = <0x8000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0xc000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x3d>; + phandle = <0x39>; + }; + + cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a72"; + reg = <0x01>; + enable-method = "spin-table"; + cpu-release-addr = <0x00 0xe0>; + d-cache-size = <0x8000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0xc000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x3d>; + phandle = <0x3a>; + }; + + cpu@2 { + device_type = "cpu"; + compatible = "arm,cortex-a72"; + reg = <0x02>; + enable-method = "spin-table"; + cpu-release-addr = <0x00 0xe8>; + d-cache-size = <0x8000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0xc000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x3d>; + phandle = <0x3b>; + }; + + cpu@3 { + device_type = "cpu"; + compatible = "arm,cortex-a72"; + reg = <0x03>; + enable-method = "spin-table"; + cpu-release-addr = <0x00 0xf0>; + d-cache-size = <0x8000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0xc000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x3d>; + phandle = <0x3c>; + }; + + l2-cache0 { + compatible = "cache"; + cache-unified; + cache-size = <0x100000>; + cache-line-size = <0x40>; + cache-sets = <0x400>; + cache-level = <0x02>; + phandle = <0x3d>; + }; + }; + + scb { + compatible = "simple-bus"; + #address-cells = <0x02>; + #size-cells = <0x02>; + ranges = <0x00 0x7c000000 0x00 0xfc000000 0x00 0x3800000 0x00 0x40000000 0x00 0xff800000 0x00 0x800000 0x06 0x00 0x06 0x00 0x00 0x40000000 0x00 0x00 0x00 0x00 0x00 0xfc000000>; + dma-ranges = <0x04 0x7c000000 0x00 0xfc000000 0x00 0x3800000 0x00 0x00 0x00 0x00 0x04 0x00>; + phandle = <0xe8>; + + pcie@7d500000 { + compatible = "brcm,bcm2711-pcie"; + reg = <0x00 0x7d500000 0x00 0x9310>; + device_type = "pci"; + #address-cells = <0x03>; + #interrupt-cells = <0x01>; + #size-cells = <0x02>; + interrupts = <0x00 0x93 0x04 0x00 0x94 0x04>; + interrupt-names = "pcie", "msi"; + interrupt-map-mask = <0x00 0x00 0x00 0x07>; + interrupt-map = <0x00 0x00 0x00 0x01 0x01 0x00 0x8f 0x04 0x00 0x00 0x00 0x02 0x01 0x00 0x90 0x04 0x00 0x00 0x00 0x03 0x01 0x00 0x91 0x04 0x00 0x00 0x00 0x04 0x01 0x00 0x92 0x04>; + msi-controller; + msi-parent = <0x3e>; + ranges = <0x2000000 0x00 0xc0000000 0x06 0x00 0x00 0x40000000>; + dma-ranges = <0x2000000 0x00 0x00 0x00 0x00 0x00 0xc0000000>; + brcm,enable-ssc; + phandle = <0x3e>; + + pci@0,0 { + device_type = "pci"; + #address-cells = <0x03>; + #size-cells = <0x02>; + ranges; + reg = <0x00 0x00 0x00 0x00 0x00>; + + usb@0,0 { + reg = <0x00 0x00 0x00 0x00 0x00>; + resets = <0x3f 0x00>; + }; + }; + }; + + ethernet@7d580000 { + compatible = "brcm,bcm2711-genet-v5"; + reg = <0x00 0x7d580000 0x00 0x10000>; + #address-cells = <0x01>; + #size-cells = <0x01>; + interrupts = <0x00 0x9d 0x04 0x00 0x9e 0x04>; + status = "okay"; + phy-handle = <0x40>; + phy-mode = "rgmii-rxid"; + phandle = <0xe9>; + + mdio@e14 { + compatible = "brcm,genet-mdio-v5"; + reg = <0xe14 0x08>; + reg-names = "mdio"; + #address-cells = <0x01>; + #size-cells = <0x00>; + phandle = <0xea>; + + ethernet-phy@1 { + reg = <0x01>; + led-modes = <0x00 0x08>; + phandle = <0x40>; + }; + }; + }; + + codec@7eb10000 { + compatible = "brcm,bcm2711-hevc-dec", "raspberrypi,hevc-dec"; + reg = <0x00 0x7eb00000 0x00 0x10000 0x00 0x7eb10000 0x00 0x1000>; + reg-names = "hevc", "intc"; + interrupts = <0x00 0x62 0x04>; + clocks = <0x14 0x0b>; + phandle = <0xeb>; + }; + + dma@7e007b00 { + compatible = "brcm,bcm2711-dma"; + reg = <0x00 0x7e007b00 0x00 0x400>; + interrupts = <0x00 0x59 0x04 0x00 0x5a 0x04 0x00 0x5b 0x04 0x00 0x5c 0x04>; + interrupt-names = "dma11", "dma12", "dma13", "dma14"; + #dma-cells = <0x01>; + brcm,dma-channel-mask = <0x7000>; + phandle = <0x2e>; + }; + + xhci@7e9c0000 { + compatible = "generic-xhci"; + status = "disabled"; + reg = <0x00 0x7e9c0000 0x00 0x100000>; + interrupts = <0x00 0xb0 0x04>; + power-domains = <0x10 0x06>; + phandle = <0xec>; + }; + }; + + memory@0 { + device_type = "memory"; + reg = <0x00 0x00 0x00>; + }; + + leds { + compatible = "gpio-leds"; + phandle = <0xed>; + + led-act { + label = "ACT"; + default-state = "off"; + linux,default-trigger = "mmc0"; + gpios = <0x07 0x2a 0x00>; + phandle = <0x5a>; + }; + + led-pwr { + label = "PWR"; + gpios = <0x0b 0x02 0x01>; + default-state = "off"; + linux,default-trigger = "default-on"; + phandle = <0x5b>; + }; + }; + + cam1_clk { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + status = "disabled"; + phandle = <0xee>; + }; + + cam0_regulator { + compatible = "regulator-fixed"; + regulator-name = "cam0-reg"; + enable-active-high; + status = "disabled"; + phandle = <0xef>; + }; + + cam0_clk { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + status = "disabled"; + phandle = <0xf0>; + }; + + cam_dummy_reg { + compatible = "regulator-fixed"; + regulator-name = "cam-dummy-reg"; + status = "okay"; + phandle = <0x52>; + }; + + __overrides__ { + cam0-pwdn-ctrl; + cam0-pwdn; + cam0-led-ctrl; + cam0-led; + bdaddr = "", "", "", "Alocal-bd-address[", "", "", "", "Afallback-bd-address?=0", "", "", "", "Blocal-bd-address[", "", "", "", "Bfallback-bd-address?=0"; + krnbt = "", "", "", "Astatus"; + krnbt_baudrate = "", "", "", "Amax-speed:0", "", "", "", "Bmax-speed:0"; + cache_line_size; + uart0 = "", "", "", "Cstatus"; + uart1 = "", "", "", "Dstatus"; + i2s = "", "", "", "Estatus"; + spi = "", "", "", "Fstatus"; + i2c0 = "", "", "", "4status", "", "", "", "Gstatus"; + i2c1 = "", "", "", "Hstatus"; + i2c = "", "", "", "Hstatus"; + i2c_arm = "", "", "", "Hstatus"; + i2c_vc = "", "", "", "4status", "", "", "", "Gstatus"; + i2c0_baudrate = "", "", "", "4clock-frequency:0"; + i2c1_baudrate = "", "", "", "Hclock-frequency:0"; + i2c_baudrate = "", "", "", "Hclock-frequency:0"; + i2c_arm_baudrate = "", "", "", "Hclock-frequency:0"; + i2c_vc_baudrate = "", "", "", "4clock-frequency:0"; + watchdog = "", "", "", "Istatus"; + random = "", "", "", "Jstatus"; + sd_overclock = "", "", "", "Kbrcm,overclock-50:0"; + sd_force_pio = "", "", "", "Kbrcm,force-pio?"; + sd_pio_limit = "", "", "", "Kbrcm,pio-limit:0"; + sd_debug = "", "", "", "Kbrcm,debug"; + sdio_overclock = "", "", "", "Lbrcm,overclock-50:0", "", "", "", "Mbrcm,overclock-50:0"; + axiperf = "", "", "", "Nstatus"; + drm_fb0_vc4 = "", "", "", "Odrm-fb0=", "/gpu"; + drm_fb1_vc4 = "", "", "", "Odrm-fb1=", "/gpu"; + drm_fb2_vc4 = "", "", "", "Odrm-fb2=", "/gpu"; + cam1_sync = "", "", "", "Psync-gpios:0=", "", "", "", "\a", "", "", "Psync-gpios:4", "", "", "", "Psync-gpios:8=", "", "", "", ""; + cam1_sync_inverted = [00 00 00 50 73 79 6e 63 2d 67 70 69 6f 73 3a 30 3d 00 00 00 00 07 00 00 00 50 73 79 6e 63 2d 67 70 69 6f 73 3a 34 00 00 00 00 50 73 79 6e 63 2d 67 70 69 6f 73 3a 38 3d 00 00 00 00 01]; + cam0_sync = "", "", "", "Qsync-gpios:0=", "", "", "", "\a", "", "", "Qsync-gpios:4", "", "", "", "Qsync-gpios:8=", "", "", "", ""; + cam0_sync_inverted = [00 00 00 51 73 79 6e 63 2d 67 70 69 6f 73 3a 30 3d 00 00 00 00 07 00 00 00 51 73 79 6e 63 2d 67 70 69 6f 73 3a 34 00 00 00 00 51 73 79 6e 63 2d 67 70 69 6f 73 3a 38 3d 00 00 00 00 01]; + cam0_reg = "", "", "", "Rstatus"; + cam0_reg_gpio = [00 00 00 52 67 70 69 6f 3a 34 00 00 00 00 52 67 70 69 6f 3a 30 3d 00 00 00 00 07]; + cam1_reg = "", "", "", "Sstatus"; + cam1_reg_gpio = [00 00 00 53 67 70 69 6f 3a 34 00 00 00 00 53 67 70 69 6f 3a 30 3d 00 00 00 00 07]; + strict_gpiod = "", "", "", "Tbootargs=pinctrl_bcm2835.persist_gpio_outputs=n"; + arm_freq; + eee = "", "", "", "Tbootargs{on='',off='genet.eee=N'}"; + hdmi = "", "", "", "Ustatus", "", "", "", "Vstatus"; + nvmem_cust_rw = "", "", "", "Wrw?"; + nvmem_priv_rw = "", "", "", "Xrw?"; + pcie = "", "", "", ">status"; + sd = "", "", "", "Ystatus"; + sd_poll_once = "", "", "", "Ynon-removable?"; + spi_dma4 = <0x46 0x646d6173 0x3a303d00 0x2e 0x46 0x646d6173 0x3a383d00 0x2e>; + i2s_dma4 = <0x45 0x646d6173 0x3a303d00 0x2e 0x45 0x646d6173 0x3a383d00 0x2e>; + audio = "", "", "", "Tbootargs{on='snd_bcm2835.enable_headphones=1 snd_bcm2835.enable_hdmi=1',off='snd_bcm2835.enable_headphones=0 snd_bcm2835.enable_hdmi=0'}"; + act_led_gpio = "", "", "", "Zgpios:4"; + act_led_activelow = "", "", "", "Zgpios:8"; + act_led_trigger = "", "", "", "Zlinux,default-trigger"; + pwr_led_gpio = "", "", "", "[gpios:4"; + pwr_led_activelow = "", "", "", "[gpios:8"; + pwr_led_trigger = "", "", "", "[linux,default-trigger"; + eth_led0 = "", "", "", "@led-modes:0"; + eth_led1 = "", "", "", "@led-modes:4"; + }; + + regulator-cam1 { + compatible = "regulator-fixed"; + regulator-name = "cam1-reg"; + enable-active-high; + gpio = <0x0b 0x05 0x00>; + phandle = <0x53>; + }; + + regulator-sd-io-1v8 { + compatible = "regulator-gpio"; + regulator-name = "vdd-sd-io"; + regulator-min-microvolt = <0x1b7740>; + regulator-max-microvolt = <0x325aa0>; + regulator-boot-on; + regulator-always-on; + regulator-settling-time-us = <0x1388>; + gpios = <0x0b 0x04 0x00>; + states = <0x1b7740 0x01 0x325aa0 0x00>; + status = "okay"; + phandle = <0x37>; + }; + + regulator-sd-vcc { + compatible = "regulator-fixed"; + regulator-name = "vcc-sd"; + regulator-min-microvolt = <0x325aa0>; + regulator-max-microvolt = <0x325aa0>; + regulator-boot-on; + enable-active-high; + gpio = <0x0b 0x06 0x00>; + phandle = <0x38>; + }; + + fixedregulator_3v3 { + compatible = "regulator-fixed"; + regulator-always-on; + regulator-max-microvolt = <0x325aa0>; + regulator-min-microvolt = <0x325aa0>; + regulator-name = "3v3"; + phandle = <0xf1>; + }; + + fixedregulator_5v0 { + compatible = "regulator-fixed"; + regulator-always-on; + regulator-max-microvolt = <0x4c4b40>; + regulator-min-microvolt = <0x4c4b40>; + regulator-name = "5v0"; + phandle = <0xf2>; + }; + + zone_dma { + #address-cells = <0x01>; + #size-cells = <0x01>; + dma-ranges = <0x00 0x00 0x00 0x40000000>; + }; + + v3dbus { + compatible = "simple-bus"; + #address-cells = <0x01>; + #size-cells = <0x02>; + ranges = <0x7c500000 0x00 0xfc500000 0x00 0x3300000 0x40000000 0x00 0xff800000 0x00 0x800000>; + dma-ranges = <0x00 0x00 0x00 0x04 0x00>; + phandle = <0xf3>; + + v3d@7ec04000 { + compatible = "brcm,2711-v3d"; + reg = <0x7ec00000 0x00 0x4000 0x7ec04000 0x00 0x4000>; + reg-names = "hub", "core0"; + power-domains = <0x49 0x01>; + resets = <0x49 0x00>; + clocks = <0x14 0x05>; + clocks-names = "v3d"; + interrupts = <0x00 0x4a 0x04>; + status = "disabled"; + phandle = <0xf4>; + }; + }; + + __symbols__ { + aliases = "/aliases"; + chosen = "/chosen"; + rmem = "/reserved-memory"; + cma = "/reserved-memory/linux,cma"; + blconfig = "/reserved-memory/nvram@0"; + blpubkey = "/reserved-memory/nvram@1"; + cpu_thermal = "/thermal-zones/cpu-thermal"; + thermal_trips = "/thermal-zones/cpu-thermal/trips"; + cooling_maps = "/thermal-zones/cpu-thermal/cooling-maps"; + soc = "/soc"; + system_timer = "/soc/timer@7e003000"; + txp = "/soc/txp@7e004000"; + clocks = "/soc/cprman@7e101000"; + mailbox = "/soc/mailbox@7e00b880"; + gpio = "/soc/gpio@7e200000"; + dpi_gpio0 = "/soc/gpio@7e200000/dpi-gpio0"; + emmc_gpio22 = "/soc/gpio@7e200000/emmc-gpio22"; + emmc_gpio34 = "/soc/gpio@7e200000/emmc-gpio34"; + emmc_gpio48 = "/soc/gpio@7e200000/emmc-gpio48"; + gpclk0_gpio4 = "/soc/gpio@7e200000/gpclk0-gpio4"; + gpclk1_gpio5 = "/soc/gpio@7e200000/gpclk1-gpio5"; + gpclk1_gpio42 = "/soc/gpio@7e200000/gpclk1-gpio42"; + gpclk1_gpio44 = "/soc/gpio@7e200000/gpclk1-gpio44"; + gpclk2_gpio6 = "/soc/gpio@7e200000/gpclk2-gpio6"; + gpclk2_gpio43 = "/soc/gpio@7e200000/gpclk2-gpio43"; + i2c0_gpio0 = "/soc/gpio@7e200000/i2c0if-gpio0"; + i2c0_gpio28 = "/soc/gpio@7e200000/i2c0if-gpio28"; + i2c0_gpio44 = "/soc/gpio@7e200000/i2c0if-gpio44"; + i2c1_gpio2 = "/soc/gpio@7e200000/i2c1-gpio2"; + i2c1_gpio44 = "/soc/gpio@7e200000/i2c1-gpio44"; + jtag_gpio22 = "/soc/gpio@7e200000/jtag-gpio22"; + pcm_gpio18 = "/soc/gpio@7e200000/pcm-gpio18"; + pcm_gpio28 = "/soc/gpio@7e200000/pcm-gpio28"; + sdhost_gpio48 = "/soc/gpio@7e200000/sdhost-gpio48"; + spi0_gpio7 = "/soc/gpio@7e200000/spi0-gpio7"; + spi0_gpio35 = "/soc/gpio@7e200000/spi0-gpio35"; + spi1_gpio16 = "/soc/gpio@7e200000/spi1-gpio16"; + spi2_gpio40 = "/soc/gpio@7e200000/spi2-gpio40"; + uart0_gpio14 = "/soc/gpio@7e200000/uart0-gpio14"; + uart0_ctsrts_gpio16 = "/soc/gpio@7e200000/uart0-ctsrts-gpio16"; + uart0_ctsrts_gpio30 = "/soc/gpio@7e200000/uart0-ctsrts-gpio30"; + uart0_gpio32 = "/soc/gpio@7e200000/uart0-gpio32"; + uart0_gpio36 = "/soc/gpio@7e200000/uart0-gpio36"; + uart0_ctsrts_gpio38 = "/soc/gpio@7e200000/uart0-ctsrts-gpio38"; + uart1_gpio14 = "/soc/gpio@7e200000/uart1-gpio14"; + uart1_ctsrts_gpio16 = "/soc/gpio@7e200000/uart1-ctsrts-gpio16"; + uart1_gpio32 = "/soc/gpio@7e200000/uart1-gpio32"; + uart1_ctsrts_gpio30 = "/soc/gpio@7e200000/uart1-ctsrts-gpio30"; + uart1_gpio40 = "/soc/gpio@7e200000/uart1-gpio40"; + uart1_ctsrts_gpio42 = "/soc/gpio@7e200000/uart1-ctsrts-gpio42"; + gpclk0_gpio49 = "/soc/gpio@7e200000/gpclk0-gpio49"; + gpclk1_gpio50 = "/soc/gpio@7e200000/gpclk1-gpio50"; + gpclk2_gpio51 = "/soc/gpio@7e200000/gpclk2-gpio51"; + i2c0_gpio46 = "/soc/gpio@7e200000/i2c0if-gpio46"; + i2c1_gpio46 = "/soc/gpio@7e200000/i2c1-gpio46"; + i2c3_gpio2 = "/soc/gpio@7e200000/i2c3-gpio2"; + i2c3_gpio4 = "/soc/gpio@7e200000/i2c3-gpio4"; + i2c4_gpio6 = "/soc/gpio@7e200000/i2c4-gpio6"; + i2c4_gpio8 = "/soc/gpio@7e200000/i2c4-gpio8"; + i2c5_gpio10 = "/soc/gpio@7e200000/i2c5-gpio10"; + i2c5_gpio12 = "/soc/gpio@7e200000/i2c5-gpio12"; + i2c6_gpio0 = "/soc/gpio@7e200000/i2c6-gpio0"; + i2c6_gpio22 = "/soc/gpio@7e200000/i2c6-gpio22"; + i2c_slave_gpio8 = "/soc/gpio@7e200000/i2c-slave-gpio8"; + jtag_gpio48 = "/soc/gpio@7e200000/jtag-gpio48"; + mii_gpio28 = "/soc/gpio@7e200000/mii-gpio28"; + mii_gpio36 = "/soc/gpio@7e200000/mii-gpio36"; + pcm_gpio50 = "/soc/gpio@7e200000/pcm-gpio50"; + pwm0_0_gpio12 = "/soc/gpio@7e200000/pwm0-0-gpio12"; + pwm0_0_gpio18 = "/soc/gpio@7e200000/pwm0-0-gpio18"; + pwm1_0_gpio40 = "/soc/gpio@7e200000/pwm1-0-gpio40"; + pwm0_1_gpio13 = "/soc/gpio@7e200000/pwm0-1-gpio13"; + pwm0_1_gpio19 = "/soc/gpio@7e200000/pwm0-1-gpio19"; + pwm1_1_gpio41 = "/soc/gpio@7e200000/pwm1-1-gpio41"; + pwm0_1_gpio45 = "/soc/gpio@7e200000/pwm0-1-gpio45"; + pwm0_0_gpio52 = "/soc/gpio@7e200000/pwm0-0-gpio52"; + pwm0_1_gpio53 = "/soc/gpio@7e200000/pwm0-1-gpio53"; + rgmii_gpio35 = "/soc/gpio@7e200000/rgmii-gpio35"; + rgmii_irq_gpio34 = "/soc/gpio@7e200000/rgmii-irq-gpio34"; + rgmii_irq_gpio39 = "/soc/gpio@7e200000/rgmii-irq-gpio39"; + rgmii_mdio_gpio28 = "/soc/gpio@7e200000/rgmii-mdio-gpio28"; + rgmii_mdio_gpio37 = "/soc/gpio@7e200000/rgmii-mdio-gpio37"; + spi0_gpio46 = "/soc/gpio@7e200000/spi0-gpio46"; + spi2_gpio46 = "/soc/gpio@7e200000/spi2-gpio46"; + spi3_gpio0 = "/soc/gpio@7e200000/spi3-gpio0"; + spi4_gpio4 = "/soc/gpio@7e200000/spi4-gpio4"; + spi5_gpio12 = "/soc/gpio@7e200000/spi5-gpio12"; + spi6_gpio18 = "/soc/gpio@7e200000/spi6-gpio18"; + uart2_gpio0 = "/soc/gpio@7e200000/uart2-gpio0"; + uart2_ctsrts_gpio2 = "/soc/gpio@7e200000/uart2-ctsrts-gpio2"; + uart3_gpio4 = "/soc/gpio@7e200000/uart3-gpio4"; + uart3_ctsrts_gpio6 = "/soc/gpio@7e200000/uart3-ctsrts-gpio6"; + uart4_gpio8 = "/soc/gpio@7e200000/uart4-gpio8"; + uart4_ctsrts_gpio10 = "/soc/gpio@7e200000/uart4-ctsrts-gpio10"; + uart5_gpio12 = "/soc/gpio@7e200000/uart5-gpio12"; + uart5_ctsrts_gpio14 = "/soc/gpio@7e200000/uart5-ctsrts-gpio14"; + gpioout = "/soc/gpio@7e200000/gpioout"; + alt0 = "/soc/gpio@7e200000/alt0"; + dpi_18bit_cpadhi_gpio0 = "/soc/gpio@7e200000/dpi_18bit_cpadhi_gpio0"; + dpi_18bit_cpadhi_gpio2 = "/soc/gpio@7e200000/dpi_18bit_cpadhi_gpio2"; + dpi_18bit_gpio0 = "/soc/gpio@7e200000/dpi_18bit_gpio0"; + dpi_18bit_gpio2 = "/soc/gpio@7e200000/dpi_18bit_gpio2"; + dpi_16bit_gpio0 = "/soc/gpio@7e200000/dpi_16bit_gpio0"; + dpi_16bit_gpio2 = "/soc/gpio@7e200000/dpi_16bit_gpio2"; + dpi_16bit_cpadhi_gpio0 = "/soc/gpio@7e200000/dpi_16bit_cpadhi_gpio0"; + dpi_16bit_cpadhi_gpio2 = "/soc/gpio@7e200000/dpi_16bit_cpadhi_gpio2"; + spi0_pins = "/soc/gpio@7e200000/spi0_pins"; + spi0_cs_pins = "/soc/gpio@7e200000/spi0_cs_pins"; + spi3_pins = "/soc/gpio@7e200000/spi3_pins"; + spi3_cs_pins = "/soc/gpio@7e200000/spi3_cs_pins"; + spi4_pins = "/soc/gpio@7e200000/spi4_pins"; + spi4_cs_pins = "/soc/gpio@7e200000/spi4_cs_pins"; + spi5_pins = "/soc/gpio@7e200000/spi5_pins"; + spi5_cs_pins = "/soc/gpio@7e200000/spi5_cs_pins"; + spi6_pins = "/soc/gpio@7e200000/spi6_pins"; + spi6_cs_pins = "/soc/gpio@7e200000/spi6_cs_pins"; + i2c0_pins = "/soc/gpio@7e200000/i2c0"; + i2c1_pins = "/soc/gpio@7e200000/i2c1"; + i2c3_pins = "/soc/gpio@7e200000/i2c3"; + i2c4_pins = "/soc/gpio@7e200000/i2c4"; + i2c5_pins = "/soc/gpio@7e200000/i2c5"; + i2c6_pins = "/soc/gpio@7e200000/i2c6"; + i2s_pins = "/soc/gpio@7e200000/i2s"; + sdio_pins = "/soc/gpio@7e200000/sdio_pins"; + uart2_pins = "/soc/gpio@7e200000/uart2_pins"; + uart3_pins = "/soc/gpio@7e200000/uart3_pins"; + uart4_pins = "/soc/gpio@7e200000/uart4_pins"; + uart5_pins = "/soc/gpio@7e200000/uart5_pins"; + bt_pins = "/soc/gpio@7e200000/bt_pins"; + uart0_pins = "/soc/gpio@7e200000/uart0_pins"; + uart1_pins = "/soc/gpio@7e200000/uart1_pins"; + uart1_bt_pins = "/soc/gpio@7e200000/uart1_bt_pins"; + audio_pins = "/soc/gpio@7e200000/audio_pins"; + uart0 = "/soc/serial@7e201000"; + bt = "/soc/serial@7e201000/bluetooth"; + sdhost = "/soc/mmc@7e202000"; + i2s_clk_consumer = "/soc/i2s@7e203000"; + i2s_clk_producer = "/soc/i2s@7e203000"; + i2s = "/soc/i2s@7e203000"; + spi0 = "/soc/spi@7e204000"; + spi = "/soc/spi@7e204000"; + spidev0 = "/soc/spi@7e204000/spidev@0"; + spidev1 = "/soc/spi@7e204000/spidev@1"; + i2c0if = "/soc/i2c@7e205000"; + dpi = "/soc/dpi@7e208000"; + dsi0 = "/soc/dsi@7e209000"; + aux = "/soc/aux@7e215000"; + uart1 = "/soc/serial@7e215040"; + minibt = "/soc/serial@7e215040/bluetooth"; + spi1 = "/soc/spi@7e215080"; + spi2 = "/soc/spi@7e2150c0"; + pwm = "/soc/pwm@7e20c000"; + mmc = "/soc/mmc@7e300000"; + sdhci = "/soc/mmc@7e300000"; + hvs = "/soc/hvs@7e400000"; + dsi1 = "/soc/dsi@7e700000"; + csi0 = "/soc/csi@7e800000"; + csi1 = "/soc/csi@7e801000"; + i2c_arm = "/soc/i2c@7e804000"; + i2c1 = "/soc/i2c@7e804000"; + usb = "/soc/usb@7e980000"; + local_intc = "/soc/interrupt-controller@40000000"; + gicv2 = "/soc/interrupt-controller@40041000"; + avs_monitor = "/soc/avs-monitor@7d5d2000"; + thermal = "/soc/avs-monitor@7d5d2000/thermal"; + dma = "/soc/dma-controller@7e007000"; + watchdog = "/soc/watchdog@7e100000"; + pm = "/soc/watchdog@7e100000"; + random = "/soc/rng@7e104000"; + uart2 = "/soc/serial@7e201400"; + uart3 = "/soc/serial@7e201600"; + uart4 = "/soc/serial@7e201800"; + uart5 = "/soc/serial@7e201a00"; + spi3 = "/soc/spi@7e204600"; + spi4 = "/soc/spi@7e204800"; + spi5 = "/soc/spi@7e204a00"; + spi6 = "/soc/spi@7e204c00"; + i2c3 = "/soc/i2c@7e205600"; + i2c4 = "/soc/i2c@7e205800"; + i2c5 = "/soc/i2c@7e205a00"; + i2c6 = "/soc/i2c@7e205c00"; + pixelvalve0 = "/soc/pixelvalve@7e206000"; + pixelvalve1 = "/soc/pixelvalve@7e207000"; + pixelvalve2 = "/soc/pixelvalve@7e20a000"; + pwm1 = "/soc/pwm@7e20c800"; + pixelvalve4 = "/soc/pixelvalve@7e216000"; + pixelvalve3 = "/soc/pixelvalve@7ec12000"; + vec = "/soc/vec@7ec13000"; + dvp = "/soc/clock@7ef00000"; + aon_intr = "/soc/interrupt-controller@7ef00100"; + hdmi0 = "/soc/hdmi@7ef00700"; + ddc0 = "/soc/i2c@7ef04500"; + hdmi1 = "/soc/hdmi@7ef05700"; + ddc1 = "/soc/i2c@7ef09500"; + firmware = "/soc/firmware"; + firmware_clocks = "/soc/firmware/clocks"; + expgpio = "/soc/firmware/gpio"; + reset = "/soc/firmware/reset"; + vcio = "/soc/firmware/vcio"; + power = "/soc/power"; + vchiq = "/soc/mailbox@7e00b840"; + mmcnr = "/soc/mmcnr@7e300000"; + brcmf = "/soc/mmcnr@7e300000/wifi@1"; + firmwarekms = "/soc/firmwarekms@7e600000"; + smi = "/soc/smi@7e600000"; + axiperf = "/soc/axiperf"; + i2c0mux = "/soc/i2c0mux"; + i2c_csi_dsi0 = "/soc/i2c0mux/i2c@0"; + i2c_vc = "/soc/i2c0mux/i2c@0"; + i2c0 = "/soc/i2c0mux/i2c@0"; + i2c_csi_dsi = "/soc/i2c0mux/i2c@1"; + fb = "/soc/fb"; + sound = "/soc/sound"; + nvmem_otp = "/soc/nvmem/nvmem_otp"; + nvmem_cust = "/soc/nvmem/nvmem_cust"; + nvmem_priv = "/soc/nvmem/nvmem_priv"; + clk_osc = "/clocks/clk-osc"; + clk_usb = "/clocks/clk-usb"; + usbphy = "/phy"; + vc4 = "/gpu"; + clk_27MHz = "/clk-27M"; + clk_108MHz = "/clk-108M"; + emmc2bus = "/emmc2bus"; + emmc2 = "/emmc2bus/mmc@7e340000"; + cpus = "/cpus"; + cpu0 = "/cpus/cpu@0"; + cpu1 = "/cpus/cpu@1"; + cpu2 = "/cpus/cpu@2"; + cpu3 = "/cpus/cpu@3"; + l2 = "/cpus/l2-cache0"; + scb = "/scb"; + pcie0 = "/scb/pcie@7d500000"; + genet = "/scb/ethernet@7d580000"; + genet_mdio = "/scb/ethernet@7d580000/mdio@e14"; + phy1 = "/scb/ethernet@7d580000/mdio@e14/ethernet-phy@1"; + hevc_dec = "/scb/codec@7eb10000"; + dma40 = "/scb/dma@7e007b00"; + xhci = "/scb/xhci@7e9c0000"; + leds = "/leds"; + led_act = "/leds/led-act"; + led_pwr = "/leds/led-pwr"; + cam1_clk = "/cam1_clk"; + cam0_regulator = "/cam0_regulator"; + cam0_clk = "/cam0_clk"; + cam0_reg = "/cam_dummy_reg"; + cam_dummy_reg = "/cam_dummy_reg"; + cam1_reg = "/regulator-cam1"; + sd_io_1v8_reg = "/regulator-sd-io-1v8"; + sd_vcc_reg = "/regulator-sd-vcc"; + vdd_3v3_reg = "/fixedregulator_3v3"; + vdd_5v0_reg = "/fixedregulator_5v0"; + v3dbus = "/v3dbus"; + v3d = "/v3dbus/v3d@7ec04000"; + }; +}; diff --git a/dtbs/rpi5b.dts b/dtbs/rpi5b.dts new file mode 100644 index 00000000..6b49f3ba --- /dev/null +++ b/dtbs/rpi5b.dts @@ -0,0 +1,3292 @@ +/dts-v1/; + +/ { + compatible = "raspberrypi,5-model-b", "brcm,bcm2712"; + #address-cells = <0x02>; + #size-cells = <0x01>; + interrupt-parent = <0x01>; + model = "Raspberry Pi 5"; + + clocks { + compatible = "simple-bus"; + #address-cells = <0x01>; + #size-cells = <0x00>; + phandle = <0x76>; + + clk-osc { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "osc"; + clock-frequency = <0x337f980>; + phandle = <0x77>; + }; + + clk-vpu { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0x2cb41780>; + clock-output-names = "vpu-clock"; + phandle = <0x0f>; + }; + + clk-uart { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0x8ca000>; + clock-output-names = "uart-clock"; + phandle = <0x0e>; + }; + + clk-emmc2 { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0xbebc200>; + clock-output-names = "emmc2-clock"; + phandle = <0x08>; + }; + + clk-usb { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "otg"; + clock-frequency = <0x1c9c3800>; + phandle = <0x46>; + }; + + clk_xosc { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "xosc"; + clock-frequency = <0x2faf080>; + phandle = <0x29>; + }; + + sdio_src { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "src"; + clock-frequency = <0x3b9aca00>; + phandle = <0x3c>; + }; + + sdhci_core { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "core"; + clock-frequency = <0x2faf080>; + phandle = <0x3d>; + }; + + clksrc_gp0 { + status = "disabled"; + compatible = "fixed-factor-clock"; + #clock-cells = <0x00>; + clock-div = <0x01>; + clock-mult = <0x01>; + clocks = <0x02 0x21>; + clock-output-names = "clksrc_gp0"; + phandle = <0x78>; + }; + + clksrc_gp1 { + status = "disabled"; + compatible = "fixed-factor-clock"; + #clock-cells = <0x00>; + clock-div = <0x01>; + clock-mult = <0x01>; + clocks = <0x02 0x22>; + clock-output-names = "clksrc_gp1"; + phandle = <0x79>; + }; + + clksrc_gp2 { + status = "disabled"; + compatible = "fixed-factor-clock"; + clock-div = <0x01>; + clock-mult = <0x01>; + #clock-cells = <0x00>; + clocks = <0x02 0x23>; + clock-output-names = "clksrc_gp2"; + phandle = <0x7a>; + }; + + clksrc_gp3 { + status = "disabled"; + compatible = "fixed-factor-clock"; + clock-div = <0x01>; + clock-mult = <0x01>; + #clock-cells = <0x00>; + clocks = <0x02 0x24>; + clock-output-names = "clksrc_gp3"; + phandle = <0x7b>; + }; + + clksrc_gp4 { + status = "disabled"; + compatible = "fixed-factor-clock"; + #clock-cells = <0x00>; + clock-div = <0x01>; + clock-mult = <0x01>; + clocks = <0x02 0x25>; + clock-output-names = "clksrc_gp4"; + phandle = <0x7c>; + }; + + clksrc_gp5 { + status = "disabled"; + compatible = "fixed-factor-clock"; + #clock-cells = <0x00>; + clock-div = <0x01>; + clock-mult = <0x01>; + clocks = <0x02 0x26>; + clock-output-names = "clksrc_gp5"; + phandle = <0x7d>; + }; + }; + + cpus { + #address-cells = <0x01>; + #size-cells = <0x00>; + phandle = <0x7e>; + + cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a76"; + reg = <0x00>; + enable-method = "psci"; + d-cache-size = <0x10000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0x10000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x03>; + phandle = <0x4e>; + + l2-cache-l0 { + compatible = "cache"; + cache-size = <0x80000>; + cache-line-size = <0x40>; + cache-sets = <0x400>; + cache-level = <0x02>; + cache-unified; + next-level-cache = <0x04>; + phandle = <0x03>; + }; + }; + + cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a76"; + reg = <0x100>; + enable-method = "psci"; + d-cache-size = <0x10000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0x10000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x05>; + phandle = <0x4f>; + + l2-cache-l1 { + compatible = "cache"; + cache-size = <0x80000>; + cache-line-size = <0x40>; + cache-sets = <0x400>; + cache-level = <0x02>; + cache-unified; + next-level-cache = <0x04>; + phandle = <0x05>; + }; + }; + + cpu@2 { + device_type = "cpu"; + compatible = "arm,cortex-a76"; + reg = <0x200>; + enable-method = "psci"; + d-cache-size = <0x10000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0x10000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x06>; + phandle = <0x50>; + + l2-cache-l2 { + compatible = "cache"; + cache-size = <0x80000>; + cache-line-size = <0x40>; + cache-sets = <0x400>; + cache-level = <0x02>; + cache-unified; + next-level-cache = <0x04>; + phandle = <0x06>; + }; + }; + + cpu@3 { + device_type = "cpu"; + compatible = "arm,cortex-a76"; + reg = <0x300>; + enable-method = "psci"; + d-cache-size = <0x10000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0x10000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x07>; + phandle = <0x51>; + + l2-cache-l3 { + compatible = "cache"; + cache-size = <0x80000>; + cache-line-size = <0x40>; + cache-sets = <0x400>; + cache-level = <0x02>; + cache-unified; + next-level-cache = <0x04>; + phandle = <0x07>; + }; + }; + + l3-cache { + compatible = "cache"; + cache-size = <0x200000>; + cache-line-size = <0x40>; + cache-sets = <0x800>; + cache-level = <0x03>; + cache-unified; + phandle = <0x04>; + }; + }; + + psci { + method = "smc"; + compatible = "arm,psci-1.0", "arm,psci-0.2"; + }; + + reserved-memory { + ranges; + #address-cells = <0x02>; + #size-cells = <0x01>; + phandle = <0x7f>; + + atf@0 { + reg = <0x00 0x00 0x80000>; + no-map; + }; + + linux,cma { + compatible = "shared-dma-pool"; + size = <0x4000000>; + reusable; + linux,cma-default; + alloc-ranges = <0x00 0x00 0x40000000>; + phandle = <0x80>; + }; + + nvram@0 { + compatible = "raspberrypi,bootloader-config", "nvmem-rmem"; + #address-cells = <0x01>; + #size-cells = <0x01>; + reg = <0x00 0x00 0x00>; + no-map; + status = "disabled"; + phandle = <0x81>; + }; + + nvram@1 { + compatible = "raspberrypi,bootloader-public-key", "nvmem-rmem"; + #address-cells = <0x01>; + #size-cells = <0x01>; + reg = <0x00 0x00 0x00>; + no-map; + status = "disabled"; + phandle = <0x82>; + }; + }; + + soc@107c000000 { + compatible = "simple-bus"; + ranges = <0x00 0x10 0x00 0x80000000>; + #address-cells = <0x01>; + #size-cells = <0x01>; + phandle = <0x83>; + + reset-controller@119500 { + compatible = "brcm,bcm7216-pcie-sata-rescal"; + reg = <0x119500 0x10>; + #reset-cells = <0x00>; + phandle = <0x23>; + }; + + mmc@fff000 { + compatible = "brcm,bcm2712-sdhci", "brcm,sdhci-brcmstb"; + reg = <0xfff000 0x260 0xfff400 0x200>; + reg-names = "host", "cfg"; + interrupts = <0x00 0x111 0x04>; + clocks = <0x08>; + clock-names = "sw_sdio"; + mmc-ddr-3_3v; + pinctrl-0 = <0x09 0x0a>; + pinctrl-names = "default"; + vqmmc-supply = <0x0b>; + vmmc-supply = <0x0c>; + bus-width = <0x04>; + sd-uhs-sdr50; + sd-uhs-ddr50; + sd-uhs-sdr104; + supports-cqe = <0x01>; + cd-gpios = <0x0d 0x05 0x01>; + status = "okay"; + phandle = <0x74>; + }; + + reset-controller@1504318 { + compatible = "brcm,brcmstb-reset"; + reg = <0x1504318 0x30>; + #reset-cells = <0x01>; + phandle = <0x24>; + }; + + timer@7c003000 { + compatible = "brcm,bcm2835-system-timer"; + reg = <0x7c003000 0x1000>; + interrupts = <0x00 0x40 0x04 0x00 0x41 0x04 0x00 0x42 0x04 0x00 0x43 0x04>; + clock-frequency = <0xf4240>; + phandle = <0x84>; + }; + + mailbox@7c013880 { + compatible = "brcm,bcm2835-mbox"; + reg = <0x7c013880 0x40>; + interrupts = <0x00 0x21 0x04>; + #mbox-cells = <0x00>; + phandle = <0x22>; + }; + + interrupt-controller@7cd00000 { + compatible = "brcm,bcm2836-l1-intc"; + reg = <0x7cd00000 0x100>; + phandle = <0x85>; + }; + + serial@7d001000 { + compatible = "arm,pl011", "arm,primecell"; + reg = <0x7d001000 0x200>; + interrupts = <0x00 0x79 0x04>; + clocks = <0x0e 0x0f>; + clock-names = "uartclk", "apb_pclk"; + arm,primecell-periphid = <0x341011>; + status = "okay"; + phandle = <0x86>; + }; + + interrupt-controller@7d517000 { + compatible = "brcm,bcm7271-l2-intc"; + reg = <0x7d517000 0x10>; + interrupts = <0x00 0xf7 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + status = "disabled"; + }; + + gpio@7d517c00 { + compatible = "brcm,brcmstb-gpio"; + reg = <0x7d517c00 0x40>; + gpio-controller; + #gpio-cells = <0x02>; + brcm,gpio-bank-widths = <0x11 0x06>; + brcm,gpio-direct; + gpio-line-names = "RP1_SDA", "RP1_SCL", "RP1_RUN", "SD_IOVDD_SEL", "SD_PWR_ON", "SD_CDET_N", "SD_FLG_N", "-", "2712_WAKE", "2712_STAT_LED", "-", "-", "PMIC_INT", "UART_TX_FS", "UART_RX_FS", "-", "-", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "HDMI0_SCL", "HDMI0_SDA", "HDMI1_SCL", "HDMI1_SDA", "PMIC_SCL", "PMIC_SDA"; + phandle = <0x0d>; + + rp1_run_hog { + gpio-hog; + gpios = <0x02 0x00>; + output-high; + line-name = "RP1 RUN pin"; + }; + }; + + interrupt-controller@7fff9000 { + compatible = "arm,gic-400"; + reg = <0x7fff9000 0x1000 0x7fffa000 0x2000 0x7fffc000 0x2000 0x7fffe000 0x2000>; + interrupt-controller; + #interrupt-cells = <0x03>; + interrupts = <0x01 0x09 0xf04>; + phandle = <0x01>; + }; + + interrupt-controller@7d510600 { + compatible = "brcm,bcm2711-l2-intc", "brcm,l2-intc"; + reg = <0x7d510600 0x30>; + interrupts = <0x00 0xef 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + status = "disabled"; + phandle = <0x14>; + }; + + pixelvalve@7c410000 { + compatible = "brcm,bcm2712-pixelvalve0"; + reg = <0x7c410000 0x100>; + interrupts = <0x00 0x65 0x04>; + status = "disabled"; + phandle = <0x87>; + }; + + pixelvalve@7c411000 { + compatible = "brcm,bcm2712-pixelvalve1"; + reg = <0x7c411000 0x100>; + interrupts = <0x00 0x6e 0x04>; + status = "disabled"; + phandle = <0x88>; + }; + + mop@7c500000 { + compatible = "brcm,bcm2712-mop"; + reg = <0x7c500000 0x28>; + interrupt-parent = <0x10>; + interrupts = <0x01>; + status = "disabled"; + phandle = <0x89>; + }; + + moplet@7c501000 { + compatible = "brcm,bcm2712-moplet"; + reg = <0x7c501000 0x20>; + interrupt-parent = <0x10>; + interrupts = <0x00>; + status = "disabled"; + phandle = <0x8a>; + }; + + interrupt-controller@7c502000 { + compatible = "brcm,bcm2711-l2-intc", "brcm,l2-intc"; + reg = <0x7c502000 0x30>; + interrupts = <0x00 0x61 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + status = "disabled"; + phandle = <0x10>; + }; + + clock@7c700000 { + compatible = "brcm,brcm2711-dvp"; + reg = <0x7c700000 0x10>; + clocks = <0x11>; + #clock-cells = <0x01>; + #reset-cells = <0x01>; + phandle = <0x13>; + }; + + i2c@7d508200 { + compatible = "brcm,brcmstb-i2c"; + reg = <0x7d508200 0x58>; + interrupt-parent = <0x12>; + interrupts = <0x01>; + clock-frequency = <0x17cdc>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + phandle = <0x15>; + }; + + i2c@7d508280 { + compatible = "brcm,brcmstb-i2c"; + reg = <0x7d508280 0x58>; + interrupt-parent = <0x12>; + interrupts = <0x02>; + clock-frequency = <0x17cdc>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + phandle = <0x19>; + }; + + intc@7d508380 { + compatible = "brcm,bcm7271-l2-intc"; + reg = <0x7d508380 0x10>; + interrupts = <0x00 0xf2 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + phandle = <0x12>; + }; + + intc@7d508400 { + compatible = "brcm,bcm7271-l2-intc"; + reg = <0x7d508400 0x10>; + interrupts = <0x00 0xf4 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + phandle = <0x1f>; + }; + + hdmi@7ef00700 { + compatible = "brcm,bcm2712-hdmi0"; + reg = <0x7c701400 0x300 0x7c701000 0x200 0x7c701d00 0x300 0x7c702000 0x80 0x7c703800 0x200 0x7c704000 0x800 0x7c700100 0x80 0x7d510800 0x100 0x7c720000 0x100>; + reg-names = "hdmi", "dvp", "phy", "rm", "packet", "metadata", "csc", "cec", "hd"; + resets = <0x13 0x01>; + interrupt-parent = <0x14>; + interrupts = <0x01 0x02 0x03 0x07 0x08>; + interrupt-names = "cec-tx", "cec-rx", "cec-low", "hpd-connected", "hpd-removed"; + ddc = <0x15>; + status = "disabled"; + dmas = <0x16 0x41fa000a>; + dma-names = "audio-rx"; + clocks = <0x17 0x0d 0x17 0x0e 0x13 0x00 0x18>; + clock-names = "hdmi", "bvb", "audio", "cec"; + phandle = <0x8b>; + }; + + hdmi@7ef05700 { + compatible = "brcm,bcm2712-hdmi1"; + reg = <0x7c706400 0x300 0x7c706000 0x200 0x7c706d00 0x300 0x7c707000 0x80 0x7c708800 0x200 0x7c709000 0x800 0x7c700180 0x80 0x7d511000 0x100 0x7c720000 0x100>; + reg-names = "hdmi", "dvp", "phy", "rm", "packet", "metadata", "csc", "cec", "hd"; + resets = <0x13 0x02>; + interrupt-parent = <0x14>; + interrupts = <0x0b 0x0c 0x0d 0x0e 0x0f>; + interrupt-names = "cec-tx", "cec-rx", "cec-low", "hpd-connected", "hpd-removed"; + ddc = <0x19>; + status = "disabled"; + dmas = <0x16 0x41fa0011>; + dma-names = "audio-rx"; + clocks = <0x17 0x0d 0x17 0x0e 0x13 0x01 0x18>; + clock-names = "hdmi", "bvb", "audio", "cec"; + phandle = <0x8c>; + }; + + axiperf@7c012800 { + compatible = "brcm,bcm2712-axiperf"; + reg = <0x7c012800 0x100 0x7e000000 0x100>; + firmware = <0x1a>; + status = "disabled"; + phandle = <0x5e>; + }; + + spi@7d004000 { + compatible = "brcm,bcm2835-spi"; + reg = <0x7d004000 0x200>; + interrupts = <0x00 0x76 0x04>; + clocks = <0x0f>; + num-cs = <0x01>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "okay"; + dmas = <0x16 0x06 0x16 0x07>; + dma-names = "tx", "rx"; + pinctrl-names = "default"; + cs-gpios = <0x1b 0x01 0x01>; + pinctrl-0 = <0x1c 0x1d>; + phandle = <0x8d>; + + spidev@0 { + compatible = "spidev"; + reg = <0x00>; + #address-cells = <0x01>; + #size-cells = <0x00>; + spi-max-frequency = <0x1312d00>; + status = "okay"; + phandle = <0x8e>; + }; + }; + + i2c@7d005600 { + compatible = "brcm,bcm2711-i2c", "brcm,bcm2835-i2c"; + reg = <0x7d005600 0x20>; + interrupts = <0x00 0x75 0x04>; + clocks = <0x0f>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + clock-frequency = <0x61a80>; + pinctrl-0 = <0x1e>; + pinctrl-names = "default"; + phandle = <0x8f>; + }; + + watchdog@7d200000 { + compatible = "brcm,bcm2712-pm"; + reg = <0x7d200000 0x308>; + reg-names = "pm"; + #power-domain-cells = <0x01>; + #reset-cells = <0x01>; + system-power-controller; + phandle = <0x4c>; + }; + + rng@7d208000 { + compatible = "brcm,bcm2711-rng200"; + reg = <0x7d208000 0x28>; + status = "okay"; + phandle = <0x6c>; + }; + + intc@7d503000 { + compatible = "brcm,l2-intc"; + reg = <0x7d503000 0x18>; + interrupts = <0x00 0xee 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + phandle = <0x59>; + }; + + pinctrl@7d504100 { + compatible = "brcm,bcm2712-pinctrl"; + reg = <0x7d504100 0x30>; + phandle = <0x90>; + + uarta_24_pins { + phandle = <0x20>; + + pin_rts { + function = "uart0"; + pins = "gpio24"; + bias-disable; + }; + + pin_cts { + function = "uart0"; + pins = "gpio25"; + bias-pull-up; + }; + + pin_txd { + function = "uart0"; + pins = "gpio26"; + bias-disable; + }; + + pin_rxd { + function = "uart0"; + pins = "gpio27"; + bias-pull-up; + }; + }; + + sdio2_30_pins { + phandle = <0x4a>; + + pin_clk { + function = "sd2"; + pins = "gpio30"; + bias-disable; + }; + + pin_cmd { + function = "sd2"; + pins = "gpio31"; + bias-pull-up; + }; + + pins_dat { + function = "sd2"; + pins = "gpio32", "gpio33", "gpio34", "gpio35"; + bias-pull-up; + }; + }; + + pwr_button_pins { + function = "gpio"; + pins = "gpio20"; + bias-pull-up; + phandle = <0x75>; + }; + + wl_on_pins { + function = "gpio"; + pins = "gpio28"; + phandle = <0x5a>; + }; + + bt_shutdown_pins { + function = "gpio"; + pins = "gpio29"; + phandle = <0x21>; + }; + + emmc_sd_pulls { + pins = "emmc_cmd", "emmc_dat0", "emmc_dat1", "emmc_dat2", "emmc_dat3"; + bias-pull-up; + phandle = <0x09>; + }; + + spi10_gpio2 { + function = "vc_spi0"; + pins = "gpio2", "gpio3", "gpio4"; + bias-disable; + phandle = <0x1c>; + }; + + spi10_cs_gpio1 { + function = "gpio"; + pins = "gpio1"; + bias-pull-up; + phandle = <0x1d>; + }; + }; + + gpio@7d508500 { + compatible = "brcm,brcmstb-gpio"; + reg = <0x7d508500 0x40>; + interrupt-parent = <0x1f>; + interrupts = <0x00>; + gpio-controller; + #gpio-cells = <0x02>; + interrupt-controller; + #interrupt-cells = <0x02>; + brcm,gpio-bank-widths = <0x20 0x04>; + brcm,gpio-direct; + gpio-line-names = "-", "2712_BOOT_CS_N", "2712_BOOT_MISO", "2712_BOOT_MOSI", "2712_BOOT_SCLK", "-", "-", "-", "-", "-", "-", "-", "-", "-", "PCIE_SDA", "PCIE_SCL", "-", "-", "-", "-", "PWR_GPIO", "2712_G21_FS", "-", "-", "BT_RTS", "BT_CTS", "BT_TXD", "BT_RXD", "WL_ON", "BT_ON", "WIFI_SDIO_CLK", "WIFI_SDIO_CMD", "WIFI_SDIO_D0", "WIFI_SDIO_D1", "WIFI_SDIO_D2", "WIFI_SDIO_D3"; + phandle = <0x1b>; + }; + + serial@7d50c000 { + compatible = "brcm,bcm7271-uart"; + reg = <0x7d50c000 0x20>; + reg-names = "uart"; + reg-shift = <0x02>; + reg-io-width = <0x04>; + interrupts = <0x00 0x114 0x04>; + skip-init; + status = "okay"; + uart-has-rtscts; + auto-flow-control; + clock-frequency = <0x5b8d800>; + pinctrl-0 = <0x20 0x21>; + pinctrl-names = "default"; + phandle = <0x91>; + + bluetooth { + compatible = "brcm,bcm43438-bt"; + max-speed = <0x2dc6c0>; + shutdown-gpios = <0x1b 0x1d 0x00>; + local-bd-address = [00 00 00 00 00 00]; + phandle = <0x5f>; + }; + }; + + pinctrl@7d510700 { + compatible = "brcm,bcm2712-aon-pinctrl"; + reg = <0x7d510700 0x20>; + phandle = <0x92>; + + i2c3_m4_agpio0_pins { + function = "vc_i2c3"; + pins = "aon_gpio0", "aon_gpio1"; + bias-pull-up; + phandle = <0x1e>; + }; + + bsc_m1_agpio13_pins { + function = "bsc_m1"; + pins = "aon_gpio13", "aon_gpio14"; + bias-pull-up; + phandle = <0x93>; + }; + + bsc_pmu_sgpio4_pins { + function = "avs_pmu_bsc"; + pins = "aon_sgpio4", "aon_sgpio5"; + phandle = <0x94>; + }; + + bsc_m2_sgpio4_pins { + function = "bsc_m2"; + pins = "aon_sgpio4", "aon_sgpio5"; + phandle = <0x95>; + }; + + pwm_aon_agpio1_pins { + function = "aon_pwm"; + pins = "aon_gpio1", "aon_gpio2"; + phandle = <0x96>; + }; + + pwm_aon_agpio4_pins { + function = "vc_pwm0"; + pins = "aon_gpio4", "aon_gpio5"; + phandle = <0x97>; + }; + + pwm_aon_agpio7_pins { + function = "aon_pwm"; + pins = "aon_gpio7", "aon_gpio9"; + phandle = <0x98>; + }; + + emmc_aon_cd_pins { + function = "sd_card_g"; + pins = "aon_gpio5"; + bias-pull-up; + phandle = <0x0a>; + }; + + aon_pwm_1pin { + function = "aon_pwm"; + pins = "aon_gpio9"; + phandle = <0x99>; + }; + }; + + intc@7d517ac0 { + compatible = "brcm,bcm7271-l2-intc"; + reg = <0x7d517ac0 0x10>; + interrupts = <0x00 0xf5 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + status = "disabled"; + phandle = <0x9a>; + }; + + avs-monitor@7d542000 { + compatible = "brcm,bcm2711-avs-monitor", "syscon", "simple-mfd"; + reg = <0x7d542000 0xf00>; + status = "okay"; + phandle = <0x9b>; + + thermal { + compatible = "brcm,bcm2711-thermal"; + #thermal-sensor-cells = <0x00>; + phandle = <0x52>; + }; + }; + + firmware { + compatible = "raspberrypi,bcm2835-firmware", "simple-mfd"; + #address-cells = <0x01>; + #size-cells = <0x01>; + mboxes = <0x22>; + dma-ranges; + phandle = <0x1a>; + + clocks { + compatible = "raspberrypi,firmware-clocks"; + #clock-cells = <0x01>; + phandle = <0x17>; + }; + + reset { + compatible = "raspberrypi,firmware-reset"; + #reset-cells = <0x01>; + phandle = <0x9c>; + }; + + vcio { + compatible = "raspberrypi,vcio"; + phandle = <0x9d>; + }; + }; + + power { + compatible = "raspberrypi,bcm2835-power"; + firmware = <0x1a>; + #power-domain-cells = <0x01>; + phandle = <0x48>; + }; + + fb { + compatible = "brcm,bcm2708-fb"; + firmware = <0x1a>; + phandle = <0x9e>; + }; + + rpi_rtc { + compatible = "raspberrypi,rpi-rtc"; + firmware = <0x1a>; + trickle-charge-microvolt = <0x00>; + phandle = <0x6d>; + }; + + nvmem { + compatible = "simple-bus"; + #address-cells = <0x01>; + #size-cells = <0x01>; + + nvmem_otp { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x1a>; + reg = <0x00 0xc0>; + phandle = <0x9f>; + }; + + nvmem_cust { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x1a>; + reg = <0x01 0x08>; + phandle = <0x68>; + }; + + nvmem_mac { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x1a>; + reg = <0x02 0x06>; + phandle = <0x69>; + }; + + nvmem_priv { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x1a>; + reg = <0x03 0x10>; + phandle = <0x6a>; + }; + }; + + fixedregulator_3v3 { + compatible = "regulator-fixed"; + regulator-always-on; + regulator-max-microvolt = <0x325aa0>; + regulator-min-microvolt = <0x325aa0>; + regulator-name = "3v3"; + phandle = <0xa0>; + }; + + fixedregulator_5v0 { + compatible = "regulator-fixed"; + regulator-always-on; + regulator-max-microvolt = <0x4c4b40>; + regulator-min-microvolt = <0x4c4b40>; + regulator-name = "5v0"; + phandle = <0xa1>; + }; + + gpiomem@7d508500 { + compatible = "raspberrypi,gpiomem"; + reg = <0x7d508500 0x40>; + chardev-name = "gpiomem1"; + }; + + gpiomem@7d517c00 { + compatible = "raspberrypi,gpiomem"; + reg = <0x7d517c00 0x40>; + chardev-name = "gpiomem2"; + }; + + gpiomem@7d504100 { + compatible = "raspberrypi,gpiomem"; + reg = <0x7d504100 0x20>; + chardev-name = "gpiomem3"; + }; + + gpiomem@7d510700 { + compatible = "raspberrypi,gpiomem"; + reg = <0x7d510700 0x20>; + chardev-name = "gpiomem4"; + }; + + sound { + status = "disabled"; + phandle = <0xa2>; + }; + }; + + axi { + compatible = "simple-bus"; + #address-cells = <0x02>; + #size-cells = <0x02>; + ranges = <0x00 0x00 0x00 0x00 0x10 0x00 0x10 0x00 0x10 0x00 0x01 0x00 0x14 0x00 0x14 0x00 0x04 0x00 0x18 0x00 0x18 0x00 0x04 0x00 0x1c 0x00 0x1c 0x00 0x04 0x00>; + dma-ranges = <0x00 0x00 0x00 0x00 0x10 0x00 0x10 0x00 0x10 0x00 0x01 0x00 0x14 0x00 0x14 0x00 0x04 0x00 0x18 0x00 0x18 0x00 0x04 0x00 0x1c 0x00 0x1c 0x00 0x04 0x00>; + phandle = <0xa3>; + + gpu { + compatible = "brcm,bcm2712-vc6"; + status = "disabled"; + phandle = <0xa4>; + }; + + pcie@1000100000 { + compatible = "brcm,bcm2712-pcie"; + reg = <0x10 0x100000 0x00 0x9310>; + device_type = "pci"; + linux,pci-domain = <0x00>; + max-link-speed = <0x02>; + num-lanes = <0x01>; + #address-cells = <0x03>; + #interrupt-cells = <0x01>; + #size-cells = <0x02>; + interrupt-parent = <0x01>; + interrupts = <0x00 0xd5 0x04 0x00 0xd6 0x04>; + interrupt-names = "pcie", "msi"; + interrupt-map-mask = <0x00 0x00 0x00 0x07>; + interrupt-map = <0x00 0x00 0x00 0x01 0x01 0x00 0xd1 0x04 0x00 0x00 0x00 0x02 0x01 0x00 0xd2 0x04 0x00 0x00 0x00 0x03 0x01 0x00 0xd3 0x04 0x00 0x00 0x00 0x04 0x01 0x00 0xd4 0x04>; + resets = <0x23 0x24 0x2a>; + reset-names = "rescal", "bridge"; + msi-controller; + msi-parent = <0x25>; + ranges = <0x2000000 0x00 0x00 0x17 0x00 0x00 0xfffffffc 0x43000000 0x04 0x00 0x14 0x00 0x03 0x00>; + dma-ranges = <0x43000000 0x10 0x00 0x00 0x00 0x10 0x00>; + status = "disabled"; + phandle = <0x25>; + }; + + pcie@1000110000 { + compatible = "brcm,bcm2712-pcie"; + reg = <0x10 0x110000 0x00 0x9310>; + device_type = "pci"; + linux,pci-domain = <0x01>; + max-link-speed = <0x02>; + num-lanes = <0x01>; + #address-cells = <0x03>; + #interrupt-cells = <0x01>; + #size-cells = <0x02>; + interrupt-parent = <0x01>; + interrupts = <0x00 0xdf 0x04 0x00 0xe0 0x04>; + interrupt-names = "pcie", "msi"; + interrupt-map-mask = <0x00 0x00 0x00 0x07>; + interrupt-map = <0x00 0x00 0x00 0x01 0x01 0x00 0xdb 0x04 0x00 0x00 0x00 0x02 0x01 0x00 0xdc 0x04 0x00 0x00 0x00 0x03 0x01 0x00 0xdd 0x04 0x00 0x00 0x00 0x04 0x01 0x00 0xde 0x04>; + resets = <0x23 0x24 0x2b>; + reset-names = "rescal", "bridge"; + msi-controller; + msi-parent = <0x26>; + ranges = <0x2000000 0x00 0x80000000 0x1b 0x80000000 0x00 0x80000000 0x43000000 0x04 0x00 0x18 0x00 0x03 0x80000000>; + dma-ranges = <0x3000000 0x10 0x00 0x00 0x00 0x10 0x00 0x3000000 0xff 0xfffff000 0x10 0x131000 0x00 0x1000>; + status = "disabled"; + brcm,fifo-qos-map = <0x3030303>; + brcm,clkreq-mode = "safe"; + phandle = <0x67>; + }; + + pcie@1000120000 { + compatible = "brcm,bcm2712-pcie"; + reg = <0x10 0x120000 0x00 0x9310>; + device_type = "pci"; + linux,pci-domain = <0x02>; + max-link-speed = <0x02>; + num-lanes = <0x04>; + #address-cells = <0x03>; + #interrupt-cells = <0x01>; + #size-cells = <0x02>; + interrupt-parent = <0x01>; + interrupts = <0x00 0xe9 0x04 0x00 0xea 0x04>; + interrupt-names = "pcie", "msi"; + interrupt-map-mask = <0x00 0x00 0x00 0x07>; + interrupt-map = <0x00 0x00 0x00 0x01 0x01 0x00 0xe5 0x04 0x00 0x00 0x00 0x02 0x01 0x00 0xe6 0x04 0x00 0x00 0x00 0x03 0x01 0x00 0xe7 0x04 0x00 0x00 0x00 0x04 0x01 0x00 0xe8 0x04>; + resets = <0x23 0x24 0x2c>; + reset-names = "rescal", "bridge"; + msi-controller; + msi-parent = <0x27>; + ranges = <0x2000000 0x00 0x00 0x1f 0x00 0x00 0xfffffffc 0x43000000 0x04 0x00 0x1c 0x00 0x03 0x00>; + dma-ranges = <0x2000000 0x00 0x00 0x1f 0x00 0x00 0x400000 0x43000000 0x10 0x00 0x00 0x00 0x10 0x00 0x3000000 0xff 0xfffff000 0x10 0x130000 0x00 0x1000>; + status = "okay"; + brcm,vdm-qos-map = <0x8080809 0xa0a0b0b>; + aspm-no-l0s; + phandle = <0xa5>; + + rp1 { + compatible = "simple-bus"; + #address-cells = <0x02>; + #size-cells = <0x02>; + #interrupt-cells = <0x02>; + interrupt-controller; + interrupt-parent = <0x28>; + ranges = <0xc0 0x40000000 0x2000000 0x00 0x00 0x00 0x410000>; + dma-ranges = <0x10 0x00 0x43000000 0x10 0x00 0x10 0x00 0xc0 0x40000000 0x2000000 0x00 0x00 0x00 0x410000 0x00 0x00 0x2000000 0x10 0x00 0x10 0x00>; + phandle = <0x28>; + + mailbox@8000 { + compatible = "raspberrypi,rp1-mbox"; + status = "okay"; + reg = <0xc0 0x40008000 0x00 0x4000>; + interrupts = <0x3a 0x04>; + #mbox-cells = <0x01>; + phandle = <0x5b>; + }; + + clocks@18000 { + compatible = "raspberrypi,rp1-clocks"; + #clock-cells = <0x01>; + reg = <0xc0 0x40018000 0x00 0x10038>; + clocks = <0x29>; + assigned-clocks = <0x02 0x00 0x02 0x01 0x02 0x03 0x02 0x09 0x02 0x10 0x02 0x04 0x02 0x0a 0x02 0x0c 0x02 0x06 0x02 0x0d 0x02 0x1f 0x02 0x20 0x02 0x1d>; + assigned-clock-rates = <0x3b9aca00 0x5b8d8000 0xbebc200 0x7735940 0x7735940 0x3a98000 0x927c000 0xbebc200 0x5f5e100 0x2faf080 0xf4240 0xbebc200 0x2faf080>; + phandle = <0x02>; + }; + + serial@30000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40030000 0x00 0x100>; + interrupts = <0x19 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + pinctrl-0 = <0x2a>; + phandle = <0x70>; + }; + + serial@34000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40034000 0x00 0x100>; + interrupts = <0x2a 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xa6>; + }; + + serial@38000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40038000 0x00 0x100>; + interrupts = <0x2b 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xa7>; + }; + + serial@3c000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x4003c000 0x00 0x100>; + interrupts = <0x2c 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xa8>; + }; + + serial@40000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40040000 0x00 0x100>; + interrupts = <0x2d 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xa9>; + }; + + serial@44000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40044000 0x00 0x100>; + interrupts = <0x2e 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xaa>; + }; + + spi@4c000 { + reg = <0xc0 0x4004c000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x38 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2b 0x37 0x2b 0x36>; + dma-names = "tx", "rx"; + status = "disabled"; + phandle = <0xab>; + }; + + spi@50000 { + reg = <0xc0 0x40050000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x13 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2b 0x0d 0x2b 0x0c>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x2c 0x2d>; + cs-gpios = <0x2e 0x08 0x01 0x2e 0x07 0x01>; + phandle = <0x6e>; + + spidev@0 { + compatible = "spidev"; + reg = <0x00>; + #address-cells = <0x01>; + #size-cells = <0x00>; + spi-max-frequency = <0x7735940>; + phandle = <0xac>; + }; + + spidev@1 { + compatible = "spidev"; + reg = <0x01>; + #address-cells = <0x01>; + #size-cells = <0x00>; + spi-max-frequency = <0x7735940>; + phandle = <0xad>; + }; + }; + + spi@54000 { + reg = <0xc0 0x40054000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x14 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2b 0x0f 0x2b 0x0e>; + dma-names = "tx", "rx"; + status = "disabled"; + phandle = <0xae>; + }; + + spi@58000 { + reg = <0xc0 0x40058000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x15 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2b 0x11 0x2b 0x10>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x2f>; + phandle = <0xaf>; + }; + + spi@5c000 { + reg = <0xc0 0x4005c000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x16 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2b 0x13 0x2b 0x12>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x30>; + phandle = <0xb0>; + }; + + spi@60000 { + reg = <0xc0 0x40060000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x17 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x00>; + #size-cells = <0x00>; + num-cs = <0x01>; + spi-slave; + dmas = <0x2b 0x15 0x2b 0x14>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x31>; + phandle = <0xb1>; + + slave { + compatible = "spidev"; + spi-max-frequency = <0xf4240>; + }; + }; + + spi@64000 { + reg = <0xc0 0x40064000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x18 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2b 0x17 0x2b 0x16>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x32>; + phandle = <0xb2>; + }; + + spi@68000 { + reg = <0xc0 0x40068000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x36 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2b 0x33 0x2b 0x32>; + dma-names = "tx", "rx"; + status = "disabled"; + phandle = <0xb3>; + }; + + spi@6c000 { + reg = <0xc0 0x4006c000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x37 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x00>; + #size-cells = <0x00>; + num-cs = <0x01>; + spi-slave; + dmas = <0x2b 0x35 0x2b 0x34>; + dma-names = "tx", "rx"; + status = "disabled"; + phandle = <0xb4>; + + slave { + compatible = "spidev"; + spi-max-frequency = <0xf4240>; + }; + }; + + i2c@70000 { + reg = <0xc0 0x40070000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x07 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-0 = <0x33>; + pinctrl-names = "default"; + clock-frequency = <0x186a0>; + phandle = <0x66>; + }; + + i2c@74000 { + reg = <0xc0 0x40074000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x08 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x34>; + clock-frequency = <0x186a0>; + phandle = <0x63>; + }; + + i2c@78000 { + reg = <0xc0 0x40078000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x09 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x35>; + phandle = <0xb5>; + }; + + i2c@7c000 { + reg = <0xc0 0x4007c000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x0a 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x36>; + phandle = <0xb6>; + }; + + i2c@80000 { + reg = <0xc0 0x40080000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x0b 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-0 = <0x37>; + pinctrl-names = "default"; + clock-frequency = <0x186a0>; + symlink = "i2c-4"; + phandle = <0x64>; + }; + + i2c@84000 { + reg = <0xc0 0x40084000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x0c 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + phandle = <0xb7>; + }; + + i2c@88000 { + reg = <0xc0 0x40088000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x0d 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-0 = <0x38>; + pinctrl-names = "default"; + clock-frequency = <0x186a0>; + symlink = "i2c-6"; + phandle = <0x65>; + }; + + audio_out@94000 { + compatible = "raspberrypi,rp1-audio-out"; + reg = <0xc0 0x40094000 0x00 0x4000>; + clocks = <0x02 0x14>; + assigned-clocks = <0x02 0x14>; + assigned-clock-rates = <0x927c000>; + assigned-clock-parents = <0x02 0x0a>; + dmas = <0x2b 0x1d>; + dma-maxburst = <0x04>; + dma-names = "tx"; + #sound-dai-cells = <0x00>; + status = "disabled"; + phandle = <0xb8>; + }; + + pwm@98000 { + compatible = "raspberrypi,rp1-pwm"; + reg = <0xc0 0x40098000 0x00 0x100>; + #pwm-cells = <0x03>; + clocks = <0x02 0x11>; + assigned-clocks = <0x02 0x11>; + assigned-clock-rates = <0x2faf080>; + status = "disabled"; + phandle = <0xb9>; + }; + + pwm@9c000 { + compatible = "raspberrypi,rp1-pwm"; + reg = <0xc0 0x4009c000 0x00 0x100>; + #pwm-cells = <0x03>; + clocks = <0x02 0x12>; + assigned-clocks = <0x02 0x12>; + assigned-clock-rates = <0x2faf080>; + status = "disabled"; + pinctrl-0 = <0x39>; + pinctrl-names = "default"; + phandle = <0x61>; + }; + + i2s@a0000 { + reg = <0xc0 0x400a0000 0x00 0x1000>; + compatible = "snps,designware-i2s"; + clocks = <0x02 0x15>; + clock-names = "i2sclk"; + #sound-dai-cells = <0x00>; + dmas = <0x2b 0x20 0x2b 0x1f>; + dma-names = "tx", "rx"; + dma-maxburst = <0x04>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x3a>; + phandle = <0xba>; + }; + + i2s@a4000 { + reg = <0xc0 0x400a4000 0x00 0x1000>; + compatible = "snps,designware-i2s"; + clocks = <0x02 0x15>; + clock-names = "i2sclk"; + #sound-dai-cells = <0x00>; + dmas = <0x2b 0x22 0x2b 0x21>; + dma-names = "tx", "rx"; + dma-maxburst = <0x04>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x3b>; + phandle = <0xbb>; + }; + + i2s@a8000 { + reg = <0xc0 0x400a8000 0x00 0x1000>; + compatible = "snps,designware-i2s"; + clocks = <0x02 0x15>; + status = "disabled"; + phandle = <0xbc>; + }; + + sdio_clk0@b0004 { + compatible = "raspberrypi,rp1-sdio-clk"; + reg = <0xc0 0x400b0004 0x00 0x1c>; + clocks = <0x3c 0x3d>; + clock-names = "src", "base"; + #clock-cells = <0x00>; + status = "disabled"; + phandle = <0x42>; + }; + + sdio_clk1@b4004 { + compatible = "raspberrypi,rp1-sdio-clk"; + reg = <0xc0 0x400b4004 0x00 0x1c>; + clocks = <0x3c 0x3d>; + clock-names = "src", "base"; + #clock-cells = <0x00>; + status = "disabled"; + phandle = <0x43>; + }; + + adc@c8000 { + compatible = "raspberrypi,rp1-adc"; + reg = <0xc0 0x400c8000 0x00 0x4000>; + clocks = <0x02 0x1e>; + clock-names = "adcclk"; + #clock-cells = <0x00>; + vref-supply = <0x3e>; + status = "okay"; + phandle = <0xbd>; + }; + + gpio@d0000 { + reg = <0xc0 0x400d0000 0x00 0xc000 0xc0 0x400e0000 0x00 0xc000 0xc0 0x400f0000 0x00 0xc000>; + compatible = "raspberrypi,rp1-gpio"; + interrupts = <0x00 0x04 0x01 0x04 0x02 0x04>; + gpio-controller; + #gpio-cells = <0x02>; + interrupt-controller; + #interrupt-cells = <0x02>; + gpio-ranges = <0x2e 0x00 0x00 0x36>; + status = "okay"; + gpio-line-names = "ID_SDA", "ID_SCL", "GPIO2", "GPIO3", "GPIO4", "GPIO5", "GPIO6", "GPIO7", "GPIO8", "GPIO9", "GPIO10", "GPIO11", "GPIO12", "GPIO13", "GPIO14", "GPIO15", "GPIO16", "GPIO17", "GPIO18", "GPIO19", "GPIO20", "GPIO21", "GPIO22", "GPIO23", "GPIO24", "GPIO25", "GPIO26", "GPIO27", "PCIE_RP1_WAKE", "FAN_TACH", "HOST_SDA", "HOST_SCL", "ETH_RST_N", "-", "CD0_IO0_MICCLK", "CD0_IO0_MICDAT0", "RP1_PCIE_CLKREQ_N", "-", "CD0_SDA", "CD0_SCL", "CD1_SDA", "CD1_SCL", "USB_VBUS_EN", "USB_OC_N", "RP1_STAT_LED", "FAN_PWM", "CD1_IO0_MICCLK", "2712_WAKE", "CD1_IO1_MICDAT1", "EN_MAX_USB_CUR", "-", "-", "-", "-"; + phandle = <0x2e>; + + rp1_uart0_14_15 { + phandle = <0x2a>; + + pin_txd { + function = "uart0"; + pins = "gpio14"; + bias-disable; + }; + + pin_rxd { + function = "uart0"; + pins = "gpio15"; + bias-pull-up; + }; + }; + + rp1_uart0_ctsrts_16_17 { + phandle = <0xbe>; + + pin_cts { + function = "uart0"; + pins = "gpio16"; + bias-pull-up; + }; + + pin_rts { + function = "uart0"; + pins = "gpio17"; + bias-disable; + }; + }; + + rp1_uart1_0_1 { + phandle = <0xbf>; + + pin_txd { + function = "uart1"; + pins = "gpio0"; + bias-disable; + }; + + pin_rxd { + function = "uart1"; + pins = "gpio1"; + bias-pull-up; + }; + }; + + rp1_uart1_ctsrts_2_3 { + phandle = <0xc0>; + + pin_cts { + function = "uart1"; + pins = "gpio2"; + bias-pull-up; + }; + + pin_rts { + function = "uart1"; + pins = "gpio3"; + bias-disable; + }; + }; + + rp1_uart2_4_5 { + phandle = <0xc1>; + + pin_txd { + function = "uart2"; + pins = "gpio4"; + bias-disable; + }; + + pin_rxd { + function = "uart2"; + pins = "gpio5"; + bias-pull-up; + }; + }; + + rp1_uart2_ctsrts_6_7 { + phandle = <0xc2>; + + pin_cts { + function = "uart2"; + pins = "gpio6"; + bias-pull-up; + }; + + pin_rts { + function = "uart2"; + pins = "gpio7"; + bias-disable; + }; + }; + + rp1_uart3_8_9 { + phandle = <0xc3>; + + pin_txd { + function = "uart3"; + pins = "gpio8"; + bias-disable; + }; + + pin_rxd { + function = "uart3"; + pins = "gpio9"; + bias-pull-up; + }; + }; + + rp1_uart3_ctsrts_10_11 { + phandle = <0xc4>; + + pin_cts { + function = "uart3"; + pins = "gpio10"; + bias-pull-up; + }; + + pin_rts { + function = "uart3"; + pins = "gpio11"; + bias-disable; + }; + }; + + rp1_uart4_12_13 { + phandle = <0xc5>; + + pin_txd { + function = "uart4"; + pins = "gpio12"; + bias-disable; + }; + + pin_rxd { + function = "uart4"; + pins = "gpio13"; + bias-pull-up; + }; + }; + + rp1_uart4_ctsrts_14_15 { + phandle = <0xc6>; + + pin_cts { + function = "uart4"; + pins = "gpio14"; + bias-pull-up; + }; + + pin_rts { + function = "uart4"; + pins = "gpio15"; + bias-disable; + }; + }; + + rp1_sdio0_22_27 { + phandle = <0xc7>; + + pin_clk { + function = "sd0"; + pins = "gpio22"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + + pin_cmd { + function = "sd0"; + pins = "gpio23"; + bias-pull-up; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + + pins_dat { + function = "sd0"; + pins = "gpio24", "gpio25", "gpio26", "gpio27"; + bias-pull-up; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + }; + + rp1_sdio1_28_33 { + phandle = <0xc8>; + + pin_clk { + function = "sd1"; + pins = "gpio28"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + + pin_cmd { + function = "sd1"; + pins = "gpio29"; + bias-pull-up; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + + pins_dat { + function = "sd1"; + pins = "gpio30", "gpio31", "gpio32", "gpio33"; + bias-pull-up; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + }; + + rp1_i2s0_18_21 { + function = "i2s0"; + pins = "gpio18", "gpio19", "gpio20", "gpio21"; + bias-disable; + phandle = <0x3a>; + }; + + rp1_i2s1_18_21 { + function = "i2s1"; + pins = "gpio18", "gpio19", "gpio20", "gpio21"; + bias-disable; + phandle = <0x3b>; + }; + + rp1_i2c4_34_35 { + function = "i2c4"; + pins = "gpio34", "gpio35"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xc9>; + }; + + rp1_i2c6_38_39 { + function = "i2c6"; + pins = "gpio38", "gpio39"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x38>; + }; + + rp1_i2c4_40_41 { + function = "i2c4"; + pins = "gpio40", "gpio41"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x37>; + }; + + rp1_i2c5_44_45 { + function = "i2c5"; + pins = "gpio44", "gpio45"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xca>; + }; + + rp1_i2c0_0_1 { + function = "i2c0"; + pins = "gpio0", "gpio1"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x33>; + }; + + rp1_i2c0_8_9 { + function = "i2c0"; + pins = "gpio8", "gpio9"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xcb>; + }; + + rp1_i2c1_2_3 { + function = "i2c1"; + pins = "gpio2", "gpio3"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x34>; + }; + + rp1_i2c1_10_11 { + function = "i2c1"; + pins = "gpio10", "gpio11"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xcc>; + }; + + rp1_i2c2_4_5 { + function = "i2c2"; + pins = "gpio4", "gpio5"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x35>; + }; + + rp1_i2c2_12_13 { + function = "i2c2"; + pins = "gpio12", "gpio13"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xcd>; + }; + + rp1_i2c3_6_7 { + function = "i2c3"; + pins = "gpio6", "gpio7"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x36>; + }; + + rp1_i2c3_14_15 { + function = "i2c3"; + pins = "gpio14", "gpio15"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xce>; + }; + + rp1_i2c3_22_23 { + function = "i2c3"; + pins = "gpio22", "gpio23"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xcf>; + }; + + rp1_dpi_16bit_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19"; + bias-disable; + phandle = <0xd0>; + }; + + rp1_dpi_16bit_cpadhi_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24"; + bias-disable; + phandle = <0xd1>; + }; + + rp1_dpi_16bit_pad666_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25"; + bias-disable; + phandle = <0xd2>; + }; + + rp1_dpi_18bit_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21"; + bias-disable; + phandle = <0xd3>; + }; + + rp1_dpi_18bit_cpadhi_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25"; + bias-disable; + phandle = <0xd4>; + }; + + rp1_dpi_24bit_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25", "gpio26", "gpio27"; + bias-disable; + phandle = <0xd5>; + }; + + rp1_dpi_hvsync { + function = "dpi"; + pins = "gpio2", "gpio3"; + bias-disable; + phandle = <0xd6>; + }; + + rp1_dpi_16bit_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19"; + bias-disable; + phandle = <0xd7>; + }; + + rp1_dpi_16bit_cpadhi_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24"; + bias-disable; + phandle = <0xd8>; + }; + + rp1_dpi_16bit_pad666_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25"; + bias-disable; + phandle = <0xd9>; + }; + + rp1_dpi_18bit_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21"; + bias-disable; + phandle = <0xda>; + }; + + rp1_dpi_18bit_cpadhi_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25"; + bias-disable; + phandle = <0xdb>; + }; + + rp1_dpi_24bit_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25", "gpio26", "gpio27"; + bias-disable; + phandle = <0xdc>; + }; + + rp1_gpclksrc0_gpio4 { + function = "gpclk0"; + pins = "gpio4"; + bias-disable; + phandle = <0xdd>; + }; + + rp1_gpclksrc0_gpio20 { + function = "gpclk0"; + pins = "gpio20"; + bias-disable; + phandle = <0xde>; + }; + + rp1_gpclksrc1_gpio5 { + function = "gpclk1"; + pins = "gpio5"; + bias-disable; + phandle = <0xdf>; + }; + + rp1_gpclksrc1_gpio18 { + function = "gpclk1"; + pins = "gpio18"; + bias-disable; + phandle = <0xe0>; + }; + + rp1_gpclksrc1_gpio21 { + function = "gpclk1"; + pins = "gpio21"; + bias-disable; + phandle = <0xe1>; + }; + + rp1_pwm1_gpio45 { + function = "pwm1"; + pins = "gpio45"; + bias-pull-down; + phandle = <0x39>; + }; + + rp1_spi0_gpio9 { + function = "spi0"; + pins = "gpio9", "gpio10", "gpio11"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x2c>; + }; + + rp1_spi0_cs_gpio7 { + function = "spi0"; + pins = "gpio7", "gpio8"; + bias-pull-up; + phandle = <0x2d>; + }; + + rp1_spi1_gpio19 { + function = "spi1"; + pins = "gpio19", "gpio20", "gpio21"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0xe2>; + }; + + rp1_spi2_gpio1 { + function = "spi2"; + pins = "gpio1", "gpio2", "gpio3"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x2f>; + }; + + rp1_spi3_gpio5 { + function = "spi3"; + pins = "gpio5", "gpio6", "gpio7"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x30>; + }; + + rp1_spi4_gpio9 { + function = "spi4"; + pins = "gpio9", "gpio10", "gpio11"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x31>; + }; + + rp1_spi5_gpio13 { + function = "spi5"; + pins = "gpio13", "gpio14", "gpio15"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x32>; + }; + + rp1_spi8_gpio49 { + function = "spi8"; + pins = "gpio49", "gpio50", "gpio51"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0xe3>; + }; + + rp1_spi8_cs_gpio52 { + function = "spi0"; + pins = "gpio52", "gpio53"; + bias-pull-up; + phandle = <0xe4>; + }; + + rp1_audio_out_12_13 { + function = "aaud"; + pins = "gpio12", "gpio13"; + bias-disable; + phandle = <0xe5>; + }; + + usb_vbus_pins { + function = "vbus1"; + pins = "gpio42", "gpio43"; + phandle = <0x44>; + }; + }; + + ethernet@100000 { + reg = <0xc0 0x40100000 0x00 0x4000>; + compatible = "raspberrypi,rp1-gem", "cdns,macb"; + #address-cells = <0x01>; + #size-cells = <0x00>; + interrupts = <0x06 0x04>; + clocks = <0x02 0x0c 0x02 0x0c 0x02 0x1d 0x02 0x10>; + clock-names = "pclk", "hclk", "tsu_clk", "tx_clk"; + phy-mode = "rgmii-id"; + cdns,aw2w-max-pipe = [08]; + cdns,ar2r-max-pipe = [08]; + cdns,use-aw2b-fill; + local-mac-address = [00 00 00 00 00 00]; + status = "okay"; + phy-handle = <0x3f>; + phy-reset-gpios = <0x2e 0x20 0x01>; + phy-reset-duration = <0x05>; + phandle = <0xe6>; + + ethernet-phy@1 { + reg = <0x01>; + brcm,powerdown-enable; + eee-broken-1000t; + eee-broken-100tx; + phandle = <0x3f>; + }; + }; + + csi@110000 { + compatible = "raspberrypi,rp1-cfe"; + reg = <0xc0 0x40110000 0x00 0x100 0xc0 0x40114000 0x00 0x100 0xc0 0x40120000 0x00 0x100 0xc0 0x40124000 0x00 0x1000>; + interrupts = <0x2f 0x04>; + clocks = <0x02 0x16>; + assigned-clocks = <0x02 0x16>; + assigned-clock-rates = <0x17d7840>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + iommus = <0x40>; + phandle = <0xe7>; + }; + + csi@128000 { + compatible = "raspberrypi,rp1-cfe"; + reg = <0xc0 0x40128000 0x00 0x100 0xc0 0x4012c000 0x00 0x100 0xc0 0x40138000 0x00 0x100 0xc0 0x4013c000 0x00 0x1000>; + interrupts = <0x30 0x04>; + clocks = <0x02 0x17>; + assigned-clocks = <0x02 0x17>; + assigned-clock-rates = <0x17d7840>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + iommus = <0x40>; + phandle = <0xe8>; + }; + + pio@178000 { + reg = <0xc0 0x40178000 0x00 0x20>; + compatible = "raspberrypi,rp1-pio"; + firmware = <0x41>; + dmas = <0x2b 0x38 0x2b 0x39 0x2b 0x3a 0x2b 0x3b 0x2b 0x3c 0x2b 0x3d 0x2b 0x3e 0x2b 0x3f>; + dma-names = "tx0", "rx0", "tx1", "rx1", "tx2", "rx2", "tx3", "rx3"; + status = "okay"; + phandle = <0xe9>; + }; + + mmc@180000 { + reg = <0xc0 0x40180000 0x00 0x100>; + compatible = "raspberrypi,rp1-dwcmshc"; + interrupts = <0x11 0x04>; + clocks = <0x02 0x0c 0x3d 0x02 0x1f 0x42>; + clock-names = "bus", "core", "timeout", "sdio"; + no-1-8-v; + bus-width = <0x04>; + vmmc-supply = <0x3e>; + broken-cd; + status = "disabled"; + phandle = <0xea>; + }; + + mmc@184000 { + reg = <0xc0 0x40184000 0x00 0x100>; + compatible = "raspberrypi,rp1-dwcmshc"; + interrupts = <0x12 0x04>; + clocks = <0x02 0x0c 0x3d 0x02 0x1f 0x43>; + clock-names = "bus", "core", "timeout", "sdio"; + bus-width = <0x04>; + vmmc-supply = <0x3e>; + sdhci-caps-mask = <0x03 0x00>; + broken-cd; + status = "disabled"; + phandle = <0xeb>; + }; + + dma@188000 { + reg = <0xc0 0x40188000 0x00 0x1000>; + compatible = "snps,axi-dma-1.01a"; + interrupts = <0x28 0x04>; + clocks = <0x02 0x0e 0x02 0x0c>; + clock-names = "core-clk", "cfgr-clk"; + #dma-cells = <0x01>; + dma-channels = <0x08>; + snps,dma-masters = <0x01>; + snps,dma-targets = <0x40>; + snps,data-width = <0x04>; + snps,block-size = <0x40000 0x40000 0x40000 0x40000 0x40000 0x40000 0x40000 0x40000>; + snps,priority = <0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07>; + snps,axi-max-burst-len = <0x04>; + status = "okay"; + phandle = <0x2b>; + }; + + usb@200000 { + reg = <0xc0 0x40200000 0x00 0x100000>; + compatible = "snps,dwc3"; + dr_mode = "host"; + usb3-lpm-capable; + snps,axi-pipe-limit = [08]; + snps,dis_rxdet_inp3_quirk; + snps,enhanced-nak-fs-quirk; + snps,parkmode-disable-ss-quirk; + snps,parkmode-disable-hs-quirk; + snps,parkmode-disable-fsls-quirk; + snps,tx-max-burst = [08]; + snps,tx-thr-num-pkt = [02]; + interrupts = <0x1f 0x01>; + status = "okay"; + pinctrl-0 = <0x44>; + pinctrl-names = "default"; + phandle = <0xec>; + }; + + usb@300000 { + reg = <0xc0 0x40300000 0x00 0x100000>; + compatible = "snps,dwc3"; + dr_mode = "host"; + usb3-lpm-capable; + snps,axi-pipe-limit = [08]; + snps,dis_rxdet_inp3_quirk; + snps,enhanced-nak-fs-quirk; + snps,parkmode-disable-ss-quirk; + snps,parkmode-disable-hs-quirk; + snps,parkmode-disable-fsls-quirk; + snps,tx-max-burst = [08]; + snps,tx-thr-num-pkt = [02]; + interrupts = <0x24 0x01>; + status = "okay"; + phandle = <0xed>; + }; + + dsi@110000 { + compatible = "raspberrypi,rp1dsi"; + status = "disabled"; + reg = <0xc0 0x40118000 0x00 0x1000 0xc0 0x4011c000 0x00 0x1000 0xc0 0x40120000 0x00 0x1000>; + interrupts = <0x2f 0x04>; + clocks = <0x02 0x16 0x02 0x29 0x02 0x2d 0x29 0x02 0x03>; + clock-names = "cfgclk", "dpiclk", "byteclk", "refclk", "pllsys"; + assigned-clocks = <0x02 0x16>; + assigned-clock-rates = <0x17d7840>; + iommus = <0x40>; + phandle = <0xee>; + }; + + dsi@128000 { + compatible = "raspberrypi,rp1dsi"; + status = "disabled"; + reg = <0xc0 0x40130000 0x00 0x1000 0xc0 0x40134000 0x00 0x1000 0xc0 0x40138000 0x00 0x1000>; + interrupts = <0x30 0x04>; + clocks = <0x02 0x17 0x02 0x2a 0x02 0x2e 0x29 0x02 0x03>; + clock-names = "cfgclk", "dpiclk", "byteclk", "refclk", "pllsys"; + assigned-clocks = <0x02 0x17>; + assigned-clock-rates = <0x17d7840>; + iommus = <0x40>; + phandle = <0xef>; + }; + + vec@144000 { + compatible = "raspberrypi,rp1vec"; + status = "disabled"; + reg = <0xc0 0x40144000 0x00 0x1000 0xc0 0x40140000 0x00 0x1000>; + interrupts = <0x31 0x04>; + clocks = <0x02 0x27>; + assigned-clocks = <0x02 0x02 0x02 0x0b 0x02 0x27>; + assigned-clock-rates = <0x46cf7100 0x66ff300 0x66ff300>; + assigned-clock-parents = <0x00 0x02 0x02 0x02 0x0b>; + iommus = <0x40>; + phandle = <0xf0>; + }; + + dpi@148000 { + compatible = "raspberrypi,rp1dpi"; + status = "disabled"; + reg = <0xc0 0x40148000 0x00 0x1000 0xc0 0x40140000 0x00 0x1000>; + interrupts = <0x31 0x04>; + clocks = <0x02 0x28 0x02 0x05 0x02 0x02>; + clock-names = "dpiclk", "plldiv", "pllcore"; + assigned-clocks = <0x02 0x28>; + assigned-clock-parents = <0x02 0x05>; + iommus = <0x40>; + phandle = <0xf1>; + }; + + sram@400000 { + compatible = "mmio-sram"; + reg = <0xc0 0x40400000 0x00 0x10000>; + #address-cells = <0x01>; + #size-cells = <0x01>; + ranges = <0x00 0xc0 0x40400000 0x10000>; + phandle = <0xf2>; + + shmem@ff00 { + compatible = "raspberrypi,rp1-shmem"; + reg = <0xff00 0x100>; + phandle = <0x5c>; + }; + }; + + gpiomem@d0000 { + compatible = "raspberrypi,gpiomem"; + reg = <0xc0 0x400d0000 0x00 0x30000>; + chardev-name = "gpiomem0"; + }; + }; + }; + + msi-controller@1000130000 { + compatible = "brcm,bcm2712-mip"; + reg = <0x10 0x130000 0x00 0xc0 0xff 0xfffff000 0x00 0x1000>; + msi-controller; + msi-ranges = <0x01 0x00 0x80 0x01 0x40>; + brcm,msi-offset = <0x00>; + phandle = <0x27>; + }; + + msi-controller@1000131000 { + compatible = "brcm,bcm2712-mip"; + reg = <0x10 0x131000 0x00 0xc0 0xff 0xfffff000 0x00 0x1000>; + msi-controller; + msi-ranges = <0x01 0x00 0xf7 0x01 0x08>; + brcm,msi-offset = <0x08>; + phandle = <0x26>; + }; + + iommu@5100 { + compatible = "brcm,bcm2712-iommu"; + reg = <0x10 0x5100 0x00 0x80>; + cache = <0x45>; + #iommu-cells = <0x00>; + phandle = <0x49>; + }; + + iommu@5200 { + compatible = "brcm,bcm2712-iommu"; + reg = <0x10 0x5200 0x00 0x80>; + cache = <0x45>; + #iommu-cells = <0x00>; + #interconnect-cells = <0x00>; + phandle = <0x4d>; + }; + + iommu@5280 { + compatible = "brcm,bcm2712-iommu"; + reg = <0x10 0x5280 0x00 0x80>; + cache = <0x45>; + #iommu-cells = <0x00>; + dma-iova-offset = <0x10 0x00>; + phandle = <0x40>; + }; + + iommuc@5b00 { + compatible = "brcm,bcm2712-iommuc"; + reg = <0x10 0x5b00 0x00 0x80>; + phandle = <0x45>; + }; + + dma@10000 { + compatible = "brcm,bcm2712-dma"; + reg = <0x10 0x10000 0x00 0x600>; + interrupts = <0x00 0x50 0x04 0x00 0x51 0x04 0x00 0x52 0x04 0x00 0x53 0x04 0x00 0x54 0x04 0x00 0x55 0x04>; + interrupt-names = "dma0", "dma1", "dma2", "dma3", "dma4", "dma5"; + #dma-cells = <0x01>; + brcm,dma-channel-mask = <0x3f>; + phandle = <0xf3>; + }; + + dma@10600 { + compatible = "brcm,bcm2712-dma"; + reg = <0x10 0x10600 0x00 0x600>; + interrupts = <0x00 0x56 0x04 0x00 0x57 0x04 0x00 0x58 0x04 0x00 0x59 0x04 0x00 0x5a 0x04 0x00 0x5b 0x04>; + interrupt-names = "dma6", "dma7", "dma8", "dma9", "dma10", "dma11"; + #dma-cells = <0x01>; + brcm,dma-channel-mask = <0x7c0>; + phandle = <0x16>; + }; + + syscon@400018 { + compatible = "brcm,syscon-piarbctl", "syscon", "simple-mfd"; + reg = <0x10 0x400018 0x00 0x18>; + phandle = <0xf4>; + }; + + usb@480000 { + compatible = "brcm,bcm2835-usb"; + reg = <0x10 0x480000 0x00 0x10000>; + interrupts = <0x00 0x49 0x04>; + #address-cells = <0x01>; + #size-cells = <0x00>; + clocks = <0x46>; + clock-names = "otg"; + phys = <0x47>; + phy-names = "usb2-phy"; + status = "disabled"; + power-domains = <0x48 0x06>; + phandle = <0xf5>; + }; + + codec@800000 { + compatible = "brcm,bcm2712-hevc-dec", "raspberrypi,hevc-dec"; + reg = <0x10 0x800000 0x00 0x10000 0x10 0x840000 0x00 0x1000>; + reg-names = "hevc", "intc"; + interrupts = <0x00 0x62 0x04>; + clocks = <0x17 0x0b>; + clock-names = "hevc"; + iommus = <0x49>; + phandle = <0xf6>; + }; + + pisp_be@880000 { + compatible = "raspberrypi,pispbe"; + reg = <0x10 0x880000 0x00 0x4000>; + interrupts = <0x00 0x48 0x04>; + clocks = <0x17 0x07>; + clocks-names = "isp_be"; + status = "okay"; + iommus = <0x49>; + phandle = <0xf7>; + }; + + mmc@1100000 { + compatible = "brcm,bcm2712-sdhci"; + reg = <0x10 0x1100000 0x00 0x260 0x10 0x1100400 0x00 0x200>; + reg-names = "host", "cfg"; + interrupts = <0x00 0x112 0x04>; + clocks = <0x08>; + sdhci-caps-mask = <0xc000 0x00>; + sdhci-caps = <0x00 0x00>; + supports-cqe = <0x01>; + mmc-ddr-3_3v; + status = "okay"; + pinctrl-0 = <0x4a>; + pinctrl-names = "default"; + bus-width = <0x04>; + vmmc-supply = <0x4b>; + sd-uhs-ddr50; + non-removable; + #address-cells = <0x01>; + #size-cells = <0x00>; + phandle = <0xf8>; + + wifi@1 { + reg = <0x01>; + compatible = "brcm,bcm4329-fmac"; + local-mac-address = [00 00 00 00 00 00]; + phandle = <0x71>; + }; + }; + + v3d@2000000 { + compatible = "brcm,2712-v3d"; + reg = <0x10 0x2000000 0x00 0x4000 0x10 0x2008000 0x00 0x6000 0x10 0x2030800 0x00 0x700>; + reg-names = "hub", "core0", "sms"; + power-domains = <0x4c 0x01>; + resets = <0x4c 0x00>; + clocks = <0x17 0x05>; + clocks-names = "v3d"; + interrupts = <0x00 0xfa 0x04 0x00 0xf9 0x04>; + status = "disabled"; + phandle = <0xf9>; + }; + }; + + timer { + compatible = "arm,armv8-timer"; + interrupts = <0x01 0x0d 0xf08 0x01 0x0e 0xf08 0x01 0x0b 0xf08 0x01 0x0a 0xf08 0x01 0x0c 0xf08>; + }; + + clk-27M { + #clock-cells = <0x00>; + compatible = "fixed-clock"; + clock-frequency = <0x19bfcc0>; + clock-output-names = "27MHz-clock"; + phandle = <0x18>; + }; + + clk-108M { + #clock-cells = <0x00>; + compatible = "fixed-clock"; + clock-frequency = <0x66ff300>; + clock-output-names = "108MHz-clock"; + phandle = <0x11>; + }; + + hvs@107c580000 { + compatible = "brcm,bcm2712-hvs"; + reg = <0x10 0x7c580000 0x1a000>; + interrupt-parent = <0x10>; + interrupts = <0x02 0x09 0x10>; + interrupt-names = "ch0-eof", "ch1-eof", "ch2-eof"; + iommus = <0x4d>; + status = "disabled"; + clocks = <0x17 0x04 0x17 0x10>; + clock-names = "core", "disp"; + phandle = <0xfa>; + }; + + arm-pmu { + compatible = "arm,cortex-a76-pmu"; + interrupts = <0x00 0x10 0x04 0x00 0x11 0x04 0x00 0x12 0x04 0x00 0x13 0x04>; + interrupt-affinity = <0x4e 0x4f 0x50 0x51>; + }; + + thermal-zones { + + cpu-thermal { + polling-delay-passive = <0x3e8>; + polling-delay = <0x3e8>; + coefficients = <0xfffffdda 0x6ddd0>; + thermal-sensors = <0x52>; + phandle = <0xfb>; + + trips { + phandle = <0xfc>; + + cpu-crit { + temperature = <0x1adb0>; + hysteresis = <0x00>; + type = "critical"; + phandle = <0x58>; + }; + + cpu-tepid { + temperature = <0xc350>; + hysteresis = <0x1388>; + type = "active"; + phandle = <0x53>; + }; + + cpu-warm { + temperature = <0xea60>; + hysteresis = <0x1388>; + type = "active"; + phandle = <0x55>; + }; + + cpu-hot { + temperature = <0x107ac>; + hysteresis = <0x1388>; + type = "active"; + phandle = <0x56>; + }; + + cpu-vhot { + temperature = <0x124f8>; + hysteresis = <0x1388>; + type = "active"; + phandle = <0x57>; + }; + }; + + cooling-maps { + phandle = <0xfd>; + + tepid { + trip = <0x53>; + cooling-device = <0x54 0x01 0x01>; + }; + + warm { + trip = <0x55>; + cooling-device = <0x54 0x02 0x02>; + }; + + hot { + trip = <0x56>; + cooling-device = <0x54 0x03 0x03>; + }; + + vhot { + trip = <0x57>; + cooling-device = <0x54 0x04 0x04>; + }; + + melt { + trip = <0x58>; + cooling-device = <0x54 0x04 0x04>; + }; + }; + }; + }; + + firmwarekms { + compatible = "raspberrypi,rpi-firmware-kms-2712"; + interrupt-parent = <0x59>; + interrupts = <0x13>; + brcm,firmware = <0x1a>; + status = "disabled"; + phandle = <0xfe>; + }; + + phy { + compatible = "usb-nop-xceiv"; + #phy-cells = <0x00>; + phandle = <0x47>; + }; + + memory@0 { + device_type = "memory"; + reg = <0x00 0x00 0x28000000>; + }; + + leds { + compatible = "gpio-leds"; + phandle = <0xff>; + + led-pwr { + label = "PWR"; + gpios = <0x2e 0x2c 0x01>; + default-state = "off"; + linux,default-trigger = "none"; + phandle = <0x6b>; + }; + + led-act { + label = "ACT"; + gpios = <0x0d 0x09 0x01>; + default-state = "off"; + linux,default-trigger = "mmc0"; + phandle = <0x5d>; + }; + }; + + sd-io-1v8-reg { + compatible = "regulator-gpio"; + regulator-name = "vdd-sd-io"; + regulator-min-microvolt = <0x1b7740>; + regulator-max-microvolt = <0x325aa0>; + regulator-boot-on; + regulator-always-on; + regulator-settling-time-us = <0x1388>; + gpios = <0x0d 0x03 0x00>; + states = <0x1b7740 0x01 0x325aa0 0x00>; + phandle = <0x0b>; + }; + + sd-vcc-reg { + compatible = "regulator-fixed"; + regulator-name = "vcc-sd"; + regulator-min-microvolt = <0x325aa0>; + regulator-max-microvolt = <0x325aa0>; + regulator-boot-on; + enable-active-high; + gpios = <0x0d 0x04 0x00>; + phandle = <0x0c>; + }; + + wl-on-reg { + compatible = "regulator-fixed"; + regulator-name = "wl-on-regulator"; + regulator-min-microvolt = <0x325aa0>; + regulator-max-microvolt = <0x325aa0>; + pinctrl-0 = <0x5a>; + pinctrl-names = "default"; + gpio = <0x1b 0x1c 0x00>; + startup-delay-us = <0x249f0>; + enable-active-high; + phandle = <0x4b>; + }; + + cam1_clk { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + status = "disabled"; + phandle = <0x100>; + }; + + cam0_clk { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + status = "disabled"; + phandle = <0x101>; + }; + + cam0_reg { + compatible = "regulator-fixed"; + regulator-name = "cam0_reg"; + enable-active-high; + gpio = <0x2e 0x22 0x00>; + phandle = <0x72>; + }; + + cam1_reg { + compatible = "regulator-fixed"; + regulator-name = "cam1_reg"; + enable-active-high; + gpio = <0x2e 0x2e 0x00>; + phandle = <0x73>; + }; + + cam_dummy_reg { + compatible = "regulator-fixed"; + regulator-name = "cam-dummy-reg"; + phandle = <0x102>; + }; + + dummy { + phandle = <0x103>; + }; + + i2c0if { + phandle = <0x104>; + }; + + i2c0mux { + phandle = <0x105>; + }; + + rp1_firmware { + compatible = "raspberrypi,rp1-firmware", "simple-mfd"; + mboxes = <0x5b 0x00>; + shmem = <0x5c>; + phandle = <0x41>; + }; + + rp1_vdd_3v3 { + compatible = "regulator-fixed"; + regulator-name = "vdd-3v3"; + regulator-min-microvolt = <0x325aa0>; + regulator-max-microvolt = <0x325aa0>; + regulator-always-on; + phandle = <0x3e>; + }; + + chosen { + bootargs = "reboot=w coherent_pool=1M 8250.nr_uarts=1 pci=pcie_bus_safe cgroup_disable=memory numa_policy=interleave nvme.max_host_mem_size_mb=0"; + stdout-path = "serial10:115200n8"; + phandle = <0x6f>; + }; + + aliases { + blconfig = "/reserved-memory/nvram@0"; + blpubkey = "/reserved-memory/nvram@1"; + bluetooth = "/soc@107c000000/serial@7d50c000/bluetooth"; + console = "/soc@107c000000/serial@7d001000"; + drm-dsi1 = "/axi/pcie@1000120000/rp1/dsi@110000"; + drm-dsi2 = "/axi/pcie@1000120000/rp1/dsi@128000"; + ethernet0 = "/axi/pcie@1000120000/rp1/ethernet@100000"; + fb = "/soc@107c000000/fb"; + gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000"; + gpio1 = "/soc@107c000000/gpio@7d508500"; + gpio2 = "/soc@107c000000/gpio@7d517c00"; + gpio3 = "/soc@107c000000/pinctrl@7d504100"; + gpio4 = "/soc@107c000000/pinctrl@7d510700"; + gpiochip0 = "/axi/pcie@1000120000/rp1/gpio@d0000"; + gpiochip10 = "/soc@107c000000/gpio@7d508500"; + i2c = "/axi/pcie@1000120000/rp1/i2c@74000"; + i2c0 = "/axi/pcie@1000120000/rp1/i2c@70000"; + i2c1 = "/axi/pcie@1000120000/rp1/i2c@74000"; + i2c2 = "/axi/pcie@1000120000/rp1/i2c@78000"; + i2c3 = "/axi/pcie@1000120000/rp1/i2c@7c000"; + i2c10 = "/axi/pcie@1000120000/rp1/i2c@88000"; + i2c11 = "/axi/pcie@1000120000/rp1/i2c@80000"; + i2c12 = "/soc@107c000000/i2c@7d005600"; + mailbox = "/soc@107c000000/mailbox@7c013880"; + mmc0 = "/soc@107c000000/mmc@fff000"; + pio0 = "/axi/pcie@1000120000/rp1/pio@178000"; + serial0 = "/axi/pcie@1000120000/rp1/serial@30000"; + serial1 = "/axi/pcie@1000120000/rp1/serial@34000"; + serial10 = "/soc@107c000000/serial@7d001000"; + serial2 = "/axi/pcie@1000120000/rp1/serial@38000"; + serial3 = "/axi/pcie@1000120000/rp1/serial@3c000"; + serial4 = "/axi/pcie@1000120000/rp1/serial@40000"; + spi0 = "/axi/pcie@1000120000/rp1/spi@50000"; + spi1 = "/axi/pcie@1000120000/rp1/spi@54000"; + spi10 = "/soc@107c000000/spi@7d004000"; + spi2 = "/axi/pcie@1000120000/rp1/spi@58000"; + spi3 = "/axi/pcie@1000120000/rp1/spi@5c000"; + spi4 = "/axi/pcie@1000120000/rp1/spi@60000"; + spi5 = "/axi/pcie@1000120000/rp1/spi@64000"; + uart0 = "/axi/pcie@1000120000/rp1/serial@30000"; + uart1 = "/axi/pcie@1000120000/rp1/serial@34000"; + uart10 = "/soc@107c000000/serial@7d001000"; + uart2 = "/axi/pcie@1000120000/rp1/serial@38000"; + uart3 = "/axi/pcie@1000120000/rp1/serial@3c000"; + uart4 = "/axi/pcie@1000120000/rp1/serial@40000"; + usb0 = "/axi/pcie@1000120000/rp1/usb@200000"; + usb1 = "/axi/pcie@1000120000/rp1/usb@300000"; + wifi0 = "/axi/mmc@1100000/wifi@1"; + phandle = <0x62>; + }; + + __overrides__ { + act_led_gpio = [00 00 00 5d 67 70 69 6f 73 3a 34 00 00 00 00 5d 67 70 69 6f 73 3a 30 3d 00 00 00 00 2e]; + act_led_activelow = "", "", "", "]gpios:8"; + act_led_trigger = "", "", "", "]linux,default-trigger"; + axiperf = "", "", "", "^status"; + bdaddr = "", "", "", "_local-bd-address["; + button_debounce = "", "", "", "`debounce-interval:0"; + cooling_fan = "", "", "", "Tstatus", "", "", "", "astatus"; + drm_fb0_rp1_dpi = "", "", "", "bdrm-fb0=", "/axi/pcie@1000120000/rp1/dpi@148000"; + drm_fb0_rp1_dsi0 = "", "", "", "bdrm-fb0=", "/axi/pcie@1000120000/rp1/dsi@110000"; + drm_fb0_rp1_dsi1 = "", "", "", "bdrm-fb0=", "/axi/pcie@1000120000/rp1/dsi@128000"; + drm_fb0_vc4 = "", "", "", "bdrm-fb0=", "/axi/gpu"; + drm_fb1_rp1_dpi = "", "", "", "bdrm-fb1=", "/axi/pcie@1000120000/rp1/dpi@148000"; + drm_fb1_rp1_dsi0 = "", "", "", "bdrm-fb1=", "/axi/pcie@1000120000/rp1/dsi@110000"; + drm_fb1_rp1_dsi1 = "", "", "", "bdrm-fb1=", "/axi/pcie@1000120000/rp1/dsi@128000"; + drm_fb1_vc4 = "", "", "", "bdrm-fb1=", "/axi/gpu"; + drm_fb2_rp1_dpi = "", "", "", "bdrm-fb2=", "/axi/pcie@1000120000/rp1/dpi@148000"; + drm_fb2_rp1_dsi0 = "", "", "", "bdrm-fb2=", "/axi/pcie@1000120000/rp1/dsi@110000"; + drm_fb2_rp1_dsi1 = "", "", "", "bdrm-fb2=", "/axi/pcie@1000120000/rp1/dsi@128000"; + drm_fb2_vc4 = "", "", "", "bdrm-fb2=", "/axi/gpu"; + eth_led0 = "", "", "", "?led-modes:0"; + eth_led1 = "", "", "", "?led-modes:4"; + fan_temp0 = "", "", "", "Stemperature:0"; + fan_temp0_hyst = "", "", "", "Shysteresis:0"; + fan_temp0_speed = "", "", "", "Tcooling-levels:4"; + fan_temp1 = "", "", "", "Utemperature:0"; + fan_temp1_hyst = "", "", "", "Uhysteresis:0"; + fan_temp1_speed = "", "", "", "Tcooling-levels:8"; + fan_temp2 = "", "", "", "Vtemperature:0"; + fan_temp2_hyst = "", "", "", "Vhysteresis:0"; + fan_temp2_speed = "", "", "", "Tcooling-levels:12"; + fan_temp3 = "", "", "", "Wtemperature:0"; + fan_temp3_hyst = "", "", "", "Whysteresis:0"; + fan_temp3_speed = "", "", "", "Tcooling-levels:16"; + i2c = "", "", "", "cstatus"; + i2c_arm = "", "", "", "cstatus"; + i2c_arm_baudrate = "", "", "", "cclock-frequency:0"; + i2c_baudrate = "", "", "", "cclock-frequency:0"; + i2c_csi_dsi = "", "", "", "dstatus"; + i2c_csi_dsi0 = "", "", "", "estatus"; + i2c_csi_dsi1 = "", "", "", "dstatus"; + i2c_vc = "", "", "", "fstatus"; + i2c_vc_baudrate = "", "", "", "fclock-frequency:0"; + i2c0 = "", "", "", "fstatus"; + i2c0_baudrate = "", "", "", "fclock-frequency:0"; + i2c1 = "", "", "", "cstatus"; + i2c1_baudrate = "", "", "", "cclock-frequency:0"; + krnbt = "", "", "", "_status"; + nvme = "", "", "", "gstatus"; + nvmem_cust_rw = "", "", "", "hrw?"; + nvmem_mac_rw = "", "", "", "irw?"; + nvmem_priv_rw = "", "", "", "jrw?"; + pcie_tperst_clk_ms = "", "", "", "gbrcm,tperst-clk-ms:0"; + pciex1 = "", "", "", "gstatus"; + pciex1_gen = "", "", "", "gmax-link-speed:0"; + pciex1_no_l0s = "", "", "", "gaspm-no-l0s?"; + pciex1_tperst_clk_ms = "", "", "", "gbrcm,tperst-clk-ms:0"; + pwr_led_gpio = "", "", "", "kgpios:4"; + pwr_led_activelow = "", "", "", "kgpios:8"; + pwr_led_trigger = "", "", "", "klinux,default-trigger"; + random = "", "", "", "lstatus"; + rtc = "", "", "", "mstatus"; + rtc_bbat_vchg = "", "", "", "mtrickle-charge-microvolt:0"; + spi = "", "", "", "nstatus"; + strict_gpiod = "", "", "", "obootargs=pinctrl_rp1.persist_gpio_outputs=n"; + suspend = "", "", "", "`linux,code:0=205"; + uart0 = "", "", "", "pstatus"; + uart0_console = "", "", "", "pstatus", "", "", "", "bconsole=", "/axi/pcie@1000120000/rp1/serial@30000"; + uart0_dma = [00 00 00 70 64 6d 61 73 3a 30 3d 00 00 00 00 2b 00 00 00 70 64 6d 61 73 3a 34 3d 00 00 00 00 1a 00 00 00 70 64 6d 61 73 3a 38 3d 00 00 00 00 2b 00 00 00 70 64 6d 61 73 3a 31 32 3d 00 00 00 00 19 00 00 00 70 64 6d 61 2d 6e 61 6d 65 73 5b 3d 37 34 37 38 30 30 37 32 37 38 30 30 00]; + wifiaddr = "", "", "", "qlocal-mac-address["; + cam0_reg = "", "", "", "rstatus"; + cam0_reg_gpio = [00 00 00 72 67 70 69 6f 3a 34 00 00 00 00 72 67 70 69 6f 3a 30 3d 00 00 00 00 2e]; + cam1_reg = "", "", "", "sstatus"; + cam1_reg_gpio = [00 00 00 73 67 70 69 6f 3a 34 00 00 00 00 73 67 70 69 6f 3a 30 3d 00 00 00 00 2e]; + sd_cqe = "", "", "", "tsupports-cqe:0"; + }; + + cooling_fan { + status = "disabled"; + compatible = "pwm-fan"; + #cooling-cells = <0x02>; + cooling-min-state = <0x00>; + cooling-max-state = <0x03>; + cooling-levels = <0x00 0x4b 0x7d 0xaf 0xfa>; + pwms = <0x61 0x03 0xa25e 0x01>; + rpm-regmap = <0x61>; + rpm-offset = <0x3c>; + phandle = <0x54>; + }; + + pwr_button { + compatible = "gpio-keys"; + pinctrl-names = "default"; + pinctrl-0 = <0x75>; + status = "okay"; + + pwr { + label = "pwr_button"; + linux,code = <0x74>; + gpios = <0x1b 0x14 0x01>; + debounce-interval = <0x32>; + phandle = <0x60>; + }; + }; + + __symbols__ { + clocks = "/clocks"; + clk_osc = "/clocks/clk-osc"; + clk_vpu = "/clocks/clk-vpu"; + clk_uart = "/clocks/clk-uart"; + clk_emmc2 = "/clocks/clk-emmc2"; + clk_usb = "/clocks/clk-usb"; + clk_xosc = "/clocks/clk_xosc"; + sdio_src = "/clocks/sdio_src"; + sdhci_core = "/clocks/sdhci_core"; + clksrc_gp0 = "/clocks/clksrc_gp0"; + clksrc_gp1 = "/clocks/clksrc_gp1"; + clksrc_gp2 = "/clocks/clksrc_gp2"; + clksrc_gp3 = "/clocks/clksrc_gp3"; + clksrc_gp4 = "/clocks/clksrc_gp4"; + clksrc_gp5 = "/clocks/clksrc_gp5"; + cpus = "/cpus"; + cpu0 = "/cpus/cpu@0"; + l2_cache_l0 = "/cpus/cpu@0/l2-cache-l0"; + cpu1 = "/cpus/cpu@1"; + l2_cache_l1 = "/cpus/cpu@1/l2-cache-l1"; + cpu2 = "/cpus/cpu@2"; + l2_cache_l2 = "/cpus/cpu@2/l2-cache-l2"; + cpu3 = "/cpus/cpu@3"; + l2_cache_l3 = "/cpus/cpu@3/l2-cache-l3"; + l3_cache = "/cpus/l3-cache"; + rmem = "/reserved-memory"; + cma = "/reserved-memory/linux,cma"; + blconfig = "/reserved-memory/nvram@0"; + blpubkey = "/reserved-memory/nvram@1"; + soc = "/soc@107c000000"; + pcie_rescal = "/soc@107c000000/reset-controller@119500"; + sdio1 = "/soc@107c000000/mmc@fff000"; + bcm_reset = "/soc@107c000000/reset-controller@1504318"; + system_timer = "/soc@107c000000/timer@7c003000"; + mailbox = "/soc@107c000000/mailbox@7c013880"; + local_intc = "/soc@107c000000/interrupt-controller@7cd00000"; + uart10 = "/soc@107c000000/serial@7d001000"; + gio_aon = "/soc@107c000000/gpio@7d517c00"; + gicv2 = "/soc@107c000000/interrupt-controller@7fff9000"; + aon_intr = "/soc@107c000000/interrupt-controller@7d510600"; + pixelvalve0 = "/soc@107c000000/pixelvalve@7c410000"; + pixelvalve1 = "/soc@107c000000/pixelvalve@7c411000"; + mop = "/soc@107c000000/mop@7c500000"; + moplet = "/soc@107c000000/moplet@7c501000"; + disp_intr = "/soc@107c000000/interrupt-controller@7c502000"; + dvp = "/soc@107c000000/clock@7c700000"; + ddc0 = "/soc@107c000000/i2c@7d508200"; + ddc1 = "/soc@107c000000/i2c@7d508280"; + bsc_irq = "/soc@107c000000/intc@7d508380"; + main_irq = "/soc@107c000000/intc@7d508400"; + hdmi0 = "/soc@107c000000/hdmi@7ef00700"; + hdmi1 = "/soc@107c000000/hdmi@7ef05700"; + axiperf = "/soc@107c000000/axiperf@7c012800"; + spi10 = "/soc@107c000000/spi@7d004000"; + spidev10 = "/soc@107c000000/spi@7d004000/spidev@0"; + i2c10 = "/soc@107c000000/i2c@7d005600"; + pm = "/soc@107c000000/watchdog@7d200000"; + random = "/soc@107c000000/rng@7d208000"; + cpu_l2_irq = "/soc@107c000000/intc@7d503000"; + pinctrl = "/soc@107c000000/pinctrl@7d504100"; + uarta_24_pins = "/soc@107c000000/pinctrl@7d504100/uarta_24_pins"; + sdio2_30_pins = "/soc@107c000000/pinctrl@7d504100/sdio2_30_pins"; + pwr_button_pins = "/soc@107c000000/pinctrl@7d504100/pwr_button_pins"; + wl_on_pins = "/soc@107c000000/pinctrl@7d504100/wl_on_pins"; + bt_shutdown_pins = "/soc@107c000000/pinctrl@7d504100/bt_shutdown_pins"; + emmc_sd_pulls = "/soc@107c000000/pinctrl@7d504100/emmc_sd_pulls"; + spi10_pins = "/soc@107c000000/pinctrl@7d504100/spi10_gpio2"; + spi10_gpio2 = "/soc@107c000000/pinctrl@7d504100/spi10_gpio2"; + spi10_cs_pins = "/soc@107c000000/pinctrl@7d504100/spi10_cs_gpio1"; + spi10_cs_gpio1 = "/soc@107c000000/pinctrl@7d504100/spi10_cs_gpio1"; + gio = "/soc@107c000000/gpio@7d508500"; + uarta = "/soc@107c000000/serial@7d50c000"; + bluetooth = "/soc@107c000000/serial@7d50c000/bluetooth"; + pinctrl_aon = "/soc@107c000000/pinctrl@7d510700"; + i2c3_m4_agpio0_pins = "/soc@107c000000/pinctrl@7d510700/i2c3_m4_agpio0_pins"; + bsc_m1_agpio13_pins = "/soc@107c000000/pinctrl@7d510700/bsc_m1_agpio13_pins"; + bsc_pmu_sgpio4_pins = "/soc@107c000000/pinctrl@7d510700/bsc_pmu_sgpio4_pins"; + bsc_m2_sgpio4_pins = "/soc@107c000000/pinctrl@7d510700/bsc_m2_sgpio4_pins"; + pwm_aon_agpio1_pins = "/soc@107c000000/pinctrl@7d510700/pwm_aon_agpio1_pins"; + pwm_aon_agpio4_pins = "/soc@107c000000/pinctrl@7d510700/pwm_aon_agpio4_pins"; + pwm_aon_agpio7_pins = "/soc@107c000000/pinctrl@7d510700/pwm_aon_agpio7_pins"; + emmc_aon_cd_pins = "/soc@107c000000/pinctrl@7d510700/emmc_aon_cd_pins"; + aon_pwm_1pin = "/soc@107c000000/pinctrl@7d510700/aon_pwm_1pin"; + main_aon_irq = "/soc@107c000000/intc@7d517ac0"; + avs_monitor = "/soc@107c000000/avs-monitor@7d542000"; + thermal = "/soc@107c000000/avs-monitor@7d542000/thermal"; + firmware = "/soc@107c000000/firmware"; + firmware_clocks = "/soc@107c000000/firmware/clocks"; + reset = "/soc@107c000000/firmware/reset"; + vcio = "/soc@107c000000/firmware/vcio"; + power = "/soc@107c000000/power"; + fb = "/soc@107c000000/fb"; + rpi_rtc = "/soc@107c000000/rpi_rtc"; + nvmem_otp = "/soc@107c000000/nvmem/nvmem_otp"; + nvmem_cust = "/soc@107c000000/nvmem/nvmem_cust"; + nvmem_mac = "/soc@107c000000/nvmem/nvmem_mac"; + nvmem_priv = "/soc@107c000000/nvmem/nvmem_priv"; + vdd_3v3_reg = "/soc@107c000000/fixedregulator_3v3"; + vdd_5v0_reg = "/soc@107c000000/fixedregulator_5v0"; + sound = "/soc@107c000000/sound"; + axi = "/axi"; + vc4 = "/axi/gpu"; + pcie0 = "/axi/pcie@1000100000"; + pciex1 = "/axi/pcie@1000110000"; + pcie1 = "/axi/pcie@1000110000"; + pciex4 = "/axi/pcie@1000120000"; + rp1_target = "/axi/pcie@1000120000"; + pcie2 = "/axi/pcie@1000120000"; + rp1 = "/axi/pcie@1000120000/rp1"; + rp1_mbox = "/axi/pcie@1000120000/rp1/mailbox@8000"; + rp1_clocks = "/axi/pcie@1000120000/rp1/clocks@18000"; + uart0 = "/axi/pcie@1000120000/rp1/serial@30000"; + rp1_uart0 = "/axi/pcie@1000120000/rp1/serial@30000"; + uart1 = "/axi/pcie@1000120000/rp1/serial@34000"; + rp1_uart1 = "/axi/pcie@1000120000/rp1/serial@34000"; + uart2 = "/axi/pcie@1000120000/rp1/serial@38000"; + rp1_uart2 = "/axi/pcie@1000120000/rp1/serial@38000"; + uart3 = "/axi/pcie@1000120000/rp1/serial@3c000"; + rp1_uart3 = "/axi/pcie@1000120000/rp1/serial@3c000"; + uart4 = "/axi/pcie@1000120000/rp1/serial@40000"; + rp1_uart4 = "/axi/pcie@1000120000/rp1/serial@40000"; + rp1_uart5 = "/axi/pcie@1000120000/rp1/serial@44000"; + rp1_spi8 = "/axi/pcie@1000120000/rp1/spi@4c000"; + spi0 = "/axi/pcie@1000120000/rp1/spi@50000"; + rp1_spi0 = "/axi/pcie@1000120000/rp1/spi@50000"; + spidev0 = "/axi/pcie@1000120000/rp1/spi@50000/spidev@0"; + spidev1 = "/axi/pcie@1000120000/rp1/spi@50000/spidev@1"; + spi1 = "/axi/pcie@1000120000/rp1/spi@54000"; + rp1_spi1 = "/axi/pcie@1000120000/rp1/spi@54000"; + spi2 = "/axi/pcie@1000120000/rp1/spi@58000"; + rp1_spi2 = "/axi/pcie@1000120000/rp1/spi@58000"; + spi3 = "/axi/pcie@1000120000/rp1/spi@5c000"; + rp1_spi3 = "/axi/pcie@1000120000/rp1/spi@5c000"; + spi4 = "/axi/pcie@1000120000/rp1/spi@60000"; + rp1_spi4 = "/axi/pcie@1000120000/rp1/spi@60000"; + spi5 = "/axi/pcie@1000120000/rp1/spi@64000"; + rp1_spi5 = "/axi/pcie@1000120000/rp1/spi@64000"; + rp1_spi6 = "/axi/pcie@1000120000/rp1/spi@68000"; + rp1_spi7 = "/axi/pcie@1000120000/rp1/spi@6c000"; + i2c_vc = "/axi/pcie@1000120000/rp1/i2c@70000"; + i2c0 = "/axi/pcie@1000120000/rp1/i2c@70000"; + rp1_i2c0 = "/axi/pcie@1000120000/rp1/i2c@70000"; + i2c_arm = "/axi/pcie@1000120000/rp1/i2c@74000"; + i2c1 = "/axi/pcie@1000120000/rp1/i2c@74000"; + rp1_i2c1 = "/axi/pcie@1000120000/rp1/i2c@74000"; + i2c2 = "/axi/pcie@1000120000/rp1/i2c@78000"; + rp1_i2c2 = "/axi/pcie@1000120000/rp1/i2c@78000"; + i2c3 = "/axi/pcie@1000120000/rp1/i2c@7c000"; + rp1_i2c3 = "/axi/pcie@1000120000/rp1/i2c@7c000"; + i2c_csi_dsi = "/axi/pcie@1000120000/rp1/i2c@80000"; + i2c_csi_dsi1 = "/axi/pcie@1000120000/rp1/i2c@80000"; + i2c4 = "/axi/pcie@1000120000/rp1/i2c@80000"; + rp1_i2c4 = "/axi/pcie@1000120000/rp1/i2c@80000"; + i2c5 = "/axi/pcie@1000120000/rp1/i2c@84000"; + rp1_i2c5 = "/axi/pcie@1000120000/rp1/i2c@84000"; + i2c_csi_dsi0 = "/axi/pcie@1000120000/rp1/i2c@88000"; + i2c6 = "/axi/pcie@1000120000/rp1/i2c@88000"; + rp1_i2c6 = "/axi/pcie@1000120000/rp1/i2c@88000"; + rp1_audio_out = "/axi/pcie@1000120000/rp1/audio_out@94000"; + pwm = "/axi/pcie@1000120000/rp1/pwm@98000"; + pwm0 = "/axi/pcie@1000120000/rp1/pwm@98000"; + rp1_pwm0 = "/axi/pcie@1000120000/rp1/pwm@98000"; + pwm1 = "/axi/pcie@1000120000/rp1/pwm@9c000"; + rp1_pwm1 = "/axi/pcie@1000120000/rp1/pwm@9c000"; + i2s_clk_producer = "/axi/pcie@1000120000/rp1/i2s@a0000"; + i2s = "/axi/pcie@1000120000/rp1/i2s@a0000"; + rp1_i2s0 = "/axi/pcie@1000120000/rp1/i2s@a0000"; + i2s_clk_consumer = "/axi/pcie@1000120000/rp1/i2s@a4000"; + rp1_i2s1 = "/axi/pcie@1000120000/rp1/i2s@a4000"; + rp1_i2s2 = "/axi/pcie@1000120000/rp1/i2s@a8000"; + rp1_sdio_clk0 = "/axi/pcie@1000120000/rp1/sdio_clk0@b0004"; + rp1_sdio_clk1 = "/axi/pcie@1000120000/rp1/sdio_clk1@b4004"; + rp1_adc = "/axi/pcie@1000120000/rp1/adc@c8000"; + gpio = "/axi/pcie@1000120000/rp1/gpio@d0000"; + rp1_gpio = "/axi/pcie@1000120000/rp1/gpio@d0000"; + uart0_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart0_14_15"; + rp1_uart0_14_15 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart0_14_15"; + uart0_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart0_ctsrts_16_17"; + rp1_uart0_ctsrts_16_17 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart0_ctsrts_16_17"; + uart1_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart1_0_1"; + rp1_uart1_0_1 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart1_0_1"; + uart1_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart1_ctsrts_2_3"; + rp1_uart1_ctsrts_2_3 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart1_ctsrts_2_3"; + uart2_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart2_4_5"; + rp1_uart2_4_5 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart2_4_5"; + uart2_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart2_ctsrts_6_7"; + rp1_uart2_ctsrts_6_7 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart2_ctsrts_6_7"; + uart3_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart3_8_9"; + rp1_uart3_8_9 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart3_8_9"; + uart3_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart3_ctsrts_10_11"; + rp1_uart3_ctsrts_10_11 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart3_ctsrts_10_11"; + uart4_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart4_12_13"; + rp1_uart4_12_13 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart4_12_13"; + uart4_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart4_ctsrts_14_15"; + rp1_uart4_ctsrts_14_15 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart4_ctsrts_14_15"; + rp1_sdio0_22_27 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_sdio0_22_27"; + rp1_sdio1_28_33 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_sdio1_28_33"; + rp1_i2s0_18_21 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2s0_18_21"; + rp1_i2s1_18_21 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2s1_18_21"; + rp1_i2c4_34_35 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c4_34_35"; + rp1_i2c6_38_39 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c6_38_39"; + rp1_i2c4_40_41 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c4_40_41"; + rp1_i2c5_44_45 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c5_44_45"; + i2c0_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c0_0_1"; + rp1_i2c0_0_1 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c0_0_1"; + rp1_i2c0_8_9 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c0_8_9"; + i2c1_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c1_2_3"; + rp1_i2c1_2_3 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c1_2_3"; + rp1_i2c1_10_11 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c1_10_11"; + i2c2_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c2_4_5"; + rp1_i2c2_4_5 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c2_4_5"; + rp1_i2c2_12_13 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c2_12_13"; + i2c3_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c3_6_7"; + rp1_i2c3_6_7 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c3_6_7"; + rp1_i2c3_14_15 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c3_14_15"; + rp1_i2c3_22_23 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c3_22_23"; + dpi_16bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_gpio2"; + rp1_dpi_16bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_gpio2"; + dpi_16bit_cpadhi_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_cpadhi_gpio2"; + rp1_dpi_16bit_cpadhi_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_cpadhi_gpio2"; + rp1_dpi_16bit_pad666_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_pad666_gpio2"; + dpi_18bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_gpio2"; + rp1_dpi_18bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_gpio2"; + dpi_18bit_cpadhi_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_cpadhi_gpio2"; + rp1_dpi_18bit_cpadhi_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_cpadhi_gpio2"; + dpi_gpio1 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_24bit_gpio2"; + rp1_dpi_24bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_24bit_gpio2"; + rp1_dpi_hvsync = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_hvsync"; + dpi_16bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_gpio0"; + rp1_dpi_16bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_gpio0"; + dpi_16bit_cpadhi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_cpadhi_gpio0"; + rp1_dpi_16bit_cpadhi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_cpadhi_gpio0"; + rp1_dpi_16bit_pad666_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_pad666_gpio0"; + dpi_18bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_gpio0"; + rp1_dpi_18bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_gpio0"; + dpi_18bit_cpadhi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_cpadhi_gpio0"; + rp1_dpi_18bit_cpadhi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_cpadhi_gpio0"; + dpi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_24bit_gpio0"; + rp1_dpi_24bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_24bit_gpio0"; + rp1_gpclksrc0_gpio4 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc0_gpio4"; + rp1_gpclksrc0_gpio20 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc0_gpio20"; + rp1_gpclksrc1_gpio5 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc1_gpio5"; + rp1_gpclksrc1_gpio18 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc1_gpio18"; + rp1_gpclksrc1_gpio21 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc1_gpio21"; + rp1_pwm1_gpio45 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_pwm1_gpio45"; + spi0_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi0_gpio9"; + rp1_spi0_gpio9 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi0_gpio9"; + spi0_cs_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi0_cs_gpio7"; + rp1_spi0_cs_gpio7 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi0_cs_gpio7"; + rp1_spi1_gpio19 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi1_gpio19"; + spi2_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi2_gpio1"; + rp1_spi2_gpio1 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi2_gpio1"; + spi3_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi3_gpio5"; + rp1_spi3_gpio5 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi3_gpio5"; + spi4_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi4_gpio9"; + rp1_spi4_gpio9 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi4_gpio9"; + spi5_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi5_gpio13"; + rp1_spi5_gpio13 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi5_gpio13"; + rp1_spi8_gpio49 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi8_gpio49"; + rp1_spi8_cs_gpio52 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi8_cs_gpio52"; + rp1_audio_out_12_13 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_audio_out_12_13"; + usb_vbus_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/usb_vbus_pins"; + rp1_eth = "/axi/pcie@1000120000/rp1/ethernet@100000"; + phy1 = "/axi/pcie@1000120000/rp1/ethernet@100000/ethernet-phy@1"; + csi0 = "/axi/pcie@1000120000/rp1/csi@110000"; + rp1_csi0 = "/axi/pcie@1000120000/rp1/csi@110000"; + csi1 = "/axi/pcie@1000120000/rp1/csi@128000"; + rp1_csi1 = "/axi/pcie@1000120000/rp1/csi@128000"; + pio = "/axi/pcie@1000120000/rp1/pio@178000"; + rp1_pio = "/axi/pcie@1000120000/rp1/pio@178000"; + rp1_mmc0 = "/axi/pcie@1000120000/rp1/mmc@180000"; + rp1_mmc1 = "/axi/pcie@1000120000/rp1/mmc@184000"; + rp1_dma = "/axi/pcie@1000120000/rp1/dma@188000"; + rp1_usb0 = "/axi/pcie@1000120000/rp1/usb@200000"; + rp1_usb1 = "/axi/pcie@1000120000/rp1/usb@300000"; + dsi0 = "/axi/pcie@1000120000/rp1/dsi@110000"; + rp1_dsi0 = "/axi/pcie@1000120000/rp1/dsi@110000"; + dsi1 = "/axi/pcie@1000120000/rp1/dsi@128000"; + rp1_dsi1 = "/axi/pcie@1000120000/rp1/dsi@128000"; + vec = "/axi/pcie@1000120000/rp1/vec@144000"; + rp1_vec = "/axi/pcie@1000120000/rp1/vec@144000"; + dpi = "/axi/pcie@1000120000/rp1/dpi@148000"; + rp1_dpi = "/axi/pcie@1000120000/rp1/dpi@148000"; + sram = "/axi/pcie@1000120000/rp1/sram@400000"; + rp1_fw_shmem = "/axi/pcie@1000120000/rp1/sram@400000/shmem@ff00"; + mip0 = "/axi/msi-controller@1000130000"; + mip1 = "/axi/msi-controller@1000131000"; + iommu2 = "/axi/iommu@5100"; + iommu4 = "/axi/iommu@5200"; + iommu5 = "/axi/iommu@5280"; + iommuc = "/axi/iommuc@5b00"; + dma32 = "/axi/dma@10000"; + dma40 = "/axi/dma@10600"; + syscon_piarbctl = "/axi/syscon@400018"; + usb = "/axi/usb@480000"; + hevc_dec = "/axi/codec@800000"; + pisp_be = "/axi/pisp_be@880000"; + sdio2 = "/axi/mmc@1100000"; + wifi = "/axi/mmc@1100000/wifi@1"; + v3d = "/axi/v3d@2000000"; + clk_27MHz = "/clk-27M"; + clk_108MHz = "/clk-108M"; + hvs = "/hvs@107c580000"; + cpu_thermal = "/thermal-zones/cpu-thermal"; + thermal_trips = "/thermal-zones/cpu-thermal/trips"; + cpu_crit = "/thermal-zones/cpu-thermal/trips/cpu-crit"; + cpu_tepid = "/thermal-zones/cpu-thermal/trips/cpu-tepid"; + cpu_warm = "/thermal-zones/cpu-thermal/trips/cpu-warm"; + cpu_hot = "/thermal-zones/cpu-thermal/trips/cpu-hot"; + cpu_vhot = "/thermal-zones/cpu-thermal/trips/cpu-vhot"; + cooling_maps = "/thermal-zones/cpu-thermal/cooling-maps"; + firmwarekms = "/firmwarekms"; + usbphy = "/phy"; + leds = "/leds"; + led_pwr = "/leds/led-pwr"; + led_act = "/leds/led-act"; + sd_io_1v8_reg = "/sd-io-1v8-reg"; + sd_vcc_reg = "/sd-vcc-reg"; + wl_on_reg = "/wl-on-reg"; + cam1_clk = "/cam1_clk"; + cam0_clk = "/cam0_clk"; + cam0_reg = "/cam0_reg"; + cam1_reg = "/cam1_reg"; + cam_dummy_reg = "/cam_dummy_reg"; + aux = "/dummy"; + dummy = "/dummy"; + i2c0if = "/i2c0if"; + i2c0mux = "/i2c0mux"; + rp1_firmware = "/rp1_firmware"; + rp1_vdd_3v3 = "/rp1_vdd_3v3"; + chosen = "/chosen"; + aliases = "/aliases"; + fan = "/cooling_fan"; + pwr_key = "/pwr_button/pwr"; + }; +}; diff --git a/dtbs/rpi5b2.dts b/dtbs/rpi5b2.dts new file mode 100644 index 00000000..adea0115 --- /dev/null +++ b/dtbs/rpi5b2.dts @@ -0,0 +1,3292 @@ +/dts-v1/; + +/ { + compatible = "raspberrypi,5-model-b", "brcm,bcm2712"; + #address-cells = <0x02>; + #size-cells = <0x01>; + interrupt-parent = <0x01>; + model = "Raspberry Pi 5"; + + clocks { + compatible = "simple-bus"; + #address-cells = <0x01>; + #size-cells = <0x00>; + phandle = <0x76>; + + clk-osc { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "osc"; + clock-frequency = <0x337f980>; + phandle = <0x77>; + }; + + clk-vpu { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0x2cb41780>; + clock-output-names = "vpu-clock"; + phandle = <0x0f>; + }; + + clk-uart { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0x8ca000>; + clock-output-names = "uart-clock"; + phandle = <0x0e>; + }; + + clk-emmc2 { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0xbebc200>; + clock-output-names = "emmc2-clock"; + phandle = <0x08>; + }; + + clk-usb { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "otg"; + clock-frequency = <0x1c9c3800>; + phandle = <0x46>; + }; + + clk_xosc { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "xosc"; + clock-frequency = <0x2faf080>; + phandle = <0x29>; + }; + + sdio_src { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "src"; + clock-frequency = <0x3b9aca00>; + phandle = <0x3c>; + }; + + sdhci_core { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "core"; + clock-frequency = <0x2faf080>; + phandle = <0x3d>; + }; + + clksrc_gp0 { + status = "disabled"; + compatible = "fixed-factor-clock"; + #clock-cells = <0x00>; + clock-div = <0x01>; + clock-mult = <0x01>; + clocks = <0x02 0x21>; + clock-output-names = "clksrc_gp0"; + phandle = <0x78>; + }; + + clksrc_gp1 { + status = "disabled"; + compatible = "fixed-factor-clock"; + #clock-cells = <0x00>; + clock-div = <0x01>; + clock-mult = <0x01>; + clocks = <0x02 0x22>; + clock-output-names = "clksrc_gp1"; + phandle = <0x79>; + }; + + clksrc_gp2 { + status = "disabled"; + compatible = "fixed-factor-clock"; + clock-div = <0x01>; + clock-mult = <0x01>; + #clock-cells = <0x00>; + clocks = <0x02 0x23>; + clock-output-names = "clksrc_gp2"; + phandle = <0x7a>; + }; + + clksrc_gp3 { + status = "disabled"; + compatible = "fixed-factor-clock"; + clock-div = <0x01>; + clock-mult = <0x01>; + #clock-cells = <0x00>; + clocks = <0x02 0x24>; + clock-output-names = "clksrc_gp3"; + phandle = <0x7b>; + }; + + clksrc_gp4 { + status = "disabled"; + compatible = "fixed-factor-clock"; + #clock-cells = <0x00>; + clock-div = <0x01>; + clock-mult = <0x01>; + clocks = <0x02 0x25>; + clock-output-names = "clksrc_gp4"; + phandle = <0x7c>; + }; + + clksrc_gp5 { + status = "disabled"; + compatible = "fixed-factor-clock"; + #clock-cells = <0x00>; + clock-div = <0x01>; + clock-mult = <0x01>; + clocks = <0x02 0x26>; + clock-output-names = "clksrc_gp5"; + phandle = <0x7d>; + }; + }; + + cpus { + #address-cells = <0x01>; + #size-cells = <0x00>; + phandle = <0x7e>; + + cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a76"; + reg = <0x00>; + enable-method = "psci"; + d-cache-size = <0x10000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0x10000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x03>; + phandle = <0x4e>; + + l2-cache-l0 { + compatible = "cache"; + cache-size = <0x80000>; + cache-line-size = <0x40>; + cache-sets = <0x400>; + cache-level = <0x02>; + cache-unified; + next-level-cache = <0x04>; + phandle = <0x03>; + }; + }; + + cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a76"; + reg = <0x100>; + enable-method = "psci"; + d-cache-size = <0x10000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0x10000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x05>; + phandle = <0x4f>; + + l2-cache-l1 { + compatible = "cache"; + cache-size = <0x80000>; + cache-line-size = <0x40>; + cache-sets = <0x400>; + cache-level = <0x02>; + cache-unified; + next-level-cache = <0x04>; + phandle = <0x05>; + }; + }; + + cpu@2 { + device_type = "cpu"; + compatible = "arm,cortex-a76"; + reg = <0x200>; + enable-method = "psci"; + d-cache-size = <0x10000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0x10000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x06>; + phandle = <0x50>; + + l2-cache-l2 { + compatible = "cache"; + cache-size = <0x80000>; + cache-line-size = <0x40>; + cache-sets = <0x400>; + cache-level = <0x02>; + cache-unified; + next-level-cache = <0x04>; + phandle = <0x06>; + }; + }; + + cpu@3 { + device_type = "cpu"; + compatible = "arm,cortex-a76"; + reg = <0x300>; + enable-method = "psci"; + d-cache-size = <0x10000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0x10000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x07>; + phandle = <0x51>; + + l2-cache-l3 { + compatible = "cache"; + cache-size = <0x80000>; + cache-line-size = <0x40>; + cache-sets = <0x400>; + cache-level = <0x02>; + cache-unified; + next-level-cache = <0x04>; + phandle = <0x07>; + }; + }; + + l3-cache { + compatible = "cache"; + cache-size = <0x200000>; + cache-line-size = <0x40>; + cache-sets = <0x800>; + cache-level = <0x03>; + cache-unified; + phandle = <0x04>; + }; + }; + + psci { + method = "smc"; + compatible = "arm,psci-1.0", "arm,psci-0.2"; + }; + + reserved-memory { + ranges; + #address-cells = <0x02>; + #size-cells = <0x01>; + phandle = <0x7f>; + + atf@0 { + reg = <0x00 0x00 0x80000>; + no-map; + }; + + linux,cma { + compatible = "shared-dma-pool"; + size = <0x4000000>; + reusable; + linux,cma-default; + alloc-ranges = <0x00 0x00 0x40000000>; + phandle = <0x80>; + }; + + nvram@0 { + compatible = "raspberrypi,bootloader-config", "nvmem-rmem"; + #address-cells = <0x01>; + #size-cells = <0x01>; + reg = <0x00 0x00 0x00>; + no-map; + status = "disabled"; + phandle = <0x81>; + }; + + nvram@1 { + compatible = "raspberrypi,bootloader-public-key", "nvmem-rmem"; + #address-cells = <0x01>; + #size-cells = <0x01>; + reg = <0x00 0x00 0x00>; + no-map; + status = "disabled"; + phandle = <0x82>; + }; + }; + + soc@107c000000 { + compatible = "simple-bus"; + ranges = <0x00 0x10 0x00 0x80000000>; + #address-cells = <0x01>; + #size-cells = <0x01>; + phandle = <0x83>; + + reset-controller@119500 { + compatible = "brcm,bcm7216-pcie-sata-rescal"; + reg = <0x119500 0x10>; + #reset-cells = <0x00>; + phandle = <0x23>; + }; + + mmc@fff000 { + compatible = "brcm,bcm2712-sdhci", "brcm,sdhci-brcmstb"; + reg = <0xfff000 0x260 0xfff400 0x200>; + reg-names = "host", "cfg"; + interrupts = <0x00 0x111 0x04>; + clocks = <0x08>; + clock-names = "sw_sdio"; + mmc-ddr-3_3v; + pinctrl-0 = <0x09 0x0a>; + pinctrl-names = "default"; + vqmmc-supply = <0x0b>; + vmmc-supply = <0x0c>; + bus-width = <0x04>; + sd-uhs-sdr50; + sd-uhs-ddr50; + sd-uhs-sdr104; + supports-cqe = <0x01>; + cd-gpios = <0x0d 0x05 0x01>; + status = "okay"; + phandle = <0x74>; + }; + + reset-controller@1504318 { + compatible = "brcm,brcmstb-reset"; + reg = <0x1504318 0x30>; + #reset-cells = <0x01>; + phandle = <0x24>; + }; + + timer@7c003000 { + compatible = "brcm,bcm2835-system-timer"; + reg = <0x7c003000 0x1000>; + interrupts = <0x00 0x40 0x04 0x00 0x41 0x04 0x00 0x42 0x04 0x00 0x43 0x04>; + clock-frequency = <0xf4240>; + phandle = <0x84>; + }; + + mailbox@7c013880 { + compatible = "brcm,bcm2835-mbox"; + reg = <0x7c013880 0x40>; + interrupts = <0x00 0x21 0x04>; + #mbox-cells = <0x00>; + phandle = <0x22>; + }; + + interrupt-controller@7cd00000 { + compatible = "brcm,bcm2836-l1-intc"; + reg = <0x7cd00000 0x100>; + phandle = <0x85>; + }; + + serial@7d001000 { + compatible = "arm,pl011", "arm,primecell"; + reg = <0x7d001000 0x200>; + interrupts = <0x00 0x78 0x04>; + clocks = <0x0e 0x0f>; + clock-names = "uartclk", "apb_pclk"; + arm,primecell-periphid = <0x341011>; + status = "okay"; + phandle = <0x86>; + }; + + interrupt-controller@7d517000 { + compatible = "brcm,bcm7271-l2-intc"; + reg = <0x7d517000 0x10>; + interrupts = <0x00 0xf7 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + status = "disabled"; + }; + + gpio@7d517c00 { + compatible = "brcm,brcmstb-gpio"; + reg = <0x7d517c00 0x40>; + gpio-controller; + #gpio-cells = <0x02>; + brcm,gpio-bank-widths = <0x0f 0x06>; + brcm,gpio-direct; + gpio-line-names = "RP1_SDA", "RP1_SCL", "RP1_RUN", "SD_IOVDD_SEL", "SD_PWR_ON", "SD_CDET_N", "SD_FLG_N", "", "2712_WAKE", "2712_STAT_LED", "", "", "PMIC_INT", "UART_TX_FS", "UART_RX_FS", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "HDMI0_SCL", "HDMI0_SDA", "HDMI1_SCL", "HDMI1_SDA", "PMIC_SCL", "PMIC_SDA"; + phandle = <0x0d>; + + rp1_run_hog { + gpio-hog; + gpios = <0x02 0x00>; + output-high; + line-name = "RP1 RUN pin"; + }; + }; + + interrupt-controller@7fff9000 { + compatible = "arm,gic-400"; + reg = <0x7fff9000 0x1000 0x7fffa000 0x2000 0x7fffc000 0x2000 0x7fffe000 0x2000>; + interrupt-controller; + #interrupt-cells = <0x03>; + interrupts = <0x01 0x09 0xf04>; + phandle = <0x01>; + }; + + interrupt-controller@7d510600 { + compatible = "brcm,bcm2711-l2-intc", "brcm,l2-intc"; + reg = <0x7d510600 0x30>; + interrupts = <0x00 0xef 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + status = "disabled"; + phandle = <0x14>; + }; + + pixelvalve@7c410000 { + compatible = "brcm,bcm2712-pixelvalve0"; + reg = <0x7c410000 0x100>; + interrupts = <0x00 0x65 0x04>; + status = "disabled"; + phandle = <0x87>; + }; + + pixelvalve@7c411000 { + compatible = "brcm,bcm2712-pixelvalve1"; + reg = <0x7c411000 0x100>; + interrupts = <0x00 0x6e 0x04>; + status = "disabled"; + phandle = <0x88>; + }; + + mop@7c500000 { + compatible = "brcm,bcm2712-mop"; + reg = <0x7c500000 0x28>; + interrupt-parent = <0x10>; + interrupts = <0x01>; + status = "disabled"; + phandle = <0x89>; + }; + + moplet@7c501000 { + compatible = "brcm,bcm2712-moplet"; + reg = <0x7c501000 0x20>; + interrupt-parent = <0x10>; + interrupts = <0x00>; + status = "disabled"; + phandle = <0x8a>; + }; + + interrupt-controller@7c502000 { + compatible = "brcm,bcm2711-l2-intc", "brcm,l2-intc"; + reg = <0x7c502000 0x30>; + interrupts = <0x00 0x61 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + status = "disabled"; + phandle = <0x10>; + }; + + clock@7c700000 { + compatible = "brcm,brcm2711-dvp"; + reg = <0x7c700000 0x10>; + clocks = <0x11>; + #clock-cells = <0x01>; + #reset-cells = <0x01>; + phandle = <0x13>; + }; + + i2c@7d508200 { + compatible = "brcm,brcmstb-i2c"; + reg = <0x7d508200 0x58>; + interrupt-parent = <0x12>; + interrupts = <0x01>; + clock-frequency = <0x17cdc>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + phandle = <0x15>; + }; + + i2c@7d508280 { + compatible = "brcm,brcmstb-i2c"; + reg = <0x7d508280 0x58>; + interrupt-parent = <0x12>; + interrupts = <0x02>; + clock-frequency = <0x17cdc>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + phandle = <0x19>; + }; + + intc@7d508380 { + compatible = "brcm,bcm7271-l2-intc"; + reg = <0x7d508380 0x10>; + interrupts = <0x00 0xf2 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + phandle = <0x12>; + }; + + intc@7d508400 { + compatible = "brcm,bcm7271-l2-intc"; + reg = <0x7d508400 0x10>; + interrupts = <0x00 0xf4 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + phandle = <0x1f>; + }; + + hdmi@7ef00700 { + compatible = "brcm,bcm2712-hdmi0"; + reg = <0x7c701400 0x300 0x7c701000 0x200 0x7c701d00 0x300 0x7c702000 0x80 0x7c703800 0x200 0x7c704000 0x800 0x7c700100 0x80 0x7d510800 0x100 0x7c720000 0x100>; + reg-names = "hdmi", "dvp", "phy", "rm", "packet", "metadata", "csc", "cec", "hd"; + resets = <0x13 0x01>; + interrupt-parent = <0x14>; + interrupts = <0x01 0x02 0x03 0x07 0x08>; + interrupt-names = "cec-tx", "cec-rx", "cec-low", "hpd-connected", "hpd-removed"; + ddc = <0x15>; + status = "disabled"; + dmas = <0x16 0x41fa000c>; + dma-names = "audio-rx"; + clocks = <0x17 0x0d 0x17 0x0e 0x13 0x00 0x18>; + clock-names = "hdmi", "bvb", "audio", "cec"; + phandle = <0x8b>; + }; + + hdmi@7ef05700 { + compatible = "brcm,bcm2712-hdmi1"; + reg = <0x7c706400 0x300 0x7c706000 0x200 0x7c706d00 0x300 0x7c707000 0x80 0x7c708800 0x200 0x7c709000 0x800 0x7c700180 0x80 0x7d511000 0x100 0x7c720000 0x100>; + reg-names = "hdmi", "dvp", "phy", "rm", "packet", "metadata", "csc", "cec", "hd"; + resets = <0x13 0x02>; + interrupt-parent = <0x14>; + interrupts = <0x0b 0x0c 0x0d 0x0e 0x0f>; + interrupt-names = "cec-tx", "cec-rx", "cec-low", "hpd-connected", "hpd-removed"; + ddc = <0x19>; + status = "disabled"; + dmas = <0x16 0x41fa000d>; + dma-names = "audio-rx"; + clocks = <0x17 0x0d 0x17 0x0e 0x13 0x01 0x18>; + clock-names = "hdmi", "bvb", "audio", "cec"; + phandle = <0x8c>; + }; + + axiperf@7c012800 { + compatible = "brcm,bcm2712-axiperf"; + reg = <0x7c012800 0x100 0x7e000000 0x100>; + firmware = <0x1a>; + status = "disabled"; + phandle = <0x5e>; + }; + + spi@7d004000 { + compatible = "brcm,bcm2835-spi"; + reg = <0x7d004000 0x200>; + interrupts = <0x00 0x76 0x04>; + clocks = <0x0f>; + num-cs = <0x01>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "okay"; + dmas = <0x16 0x03 0x16 0x04>; + dma-names = "tx", "rx"; + pinctrl-names = "default"; + cs-gpios = <0x1b 0x01 0x01>; + pinctrl-0 = <0x1c 0x1d>; + phandle = <0x8d>; + + spidev@0 { + compatible = "spidev"; + reg = <0x00>; + #address-cells = <0x01>; + #size-cells = <0x00>; + spi-max-frequency = <0x1312d00>; + status = "okay"; + phandle = <0x8e>; + }; + }; + + i2c@7d005600 { + compatible = "brcm,bcm2711-i2c", "brcm,bcm2835-i2c"; + reg = <0x7d005600 0x20>; + interrupts = <0x00 0x75 0x04>; + clocks = <0x0f>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + clock-frequency = <0x61a80>; + pinctrl-0 = <0x1e>; + pinctrl-names = "default"; + phandle = <0x8f>; + }; + + watchdog@7d200000 { + compatible = "brcm,bcm2712-pm"; + reg = <0x7d200000 0x308>; + reg-names = "pm"; + #power-domain-cells = <0x01>; + #reset-cells = <0x01>; + system-power-controller; + phandle = <0x4c>; + }; + + rng@7d208000 { + compatible = "brcm,bcm2711-rng200"; + reg = <0x7d208000 0x28>; + status = "okay"; + phandle = <0x6c>; + }; + + intc@7d503000 { + compatible = "brcm,l2-intc"; + reg = <0x7d503000 0x18>; + interrupts = <0x00 0xee 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + phandle = <0x59>; + }; + + pinctrl@7d504100 { + compatible = "brcm,bcm2712d0-pinctrl"; + reg = <0x7d504100 0x20>; + phandle = <0x90>; + + uarta_24_pins { + phandle = <0x20>; + + pin_rts { + function = "uart0"; + pins = "gpio24"; + bias-disable; + }; + + pin_cts { + function = "uart0"; + pins = "gpio25"; + bias-pull-up; + }; + + pin_txd { + function = "uart0"; + pins = "gpio26"; + bias-disable; + }; + + pin_rxd { + function = "uart0"; + pins = "gpio27"; + bias-pull-up; + }; + }; + + sdio2_30_pins { + phandle = <0x4a>; + + pin_clk { + function = "sd2"; + pins = "gpio30"; + bias-disable; + }; + + pin_cmd { + function = "sd2"; + pins = "gpio31"; + bias-pull-up; + }; + + pins_dat { + function = "sd2"; + pins = "gpio32", "gpio33", "gpio34", "gpio35"; + bias-pull-up; + }; + }; + + pwr_button_pins { + function = "gpio"; + pins = "gpio20"; + bias-pull-up; + phandle = <0x75>; + }; + + wl_on_pins { + function = "gpio"; + pins = "gpio28"; + phandle = <0x5a>; + }; + + bt_shutdown_pins { + function = "gpio"; + pins = "gpio29"; + phandle = <0x21>; + }; + + emmc_sd_pulls { + pins = "emmc_cmd", "emmc_dat0", "emmc_dat1", "emmc_dat2", "emmc_dat3"; + bias-pull-up; + phandle = <0x09>; + }; + + spi10_gpio2 { + function = "vc_spi0"; + pins = "gpio2", "gpio3", "gpio4"; + bias-disable; + phandle = <0x1c>; + }; + + spi10_cs_gpio1 { + function = "gpio"; + pins = "gpio1"; + bias-pull-up; + phandle = <0x1d>; + }; + }; + + gpio@7d508500 { + compatible = "brcm,brcmstb-gpio"; + reg = <0x7d508500 0x40>; + interrupt-parent = <0x1f>; + interrupts = <0x00>; + gpio-controller; + #gpio-cells = <0x02>; + interrupt-controller; + #interrupt-cells = <0x02>; + brcm,gpio-bank-widths = <0x20 0x04>; + brcm,gpio-direct; + gpio-line-names = "", "2712_BOOT_CS_N", "2712_BOOT_MISO", "2712_BOOT_MOSI", "2712_BOOT_SCLK", "", "", "", "", "", "-", "-", "-", "-", "PCIE_SDA", "PCIE_SCL", "", "", "-", "-", "PWR_GPIO", "2712_G21_FS", "-", "-", "BT_RTS", "BT_CTS", "BT_TXD", "BT_RXD", "WL_ON", "BT_ON", "WIFI_SDIO_CLK", "WIFI_SDIO_CMD", "WIFI_SDIO_D0", "WIFI_SDIO_D1", "WIFI_SDIO_D2", "WIFI_SDIO_D3"; + phandle = <0x1b>; + }; + + serial@7d50c000 { + compatible = "brcm,bcm7271-uart"; + reg = <0x7d50c000 0x20>; + reg-names = "uart"; + reg-shift = <0x02>; + reg-io-width = <0x04>; + interrupts = <0x00 0x114 0x04>; + skip-init; + status = "okay"; + uart-has-rtscts; + auto-flow-control; + clock-frequency = <0x5b8d800>; + pinctrl-0 = <0x20 0x21>; + pinctrl-names = "default"; + phandle = <0x91>; + + bluetooth { + compatible = "brcm,bcm43438-bt"; + max-speed = <0x2dc6c0>; + shutdown-gpios = <0x1b 0x1d 0x00>; + local-bd-address = [00 00 00 00 00 00]; + phandle = <0x5f>; + }; + }; + + pinctrl@7d510700 { + compatible = "brcm,bcm2712d0-aon-pinctrl"; + reg = <0x7d510700 0x1c>; + phandle = <0x92>; + + i2c3_m4_agpio0_pins { + function = "vc_i2c3"; + pins = "aon_gpio0", "aon_gpio1"; + bias-pull-up; + phandle = <0x1e>; + }; + + bsc_m1_agpio13_pins { + function = "bsc_m1"; + pins = "aon_gpio13", "aon_gpio14"; + bias-pull-up; + phandle = <0x93>; + }; + + bsc_pmu_sgpio4_pins { + function = "avs_pmu_bsc"; + pins = "aon_sgpio4", "aon_sgpio5"; + phandle = <0x94>; + }; + + bsc_m2_sgpio4_pins { + function = "bsc_m2"; + pins = "aon_sgpio4", "aon_sgpio5"; + phandle = <0x95>; + }; + + pwm_aon_agpio1_pins { + function = "aon_pwm"; + pins = "aon_gpio1", "aon_gpio2"; + phandle = <0x96>; + }; + + pwm_aon_agpio4_pins { + function = "vc_pwm0"; + pins = "aon_gpio4", "aon_gpio5"; + phandle = <0x97>; + }; + + pwm_aon_agpio7_pins { + function = "aon_pwm"; + pins = "aon_gpio7", "aon_gpio9"; + phandle = <0x98>; + }; + + emmc_aon_cd_pins { + function = "sd_card_g"; + pins = "aon_gpio5"; + bias-pull-up; + phandle = <0x0a>; + }; + + aon_pwm_1pin { + function = "aon_pwm"; + pins = "aon_gpio9"; + phandle = <0x99>; + }; + }; + + intc@7d517ac0 { + compatible = "brcm,bcm7271-l2-intc"; + reg = <0x7d517ac0 0x10>; + interrupts = <0x00 0xf5 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + status = "disabled"; + phandle = <0x9a>; + }; + + avs-monitor@7d542000 { + compatible = "brcm,bcm2711-avs-monitor", "syscon", "simple-mfd"; + reg = <0x7d542000 0xf00>; + status = "okay"; + phandle = <0x9b>; + + thermal { + compatible = "brcm,bcm2711-thermal"; + #thermal-sensor-cells = <0x00>; + phandle = <0x52>; + }; + }; + + firmware { + compatible = "raspberrypi,bcm2835-firmware", "simple-mfd"; + #address-cells = <0x01>; + #size-cells = <0x01>; + mboxes = <0x22>; + dma-ranges; + phandle = <0x1a>; + + clocks { + compatible = "raspberrypi,firmware-clocks"; + #clock-cells = <0x01>; + phandle = <0x17>; + }; + + reset { + compatible = "raspberrypi,firmware-reset"; + #reset-cells = <0x01>; + phandle = <0x9c>; + }; + + vcio { + compatible = "raspberrypi,vcio"; + phandle = <0x9d>; + }; + }; + + power { + compatible = "raspberrypi,bcm2835-power"; + firmware = <0x1a>; + #power-domain-cells = <0x01>; + phandle = <0x48>; + }; + + fb { + compatible = "brcm,bcm2708-fb"; + firmware = <0x1a>; + phandle = <0x9e>; + }; + + rpi_rtc { + compatible = "raspberrypi,rpi-rtc"; + firmware = <0x1a>; + trickle-charge-microvolt = <0x00>; + phandle = <0x6d>; + }; + + nvmem { + compatible = "simple-bus"; + #address-cells = <0x01>; + #size-cells = <0x01>; + + nvmem_otp { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x1a>; + reg = <0x00 0xc0>; + phandle = <0x9f>; + }; + + nvmem_cust { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x1a>; + reg = <0x01 0x08>; + phandle = <0x68>; + }; + + nvmem_mac { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x1a>; + reg = <0x02 0x06>; + phandle = <0x69>; + }; + + nvmem_priv { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x1a>; + reg = <0x03 0x10>; + phandle = <0x6a>; + }; + }; + + fixedregulator_3v3 { + compatible = "regulator-fixed"; + regulator-always-on; + regulator-max-microvolt = <0x325aa0>; + regulator-min-microvolt = <0x325aa0>; + regulator-name = "3v3"; + phandle = <0xa0>; + }; + + fixedregulator_5v0 { + compatible = "regulator-fixed"; + regulator-always-on; + regulator-max-microvolt = <0x4c4b40>; + regulator-min-microvolt = <0x4c4b40>; + regulator-name = "5v0"; + phandle = <0xa1>; + }; + + gpiomem@7d508500 { + compatible = "raspberrypi,gpiomem"; + reg = <0x7d508500 0x40>; + chardev-name = "gpiomem1"; + }; + + gpiomem@7d517c00 { + compatible = "raspberrypi,gpiomem"; + reg = <0x7d517c00 0x40>; + chardev-name = "gpiomem2"; + }; + + gpiomem@7d504100 { + compatible = "raspberrypi,gpiomem"; + reg = <0x7d504100 0x20>; + chardev-name = "gpiomem3"; + }; + + gpiomem@7d510700 { + compatible = "raspberrypi,gpiomem"; + reg = <0x7d510700 0x20>; + chardev-name = "gpiomem4"; + }; + + sound { + status = "disabled"; + phandle = <0xa2>; + }; + }; + + axi { + compatible = "simple-bus"; + #address-cells = <0x02>; + #size-cells = <0x02>; + ranges = <0x00 0x00 0x00 0x00 0x10 0x00 0x10 0x00 0x10 0x00 0x01 0x00 0x14 0x00 0x14 0x00 0x04 0x00 0x18 0x00 0x18 0x00 0x04 0x00 0x1c 0x00 0x1c 0x00 0x04 0x00>; + dma-ranges = <0x00 0x00 0x00 0x00 0x10 0x00 0x10 0x00 0x10 0x00 0x01 0x00 0x14 0x00 0x14 0x00 0x04 0x00 0x18 0x00 0x18 0x00 0x04 0x00 0x1c 0x00 0x1c 0x00 0x04 0x00>; + phandle = <0xa3>; + + gpu { + compatible = "brcm,bcm2712d0-vc6", "brcm,bcm2712-vc6"; + status = "disabled"; + phandle = <0xa4>; + }; + + pcie@1000100000 { + compatible = "brcm,bcm2712-pcie"; + reg = <0x10 0x100000 0x00 0x9310>; + device_type = "pci"; + linux,pci-domain = <0x00>; + max-link-speed = <0x02>; + num-lanes = <0x01>; + #address-cells = <0x03>; + #interrupt-cells = <0x01>; + #size-cells = <0x02>; + interrupt-parent = <0x01>; + interrupts = <0x00 0xd5 0x04 0x00 0xd6 0x04>; + interrupt-names = "pcie", "msi"; + interrupt-map-mask = <0x00 0x00 0x00 0x07>; + interrupt-map = <0x00 0x00 0x00 0x01 0x01 0x00 0xd1 0x04 0x00 0x00 0x00 0x02 0x01 0x00 0xd2 0x04 0x00 0x00 0x00 0x03 0x01 0x00 0xd3 0x04 0x00 0x00 0x00 0x04 0x01 0x00 0xd4 0x04>; + resets = <0x23 0x24 0x2a>; + reset-names = "rescal", "bridge"; + msi-controller; + msi-parent = <0x25>; + ranges = <0x2000000 0x00 0x00 0x17 0x00 0x00 0xfffffffc 0x43000000 0x04 0x00 0x14 0x00 0x03 0x00>; + dma-ranges = <0x43000000 0x10 0x00 0x00 0x00 0x10 0x00>; + status = "disabled"; + phandle = <0x25>; + }; + + pcie@1000110000 { + compatible = "brcm,bcm2712-pcie"; + reg = <0x10 0x110000 0x00 0x9310>; + device_type = "pci"; + linux,pci-domain = <0x01>; + max-link-speed = <0x02>; + num-lanes = <0x01>; + #address-cells = <0x03>; + #interrupt-cells = <0x01>; + #size-cells = <0x02>; + interrupt-parent = <0x01>; + interrupts = <0x00 0xdf 0x04 0x00 0xe0 0x04>; + interrupt-names = "pcie", "msi"; + interrupt-map-mask = <0x00 0x00 0x00 0x07>; + interrupt-map = <0x00 0x00 0x00 0x01 0x01 0x00 0xdb 0x04 0x00 0x00 0x00 0x02 0x01 0x00 0xdc 0x04 0x00 0x00 0x00 0x03 0x01 0x00 0xdd 0x04 0x00 0x00 0x00 0x04 0x01 0x00 0xde 0x04>; + resets = <0x23 0x24 0x2b>; + reset-names = "rescal", "bridge"; + msi-controller; + msi-parent = <0x26>; + ranges = <0x2000000 0x00 0x80000000 0x1b 0x80000000 0x00 0x80000000 0x43000000 0x04 0x00 0x18 0x00 0x03 0x80000000>; + dma-ranges = <0x3000000 0x10 0x00 0x00 0x00 0x10 0x00 0x3000000 0xff 0xfffff000 0x10 0x131000 0x00 0x1000>; + status = "disabled"; + brcm,fifo-qos-map = <0x3030303>; + brcm,clkreq-mode = "safe"; + phandle = <0x67>; + }; + + pcie@1000120000 { + compatible = "brcm,bcm2712-pcie"; + reg = <0x10 0x120000 0x00 0x9310>; + device_type = "pci"; + linux,pci-domain = <0x02>; + max-link-speed = <0x02>; + num-lanes = <0x04>; + #address-cells = <0x03>; + #interrupt-cells = <0x01>; + #size-cells = <0x02>; + interrupt-parent = <0x01>; + interrupts = <0x00 0xe9 0x04 0x00 0xea 0x04>; + interrupt-names = "pcie", "msi"; + interrupt-map-mask = <0x00 0x00 0x00 0x07>; + interrupt-map = <0x00 0x00 0x00 0x01 0x01 0x00 0xe5 0x04 0x00 0x00 0x00 0x02 0x01 0x00 0xe6 0x04 0x00 0x00 0x00 0x03 0x01 0x00 0xe7 0x04 0x00 0x00 0x00 0x04 0x01 0x00 0xe8 0x04>; + resets = <0x23 0x24 0x2c>; + reset-names = "rescal", "bridge"; + msi-controller; + msi-parent = <0x27>; + ranges = <0x2000000 0x00 0x00 0x1f 0x00 0x00 0xfffffffc 0x43000000 0x04 0x00 0x1c 0x00 0x03 0x00>; + dma-ranges = <0x2000000 0x00 0x00 0x1f 0x00 0x00 0x400000 0x43000000 0x10 0x00 0x00 0x00 0x10 0x00 0x3000000 0xff 0xfffff000 0x10 0x130000 0x00 0x1000>; + status = "okay"; + brcm,vdm-qos-map = <0x8080809 0xa0a0b0b>; + aspm-no-l0s; + phandle = <0xa5>; + + rp1 { + compatible = "simple-bus"; + #address-cells = <0x02>; + #size-cells = <0x02>; + #interrupt-cells = <0x02>; + interrupt-controller; + interrupt-parent = <0x28>; + ranges = <0xc0 0x40000000 0x2000000 0x00 0x00 0x00 0x410000>; + dma-ranges = <0x10 0x00 0x43000000 0x10 0x00 0x10 0x00 0xc0 0x40000000 0x2000000 0x00 0x00 0x00 0x410000 0x00 0x00 0x2000000 0x10 0x00 0x10 0x00>; + phandle = <0x28>; + + mailbox@8000 { + compatible = "raspberrypi,rp1-mbox"; + status = "okay"; + reg = <0xc0 0x40008000 0x00 0x4000>; + interrupts = <0x3a 0x04>; + #mbox-cells = <0x01>; + phandle = <0x5b>; + }; + + clocks@18000 { + compatible = "raspberrypi,rp1-clocks"; + #clock-cells = <0x01>; + reg = <0xc0 0x40018000 0x00 0x10038>; + clocks = <0x29>; + assigned-clocks = <0x02 0x00 0x02 0x01 0x02 0x03 0x02 0x09 0x02 0x10 0x02 0x04 0x02 0x0a 0x02 0x0c 0x02 0x06 0x02 0x0d 0x02 0x1f 0x02 0x20 0x02 0x1d>; + assigned-clock-rates = <0x3b9aca00 0x5b8d8000 0xbebc200 0x7735940 0x7735940 0x3a98000 0x927c000 0xbebc200 0x5f5e100 0x2faf080 0xf4240 0xbebc200 0x2faf080>; + phandle = <0x02>; + }; + + serial@30000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40030000 0x00 0x100>; + interrupts = <0x19 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + pinctrl-0 = <0x2a>; + phandle = <0x70>; + }; + + serial@34000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40034000 0x00 0x100>; + interrupts = <0x2a 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xa6>; + }; + + serial@38000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40038000 0x00 0x100>; + interrupts = <0x2b 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xa7>; + }; + + serial@3c000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x4003c000 0x00 0x100>; + interrupts = <0x2c 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xa8>; + }; + + serial@40000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40040000 0x00 0x100>; + interrupts = <0x2d 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xa9>; + }; + + serial@44000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40044000 0x00 0x100>; + interrupts = <0x2e 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xaa>; + }; + + spi@4c000 { + reg = <0xc0 0x4004c000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x38 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2b 0x37 0x2b 0x36>; + dma-names = "tx", "rx"; + status = "disabled"; + phandle = <0xab>; + }; + + spi@50000 { + reg = <0xc0 0x40050000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x13 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2b 0x0d 0x2b 0x0c>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x2c 0x2d>; + cs-gpios = <0x2e 0x08 0x01 0x2e 0x07 0x01>; + phandle = <0x6e>; + + spidev@0 { + compatible = "spidev"; + reg = <0x00>; + #address-cells = <0x01>; + #size-cells = <0x00>; + spi-max-frequency = <0x7735940>; + phandle = <0xac>; + }; + + spidev@1 { + compatible = "spidev"; + reg = <0x01>; + #address-cells = <0x01>; + #size-cells = <0x00>; + spi-max-frequency = <0x7735940>; + phandle = <0xad>; + }; + }; + + spi@54000 { + reg = <0xc0 0x40054000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x14 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2b 0x0f 0x2b 0x0e>; + dma-names = "tx", "rx"; + status = "disabled"; + phandle = <0xae>; + }; + + spi@58000 { + reg = <0xc0 0x40058000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x15 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2b 0x11 0x2b 0x10>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x2f>; + phandle = <0xaf>; + }; + + spi@5c000 { + reg = <0xc0 0x4005c000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x16 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2b 0x13 0x2b 0x12>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x30>; + phandle = <0xb0>; + }; + + spi@60000 { + reg = <0xc0 0x40060000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x17 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x00>; + #size-cells = <0x00>; + num-cs = <0x01>; + spi-slave; + dmas = <0x2b 0x15 0x2b 0x14>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x31>; + phandle = <0xb1>; + + slave { + compatible = "spidev"; + spi-max-frequency = <0xf4240>; + }; + }; + + spi@64000 { + reg = <0xc0 0x40064000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x18 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2b 0x17 0x2b 0x16>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x32>; + phandle = <0xb2>; + }; + + spi@68000 { + reg = <0xc0 0x40068000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x36 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2b 0x33 0x2b 0x32>; + dma-names = "tx", "rx"; + status = "disabled"; + phandle = <0xb3>; + }; + + spi@6c000 { + reg = <0xc0 0x4006c000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x37 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x00>; + #size-cells = <0x00>; + num-cs = <0x01>; + spi-slave; + dmas = <0x2b 0x35 0x2b 0x34>; + dma-names = "tx", "rx"; + status = "disabled"; + phandle = <0xb4>; + + slave { + compatible = "spidev"; + spi-max-frequency = <0xf4240>; + }; + }; + + i2c@70000 { + reg = <0xc0 0x40070000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x07 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-0 = <0x33>; + pinctrl-names = "default"; + clock-frequency = <0x186a0>; + phandle = <0x66>; + }; + + i2c@74000 { + reg = <0xc0 0x40074000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x08 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x34>; + clock-frequency = <0x186a0>; + phandle = <0x63>; + }; + + i2c@78000 { + reg = <0xc0 0x40078000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x09 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x35>; + phandle = <0xb5>; + }; + + i2c@7c000 { + reg = <0xc0 0x4007c000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x0a 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x36>; + phandle = <0xb6>; + }; + + i2c@80000 { + reg = <0xc0 0x40080000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x0b 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-0 = <0x37>; + pinctrl-names = "default"; + clock-frequency = <0x186a0>; + symlink = "i2c-4"; + phandle = <0x64>; + }; + + i2c@84000 { + reg = <0xc0 0x40084000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x0c 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + phandle = <0xb7>; + }; + + i2c@88000 { + reg = <0xc0 0x40088000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x0d 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-0 = <0x38>; + pinctrl-names = "default"; + clock-frequency = <0x186a0>; + symlink = "i2c-6"; + phandle = <0x65>; + }; + + audio_out@94000 { + compatible = "raspberrypi,rp1-audio-out"; + reg = <0xc0 0x40094000 0x00 0x4000>; + clocks = <0x02 0x14>; + assigned-clocks = <0x02 0x14>; + assigned-clock-rates = <0x927c000>; + assigned-clock-parents = <0x02 0x0a>; + dmas = <0x2b 0x1d>; + dma-maxburst = <0x04>; + dma-names = "tx"; + #sound-dai-cells = <0x00>; + status = "disabled"; + phandle = <0xb8>; + }; + + pwm@98000 { + compatible = "raspberrypi,rp1-pwm"; + reg = <0xc0 0x40098000 0x00 0x100>; + #pwm-cells = <0x03>; + clocks = <0x02 0x11>; + assigned-clocks = <0x02 0x11>; + assigned-clock-rates = <0x2faf080>; + status = "disabled"; + phandle = <0xb9>; + }; + + pwm@9c000 { + compatible = "raspberrypi,rp1-pwm"; + reg = <0xc0 0x4009c000 0x00 0x100>; + #pwm-cells = <0x03>; + clocks = <0x02 0x12>; + assigned-clocks = <0x02 0x12>; + assigned-clock-rates = <0x2faf080>; + status = "disabled"; + pinctrl-0 = <0x39>; + pinctrl-names = "default"; + phandle = <0x61>; + }; + + i2s@a0000 { + reg = <0xc0 0x400a0000 0x00 0x1000>; + compatible = "snps,designware-i2s"; + clocks = <0x02 0x15>; + clock-names = "i2sclk"; + #sound-dai-cells = <0x00>; + dmas = <0x2b 0x20 0x2b 0x1f>; + dma-names = "tx", "rx"; + dma-maxburst = <0x04>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x3a>; + phandle = <0xba>; + }; + + i2s@a4000 { + reg = <0xc0 0x400a4000 0x00 0x1000>; + compatible = "snps,designware-i2s"; + clocks = <0x02 0x15>; + clock-names = "i2sclk"; + #sound-dai-cells = <0x00>; + dmas = <0x2b 0x22 0x2b 0x21>; + dma-names = "tx", "rx"; + dma-maxburst = <0x04>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x3b>; + phandle = <0xbb>; + }; + + i2s@a8000 { + reg = <0xc0 0x400a8000 0x00 0x1000>; + compatible = "snps,designware-i2s"; + clocks = <0x02 0x15>; + status = "disabled"; + phandle = <0xbc>; + }; + + sdio_clk0@b0004 { + compatible = "raspberrypi,rp1-sdio-clk"; + reg = <0xc0 0x400b0004 0x00 0x1c>; + clocks = <0x3c 0x3d>; + clock-names = "src", "base"; + #clock-cells = <0x00>; + status = "disabled"; + phandle = <0x42>; + }; + + sdio_clk1@b4004 { + compatible = "raspberrypi,rp1-sdio-clk"; + reg = <0xc0 0x400b4004 0x00 0x1c>; + clocks = <0x3c 0x3d>; + clock-names = "src", "base"; + #clock-cells = <0x00>; + status = "disabled"; + phandle = <0x43>; + }; + + adc@c8000 { + compatible = "raspberrypi,rp1-adc"; + reg = <0xc0 0x400c8000 0x00 0x4000>; + clocks = <0x02 0x1e>; + clock-names = "adcclk"; + #clock-cells = <0x00>; + vref-supply = <0x3e>; + status = "okay"; + phandle = <0xbd>; + }; + + gpio@d0000 { + reg = <0xc0 0x400d0000 0x00 0xc000 0xc0 0x400e0000 0x00 0xc000 0xc0 0x400f0000 0x00 0xc000>; + compatible = "raspberrypi,rp1-gpio"; + interrupts = <0x00 0x04 0x01 0x04 0x02 0x04>; + gpio-controller; + #gpio-cells = <0x02>; + interrupt-controller; + #interrupt-cells = <0x02>; + gpio-ranges = <0x2e 0x00 0x00 0x36>; + status = "okay"; + gpio-line-names = "ID_SDA", "ID_SCL", "GPIO2", "GPIO3", "GPIO4", "GPIO5", "GPIO6", "GPIO7", "GPIO8", "GPIO9", "GPIO10", "GPIO11", "GPIO12", "GPIO13", "GPIO14", "GPIO15", "GPIO16", "GPIO17", "GPIO18", "GPIO19", "GPIO20", "GPIO21", "GPIO22", "GPIO23", "GPIO24", "GPIO25", "GPIO26", "GPIO27", "PCIE_RP1_WAKE", "FAN_TACH", "HOST_SDA", "HOST_SCL", "ETH_RST_N", "-", "CD0_IO0_MICCLK", "CD0_IO0_MICDAT0", "RP1_PCIE_CLKREQ_N", "-", "CD0_SDA", "CD0_SCL", "CD1_SDA", "CD1_SCL", "USB_VBUS_EN", "USB_OC_N", "RP1_STAT_LED", "FAN_PWM", "CD1_IO0_MICCLK", "2712_WAKE", "CD1_IO1_MICDAT1", "EN_MAX_USB_CUR", "-", "-", "-", "-"; + phandle = <0x2e>; + + rp1_uart0_14_15 { + phandle = <0x2a>; + + pin_txd { + function = "uart0"; + pins = "gpio14"; + bias-disable; + }; + + pin_rxd { + function = "uart0"; + pins = "gpio15"; + bias-pull-up; + }; + }; + + rp1_uart0_ctsrts_16_17 { + phandle = <0xbe>; + + pin_cts { + function = "uart0"; + pins = "gpio16"; + bias-pull-up; + }; + + pin_rts { + function = "uart0"; + pins = "gpio17"; + bias-disable; + }; + }; + + rp1_uart1_0_1 { + phandle = <0xbf>; + + pin_txd { + function = "uart1"; + pins = "gpio0"; + bias-disable; + }; + + pin_rxd { + function = "uart1"; + pins = "gpio1"; + bias-pull-up; + }; + }; + + rp1_uart1_ctsrts_2_3 { + phandle = <0xc0>; + + pin_cts { + function = "uart1"; + pins = "gpio2"; + bias-pull-up; + }; + + pin_rts { + function = "uart1"; + pins = "gpio3"; + bias-disable; + }; + }; + + rp1_uart2_4_5 { + phandle = <0xc1>; + + pin_txd { + function = "uart2"; + pins = "gpio4"; + bias-disable; + }; + + pin_rxd { + function = "uart2"; + pins = "gpio5"; + bias-pull-up; + }; + }; + + rp1_uart2_ctsrts_6_7 { + phandle = <0xc2>; + + pin_cts { + function = "uart2"; + pins = "gpio6"; + bias-pull-up; + }; + + pin_rts { + function = "uart2"; + pins = "gpio7"; + bias-disable; + }; + }; + + rp1_uart3_8_9 { + phandle = <0xc3>; + + pin_txd { + function = "uart3"; + pins = "gpio8"; + bias-disable; + }; + + pin_rxd { + function = "uart3"; + pins = "gpio9"; + bias-pull-up; + }; + }; + + rp1_uart3_ctsrts_10_11 { + phandle = <0xc4>; + + pin_cts { + function = "uart3"; + pins = "gpio10"; + bias-pull-up; + }; + + pin_rts { + function = "uart3"; + pins = "gpio11"; + bias-disable; + }; + }; + + rp1_uart4_12_13 { + phandle = <0xc5>; + + pin_txd { + function = "uart4"; + pins = "gpio12"; + bias-disable; + }; + + pin_rxd { + function = "uart4"; + pins = "gpio13"; + bias-pull-up; + }; + }; + + rp1_uart4_ctsrts_14_15 { + phandle = <0xc6>; + + pin_cts { + function = "uart4"; + pins = "gpio14"; + bias-pull-up; + }; + + pin_rts { + function = "uart4"; + pins = "gpio15"; + bias-disable; + }; + }; + + rp1_sdio0_22_27 { + phandle = <0xc7>; + + pin_clk { + function = "sd0"; + pins = "gpio22"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + + pin_cmd { + function = "sd0"; + pins = "gpio23"; + bias-pull-up; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + + pins_dat { + function = "sd0"; + pins = "gpio24", "gpio25", "gpio26", "gpio27"; + bias-pull-up; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + }; + + rp1_sdio1_28_33 { + phandle = <0xc8>; + + pin_clk { + function = "sd1"; + pins = "gpio28"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + + pin_cmd { + function = "sd1"; + pins = "gpio29"; + bias-pull-up; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + + pins_dat { + function = "sd1"; + pins = "gpio30", "gpio31", "gpio32", "gpio33"; + bias-pull-up; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + }; + + rp1_i2s0_18_21 { + function = "i2s0"; + pins = "gpio18", "gpio19", "gpio20", "gpio21"; + bias-disable; + phandle = <0x3a>; + }; + + rp1_i2s1_18_21 { + function = "i2s1"; + pins = "gpio18", "gpio19", "gpio20", "gpio21"; + bias-disable; + phandle = <0x3b>; + }; + + rp1_i2c4_34_35 { + function = "i2c4"; + pins = "gpio34", "gpio35"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xc9>; + }; + + rp1_i2c6_38_39 { + function = "i2c6"; + pins = "gpio38", "gpio39"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x38>; + }; + + rp1_i2c4_40_41 { + function = "i2c4"; + pins = "gpio40", "gpio41"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x37>; + }; + + rp1_i2c5_44_45 { + function = "i2c5"; + pins = "gpio44", "gpio45"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xca>; + }; + + rp1_i2c0_0_1 { + function = "i2c0"; + pins = "gpio0", "gpio1"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x33>; + }; + + rp1_i2c0_8_9 { + function = "i2c0"; + pins = "gpio8", "gpio9"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xcb>; + }; + + rp1_i2c1_2_3 { + function = "i2c1"; + pins = "gpio2", "gpio3"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x34>; + }; + + rp1_i2c1_10_11 { + function = "i2c1"; + pins = "gpio10", "gpio11"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xcc>; + }; + + rp1_i2c2_4_5 { + function = "i2c2"; + pins = "gpio4", "gpio5"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x35>; + }; + + rp1_i2c2_12_13 { + function = "i2c2"; + pins = "gpio12", "gpio13"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xcd>; + }; + + rp1_i2c3_6_7 { + function = "i2c3"; + pins = "gpio6", "gpio7"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x36>; + }; + + rp1_i2c3_14_15 { + function = "i2c3"; + pins = "gpio14", "gpio15"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xce>; + }; + + rp1_i2c3_22_23 { + function = "i2c3"; + pins = "gpio22", "gpio23"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xcf>; + }; + + rp1_dpi_16bit_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19"; + bias-disable; + phandle = <0xd0>; + }; + + rp1_dpi_16bit_cpadhi_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24"; + bias-disable; + phandle = <0xd1>; + }; + + rp1_dpi_16bit_pad666_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25"; + bias-disable; + phandle = <0xd2>; + }; + + rp1_dpi_18bit_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21"; + bias-disable; + phandle = <0xd3>; + }; + + rp1_dpi_18bit_cpadhi_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25"; + bias-disable; + phandle = <0xd4>; + }; + + rp1_dpi_24bit_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25", "gpio26", "gpio27"; + bias-disable; + phandle = <0xd5>; + }; + + rp1_dpi_hvsync { + function = "dpi"; + pins = "gpio2", "gpio3"; + bias-disable; + phandle = <0xd6>; + }; + + rp1_dpi_16bit_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19"; + bias-disable; + phandle = <0xd7>; + }; + + rp1_dpi_16bit_cpadhi_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24"; + bias-disable; + phandle = <0xd8>; + }; + + rp1_dpi_16bit_pad666_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25"; + bias-disable; + phandle = <0xd9>; + }; + + rp1_dpi_18bit_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21"; + bias-disable; + phandle = <0xda>; + }; + + rp1_dpi_18bit_cpadhi_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25"; + bias-disable; + phandle = <0xdb>; + }; + + rp1_dpi_24bit_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25", "gpio26", "gpio27"; + bias-disable; + phandle = <0xdc>; + }; + + rp1_gpclksrc0_gpio4 { + function = "gpclk0"; + pins = "gpio4"; + bias-disable; + phandle = <0xdd>; + }; + + rp1_gpclksrc0_gpio20 { + function = "gpclk0"; + pins = "gpio20"; + bias-disable; + phandle = <0xde>; + }; + + rp1_gpclksrc1_gpio5 { + function = "gpclk1"; + pins = "gpio5"; + bias-disable; + phandle = <0xdf>; + }; + + rp1_gpclksrc1_gpio18 { + function = "gpclk1"; + pins = "gpio18"; + bias-disable; + phandle = <0xe0>; + }; + + rp1_gpclksrc1_gpio21 { + function = "gpclk1"; + pins = "gpio21"; + bias-disable; + phandle = <0xe1>; + }; + + rp1_pwm1_gpio45 { + function = "pwm1"; + pins = "gpio45"; + bias-pull-down; + phandle = <0x39>; + }; + + rp1_spi0_gpio9 { + function = "spi0"; + pins = "gpio9", "gpio10", "gpio11"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x2c>; + }; + + rp1_spi0_cs_gpio7 { + function = "spi0"; + pins = "gpio7", "gpio8"; + bias-pull-up; + phandle = <0x2d>; + }; + + rp1_spi1_gpio19 { + function = "spi1"; + pins = "gpio19", "gpio20", "gpio21"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0xe2>; + }; + + rp1_spi2_gpio1 { + function = "spi2"; + pins = "gpio1", "gpio2", "gpio3"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x2f>; + }; + + rp1_spi3_gpio5 { + function = "spi3"; + pins = "gpio5", "gpio6", "gpio7"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x30>; + }; + + rp1_spi4_gpio9 { + function = "spi4"; + pins = "gpio9", "gpio10", "gpio11"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x31>; + }; + + rp1_spi5_gpio13 { + function = "spi5"; + pins = "gpio13", "gpio14", "gpio15"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x32>; + }; + + rp1_spi8_gpio49 { + function = "spi8"; + pins = "gpio49", "gpio50", "gpio51"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0xe3>; + }; + + rp1_spi8_cs_gpio52 { + function = "spi0"; + pins = "gpio52", "gpio53"; + bias-pull-up; + phandle = <0xe4>; + }; + + rp1_audio_out_12_13 { + function = "aaud"; + pins = "gpio12", "gpio13"; + bias-disable; + phandle = <0xe5>; + }; + + usb_vbus_pins { + function = "vbus1"; + pins = "gpio42", "gpio43"; + phandle = <0x44>; + }; + }; + + ethernet@100000 { + reg = <0xc0 0x40100000 0x00 0x4000>; + compatible = "raspberrypi,rp1-gem", "cdns,macb"; + #address-cells = <0x01>; + #size-cells = <0x00>; + interrupts = <0x06 0x04>; + clocks = <0x02 0x0c 0x02 0x0c 0x02 0x1d 0x02 0x10>; + clock-names = "pclk", "hclk", "tsu_clk", "tx_clk"; + phy-mode = "rgmii-id"; + cdns,aw2w-max-pipe = [08]; + cdns,ar2r-max-pipe = [08]; + cdns,use-aw2b-fill; + local-mac-address = [00 00 00 00 00 00]; + status = "okay"; + phy-handle = <0x3f>; + phy-reset-gpios = <0x2e 0x20 0x01>; + phy-reset-duration = <0x05>; + phandle = <0xe6>; + + ethernet-phy@1 { + reg = <0x01>; + brcm,powerdown-enable; + eee-broken-1000t; + eee-broken-100tx; + phandle = <0x3f>; + }; + }; + + csi@110000 { + compatible = "raspberrypi,rp1-cfe"; + reg = <0xc0 0x40110000 0x00 0x100 0xc0 0x40114000 0x00 0x100 0xc0 0x40120000 0x00 0x100 0xc0 0x40124000 0x00 0x1000>; + interrupts = <0x2f 0x04>; + clocks = <0x02 0x16>; + assigned-clocks = <0x02 0x16>; + assigned-clock-rates = <0x17d7840>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + iommus = <0x40>; + phandle = <0xe7>; + }; + + csi@128000 { + compatible = "raspberrypi,rp1-cfe"; + reg = <0xc0 0x40128000 0x00 0x100 0xc0 0x4012c000 0x00 0x100 0xc0 0x40138000 0x00 0x100 0xc0 0x4013c000 0x00 0x1000>; + interrupts = <0x30 0x04>; + clocks = <0x02 0x17>; + assigned-clocks = <0x02 0x17>; + assigned-clock-rates = <0x17d7840>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + iommus = <0x40>; + phandle = <0xe8>; + }; + + pio@178000 { + reg = <0xc0 0x40178000 0x00 0x20>; + compatible = "raspberrypi,rp1-pio"; + firmware = <0x41>; + dmas = <0x2b 0x38 0x2b 0x39 0x2b 0x3a 0x2b 0x3b 0x2b 0x3c 0x2b 0x3d 0x2b 0x3e 0x2b 0x3f>; + dma-names = "tx0", "rx0", "tx1", "rx1", "tx2", "rx2", "tx3", "rx3"; + status = "okay"; + phandle = <0xe9>; + }; + + mmc@180000 { + reg = <0xc0 0x40180000 0x00 0x100>; + compatible = "raspberrypi,rp1-dwcmshc"; + interrupts = <0x11 0x04>; + clocks = <0x02 0x0c 0x3d 0x02 0x1f 0x42>; + clock-names = "bus", "core", "timeout", "sdio"; + no-1-8-v; + bus-width = <0x04>; + vmmc-supply = <0x3e>; + broken-cd; + status = "disabled"; + phandle = <0xea>; + }; + + mmc@184000 { + reg = <0xc0 0x40184000 0x00 0x100>; + compatible = "raspberrypi,rp1-dwcmshc"; + interrupts = <0x12 0x04>; + clocks = <0x02 0x0c 0x3d 0x02 0x1f 0x43>; + clock-names = "bus", "core", "timeout", "sdio"; + bus-width = <0x04>; + vmmc-supply = <0x3e>; + sdhci-caps-mask = <0x03 0x00>; + broken-cd; + status = "disabled"; + phandle = <0xeb>; + }; + + dma@188000 { + reg = <0xc0 0x40188000 0x00 0x1000>; + compatible = "snps,axi-dma-1.01a"; + interrupts = <0x28 0x04>; + clocks = <0x02 0x0e 0x02 0x0c>; + clock-names = "core-clk", "cfgr-clk"; + #dma-cells = <0x01>; + dma-channels = <0x08>; + snps,dma-masters = <0x01>; + snps,dma-targets = <0x40>; + snps,data-width = <0x04>; + snps,block-size = <0x40000 0x40000 0x40000 0x40000 0x40000 0x40000 0x40000 0x40000>; + snps,priority = <0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07>; + snps,axi-max-burst-len = <0x04>; + status = "okay"; + phandle = <0x2b>; + }; + + usb@200000 { + reg = <0xc0 0x40200000 0x00 0x100000>; + compatible = "snps,dwc3"; + dr_mode = "host"; + usb3-lpm-capable; + snps,axi-pipe-limit = [08]; + snps,dis_rxdet_inp3_quirk; + snps,enhanced-nak-fs-quirk; + snps,parkmode-disable-ss-quirk; + snps,parkmode-disable-hs-quirk; + snps,parkmode-disable-fsls-quirk; + snps,tx-max-burst = [08]; + snps,tx-thr-num-pkt = [02]; + interrupts = <0x1f 0x01>; + status = "okay"; + pinctrl-0 = <0x44>; + pinctrl-names = "default"; + phandle = <0xec>; + }; + + usb@300000 { + reg = <0xc0 0x40300000 0x00 0x100000>; + compatible = "snps,dwc3"; + dr_mode = "host"; + usb3-lpm-capable; + snps,axi-pipe-limit = [08]; + snps,dis_rxdet_inp3_quirk; + snps,enhanced-nak-fs-quirk; + snps,parkmode-disable-ss-quirk; + snps,parkmode-disable-hs-quirk; + snps,parkmode-disable-fsls-quirk; + snps,tx-max-burst = [08]; + snps,tx-thr-num-pkt = [02]; + interrupts = <0x24 0x01>; + status = "okay"; + phandle = <0xed>; + }; + + dsi@110000 { + compatible = "raspberrypi,rp1dsi"; + status = "disabled"; + reg = <0xc0 0x40118000 0x00 0x1000 0xc0 0x4011c000 0x00 0x1000 0xc0 0x40120000 0x00 0x1000>; + interrupts = <0x2f 0x04>; + clocks = <0x02 0x16 0x02 0x29 0x02 0x2d 0x29 0x02 0x03>; + clock-names = "cfgclk", "dpiclk", "byteclk", "refclk", "pllsys"; + assigned-clocks = <0x02 0x16>; + assigned-clock-rates = <0x17d7840>; + iommus = <0x40>; + phandle = <0xee>; + }; + + dsi@128000 { + compatible = "raspberrypi,rp1dsi"; + status = "disabled"; + reg = <0xc0 0x40130000 0x00 0x1000 0xc0 0x40134000 0x00 0x1000 0xc0 0x40138000 0x00 0x1000>; + interrupts = <0x30 0x04>; + clocks = <0x02 0x17 0x02 0x2a 0x02 0x2e 0x29 0x02 0x03>; + clock-names = "cfgclk", "dpiclk", "byteclk", "refclk", "pllsys"; + assigned-clocks = <0x02 0x17>; + assigned-clock-rates = <0x17d7840>; + iommus = <0x40>; + phandle = <0xef>; + }; + + vec@144000 { + compatible = "raspberrypi,rp1vec"; + status = "disabled"; + reg = <0xc0 0x40144000 0x00 0x1000 0xc0 0x40140000 0x00 0x1000>; + interrupts = <0x31 0x04>; + clocks = <0x02 0x27>; + assigned-clocks = <0x02 0x02 0x02 0x0b 0x02 0x27>; + assigned-clock-rates = <0x46cf7100 0x66ff300 0x66ff300>; + assigned-clock-parents = <0x00 0x02 0x02 0x02 0x0b>; + iommus = <0x40>; + phandle = <0xf0>; + }; + + dpi@148000 { + compatible = "raspberrypi,rp1dpi"; + status = "disabled"; + reg = <0xc0 0x40148000 0x00 0x1000 0xc0 0x40140000 0x00 0x1000>; + interrupts = <0x31 0x04>; + clocks = <0x02 0x28 0x02 0x05 0x02 0x02>; + clock-names = "dpiclk", "plldiv", "pllcore"; + assigned-clocks = <0x02 0x28>; + assigned-clock-parents = <0x02 0x05>; + iommus = <0x40>; + phandle = <0xf1>; + }; + + sram@400000 { + compatible = "mmio-sram"; + reg = <0xc0 0x40400000 0x00 0x10000>; + #address-cells = <0x01>; + #size-cells = <0x01>; + ranges = <0x00 0xc0 0x40400000 0x10000>; + phandle = <0xf2>; + + shmem@ff00 { + compatible = "raspberrypi,rp1-shmem"; + reg = <0xff00 0x100>; + phandle = <0x5c>; + }; + }; + + gpiomem@d0000 { + compatible = "raspberrypi,gpiomem"; + reg = <0xc0 0x400d0000 0x00 0x30000>; + chardev-name = "gpiomem0"; + }; + }; + }; + + msi-controller@1000130000 { + compatible = "brcm,bcm2712-mip"; + reg = <0x10 0x130000 0x00 0xc0 0xff 0xfffff000 0x00 0x1000>; + msi-controller; + msi-ranges = <0x01 0x00 0x80 0x01 0x40>; + brcm,msi-offset = <0x00>; + phandle = <0x27>; + }; + + msi-controller@1000131000 { + compatible = "brcm,bcm2712-mip"; + reg = <0x10 0x131000 0x00 0xc0 0xff 0xfffff000 0x00 0x1000>; + msi-controller; + msi-ranges = <0x01 0x00 0xf7 0x01 0x08>; + brcm,msi-offset = <0x08>; + phandle = <0x26>; + }; + + iommu@5100 { + compatible = "brcm,bcm2712-iommu"; + reg = <0x10 0x5100 0x00 0x80>; + cache = <0x45>; + #iommu-cells = <0x00>; + phandle = <0x49>; + }; + + iommu@5200 { + compatible = "brcm,bcm2712-iommu"; + reg = <0x10 0x5200 0x00 0x80>; + cache = <0x45>; + #iommu-cells = <0x00>; + #interconnect-cells = <0x00>; + phandle = <0x4d>; + }; + + iommu@5280 { + compatible = "brcm,bcm2712-iommu"; + reg = <0x10 0x5280 0x00 0x80>; + cache = <0x45>; + #iommu-cells = <0x00>; + dma-iova-offset = <0x10 0x00>; + phandle = <0x40>; + }; + + iommuc@5b00 { + compatible = "brcm,bcm2712-iommuc"; + reg = <0x10 0x5b00 0x00 0x80>; + phandle = <0x45>; + }; + + dma@10000 { + compatible = "brcm,bcm2712-dma"; + reg = <0x10 0x10000 0x00 0x600>; + interrupts = <0x00 0x50 0x04 0x00 0x51 0x04 0x00 0x52 0x04 0x00 0x53 0x04 0x00 0x54 0x04 0x00 0x55 0x04>; + interrupt-names = "dma0", "dma1", "dma2", "dma3", "dma4", "dma5"; + #dma-cells = <0x01>; + brcm,dma-channel-mask = <0x3f>; + phandle = <0xf3>; + }; + + dma@10600 { + compatible = "brcm,bcm2712-dma"; + reg = <0x10 0x10600 0x00 0x600>; + interrupts = <0x00 0x56 0x04 0x00 0x57 0x04 0x00 0x58 0x04 0x00 0x59 0x04 0x00 0x5a 0x04 0x00 0x5b 0x04>; + interrupt-names = "dma6", "dma7", "dma8", "dma9", "dma10", "dma11"; + #dma-cells = <0x01>; + brcm,dma-channel-mask = <0x7c0>; + phandle = <0x16>; + }; + + syscon@400018 { + compatible = "brcm,syscon-piarbctl", "syscon", "simple-mfd"; + reg = <0x10 0x400018 0x00 0x18>; + phandle = <0xf4>; + }; + + usb@480000 { + compatible = "brcm,bcm2835-usb"; + reg = <0x10 0x480000 0x00 0x10000>; + interrupts = <0x00 0x49 0x04>; + #address-cells = <0x01>; + #size-cells = <0x00>; + clocks = <0x46>; + clock-names = "otg"; + phys = <0x47>; + phy-names = "usb2-phy"; + status = "disabled"; + power-domains = <0x48 0x06>; + phandle = <0xf5>; + }; + + codec@800000 { + compatible = "brcm,bcm2712-hevc-dec", "raspberrypi,hevc-dec"; + reg = <0x10 0x800000 0x00 0x10000 0x10 0x840000 0x00 0x1000>; + reg-names = "hevc", "intc"; + interrupts = <0x00 0x62 0x04>; + clocks = <0x17 0x0b>; + clock-names = "hevc"; + iommus = <0x49>; + phandle = <0xf6>; + }; + + pisp_be@880000 { + compatible = "raspberrypi,pispbe"; + reg = <0x10 0x880000 0x00 0x4000>; + interrupts = <0x00 0x48 0x04>; + clocks = <0x17 0x07>; + clocks-names = "isp_be"; + status = "okay"; + iommus = <0x49>; + phandle = <0xf7>; + }; + + mmc@1100000 { + compatible = "brcm,bcm2712-sdhci"; + reg = <0x10 0x1100000 0x00 0x260 0x10 0x1100400 0x00 0x200>; + reg-names = "host", "cfg"; + interrupts = <0x00 0x112 0x04>; + clocks = <0x08>; + sdhci-caps-mask = <0xc000 0x00>; + sdhci-caps = <0x00 0x00>; + supports-cqe = <0x01>; + mmc-ddr-3_3v; + status = "okay"; + pinctrl-0 = <0x4a>; + pinctrl-names = "default"; + bus-width = <0x04>; + vmmc-supply = <0x4b>; + sd-uhs-ddr50; + non-removable; + #address-cells = <0x01>; + #size-cells = <0x00>; + phandle = <0xf8>; + + wifi@1 { + reg = <0x01>; + compatible = "brcm,bcm4329-fmac"; + local-mac-address = [00 00 00 00 00 00]; + phandle = <0x71>; + }; + }; + + v3d@2000000 { + compatible = "brcm,2712-v3d"; + reg = <0x10 0x2000000 0x00 0x4000 0x10 0x2008000 0x00 0x6000 0x10 0x2030800 0x00 0x700>; + reg-names = "hub", "core0", "sms"; + power-domains = <0x4c 0x01>; + resets = <0x4c 0x00>; + clocks = <0x17 0x05>; + clocks-names = "v3d"; + interrupts = <0x00 0xfa 0x04 0x00 0xf9 0x04>; + status = "disabled"; + phandle = <0xf9>; + }; + }; + + timer { + compatible = "arm,armv8-timer"; + interrupts = <0x01 0x0d 0xf08 0x01 0x0e 0xf08 0x01 0x0b 0xf08 0x01 0x0a 0xf08 0x01 0x0c 0xf08>; + }; + + clk-27M { + #clock-cells = <0x00>; + compatible = "fixed-clock"; + clock-frequency = <0x19bfcc0>; + clock-output-names = "27MHz-clock"; + phandle = <0x18>; + }; + + clk-108M { + #clock-cells = <0x00>; + compatible = "fixed-clock"; + clock-frequency = <0x66ff300>; + clock-output-names = "108MHz-clock"; + phandle = <0x11>; + }; + + hvs@107c580000 { + compatible = "brcm,bcm2712-hvs"; + reg = <0x10 0x7c580000 0x1a000>; + interrupt-parent = <0x10>; + interrupts = <0x02 0x09 0x10>; + interrupt-names = "ch0-eof", "ch1-eof", "ch2-eof"; + iommus = <0x4d>; + status = "disabled"; + clocks = <0x17 0x04 0x17 0x10>; + clock-names = "core", "disp"; + phandle = <0xfa>; + }; + + arm-pmu { + compatible = "arm,cortex-a76-pmu"; + interrupts = <0x00 0x10 0x04 0x00 0x11 0x04 0x00 0x12 0x04 0x00 0x13 0x04>; + interrupt-affinity = <0x4e 0x4f 0x50 0x51>; + }; + + thermal-zones { + + cpu-thermal { + polling-delay-passive = <0x3e8>; + polling-delay = <0x3e8>; + coefficients = <0xfffffdda 0x6ddd0>; + thermal-sensors = <0x52>; + phandle = <0xfb>; + + trips { + phandle = <0xfc>; + + cpu-crit { + temperature = <0x1adb0>; + hysteresis = <0x00>; + type = "critical"; + phandle = <0x58>; + }; + + cpu-tepid { + temperature = <0xc350>; + hysteresis = <0x1388>; + type = "active"; + phandle = <0x53>; + }; + + cpu-warm { + temperature = <0xea60>; + hysteresis = <0x1388>; + type = "active"; + phandle = <0x55>; + }; + + cpu-hot { + temperature = <0x107ac>; + hysteresis = <0x1388>; + type = "active"; + phandle = <0x56>; + }; + + cpu-vhot { + temperature = <0x124f8>; + hysteresis = <0x1388>; + type = "active"; + phandle = <0x57>; + }; + }; + + cooling-maps { + phandle = <0xfd>; + + tepid { + trip = <0x53>; + cooling-device = <0x54 0x01 0x01>; + }; + + warm { + trip = <0x55>; + cooling-device = <0x54 0x02 0x02>; + }; + + hot { + trip = <0x56>; + cooling-device = <0x54 0x03 0x03>; + }; + + vhot { + trip = <0x57>; + cooling-device = <0x54 0x04 0x04>; + }; + + melt { + trip = <0x58>; + cooling-device = <0x54 0x04 0x04>; + }; + }; + }; + }; + + firmwarekms { + compatible = "raspberrypi,rpi-firmware-kms-2712"; + interrupt-parent = <0x59>; + interrupts = <0x13>; + brcm,firmware = <0x1a>; + status = "disabled"; + phandle = <0xfe>; + }; + + phy { + compatible = "usb-nop-xceiv"; + #phy-cells = <0x00>; + phandle = <0x47>; + }; + + memory@0 { + device_type = "memory"; + reg = <0x00 0x00 0x28000000>; + }; + + leds { + compatible = "gpio-leds"; + phandle = <0xff>; + + led-pwr { + label = "PWR"; + gpios = <0x2e 0x2c 0x01>; + default-state = "off"; + linux,default-trigger = "none"; + phandle = <0x6b>; + }; + + led-act { + label = "ACT"; + gpios = <0x0d 0x09 0x01>; + default-state = "off"; + linux,default-trigger = "mmc0"; + phandle = <0x5d>; + }; + }; + + sd-io-1v8-reg { + compatible = "regulator-gpio"; + regulator-name = "vdd-sd-io"; + regulator-min-microvolt = <0x1b7740>; + regulator-max-microvolt = <0x325aa0>; + regulator-boot-on; + regulator-always-on; + regulator-settling-time-us = <0x1388>; + gpios = <0x0d 0x03 0x00>; + states = <0x1b7740 0x01 0x325aa0 0x00>; + phandle = <0x0b>; + }; + + sd-vcc-reg { + compatible = "regulator-fixed"; + regulator-name = "vcc-sd"; + regulator-min-microvolt = <0x325aa0>; + regulator-max-microvolt = <0x325aa0>; + regulator-boot-on; + enable-active-high; + gpios = <0x0d 0x04 0x00>; + phandle = <0x0c>; + }; + + wl-on-reg { + compatible = "regulator-fixed"; + regulator-name = "wl-on-regulator"; + regulator-min-microvolt = <0x325aa0>; + regulator-max-microvolt = <0x325aa0>; + pinctrl-0 = <0x5a>; + pinctrl-names = "default"; + gpio = <0x1b 0x1c 0x00>; + startup-delay-us = <0x249f0>; + enable-active-high; + phandle = <0x4b>; + }; + + cam1_clk { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + status = "disabled"; + phandle = <0x100>; + }; + + cam0_clk { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + status = "disabled"; + phandle = <0x101>; + }; + + cam0_reg { + compatible = "regulator-fixed"; + regulator-name = "cam0_reg"; + enable-active-high; + gpio = <0x2e 0x22 0x00>; + phandle = <0x72>; + }; + + cam1_reg { + compatible = "regulator-fixed"; + regulator-name = "cam1_reg"; + enable-active-high; + gpio = <0x2e 0x2e 0x00>; + phandle = <0x73>; + }; + + cam_dummy_reg { + compatible = "regulator-fixed"; + regulator-name = "cam-dummy-reg"; + phandle = <0x102>; + }; + + dummy { + phandle = <0x103>; + }; + + i2c0if { + phandle = <0x104>; + }; + + i2c0mux { + phandle = <0x105>; + }; + + rp1_firmware { + compatible = "raspberrypi,rp1-firmware", "simple-mfd"; + mboxes = <0x5b 0x00>; + shmem = <0x5c>; + phandle = <0x41>; + }; + + rp1_vdd_3v3 { + compatible = "regulator-fixed"; + regulator-name = "vdd-3v3"; + regulator-min-microvolt = <0x325aa0>; + regulator-max-microvolt = <0x325aa0>; + regulator-always-on; + phandle = <0x3e>; + }; + + chosen { + bootargs = "reboot=w coherent_pool=1M 8250.nr_uarts=1 pci=pcie_bus_safe cgroup_disable=memory numa_policy=interleave nvme.max_host_mem_size_mb=0"; + stdout-path = "serial10:115200n8"; + phandle = <0x6f>; + }; + + aliases { + blconfig = "/reserved-memory/nvram@0"; + blpubkey = "/reserved-memory/nvram@1"; + bluetooth = "/soc@107c000000/serial@7d50c000/bluetooth"; + console = "/soc@107c000000/serial@7d001000"; + drm-dsi1 = "/axi/pcie@1000120000/rp1/dsi@110000"; + drm-dsi2 = "/axi/pcie@1000120000/rp1/dsi@128000"; + ethernet0 = "/axi/pcie@1000120000/rp1/ethernet@100000"; + fb = "/soc@107c000000/fb"; + gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000"; + gpio1 = "/soc@107c000000/gpio@7d508500"; + gpio2 = "/soc@107c000000/gpio@7d517c00"; + gpio3 = "/soc@107c000000/pinctrl@7d504100"; + gpio4 = "/soc@107c000000/pinctrl@7d510700"; + gpiochip0 = "/axi/pcie@1000120000/rp1/gpio@d0000"; + gpiochip10 = "/soc@107c000000/gpio@7d508500"; + i2c = "/axi/pcie@1000120000/rp1/i2c@74000"; + i2c0 = "/axi/pcie@1000120000/rp1/i2c@70000"; + i2c1 = "/axi/pcie@1000120000/rp1/i2c@74000"; + i2c2 = "/axi/pcie@1000120000/rp1/i2c@78000"; + i2c3 = "/axi/pcie@1000120000/rp1/i2c@7c000"; + i2c10 = "/axi/pcie@1000120000/rp1/i2c@88000"; + i2c11 = "/axi/pcie@1000120000/rp1/i2c@80000"; + i2c12 = "/soc@107c000000/i2c@7d005600"; + mailbox = "/soc@107c000000/mailbox@7c013880"; + mmc0 = "/soc@107c000000/mmc@fff000"; + pio0 = "/axi/pcie@1000120000/rp1/pio@178000"; + serial0 = "/axi/pcie@1000120000/rp1/serial@30000"; + serial1 = "/axi/pcie@1000120000/rp1/serial@34000"; + serial10 = "/soc@107c000000/serial@7d001000"; + serial2 = "/axi/pcie@1000120000/rp1/serial@38000"; + serial3 = "/axi/pcie@1000120000/rp1/serial@3c000"; + serial4 = "/axi/pcie@1000120000/rp1/serial@40000"; + spi0 = "/axi/pcie@1000120000/rp1/spi@50000"; + spi1 = "/axi/pcie@1000120000/rp1/spi@54000"; + spi10 = "/soc@107c000000/spi@7d004000"; + spi2 = "/axi/pcie@1000120000/rp1/spi@58000"; + spi3 = "/axi/pcie@1000120000/rp1/spi@5c000"; + spi4 = "/axi/pcie@1000120000/rp1/spi@60000"; + spi5 = "/axi/pcie@1000120000/rp1/spi@64000"; + uart0 = "/axi/pcie@1000120000/rp1/serial@30000"; + uart1 = "/axi/pcie@1000120000/rp1/serial@34000"; + uart10 = "/soc@107c000000/serial@7d001000"; + uart2 = "/axi/pcie@1000120000/rp1/serial@38000"; + uart3 = "/axi/pcie@1000120000/rp1/serial@3c000"; + uart4 = "/axi/pcie@1000120000/rp1/serial@40000"; + usb0 = "/axi/pcie@1000120000/rp1/usb@200000"; + usb1 = "/axi/pcie@1000120000/rp1/usb@300000"; + wifi0 = "/axi/mmc@1100000/wifi@1"; + phandle = <0x62>; + }; + + __overrides__ { + act_led_gpio = [00 00 00 5d 67 70 69 6f 73 3a 34 00 00 00 00 5d 67 70 69 6f 73 3a 30 3d 00 00 00 00 2e]; + act_led_activelow = "", "", "", "]gpios:8"; + act_led_trigger = "", "", "", "]linux,default-trigger"; + axiperf = "", "", "", "^status"; + bdaddr = "", "", "", "_local-bd-address["; + button_debounce = "", "", "", "`debounce-interval:0"; + cooling_fan = "", "", "", "Tstatus", "", "", "", "astatus"; + drm_fb0_rp1_dpi = "", "", "", "bdrm-fb0=", "/axi/pcie@1000120000/rp1/dpi@148000"; + drm_fb0_rp1_dsi0 = "", "", "", "bdrm-fb0=", "/axi/pcie@1000120000/rp1/dsi@110000"; + drm_fb0_rp1_dsi1 = "", "", "", "bdrm-fb0=", "/axi/pcie@1000120000/rp1/dsi@128000"; + drm_fb0_vc4 = "", "", "", "bdrm-fb0=", "/axi/gpu"; + drm_fb1_rp1_dpi = "", "", "", "bdrm-fb1=", "/axi/pcie@1000120000/rp1/dpi@148000"; + drm_fb1_rp1_dsi0 = "", "", "", "bdrm-fb1=", "/axi/pcie@1000120000/rp1/dsi@110000"; + drm_fb1_rp1_dsi1 = "", "", "", "bdrm-fb1=", "/axi/pcie@1000120000/rp1/dsi@128000"; + drm_fb1_vc4 = "", "", "", "bdrm-fb1=", "/axi/gpu"; + drm_fb2_rp1_dpi = "", "", "", "bdrm-fb2=", "/axi/pcie@1000120000/rp1/dpi@148000"; + drm_fb2_rp1_dsi0 = "", "", "", "bdrm-fb2=", "/axi/pcie@1000120000/rp1/dsi@110000"; + drm_fb2_rp1_dsi1 = "", "", "", "bdrm-fb2=", "/axi/pcie@1000120000/rp1/dsi@128000"; + drm_fb2_vc4 = "", "", "", "bdrm-fb2=", "/axi/gpu"; + eth_led0 = "", "", "", "?led-modes:0"; + eth_led1 = "", "", "", "?led-modes:4"; + fan_temp0 = "", "", "", "Stemperature:0"; + fan_temp0_hyst = "", "", "", "Shysteresis:0"; + fan_temp0_speed = "", "", "", "Tcooling-levels:4"; + fan_temp1 = "", "", "", "Utemperature:0"; + fan_temp1_hyst = "", "", "", "Uhysteresis:0"; + fan_temp1_speed = "", "", "", "Tcooling-levels:8"; + fan_temp2 = "", "", "", "Vtemperature:0"; + fan_temp2_hyst = "", "", "", "Vhysteresis:0"; + fan_temp2_speed = "", "", "", "Tcooling-levels:12"; + fan_temp3 = "", "", "", "Wtemperature:0"; + fan_temp3_hyst = "", "", "", "Whysteresis:0"; + fan_temp3_speed = "", "", "", "Tcooling-levels:16"; + i2c = "", "", "", "cstatus"; + i2c_arm = "", "", "", "cstatus"; + i2c_arm_baudrate = "", "", "", "cclock-frequency:0"; + i2c_baudrate = "", "", "", "cclock-frequency:0"; + i2c_csi_dsi = "", "", "", "dstatus"; + i2c_csi_dsi0 = "", "", "", "estatus"; + i2c_csi_dsi1 = "", "", "", "dstatus"; + i2c_vc = "", "", "", "fstatus"; + i2c_vc_baudrate = "", "", "", "fclock-frequency:0"; + i2c0 = "", "", "", "fstatus"; + i2c0_baudrate = "", "", "", "fclock-frequency:0"; + i2c1 = "", "", "", "cstatus"; + i2c1_baudrate = "", "", "", "cclock-frequency:0"; + krnbt = "", "", "", "_status"; + nvme = "", "", "", "gstatus"; + nvmem_cust_rw = "", "", "", "hrw?"; + nvmem_mac_rw = "", "", "", "irw?"; + nvmem_priv_rw = "", "", "", "jrw?"; + pcie_tperst_clk_ms = "", "", "", "gbrcm,tperst-clk-ms:0"; + pciex1 = "", "", "", "gstatus"; + pciex1_gen = "", "", "", "gmax-link-speed:0"; + pciex1_no_l0s = "", "", "", "gaspm-no-l0s?"; + pciex1_tperst_clk_ms = "", "", "", "gbrcm,tperst-clk-ms:0"; + pwr_led_gpio = "", "", "", "kgpios:4"; + pwr_led_activelow = "", "", "", "kgpios:8"; + pwr_led_trigger = "", "", "", "klinux,default-trigger"; + random = "", "", "", "lstatus"; + rtc = "", "", "", "mstatus"; + rtc_bbat_vchg = "", "", "", "mtrickle-charge-microvolt:0"; + spi = "", "", "", "nstatus"; + strict_gpiod = "", "", "", "obootargs=pinctrl_rp1.persist_gpio_outputs=n"; + suspend = "", "", "", "`linux,code:0=205"; + uart0 = "", "", "", "pstatus"; + uart0_console = "", "", "", "pstatus", "", "", "", "bconsole=", "/axi/pcie@1000120000/rp1/serial@30000"; + uart0_dma = [00 00 00 70 64 6d 61 73 3a 30 3d 00 00 00 00 2b 00 00 00 70 64 6d 61 73 3a 34 3d 00 00 00 00 1a 00 00 00 70 64 6d 61 73 3a 38 3d 00 00 00 00 2b 00 00 00 70 64 6d 61 73 3a 31 32 3d 00 00 00 00 19 00 00 00 70 64 6d 61 2d 6e 61 6d 65 73 5b 3d 37 34 37 38 30 30 37 32 37 38 30 30 00]; + wifiaddr = "", "", "", "qlocal-mac-address["; + cam0_reg = "", "", "", "rstatus"; + cam0_reg_gpio = [00 00 00 72 67 70 69 6f 3a 34 00 00 00 00 72 67 70 69 6f 3a 30 3d 00 00 00 00 2e]; + cam1_reg = "", "", "", "sstatus"; + cam1_reg_gpio = [00 00 00 73 67 70 69 6f 3a 34 00 00 00 00 73 67 70 69 6f 3a 30 3d 00 00 00 00 2e]; + sd_cqe = "", "", "", "tsupports-cqe:0"; + }; + + cooling_fan { + status = "disabled"; + compatible = "pwm-fan"; + #cooling-cells = <0x02>; + cooling-min-state = <0x00>; + cooling-max-state = <0x03>; + cooling-levels = <0x00 0x4b 0x7d 0xaf 0xfa>; + pwms = <0x61 0x03 0xa25e 0x01>; + rpm-regmap = <0x61>; + rpm-offset = <0x3c>; + phandle = <0x54>; + }; + + pwr_button { + compatible = "gpio-keys"; + pinctrl-names = "default"; + pinctrl-0 = <0x75>; + status = "okay"; + + pwr { + label = "pwr_button"; + linux,code = <0x74>; + gpios = <0x1b 0x14 0x01>; + debounce-interval = <0x32>; + phandle = <0x60>; + }; + }; + + __symbols__ { + clocks = "/clocks"; + clk_osc = "/clocks/clk-osc"; + clk_vpu = "/clocks/clk-vpu"; + clk_uart = "/clocks/clk-uart"; + clk_emmc2 = "/clocks/clk-emmc2"; + clk_usb = "/clocks/clk-usb"; + clk_xosc = "/clocks/clk_xosc"; + sdio_src = "/clocks/sdio_src"; + sdhci_core = "/clocks/sdhci_core"; + clksrc_gp0 = "/clocks/clksrc_gp0"; + clksrc_gp1 = "/clocks/clksrc_gp1"; + clksrc_gp2 = "/clocks/clksrc_gp2"; + clksrc_gp3 = "/clocks/clksrc_gp3"; + clksrc_gp4 = "/clocks/clksrc_gp4"; + clksrc_gp5 = "/clocks/clksrc_gp5"; + cpus = "/cpus"; + cpu0 = "/cpus/cpu@0"; + l2_cache_l0 = "/cpus/cpu@0/l2-cache-l0"; + cpu1 = "/cpus/cpu@1"; + l2_cache_l1 = "/cpus/cpu@1/l2-cache-l1"; + cpu2 = "/cpus/cpu@2"; + l2_cache_l2 = "/cpus/cpu@2/l2-cache-l2"; + cpu3 = "/cpus/cpu@3"; + l2_cache_l3 = "/cpus/cpu@3/l2-cache-l3"; + l3_cache = "/cpus/l3-cache"; + rmem = "/reserved-memory"; + cma = "/reserved-memory/linux,cma"; + blconfig = "/reserved-memory/nvram@0"; + blpubkey = "/reserved-memory/nvram@1"; + soc = "/soc@107c000000"; + pcie_rescal = "/soc@107c000000/reset-controller@119500"; + sdio1 = "/soc@107c000000/mmc@fff000"; + bcm_reset = "/soc@107c000000/reset-controller@1504318"; + system_timer = "/soc@107c000000/timer@7c003000"; + mailbox = "/soc@107c000000/mailbox@7c013880"; + local_intc = "/soc@107c000000/interrupt-controller@7cd00000"; + uart10 = "/soc@107c000000/serial@7d001000"; + gio_aon = "/soc@107c000000/gpio@7d517c00"; + gicv2 = "/soc@107c000000/interrupt-controller@7fff9000"; + aon_intr = "/soc@107c000000/interrupt-controller@7d510600"; + pixelvalve0 = "/soc@107c000000/pixelvalve@7c410000"; + pixelvalve1 = "/soc@107c000000/pixelvalve@7c411000"; + mop = "/soc@107c000000/mop@7c500000"; + moplet = "/soc@107c000000/moplet@7c501000"; + disp_intr = "/soc@107c000000/interrupt-controller@7c502000"; + dvp = "/soc@107c000000/clock@7c700000"; + ddc0 = "/soc@107c000000/i2c@7d508200"; + ddc1 = "/soc@107c000000/i2c@7d508280"; + bsc_irq = "/soc@107c000000/intc@7d508380"; + main_irq = "/soc@107c000000/intc@7d508400"; + hdmi0 = "/soc@107c000000/hdmi@7ef00700"; + hdmi1 = "/soc@107c000000/hdmi@7ef05700"; + axiperf = "/soc@107c000000/axiperf@7c012800"; + spi10 = "/soc@107c000000/spi@7d004000"; + spidev10 = "/soc@107c000000/spi@7d004000/spidev@0"; + i2c10 = "/soc@107c000000/i2c@7d005600"; + pm = "/soc@107c000000/watchdog@7d200000"; + random = "/soc@107c000000/rng@7d208000"; + cpu_l2_irq = "/soc@107c000000/intc@7d503000"; + pinctrl = "/soc@107c000000/pinctrl@7d504100"; + uarta_24_pins = "/soc@107c000000/pinctrl@7d504100/uarta_24_pins"; + sdio2_30_pins = "/soc@107c000000/pinctrl@7d504100/sdio2_30_pins"; + pwr_button_pins = "/soc@107c000000/pinctrl@7d504100/pwr_button_pins"; + wl_on_pins = "/soc@107c000000/pinctrl@7d504100/wl_on_pins"; + bt_shutdown_pins = "/soc@107c000000/pinctrl@7d504100/bt_shutdown_pins"; + emmc_sd_pulls = "/soc@107c000000/pinctrl@7d504100/emmc_sd_pulls"; + spi10_pins = "/soc@107c000000/pinctrl@7d504100/spi10_gpio2"; + spi10_gpio2 = "/soc@107c000000/pinctrl@7d504100/spi10_gpio2"; + spi10_cs_pins = "/soc@107c000000/pinctrl@7d504100/spi10_cs_gpio1"; + spi10_cs_gpio1 = "/soc@107c000000/pinctrl@7d504100/spi10_cs_gpio1"; + gio = "/soc@107c000000/gpio@7d508500"; + uarta = "/soc@107c000000/serial@7d50c000"; + bluetooth = "/soc@107c000000/serial@7d50c000/bluetooth"; + pinctrl_aon = "/soc@107c000000/pinctrl@7d510700"; + i2c3_m4_agpio0_pins = "/soc@107c000000/pinctrl@7d510700/i2c3_m4_agpio0_pins"; + bsc_m1_agpio13_pins = "/soc@107c000000/pinctrl@7d510700/bsc_m1_agpio13_pins"; + bsc_pmu_sgpio4_pins = "/soc@107c000000/pinctrl@7d510700/bsc_pmu_sgpio4_pins"; + bsc_m2_sgpio4_pins = "/soc@107c000000/pinctrl@7d510700/bsc_m2_sgpio4_pins"; + pwm_aon_agpio1_pins = "/soc@107c000000/pinctrl@7d510700/pwm_aon_agpio1_pins"; + pwm_aon_agpio4_pins = "/soc@107c000000/pinctrl@7d510700/pwm_aon_agpio4_pins"; + pwm_aon_agpio7_pins = "/soc@107c000000/pinctrl@7d510700/pwm_aon_agpio7_pins"; + emmc_aon_cd_pins = "/soc@107c000000/pinctrl@7d510700/emmc_aon_cd_pins"; + aon_pwm_1pin = "/soc@107c000000/pinctrl@7d510700/aon_pwm_1pin"; + main_aon_irq = "/soc@107c000000/intc@7d517ac0"; + avs_monitor = "/soc@107c000000/avs-monitor@7d542000"; + thermal = "/soc@107c000000/avs-monitor@7d542000/thermal"; + firmware = "/soc@107c000000/firmware"; + firmware_clocks = "/soc@107c000000/firmware/clocks"; + reset = "/soc@107c000000/firmware/reset"; + vcio = "/soc@107c000000/firmware/vcio"; + power = "/soc@107c000000/power"; + fb = "/soc@107c000000/fb"; + rpi_rtc = "/soc@107c000000/rpi_rtc"; + nvmem_otp = "/soc@107c000000/nvmem/nvmem_otp"; + nvmem_cust = "/soc@107c000000/nvmem/nvmem_cust"; + nvmem_mac = "/soc@107c000000/nvmem/nvmem_mac"; + nvmem_priv = "/soc@107c000000/nvmem/nvmem_priv"; + vdd_3v3_reg = "/soc@107c000000/fixedregulator_3v3"; + vdd_5v0_reg = "/soc@107c000000/fixedregulator_5v0"; + sound = "/soc@107c000000/sound"; + axi = "/axi"; + vc4 = "/axi/gpu"; + pcie0 = "/axi/pcie@1000100000"; + pciex1 = "/axi/pcie@1000110000"; + pcie1 = "/axi/pcie@1000110000"; + pciex4 = "/axi/pcie@1000120000"; + rp1_target = "/axi/pcie@1000120000"; + pcie2 = "/axi/pcie@1000120000"; + rp1 = "/axi/pcie@1000120000/rp1"; + rp1_mbox = "/axi/pcie@1000120000/rp1/mailbox@8000"; + rp1_clocks = "/axi/pcie@1000120000/rp1/clocks@18000"; + uart0 = "/axi/pcie@1000120000/rp1/serial@30000"; + rp1_uart0 = "/axi/pcie@1000120000/rp1/serial@30000"; + uart1 = "/axi/pcie@1000120000/rp1/serial@34000"; + rp1_uart1 = "/axi/pcie@1000120000/rp1/serial@34000"; + uart2 = "/axi/pcie@1000120000/rp1/serial@38000"; + rp1_uart2 = "/axi/pcie@1000120000/rp1/serial@38000"; + uart3 = "/axi/pcie@1000120000/rp1/serial@3c000"; + rp1_uart3 = "/axi/pcie@1000120000/rp1/serial@3c000"; + uart4 = "/axi/pcie@1000120000/rp1/serial@40000"; + rp1_uart4 = "/axi/pcie@1000120000/rp1/serial@40000"; + rp1_uart5 = "/axi/pcie@1000120000/rp1/serial@44000"; + rp1_spi8 = "/axi/pcie@1000120000/rp1/spi@4c000"; + spi0 = "/axi/pcie@1000120000/rp1/spi@50000"; + rp1_spi0 = "/axi/pcie@1000120000/rp1/spi@50000"; + spidev0 = "/axi/pcie@1000120000/rp1/spi@50000/spidev@0"; + spidev1 = "/axi/pcie@1000120000/rp1/spi@50000/spidev@1"; + spi1 = "/axi/pcie@1000120000/rp1/spi@54000"; + rp1_spi1 = "/axi/pcie@1000120000/rp1/spi@54000"; + spi2 = "/axi/pcie@1000120000/rp1/spi@58000"; + rp1_spi2 = "/axi/pcie@1000120000/rp1/spi@58000"; + spi3 = "/axi/pcie@1000120000/rp1/spi@5c000"; + rp1_spi3 = "/axi/pcie@1000120000/rp1/spi@5c000"; + spi4 = "/axi/pcie@1000120000/rp1/spi@60000"; + rp1_spi4 = "/axi/pcie@1000120000/rp1/spi@60000"; + spi5 = "/axi/pcie@1000120000/rp1/spi@64000"; + rp1_spi5 = "/axi/pcie@1000120000/rp1/spi@64000"; + rp1_spi6 = "/axi/pcie@1000120000/rp1/spi@68000"; + rp1_spi7 = "/axi/pcie@1000120000/rp1/spi@6c000"; + i2c_vc = "/axi/pcie@1000120000/rp1/i2c@70000"; + i2c0 = "/axi/pcie@1000120000/rp1/i2c@70000"; + rp1_i2c0 = "/axi/pcie@1000120000/rp1/i2c@70000"; + i2c_arm = "/axi/pcie@1000120000/rp1/i2c@74000"; + i2c1 = "/axi/pcie@1000120000/rp1/i2c@74000"; + rp1_i2c1 = "/axi/pcie@1000120000/rp1/i2c@74000"; + i2c2 = "/axi/pcie@1000120000/rp1/i2c@78000"; + rp1_i2c2 = "/axi/pcie@1000120000/rp1/i2c@78000"; + i2c3 = "/axi/pcie@1000120000/rp1/i2c@7c000"; + rp1_i2c3 = "/axi/pcie@1000120000/rp1/i2c@7c000"; + i2c_csi_dsi = "/axi/pcie@1000120000/rp1/i2c@80000"; + i2c_csi_dsi1 = "/axi/pcie@1000120000/rp1/i2c@80000"; + i2c4 = "/axi/pcie@1000120000/rp1/i2c@80000"; + rp1_i2c4 = "/axi/pcie@1000120000/rp1/i2c@80000"; + i2c5 = "/axi/pcie@1000120000/rp1/i2c@84000"; + rp1_i2c5 = "/axi/pcie@1000120000/rp1/i2c@84000"; + i2c_csi_dsi0 = "/axi/pcie@1000120000/rp1/i2c@88000"; + i2c6 = "/axi/pcie@1000120000/rp1/i2c@88000"; + rp1_i2c6 = "/axi/pcie@1000120000/rp1/i2c@88000"; + rp1_audio_out = "/axi/pcie@1000120000/rp1/audio_out@94000"; + pwm = "/axi/pcie@1000120000/rp1/pwm@98000"; + pwm0 = "/axi/pcie@1000120000/rp1/pwm@98000"; + rp1_pwm0 = "/axi/pcie@1000120000/rp1/pwm@98000"; + pwm1 = "/axi/pcie@1000120000/rp1/pwm@9c000"; + rp1_pwm1 = "/axi/pcie@1000120000/rp1/pwm@9c000"; + i2s_clk_producer = "/axi/pcie@1000120000/rp1/i2s@a0000"; + i2s = "/axi/pcie@1000120000/rp1/i2s@a0000"; + rp1_i2s0 = "/axi/pcie@1000120000/rp1/i2s@a0000"; + i2s_clk_consumer = "/axi/pcie@1000120000/rp1/i2s@a4000"; + rp1_i2s1 = "/axi/pcie@1000120000/rp1/i2s@a4000"; + rp1_i2s2 = "/axi/pcie@1000120000/rp1/i2s@a8000"; + rp1_sdio_clk0 = "/axi/pcie@1000120000/rp1/sdio_clk0@b0004"; + rp1_sdio_clk1 = "/axi/pcie@1000120000/rp1/sdio_clk1@b4004"; + rp1_adc = "/axi/pcie@1000120000/rp1/adc@c8000"; + gpio = "/axi/pcie@1000120000/rp1/gpio@d0000"; + rp1_gpio = "/axi/pcie@1000120000/rp1/gpio@d0000"; + uart0_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart0_14_15"; + rp1_uart0_14_15 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart0_14_15"; + uart0_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart0_ctsrts_16_17"; + rp1_uart0_ctsrts_16_17 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart0_ctsrts_16_17"; + uart1_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart1_0_1"; + rp1_uart1_0_1 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart1_0_1"; + uart1_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart1_ctsrts_2_3"; + rp1_uart1_ctsrts_2_3 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart1_ctsrts_2_3"; + uart2_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart2_4_5"; + rp1_uart2_4_5 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart2_4_5"; + uart2_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart2_ctsrts_6_7"; + rp1_uart2_ctsrts_6_7 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart2_ctsrts_6_7"; + uart3_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart3_8_9"; + rp1_uart3_8_9 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart3_8_9"; + uart3_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart3_ctsrts_10_11"; + rp1_uart3_ctsrts_10_11 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart3_ctsrts_10_11"; + uart4_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart4_12_13"; + rp1_uart4_12_13 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart4_12_13"; + uart4_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart4_ctsrts_14_15"; + rp1_uart4_ctsrts_14_15 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart4_ctsrts_14_15"; + rp1_sdio0_22_27 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_sdio0_22_27"; + rp1_sdio1_28_33 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_sdio1_28_33"; + rp1_i2s0_18_21 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2s0_18_21"; + rp1_i2s1_18_21 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2s1_18_21"; + rp1_i2c4_34_35 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c4_34_35"; + rp1_i2c6_38_39 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c6_38_39"; + rp1_i2c4_40_41 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c4_40_41"; + rp1_i2c5_44_45 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c5_44_45"; + i2c0_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c0_0_1"; + rp1_i2c0_0_1 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c0_0_1"; + rp1_i2c0_8_9 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c0_8_9"; + i2c1_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c1_2_3"; + rp1_i2c1_2_3 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c1_2_3"; + rp1_i2c1_10_11 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c1_10_11"; + i2c2_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c2_4_5"; + rp1_i2c2_4_5 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c2_4_5"; + rp1_i2c2_12_13 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c2_12_13"; + i2c3_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c3_6_7"; + rp1_i2c3_6_7 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c3_6_7"; + rp1_i2c3_14_15 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c3_14_15"; + rp1_i2c3_22_23 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c3_22_23"; + dpi_16bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_gpio2"; + rp1_dpi_16bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_gpio2"; + dpi_16bit_cpadhi_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_cpadhi_gpio2"; + rp1_dpi_16bit_cpadhi_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_cpadhi_gpio2"; + rp1_dpi_16bit_pad666_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_pad666_gpio2"; + dpi_18bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_gpio2"; + rp1_dpi_18bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_gpio2"; + dpi_18bit_cpadhi_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_cpadhi_gpio2"; + rp1_dpi_18bit_cpadhi_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_cpadhi_gpio2"; + dpi_gpio1 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_24bit_gpio2"; + rp1_dpi_24bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_24bit_gpio2"; + rp1_dpi_hvsync = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_hvsync"; + dpi_16bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_gpio0"; + rp1_dpi_16bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_gpio0"; + dpi_16bit_cpadhi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_cpadhi_gpio0"; + rp1_dpi_16bit_cpadhi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_cpadhi_gpio0"; + rp1_dpi_16bit_pad666_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_pad666_gpio0"; + dpi_18bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_gpio0"; + rp1_dpi_18bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_gpio0"; + dpi_18bit_cpadhi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_cpadhi_gpio0"; + rp1_dpi_18bit_cpadhi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_cpadhi_gpio0"; + dpi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_24bit_gpio0"; + rp1_dpi_24bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_24bit_gpio0"; + rp1_gpclksrc0_gpio4 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc0_gpio4"; + rp1_gpclksrc0_gpio20 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc0_gpio20"; + rp1_gpclksrc1_gpio5 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc1_gpio5"; + rp1_gpclksrc1_gpio18 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc1_gpio18"; + rp1_gpclksrc1_gpio21 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc1_gpio21"; + rp1_pwm1_gpio45 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_pwm1_gpio45"; + spi0_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi0_gpio9"; + rp1_spi0_gpio9 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi0_gpio9"; + spi0_cs_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi0_cs_gpio7"; + rp1_spi0_cs_gpio7 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi0_cs_gpio7"; + rp1_spi1_gpio19 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi1_gpio19"; + spi2_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi2_gpio1"; + rp1_spi2_gpio1 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi2_gpio1"; + spi3_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi3_gpio5"; + rp1_spi3_gpio5 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi3_gpio5"; + spi4_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi4_gpio9"; + rp1_spi4_gpio9 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi4_gpio9"; + spi5_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi5_gpio13"; + rp1_spi5_gpio13 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi5_gpio13"; + rp1_spi8_gpio49 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi8_gpio49"; + rp1_spi8_cs_gpio52 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi8_cs_gpio52"; + rp1_audio_out_12_13 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_audio_out_12_13"; + usb_vbus_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/usb_vbus_pins"; + rp1_eth = "/axi/pcie@1000120000/rp1/ethernet@100000"; + phy1 = "/axi/pcie@1000120000/rp1/ethernet@100000/ethernet-phy@1"; + csi0 = "/axi/pcie@1000120000/rp1/csi@110000"; + rp1_csi0 = "/axi/pcie@1000120000/rp1/csi@110000"; + csi1 = "/axi/pcie@1000120000/rp1/csi@128000"; + rp1_csi1 = "/axi/pcie@1000120000/rp1/csi@128000"; + pio = "/axi/pcie@1000120000/rp1/pio@178000"; + rp1_pio = "/axi/pcie@1000120000/rp1/pio@178000"; + rp1_mmc0 = "/axi/pcie@1000120000/rp1/mmc@180000"; + rp1_mmc1 = "/axi/pcie@1000120000/rp1/mmc@184000"; + rp1_dma = "/axi/pcie@1000120000/rp1/dma@188000"; + rp1_usb0 = "/axi/pcie@1000120000/rp1/usb@200000"; + rp1_usb1 = "/axi/pcie@1000120000/rp1/usb@300000"; + dsi0 = "/axi/pcie@1000120000/rp1/dsi@110000"; + rp1_dsi0 = "/axi/pcie@1000120000/rp1/dsi@110000"; + dsi1 = "/axi/pcie@1000120000/rp1/dsi@128000"; + rp1_dsi1 = "/axi/pcie@1000120000/rp1/dsi@128000"; + vec = "/axi/pcie@1000120000/rp1/vec@144000"; + rp1_vec = "/axi/pcie@1000120000/rp1/vec@144000"; + dpi = "/axi/pcie@1000120000/rp1/dpi@148000"; + rp1_dpi = "/axi/pcie@1000120000/rp1/dpi@148000"; + sram = "/axi/pcie@1000120000/rp1/sram@400000"; + rp1_fw_shmem = "/axi/pcie@1000120000/rp1/sram@400000/shmem@ff00"; + mip0 = "/axi/msi-controller@1000130000"; + mip1 = "/axi/msi-controller@1000131000"; + iommu2 = "/axi/iommu@5100"; + iommu4 = "/axi/iommu@5200"; + iommu5 = "/axi/iommu@5280"; + iommuc = "/axi/iommuc@5b00"; + dma32 = "/axi/dma@10000"; + dma40 = "/axi/dma@10600"; + syscon_piarbctl = "/axi/syscon@400018"; + usb = "/axi/usb@480000"; + hevc_dec = "/axi/codec@800000"; + pisp_be = "/axi/pisp_be@880000"; + sdio2 = "/axi/mmc@1100000"; + wifi = "/axi/mmc@1100000/wifi@1"; + v3d = "/axi/v3d@2000000"; + clk_27MHz = "/clk-27M"; + clk_108MHz = "/clk-108M"; + hvs = "/hvs@107c580000"; + cpu_thermal = "/thermal-zones/cpu-thermal"; + thermal_trips = "/thermal-zones/cpu-thermal/trips"; + cpu_crit = "/thermal-zones/cpu-thermal/trips/cpu-crit"; + cpu_tepid = "/thermal-zones/cpu-thermal/trips/cpu-tepid"; + cpu_warm = "/thermal-zones/cpu-thermal/trips/cpu-warm"; + cpu_hot = "/thermal-zones/cpu-thermal/trips/cpu-hot"; + cpu_vhot = "/thermal-zones/cpu-thermal/trips/cpu-vhot"; + cooling_maps = "/thermal-zones/cpu-thermal/cooling-maps"; + firmwarekms = "/firmwarekms"; + usbphy = "/phy"; + leds = "/leds"; + led_pwr = "/leds/led-pwr"; + led_act = "/leds/led-act"; + sd_io_1v8_reg = "/sd-io-1v8-reg"; + sd_vcc_reg = "/sd-vcc-reg"; + wl_on_reg = "/wl-on-reg"; + cam1_clk = "/cam1_clk"; + cam0_clk = "/cam0_clk"; + cam0_reg = "/cam0_reg"; + cam1_reg = "/cam1_reg"; + cam_dummy_reg = "/cam_dummy_reg"; + aux = "/dummy"; + dummy = "/dummy"; + i2c0if = "/i2c0if"; + i2c0mux = "/i2c0mux"; + rp1_firmware = "/rp1_firmware"; + rp1_vdd_3v3 = "/rp1_vdd_3v3"; + chosen = "/chosen"; + aliases = "/aliases"; + fan = "/cooling_fan"; + pwr_key = "/pwr_button/pwr"; + }; +}; diff --git a/dtbs/rpicm5lio.dts b/dtbs/rpicm5lio.dts new file mode 100644 index 00000000..709196cc --- /dev/null +++ b/dtbs/rpicm5lio.dts @@ -0,0 +1,3324 @@ +/dts-v1/; + +/ { + compatible = "raspberrypi,5-compute-module", "brcm,bcm2712"; + #address-cells = <0x02>; + #size-cells = <0x01>; + interrupt-parent = <0x01>; + model = "Raspberry Pi Compute Module 5 Lite"; + + clocks { + compatible = "simple-bus"; + #address-cells = <0x01>; + #size-cells = <0x00>; + phandle = <0x76>; + + clk-osc { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "osc"; + clock-frequency = <0x337f980>; + phandle = <0x77>; + }; + + clk-vpu { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0x2cb41780>; + clock-output-names = "vpu-clock"; + phandle = <0x0e>; + }; + + clk-uart { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0x8ca000>; + clock-output-names = "uart-clock"; + phandle = <0x0d>; + }; + + clk-emmc2 { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0xbebc200>; + clock-output-names = "emmc2-clock"; + phandle = <0x08>; + }; + + clk-usb { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "otg"; + clock-frequency = <0x1c9c3800>; + phandle = <0x44>; + }; + + clk_xosc { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "xosc"; + clock-frequency = <0x2faf080>; + phandle = <0x28>; + }; + + sdio_src { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "src"; + clock-frequency = <0x3b9aca00>; + phandle = <0x3a>; + }; + + sdhci_core { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-output-names = "core"; + clock-frequency = <0x2faf080>; + phandle = <0x3b>; + }; + + clksrc_gp0 { + status = "disabled"; + compatible = "fixed-factor-clock"; + #clock-cells = <0x00>; + clock-div = <0x01>; + clock-mult = <0x01>; + clocks = <0x02 0x21>; + clock-output-names = "clksrc_gp0"; + phandle = <0x78>; + }; + + clksrc_gp1 { + status = "disabled"; + compatible = "fixed-factor-clock"; + #clock-cells = <0x00>; + clock-div = <0x01>; + clock-mult = <0x01>; + clocks = <0x02 0x22>; + clock-output-names = "clksrc_gp1"; + phandle = <0x79>; + }; + + clksrc_gp2 { + status = "disabled"; + compatible = "fixed-factor-clock"; + clock-div = <0x01>; + clock-mult = <0x01>; + #clock-cells = <0x00>; + clocks = <0x02 0x23>; + clock-output-names = "clksrc_gp2"; + phandle = <0x7a>; + }; + + clksrc_gp3 { + status = "disabled"; + compatible = "fixed-factor-clock"; + clock-div = <0x01>; + clock-mult = <0x01>; + #clock-cells = <0x00>; + clocks = <0x02 0x24>; + clock-output-names = "clksrc_gp3"; + phandle = <0x7b>; + }; + + clksrc_gp4 { + status = "disabled"; + compatible = "fixed-factor-clock"; + #clock-cells = <0x00>; + clock-div = <0x01>; + clock-mult = <0x01>; + clocks = <0x02 0x25>; + clock-output-names = "clksrc_gp4"; + phandle = <0x7c>; + }; + + clksrc_gp5 { + status = "disabled"; + compatible = "fixed-factor-clock"; + #clock-cells = <0x00>; + clock-div = <0x01>; + clock-mult = <0x01>; + clocks = <0x02 0x26>; + clock-output-names = "clksrc_gp5"; + phandle = <0x7d>; + }; + }; + + cpus { + #address-cells = <0x01>; + #size-cells = <0x00>; + phandle = <0x7e>; + + cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a76"; + reg = <0x00>; + enable-method = "psci"; + d-cache-size = <0x10000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0x10000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x03>; + phandle = <0x4d>; + + l2-cache-l0 { + compatible = "cache"; + cache-size = <0x80000>; + cache-line-size = <0x40>; + cache-sets = <0x400>; + cache-level = <0x02>; + cache-unified; + next-level-cache = <0x04>; + phandle = <0x03>; + }; + }; + + cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a76"; + reg = <0x100>; + enable-method = "psci"; + d-cache-size = <0x10000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0x10000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x05>; + phandle = <0x4e>; + + l2-cache-l1 { + compatible = "cache"; + cache-size = <0x80000>; + cache-line-size = <0x40>; + cache-sets = <0x400>; + cache-level = <0x02>; + cache-unified; + next-level-cache = <0x04>; + phandle = <0x05>; + }; + }; + + cpu@2 { + device_type = "cpu"; + compatible = "arm,cortex-a76"; + reg = <0x200>; + enable-method = "psci"; + d-cache-size = <0x10000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0x10000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x06>; + phandle = <0x4f>; + + l2-cache-l2 { + compatible = "cache"; + cache-size = <0x80000>; + cache-line-size = <0x40>; + cache-sets = <0x400>; + cache-level = <0x02>; + cache-unified; + next-level-cache = <0x04>; + phandle = <0x06>; + }; + }; + + cpu@3 { + device_type = "cpu"; + compatible = "arm,cortex-a76"; + reg = <0x300>; + enable-method = "psci"; + d-cache-size = <0x10000>; + d-cache-line-size = <0x40>; + d-cache-sets = <0x100>; + i-cache-size = <0x10000>; + i-cache-line-size = <0x40>; + i-cache-sets = <0x100>; + next-level-cache = <0x07>; + phandle = <0x50>; + + l2-cache-l3 { + compatible = "cache"; + cache-size = <0x80000>; + cache-line-size = <0x40>; + cache-sets = <0x400>; + cache-level = <0x02>; + cache-unified; + next-level-cache = <0x04>; + phandle = <0x07>; + }; + }; + + l3-cache { + compatible = "cache"; + cache-size = <0x200000>; + cache-line-size = <0x40>; + cache-sets = <0x800>; + cache-level = <0x03>; + cache-unified; + phandle = <0x04>; + }; + }; + + psci { + method = "smc"; + compatible = "arm,psci-1.0", "arm,psci-0.2"; + }; + + reserved-memory { + ranges; + #address-cells = <0x02>; + #size-cells = <0x01>; + phandle = <0x7f>; + + atf@0 { + reg = <0x00 0x00 0x80000>; + no-map; + }; + + linux,cma { + compatible = "shared-dma-pool"; + size = <0x4000000>; + reusable; + linux,cma-default; + alloc-ranges = <0x00 0x00 0x40000000>; + phandle = <0x80>; + }; + + nvram@0 { + compatible = "raspberrypi,bootloader-config", "nvmem-rmem"; + #address-cells = <0x01>; + #size-cells = <0x01>; + reg = <0x00 0x00 0x00>; + no-map; + status = "disabled"; + phandle = <0x81>; + }; + + nvram@1 { + compatible = "raspberrypi,bootloader-public-key", "nvmem-rmem"; + #address-cells = <0x01>; + #size-cells = <0x01>; + reg = <0x00 0x00 0x00>; + no-map; + status = "disabled"; + phandle = <0x82>; + }; + }; + + soc@107c000000 { + compatible = "simple-bus"; + ranges = <0x00 0x10 0x00 0x80000000>; + #address-cells = <0x01>; + #size-cells = <0x01>; + phandle = <0x83>; + + reset-controller@119500 { + compatible = "brcm,bcm7216-pcie-sata-rescal"; + reg = <0x119500 0x10>; + #reset-cells = <0x00>; + phandle = <0x22>; + }; + + mmc@fff000 { + compatible = "brcm,bcm2712-sdhci", "brcm,sdhci-brcmstb"; + reg = <0xfff000 0x260 0xfff400 0x200>; + reg-names = "host", "cfg"; + interrupts = <0x00 0x111 0x04>; + clocks = <0x08>; + clock-names = "sw_sdio"; + mmc-ddr-3_3v; + pinctrl-0 = <0x09 0x0a>; + pinctrl-names = "default"; + vqmmc-supply = <0x0b>; + vmmc-supply = <0x0c>; + bus-width = <0x08>; + sd-uhs-sdr50; + sd-uhs-ddr50; + sd-uhs-sdr104; + mmc-hs200-1_8v; + broken-cd; + supports-cqe = <0x01>; + status = "okay"; + phandle = <0x74>; + }; + + reset-controller@1504318 { + compatible = "brcm,brcmstb-reset"; + reg = <0x1504318 0x30>; + #reset-cells = <0x01>; + phandle = <0x23>; + }; + + timer@7c003000 { + compatible = "brcm,bcm2835-system-timer"; + reg = <0x7c003000 0x1000>; + interrupts = <0x00 0x40 0x04 0x00 0x41 0x04 0x00 0x42 0x04 0x00 0x43 0x04>; + clock-frequency = <0xf4240>; + phandle = <0x84>; + }; + + mailbox@7c013880 { + compatible = "brcm,bcm2835-mbox"; + reg = <0x7c013880 0x40>; + interrupts = <0x00 0x21 0x04>; + #mbox-cells = <0x00>; + phandle = <0x21>; + }; + + interrupt-controller@7cd00000 { + compatible = "brcm,bcm2836-l1-intc"; + reg = <0x7cd00000 0x100>; + phandle = <0x85>; + }; + + serial@7d001000 { + compatible = "arm,pl011", "arm,primecell"; + reg = <0x7d001000 0x200>; + interrupts = <0x00 0x79 0x04>; + clocks = <0x0d 0x0e>; + clock-names = "uartclk", "apb_pclk"; + arm,primecell-periphid = <0x341011>; + status = "okay"; + phandle = <0x86>; + }; + + interrupt-controller@7d517000 { + compatible = "brcm,bcm7271-l2-intc"; + reg = <0x7d517000 0x10>; + interrupts = <0x00 0xf7 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + status = "disabled"; + }; + + gpio@7d517c00 { + compatible = "brcm,brcmstb-gpio"; + reg = <0x7d517c00 0x40>; + gpio-controller; + #gpio-cells = <0x02>; + brcm,gpio-bank-widths = <0x11 0x06>; + brcm,gpio-direct; + gpio-line-names = "RP1_SDA", "RP1_SCL", "RP1_RUN", "SD_IOVDD_SEL", "SD_PWR_ON", "ANT1", "ANT2", "-", "2712_WAKE", "2712_STAT_LED", "-", "-", "PMIC_INT", "UART_TX_FS", "UART_RX_FS", "-", "-", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "HDMI0_SCL", "HDMI0_SDA", "HDMI1_SCL", "HDMI1_SDA", "PMIC_SCL", "PMIC_SDA"; + phandle = <0x59>; + + rp1_run_hog { + gpio-hog; + gpios = <0x02 0x00>; + output-high; + line-name = "RP1 RUN pin"; + }; + + ant1-hog { + gpio-hog; + gpios = <0x05 0x00>; + output-high; + line-name = "ant1"; + phandle = <0x72>; + }; + + ant2-hog { + gpio-hog; + gpios = <0x06 0x00>; + output-low; + line-name = "ant2"; + phandle = <0x73>; + }; + }; + + interrupt-controller@7fff9000 { + compatible = "arm,gic-400"; + reg = <0x7fff9000 0x1000 0x7fffa000 0x2000 0x7fffc000 0x2000 0x7fffe000 0x2000>; + interrupt-controller; + #interrupt-cells = <0x03>; + interrupts = <0x01 0x09 0xf04>; + phandle = <0x01>; + }; + + interrupt-controller@7d510600 { + compatible = "brcm,bcm2711-l2-intc", "brcm,l2-intc"; + reg = <0x7d510600 0x30>; + interrupts = <0x00 0xef 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + status = "disabled"; + phandle = <0x13>; + }; + + pixelvalve@7c410000 { + compatible = "brcm,bcm2712-pixelvalve0"; + reg = <0x7c410000 0x100>; + interrupts = <0x00 0x65 0x04>; + status = "disabled"; + phandle = <0x87>; + }; + + pixelvalve@7c411000 { + compatible = "brcm,bcm2712-pixelvalve1"; + reg = <0x7c411000 0x100>; + interrupts = <0x00 0x6e 0x04>; + status = "disabled"; + phandle = <0x88>; + }; + + mop@7c500000 { + compatible = "brcm,bcm2712-mop"; + reg = <0x7c500000 0x28>; + interrupt-parent = <0x0f>; + interrupts = <0x01>; + status = "disabled"; + phandle = <0x89>; + }; + + moplet@7c501000 { + compatible = "brcm,bcm2712-moplet"; + reg = <0x7c501000 0x20>; + interrupt-parent = <0x0f>; + interrupts = <0x00>; + status = "disabled"; + phandle = <0x8a>; + }; + + interrupt-controller@7c502000 { + compatible = "brcm,bcm2711-l2-intc", "brcm,l2-intc"; + reg = <0x7c502000 0x30>; + interrupts = <0x00 0x61 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + status = "disabled"; + phandle = <0x0f>; + }; + + clock@7c700000 { + compatible = "brcm,brcm2711-dvp"; + reg = <0x7c700000 0x10>; + clocks = <0x10>; + #clock-cells = <0x01>; + #reset-cells = <0x01>; + phandle = <0x12>; + }; + + i2c@7d508200 { + compatible = "brcm,brcmstb-i2c"; + reg = <0x7d508200 0x58>; + interrupt-parent = <0x11>; + interrupts = <0x01>; + clock-frequency = <0x17cdc>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + phandle = <0x14>; + }; + + i2c@7d508280 { + compatible = "brcm,brcmstb-i2c"; + reg = <0x7d508280 0x58>; + interrupt-parent = <0x11>; + interrupts = <0x02>; + clock-frequency = <0x17cdc>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + phandle = <0x18>; + }; + + intc@7d508380 { + compatible = "brcm,bcm7271-l2-intc"; + reg = <0x7d508380 0x10>; + interrupts = <0x00 0xf2 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + phandle = <0x11>; + }; + + intc@7d508400 { + compatible = "brcm,bcm7271-l2-intc"; + reg = <0x7d508400 0x10>; + interrupts = <0x00 0xf4 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + phandle = <0x1e>; + }; + + hdmi@7ef00700 { + compatible = "brcm,bcm2712-hdmi0"; + reg = <0x7c701400 0x300 0x7c701000 0x200 0x7c701d00 0x300 0x7c702000 0x80 0x7c703800 0x200 0x7c704000 0x800 0x7c700100 0x80 0x7d510800 0x100 0x7c720000 0x100>; + reg-names = "hdmi", "dvp", "phy", "rm", "packet", "metadata", "csc", "cec", "hd"; + resets = <0x12 0x01>; + interrupt-parent = <0x13>; + interrupts = <0x01 0x02 0x03 0x07 0x08>; + interrupt-names = "cec-tx", "cec-rx", "cec-low", "hpd-connected", "hpd-removed"; + ddc = <0x14>; + status = "disabled"; + dmas = <0x15 0x41fa000a>; + dma-names = "audio-rx"; + clocks = <0x16 0x0d 0x16 0x0e 0x12 0x00 0x17>; + clock-names = "hdmi", "bvb", "audio", "cec"; + phandle = <0x8b>; + }; + + hdmi@7ef05700 { + compatible = "brcm,bcm2712-hdmi1"; + reg = <0x7c706400 0x300 0x7c706000 0x200 0x7c706d00 0x300 0x7c707000 0x80 0x7c708800 0x200 0x7c709000 0x800 0x7c700180 0x80 0x7d511000 0x100 0x7c720000 0x100>; + reg-names = "hdmi", "dvp", "phy", "rm", "packet", "metadata", "csc", "cec", "hd"; + resets = <0x12 0x02>; + interrupt-parent = <0x13>; + interrupts = <0x0b 0x0c 0x0d 0x0e 0x0f>; + interrupt-names = "cec-tx", "cec-rx", "cec-low", "hpd-connected", "hpd-removed"; + ddc = <0x18>; + status = "disabled"; + dmas = <0x15 0x41fa0011>; + dma-names = "audio-rx"; + clocks = <0x16 0x0d 0x16 0x0e 0x12 0x01 0x17>; + clock-names = "hdmi", "bvb", "audio", "cec"; + phandle = <0x8c>; + }; + + axiperf@7c012800 { + compatible = "brcm,bcm2712-axiperf"; + reg = <0x7c012800 0x100 0x7e000000 0x100>; + firmware = <0x19>; + status = "disabled"; + phandle = <0x5e>; + }; + + spi@7d004000 { + compatible = "brcm,bcm2835-spi"; + reg = <0x7d004000 0x200>; + interrupts = <0x00 0x76 0x04>; + clocks = <0x0e>; + num-cs = <0x01>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "okay"; + dmas = <0x15 0x06 0x15 0x07>; + dma-names = "tx", "rx"; + pinctrl-names = "default"; + cs-gpios = <0x1a 0x01 0x01>; + pinctrl-0 = <0x1b 0x1c>; + phandle = <0x8d>; + + spidev@0 { + compatible = "spidev"; + reg = <0x00>; + #address-cells = <0x01>; + #size-cells = <0x00>; + spi-max-frequency = <0x1312d00>; + status = "okay"; + phandle = <0x8e>; + }; + }; + + i2c@7d005600 { + compatible = "brcm,bcm2711-i2c", "brcm,bcm2835-i2c"; + reg = <0x7d005600 0x20>; + interrupts = <0x00 0x75 0x04>; + clocks = <0x0e>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + clock-frequency = <0x61a80>; + pinctrl-0 = <0x1d>; + pinctrl-names = "default"; + phandle = <0x8f>; + }; + + watchdog@7d200000 { + compatible = "brcm,bcm2712-pm"; + reg = <0x7d200000 0x308>; + reg-names = "pm"; + #power-domain-cells = <0x01>; + #reset-cells = <0x01>; + system-power-controller; + phandle = <0x4b>; + }; + + rng@7d208000 { + compatible = "brcm,bcm2711-rng200"; + reg = <0x7d208000 0x28>; + status = "okay"; + phandle = <0x6b>; + }; + + intc@7d503000 { + compatible = "brcm,l2-intc"; + reg = <0x7d503000 0x18>; + interrupts = <0x00 0xee 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + phandle = <0x58>; + }; + + pinctrl@7d504100 { + compatible = "brcm,bcm2712-pinctrl"; + reg = <0x7d504100 0x30>; + phandle = <0x90>; + + uarta_24_pins { + phandle = <0x1f>; + + pin_rts { + function = "uart0"; + pins = "gpio24"; + bias-disable; + }; + + pin_cts { + function = "uart0"; + pins = "gpio25"; + bias-pull-up; + }; + + pin_txd { + function = "uart0"; + pins = "gpio26"; + bias-disable; + }; + + pin_rxd { + function = "uart0"; + pins = "gpio27"; + bias-pull-up; + }; + }; + + sdio2_30_pins { + phandle = <0x48>; + + pin_clk { + function = "sd2"; + pins = "gpio30"; + bias-disable; + }; + + pin_cmd { + function = "sd2"; + pins = "gpio31"; + bias-pull-up; + }; + + pins_dat { + function = "sd2"; + pins = "gpio32", "gpio33", "gpio34", "gpio35"; + bias-pull-up; + }; + }; + + pwr_button_pins { + function = "gpio"; + pins = "gpio20"; + bias-pull-up; + phandle = <0x75>; + }; + + wl_on_pins { + function = "gpio"; + pins = "gpio28"; + phandle = <0x5a>; + }; + + bt_shutdown_pins { + function = "gpio"; + pins = "gpio29"; + phandle = <0x20>; + }; + + emmc_ds_pull { + pins = "emmc_ds"; + bias-pull-down; + phandle = <0x0a>; + }; + + emmc_cmddat_pulls { + pins = "emmc_cmd", "emmc_dat0", "emmc_dat1", "emmc_dat2", "emmc_dat3", "emmc_dat4", "emmc_dat5", "emmc_dat6", "emmc_dat7"; + bias-pull-up; + phandle = <0x09>; + }; + + spi10_gpio2 { + function = "vc_spi0"; + pins = "gpio2", "gpio3", "gpio4"; + bias-disable; + phandle = <0x1b>; + }; + + spi10_cs_gpio1 { + function = "gpio"; + pins = "gpio1"; + bias-pull-up; + phandle = <0x1c>; + }; + }; + + gpio@7d508500 { + compatible = "brcm,brcmstb-gpio"; + reg = <0x7d508500 0x40>; + interrupt-parent = <0x1e>; + interrupts = <0x00>; + gpio-controller; + #gpio-cells = <0x02>; + interrupt-controller; + #interrupt-cells = <0x02>; + brcm,gpio-bank-widths = <0x20 0x04>; + brcm,gpio-direct; + gpio-line-names = "-", "2712_BOOT_CS_N", "2712_BOOT_MISO", "2712_BOOT_MOSI", "2712_BOOT_SCLK", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "PWR_GPIO", "2712_G21_FS", "-", "-", "BT_RTS", "BT_CTS", "BT_TXD", "BT_RXD", "WL_ON", "BT_ON", "WIFI_SDIO_CLK", "WIFI_SDIO_CMD", "WIFI_SDIO_D0", "WIFI_SDIO_D1", "WIFI_SDIO_D2", "WIFI_SDIO_D3"; + phandle = <0x1a>; + }; + + serial@7d50c000 { + compatible = "brcm,bcm7271-uart"; + reg = <0x7d50c000 0x20>; + reg-names = "uart"; + reg-shift = <0x02>; + reg-io-width = <0x04>; + interrupts = <0x00 0x114 0x04>; + skip-init; + status = "okay"; + uart-has-rtscts; + auto-flow-control; + clock-frequency = <0x5b8d800>; + pinctrl-0 = <0x1f 0x20>; + pinctrl-names = "default"; + phandle = <0x91>; + + bluetooth { + compatible = "brcm,bcm43438-bt"; + max-speed = <0x2dc6c0>; + shutdown-gpios = <0x1a 0x1d 0x00>; + local-bd-address = [00 00 00 00 00 00]; + phandle = <0x5f>; + }; + }; + + pinctrl@7d510700 { + compatible = "brcm,bcm2712-aon-pinctrl"; + reg = <0x7d510700 0x20>; + phandle = <0x92>; + + i2c3_m4_agpio0_pins { + function = "vc_i2c3"; + pins = "aon_gpio0", "aon_gpio1"; + bias-pull-up; + phandle = <0x1d>; + }; + + bsc_m1_agpio13_pins { + function = "bsc_m1"; + pins = "aon_gpio13", "aon_gpio14"; + bias-pull-up; + phandle = <0x93>; + }; + + bsc_pmu_sgpio4_pins { + function = "avs_pmu_bsc"; + pins = "aon_sgpio4", "aon_sgpio5"; + phandle = <0x94>; + }; + + bsc_m2_sgpio4_pins { + function = "bsc_m2"; + pins = "aon_sgpio4", "aon_sgpio5"; + phandle = <0x95>; + }; + + pwm_aon_agpio1_pins { + function = "aon_pwm"; + pins = "aon_gpio1", "aon_gpio2"; + phandle = <0x96>; + }; + + pwm_aon_agpio4_pins { + function = "vc_pwm0"; + pins = "aon_gpio4", "aon_gpio5"; + phandle = <0x97>; + }; + + pwm_aon_agpio7_pins { + function = "aon_pwm"; + pins = "aon_gpio7", "aon_gpio9"; + phandle = <0x98>; + }; + + ant_pins { + function = "gpio"; + pins = "aon_gpio5", "aon_gpio6"; + phandle = <0x49>; + }; + + aon_pwm_1pin { + function = "aon_pwm"; + pins = "aon_gpio9"; + phandle = <0x99>; + }; + }; + + intc@7d517ac0 { + compatible = "brcm,bcm7271-l2-intc"; + reg = <0x7d517ac0 0x10>; + interrupts = <0x00 0xf5 0x04>; + interrupt-controller; + #interrupt-cells = <0x01>; + status = "disabled"; + phandle = <0x9a>; + }; + + avs-monitor@7d542000 { + compatible = "brcm,bcm2711-avs-monitor", "syscon", "simple-mfd"; + reg = <0x7d542000 0xf00>; + status = "okay"; + phandle = <0x9b>; + + thermal { + compatible = "brcm,bcm2711-thermal"; + #thermal-sensor-cells = <0x00>; + phandle = <0x51>; + }; + }; + + firmware { + compatible = "raspberrypi,bcm2835-firmware", "simple-mfd"; + #address-cells = <0x01>; + #size-cells = <0x01>; + mboxes = <0x21>; + dma-ranges; + phandle = <0x19>; + + clocks { + compatible = "raspberrypi,firmware-clocks"; + #clock-cells = <0x01>; + phandle = <0x16>; + }; + + reset { + compatible = "raspberrypi,firmware-reset"; + #reset-cells = <0x01>; + phandle = <0x9c>; + }; + + vcio { + compatible = "raspberrypi,vcio"; + phandle = <0x9d>; + }; + }; + + power { + compatible = "raspberrypi,bcm2835-power"; + firmware = <0x19>; + #power-domain-cells = <0x01>; + phandle = <0x46>; + }; + + fb { + compatible = "brcm,bcm2708-fb"; + firmware = <0x19>; + phandle = <0x9e>; + }; + + rpi_rtc { + compatible = "raspberrypi,rpi-rtc"; + firmware = <0x19>; + trickle-charge-microvolt = <0x00>; + phandle = <0x6c>; + }; + + nvmem { + compatible = "simple-bus"; + #address-cells = <0x01>; + #size-cells = <0x01>; + + nvmem_otp { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x19>; + reg = <0x00 0xc0>; + phandle = <0x9f>; + }; + + nvmem_cust { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x19>; + reg = <0x01 0x08>; + phandle = <0x67>; + }; + + nvmem_mac { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x19>; + reg = <0x02 0x06>; + phandle = <0x68>; + }; + + nvmem_priv { + compatible = "raspberrypi,rpi-otp"; + firmware = <0x19>; + reg = <0x03 0x10>; + phandle = <0x69>; + }; + }; + + fixedregulator_3v3 { + compatible = "regulator-fixed"; + regulator-always-on; + regulator-max-microvolt = <0x325aa0>; + regulator-min-microvolt = <0x325aa0>; + regulator-name = "3v3"; + phandle = <0xa0>; + }; + + fixedregulator_5v0 { + compatible = "regulator-fixed"; + regulator-always-on; + regulator-max-microvolt = <0x4c4b40>; + regulator-min-microvolt = <0x4c4b40>; + regulator-name = "5v0"; + phandle = <0xa1>; + }; + + gpiomem@7d508500 { + compatible = "raspberrypi,gpiomem"; + reg = <0x7d508500 0x40>; + chardev-name = "gpiomem1"; + }; + + gpiomem@7d517c00 { + compatible = "raspberrypi,gpiomem"; + reg = <0x7d517c00 0x40>; + chardev-name = "gpiomem2"; + }; + + gpiomem@7d504100 { + compatible = "raspberrypi,gpiomem"; + reg = <0x7d504100 0x20>; + chardev-name = "gpiomem3"; + }; + + gpiomem@7d510700 { + compatible = "raspberrypi,gpiomem"; + reg = <0x7d510700 0x20>; + chardev-name = "gpiomem4"; + }; + + sound { + status = "disabled"; + phandle = <0xa2>; + }; + }; + + axi { + compatible = "simple-bus"; + #address-cells = <0x02>; + #size-cells = <0x02>; + ranges = <0x00 0x00 0x00 0x00 0x10 0x00 0x10 0x00 0x10 0x00 0x01 0x00 0x14 0x00 0x14 0x00 0x04 0x00 0x18 0x00 0x18 0x00 0x04 0x00 0x1c 0x00 0x1c 0x00 0x04 0x00>; + dma-ranges = <0x00 0x00 0x00 0x00 0x10 0x00 0x10 0x00 0x10 0x00 0x01 0x00 0x14 0x00 0x14 0x00 0x04 0x00 0x18 0x00 0x18 0x00 0x04 0x00 0x1c 0x00 0x1c 0x00 0x04 0x00>; + phandle = <0xa3>; + + gpu { + compatible = "brcm,bcm2712-vc6"; + status = "disabled"; + phandle = <0xa4>; + }; + + pcie@1000100000 { + compatible = "brcm,bcm2712-pcie"; + reg = <0x10 0x100000 0x00 0x9310>; + device_type = "pci"; + linux,pci-domain = <0x00>; + max-link-speed = <0x02>; + num-lanes = <0x01>; + #address-cells = <0x03>; + #interrupt-cells = <0x01>; + #size-cells = <0x02>; + interrupt-parent = <0x01>; + interrupts = <0x00 0xd5 0x04 0x00 0xd6 0x04>; + interrupt-names = "pcie", "msi"; + interrupt-map-mask = <0x00 0x00 0x00 0x07>; + interrupt-map = <0x00 0x00 0x00 0x01 0x01 0x00 0xd1 0x04 0x00 0x00 0x00 0x02 0x01 0x00 0xd2 0x04 0x00 0x00 0x00 0x03 0x01 0x00 0xd3 0x04 0x00 0x00 0x00 0x04 0x01 0x00 0xd4 0x04>; + resets = <0x22 0x23 0x2a>; + reset-names = "rescal", "bridge"; + msi-controller; + msi-parent = <0x24>; + ranges = <0x2000000 0x00 0x00 0x17 0x00 0x00 0xfffffffc 0x43000000 0x04 0x00 0x14 0x00 0x03 0x00>; + dma-ranges = <0x43000000 0x10 0x00 0x00 0x00 0x10 0x00>; + status = "disabled"; + phandle = <0x24>; + }; + + pcie@1000110000 { + compatible = "brcm,bcm2712-pcie"; + reg = <0x10 0x110000 0x00 0x9310>; + device_type = "pci"; + linux,pci-domain = <0x01>; + max-link-speed = <0x02>; + num-lanes = <0x01>; + #address-cells = <0x03>; + #interrupt-cells = <0x01>; + #size-cells = <0x02>; + interrupt-parent = <0x01>; + interrupts = <0x00 0xdf 0x04 0x00 0xe0 0x04>; + interrupt-names = "pcie", "msi"; + interrupt-map-mask = <0x00 0x00 0x00 0x07>; + interrupt-map = <0x00 0x00 0x00 0x01 0x01 0x00 0xdb 0x04 0x00 0x00 0x00 0x02 0x01 0x00 0xdc 0x04 0x00 0x00 0x00 0x03 0x01 0x00 0xdd 0x04 0x00 0x00 0x00 0x04 0x01 0x00 0xde 0x04>; + resets = <0x22 0x23 0x2b>; + reset-names = "rescal", "bridge"; + msi-controller; + msi-parent = <0x25>; + ranges = <0x2000000 0x00 0x80000000 0x1b 0x80000000 0x00 0x80000000 0x43000000 0x04 0x00 0x18 0x00 0x03 0x80000000>; + dma-ranges = <0x3000000 0x10 0x00 0x00 0x00 0x10 0x00 0x3000000 0xff 0xfffff000 0x10 0x131000 0x00 0x1000>; + status = "disabled"; + brcm,fifo-qos-map = <0x3030303>; + phandle = <0x66>; + }; + + pcie@1000120000 { + compatible = "brcm,bcm2712-pcie"; + reg = <0x10 0x120000 0x00 0x9310>; + device_type = "pci"; + linux,pci-domain = <0x02>; + max-link-speed = <0x02>; + num-lanes = <0x04>; + #address-cells = <0x03>; + #interrupt-cells = <0x01>; + #size-cells = <0x02>; + interrupt-parent = <0x01>; + interrupts = <0x00 0xe9 0x04 0x00 0xea 0x04>; + interrupt-names = "pcie", "msi"; + interrupt-map-mask = <0x00 0x00 0x00 0x07>; + interrupt-map = <0x00 0x00 0x00 0x01 0x01 0x00 0xe5 0x04 0x00 0x00 0x00 0x02 0x01 0x00 0xe6 0x04 0x00 0x00 0x00 0x03 0x01 0x00 0xe7 0x04 0x00 0x00 0x00 0x04 0x01 0x00 0xe8 0x04>; + resets = <0x22 0x23 0x2c>; + reset-names = "rescal", "bridge"; + msi-controller; + msi-parent = <0x26>; + ranges = <0x2000000 0x00 0x00 0x1f 0x00 0x00 0xfffffffc 0x43000000 0x04 0x00 0x1c 0x00 0x03 0x00>; + dma-ranges = <0x2000000 0x00 0x00 0x1f 0x00 0x00 0x400000 0x43000000 0x10 0x00 0x00 0x00 0x10 0x00 0x3000000 0xff 0xfffff000 0x10 0x130000 0x00 0x1000>; + status = "okay"; + brcm,vdm-qos-map = <0x8080809 0xa0a0b0b>; + aspm-no-l0s; + phandle = <0xa5>; + + rp1 { + compatible = "simple-bus"; + #address-cells = <0x02>; + #size-cells = <0x02>; + #interrupt-cells = <0x02>; + interrupt-controller; + interrupt-parent = <0x27>; + ranges = <0xc0 0x40000000 0x2000000 0x00 0x00 0x00 0x410000>; + dma-ranges = <0x10 0x00 0x43000000 0x10 0x00 0x10 0x00 0xc0 0x40000000 0x2000000 0x00 0x00 0x00 0x410000 0x00 0x00 0x2000000 0x10 0x00 0x10 0x00>; + phandle = <0x27>; + + mailbox@8000 { + compatible = "raspberrypi,rp1-mbox"; + status = "okay"; + reg = <0xc0 0x40008000 0x00 0x4000>; + interrupts = <0x3a 0x04>; + #mbox-cells = <0x01>; + phandle = <0x5b>; + }; + + clocks@18000 { + compatible = "raspberrypi,rp1-clocks"; + #clock-cells = <0x01>; + reg = <0xc0 0x40018000 0x00 0x10038>; + clocks = <0x28>; + assigned-clocks = <0x02 0x00 0x02 0x01 0x02 0x03 0x02 0x09 0x02 0x10 0x02 0x04 0x02 0x0a 0x02 0x0c 0x02 0x06 0x02 0x0d 0x02 0x1f 0x02 0x20 0x02 0x1d>; + assigned-clock-rates = <0x3b9aca00 0x5b8d8000 0xbebc200 0x7735940 0x7735940 0x3a98000 0x927c000 0xbebc200 0x5f5e100 0x2faf080 0xf4240 0xbebc200 0x2faf080>; + phandle = <0x02>; + }; + + serial@30000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40030000 0x00 0x100>; + interrupts = <0x19 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + pinctrl-0 = <0x29>; + phandle = <0x6f>; + }; + + serial@34000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40034000 0x00 0x100>; + interrupts = <0x2a 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xa6>; + }; + + serial@38000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40038000 0x00 0x100>; + interrupts = <0x2b 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xa7>; + }; + + serial@3c000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x4003c000 0x00 0x100>; + interrupts = <0x2c 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xa8>; + }; + + serial@40000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40040000 0x00 0x100>; + interrupts = <0x2d 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xa9>; + }; + + serial@44000 { + compatible = "arm,pl011-axi"; + reg = <0xc0 0x40044000 0x00 0x100>; + interrupts = <0x2e 0x04>; + clocks = <0x02 0x0f 0x02 0x06>; + clock-names = "uartclk", "apb_pclk"; + pinctrl-names = "default"; + arm,primecell-periphid = <0x341011>; + uart-has-rtscts; + cts-event-workaround; + skip-init; + status = "disabled"; + phandle = <0xaa>; + }; + + spi@4c000 { + reg = <0xc0 0x4004c000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x38 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2a 0x37 0x2a 0x36>; + dma-names = "tx", "rx"; + status = "disabled"; + phandle = <0xab>; + }; + + spi@50000 { + reg = <0xc0 0x40050000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x13 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2a 0x0d 0x2a 0x0c>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x2b 0x2c>; + cs-gpios = <0x2d 0x08 0x01 0x2d 0x07 0x01>; + phandle = <0x6d>; + + spidev@0 { + compatible = "spidev"; + reg = <0x00>; + #address-cells = <0x01>; + #size-cells = <0x00>; + spi-max-frequency = <0x7735940>; + phandle = <0xac>; + }; + + spidev@1 { + compatible = "spidev"; + reg = <0x01>; + #address-cells = <0x01>; + #size-cells = <0x00>; + spi-max-frequency = <0x7735940>; + phandle = <0xad>; + }; + }; + + spi@54000 { + reg = <0xc0 0x40054000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x14 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2a 0x0f 0x2a 0x0e>; + dma-names = "tx", "rx"; + status = "disabled"; + phandle = <0xae>; + }; + + spi@58000 { + reg = <0xc0 0x40058000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x15 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2a 0x11 0x2a 0x10>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x2e>; + phandle = <0xaf>; + }; + + spi@5c000 { + reg = <0xc0 0x4005c000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x16 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2a 0x13 0x2a 0x12>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x2f>; + phandle = <0xb0>; + }; + + spi@60000 { + reg = <0xc0 0x40060000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x17 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x00>; + #size-cells = <0x00>; + num-cs = <0x01>; + spi-slave; + dmas = <0x2a 0x15 0x2a 0x14>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x30>; + phandle = <0xb1>; + + slave { + compatible = "spidev"; + spi-max-frequency = <0xf4240>; + }; + }; + + spi@64000 { + reg = <0xc0 0x40064000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x18 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2a 0x17 0x2a 0x16>; + dma-names = "tx", "rx"; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x31>; + phandle = <0xb2>; + }; + + spi@68000 { + reg = <0xc0 0x40068000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x36 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + dmas = <0x2a 0x33 0x2a 0x32>; + dma-names = "tx", "rx"; + status = "disabled"; + phandle = <0xb3>; + }; + + spi@6c000 { + reg = <0xc0 0x4006c000 0x00 0x130>; + compatible = "snps,dw-apb-ssi"; + interrupts = <0x37 0x04>; + clocks = <0x02 0x0c>; + clock-names = "ssi_clk"; + #address-cells = <0x00>; + #size-cells = <0x00>; + num-cs = <0x01>; + spi-slave; + dmas = <0x2a 0x35 0x2a 0x34>; + dma-names = "tx", "rx"; + status = "disabled"; + phandle = <0xb4>; + + slave { + compatible = "spidev"; + spi-max-frequency = <0xf4240>; + }; + }; + + i2c@70000 { + reg = <0xc0 0x40070000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x07 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-0 = <0x32>; + pinctrl-names = "default"; + clock-frequency = <0x186a0>; + symlink = "i2c-11"; + phandle = <0x64>; + }; + + i2c@74000 { + reg = <0xc0 0x40074000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x08 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x33>; + clock-frequency = <0x186a0>; + phandle = <0x63>; + }; + + i2c@78000 { + reg = <0xc0 0x40078000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x09 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x34>; + phandle = <0xb5>; + }; + + i2c@7c000 { + reg = <0xc0 0x4007c000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x0a 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x35>; + phandle = <0xb6>; + }; + + i2c@80000 { + reg = <0xc0 0x40080000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x0b 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + phandle = <0xb7>; + }; + + i2c@84000 { + reg = <0xc0 0x40084000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x0c 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + phandle = <0xb8>; + }; + + i2c@88000 { + reg = <0xc0 0x40088000 0x00 0x1000>; + compatible = "snps,designware-i2c"; + interrupts = <0x0d 0x04>; + clocks = <0x02 0x0c>; + i2c-scl-rising-time-ns = <0x41>; + i2c-scl-falling-time-ns = <0x64>; + status = "disabled"; + pinctrl-0 = <0x36>; + pinctrl-names = "default"; + clock-frequency = <0x186a0>; + symlink = "i2c-6"; + phandle = <0x65>; + }; + + audio_out@94000 { + compatible = "raspberrypi,rp1-audio-out"; + reg = <0xc0 0x40094000 0x00 0x4000>; + clocks = <0x02 0x14>; + assigned-clocks = <0x02 0x14>; + assigned-clock-rates = <0x927c000>; + assigned-clock-parents = <0x02 0x0a>; + dmas = <0x2a 0x1d>; + dma-maxburst = <0x04>; + dma-names = "tx"; + #sound-dai-cells = <0x00>; + status = "disabled"; + phandle = <0xb9>; + }; + + pwm@98000 { + compatible = "raspberrypi,rp1-pwm"; + reg = <0xc0 0x40098000 0x00 0x100>; + #pwm-cells = <0x03>; + clocks = <0x02 0x11>; + assigned-clocks = <0x02 0x11>; + assigned-clock-rates = <0x2faf080>; + status = "disabled"; + phandle = <0xba>; + }; + + pwm@9c000 { + compatible = "raspberrypi,rp1-pwm"; + reg = <0xc0 0x4009c000 0x00 0x100>; + #pwm-cells = <0x03>; + clocks = <0x02 0x12>; + assigned-clocks = <0x02 0x12>; + assigned-clock-rates = <0x2faf080>; + status = "disabled"; + pinctrl-0 = <0x37>; + pinctrl-names = "default"; + phandle = <0x61>; + }; + + i2s@a0000 { + reg = <0xc0 0x400a0000 0x00 0x1000>; + compatible = "snps,designware-i2s"; + clocks = <0x02 0x15>; + clock-names = "i2sclk"; + #sound-dai-cells = <0x00>; + dmas = <0x2a 0x20 0x2a 0x1f>; + dma-names = "tx", "rx"; + dma-maxburst = <0x04>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x38>; + phandle = <0xbb>; + }; + + i2s@a4000 { + reg = <0xc0 0x400a4000 0x00 0x1000>; + compatible = "snps,designware-i2s"; + clocks = <0x02 0x15>; + clock-names = "i2sclk"; + #sound-dai-cells = <0x00>; + dmas = <0x2a 0x22 0x2a 0x21>; + dma-names = "tx", "rx"; + dma-maxburst = <0x04>; + status = "disabled"; + pinctrl-names = "default"; + pinctrl-0 = <0x39>; + phandle = <0xbc>; + }; + + i2s@a8000 { + reg = <0xc0 0x400a8000 0x00 0x1000>; + compatible = "snps,designware-i2s"; + clocks = <0x02 0x15>; + status = "disabled"; + phandle = <0xbd>; + }; + + sdio_clk0@b0004 { + compatible = "raspberrypi,rp1-sdio-clk"; + reg = <0xc0 0x400b0004 0x00 0x1c>; + clocks = <0x3a 0x3b>; + clock-names = "src", "base"; + #clock-cells = <0x00>; + status = "disabled"; + phandle = <0x40>; + }; + + sdio_clk1@b4004 { + compatible = "raspberrypi,rp1-sdio-clk"; + reg = <0xc0 0x400b4004 0x00 0x1c>; + clocks = <0x3a 0x3b>; + clock-names = "src", "base"; + #clock-cells = <0x00>; + status = "disabled"; + phandle = <0x41>; + }; + + adc@c8000 { + compatible = "raspberrypi,rp1-adc"; + reg = <0xc0 0x400c8000 0x00 0x4000>; + clocks = <0x02 0x1e>; + clock-names = "adcclk"; + #clock-cells = <0x00>; + vref-supply = <0x3c>; + status = "okay"; + phandle = <0xbe>; + }; + + gpio@d0000 { + reg = <0xc0 0x400d0000 0x00 0xc000 0xc0 0x400e0000 0x00 0xc000 0xc0 0x400f0000 0x00 0xc000>; + compatible = "raspberrypi,rp1-gpio"; + interrupts = <0x00 0x04 0x01 0x04 0x02 0x04>; + gpio-controller; + #gpio-cells = <0x02>; + interrupt-controller; + #interrupt-cells = <0x02>; + gpio-ranges = <0x2d 0x00 0x00 0x36>; + status = "okay"; + gpio-line-names = "ID_SDA", "ID_SCL", "GPIO2", "GPIO3", "GPIO4", "GPIO5", "GPIO6", "GPIO7", "GPIO8", "GPIO9", "GPIO10", "GPIO11", "GPIO12", "GPIO13", "GPIO14", "GPIO15", "GPIO16", "GPIO17", "GPIO18", "GPIO19", "GPIO20", "GPIO21", "GPIO22", "GPIO23", "GPIO24", "GPIO25", "GPIO26", "GPIO27", "PCIE_PWR_EN", "FAN_TACH", "HOST_SDA", "HOST_SCL", "ETH_RST_N", "PCIE_DET_WAKE", "CD0_IO0_MICCLK", "CD0_IO0_MICDAT0", "RP1_PCIE_CLKREQ_N", "ETH_IRQ_N", "SDA0", "SCL0", "-", "-", "USB_VBUS_EN", "-", "RP1_STAT_LED", "FAN_PWM", "-", "2712_WAKE", "-", "-", "-", "-", "-", "-"; + phandle = <0x2d>; + + rp1_uart0_14_15 { + phandle = <0x29>; + + pin_txd { + function = "uart0"; + pins = "gpio14"; + bias-disable; + }; + + pin_rxd { + function = "uart0"; + pins = "gpio15"; + bias-pull-up; + }; + }; + + rp1_uart0_ctsrts_16_17 { + phandle = <0xbf>; + + pin_cts { + function = "uart0"; + pins = "gpio16"; + bias-pull-up; + }; + + pin_rts { + function = "uart0"; + pins = "gpio17"; + bias-disable; + }; + }; + + rp1_uart1_0_1 { + phandle = <0xc0>; + + pin_txd { + function = "uart1"; + pins = "gpio0"; + bias-disable; + }; + + pin_rxd { + function = "uart1"; + pins = "gpio1"; + bias-pull-up; + }; + }; + + rp1_uart1_ctsrts_2_3 { + phandle = <0xc1>; + + pin_cts { + function = "uart1"; + pins = "gpio2"; + bias-pull-up; + }; + + pin_rts { + function = "uart1"; + pins = "gpio3"; + bias-disable; + }; + }; + + rp1_uart2_4_5 { + phandle = <0xc2>; + + pin_txd { + function = "uart2"; + pins = "gpio4"; + bias-disable; + }; + + pin_rxd { + function = "uart2"; + pins = "gpio5"; + bias-pull-up; + }; + }; + + rp1_uart2_ctsrts_6_7 { + phandle = <0xc3>; + + pin_cts { + function = "uart2"; + pins = "gpio6"; + bias-pull-up; + }; + + pin_rts { + function = "uart2"; + pins = "gpio7"; + bias-disable; + }; + }; + + rp1_uart3_8_9 { + phandle = <0xc4>; + + pin_txd { + function = "uart3"; + pins = "gpio8"; + bias-disable; + }; + + pin_rxd { + function = "uart3"; + pins = "gpio9"; + bias-pull-up; + }; + }; + + rp1_uart3_ctsrts_10_11 { + phandle = <0xc5>; + + pin_cts { + function = "uart3"; + pins = "gpio10"; + bias-pull-up; + }; + + pin_rts { + function = "uart3"; + pins = "gpio11"; + bias-disable; + }; + }; + + rp1_uart4_12_13 { + phandle = <0xc6>; + + pin_txd { + function = "uart4"; + pins = "gpio12"; + bias-disable; + }; + + pin_rxd { + function = "uart4"; + pins = "gpio13"; + bias-pull-up; + }; + }; + + rp1_uart4_ctsrts_14_15 { + phandle = <0xc7>; + + pin_cts { + function = "uart4"; + pins = "gpio14"; + bias-pull-up; + }; + + pin_rts { + function = "uart4"; + pins = "gpio15"; + bias-disable; + }; + }; + + rp1_sdio0_22_27 { + phandle = <0xc8>; + + pin_clk { + function = "sd0"; + pins = "gpio22"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + + pin_cmd { + function = "sd0"; + pins = "gpio23"; + bias-pull-up; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + + pins_dat { + function = "sd0"; + pins = "gpio24", "gpio25", "gpio26", "gpio27"; + bias-pull-up; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + }; + + rp1_sdio1_28_33 { + phandle = <0xc9>; + + pin_clk { + function = "sd1"; + pins = "gpio28"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + + pin_cmd { + function = "sd1"; + pins = "gpio29"; + bias-pull-up; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + + pins_dat { + function = "sd1"; + pins = "gpio30", "gpio31", "gpio32", "gpio33"; + bias-pull-up; + drive-strength = <0x0c>; + slew-rate = <0x01>; + }; + }; + + rp1_i2s0_18_21 { + function = "i2s0"; + pins = "gpio18", "gpio19", "gpio20", "gpio21"; + bias-disable; + phandle = <0x38>; + }; + + rp1_i2s1_18_21 { + function = "i2s1"; + pins = "gpio18", "gpio19", "gpio20", "gpio21"; + bias-disable; + phandle = <0x39>; + }; + + rp1_i2c4_34_35 { + function = "i2c4"; + pins = "gpio34", "gpio35"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xca>; + }; + + rp1_i2c6_38_39 { + function = "i2c6"; + pins = "gpio38", "gpio39"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x36>; + }; + + rp1_i2c4_40_41 { + function = "i2c4"; + pins = "gpio40", "gpio41"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xcb>; + }; + + rp1_i2c5_44_45 { + function = "i2c5"; + pins = "gpio44", "gpio45"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xcc>; + }; + + rp1_i2c0_0_1 { + function = "i2c0"; + pins = "gpio0", "gpio1"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x32>; + }; + + rp1_i2c0_8_9 { + function = "i2c0"; + pins = "gpio8", "gpio9"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xcd>; + }; + + rp1_i2c1_2_3 { + function = "i2c1"; + pins = "gpio2", "gpio3"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x33>; + }; + + rp1_i2c1_10_11 { + function = "i2c1"; + pins = "gpio10", "gpio11"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xce>; + }; + + rp1_i2c2_4_5 { + function = "i2c2"; + pins = "gpio4", "gpio5"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x34>; + }; + + rp1_i2c2_12_13 { + function = "i2c2"; + pins = "gpio12", "gpio13"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xcf>; + }; + + rp1_i2c3_6_7 { + function = "i2c3"; + pins = "gpio6", "gpio7"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0x35>; + }; + + rp1_i2c3_14_15 { + function = "i2c3"; + pins = "gpio14", "gpio15"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xd0>; + }; + + rp1_i2c3_22_23 { + function = "i2c3"; + pins = "gpio22", "gpio23"; + drive-strength = <0x0c>; + bias-pull-up; + phandle = <0xd1>; + }; + + rp1_dpi_16bit_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19"; + bias-disable; + phandle = <0xd2>; + }; + + rp1_dpi_16bit_cpadhi_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24"; + bias-disable; + phandle = <0xd3>; + }; + + rp1_dpi_16bit_pad666_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25"; + bias-disable; + phandle = <0xd4>; + }; + + rp1_dpi_18bit_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21"; + bias-disable; + phandle = <0xd5>; + }; + + rp1_dpi_18bit_cpadhi_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25"; + bias-disable; + phandle = <0xd6>; + }; + + rp1_dpi_24bit_gpio2 { + function = "dpi"; + pins = "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25", "gpio26", "gpio27"; + bias-disable; + phandle = <0xd7>; + }; + + rp1_dpi_hvsync { + function = "dpi"; + pins = "gpio2", "gpio3"; + bias-disable; + phandle = <0xd8>; + }; + + rp1_dpi_16bit_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19"; + bias-disable; + phandle = <0xd9>; + }; + + rp1_dpi_16bit_cpadhi_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24"; + bias-disable; + phandle = <0xda>; + }; + + rp1_dpi_16bit_pad666_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25"; + bias-disable; + phandle = <0xdb>; + }; + + rp1_dpi_18bit_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21"; + bias-disable; + phandle = <0xdc>; + }; + + rp1_dpi_18bit_cpadhi_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25"; + bias-disable; + phandle = <0xdd>; + }; + + rp1_dpi_24bit_gpio0 { + function = "dpi"; + pins = "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21", "gpio22", "gpio23", "gpio24", "gpio25", "gpio26", "gpio27"; + bias-disable; + phandle = <0xde>; + }; + + rp1_gpclksrc0_gpio4 { + function = "gpclk0"; + pins = "gpio4"; + bias-disable; + phandle = <0xdf>; + }; + + rp1_gpclksrc0_gpio20 { + function = "gpclk0"; + pins = "gpio20"; + bias-disable; + phandle = <0xe0>; + }; + + rp1_gpclksrc1_gpio5 { + function = "gpclk1"; + pins = "gpio5"; + bias-disable; + phandle = <0xe1>; + }; + + rp1_gpclksrc1_gpio18 { + function = "gpclk1"; + pins = "gpio18"; + bias-disable; + phandle = <0xe2>; + }; + + rp1_gpclksrc1_gpio21 { + function = "gpclk1"; + pins = "gpio21"; + bias-disable; + phandle = <0xe3>; + }; + + rp1_pwm1_gpio45 { + function = "pwm1"; + pins = "gpio45"; + bias-pull-down; + phandle = <0x37>; + }; + + rp1_spi0_gpio9 { + function = "spi0"; + pins = "gpio9", "gpio10", "gpio11"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x2b>; + }; + + rp1_spi0_cs_gpio7 { + function = "spi0"; + pins = "gpio7", "gpio8"; + bias-pull-up; + phandle = <0x2c>; + }; + + rp1_spi1_gpio19 { + function = "spi1"; + pins = "gpio19", "gpio20", "gpio21"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0xe4>; + }; + + rp1_spi2_gpio1 { + function = "spi2"; + pins = "gpio1", "gpio2", "gpio3"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x2e>; + }; + + rp1_spi3_gpio5 { + function = "spi3"; + pins = "gpio5", "gpio6", "gpio7"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x2f>; + }; + + rp1_spi4_gpio9 { + function = "spi4"; + pins = "gpio9", "gpio10", "gpio11"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x30>; + }; + + rp1_spi5_gpio13 { + function = "spi5"; + pins = "gpio13", "gpio14", "gpio15"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0x31>; + }; + + rp1_spi8_gpio49 { + function = "spi8"; + pins = "gpio49", "gpio50", "gpio51"; + bias-disable; + drive-strength = <0x0c>; + slew-rate = <0x01>; + phandle = <0xe5>; + }; + + rp1_spi8_cs_gpio52 { + function = "spi0"; + pins = "gpio52", "gpio53"; + bias-pull-up; + phandle = <0xe6>; + }; + + rp1_audio_out_12_13 { + function = "aaud"; + pins = "gpio12", "gpio13"; + bias-disable; + phandle = <0xe7>; + }; + + usb_vbus_pins { + function = "vbus1"; + pins = "gpio42", "gpio43"; + phandle = <0x42>; + }; + + micclk1_hog { + gpio-hog; + gpios = <0x2e 0x00>; + output-high; + }; + + micdat1_hog { + gpio-hog; + gpios = <0x30 0x00>; + output-high; + }; + }; + + ethernet@100000 { + reg = <0xc0 0x40100000 0x00 0x4000>; + compatible = "raspberrypi,rp1-gem", "cdns,macb"; + #address-cells = <0x01>; + #size-cells = <0x00>; + interrupts = <0x06 0x04>; + clocks = <0x02 0x0c 0x02 0x0c 0x02 0x1d 0x02 0x10>; + clock-names = "pclk", "hclk", "tsu_clk", "tx_clk"; + phy-mode = "rgmii-id"; + cdns,aw2w-max-pipe = [08]; + cdns,ar2r-max-pipe = [08]; + cdns,use-aw2b-fill; + local-mac-address = [00 00 00 00 00 00]; + status = "okay"; + phy-handle = <0x3d>; + phy-reset-gpios = <0x2d 0x20 0x01>; + phy-reset-duration = <0x05>; + phandle = <0xe8>; + + ethernet-phy@1 { + reg = <0x01>; + brcm,powerdown-enable; + interrupt-parent = <0x2d>; + interrupts = <0x25 0x08>; + eee-broken-1000t; + eee-broken-100tx; + phandle = <0x3d>; + }; + }; + + csi@110000 { + compatible = "raspberrypi,rp1-cfe"; + reg = <0xc0 0x40110000 0x00 0x100 0xc0 0x40114000 0x00 0x100 0xc0 0x40120000 0x00 0x100 0xc0 0x40124000 0x00 0x1000>; + interrupts = <0x2f 0x04>; + clocks = <0x02 0x16>; + assigned-clocks = <0x02 0x16>; + assigned-clock-rates = <0x17d7840>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + iommus = <0x3e>; + phandle = <0xe9>; + }; + + csi@128000 { + compatible = "raspberrypi,rp1-cfe"; + reg = <0xc0 0x40128000 0x00 0x100 0xc0 0x4012c000 0x00 0x100 0xc0 0x40138000 0x00 0x100 0xc0 0x4013c000 0x00 0x1000>; + interrupts = <0x30 0x04>; + clocks = <0x02 0x17>; + assigned-clocks = <0x02 0x17>; + assigned-clock-rates = <0x17d7840>; + #address-cells = <0x01>; + #size-cells = <0x00>; + status = "disabled"; + iommus = <0x3e>; + phandle = <0xea>; + }; + + pio@178000 { + reg = <0xc0 0x40178000 0x00 0x20>; + compatible = "raspberrypi,rp1-pio"; + firmware = <0x3f>; + dmas = <0x2a 0x38 0x2a 0x39 0x2a 0x3a 0x2a 0x3b 0x2a 0x3c 0x2a 0x3d 0x2a 0x3e 0x2a 0x3f>; + dma-names = "tx0", "rx0", "tx1", "rx1", "tx2", "rx2", "tx3", "rx3"; + status = "okay"; + phandle = <0xeb>; + }; + + mmc@180000 { + reg = <0xc0 0x40180000 0x00 0x100>; + compatible = "raspberrypi,rp1-dwcmshc"; + interrupts = <0x11 0x04>; + clocks = <0x02 0x0c 0x3b 0x02 0x1f 0x40>; + clock-names = "bus", "core", "timeout", "sdio"; + no-1-8-v; + bus-width = <0x04>; + vmmc-supply = <0x3c>; + broken-cd; + status = "disabled"; + phandle = <0xec>; + }; + + mmc@184000 { + reg = <0xc0 0x40184000 0x00 0x100>; + compatible = "raspberrypi,rp1-dwcmshc"; + interrupts = <0x12 0x04>; + clocks = <0x02 0x0c 0x3b 0x02 0x1f 0x41>; + clock-names = "bus", "core", "timeout", "sdio"; + bus-width = <0x04>; + vmmc-supply = <0x3c>; + sdhci-caps-mask = <0x03 0x00>; + broken-cd; + status = "disabled"; + phandle = <0xed>; + }; + + dma@188000 { + reg = <0xc0 0x40188000 0x00 0x1000>; + compatible = "snps,axi-dma-1.01a"; + interrupts = <0x28 0x04>; + clocks = <0x02 0x0e 0x02 0x0c>; + clock-names = "core-clk", "cfgr-clk"; + #dma-cells = <0x01>; + dma-channels = <0x08>; + snps,dma-masters = <0x01>; + snps,dma-targets = <0x40>; + snps,data-width = <0x04>; + snps,block-size = <0x40000 0x40000 0x40000 0x40000 0x40000 0x40000 0x40000 0x40000>; + snps,priority = <0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07>; + snps,axi-max-burst-len = <0x04>; + status = "okay"; + phandle = <0x2a>; + }; + + usb@200000 { + reg = <0xc0 0x40200000 0x00 0x100000>; + compatible = "snps,dwc3"; + dr_mode = "host"; + usb3-lpm-capable; + snps,axi-pipe-limit = [08]; + snps,dis_rxdet_inp3_quirk; + snps,enhanced-nak-fs-quirk; + snps,parkmode-disable-ss-quirk; + snps,parkmode-disable-hs-quirk; + snps,parkmode-disable-fsls-quirk; + snps,tx-max-burst = [08]; + snps,tx-thr-num-pkt = [02]; + interrupts = <0x1f 0x01>; + status = "okay"; + pinctrl-0 = <0x42>; + pinctrl-names = "default"; + phandle = <0xee>; + }; + + usb@300000 { + reg = <0xc0 0x40300000 0x00 0x100000>; + compatible = "snps,dwc3"; + dr_mode = "host"; + usb3-lpm-capable; + snps,axi-pipe-limit = [08]; + snps,dis_rxdet_inp3_quirk; + snps,enhanced-nak-fs-quirk; + snps,parkmode-disable-ss-quirk; + snps,parkmode-disable-hs-quirk; + snps,parkmode-disable-fsls-quirk; + snps,tx-max-burst = [08]; + snps,tx-thr-num-pkt = [02]; + interrupts = <0x24 0x01>; + status = "okay"; + phandle = <0xef>; + }; + + dsi@110000 { + compatible = "raspberrypi,rp1dsi"; + status = "disabled"; + reg = <0xc0 0x40118000 0x00 0x1000 0xc0 0x4011c000 0x00 0x1000 0xc0 0x40120000 0x00 0x1000>; + interrupts = <0x2f 0x04>; + clocks = <0x02 0x16 0x02 0x29 0x02 0x2d 0x28 0x02 0x03>; + clock-names = "cfgclk", "dpiclk", "byteclk", "refclk", "pllsys"; + assigned-clocks = <0x02 0x16>; + assigned-clock-rates = <0x17d7840>; + iommus = <0x3e>; + phandle = <0xf0>; + }; + + dsi@128000 { + compatible = "raspberrypi,rp1dsi"; + status = "disabled"; + reg = <0xc0 0x40130000 0x00 0x1000 0xc0 0x40134000 0x00 0x1000 0xc0 0x40138000 0x00 0x1000>; + interrupts = <0x30 0x04>; + clocks = <0x02 0x17 0x02 0x2a 0x02 0x2e 0x28 0x02 0x03>; + clock-names = "cfgclk", "dpiclk", "byteclk", "refclk", "pllsys"; + assigned-clocks = <0x02 0x17>; + assigned-clock-rates = <0x17d7840>; + iommus = <0x3e>; + phandle = <0xf1>; + }; + + vec@144000 { + compatible = "raspberrypi,rp1vec"; + status = "disabled"; + reg = <0xc0 0x40144000 0x00 0x1000 0xc0 0x40140000 0x00 0x1000>; + interrupts = <0x31 0x04>; + clocks = <0x02 0x27>; + assigned-clocks = <0x02 0x02 0x02 0x0b 0x02 0x27>; + assigned-clock-rates = <0x46cf7100 0x66ff300 0x66ff300>; + assigned-clock-parents = <0x00 0x02 0x02 0x02 0x0b>; + iommus = <0x3e>; + phandle = <0xf2>; + }; + + dpi@148000 { + compatible = "raspberrypi,rp1dpi"; + status = "disabled"; + reg = <0xc0 0x40148000 0x00 0x1000 0xc0 0x40140000 0x00 0x1000>; + interrupts = <0x31 0x04>; + clocks = <0x02 0x28 0x02 0x05 0x02 0x02>; + clock-names = "dpiclk", "plldiv", "pllcore"; + assigned-clocks = <0x02 0x28>; + assigned-clock-parents = <0x02 0x05>; + iommus = <0x3e>; + phandle = <0xf3>; + }; + + sram@400000 { + compatible = "mmio-sram"; + reg = <0xc0 0x40400000 0x00 0x10000>; + #address-cells = <0x01>; + #size-cells = <0x01>; + ranges = <0x00 0xc0 0x40400000 0x10000>; + phandle = <0xf4>; + + shmem@ff00 { + compatible = "raspberrypi,rp1-shmem"; + reg = <0xff00 0x100>; + phandle = <0x5c>; + }; + }; + + gpiomem@d0000 { + compatible = "raspberrypi,gpiomem"; + reg = <0xc0 0x400d0000 0x00 0x30000>; + chardev-name = "gpiomem0"; + }; + }; + }; + + msi-controller@1000130000 { + compatible = "brcm,bcm2712-mip"; + reg = <0x10 0x130000 0x00 0xc0 0xff 0xfffff000 0x00 0x1000>; + msi-controller; + msi-ranges = <0x01 0x00 0x80 0x01 0x40>; + brcm,msi-offset = <0x00>; + phandle = <0x26>; + }; + + msi-controller@1000131000 { + compatible = "brcm,bcm2712-mip"; + reg = <0x10 0x131000 0x00 0xc0 0xff 0xfffff000 0x00 0x1000>; + msi-controller; + msi-ranges = <0x01 0x00 0xf7 0x01 0x08>; + brcm,msi-offset = <0x08>; + phandle = <0x25>; + }; + + iommu@5100 { + compatible = "brcm,bcm2712-iommu"; + reg = <0x10 0x5100 0x00 0x80>; + cache = <0x43>; + #iommu-cells = <0x00>; + phandle = <0x47>; + }; + + iommu@5200 { + compatible = "brcm,bcm2712-iommu"; + reg = <0x10 0x5200 0x00 0x80>; + cache = <0x43>; + #iommu-cells = <0x00>; + #interconnect-cells = <0x00>; + phandle = <0x4c>; + }; + + iommu@5280 { + compatible = "brcm,bcm2712-iommu"; + reg = <0x10 0x5280 0x00 0x80>; + cache = <0x43>; + #iommu-cells = <0x00>; + dma-iova-offset = <0x10 0x00>; + phandle = <0x3e>; + }; + + iommuc@5b00 { + compatible = "brcm,bcm2712-iommuc"; + reg = <0x10 0x5b00 0x00 0x80>; + phandle = <0x43>; + }; + + dma@10000 { + compatible = "brcm,bcm2712-dma"; + reg = <0x10 0x10000 0x00 0x600>; + interrupts = <0x00 0x50 0x04 0x00 0x51 0x04 0x00 0x52 0x04 0x00 0x53 0x04 0x00 0x54 0x04 0x00 0x55 0x04>; + interrupt-names = "dma0", "dma1", "dma2", "dma3", "dma4", "dma5"; + #dma-cells = <0x01>; + brcm,dma-channel-mask = <0x3f>; + phandle = <0xf5>; + }; + + dma@10600 { + compatible = "brcm,bcm2712-dma"; + reg = <0x10 0x10600 0x00 0x600>; + interrupts = <0x00 0x56 0x04 0x00 0x57 0x04 0x00 0x58 0x04 0x00 0x59 0x04 0x00 0x5a 0x04 0x00 0x5b 0x04>; + interrupt-names = "dma6", "dma7", "dma8", "dma9", "dma10", "dma11"; + #dma-cells = <0x01>; + brcm,dma-channel-mask = <0x7c0>; + phandle = <0x15>; + }; + + syscon@400018 { + compatible = "brcm,syscon-piarbctl", "syscon", "simple-mfd"; + reg = <0x10 0x400018 0x00 0x18>; + phandle = <0xf6>; + }; + + usb@480000 { + compatible = "brcm,bcm2835-usb"; + reg = <0x10 0x480000 0x00 0x10000>; + interrupts = <0x00 0x49 0x04>; + #address-cells = <0x01>; + #size-cells = <0x00>; + clocks = <0x44>; + clock-names = "otg"; + phys = <0x45>; + phy-names = "usb2-phy"; + status = "disabled"; + power-domains = <0x46 0x06>; + phandle = <0xf7>; + }; + + codec@800000 { + compatible = "brcm,bcm2712-hevc-dec", "raspberrypi,hevc-dec"; + reg = <0x10 0x800000 0x00 0x10000 0x10 0x840000 0x00 0x1000>; + reg-names = "hevc", "intc"; + interrupts = <0x00 0x62 0x04>; + clocks = <0x16 0x0b>; + clock-names = "hevc"; + iommus = <0x47>; + phandle = <0xf8>; + }; + + pisp_be@880000 { + compatible = "raspberrypi,pispbe"; + reg = <0x10 0x880000 0x00 0x4000>; + interrupts = <0x00 0x48 0x04>; + clocks = <0x16 0x07>; + clocks-names = "isp_be"; + status = "okay"; + iommus = <0x47>; + phandle = <0xf9>; + }; + + mmc@1100000 { + compatible = "brcm,bcm2712-sdhci"; + reg = <0x10 0x1100000 0x00 0x260 0x10 0x1100400 0x00 0x200>; + reg-names = "host", "cfg"; + interrupts = <0x00 0x112 0x04>; + clocks = <0x08>; + sdhci-caps-mask = <0xc000 0x00>; + sdhci-caps = <0x00 0x00>; + supports-cqe = <0x01>; + mmc-ddr-3_3v; + status = "okay"; + pinctrl-0 = <0x48 0x49>; + pinctrl-names = "default"; + bus-width = <0x04>; + vmmc-supply = <0x4a>; + sd-uhs-ddr50; + non-removable; + #address-cells = <0x01>; + #size-cells = <0x00>; + phandle = <0xfa>; + + wifi@1 { + reg = <0x01>; + compatible = "brcm,bcm4329-fmac"; + local-mac-address = [00 00 00 00 00 00]; + phandle = <0x70>; + }; + }; + + v3d@2000000 { + compatible = "brcm,2712-v3d"; + reg = <0x10 0x2000000 0x00 0x4000 0x10 0x2008000 0x00 0x6000 0x10 0x2030800 0x00 0x700>; + reg-names = "hub", "core0", "sms"; + power-domains = <0x4b 0x01>; + resets = <0x4b 0x00>; + clocks = <0x16 0x05>; + clocks-names = "v3d"; + interrupts = <0x00 0xfa 0x04 0x00 0xf9 0x04>; + status = "disabled"; + phandle = <0xfb>; + }; + }; + + timer { + compatible = "arm,armv8-timer"; + interrupts = <0x01 0x0d 0xf08 0x01 0x0e 0xf08 0x01 0x0b 0xf08 0x01 0x0a 0xf08 0x01 0x0c 0xf08>; + }; + + clk-27M { + #clock-cells = <0x00>; + compatible = "fixed-clock"; + clock-frequency = <0x19bfcc0>; + clock-output-names = "27MHz-clock"; + phandle = <0x17>; + }; + + clk-108M { + #clock-cells = <0x00>; + compatible = "fixed-clock"; + clock-frequency = <0x66ff300>; + clock-output-names = "108MHz-clock"; + phandle = <0x10>; + }; + + hvs@107c580000 { + compatible = "brcm,bcm2712-hvs"; + reg = <0x10 0x7c580000 0x1a000>; + interrupt-parent = <0x0f>; + interrupts = <0x02 0x09 0x10>; + interrupt-names = "ch0-eof", "ch1-eof", "ch2-eof"; + iommus = <0x4c>; + status = "disabled"; + clocks = <0x16 0x04 0x16 0x10>; + clock-names = "core", "disp"; + phandle = <0xfc>; + }; + + arm-pmu { + compatible = "arm,cortex-a76-pmu"; + interrupts = <0x00 0x10 0x04 0x00 0x11 0x04 0x00 0x12 0x04 0x00 0x13 0x04>; + interrupt-affinity = <0x4d 0x4e 0x4f 0x50>; + }; + + thermal-zones { + + cpu-thermal { + polling-delay-passive = <0x3e8>; + polling-delay = <0x3e8>; + coefficients = <0xfffffdda 0x6ddd0>; + thermal-sensors = <0x51>; + phandle = <0xfd>; + + trips { + phandle = <0xfe>; + + cpu-crit { + temperature = <0x1adb0>; + hysteresis = <0x00>; + type = "critical"; + phandle = <0x57>; + }; + + cpu-tepid { + temperature = <0xc350>; + hysteresis = <0x1388>; + type = "active"; + phandle = <0x52>; + }; + + cpu-warm { + temperature = <0xea60>; + hysteresis = <0x1388>; + type = "active"; + phandle = <0x54>; + }; + + cpu-hot { + temperature = <0x107ac>; + hysteresis = <0x1388>; + type = "active"; + phandle = <0x55>; + }; + + cpu-vhot { + temperature = <0x124f8>; + hysteresis = <0x1388>; + type = "active"; + phandle = <0x56>; + }; + }; + + cooling-maps { + phandle = <0xff>; + + tepid { + trip = <0x52>; + cooling-device = <0x53 0x01 0x01>; + }; + + warm { + trip = <0x54>; + cooling-device = <0x53 0x02 0x02>; + }; + + hot { + trip = <0x55>; + cooling-device = <0x53 0x03 0x03>; + }; + + vhot { + trip = <0x56>; + cooling-device = <0x53 0x04 0x04>; + }; + + melt { + trip = <0x57>; + cooling-device = <0x53 0x04 0x04>; + }; + }; + }; + }; + + firmwarekms { + compatible = "raspberrypi,rpi-firmware-kms-2712"; + interrupt-parent = <0x58>; + interrupts = <0x13>; + brcm,firmware = <0x19>; + status = "disabled"; + phandle = <0x100>; + }; + + phy { + compatible = "usb-nop-xceiv"; + #phy-cells = <0x00>; + phandle = <0x45>; + }; + + memory@0 { + device_type = "memory"; + reg = <0x00 0x00 0x28000000>; + }; + + leds { + compatible = "gpio-leds"; + phandle = <0x101>; + + led-pwr { + label = "PWR"; + gpios = <0x2d 0x2c 0x01>; + default-state = "off"; + linux,default-trigger = "none"; + phandle = <0x6a>; + }; + + led-act { + label = "ACT"; + gpios = <0x59 0x09 0x01>; + default-state = "off"; + linux,default-trigger = "mmc0"; + phandle = <0x5d>; + }; + }; + + sd-io-1v8-reg { + compatible = "regulator-gpio"; + regulator-name = "vdd-sd-io"; + regulator-min-microvolt = <0x1b7740>; + regulator-max-microvolt = <0x325aa0>; + regulator-always-on; + regulator-settling-time-us = <0x1388>; + gpios = <0x59 0x03 0x00>; + states = <0x1b7740 0x01 0x325aa0 0x00>; + phandle = <0x0b>; + }; + + sd-vcc-reg { + compatible = "regulator-fixed"; + regulator-name = "vcc-sd"; + regulator-min-microvolt = <0x325aa0>; + regulator-max-microvolt = <0x325aa0>; + regulator-boot-on; + enable-active-high; + gpios = <0x59 0x04 0x00>; + phandle = <0x0c>; + }; + + wl-on-reg { + compatible = "regulator-fixed"; + regulator-name = "wl-on-regulator"; + regulator-min-microvolt = <0x325aa0>; + regulator-max-microvolt = <0x325aa0>; + pinctrl-0 = <0x5a>; + pinctrl-names = "default"; + gpio = <0x1a 0x1c 0x00>; + startup-delay-us = <0x249f0>; + enable-active-high; + phandle = <0x4a>; + }; + + cam1_clk { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + status = "disabled"; + phandle = <0x102>; + }; + + cam0_clk { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + status = "disabled"; + phandle = <0x103>; + }; + + cam0_reg { + compatible = "regulator-fixed"; + regulator-name = "cam0_reg"; + enable-active-high; + gpio = <0x2d 0x22 0x00>; + phandle = <0x71>; + }; + + cam_dummy_reg { + compatible = "regulator-fixed"; + regulator-name = "cam-dummy-reg"; + phandle = <0x104>; + }; + + dummy { + phandle = <0x105>; + }; + + i2c0if { + phandle = <0x106>; + }; + + i2c0mux { + phandle = <0x107>; + }; + + rp1_firmware { + compatible = "raspberrypi,rp1-firmware", "simple-mfd"; + mboxes = <0x5b 0x00>; + shmem = <0x5c>; + phandle = <0x3f>; + }; + + rp1_vdd_3v3 { + compatible = "regulator-fixed"; + regulator-name = "vdd-3v3"; + regulator-min-microvolt = <0x325aa0>; + regulator-max-microvolt = <0x325aa0>; + regulator-always-on; + phandle = <0x3c>; + }; + + chosen { + bootargs = "reboot=w coherent_pool=1M 8250.nr_uarts=1 pci=pcie_bus_safe cgroup_disable=memory numa_policy=interleave nvme.max_host_mem_size_mb=0"; + stdout-path = "serial10:115200n8"; + phandle = <0x6e>; + }; + + aliases { + blconfig = "/reserved-memory/nvram@0"; + blpubkey = "/reserved-memory/nvram@1"; + bluetooth = "/soc@107c000000/serial@7d50c000/bluetooth"; + console = "/soc@107c000000/serial@7d001000"; + drm-dsi1 = "/axi/pcie@1000120000/rp1/dsi@110000"; + drm-dsi2 = "/axi/pcie@1000120000/rp1/dsi@128000"; + ethernet0 = "/axi/pcie@1000120000/rp1/ethernet@100000"; + fb = "/soc@107c000000/fb"; + gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000"; + gpio1 = "/soc@107c000000/gpio@7d508500"; + gpio2 = "/soc@107c000000/gpio@7d517c00"; + gpio3 = "/soc@107c000000/pinctrl@7d504100"; + gpio4 = "/soc@107c000000/pinctrl@7d510700"; + gpiochip0 = "/axi/pcie@1000120000/rp1/gpio@d0000"; + gpiochip10 = "/soc@107c000000/gpio@7d508500"; + i2c = "/axi/pcie@1000120000/rp1/i2c@74000"; + i2c0 = "/axi/pcie@1000120000/rp1/i2c@70000"; + i2c1 = "/axi/pcie@1000120000/rp1/i2c@74000"; + i2c2 = "/axi/pcie@1000120000/rp1/i2c@78000"; + i2c3 = "/axi/pcie@1000120000/rp1/i2c@7c000"; + i2c10 = "/axi/pcie@1000120000/rp1/i2c@88000"; + i2c11 = "/axi/pcie@1000120000/rp1/i2c@70000"; + i2c12 = "/soc@107c000000/i2c@7d005600"; + mailbox = "/soc@107c000000/mailbox@7c013880"; + mmc0 = "/soc@107c000000/mmc@fff000"; + pio0 = "/axi/pcie@1000120000/rp1/pio@178000"; + serial0 = "/axi/pcie@1000120000/rp1/serial@30000"; + serial1 = "/axi/pcie@1000120000/rp1/serial@34000"; + serial10 = "/soc@107c000000/serial@7d001000"; + serial2 = "/axi/pcie@1000120000/rp1/serial@38000"; + serial3 = "/axi/pcie@1000120000/rp1/serial@3c000"; + serial4 = "/axi/pcie@1000120000/rp1/serial@40000"; + spi0 = "/axi/pcie@1000120000/rp1/spi@50000"; + spi1 = "/axi/pcie@1000120000/rp1/spi@54000"; + spi10 = "/soc@107c000000/spi@7d004000"; + spi2 = "/axi/pcie@1000120000/rp1/spi@58000"; + spi3 = "/axi/pcie@1000120000/rp1/spi@5c000"; + spi4 = "/axi/pcie@1000120000/rp1/spi@60000"; + spi5 = "/axi/pcie@1000120000/rp1/spi@64000"; + uart0 = "/axi/pcie@1000120000/rp1/serial@30000"; + uart1 = "/axi/pcie@1000120000/rp1/serial@34000"; + uart10 = "/soc@107c000000/serial@7d001000"; + uart2 = "/axi/pcie@1000120000/rp1/serial@38000"; + uart3 = "/axi/pcie@1000120000/rp1/serial@3c000"; + uart4 = "/axi/pcie@1000120000/rp1/serial@40000"; + usb0 = "/axi/pcie@1000120000/rp1/usb@200000"; + usb1 = "/axi/pcie@1000120000/rp1/usb@300000"; + wifi0 = "/axi/mmc@1100000/wifi@1"; + phandle = <0x62>; + }; + + __overrides__ { + act_led_gpio = [00 00 00 5d 67 70 69 6f 73 3a 34 00 00 00 00 5d 67 70 69 6f 73 3a 30 3d 00 00 00 00 2d]; + act_led_activelow = "", "", "", "]gpios:8"; + act_led_trigger = "", "", "", "]linux,default-trigger"; + axiperf = "", "", "", "^status"; + bdaddr = "", "", "", "_local-bd-address["; + button_debounce = "", "", "", "`debounce-interval:0"; + cooling_fan = "", "", "", "Sstatus", "", "", "", "astatus"; + drm_fb0_rp1_dpi = "", "", "", "bdrm-fb0=", "/axi/pcie@1000120000/rp1/dpi@148000"; + drm_fb0_rp1_dsi0 = "", "", "", "bdrm-fb0=", "/axi/pcie@1000120000/rp1/dsi@110000"; + drm_fb0_rp1_dsi1 = "", "", "", "bdrm-fb0=", "/axi/pcie@1000120000/rp1/dsi@128000"; + drm_fb0_vc4 = "", "", "", "bdrm-fb0=", "/axi/gpu"; + drm_fb1_rp1_dpi = "", "", "", "bdrm-fb1=", "/axi/pcie@1000120000/rp1/dpi@148000"; + drm_fb1_rp1_dsi0 = "", "", "", "bdrm-fb1=", "/axi/pcie@1000120000/rp1/dsi@110000"; + drm_fb1_rp1_dsi1 = "", "", "", "bdrm-fb1=", "/axi/pcie@1000120000/rp1/dsi@128000"; + drm_fb1_vc4 = "", "", "", "bdrm-fb1=", "/axi/gpu"; + drm_fb2_rp1_dpi = "", "", "", "bdrm-fb2=", "/axi/pcie@1000120000/rp1/dpi@148000"; + drm_fb2_rp1_dsi0 = "", "", "", "bdrm-fb2=", "/axi/pcie@1000120000/rp1/dsi@110000"; + drm_fb2_rp1_dsi1 = "", "", "", "bdrm-fb2=", "/axi/pcie@1000120000/rp1/dsi@128000"; + drm_fb2_vc4 = "", "", "", "bdrm-fb2=", "/axi/gpu"; + eth_led0 = "", "", "", "=led-modes:0"; + eth_led1 = "", "", "", "=led-modes:4"; + fan_temp0 = "", "", "", "Rtemperature:0"; + fan_temp0_hyst = "", "", "", "Rhysteresis:0"; + fan_temp0_speed = "", "", "", "Scooling-levels:4"; + fan_temp1 = "", "", "", "Ttemperature:0"; + fan_temp1_hyst = "", "", "", "Thysteresis:0"; + fan_temp1_speed = "", "", "", "Scooling-levels:8"; + fan_temp2 = "", "", "", "Utemperature:0"; + fan_temp2_hyst = "", "", "", "Uhysteresis:0"; + fan_temp2_speed = "", "", "", "Scooling-levels:12"; + fan_temp3 = "", "", "", "Vtemperature:0"; + fan_temp3_hyst = "", "", "", "Vhysteresis:0"; + fan_temp3_speed = "", "", "", "Scooling-levels:16"; + i2c = "", "", "", "cstatus"; + i2c_arm = "", "", "", "cstatus"; + i2c_arm_baudrate = "", "", "", "cclock-frequency:0"; + i2c_baudrate = "", "", "", "cclock-frequency:0"; + i2c_csi_dsi = "", "", "", "dstatus"; + i2c_csi_dsi0 = "", "", "", "estatus"; + i2c_csi_dsi1 = "", "", "", "dstatus"; + i2c_vc = "", "", "", "dstatus"; + i2c_vc_baudrate = "", "", "", "dclock-frequency:0"; + i2c0 = "", "", "", "dstatus"; + i2c0_baudrate = "", "", "", "dclock-frequency:0"; + i2c1 = "", "", "", "cstatus"; + i2c1_baudrate = "", "", "", "cclock-frequency:0"; + krnbt = "", "", "", "_status"; + nvme = "", "", "", "fstatus"; + nvmem_cust_rw = "", "", "", "grw?"; + nvmem_mac_rw = "", "", "", "hrw?"; + nvmem_priv_rw = "", "", "", "irw?"; + pcie_tperst_clk_ms = "", "", "", "fbrcm,tperst-clk-ms:0"; + pciex1 = "", "", "", "fstatus"; + pciex1_gen = "", "", "", "fmax-link-speed:0"; + pciex1_no_l0s = "", "", "", "faspm-no-l0s?"; + pciex1_tperst_clk_ms = "", "", "", "fbrcm,tperst-clk-ms:0"; + pwr_led_gpio = "", "", "", "jgpios:4"; + pwr_led_activelow = "", "", "", "jgpios:8"; + pwr_led_trigger = "", "", "", "jlinux,default-trigger"; + random = "", "", "", "kstatus"; + rtc = "", "", "", "lstatus"; + rtc_bbat_vchg = "", "", "", "ltrickle-charge-microvolt:0"; + spi = "", "", "", "mstatus"; + strict_gpiod = "", "", "", "nbootargs=pinctrl_rp1.persist_gpio_outputs=n"; + suspend = "", "", "", "`linux,code:0=205"; + uart0 = "", "", "", "ostatus"; + uart0_console = "", "", "", "ostatus", "", "", "", "bconsole=", "/axi/pcie@1000120000/rp1/serial@30000"; + uart0_dma = [00 00 00 6f 64 6d 61 73 3a 30 3d 00 00 00 00 2a 00 00 00 6f 64 6d 61 73 3a 34 3d 00 00 00 00 1a 00 00 00 6f 64 6d 61 73 3a 38 3d 00 00 00 00 2a 00 00 00 6f 64 6d 61 73 3a 31 32 3d 00 00 00 00 19 00 00 00 6f 64 6d 61 2d 6e 61 6d 65 73 5b 3d 37 34 37 38 30 30 37 32 37 38 30 30 00]; + wifiaddr = "", "", "", "plocal-mac-address["; + cam0_reg = "", "", "", "qstatus"; + cam0_reg_gpio = [00 00 00 71 67 70 69 6f 3a 34 00 00 00 00 71 67 70 69 6f 3a 30 3d 00 00 00 00 2d]; + cam1_reg = "", "", "", "qstatus"; + cam1_reg_gpio = [00 00 00 71 67 70 69 6f 3a 34 00 00 00 00 71 67 70 69 6f 3a 30 3d 00 00 00 00 2d]; + ant1 = "", "", "", "routput-high?=on", "", "", "", "routput-low?=off", "", "", "", "soutput-high?=off", "", "", "", "soutput-low?=on"; + ant2 = "", "", "", "routput-high?=off", "", "", "", "routput-low?=on", "", "", "", "soutput-high?=on", "", "", "", "soutput-low?=off"; + noant = "", "", "", "routput-high?=off", "", "", "", "routput-low?=on", "", "", "", "soutput-high?=off", "", "", "", "soutput-low?=on"; + noanthogs = "", "", "", "rstatus=disabled", "", "", "", "sstatus=disabled"; + sd = "", "", "", "tstatus"; + sd_poll_once = "", "", "", "tnon-removable?"; + sd_cqe = "", "", "", "tsupports-cqe:0"; + }; + + cooling_fan { + status = "disabled"; + compatible = "pwm-fan"; + #cooling-cells = <0x02>; + cooling-min-state = <0x00>; + cooling-max-state = <0x03>; + cooling-levels = <0x00 0x4b 0x7d 0xaf 0xfa>; + pwms = <0x61 0x03 0xa25e 0x01>; + rpm-regmap = <0x61>; + rpm-offset = <0x3c>; + phandle = <0x53>; + }; + + pwr_button { + compatible = "gpio-keys"; + pinctrl-names = "default"; + pinctrl-0 = <0x75>; + status = "okay"; + + pwr { + label = "pwr_button"; + linux,code = <0x74>; + gpios = <0x1a 0x14 0x01>; + debounce-interval = <0x32>; + phandle = <0x60>; + }; + }; + + __symbols__ { + clocks = "/clocks"; + clk_osc = "/clocks/clk-osc"; + clk_vpu = "/clocks/clk-vpu"; + clk_uart = "/clocks/clk-uart"; + clk_emmc2 = "/clocks/clk-emmc2"; + clk_usb = "/clocks/clk-usb"; + clk_xosc = "/clocks/clk_xosc"; + sdio_src = "/clocks/sdio_src"; + sdhci_core = "/clocks/sdhci_core"; + clksrc_gp0 = "/clocks/clksrc_gp0"; + clksrc_gp1 = "/clocks/clksrc_gp1"; + clksrc_gp2 = "/clocks/clksrc_gp2"; + clksrc_gp3 = "/clocks/clksrc_gp3"; + clksrc_gp4 = "/clocks/clksrc_gp4"; + clksrc_gp5 = "/clocks/clksrc_gp5"; + cpus = "/cpus"; + cpu0 = "/cpus/cpu@0"; + l2_cache_l0 = "/cpus/cpu@0/l2-cache-l0"; + cpu1 = "/cpus/cpu@1"; + l2_cache_l1 = "/cpus/cpu@1/l2-cache-l1"; + cpu2 = "/cpus/cpu@2"; + l2_cache_l2 = "/cpus/cpu@2/l2-cache-l2"; + cpu3 = "/cpus/cpu@3"; + l2_cache_l3 = "/cpus/cpu@3/l2-cache-l3"; + l3_cache = "/cpus/l3-cache"; + rmem = "/reserved-memory"; + cma = "/reserved-memory/linux,cma"; + blconfig = "/reserved-memory/nvram@0"; + blpubkey = "/reserved-memory/nvram@1"; + soc = "/soc@107c000000"; + pcie_rescal = "/soc@107c000000/reset-controller@119500"; + sdio1 = "/soc@107c000000/mmc@fff000"; + bcm_reset = "/soc@107c000000/reset-controller@1504318"; + system_timer = "/soc@107c000000/timer@7c003000"; + mailbox = "/soc@107c000000/mailbox@7c013880"; + local_intc = "/soc@107c000000/interrupt-controller@7cd00000"; + uart10 = "/soc@107c000000/serial@7d001000"; + gio_aon = "/soc@107c000000/gpio@7d517c00"; + ant1 = "/soc@107c000000/gpio@7d517c00/ant1-hog"; + ant2 = "/soc@107c000000/gpio@7d517c00/ant2-hog"; + gicv2 = "/soc@107c000000/interrupt-controller@7fff9000"; + aon_intr = "/soc@107c000000/interrupt-controller@7d510600"; + pixelvalve0 = "/soc@107c000000/pixelvalve@7c410000"; + pixelvalve1 = "/soc@107c000000/pixelvalve@7c411000"; + mop = "/soc@107c000000/mop@7c500000"; + moplet = "/soc@107c000000/moplet@7c501000"; + disp_intr = "/soc@107c000000/interrupt-controller@7c502000"; + dvp = "/soc@107c000000/clock@7c700000"; + ddc0 = "/soc@107c000000/i2c@7d508200"; + ddc1 = "/soc@107c000000/i2c@7d508280"; + bsc_irq = "/soc@107c000000/intc@7d508380"; + main_irq = "/soc@107c000000/intc@7d508400"; + hdmi0 = "/soc@107c000000/hdmi@7ef00700"; + hdmi1 = "/soc@107c000000/hdmi@7ef05700"; + axiperf = "/soc@107c000000/axiperf@7c012800"; + spi10 = "/soc@107c000000/spi@7d004000"; + spidev10 = "/soc@107c000000/spi@7d004000/spidev@0"; + i2c10 = "/soc@107c000000/i2c@7d005600"; + pm = "/soc@107c000000/watchdog@7d200000"; + random = "/soc@107c000000/rng@7d208000"; + cpu_l2_irq = "/soc@107c000000/intc@7d503000"; + pinctrl = "/soc@107c000000/pinctrl@7d504100"; + uarta_24_pins = "/soc@107c000000/pinctrl@7d504100/uarta_24_pins"; + sdio2_30_pins = "/soc@107c000000/pinctrl@7d504100/sdio2_30_pins"; + pwr_button_pins = "/soc@107c000000/pinctrl@7d504100/pwr_button_pins"; + wl_on_pins = "/soc@107c000000/pinctrl@7d504100/wl_on_pins"; + bt_shutdown_pins = "/soc@107c000000/pinctrl@7d504100/bt_shutdown_pins"; + emmc_ds_pull = "/soc@107c000000/pinctrl@7d504100/emmc_ds_pull"; + emmc_cmddat_pulls = "/soc@107c000000/pinctrl@7d504100/emmc_cmddat_pulls"; + spi10_pins = "/soc@107c000000/pinctrl@7d504100/spi10_gpio2"; + spi10_gpio2 = "/soc@107c000000/pinctrl@7d504100/spi10_gpio2"; + spi10_cs_pins = "/soc@107c000000/pinctrl@7d504100/spi10_cs_gpio1"; + spi10_cs_gpio1 = "/soc@107c000000/pinctrl@7d504100/spi10_cs_gpio1"; + gio = "/soc@107c000000/gpio@7d508500"; + uarta = "/soc@107c000000/serial@7d50c000"; + bluetooth = "/soc@107c000000/serial@7d50c000/bluetooth"; + pinctrl_aon = "/soc@107c000000/pinctrl@7d510700"; + i2c3_m4_agpio0_pins = "/soc@107c000000/pinctrl@7d510700/i2c3_m4_agpio0_pins"; + bsc_m1_agpio13_pins = "/soc@107c000000/pinctrl@7d510700/bsc_m1_agpio13_pins"; + bsc_pmu_sgpio4_pins = "/soc@107c000000/pinctrl@7d510700/bsc_pmu_sgpio4_pins"; + bsc_m2_sgpio4_pins = "/soc@107c000000/pinctrl@7d510700/bsc_m2_sgpio4_pins"; + pwm_aon_agpio1_pins = "/soc@107c000000/pinctrl@7d510700/pwm_aon_agpio1_pins"; + pwm_aon_agpio4_pins = "/soc@107c000000/pinctrl@7d510700/pwm_aon_agpio4_pins"; + pwm_aon_agpio7_pins = "/soc@107c000000/pinctrl@7d510700/pwm_aon_agpio7_pins"; + ant_pins = "/soc@107c000000/pinctrl@7d510700/ant_pins"; + aon_pwm_1pin = "/soc@107c000000/pinctrl@7d510700/aon_pwm_1pin"; + main_aon_irq = "/soc@107c000000/intc@7d517ac0"; + avs_monitor = "/soc@107c000000/avs-monitor@7d542000"; + thermal = "/soc@107c000000/avs-monitor@7d542000/thermal"; + firmware = "/soc@107c000000/firmware"; + firmware_clocks = "/soc@107c000000/firmware/clocks"; + reset = "/soc@107c000000/firmware/reset"; + vcio = "/soc@107c000000/firmware/vcio"; + power = "/soc@107c000000/power"; + fb = "/soc@107c000000/fb"; + rpi_rtc = "/soc@107c000000/rpi_rtc"; + nvmem_otp = "/soc@107c000000/nvmem/nvmem_otp"; + nvmem_cust = "/soc@107c000000/nvmem/nvmem_cust"; + nvmem_mac = "/soc@107c000000/nvmem/nvmem_mac"; + nvmem_priv = "/soc@107c000000/nvmem/nvmem_priv"; + vdd_3v3_reg = "/soc@107c000000/fixedregulator_3v3"; + vdd_5v0_reg = "/soc@107c000000/fixedregulator_5v0"; + sound = "/soc@107c000000/sound"; + axi = "/axi"; + vc4 = "/axi/gpu"; + pcie0 = "/axi/pcie@1000100000"; + pciex1 = "/axi/pcie@1000110000"; + pcie1 = "/axi/pcie@1000110000"; + pciex4 = "/axi/pcie@1000120000"; + rp1_target = "/axi/pcie@1000120000"; + pcie2 = "/axi/pcie@1000120000"; + rp1 = "/axi/pcie@1000120000/rp1"; + rp1_mbox = "/axi/pcie@1000120000/rp1/mailbox@8000"; + rp1_clocks = "/axi/pcie@1000120000/rp1/clocks@18000"; + uart0 = "/axi/pcie@1000120000/rp1/serial@30000"; + rp1_uart0 = "/axi/pcie@1000120000/rp1/serial@30000"; + uart1 = "/axi/pcie@1000120000/rp1/serial@34000"; + rp1_uart1 = "/axi/pcie@1000120000/rp1/serial@34000"; + uart2 = "/axi/pcie@1000120000/rp1/serial@38000"; + rp1_uart2 = "/axi/pcie@1000120000/rp1/serial@38000"; + uart3 = "/axi/pcie@1000120000/rp1/serial@3c000"; + rp1_uart3 = "/axi/pcie@1000120000/rp1/serial@3c000"; + uart4 = "/axi/pcie@1000120000/rp1/serial@40000"; + rp1_uart4 = "/axi/pcie@1000120000/rp1/serial@40000"; + rp1_uart5 = "/axi/pcie@1000120000/rp1/serial@44000"; + rp1_spi8 = "/axi/pcie@1000120000/rp1/spi@4c000"; + spi0 = "/axi/pcie@1000120000/rp1/spi@50000"; + rp1_spi0 = "/axi/pcie@1000120000/rp1/spi@50000"; + spidev0 = "/axi/pcie@1000120000/rp1/spi@50000/spidev@0"; + spidev1 = "/axi/pcie@1000120000/rp1/spi@50000/spidev@1"; + spi1 = "/axi/pcie@1000120000/rp1/spi@54000"; + rp1_spi1 = "/axi/pcie@1000120000/rp1/spi@54000"; + spi2 = "/axi/pcie@1000120000/rp1/spi@58000"; + rp1_spi2 = "/axi/pcie@1000120000/rp1/spi@58000"; + spi3 = "/axi/pcie@1000120000/rp1/spi@5c000"; + rp1_spi3 = "/axi/pcie@1000120000/rp1/spi@5c000"; + spi4 = "/axi/pcie@1000120000/rp1/spi@60000"; + rp1_spi4 = "/axi/pcie@1000120000/rp1/spi@60000"; + spi5 = "/axi/pcie@1000120000/rp1/spi@64000"; + rp1_spi5 = "/axi/pcie@1000120000/rp1/spi@64000"; + rp1_spi6 = "/axi/pcie@1000120000/rp1/spi@68000"; + rp1_spi7 = "/axi/pcie@1000120000/rp1/spi@6c000"; + i2c_csi_dsi = "/axi/pcie@1000120000/rp1/i2c@70000"; + i2c_csi_dsi1 = "/axi/pcie@1000120000/rp1/i2c@70000"; + i2c_vc = "/axi/pcie@1000120000/rp1/i2c@70000"; + i2c0 = "/axi/pcie@1000120000/rp1/i2c@70000"; + rp1_i2c0 = "/axi/pcie@1000120000/rp1/i2c@70000"; + i2c_arm = "/axi/pcie@1000120000/rp1/i2c@74000"; + i2c1 = "/axi/pcie@1000120000/rp1/i2c@74000"; + rp1_i2c1 = "/axi/pcie@1000120000/rp1/i2c@74000"; + i2c2 = "/axi/pcie@1000120000/rp1/i2c@78000"; + rp1_i2c2 = "/axi/pcie@1000120000/rp1/i2c@78000"; + i2c3 = "/axi/pcie@1000120000/rp1/i2c@7c000"; + rp1_i2c3 = "/axi/pcie@1000120000/rp1/i2c@7c000"; + i2c4 = "/axi/pcie@1000120000/rp1/i2c@80000"; + rp1_i2c4 = "/axi/pcie@1000120000/rp1/i2c@80000"; + i2c5 = "/axi/pcie@1000120000/rp1/i2c@84000"; + rp1_i2c5 = "/axi/pcie@1000120000/rp1/i2c@84000"; + i2c_csi_dsi0 = "/axi/pcie@1000120000/rp1/i2c@88000"; + i2c6 = "/axi/pcie@1000120000/rp1/i2c@88000"; + rp1_i2c6 = "/axi/pcie@1000120000/rp1/i2c@88000"; + rp1_audio_out = "/axi/pcie@1000120000/rp1/audio_out@94000"; + pwm = "/axi/pcie@1000120000/rp1/pwm@98000"; + pwm0 = "/axi/pcie@1000120000/rp1/pwm@98000"; + rp1_pwm0 = "/axi/pcie@1000120000/rp1/pwm@98000"; + pwm1 = "/axi/pcie@1000120000/rp1/pwm@9c000"; + rp1_pwm1 = "/axi/pcie@1000120000/rp1/pwm@9c000"; + i2s_clk_producer = "/axi/pcie@1000120000/rp1/i2s@a0000"; + i2s = "/axi/pcie@1000120000/rp1/i2s@a0000"; + rp1_i2s0 = "/axi/pcie@1000120000/rp1/i2s@a0000"; + i2s_clk_consumer = "/axi/pcie@1000120000/rp1/i2s@a4000"; + rp1_i2s1 = "/axi/pcie@1000120000/rp1/i2s@a4000"; + rp1_i2s2 = "/axi/pcie@1000120000/rp1/i2s@a8000"; + rp1_sdio_clk0 = "/axi/pcie@1000120000/rp1/sdio_clk0@b0004"; + rp1_sdio_clk1 = "/axi/pcie@1000120000/rp1/sdio_clk1@b4004"; + rp1_adc = "/axi/pcie@1000120000/rp1/adc@c8000"; + gpio = "/axi/pcie@1000120000/rp1/gpio@d0000"; + rp1_gpio = "/axi/pcie@1000120000/rp1/gpio@d0000"; + uart0_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart0_14_15"; + rp1_uart0_14_15 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart0_14_15"; + uart0_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart0_ctsrts_16_17"; + rp1_uart0_ctsrts_16_17 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart0_ctsrts_16_17"; + uart1_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart1_0_1"; + rp1_uart1_0_1 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart1_0_1"; + uart1_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart1_ctsrts_2_3"; + rp1_uart1_ctsrts_2_3 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart1_ctsrts_2_3"; + uart2_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart2_4_5"; + rp1_uart2_4_5 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart2_4_5"; + uart2_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart2_ctsrts_6_7"; + rp1_uart2_ctsrts_6_7 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart2_ctsrts_6_7"; + uart3_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart3_8_9"; + rp1_uart3_8_9 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart3_8_9"; + uart3_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart3_ctsrts_10_11"; + rp1_uart3_ctsrts_10_11 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart3_ctsrts_10_11"; + uart4_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart4_12_13"; + rp1_uart4_12_13 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart4_12_13"; + uart4_ctsrts_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart4_ctsrts_14_15"; + rp1_uart4_ctsrts_14_15 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_uart4_ctsrts_14_15"; + rp1_sdio0_22_27 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_sdio0_22_27"; + rp1_sdio1_28_33 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_sdio1_28_33"; + rp1_i2s0_18_21 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2s0_18_21"; + rp1_i2s1_18_21 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2s1_18_21"; + rp1_i2c4_34_35 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c4_34_35"; + rp1_i2c6_38_39 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c6_38_39"; + rp1_i2c4_40_41 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c4_40_41"; + rp1_i2c5_44_45 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c5_44_45"; + i2c0_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c0_0_1"; + rp1_i2c0_0_1 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c0_0_1"; + rp1_i2c0_8_9 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c0_8_9"; + i2c1_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c1_2_3"; + rp1_i2c1_2_3 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c1_2_3"; + rp1_i2c1_10_11 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c1_10_11"; + i2c2_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c2_4_5"; + rp1_i2c2_4_5 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c2_4_5"; + rp1_i2c2_12_13 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c2_12_13"; + i2c3_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c3_6_7"; + rp1_i2c3_6_7 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c3_6_7"; + rp1_i2c3_14_15 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c3_14_15"; + rp1_i2c3_22_23 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_i2c3_22_23"; + dpi_16bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_gpio2"; + rp1_dpi_16bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_gpio2"; + dpi_16bit_cpadhi_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_cpadhi_gpio2"; + rp1_dpi_16bit_cpadhi_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_cpadhi_gpio2"; + rp1_dpi_16bit_pad666_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_pad666_gpio2"; + dpi_18bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_gpio2"; + rp1_dpi_18bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_gpio2"; + dpi_18bit_cpadhi_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_cpadhi_gpio2"; + rp1_dpi_18bit_cpadhi_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_cpadhi_gpio2"; + dpi_gpio1 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_24bit_gpio2"; + rp1_dpi_24bit_gpio2 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_24bit_gpio2"; + rp1_dpi_hvsync = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_hvsync"; + dpi_16bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_gpio0"; + rp1_dpi_16bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_gpio0"; + dpi_16bit_cpadhi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_cpadhi_gpio0"; + rp1_dpi_16bit_cpadhi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_cpadhi_gpio0"; + rp1_dpi_16bit_pad666_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_16bit_pad666_gpio0"; + dpi_18bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_gpio0"; + rp1_dpi_18bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_gpio0"; + dpi_18bit_cpadhi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_cpadhi_gpio0"; + rp1_dpi_18bit_cpadhi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_18bit_cpadhi_gpio0"; + dpi_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_24bit_gpio0"; + rp1_dpi_24bit_gpio0 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_dpi_24bit_gpio0"; + rp1_gpclksrc0_gpio4 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc0_gpio4"; + rp1_gpclksrc0_gpio20 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc0_gpio20"; + rp1_gpclksrc1_gpio5 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc1_gpio5"; + rp1_gpclksrc1_gpio18 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc1_gpio18"; + rp1_gpclksrc1_gpio21 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_gpclksrc1_gpio21"; + rp1_pwm1_gpio45 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_pwm1_gpio45"; + spi0_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi0_gpio9"; + rp1_spi0_gpio9 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi0_gpio9"; + spi0_cs_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi0_cs_gpio7"; + rp1_spi0_cs_gpio7 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi0_cs_gpio7"; + rp1_spi1_gpio19 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi1_gpio19"; + spi2_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi2_gpio1"; + rp1_spi2_gpio1 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi2_gpio1"; + spi3_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi3_gpio5"; + rp1_spi3_gpio5 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi3_gpio5"; + spi4_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi4_gpio9"; + rp1_spi4_gpio9 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi4_gpio9"; + spi5_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi5_gpio13"; + rp1_spi5_gpio13 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi5_gpio13"; + rp1_spi8_gpio49 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi8_gpio49"; + rp1_spi8_cs_gpio52 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_spi8_cs_gpio52"; + rp1_audio_out_12_13 = "/axi/pcie@1000120000/rp1/gpio@d0000/rp1_audio_out_12_13"; + usb_vbus_pins = "/axi/pcie@1000120000/rp1/gpio@d0000/usb_vbus_pins"; + rp1_eth = "/axi/pcie@1000120000/rp1/ethernet@100000"; + phy1 = "/axi/pcie@1000120000/rp1/ethernet@100000/ethernet-phy@1"; + csi0 = "/axi/pcie@1000120000/rp1/csi@110000"; + rp1_csi0 = "/axi/pcie@1000120000/rp1/csi@110000"; + csi1 = "/axi/pcie@1000120000/rp1/csi@128000"; + rp1_csi1 = "/axi/pcie@1000120000/rp1/csi@128000"; + pio = "/axi/pcie@1000120000/rp1/pio@178000"; + rp1_pio = "/axi/pcie@1000120000/rp1/pio@178000"; + rp1_mmc0 = "/axi/pcie@1000120000/rp1/mmc@180000"; + rp1_mmc1 = "/axi/pcie@1000120000/rp1/mmc@184000"; + rp1_dma = "/axi/pcie@1000120000/rp1/dma@188000"; + rp1_usb0 = "/axi/pcie@1000120000/rp1/usb@200000"; + rp1_usb1 = "/axi/pcie@1000120000/rp1/usb@300000"; + dsi0 = "/axi/pcie@1000120000/rp1/dsi@110000"; + rp1_dsi0 = "/axi/pcie@1000120000/rp1/dsi@110000"; + dsi1 = "/axi/pcie@1000120000/rp1/dsi@128000"; + rp1_dsi1 = "/axi/pcie@1000120000/rp1/dsi@128000"; + vec = "/axi/pcie@1000120000/rp1/vec@144000"; + rp1_vec = "/axi/pcie@1000120000/rp1/vec@144000"; + dpi = "/axi/pcie@1000120000/rp1/dpi@148000"; + rp1_dpi = "/axi/pcie@1000120000/rp1/dpi@148000"; + sram = "/axi/pcie@1000120000/rp1/sram@400000"; + rp1_fw_shmem = "/axi/pcie@1000120000/rp1/sram@400000/shmem@ff00"; + mip0 = "/axi/msi-controller@1000130000"; + mip1 = "/axi/msi-controller@1000131000"; + iommu2 = "/axi/iommu@5100"; + iommu4 = "/axi/iommu@5200"; + iommu5 = "/axi/iommu@5280"; + iommuc = "/axi/iommuc@5b00"; + dma32 = "/axi/dma@10000"; + dma40 = "/axi/dma@10600"; + syscon_piarbctl = "/axi/syscon@400018"; + usb = "/axi/usb@480000"; + hevc_dec = "/axi/codec@800000"; + pisp_be = "/axi/pisp_be@880000"; + sdio2 = "/axi/mmc@1100000"; + wifi = "/axi/mmc@1100000/wifi@1"; + v3d = "/axi/v3d@2000000"; + clk_27MHz = "/clk-27M"; + clk_108MHz = "/clk-108M"; + hvs = "/hvs@107c580000"; + cpu_thermal = "/thermal-zones/cpu-thermal"; + thermal_trips = "/thermal-zones/cpu-thermal/trips"; + cpu_crit = "/thermal-zones/cpu-thermal/trips/cpu-crit"; + cpu_tepid = "/thermal-zones/cpu-thermal/trips/cpu-tepid"; + cpu_warm = "/thermal-zones/cpu-thermal/trips/cpu-warm"; + cpu_hot = "/thermal-zones/cpu-thermal/trips/cpu-hot"; + cpu_vhot = "/thermal-zones/cpu-thermal/trips/cpu-vhot"; + cooling_maps = "/thermal-zones/cpu-thermal/cooling-maps"; + firmwarekms = "/firmwarekms"; + usbphy = "/phy"; + leds = "/leds"; + led_pwr = "/leds/led-pwr"; + led_act = "/leds/led-act"; + sd_io_1v8_reg = "/sd-io-1v8-reg"; + sd_vcc_reg = "/sd-vcc-reg"; + wl_on_reg = "/wl-on-reg"; + cam1_clk = "/cam1_clk"; + cam0_clk = "/cam0_clk"; + cam1_reg = "/cam0_reg"; + cam0_reg = "/cam0_reg"; + cam_dummy_reg = "/cam_dummy_reg"; + aux = "/dummy"; + dummy = "/dummy"; + i2c0if = "/i2c0if"; + i2c0mux = "/i2c0mux"; + rp1_firmware = "/rp1_firmware"; + rp1_vdd_3v3 = "/rp1_vdd_3v3"; + chosen = "/chosen"; + aliases = "/aliases"; + fan = "/cooling_fan"; + pwr_key = "/pwr_button/pwr"; + }; +}; diff --git a/virt.dts b/dtbs/virt.dts similarity index 100% rename from virt.dts rename to dtbs/virt.dts From a3a0e0a0a60bb44c1e2599d55ece66d47fd84dfc Mon Sep 17 00:00:00 2001 From: differrari Date: Wed, 23 Jul 2025 01:16:13 +0200 Subject: [PATCH 079/123] [PROJ] fixed run scripts for linux --- run_raspi | 8 ++++---- run_virt | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/run_raspi b/run_raspi index 3b6c756e..d9806363 100755 --- a/run_raspi +++ b/run_raspi @@ -1,4 +1,4 @@ -#/!bin/sh +#!/bin/sh echo "Running raspi emulator" @@ -9,10 +9,10 @@ fi OS_TYPE="$(uname)" -if [[ "$OS_TYPE" == "Darwin" ]]; then +if [ "$OS_TYPE" = "Darwin" ]; then NETARG="vmnet-bridged,id=net0,ifname=en0" PRIVILEGE="sudo" -elif [[ "$OS_TYPE" == "Linux" ]]; then +elif [ "$OS_TYPE" = "Linux" ]; then NETARG="user,id=net0" PRIVILEGE="" else @@ -23,7 +23,7 @@ fi $PRIVILEGE qemu-system-aarch64 \ -M raspi4b \ -kernel kernel.img \ --display sdl \ +-display default \ -device sd-card,drive=sd -drive id=sd,format=raw,file=disk.img,if=none \ -netdev $NETARG \ -serial mon:stdio \ diff --git a/run_virt b/run_virt index 25663d9f..faad60d0 100755 --- a/run_virt +++ b/run_virt @@ -1,4 +1,4 @@ -#/!bin/sh +#!/bin/sh echo "Running virt emulator" @@ -17,10 +17,10 @@ fi OS_TYPE="$(uname)" -if [[ "$OS_TYPE" == "Darwin" ]]; then +if [ "$OS_TYPE" = "Darwin" ]; then NETARG="vmnet-bridged,id=net0,ifname=en0" PRIVILEGE="sudo" -elif [[ "$OS_TYPE" == "Linux" ]]; then +elif [ "$OS_TYPE" = "Linux" ]; then NETARG="user,id=net0" PRIVILEGE="" else @@ -34,7 +34,7 @@ $PRIVILEGE qemu-system-aarch64 \ -m 512M \ -kernel kernel.elf \ -device virtio-gpu-pci \ - -display sdl \ + -display default \ -netdev $NETARG \ -device virtio-net-pci,netdev=net0 \ -serial mon:stdio \ From 23519f83e7bece3a4314c61f0c396bc261c110e7 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Wed, 23 Jul 2025 00:00:00 +0000 Subject: [PATCH 080/123] [PROJ] display fix for mac --- run_raspi | 5 ++++- run_virt | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/run_raspi b/run_raspi index d9806363..15a159a4 100755 --- a/run_raspi +++ b/run_raspi @@ -9,9 +9,12 @@ fi OS_TYPE="$(uname)" +DISPLAY="default" + if [ "$OS_TYPE" = "Darwin" ]; then NETARG="vmnet-bridged,id=net0,ifname=en0" PRIVILEGE="sudo" + DISPLAY="sdl" elif [ "$OS_TYPE" = "Linux" ]; then NETARG="user,id=net0" PRIVILEGE="" @@ -23,7 +26,7 @@ fi $PRIVILEGE qemu-system-aarch64 \ -M raspi4b \ -kernel kernel.img \ --display default \ +-display $DISPLAY \ -device sd-card,drive=sd -drive id=sd,format=raw,file=disk.img,if=none \ -netdev $NETARG \ -serial mon:stdio \ diff --git a/run_virt b/run_virt index faad60d0..22095e53 100755 --- a/run_virt +++ b/run_virt @@ -17,9 +17,12 @@ fi OS_TYPE="$(uname)" +DISPLAY="default" + if [ "$OS_TYPE" = "Darwin" ]; then NETARG="vmnet-bridged,id=net0,ifname=en0" PRIVILEGE="sudo" + DISPLAY="sdl" elif [ "$OS_TYPE" = "Linux" ]; then NETARG="user,id=net0" PRIVILEGE="" @@ -34,7 +37,7 @@ $PRIVILEGE qemu-system-aarch64 \ -m 512M \ -kernel kernel.elf \ -device virtio-gpu-pci \ - -display default \ + -display $DISPLAY \ -netdev $NETARG \ -device virtio-net-pci,netdev=net0 \ -serial mon:stdio \ From 57ea33f87b9be0e1f5e4c8e93d995c78d96d4a8a Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Wed, 23 Jul 2025 00:00:00 +0000 Subject: [PATCH 081/123] [USB] return true for DWC2 only if there's new input --- kernel/input/dwc2.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/input/dwc2.cpp b/kernel/input/dwc2.cpp index e556d706..99ccc72f 100644 --- a/kernel/input/dwc2.cpp +++ b/kernel/input/dwc2.cpp @@ -6,6 +6,8 @@ #include "memory/mmu.h" #include "hw/hw.h" +#define DWC2_INT_DATA 0b11 + dwc2_host_channel* DWC2Driver::get_channel(uint16_t channel){ return (dwc2_host_channel *)(DWC2_BASE + 0x500 + (channel * 0x20)); } @@ -220,10 +222,12 @@ bool DWC2Driver::poll(uint8_t address, uint8_t endpoint, void *out_buf, uint16_t return false; } + bool found_input = (endpoint_channel->interrupt & DWC2_INT_DATA) == DWC2_INT_DATA; + endpoint_channel->interrupt = 0xFFFFFFFF; endpoint_channel->cchar &= ~(1 << 31); - return true; + return found_input; } void DWC2Driver::handle_hub_routing(uint8_t hub, uint8_t port){ From 6425f5db3607dfb4e099c382bb41d22d5076ee4f Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Wed, 23 Jul 2025 00:00:00 +0000 Subject: [PATCH 082/123] USB polling through process --- kernel/input/USBKeyboard.cpp | 3 +-- kernel/input/input_dispatch.cpp | 24 ++++++++++++++++++++---- kernel/input/input_dispatch.h | 2 ++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/kernel/input/USBKeyboard.cpp b/kernel/input/USBKeyboard.cpp index 671bd3b7..f6ba88e6 100644 --- a/kernel/input/USBKeyboard.cpp +++ b/kernel/input/USBKeyboard.cpp @@ -11,9 +11,8 @@ void USBKeyboard::request_data(USBDriver *driver){ buffer = alloc_page(packet_size, true, true, true); } - if (!driver->poll(slot_id, endpoint, buffer, packet_size)){ + if (!driver->poll(slot_id, endpoint, buffer, packet_size)) return; - } if (!driver->use_interrupts){ process_keypress((keypress*)buffer); diff --git a/kernel/input/input_dispatch.cpp b/kernel/input/input_dispatch.cpp index 48c196ee..c6cbc825 100644 --- a/kernel/input/input_dispatch.cpp +++ b/kernel/input/input_dispatch.cpp @@ -5,6 +5,7 @@ #include "xhci.hpp" #include "hw/hw.h" #include "std/std.hpp" +#include "kernel_processes/kprocess_loader.h" process_t* focused_proc; @@ -88,10 +89,6 @@ bool is_new_keypress(keypress* current, keypress* previous) { } bool sys_read_input(int pid, keypress *out){ - if (!input_driver->use_interrupts) - input_driver->poll_inputs(); - else if (input_driver->quirk_simulate_interrupts) - input_driver->handle_interrupt(); process_t *process = get_proc_by_pid(pid); if (process->input_buffer.read_index == process->input_buffer.write_index) return false; @@ -122,6 +119,25 @@ bool input_init(){ } } +void input_process_poll(){ + while (1){ + input_driver->poll_inputs(); + } +} + +void input_process_fake_interrupts(){ + while (1){ + input_driver->handle_interrupt(); + } +} + +void init_input_process(){ + if (!input_driver->use_interrupts) + create_kernel_process("input_poll", &input_process_poll); + if (input_driver->quirk_simulate_interrupts) + create_kernel_process("input_int_mock", &input_process_fake_interrupts); +} + void handle_input_interrupt(){ if (input_driver->use_interrupts) input_driver->handle_interrupt(); } \ No newline at end of file diff --git a/kernel/input/input_dispatch.h b/kernel/input/input_dispatch.h index 9976c6ff..aa969517 100644 --- a/kernel/input/input_dispatch.h +++ b/kernel/input/input_dispatch.h @@ -29,6 +29,8 @@ bool input_init(); void handle_input_interrupt(); +void init_input_process(); + #ifdef __cplusplus } #endif \ No newline at end of file From 4f9e2e3d7c320cb757fa4abe4b4f3287caae6a12 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Wed, 23 Jul 2025 00:00:00 +0000 Subject: [PATCH 083/123] Fixes to allow disk being optional --- kernel/filesystem/disk.cpp | 2 ++ kernel/filesystem/fat32.cpp | 6 +++++- kernel/filesystem/fat32.hpp | 16 ++++++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/kernel/filesystem/disk.cpp b/kernel/filesystem/disk.cpp index 232a3b4f..07b971d4 100644 --- a/kernel/filesystem/disk.cpp +++ b/kernel/filesystem/disk.cpp @@ -53,9 +53,11 @@ void disk_read(void *buffer, uint32_t sector, uint32_t count){ } void* read_file(char *path){ + if (!fs_driver) return 0; return fs_driver->read_file(path); } string_list* list_directory_contents(char *path){ + if (!fs_driver) return 0; return fs_driver->list_contents(path); } \ No newline at end of file diff --git a/kernel/filesystem/fat32.cpp b/kernel/filesystem/fat32.cpp index a88fe553..22888047 100644 --- a/kernel/filesystem/fat32.cpp +++ b/kernel/filesystem/fat32.cpp @@ -65,7 +65,8 @@ bool FAT32FS::init(uint32_t partition_sector){ read_FAT(mbs->reserved_sectors, mbs->sectors_per_fat, mbs->number_of_fats); - return true;} + return true; +} void* FAT32FS::read_cluster(uint32_t cluster_start, uint32_t cluster_size, uint32_t cluster_count, uint32_t root_index){ @@ -162,6 +163,7 @@ void* FAT32FS::walk_directory(uint32_t cluster_count, uint32_t root_index, char } void* FAT32FS::list_directory(uint32_t cluster_count, uint32_t root_index) { + if (!mbs) return 0; uint32_t cluster_size = mbs->sectors_per_cluster; char *buffer = (char*)read_cluster(data_start_sector, cluster_size, cluster_count, root_index); f32file_entry *entry = 0; @@ -256,6 +258,7 @@ void* FAT32FS::read_entry_handler(FAT32FS *instance, f32file_entry *entry, char } void* FAT32FS::read_file(char *path){ + if (!mbs) return 0; path = advance_path(path); uint32_t count = count_FAT(mbs->first_cluster_of_root_directory); @@ -282,6 +285,7 @@ void* FAT32FS::list_entries_handler(FAT32FS *instance, f32file_entry *entry, cha } string_list* FAT32FS::list_contents(char *path){ + if (!mbs) return 0; path = advance_path(path); uint32_t count = count_FAT(mbs->first_cluster_of_root_directory); diff --git a/kernel/filesystem/fat32.hpp b/kernel/filesystem/fat32.hpp index e2aa7af8..f62296bd 100644 --- a/kernel/filesystem/fat32.hpp +++ b/kernel/filesystem/fat32.hpp @@ -92,14 +92,14 @@ class FAT32FS { void* read_cluster(uint32_t cluster_start, uint32_t cluster_size, uint32_t cluster_count, uint32_t root_index); char* advance_path(char *path); - fat32_mbs* mbs; - void *fs_page; - uint32_t cluster_count; - uint32_t data_start_sector; - uint32_t* fat; - uint32_t total_fat_entries; - uint16_t bytes_per_sector; - uint32_t partition_first_sector; + fat32_mbs* mbs = 0x0; + void *fs_page = 0x0; + uint32_t cluster_count = 0; + uint32_t data_start_sector = 0; + uint32_t* fat = 0x0; + uint32_t total_fat_entries = 0; + uint16_t bytes_per_sector = 0; + uint32_t partition_first_sector = 0; static void* read_entry_handler(FAT32FS *instance, f32file_entry *entry, char *filename, char *seek); static void* list_entries_handler(FAT32FS *instance, f32file_entry *entry, char *filename, char *seek); From 1ba3c2c21791ea075e2a3e5fb6320ff3dad77e1b Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Wed, 23 Jul 2025 00:00:00 +0000 Subject: [PATCH 084/123] [USB] init polling process for input --- kernel/kernel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/kernel.c b/kernel/kernel.c index 101d43e7..1b524537 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -67,6 +67,7 @@ void kernel_main() { panic("Input initialization error"); bool network_available = network_init(); + init_input_process(); mmu_init(); kprintf_l("MMU Mapped"); From 68fbebae7d073b0e760c2e08e9538a983bad196a Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Wed, 23 Jul 2025 00:00:00 +0000 Subject: [PATCH 085/123] Fixed issue with sdhci addressing --- Makefile | 9 +++++---- kernel/Makefile | 4 ++++ kernel/filesystem/fat32.cpp | 6 +++--- kernel/filesystem/sdhci.cpp | 5 +++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 5f4453fc..567c0902 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ MODE ?= virt LOAD_ADDR ?= 0x41000000 XHCI_CTX_SIZE ?= 32 +QEMU ?= true OS := $(shell uname) @@ -26,7 +27,7 @@ user: $(MAKE) -C user kernel: - $(MAKE) -C kernel LOAD_ADDR=$(LOAD_ADDR) XHCI_CTX_SIZE=$(XHCI_CTX_SIZE) + $(MAKE) -C kernel LOAD_ADDR=$(LOAD_ADDR) XHCI_CTX_SIZE=$(XHCI_CTX_SIZE) QEMU=$(QEMU) clean: $(MAKE) -C shared clean @@ -34,10 +35,10 @@ clean: $(MAKE) -C user clean raspi: - $(MAKE) LOAD_ADDR=0x80000 XHCI_CTX_SIZE=64 all + $(MAKE) LOAD_ADDR=0x80000 XHCI_CTX_SIZE=64 QEMU=true all virt: - $(MAKE) LOAD_ADDR=0x41000000 XHCI_CTX_SIZE=32 all + $(MAKE) LOAD_ADDR=0x41000000 XHCI_CTX_SIZE=32 QEMU=true all debug: $(MAKE) $(MODE) @@ -45,7 +46,7 @@ debug: install: $(MAKE) clean - $(MAKE) LOAD_ADDR=0x80000 XHCI_CTX_SIZE=64 all + $(MAKE) LOAD_ADDR=0x80000 XHCI_CTX_SIZE=64 QEMU=false all cp kernel.img $(BOOTFS)/kernel8.img cp kernel.img $(BOOTFS)/kernel_2712.img cp config.txt $(BOOTFS)/config.txt diff --git a/kernel/Makefile b/kernel/Makefile index 97ebfb3b..8ca65871 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -5,6 +5,10 @@ OBJCOPY = $(ARCH)-objcopy CFLAGS = -g -O0 -std=c17 -nostdlib -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wall -Wextra -DXHCI_CTX_SIZE=$(XHCI_CTX_SIZE) -mcpu=cortex-a72 -I. -I../shared -I../user +ifeq ($(QEMU),true) + CFLAGS += -DQEMU +endif + LDFLAGS = -T $(shell ls *.ld) --defsym=LOAD_ADDR=$(LOAD_ADDR) C_SRC = $(shell find . -name '*.c') diff --git a/kernel/filesystem/fat32.cpp b/kernel/filesystem/fat32.cpp index 22888047..0e8f4289 100644 --- a/kernel/filesystem/fat32.cpp +++ b/kernel/filesystem/fat32.cpp @@ -51,7 +51,7 @@ bool FAT32FS::init(uint32_t partition_sector){ uint16_t num_sectors = read_unaligned16(&mbs->num_sectors); cluster_count = (num_sectors == 0 ? mbs->large_num_sectors : num_sectors)/mbs->sectors_per_cluster; - data_start_sector = mbs->reserved_sectors + (mbs->sectors_per_fat * mbs->number_of_fats); + data_start_sector = partition_first_sector + mbs->reserved_sectors + (mbs->sectors_per_fat * mbs->number_of_fats); if (mbs->first_cluster_of_root_directory > cluster_count){ kprintf("[fat32 error] root directory cluster not found"); @@ -63,7 +63,7 @@ bool FAT32FS::init(uint32_t partition_sector){ kprintf("FAT32 Volume uses %i cluster size", bytes_per_sector); kprintf("Data start at %x",data_start_sector*512); - read_FAT(mbs->reserved_sectors, mbs->sectors_per_fat, mbs->number_of_fats); + read_FAT(partition_first_sector + mbs->reserved_sectors, mbs->sectors_per_fat, mbs->number_of_fats); return true; } @@ -232,7 +232,7 @@ void FAT32FS::read_FAT(uint32_t location, uint32_t size, uint8_t count){ uint32_t FAT32FS::count_FAT(uint32_t first){ uint32_t entry = fat[first]; int count = 1; - while (entry < 0x0FFFFFF8){ + while (entry < 0x0FFFFFF8 && entry != 0){ entry = fat[entry]; count++; } diff --git a/kernel/filesystem/sdhci.cpp b/kernel/filesystem/sdhci.cpp index e979c961..89c5831b 100644 --- a/kernel/filesystem/sdhci.cpp +++ b/kernel/filesystem/sdhci.cpp @@ -263,9 +263,10 @@ bool SDHCI::read(void *buffer, uint32_t sector, uint32_t count){ regs->blksize_count = (count << 16) | 512; uint32_t command = multiple ? READ_MULTIPLE : READ_ONE; uint32_t flags = multiple ? 0b110110 : 0b010000; +#if QEMU + sector *= 512; +#endif for (int i = 5; i >= 0; i--){ - if (!v2_card) - sector *= 512; if (issue_command(command, sector, flags)) break; if (i == 0) { kprintf("[SDHCI error] read request timeout"); return false; } delay(500); From 20aaf4f15d254b598221b48579d7fd3ab9c39c34 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Thu, 24 Jul 2025 00:00:00 +0000 Subject: [PATCH 086/123] [PROC] test process colors --- user/default_process.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/user/default_process.c b/user/default_process.c index 4d9d644e..345af5f9 100644 --- a/user/default_process.c +++ b/user/default_process.c @@ -15,10 +15,10 @@ void proc_func() { if (kp.keys[0] == KEY_ESC) halt(); } - clear_screen(0xFFFFFF); - draw_primitive_rect(&rect, 0x222233); + clear_screen(0xFFFFFFFF); + draw_primitive_rect(&rect, 0xFF222233); string s = string_l("Print screen test"); - draw_primitive_string(&s,&rect.point,2, 0xFFFFFF); + draw_primitive_string(&s,&rect.point,2, 0xFFFFFFFF); free(s.data,s.mem_length); gpu_flush_data(); } From a7a9675357853ed53c2934766613f0a197212150 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Thu, 24 Jul 2025 00:00:00 +0000 Subject: [PATCH 087/123] [INPUT] use keypad enter as alternative to enter --- kernel/input/USBKeyboard.cpp | 2 +- kernel/kernel_processes/boot/login_screen.c | 5 +++-- kernel/kernel_processes/windows/desktop.cpp | 3 +-- shared/input_keycodes.h | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/kernel/input/USBKeyboard.cpp b/kernel/input/USBKeyboard.cpp index f6ba88e6..8f23f876 100644 --- a/kernel/input/USBKeyboard.cpp +++ b/kernel/input/USBKeyboard.cpp @@ -39,7 +39,7 @@ void USBKeyboard::process_keypress(keypress *rkp){ // kprintf_raw("Mod: %i", kp.modifier); for (int i = 0; i < 6; i++){ kp.keys[i] = rkp->keys[i]; - // kprintf_raw("Key [%i]: %i", i, kp.keys[i]); + // kprintf_raw("Key [%i]: %x", i, kp.keys[i]); } last_keypress = kp; register_keypress(kp); diff --git a/kernel/kernel_processes/boot/login_screen.c b/kernel/kernel_processes/boot/login_screen.c index 7f1a0aa7..e3552584 100644 --- a/kernel/kernel_processes/boot/login_screen.c +++ b/kernel/kernel_processes/boot/login_screen.c @@ -10,6 +10,7 @@ #include "std/string.h" #include "syscalls/syscalls.h" +//TODO: properly handle keypad static const char hid_keycode_to_char[256] = { [0x04] = 'a', [0x05] = 'b', [0x06] = 'c', [0x07] = 'd', [0x08] = 'e', [0x09] = 'f', [0x0A] = 'g', [0x0B] = 'h', @@ -24,7 +25,7 @@ static const char hid_keycode_to_char[256] = { [0x28] = '\n', [0x2C] = ' ', [0x2D] = '-', [0x2E] = '=', [0x2F] = '[', [0x30] = ']', [0x31] = '\\', [0x33] = ';', [0x34] = '\'', [0x35] = '`', [0x36] = ',', [0x37] = '.', - [0x38] = '/', + [0x38] = '/', [0x58] = '\n', }; bool keypress_contains(keypress *kp, char key, uint8_t modifier){ @@ -68,7 +69,7 @@ void login_screen(){ for (int i = 0; i < 6; i++){ char key = kp.keys[i]; if (hid_keycode_to_char[(uint8_t)key]){ - if (key == KEY_ENTER){ + if (key == KEY_ENTER || key == KEY_KEYPAD_ENTER){ if (strcmp(buf,default_pwd, false) == 0){ free(s.data,s.mem_length); free(title.data,title.mem_length); diff --git a/kernel/kernel_processes/windows/desktop.cpp b/kernel/kernel_processes/windows/desktop.cpp index 85884f3b..950e85db 100644 --- a/kernel/kernel_processes/windows/desktop.cpp +++ b/kernel/kernel_processes/windows/desktop.cpp @@ -59,10 +59,9 @@ void Desktop::draw_desktop(){ keypress kp; gpu_point old_selected = selected; while (sys_read_input_current(&kp)){ - //TODO: there's a crash when moving in the desktop with no processes loaded. Memcpy for (int i = 0; i < 6; i++){ char key = kp.keys[i]; - if (key == KEY_ENTER){ + if (key == KEY_ENTER || key == KEY_KEYPAD_ENTER){ activate_current(); return; } diff --git a/shared/input_keycodes.h b/shared/input_keycodes.h index 7804ef94..14576eb5 100644 --- a/shared/input_keycodes.h +++ b/shared/input_keycodes.h @@ -9,6 +9,7 @@ extern "C" { #define KEY_ARROW_RIGHT 0x4F #define KEY_BACKSPACE 0x2A #define KEY_ENTER 0x28 +#define KEY_KEYPAD_ENTER 0x58 #define KEY_ESC 0x29 #define KEY_MOD_CMD 0x8 From a5f68b28b2d9abd52f274e5f7c6332bed248ae38 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Thu, 24 Jul 2025 00:00:00 +0000 Subject: [PATCH 088/123] syscall return fix --- kernel/process/syscall.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/process/syscall.c b/kernel/process/syscall.c index a8e03ab6..20428fba 100644 --- a/kernel/process/syscall.c +++ b/kernel/process/syscall.c @@ -165,8 +165,7 @@ void sync_el0_handler_c(){ stop_current_process(); } } - if (result > 0) - save_syscall_return(result); + save_syscall_return(result); process_restore(); } From 35ed20072c434e40c89a322bf24c6b352e774bf1 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Thu, 24 Jul 2025 00:00:00 +0000 Subject: [PATCH 089/123] [FS] reverted wrong offsets --- kernel/filesystem/fat32.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/filesystem/fat32.cpp b/kernel/filesystem/fat32.cpp index 0e8f4289..d871be32 100644 --- a/kernel/filesystem/fat32.cpp +++ b/kernel/filesystem/fat32.cpp @@ -51,7 +51,7 @@ bool FAT32FS::init(uint32_t partition_sector){ uint16_t num_sectors = read_unaligned16(&mbs->num_sectors); cluster_count = (num_sectors == 0 ? mbs->large_num_sectors : num_sectors)/mbs->sectors_per_cluster; - data_start_sector = partition_first_sector + mbs->reserved_sectors + (mbs->sectors_per_fat * mbs->number_of_fats); + data_start_sector = mbs->reserved_sectors + (mbs->sectors_per_fat * mbs->number_of_fats); if (mbs->first_cluster_of_root_directory > cluster_count){ kprintf("[fat32 error] root directory cluster not found"); @@ -63,7 +63,7 @@ bool FAT32FS::init(uint32_t partition_sector){ kprintf("FAT32 Volume uses %i cluster size", bytes_per_sector); kprintf("Data start at %x",data_start_sector*512); - read_FAT(partition_first_sector + mbs->reserved_sectors, mbs->sectors_per_fat, mbs->number_of_fats); + read_FAT(mbs->reserved_sectors, mbs->sectors_per_fat, mbs->number_of_fats); return true; } From 3ff7a18d47a41940256b30df12c7adc5c2117f00 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Thu, 24 Jul 2025 00:00:00 +0000 Subject: [PATCH 090/123] [PROC, TEMP] Disable process monitor on real hw due to a weird bug --- kernel/input/input_dispatch.cpp | 8 +++++--- kernel/kernel.c | 5 ++--- kernel/kernel_processes/monitor/monitor_processes.c | 5 +++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/kernel/input/input_dispatch.cpp b/kernel/input/input_dispatch.cpp index c6cbc825..6a4e5b55 100644 --- a/kernel/input/input_dispatch.cpp +++ b/kernel/input/input_dispatch.cpp @@ -15,7 +15,7 @@ typedef struct { bool triggered; } shortcut; -shortcut shortcuts[16]; +shortcut shortcuts[16] = {0}; uint16_t shortcut_count = 0; @@ -52,7 +52,8 @@ uint16_t sys_subscribe_shortcut_current(keypress kp){ uint16_t sys_subscribe_shortcut(uint16_t pid, keypress kp){ shortcuts[shortcut_count] = (shortcut){ .kp = kp, - .pid = pid + .pid = pid, + .triggered = false }; return shortcut_count++; } @@ -98,7 +99,8 @@ bool sys_read_input(int pid, keypress *out){ } bool sys_shortcut_triggered_current(uint16_t sid){ - return sys_shortcut_triggered(get_current_proc_pid(), sid); + bool value = sys_shortcut_triggered(get_current_proc_pid(), sid); + return value; } bool sys_shortcut_triggered(uint16_t pid, uint16_t sid){ diff --git a/kernel/kernel.c b/kernel/kernel.c index 1b524537..ab38a44e 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -13,7 +13,6 @@ #include "filesystem/disk.h" #include "kernel_processes/boot/bootprocess.h" #include "input/input_dispatch.h" -#include "kernel_processes/monitor/monitor_processes.h" #include "networking/processes/net_proc.h" #include "memory/page_allocator.h" #include "networking/network.h" @@ -66,7 +65,7 @@ void kernel_main() { if (!input_init()) panic("Input initialization error"); - bool network_available = network_init(); + // bool network_available = network_init(); init_input_process(); mmu_init(); @@ -79,7 +78,7 @@ void kernel_main() { kprintf_l("Starting processes"); - if (network_available) launch_net_process(); + // if (network_available) launch_net_process(); init_bootprocess(); diff --git a/kernel/kernel_processes/monitor/monitor_processes.c b/kernel/kernel_processes/monitor/monitor_processes.c index 18149b56..bcca64e7 100644 --- a/kernel/kernel_processes/monitor/monitor_processes.c +++ b/kernel/kernel_processes/monitor/monitor_processes.c @@ -170,5 +170,10 @@ void monitor_procs(){ } process_t* start_process_monitor(){ +#if QEMU return create_kernel_process("procmonitor",monitor_procs); +#else + //TODO: disabled process monitor since shortcuts seem broken on rpi + return 0x0;//create_kernel_process("procmonitor",monitor_procs); +#endif } \ No newline at end of file From fa4348485bd8aac655ff1819bd2d2bb673d690df Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Thu, 24 Jul 2025 00:00:00 +0000 Subject: [PATCH 091/123] [UI] fixed process label colors --- kernel/kernel_processes/windows/desktop.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/kernel_processes/windows/desktop.cpp b/kernel/kernel_processes/windows/desktop.cpp index 950e85db..bb99ffc1 100644 --- a/kernel/kernel_processes/windows/desktop.cpp +++ b/kernel/kernel_processes/windows/desktop.cpp @@ -149,7 +149,7 @@ void Desktop::draw_tile(uint32_t column, uint32_t row){ single_label->set_text(namestr); single_label->set_bg_color(BG_COLOR+0x111111); - single_label->set_text_color(0xFFFFFF); + single_label->set_text_color(0xFFFFFFFF); single_label->set_font_size(3); single_label->rect = inner_rect; single_label->set_alignment(HorizontalAlignment::HorizontalCenter, VerticalAlignment::VerticalCenter); @@ -157,7 +157,7 @@ void Desktop::draw_tile(uint32_t column, uint32_t row){ extension_label->set_text(extstr); extension_label->set_bg_color(BG_COLOR+0x111111); - extension_label->set_text_color(0xFFFFFF); + extension_label->set_text_color(0xFFFFFFFF); extension_label->set_font_size(1); extension_label->rect = (gpu_rect){10 + ((tile_size.width + 10)*column)+ (sel ? border*2 : border), 50 + ((tile_size.height + 10) *row) + (sel ? border*2 : border), 1, 1}; extension_label->set_alignment(HorizontalAlignment::Leading, VerticalAlignment::Top); From 0c4f793eff0da4edb38f65e4e8e1acd97667aee6 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Thu, 24 Jul 2025 00:00:00 +0000 Subject: [PATCH 092/123] [MEM] gpu clear, memset and login optimizations --- kernel/kernel_processes/boot/login_screen.c | 2 +- shared/std/memfunctions.c | 39 ++++++++++++++------- shared/std/memfunctions.h | 6 ++-- shared/ui/draw/draw.c | 7 ++-- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/kernel/kernel_processes/boot/login_screen.c b/kernel/kernel_processes/boot/login_screen.c index e3552584..8d8f8c49 100644 --- a/kernel/kernel_processes/boot/login_screen.c +++ b/kernel/kernel_processes/boot/login_screen.c @@ -47,9 +47,9 @@ void login_screen(){ const char* name = BOOTSCREEN_TEXT; string title = string_l(name); string subtitle = string_l("Login"); + gpu_clear(BG_COLOR); while (1) { - gpu_clear(BG_COLOR); gpu_size screen_size = gpu_get_screen_size(); gpu_point screen_middle = {screen_size.width/2,screen_size.height/2}; string s = string_repeat('*',min(len,20)); diff --git a/shared/std/memfunctions.c b/shared/std/memfunctions.c index 1faa8314..fef21cb1 100644 --- a/shared/std/memfunctions.c +++ b/shared/std/memfunctions.c @@ -1,27 +1,42 @@ #include "memfunctions.h" -int memcmp(const void *s1, const void *s2, unsigned long n) { +int memcmp(const void *s1, const void *s2, unsigned long count) { const unsigned char *a = s1; const unsigned char *b = s2; - for (unsigned long i = 0; i < n; i++) { + for (unsigned long i = 0; i < count; i++) { if (a[i] != b[i]) return a[i] - b[i]; } return 0; } -void *memset(void *dest, int val, unsigned long count) { - unsigned char *ptr = dest; - while (count--) { - *ptr++ = (unsigned char)val; +void* memset(void* dest, uint32_t val, size_t count) { + uint64_t *d64 = (uint64_t *)dest; + uint64_t pattern = ((uint64_t)val << 32) | val; + + uint64_t blocks = count / 32; + for (uint64_t i = 0; i < blocks; i++) { + d64[0] = pattern; + d64[1] = pattern; + d64[2] = pattern; + d64[3] = pattern; + d64 += 4; } + + uint64_t remaining = (count % 32) / 8; + for (uint64_t i = 0; i < remaining; i++) d64[i] = pattern; + + uint8_t *d8 = (uint8_t *)(d64 + remaining); + uint8_t byte_val = val & 0xFF; + for (uint64_t i = 0; i < count % 8; i++) d8[i] = byte_val; + return dest; } -void *memcpy(void *dest, const void *src, uint64_t n) { +void* memcpy(void *dest, const void *src, uint64_t count) { uint64_t *d64 = (uint64_t *)dest; const uint64_t *s64 = (const uint64_t *)src; - uint64_t blocks = n / 32; + uint64_t blocks = count / 32; for (uint64_t i = 0; i < blocks; i++) { d64[0] = s64[0]; d64[1] = s64[1]; @@ -31,14 +46,12 @@ void *memcpy(void *dest, const void *src, uint64_t n) { s64 += 4; } - uint64_t remaining = (n % 32) / 8; - for (uint64_t i = 0; i < remaining; i++) { - d64[i] = s64[i]; - } + uint64_t remaining = (count % 32) / 8; + for (uint64_t i = 0; i < remaining; i++) d64[i] = s64[i]; uint8_t *d8 = (uint8_t *)(d64 + remaining); const uint8_t *s8 = (const uint8_t *)(s64 + remaining); - for (uint64_t i = 0; i < n % 8; i++) d8[i] = s8[i]; + for (uint64_t i = 0; i < count % 8; i++) d8[i] = s8[i]; return dest; } \ No newline at end of file diff --git a/shared/std/memfunctions.h b/shared/std/memfunctions.h index dfafaeeb..f8bb15b7 100644 --- a/shared/std/memfunctions.h +++ b/shared/std/memfunctions.h @@ -4,9 +4,9 @@ extern "C" { #include "types.h" -int memcmp(const void *s1, const void *s2, unsigned long n); -void *memset(void *dest, int val, unsigned long count); -void *memcpy(void *dest, const void *src, uint64_t n); +int memcmp(const void *s1, const void *s2, unsigned long count); +void* memset(void* dest, uint32_t val, size_t count); +void* memcpy(void *dest, const void *src, uint64_t count); #ifdef __cplusplus } diff --git a/shared/ui/draw/draw.c b/shared/ui/draw/draw.c index a0ab4c1e..e19a301c 100644 --- a/shared/ui/draw/draw.c +++ b/shared/ui/draw/draw.c @@ -1,6 +1,7 @@ #include "draw.h" #include "graph/font8x8_bridge.h" #include "kstring.h" +#include "std/memfunctions.h" #define line_height char_size + 2 @@ -61,11 +62,7 @@ void mark_dirty(uint32_t x, uint32_t y, uint32_t w, uint32_t h) { } void fb_clear(uint32_t* fb, uint32_t color) { - for (uint32_t y = 0; y < max_height; y++){ - for (uint32_t x = 0; x < max_width; x++){ - fb[y * (stride / 4) + x] = color; - } - } + memset(fb, color, stride * max_height); full_redraw = true; } From acb06c7774c4d4716aeb113f993ef463b66db1a8 Mon Sep 17 00:00:00 2001 From: differrari Date: Fri, 25 Jul 2025 00:00:00 +0000 Subject: [PATCH 093/123] fixed display variable --- run_raspi | 6 +++--- run_virt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/run_raspi b/run_raspi index 15a159a4..aa0b17eb 100755 --- a/run_raspi +++ b/run_raspi @@ -9,12 +9,12 @@ fi OS_TYPE="$(uname)" -DISPLAY="default" +DISPLAY_MODE="default" if [ "$OS_TYPE" = "Darwin" ]; then NETARG="vmnet-bridged,id=net0,ifname=en0" PRIVILEGE="sudo" - DISPLAY="sdl" + DISPLAY_MODE="sdl" elif [ "$OS_TYPE" = "Linux" ]; then NETARG="user,id=net0" PRIVILEGE="" @@ -26,7 +26,7 @@ fi $PRIVILEGE qemu-system-aarch64 \ -M raspi4b \ -kernel kernel.img \ --display $DISPLAY \ +-display $DISPLAY_MODE \ -device sd-card,drive=sd -drive id=sd,format=raw,file=disk.img,if=none \ -netdev $NETARG \ -serial mon:stdio \ diff --git a/run_virt b/run_virt index 22095e53..ab0b1c97 100755 --- a/run_virt +++ b/run_virt @@ -17,12 +17,12 @@ fi OS_TYPE="$(uname)" -DISPLAY="default" +DISPLAY_MODE="default" if [ "$OS_TYPE" = "Darwin" ]; then NETARG="vmnet-bridged,id=net0,ifname=en0" PRIVILEGE="sudo" - DISPLAY="sdl" + DISPLAY_MODE="sdl" elif [ "$OS_TYPE" = "Linux" ]; then NETARG="user,id=net0" PRIVILEGE="" @@ -37,7 +37,7 @@ $PRIVILEGE qemu-system-aarch64 \ -m 512M \ -kernel kernel.elf \ -device virtio-gpu-pci \ - -display $DISPLAY \ + -display $DISPLAY_MODE \ -netdev $NETARG \ -device virtio-net-pci,netdev=net0 \ -serial mon:stdio \ From 819bb10c6cde93bde3b38a3043537d1e55a91b20 Mon Sep 17 00:00:00 2001 From: differrari Date: Fri, 25 Jul 2025 00:00:00 +0000 Subject: [PATCH 094/123] [PROJ] Added variable for GPU --- run_virt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/run_virt b/run_virt index ab0b1c97..8399322d 100755 --- a/run_virt +++ b/run_virt @@ -18,6 +18,7 @@ fi OS_TYPE="$(uname)" DISPLAY_MODE="default" +SELECTED_GPU="virtio-gpu-pci" if [ "$OS_TYPE" = "Darwin" ]; then NETARG="vmnet-bridged,id=net0,ifname=en0" @@ -36,7 +37,7 @@ $PRIVILEGE qemu-system-aarch64 \ -cpu cortex-a72 \ -m 512M \ -kernel kernel.elf \ - -device virtio-gpu-pci \ + -device $SELECTED_GPU \ -display $DISPLAY_MODE \ -netdev $NETARG \ -device virtio-net-pci,netdev=net0 \ From 604fbf6cfe6aa75aa6c5fa914a71571bf47cf2d2 Mon Sep 17 00:00:00 2001 From: differrari Date: Fri, 25 Jul 2025 00:00:00 +0000 Subject: [PATCH 095/123] [MEM] replaced talloc with alloc_in_page in virtio gpu --- .../drivers/virtio_gpu_pci/virtio_gpu_pci.cpp | 97 +++++++++---------- 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/kernel/graph/drivers/virtio_gpu_pci/virtio_gpu_pci.cpp b/kernel/graph/drivers/virtio_gpu_pci/virtio_gpu_pci.cpp index f9c440e7..7e450bc1 100644 --- a/kernel/graph/drivers/virtio_gpu_pci/virtio_gpu_pci.cpp +++ b/kernel/graph/drivers/virtio_gpu_pci/virtio_gpu_pci.cpp @@ -113,8 +113,7 @@ typedef struct virtio_2d_resource { } virtio_2d_resource; gpu_size VirtioGPUDriver::get_display_info(){ - //TODO: replace talloc as we did in disk - virtio_gpu_ctrl_hdr* cmd = (virtio_gpu_ctrl_hdr*)talloc(sizeof(virtio_gpu_ctrl_hdr)); + virtio_gpu_ctrl_hdr* cmd = (virtio_gpu_ctrl_hdr*)allocate_in_page(gpu_dev.memory_page, sizeof(virtio_gpu_ctrl_hdr), ALIGN_4KB, true, true); cmd->type = VIRTIO_GPU_CMD_GET_DISPLAY_INFO; cmd->flags = 0; cmd->fence_id = 0; @@ -124,18 +123,18 @@ gpu_size VirtioGPUDriver::get_display_info(){ cmd->padding[1] = 0; cmd->padding[2] = 0; - virtio_gpu_resp_display_info* resp = (virtio_gpu_resp_display_info*)talloc(sizeof(virtio_gpu_resp_display_info)); + virtio_gpu_resp_display_info* resp = (virtio_gpu_resp_display_info*)allocate_in_page(gpu_dev.memory_page, sizeof(virtio_gpu_resp_display_info), ALIGN_4KB, true, true); if (!virtio_send(&gpu_dev, gpu_dev.common_cfg->queue_desc, gpu_dev.common_cfg->queue_driver, gpu_dev.common_cfg->queue_device, (uintptr_t)cmd, sizeof(virtio_gpu_ctrl_hdr), (uintptr_t)resp, sizeof(virtio_gpu_resp_display_info), VIRTQ_DESC_F_WRITE)){ - temp_free(cmd, sizeof(virtio_gpu_ctrl_hdr)); - temp_free(resp, sizeof(virtio_gpu_resp_display_info)); + free_from_page((void*)cmd, sizeof(virtio_gpu_ctrl_hdr)); + free_from_page((void*)resp, sizeof(virtio_gpu_resp_display_info)); return (gpu_size){0, 0}; } if (resp->hdr.type != 0x1101) { - temp_free(cmd, sizeof(virtio_gpu_ctrl_hdr)); - temp_free(resp, sizeof(virtio_gpu_resp_display_info)); + free_from_page((void*)(void*)cmd, sizeof(virtio_gpu_ctrl_hdr)); + free_from_page((void*)resp, sizeof(virtio_gpu_resp_display_info)); return (gpu_size){0, 0}; } @@ -151,13 +150,13 @@ gpu_size VirtioGPUDriver::get_display_info(){ } scanout_found = false; - temp_free(cmd, sizeof(virtio_gpu_ctrl_hdr)); - temp_free(resp, sizeof(virtio_gpu_resp_display_info)); + free_from_page((void*)cmd, sizeof(virtio_gpu_ctrl_hdr)); + free_from_page((void*)resp, sizeof(virtio_gpu_resp_display_info)); return (gpu_size){0, 0}; } bool VirtioGPUDriver::create_2d_resource(gpu_size size) { - virtio_2d_resource* cmd = (virtio_2d_resource*)talloc(sizeof(virtio_2d_resource)); + virtio_2d_resource* cmd = (virtio_2d_resource*)allocate_in_page(gpu_dev.memory_page, sizeof(virtio_2d_resource), ALIGN_4KB, true, true); cmd->hdr.type = VIRTIO_GPU_CMD_RESOURCE_CREATE_2D; cmd->hdr.flags = 0; @@ -172,23 +171,23 @@ bool VirtioGPUDriver::create_2d_resource(gpu_size size) { cmd->width = size.width; cmd->height = size.height; - virtio_gpu_ctrl_hdr* resp = (virtio_gpu_ctrl_hdr*)talloc(sizeof(virtio_gpu_ctrl_hdr)); + virtio_gpu_ctrl_hdr* resp = (virtio_gpu_ctrl_hdr*)allocate_in_page(gpu_dev.memory_page, sizeof(virtio_gpu_ctrl_hdr), ALIGN_4KB, true, true); if (!virtio_send(&gpu_dev, gpu_dev.common_cfg->queue_desc, gpu_dev.common_cfg->queue_driver, gpu_dev.common_cfg->queue_device, (uintptr_t)cmd, sizeof(virtio_2d_resource), (uintptr_t)resp, sizeof(virtio_gpu_ctrl_hdr), VIRTQ_DESC_F_WRITE)){ - temp_free(cmd, sizeof(virtio_2d_resource)); - temp_free(resp, sizeof(virtio_gpu_ctrl_hdr)); + free_from_page((void*)cmd, sizeof(virtio_2d_resource)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return false; } if (resp->type != 0x1100) { - temp_free(cmd, sizeof(virtio_2d_resource)); - temp_free(resp, sizeof(virtio_gpu_ctrl_hdr)); + free_from_page((void*)cmd, sizeof(virtio_2d_resource)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return false; } - temp_free(cmd, sizeof(virtio_2d_resource)); - temp_free(resp, sizeof(virtio_gpu_ctrl_hdr)); + free_from_page((void*)cmd, sizeof(virtio_2d_resource)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return true; } @@ -205,7 +204,7 @@ typedef struct virtio_backing_cmd { }__attribute__((packed)) virtio_backing_cmd; bool VirtioGPUDriver::attach_backing() { - virtio_backing_cmd* cmd = (virtio_backing_cmd*)talloc(sizeof(virtio_backing_cmd)); + virtio_backing_cmd* cmd = (virtio_backing_cmd*)allocate_in_page(gpu_dev.memory_page, sizeof(virtio_backing_cmd), ALIGN_4KB, true, true); cmd->hdr.type = VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING; cmd->hdr.flags = 0; @@ -222,23 +221,23 @@ bool VirtioGPUDriver::attach_backing() { cmd->entries[0].length = framebuffer_size; cmd->entries[0].padding = 0; - virtio_gpu_ctrl_hdr* resp = (virtio_gpu_ctrl_hdr*)talloc(sizeof(virtio_gpu_ctrl_hdr)); + virtio_gpu_ctrl_hdr* resp = (virtio_gpu_ctrl_hdr*)allocate_in_page(gpu_dev.memory_page, sizeof(virtio_gpu_ctrl_hdr), ALIGN_4KB, true, true); if (!virtio_send2(&gpu_dev, gpu_dev.common_cfg->queue_desc, gpu_dev.common_cfg->queue_driver, gpu_dev.common_cfg->queue_device, (uintptr_t)cmd, sizeof(*cmd), (uintptr_t)resp, sizeof(virtio_gpu_ctrl_hdr), VIRTQ_DESC_F_NEXT)){ - temp_free(cmd, sizeof(*cmd)); - temp_free(resp, sizeof(virtio_gpu_ctrl_hdr)); + free_from_page((void*)cmd, sizeof(*cmd)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return false; } if (resp->type != 0x1100) { - temp_free(cmd, sizeof(virtio_backing_cmd)); - temp_free(resp, sizeof(virtio_gpu_ctrl_hdr)); + free_from_page((void*)cmd, sizeof(virtio_backing_cmd)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return false; } - temp_free(cmd, sizeof(virtio_backing_cmd)); - temp_free(resp, sizeof(virtio_gpu_ctrl_hdr)); + free_from_page((void*)cmd, sizeof(virtio_backing_cmd)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return true; } @@ -250,7 +249,7 @@ typedef struct virtio_scanout_cmd { }__attribute__((packed)) virtio_scanout_cmd; bool VirtioGPUDriver::set_scanout() { - virtio_scanout_cmd* cmd = (virtio_scanout_cmd*)talloc(sizeof(virtio_scanout_cmd)); + virtio_scanout_cmd* cmd = (virtio_scanout_cmd*)allocate_in_page(gpu_dev.memory_page, sizeof(virtio_scanout_cmd), ALIGN_4KB, true, true); cmd->r.x = 0; cmd->r.y = 0; @@ -269,23 +268,23 @@ bool VirtioGPUDriver::set_scanout() { cmd->hdr.padding[1] = 0; cmd->hdr.padding[2] = 0; - virtio_gpu_ctrl_hdr* resp = (virtio_gpu_ctrl_hdr*)talloc(sizeof(virtio_gpu_ctrl_hdr)); + virtio_gpu_ctrl_hdr* resp = (virtio_gpu_ctrl_hdr*)allocate_in_page(gpu_dev.memory_page, sizeof(virtio_gpu_ctrl_hdr), ALIGN_4KB, true, true); if (!virtio_send(&gpu_dev, gpu_dev.common_cfg->queue_desc, gpu_dev.common_cfg->queue_driver, gpu_dev.common_cfg->queue_device, (uintptr_t)cmd, sizeof(*cmd), (uintptr_t)resp, sizeof(virtio_gpu_ctrl_hdr), VIRTQ_DESC_F_WRITE)){ - temp_free(cmd, sizeof(*cmd)); - temp_free(resp, sizeof(*resp)); + free_from_page((void*)cmd, sizeof(virtio_scanout_cmd)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return false; } if (resp->type != 0x1100) { - temp_free(cmd, sizeof(*cmd)); - temp_free(resp, sizeof(*resp)); + free_from_page((void*)cmd, sizeof(virtio_scanout_cmd)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return false; } - temp_free(cmd, sizeof(*cmd)); - temp_free(resp, sizeof(*resp)); + free_from_page((void*)cmd, sizeof(virtio_scanout_cmd)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return true; } @@ -298,7 +297,7 @@ typedef struct virtio_transfer_cmd { }__attribute__((packed)) virtio_transfer_cmd; bool VirtioGPUDriver::transfer_to_host(gpu_rect rect) { - virtio_transfer_cmd* cmd = (virtio_transfer_cmd*)talloc(sizeof(virtio_transfer_cmd)); + virtio_transfer_cmd* cmd = (virtio_transfer_cmd*)allocate_in_page(gpu_dev.memory_page, sizeof(virtio_transfer_cmd), ALIGN_4KB, true, true); cmd->hdr.type = VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D; cmd->hdr.flags = 0; @@ -314,23 +313,23 @@ bool VirtioGPUDriver::transfer_to_host(gpu_rect rect) { cmd->rect.width = rect.size.width; cmd->rect.height = rect.size.height; - virtio_gpu_ctrl_hdr* resp = (virtio_gpu_ctrl_hdr*)talloc(sizeof(virtio_gpu_ctrl_hdr)); + virtio_gpu_ctrl_hdr* resp = (virtio_gpu_ctrl_hdr*)allocate_in_page(gpu_dev.memory_page, sizeof(virtio_gpu_ctrl_hdr), ALIGN_4KB, true, true); if (!virtio_send(&gpu_dev, gpu_dev.common_cfg->queue_desc, gpu_dev.common_cfg->queue_driver, gpu_dev.common_cfg->queue_device, (uintptr_t)cmd, sizeof(*cmd), (uintptr_t)resp, sizeof(*resp), VIRTQ_DESC_F_WRITE)){ - temp_free(cmd, sizeof(*cmd)); - temp_free(resp, sizeof(*resp)); + free_from_page((void*)cmd, sizeof(virtio_transfer_cmd)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return false; } if (resp->type != 0x1100) { - temp_free(cmd, sizeof(*cmd)); - temp_free(resp, sizeof(*resp)); + free_from_page((void*)cmd, sizeof(virtio_transfer_cmd)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return false; } - temp_free(cmd, sizeof(*cmd)); - temp_free(resp, sizeof(*resp)); + free_from_page((void*)cmd, sizeof(virtio_transfer_cmd)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return true; } @@ -352,7 +351,7 @@ void VirtioGPUDriver::flush() { } } - virtio_flush_cmd* cmd = (virtio_flush_cmd*)talloc(sizeof(virtio_flush_cmd)); + virtio_flush_cmd* cmd = (virtio_flush_cmd*)allocate_in_page(gpu_dev.memory_page, sizeof(virtio_flush_cmd), ALIGN_4KB, true, true); cmd->hdr.type = VIRTIO_GPU_CMD_RESOURCE_FLUSH; cmd->hdr.flags = 0; @@ -367,23 +366,23 @@ void VirtioGPUDriver::flush() { cmd->rect.width = screen_size.width; cmd->rect.height = screen_size.height; - virtio_gpu_ctrl_hdr* resp = (virtio_gpu_ctrl_hdr*)talloc(sizeof(virtio_gpu_ctrl_hdr)); + virtio_gpu_ctrl_hdr* resp = (virtio_gpu_ctrl_hdr*)allocate_in_page(gpu_dev.memory_page, sizeof(virtio_gpu_ctrl_hdr), ALIGN_4KB, true, true); if (!virtio_send(&gpu_dev, gpu_dev.common_cfg->queue_desc, gpu_dev.common_cfg->queue_driver, gpu_dev.common_cfg->queue_device, (uintptr_t)cmd, sizeof(*cmd), (uintptr_t)resp, sizeof(*resp), VIRTQ_DESC_F_WRITE)){ - temp_free(cmd, sizeof(*cmd)); - temp_free(resp, sizeof(*resp)); + free_from_page((void*)cmd, sizeof(virtio_flush_cmd)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return; } if (resp->type != 0x1100) { - temp_free(cmd, sizeof(*cmd)); - temp_free(resp, sizeof(*resp)); + free_from_page((void*)cmd, sizeof(virtio_flush_cmd)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return; } - temp_free(cmd, sizeof(*cmd)); - temp_free(resp, sizeof(*resp)); + free_from_page((void*)cmd, sizeof(virtio_flush_cmd)); + free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return; } From 662226f2345ecfaa3b2bf1fa62e96dde223f9662 Mon Sep 17 00:00:00 2001 From: differrari Date: Fri, 25 Jul 2025 00:00:00 +0000 Subject: [PATCH 096/123] [MEM] using new allocator for virtio framebuffer --- kernel/graph/drivers/virtio_gpu_pci/virtio_gpu_pci.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/graph/drivers/virtio_gpu_pci/virtio_gpu_pci.cpp b/kernel/graph/drivers/virtio_gpu_pci/virtio_gpu_pci.cpp index 7e450bc1..089ea033 100644 --- a/kernel/graph/drivers/virtio_gpu_pci/virtio_gpu_pci.cpp +++ b/kernel/graph/drivers/virtio_gpu_pci/virtio_gpu_pci.cpp @@ -58,8 +58,7 @@ bool VirtioGPUDriver::init(gpu_size preferred_screen_size){ kprintf("Stride %i",screen_size.width * BPP); framebuffer_size = screen_size.width * screen_size.height * BPP; - framebuffer_size = (framebuffer_size); - framebuffer = talloc(framebuffer_size); + framebuffer = (uintptr_t)allocate_in_page(gpu_dev.memory_page, framebuffer_size, ALIGN_4KB, true, true); fb_set_bounds(screen_size.width,screen_size.height); @@ -316,7 +315,7 @@ bool VirtioGPUDriver::transfer_to_host(gpu_rect rect) { virtio_gpu_ctrl_hdr* resp = (virtio_gpu_ctrl_hdr*)allocate_in_page(gpu_dev.memory_page, sizeof(virtio_gpu_ctrl_hdr), ALIGN_4KB, true, true); if (!virtio_send(&gpu_dev, gpu_dev.common_cfg->queue_desc, gpu_dev.common_cfg->queue_driver, gpu_dev.common_cfg->queue_device, - (uintptr_t)cmd, sizeof(*cmd), (uintptr_t)resp, sizeof(*resp), VIRTQ_DESC_F_WRITE)){ + (uintptr_t)cmd, sizeof(virtio_transfer_cmd), (uintptr_t)resp, sizeof(virtio_gpu_ctrl_hdr), VIRTQ_DESC_F_WRITE)){ free_from_page((void*)cmd, sizeof(virtio_transfer_cmd)); free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return false; @@ -369,7 +368,7 @@ void VirtioGPUDriver::flush() { virtio_gpu_ctrl_hdr* resp = (virtio_gpu_ctrl_hdr*)allocate_in_page(gpu_dev.memory_page, sizeof(virtio_gpu_ctrl_hdr), ALIGN_4KB, true, true); if (!virtio_send(&gpu_dev, gpu_dev.common_cfg->queue_desc, gpu_dev.common_cfg->queue_driver, gpu_dev.common_cfg->queue_device, - (uintptr_t)cmd, sizeof(*cmd), (uintptr_t)resp, sizeof(*resp), VIRTQ_DESC_F_WRITE)){ + (uintptr_t)cmd, sizeof(virtio_flush_cmd), (uintptr_t)resp, sizeof(virtio_gpu_ctrl_hdr), VIRTQ_DESC_F_WRITE)){ free_from_page((void*)cmd, sizeof(virtio_flush_cmd)); free_from_page((void*)resp, sizeof(virtio_gpu_ctrl_hdr)); return; From 33bd876a5e36193968547141ce475de8ed1e8680 Mon Sep 17 00:00:00 2001 From: differrari Date: Fri, 25 Jul 2025 00:00:00 +0000 Subject: [PATCH 097/123] [MEM] fixed virtio descriptor alignment issue --- kernel/kernel_processes/boot/bootscreen.c | 1 - kernel/virtio/virtio_pci.c | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/kernel_processes/boot/bootscreen.c b/kernel/kernel_processes/boot/bootscreen.c index 7d81a385..25b9f32d 100644 --- a/kernel/kernel_processes/boot/bootscreen.c +++ b/kernel/kernel_processes/boot/bootscreen.c @@ -85,7 +85,6 @@ void boot_draw_lines(gpu_point current_point, gpu_point next_point, gpu_size siz stop_current_process(); } gpu_flush(); - // sleep(0); } } diff --git a/kernel/virtio/virtio_pci.c b/kernel/virtio/virtio_pci.c index a7a11ddb..db3e48ad 100644 --- a/kernel/virtio/virtio_pci.c +++ b/kernel/virtio/virtio_pci.c @@ -123,9 +123,9 @@ bool virtio_init_device(virtio_device *dev) { uint32_t queue_index = 0; uint32_t size; while ((size = select_queue(dev,queue_index))){ - uint64_t base = (uintptr_t)allocate_in_page(dev->memory_page, 16 * size, ALIGN_64B, true, true); - uint64_t avail = (uintptr_t)allocate_in_page(dev->memory_page, 4 + (2 * size), ALIGN_64B, true, true); - uint64_t used = (uintptr_t)allocate_in_page(dev->memory_page, sizeof(uint16_t) * (2 + size), ALIGN_64B, true, true); + uint64_t base = (uintptr_t)allocate_in_page(dev->memory_page, 16 * size, ALIGN_4KB, true, true); + uint64_t avail = (uintptr_t)allocate_in_page(dev->memory_page, 4 + (2 * size), ALIGN_4KB, true, true); + uint64_t used = (uintptr_t)allocate_in_page(dev->memory_page, sizeof(uint16_t) * (2 + size), ALIGN_4KB, true, true); kprintfv("[VIRTIO QUEUE %i] Device base %x",queue_index,base); kprintfv("[VIRTIO QUEUE %i] Device avail %x",queue_index,avail); From 582a73e1ca9c375e74634668e4dec48b7587502f Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 11:33:46 +0200 Subject: [PATCH 098/123] Update kconsole.cpp format --- kernel/console/kconsole/kconsole.cpp | 96 ++++++++++++++-------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/kernel/console/kconsole/kconsole.cpp b/kernel/console/kconsole/kconsole.cpp index e8975005..0524f096 100644 --- a/kernel/console/kconsole/kconsole.cpp +++ b/kernel/console/kconsole/kconsole.cpp @@ -7,8 +7,8 @@ KernelConsole::KernelConsole():cursor_x(0),cursor_y(0),is_initialized(false){ } bool KernelConsole::check_ready(){ - if(!gpu_ready()) return false; - if(!is_initialized){ + if (!gpu_ready()) return false; + if (!is_initialized){ is_initialized= true; resize(); clear(); @@ -17,86 +17,86 @@ bool KernelConsole::check_ready(){ } void KernelConsole::resize(){ - gpu_size s=gpu_get_screen_size(); - columns=s.width/char_width; - rows=s.height/ char_height; + gpu_size s = gpu_get_screen_size(); + columns = s.width / char_width; + rows = s.height / char_height; - if(row_data) temp_free(row_data,buffer_data_size); - buffer_data_size = rows*columns; - row_data= (char*)talloc(buffer_data_size); - if(!row_data){ - rows=columns=0; + if (row_data) temp_free(row_data, buffer_data_size); + buffer_data_size = rows * columns; + row_data = (char*)talloc(buffer_data_size); + if (!row_data){ + rows = columns = 0; row_ring.clear(); return; } row_ring.clear(); - for(uint32_t i=0;i=columns) newline(); + return; + } + if (cursor_x >= columns) newline(); uint32_t ri; - if(row_ring.pop(ri)){ + if (row_ring.pop(ri)){ row_ring.push(ri); - char* line=row_data+ri*columns; - line[cursor_x]=c; - gpu_draw_char({cursor_x*char_width,cursor_y*char_height},c,1,0xFFFFFFFF); + char* line = row_data + ri * columns; + line[cursor_x] = c; + gpu_draw_char({cursor_x * char_width,cursor_y*char_height}, c, 1, 0xFFFFFFFF); cursor_x++; } } void KernelConsole::put_string(const char* s){ - if(!check_ready()) return; - for(uint32_t i=0;s[i];i++) - put_char(s[i]); + if (!check_ready()) return; + for (uint32_t i=0; s[i]; i++) put_char(s[i]); gpu_flush(); } void KernelConsole::put_hex(uint64_t v){ - if(!check_ready()) return; + if (!check_ready()) return; put_char('0'); put_char('x'); - bool started=false; - for(uint32_t i=60;;i-=4){ - uint8_t n=(v>>i)&0xF; - char c=n<10?'0'+n:'A'+(n-10); - if(started||c!='0' ||i==0){ - started=true; + bool started = false; + for(uint32_t i =60 ;; i-=4){ + uint8_t n = (v>>i)&0xF; + char c = n < 10 ? '0' + n : 'A' + (n - 10); + if (started || c!='0' || i==0){ + started = true; put_char(c); } - if(i==0) break; + if (i == 0) break; } gpu_flush(); } void KernelConsole::newline(){ - if(!check_ready()) return; + if (!check_ready()) return; uint32_t ri; - if(row_ring.pop(ri)){ + if (row_ring.pop(ri)){ char* line=row_data+ri*columns; - for(uint32_t x=cursor_x;x=rows){ + if (cursor_y >= rows){ scroll(); - cursor_y= rows -1; + cursor_y = rows -1; } } void KernelConsole::scroll(){ - if(!check_ready()) return; + if (!check_ready()) return; uint32_t ri; - if(row_ring.pop(ri)){ + if (row_ring.pop(ri)){ char* line=row_data+ri*columns; - for(uint32_t x=0;x Date: Fri, 25 Jul 2025 11:34:28 +0200 Subject: [PATCH 099/123] Update kconsole.cpp format --- kernel/console/kconsole/kconsole.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/console/kconsole/kconsole.cpp b/kernel/console/kconsole/kconsole.cpp index 0524f096..3581472e 100644 --- a/kernel/console/kconsole/kconsole.cpp +++ b/kernel/console/kconsole/kconsole.cpp @@ -1,7 +1,7 @@ #include "kconsole.hpp" #include "console/serial/uart.h" -KernelConsole::KernelConsole():cursor_x(0),cursor_y(0),is_initialized(false){ +KernelConsole::KernelConsole() : cursor_x(0), cursor_y(0), is_initialized(false){ resize(); clear(); } From c7a28967b127bb6faf9745cc752fc0f03363711b Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 11:35:10 +0200 Subject: [PATCH 100/123] Update kconsole.h format --- kernel/console/kconsole/kconsole.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/console/kconsole/kconsole.h b/kernel/console/kconsole/kconsole.h index 7f8aee41..c381bbc2 100644 --- a/kernel/console/kconsole/kconsole.h +++ b/kernel/console/kconsole/kconsole.h @@ -7,8 +7,8 @@ extern "C" { void kconsole_putc(char c); void kconsole_puts(const char *s); void kconsole_puthex(uint64_t value); -void kconsole_clear(); +void kconsole_clear(); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif From 2673f8ecc737a4be7e6672be82e97ec11ff69680 Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 11:35:55 +0200 Subject: [PATCH 101/123] Update kconsole.hpp format --- kernel/console/kconsole/kconsole.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/console/kconsole/kconsole.hpp b/kernel/console/kconsole/kconsole.hpp index 8272d22e..feefa40f 100644 --- a/kernel/console/kconsole/kconsole.hpp +++ b/kernel/console/kconsole/kconsole.hpp @@ -1,4 +1,5 @@ #pragma once + #include "types.h" #include "data_struct/ring_buffer.hpp" #include "graph/graphics.h" @@ -7,9 +8,11 @@ class KernelConsole{ public: KernelConsole(); + void put_char(char c); void put_string(const char* str); void put_hex(uint64_t value); + void newline(); void scroll(); void clear(); @@ -28,9 +31,9 @@ class KernelConsole{ static constexpr uint32_t char_height=16; static constexpr uint32_t max_rows=128; - RingBuffer row_ring; + RingBuffer row_ring; char* row_data; uint32_t buffer_data_size; }; -extern KernelConsole kconsole; \ No newline at end of file +extern KernelConsole kconsole; From 9a5890746bfa26e894328769e1d3a46d1c74294b Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 11:36:50 +0200 Subject: [PATCH 102/123] Update fat32.cpp format --- kernel/filesystem/fat32.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/filesystem/fat32.cpp b/kernel/filesystem/fat32.cpp index 0da4fa9b..00eca4dd 100644 --- a/kernel/filesystem/fat32.cpp +++ b/kernel/filesystem/fat32.cpp @@ -6,7 +6,6 @@ #include "std/string.h" #include "std/memfunctions.h" #include "math/math.h" -#include "data_struct/linked_list.hpp" #define kprintfv(fmt, ...) \ ({ \ @@ -290,4 +289,4 @@ string_list* FAT32FS::list_contents(char *path){ uint32_t count = count_FAT(mbs->first_cluster_of_root_directory); return (string_list*)walk_directory(count, mbs->first_cluster_of_root_directory, path, list_entries_handler); -} \ No newline at end of file +} From 38b04b7ae91d071050f2e2ea5113f08fbbb5564c Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 11:44:40 +0200 Subject: [PATCH 103/123] Update kstring.c format --- kernel/kstring.c | 126 +++++++++++++++++++++-------------------------- 1 file changed, 56 insertions(+), 70 deletions(-) diff --git a/kernel/kstring.c b/kernel/kstring.c index 6cce742a..e4157794 100644 --- a/kernel/kstring.c +++ b/kernel/kstring.c @@ -6,80 +6,71 @@ //TODO: we can most likely get rid of this class now and use string entirely static uint32_t compute_length(const char *s, uint32_t max_length){ - if(s == NULL){return 0;} + if (s == NULL) return 0; + uint32_t len = 0; - while((max_length == 0 || len < max_length) && s[len] != '\0'){ - len++; - } + while ((max_length == 0 || len < max_length) && s[len] != '\0') len++; + return len; } kstring kstring_l(const char *literal){ - if(literal == NULL){ - return (kstring){.data = NULL, .length = 0}; - } + + if (literal == NULL) return (kstring){.data = NULL, .length = 0}; + uint32_t len = compute_length(literal, 0); - char *buf = (char*)talloc(len+1); - if(!buf){ - return (kstring){ .data = NULL, .length = 0}; - } - for(uint32_t i = 0; i < len; i++){ - buf[i] = literal[i]; - } + char *buf = (char*)talloc(len + 1); + if (!buf) return (kstring){ .data = NULL, .length = 0}; + + for (uint32_t i = 0; i < len; i++) buf[i] = literal[i]; + buf[len] = '\0'; return (kstring){.data = buf, .length = len}; } kstring kstring_repeat(char symbol, uint32_t amount){ - char *buf = (char*)talloc(amount+ 1); - if(!buf){ - return (kstring){ .data = NULL, .length = 0}; - } + char *buf = (char*)talloc(amount + 1); + if(!buf) return (kstring){ .data = NULL, .length = 0}; + memset(buf, symbol, amount); buf[amount] = '\0'; return (kstring){.data = buf, .length = amount}; } kstring kstring_tail(const char *array, uint32_t max_length){ - if(array == NULL){ - return (kstring){.data = NULL, .length = 0}; - } + if (array == NULL) return (kstring){.data = NULL, .length = 0}; + uint32_t len = compute_length(array, 0); - int offset = (int)len-(int)max_length; - if (offset < 0) offset=0; + int offset = (int)len - (int)max_length; + if (offset < 0) offset = 0; + uint32_t adjusted_len = len - offset; char *buf = (char*)talloc(adjusted_len+1); - if(!buf){ - return (kstring){.data = NULL, .length = 0}; - } - for(uint32_t i = 0; i < adjusted_len; i++){ - buf[i] = array[offset + i]; - } + if (!buf) return (kstring){.data = NULL, .length = 0}; + + for (uint32_t i = 0; i < adjusted_len; i++) buf[i] = array[offset + i]; + buf[adjusted_len] = '\0'; return (kstring){ .data = buf, .length = adjusted_len}; } kstring kstring_ca_max(const char *array, uint32_t max_length){ - if(array == NULL){ - return (kstring){ .data = NULL, .length = 0 }; - } + if(array == NULL) return (kstring){ .data = NULL, .length = 0 }; + uint32_t len=compute_length(array, max_length); char *buf = (char*)talloc(len+1); - if(!buf) { - return (kstring){.data = NULL, .length = 0}; - } - for(uint32_t i = 0; i < len; i++){ - buf[i] = array[i]; - } + if(!buf) return (kstring){.data = NULL, .length = 0}; + + for(uint32_t i = 0; i < len; i++) buf[i] = array[i]; + buf[len] = '\0'; return (kstring){.data = buf, .length = len}; } kstring kstring_c(const char c){ - char *buf=(char*)talloc(2); - if(!buf){ - return (kstring){ .data = NULL, .length = 0 }; - } + char *buf = (char*)talloc(2); + if(!buf) return (kstring){ .data = NULL, .length = 0 }; + buf[0] = c; buf[1] = '\0'; return (kstring){.data = buf, .length = 1}; @@ -92,14 +83,14 @@ kstring kstring_from_hex(uint64_t value){ buf[len++] = 'x'; bool started = false; - for(uint32_t i = 60;; i -= 4){ + for (uint32_t i = 60;; i -= 4){ uint8_t nibble = (value>>i)&0xF; - char curr_char=nibble<10?'0' + nibble : 'A'+(nibble - 10); - if(started||curr_char != '0'||i == 0) { + char curr_char = nibble < 10 ? '0' + nibble : 'A'+(nibble - 10); + if (started || curr_char != '0' || i == 0) { started = true; buf[len++] = curr_char; } - if(i == 0) break; + if (i == 0) break; } buf[len] = 0; @@ -113,41 +104,36 @@ kstring kstring_from_bin(uint64_t value){ buf[len++] = 'b'; bool started = false; - for(uint32_t i = 60;; i --){ + for (uint32_t i = 60;; i--){ char bit = (value >> i) & 1 ? '1' : '0'; - if(started || bit != '0' || i == 0){ + if (started || bit != '0' || i == 0){ started = true; buf[len++] = bit; } - if(i == 0) break; + if (i == 0) break; } buf[len] = 0; return (kstring){ .data = buf, .length = len }; } bool kstring_equals(kstring a, kstring b){ - return strcmp(a.data,b.data, false) == 0; + return strcmp(a.data, b.data, false) == 0; } kstring kstring_format_args(const char *fmt, const uint64_t *args, uint32_t arg_count){ - if(fmt == NULL){ - return (kstring){ .data = NULL, .length = 0 }; - } - if(arg_count > 0 && args == NULL){ - return (kstring){ .data = NULL, .length = 0 }; - } + if(fmt == NULL) return (kstring){ .data = NULL, .length = 0 }; + + if(arg_count > 0 && args == NULL) return (kstring){ .data = NULL, .length = 0 }; char *buf = (char*)talloc(256); - if(!buf){ - return (kstring){ .data = NULL, .length = 0 }; - } + if (!buf) return (kstring){ .data = NULL, .length = 0 }; uint32_t len = 0; uint32_t arg_index = 0; - for(uint32_t i = 0; fmt[i] && len < 255; i++){ - if(fmt[i] == '%' && fmt[i+1]) { + for (uint32_t i = 0; fmt[i] && len < 255; i++){ + if (fmt[i] == '%' && fmt[i + 1]) { i++; - if(arg_index >= arg_count){ + if (arg_index >= arg_count){ buf[len++] = '%'; buf[len++] = fmt[i]; continue; @@ -174,8 +160,8 @@ kstring kstring_format_args(const char *fmt, const uint64_t *args, uint32_t arg_ } case 's': { const char *str = (const char *)(uintptr_t)args[arg_index++]; - if(str){ - for(uint32_t j = 0; str[j] && len < 255; j++) buf[len++] = str[j]; + if (str){ + for (uint32_t j = 0; str[j] && len < 255; j++) buf[len++] = str[j]; } break; } @@ -184,18 +170,18 @@ kstring kstring_format_args(const char *fmt, const uint64_t *args, uint32_t arg_ char temp[21]; uint32_t temp_len = 0; bool negative = false; - if((int64_t)val < 0){ + if ((int64_t)val < 0){ negative = true; val = (uint64_t)(-(int64_t)val); } - do{ + do { temp[temp_len++] = '0' + (val % 10); val /= 10; - }while(val && temp_len < sizeof(temp)-1); - if(negative && temp_len < sizeof(temp)-1){ + } while (val && temp_len < sizeof(temp)-1); + if (negative && temp_len < sizeof(temp)-1){ temp[temp_len++] = '-'; } - for(int j = temp_len - 1; j >= 0 && len < 255; j--){ + for (int j = temp_len - 1; j >= 0 && len < 255; j--){ buf[len++] = temp[j]; } break; @@ -204,7 +190,7 @@ kstring kstring_format_args(const char *fmt, const uint64_t *args, uint32_t arg_ buf[len++] = '%'; buf[len++] = fmt[i]; } - }else{ + } else { buf[len++] = fmt[i]; } } From c0e6bd8efb3f351a22e8c5e9430f5fcf7737c9d8 Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:01:45 +0200 Subject: [PATCH 104/123] Update chunked_list.cpp format --- shared/data_struct/chunked_list.cpp | 121 +++++++++++++++------------- 1 file changed, 65 insertions(+), 56 deletions(-) diff --git a/shared/data_struct/chunked_list.cpp b/shared/data_struct/chunked_list.cpp index 96ceaa02..af95e3d7 100644 --- a/shared/data_struct/chunked_list.cpp +++ b/shared/data_struct/chunked_list.cpp @@ -4,110 +4,119 @@ extern "C" { cchunked_list_t* cchunked_list_create(uint64_t chunkSize){ - uintptr_t raw=malloc(sizeof(cchunked_node_t)+chunkSize*sizeof(void*)); - if(!raw) return NULL; - cchunked_list_t* list=(cchunked_list_t*)malloc(sizeof(cchunked_list_t)); - if(!list){ + uintptr_t raw = malloc(sizeof(cchunked_node_t)+chunkSize*sizeof(void*)); + if (!raw) return NULL; + + cchunked_list_t* list = (cchunked_list_t*)malloc(sizeof(cchunked_list_t)); + if (!list){ free((void*)raw,sizeof(cchunked_node_t)+chunkSize*sizeof(void*)); - return NULL;} + return NULL; + } + list->chunkSize=chunkSize; list->length=0; list->head=(cchunked_node_t*)raw; list->head->count=0; list->head->next=NULL; list->tail=list->head; + return list; } void cchunked_list_destroy(cchunked_list_t* list){ - if(!list) return; + if (!list) return; + cchunked_node_t* node=list->head; - while(node){ + while (node){ cchunked_node_t* next=node->next; free(node,sizeof(cchunked_node_t)+list->chunkSize*sizeof(void*)); node=next; } + free(list,sizeof(cchunked_list_t)); } cchunked_list_t* cchunked_list_clone(const cchunked_list_t* list){ - if(!list) return NULL; + if (!list) return NULL; + cchunked_list_t* clone=cchunked_list_create(list->chunkSize); - if(!clone) return NULL; - for(cchunked_node_t* it=list->head;it;it=it->next){ - for(uint64_t i=0;icount;i++) + if (!clone) return NULL; + + for (cchunked_node_t* it = list->head; it; it = it->next){ + for (uint64_t i = 0; icount; i++) cchunked_list_push_back(clone,it->data[i]); } return clone; } void cchunked_list_push_back(cchunked_list_t* list, void* data){ - if(!list) return; + if (!list) return; //first mnode - if(list->tail == NULL){ + if (list->tail == NULL){ uintptr_t m = malloc(sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); - if(!m) return; + if (!m) return; cchunked_node_t* node = (cchunked_node_t*)m; node->count = 0; - node->next = NULL; + node->next = NULL; list->head=list->tail = node; } - if(list->tail->count == list->chunkSize){ //last chunk - uintptr_t m = malloc(sizeof(cchunked_node_t)+list->chunkSize * sizeof(void*)); - if(!m) return; - cchunked_node_t* node=(cchunked_node_t*)m; + + if (list->tail->count == list->chunkSize){ //last chunk + uintptr_t m = malloc(sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); + if (!m) return; + cchunked_node_t* node = (cchunked_node_t*)m; node->count = 0; - node->next = NULL; + node->next = NULL; list->tail->next = node; list->tail = node; } - list->tail->data[list->tail->count++]=data; + list->tail->data[list->tail->count++] = data; list->length++; } cchunked_node_t* cchunked_list_insert_after(cchunked_list_t* list,cchunked_node_t* node, void* data){ - if(!list) - return NULL; - if(!node){ + if (!list) return NULL; + + if (!node){ cchunked_list_push_back(list, data); return list->tail; } + if(node->count < list->chunkSize){//chunk isnt completrly full - node->data[node->count++]=data; + node->data[node->count++] = data; list->length++; return node; } + //new node - uintptr_t m = malloc(sizeof(cchunked_node_t) + list->chunkSize*sizeof(void*)); - if(!m) return NULL; + uintptr_t m = malloc(sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); + if (!m) return NULL; cchunked_node_t* new_node = (cchunked_node_t*)m; - new_node->count =1; + new_node->count = 1; new_node->next = node->next; new_node->data[0] = data; //linking new node node->next = new_node; - if (list->tail == node) - list->tail = new_node; + if (list->tail == node) list->tail = new_node; + list->length++; return new_node; } void* cchunked_list_pop_front(cchunked_list_t* list){ - if(!list || list->length == 0 || list->head == NULL) - return NULL; + if (!list || list->length == 0 || list->head == NULL) return NULL; + void* data = list->head->data[0]; - if(list->head->count > 1){ - for(uint64_t i = 1; i < list->head->count; ++i) - list->head->data[i-1] = list->head->data[i]; + if (list->head->count > 1){ + for (uint64_t i = 1; i < list->head->count; ++i) list->head->data[i-1] = list->head->data[i]; list->head->count--; - }else{ + } else { //uniq element cchunked_node_t* old =list->head; list->head = old->next; - if(list->head == NULL){ - list->tail = NULL; - } + if(list->head == NULL) list->tail = NULL; free(old, sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); } + list->length--; return data; } @@ -115,22 +124,21 @@ void* cchunked_list_pop_front(cchunked_list_t* list){ void* cchunked_list_remove_node(cchunked_list_t* list, cchunked_node_t* node){ - if(!list||!node|| !list->head) return NULL; + if (!list || !node || !list->head) return NULL; //delegate to pop_front - if(node == list->head) - return cchunked_list_pop_front(list); + if (node == list->head) return cchunked_list_pop_front(list); cchunked_node_t* prev = list->head; - while(prev->next && prev->next != node) prev= prev->next; - if(prev->next != node) return NULL; + while (prev->next && prev->next != node) prev= prev->next; + if (prev->next != node) return NULL; void* data = node->data[0]; - for(uint64_t i = 1; i < node->count; ++i) - node->data[i-1] = node->data[i]; + for (uint64_t i = 1; i < node->count; ++i) node->data[i-1] = node->data[i]; + node->count--; list->length--; - if(node->count == 0){ + if (node->count == 0){ prev->next = node->next; if(list->tail == node) list->tail = prev; free(node, sizeof(cchunked_node_t)+list->chunkSize * sizeof(void*)); @@ -141,7 +149,7 @@ void* cchunked_list_remove_node(cchunked_list_t* list, cchunked_node_t* node){ void cchunked_list_update(cchunked_list_t* list, cchunked_node_t* node, void* new_data){ (void)list; - if(node&&node->count) node->data[0] = new_data; + if (node&&node->count) node->data[0] = new_data; } uint64_t cchunked_list_length(const cchunked_list_t* list){ @@ -149,25 +157,26 @@ uint64_t cchunked_list_length(const cchunked_list_t* list){ } uint64_t cchunked_list_size_bytes(const cchunked_list_t* list){ - if(!list) return 0; + if (!list) return 0; uint64_t nodes = 0; - for(cchunked_node_t* it = list->head; it; it = it->next) nodes++; + for (cchunked_node_t* it = list->head; it; it = it->next) nodes++; + return nodes * (sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); } void cchunked_list_for_each(const cchunked_list_t* list, void (*func)(void*)){ - if(!list||!func) return; - for(cchunked_node_t* it = list->head; it; it = it->next) - for(uint64_t i = 0; i < it->count; ++i) + if (!list || !func) return; + for (cchunked_node_t* it = list->head; it; it = it->next) + for (uint64_t i = 0; i < it->count; ++i) func(it->data[i]); } void cchunked_list_update_at(cchunked_list_t* list, cchunked_node_t* node,uint64_t offset,void* new_data){ - if(!list || !node || offset >= node->count)//{ - return; + if(!list || !node || offset >= node->count)return; + node->data[offset] = new_data; } int cchunked_list_is_empty(const cchunked_list_t* list){ - return (!list ||list->length == 0) ? 1 : 0; + return (!list || list->length == 0) ? 1 : 0; } } From 6d5119ba83285a5c9989c3af22511ffe5b391bcc Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:05:11 +0200 Subject: [PATCH 105/123] Update chunked_list.hpp format --- shared/data_struct/chunked_list.hpp | 57 +++++++++++++++-------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/shared/data_struct/chunked_list.hpp b/shared/data_struct/chunked_list.hpp index d20c3142..41069f58 100644 --- a/shared/data_struct/chunked_list.hpp +++ b/shared/data_struct/chunked_list.hpp @@ -49,7 +49,7 @@ class ChunkedList{ explicit ChunkedList(uint64_t cs): head(nullptr), tail(nullptr), length_(0), chunkSize(cs){} ~ChunkedList(){ - while(head){ + while (head){ Node* nx = head->next; ::free(head, sizeof(Node) + chunkSize * sizeof(T)); head = nx; @@ -57,52 +57,51 @@ class ChunkedList{ } ChunkedList(const ChunkedList& other): head(nullptr), tail(nullptr), length_(0), chunkSize(other.chunkSize){ - for(Node* c = other.head; c; c = c->next) - for(uint64_t i = 0; i < c->count; ++i) + for (Node* c = other.head; c; c = c->next) + for (uint64_t i = 0; i < c->count; ++i) push_back(c->data[i]); } ChunkedList& operator=(const ChunkedList& other){ - if(this != &other){ + if (this != &other){ clear(); chunkSize = other.chunkSize; - for(Node* c = other.head; c; c = c->next) - for(uint64_t i = 0; i < c->count; ++i) + for (Node* c = other.head; c; c = c->next) + for (uint64_t i = 0; i < c->count; ++i) push_back(c->data[i]); } return *this; } void push_back(const T& value){ - if(!tail) allocFirst(); - if(tail->count == chunkSize) allocChunk(); + if (!tail) allocFirst(); + if (tail->count == chunkSize) allocChunk(); tail->data[tail->count++] = value; ++length_; } T pop_front(){ - if(!head) return T(); + if (!head) return T(); T val = head->data[0]; - if(head->count > 1){ - for(uint64_t i = 1; i < head->count; ++i) - head->data[i-1] = head->data[i]; + if (head->count > 1){ + for (uint64_t i = 1; i < head->count; ++i) head->data[i-1] = head->data[i]; --head->count; - }else{ + } else { Node* old = head; head = head->next; ::free(old, sizeof(Node) + chunkSize * sizeof(T)); - if(!head) tail = nullptr; + if (!head) tail = nullptr; } --length_; return val; } Node* insert_after(Node* node, const T& value){ - if(!node){ + if (!node){ push_back(value); return tail; } - if(node->count < chunkSize){ + if (node->count < chunkSize){ node->data[node->count++] = value; ++length_; return node; @@ -110,14 +109,14 @@ class ChunkedList{ Node* n=allocNode(value); n->next = node->next; node->next = n; - if(tail ==node) tail = n; + if (tail ==node) tail = n; ++length_; return n; } T remove_node(Node* node){ - if(!node|| !head) return T(); - if(node == head){ + if (!node|| !head) return T(); + if (node == head){ T val = head->data[0]; uint64_t removed = head->count; Node* nxt = head->next; @@ -128,12 +127,14 @@ T remove_node(Node* node){ return val; } Node* prev = head; - while(prev->next && prev->next != node) prev = prev->next; - if(prev->next != node) return T(); + while (prev->next && prev->next != node) prev = prev->next; + if (prev->next != node) return T(); + T val = node->data[0]; uint64_t removed = node->count; - prev->next= node->next; - if(tail==node) tail = prev; + prev->next = node->next; + if (tail==node) tail = prev; + ::free(node, sizeof(Node) + chunkSize * sizeof(T)); length_ -= removed; return val; @@ -159,8 +160,8 @@ T remove_node(Node* node){ template void for_each(Func f) const{ - for(Node* it = head; it; it = it->next) - for(uint64_t i = 0; i < it->count; ++i) + for (Node* it = head; it; it = it->next) + for (uint64_t i = 0; i < it->count; ++i) f(it->data[i]); } @@ -181,7 +182,7 @@ T remove_node(Node* node){ void allocFirst(){ uintptr_t raw = ::malloc(sizeof(Node) +chunkSize*sizeof(T)); - head = tail =reinterpret_cast(raw); + head = tail = reinterpret_cast(raw); head->count = 0; head->next = nullptr; } @@ -196,7 +197,7 @@ T remove_node(Node* node){ } void clear(){ - while(head) pop_front(); + while (head) pop_front(); } }; -#endif \ No newline at end of file +#endif From 18617b976c7650fb0b8f000f9634bf9801cb0170 Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:08:38 +0200 Subject: [PATCH 106/123] Update doubly_linked_list.cpp format --- shared/data_struct/doubly_linked_list.cpp | 116 ++++++++++++---------- 1 file changed, 65 insertions(+), 51 deletions(-) diff --git a/shared/data_struct/doubly_linked_list.cpp b/shared/data_struct/doubly_linked_list.cpp index 8623c6bd..2b01d051 100644 --- a/shared/data_struct/doubly_linked_list.cpp +++ b/shared/data_struct/doubly_linked_list.cpp @@ -1,18 +1,20 @@ #include "doubly_linked_list.hpp" cdouble_linked_list_t* cdouble_linked_list_create(void){ - uintptr_t raw= malloc((uint64_t)sizeof(cdouble_linked_list_t));//i believe that casting sizeof is better until size_t is defined correctly - if(raw == 0) return NULL; - cdouble_linked_list_t *list=(cdouble_linked_list_t*)raw; - list->head = list->tail =NULL; + uintptr_t raw = malloc((uint64_t)sizeof(cdouble_linked_list_t));//i believe that casting sizeof is better until size_t is defined correctly + if (raw == 0) return NULL; + + cdouble_linked_list_t *list = (cdouble_linked_list_t*)raw; + list->head = list->tail = NULL; list->length = 0; return list; } void cdouble_linked_list_destroy(cdouble_linked_list_t *list){ - if(!list) return; + if (!list) return; + cdouble_linked_list_node_t *node=list->head; - for(uint64_t i = 0; i < list->length; ++i){ + for (uint64_t i = 0; i < list->length; ++i){ cdouble_linked_list_node_t *next = node->next; free(node,(uint64_t)sizeof(cdouble_linked_list_node_t)); node = next; @@ -21,19 +23,22 @@ void cdouble_linked_list_destroy(cdouble_linked_list_t *list){ } cdouble_linked_list_t* cdouble_linked_list_clone(const cdouble_linked_list_t *list){ //could create data aliasing. be careful. TODO - if(!list) return NULL; + if (!list) return NULL; + cdouble_linked_list_t *clone=cdouble_linked_list_create(); - if(!clone) return NULL; + if (!clone) return NULL; + cdouble_linked_list_node_t *it =list->head; - for(uint64_t i = 0; ilength; ++i){ + for (uint64_t i = 0; ilength; ++i){ uintptr_t raw =malloc((uint64_t)sizeof(cdouble_linked_list_node_t)); - if(raw) { + if (raw) { cdouble_linked_list_node_t *node =(cdouble_linked_list_node_t*)raw; node->data = it->data; - if(clone->length == 0){ + + if (clone->length == 0){ node->next=node->prev = node; clone->head=clone->tail = node; - }else{ + } else { node->prev=clone->tail; node->next=clone->head; clone->tail->next=node; @@ -48,15 +53,16 @@ cdouble_linked_list_t* cdouble_linked_list_clone(const cdouble_linked_list_t *li } void cdouble_linked_list_push_front(cdouble_linked_list_t *list, void *data){ - if(!list) return; + if (!list) return; uintptr_t raw= malloc((uint64_t)sizeof(cdouble_linked_list_node_t)); - if(raw == 0) return; + if (raw == 0) return; cdouble_linked_list_node_t *node=(cdouble_linked_list_node_t*)raw; node->data = data; - if(list->length == 0){ + + if (list->length == 0){ node->next=node->prev = node; list->head=list->tail = node; - }else{ + } else { node->next=list->head; node->prev=list->tail; list->head->prev= node; @@ -67,15 +73,16 @@ void cdouble_linked_list_push_front(cdouble_linked_list_t *list, void *data){ } void cdouble_linked_list_push_back(cdouble_linked_list_t* list, void* data){ - if(!list) return; + if (!list) return; uintptr_t raw=malloc((uint64_t)sizeof(cdouble_linked_list_node_t)); - if(raw ==0) return; + if (raw ==0) return; cdouble_linked_list_node_t* node=(cdouble_linked_list_node_t*)raw; - node->data=data; - if(list->length==0){ + node->data = data; + + if (list->length==0){ node->next=node->prev=node; list->head=list->tail = node; - }else{ + } else { node->prev= list->tail; node->next=list->head; list->tail->next=node; @@ -86,12 +93,13 @@ void cdouble_linked_list_push_back(cdouble_linked_list_t* list, void* data){ } void* cdouble_linked_list_pop_front(cdouble_linked_list_t* list){ - if(!list||list->length==0) return NULL; + if (!list||list->length==0) return NULL; + cdouble_linked_list_node_t* node=list->head; void* data=node->data; - if(list->length == 1){ + if (list->length == 1){ list->head=list->tail=NULL; - }else{ + } else { list->head=node->next; list->head->prev =list->tail; list->tail->next=list->head; @@ -102,12 +110,13 @@ void* cdouble_linked_list_pop_front(cdouble_linked_list_t* list){ } void* cdouble_linked_list_pop_back(cdouble_linked_list_t* list){ - if(!list||list->length==0) return NULL; + if (!list||list->length==0) return NULL; + cdouble_linked_list_node_t* node=list->tail; void* data=node->data; - if(list->length==1){ + if (list->length==1){ list->head = list->tail=NULL; - }else{ + } else { list->tail=node->prev; list->tail->next=list->head; list->head->prev=list->tail; @@ -118,27 +127,30 @@ void* cdouble_linked_list_pop_back(cdouble_linked_list_t* list){ } cdouble_linked_list_node_t* cdouble_linked_list_insert_after(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* data){ - if(!list) return NULL; - if(!node){ + if (!list) return NULL; + if (!node){ cdouble_linked_list_push_front(list, data); return list->head; } + uintptr_t raw=malloc((uint64_t)sizeof(cdouble_linked_list_node_t)); - if(raw==0) return NULL; - cdouble_linked_list_node_t* new_node=(cdouble_linked_list_node_t*)raw; - new_node->data=data; - new_node->next= node->next; - new_node->prev=node; - node->next->prev= new_node; - node->next= new_node; - if(list->tail == node) list->tail=new_node; + if (raw==0) return NULL; + + cdouble_linked_list_node_t* new_node = (cdouble_linked_list_node_t*)raw; + new_node->data = data; + new_node->next = node->next; + new_node->prev = node; + node->next->prev = new_node; + node->next = new_node; + if (list->tail == node) list->tail = new_node; ++list->length; return new_node; } cdouble_linked_list_node_t* cdouble_linked_list_insert_before(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* data){ - if(!list) return NULL; - if(!node){ + if (!list) return NULL; + + if (!node){ cdouble_linked_list_push_back(list, data); return list->tail; } @@ -146,12 +158,13 @@ cdouble_linked_list_node_t* cdouble_linked_list_insert_before(cdouble_linked_lis } void* cdouble_linked_list_remove(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node){ - if(!list|| !node|| list->length==0) return NULL; - if(node==list->head) return cdouble_linked_list_pop_front(list); - if(node==list->tail) return cdouble_linked_list_pop_back(list); - node->prev->next=node->next; - node->next->prev=node->prev; - void* data=node->data; + if (!list|| !node|| list->length==0) return NULL; + + if (node==list->head) return cdouble_linked_list_pop_front(list); + if (node==list->tail) return cdouble_linked_list_pop_back(list); + node->prev->next = node->next; + node->next->prev = node->prev; + void* data = node->data; --list->length; free(node,(uint64_t)sizeof(cdouble_linked_list_node_t)); return data; @@ -159,7 +172,7 @@ void* cdouble_linked_list_remove(cdouble_linked_list_t* list, cdouble_linked_lis void cdouble_linked_list_update(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* new_data){ (void)list; - if(node) node->data=new_data; + if (node) node->data=new_data; } uint64_t cdouble_linked_list_length(const cdouble_linked_list_t* list){ @@ -167,15 +180,16 @@ uint64_t cdouble_linked_list_length(const cdouble_linked_list_t* list){ } uint64_t cdouble_linked_list_size_bytes(const cdouble_linked_list_t* list){ - return list?list-> length*sizeof(cdouble_linked_list_node_t):0; + return list?list-> length * sizeof(cdouble_linked_list_node_t):0; } cdouble_linked_list_node_t* cdouble_linked_list_find(cdouble_linked_list_t* list, void* key, int (*cmp)(void*,void*)){ - if(!list||!cmp|| list->length==0) return NULL; + if (!list||!cmp|| list->length==0) return NULL; + cdouble_linked_list_node_t* it=list->head; - for(uint64_t i=0; ilength; ++i){ - if(cmp(it->data,key)==0) return it; - it=it->next; + for (uint64_t i=0; ilength; ++i){ + if (cmp(it->data,key)==0) return it; + it = it->next; } return NULL; } From b4c7d891deeb1bf5a61437ccd424d03a4d272e4e Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:12:05 +0200 Subject: [PATCH 107/123] Update doubly_linked_list.hpp format --- shared/data_struct/doubly_linked_list.hpp | 136 ++++++++++++---------- 1 file changed, 75 insertions(+), 61 deletions(-) diff --git a/shared/data_struct/doubly_linked_list.hpp b/shared/data_struct/doubly_linked_list.hpp index 1c6d045e..0bc71f34 100644 --- a/shared/data_struct/doubly_linked_list.hpp +++ b/shared/data_struct/doubly_linked_list.hpp @@ -17,9 +17,11 @@ typedef struct cdouble_linked_list{ uint64_t length; }cdouble_linked_list_t; + extern uintptr_t malloc(uint64_t size); extern void free(void *ptr, uint64_t size); + cdouble_linked_list_t *cdouble_linked_list_create(void); void cdouble_linked_list_destroy(cdouble_linked_list_t *list); cdouble_linked_list_t *cdouble_linked_list_clone(const cdouble_linked_list_t *list); @@ -34,6 +36,7 @@ void cdouble_linked_list_update(cdouble_linked_list_t *list, cdouble_linked_list uint64_t cdouble_linked_list_length(const cdouble_linked_list_t *list); uint64_t cdouble_linked_list_size_bytes(const cdouble_linked_list_t *list); cdouble_linked_list_node_t* cdouble_linked_list_find(cdouble_linked_list_t *list, void *key, int (*cmp)(void *, void *)); + #ifdef __cplusplus } @@ -52,48 +55,50 @@ class LinkedList{ Node* alloc_node(const T& value){ uintptr_t raw= malloc((uint64_t)sizeof(Node)); - if(raw == 0) return nullptr; - Node* n =(Node*)raw; - n->data=value; - n->next=n->prev=nullptr; + if (raw == 0) return nullptr; + + Node* n = (Node*)raw; + n->data = value; + n->next = n->prev = nullptr; return n; } + void free_node(Node* n){ - if(!n) return; + if (!n) return; free(n,(uint64_t)sizeof(Node)); } static void swap(LinkedList& a, LinkedList& b) noexcept{ Node* tmp_head = a.head; - a.head= b.head; - b.head= tmp_head; - Node* tmp_tail =a.tail; - a.tail= b.tail; - b.tail= tmp_tail; + a.head = b.head; + b.head = tmp_head; + Node* tmp_tail = a.tail; + a.tail = b.tail; + b.tail = tmp_tail; uint64_t tmp_length = a.length; a.length = b.length; b.length = tmp_length; } public: - LinkedList():head(nullptr), tail(nullptr), length(0){} + LinkedList() : head(nullptr), tail(nullptr), length(0){} LinkedList(const LinkedList& other):head(nullptr), tail(nullptr), length(0){ - if(other.head){ + if (other.head){ Node* it = other.head; - do{ + do { push_back(it->data); it = it->next; - }while(it != other.head); + } while (it != other.head); } } ~LinkedList(){ - while(!empty()) pop_front(); + while (!empty()) pop_front(); } LinkedList& operator=(const LinkedList& other){ - if(this != &other){ + if (this != &other) { LinkedList tmp(other); swap(*this, tmp); } @@ -102,43 +107,46 @@ class LinkedList{ void push_front(const T& value){ Node* n = alloc_node(value); - if(!n) return; - if(!head){ + if( !n) return; + + if (!head){ head = tail = n; n->next = n->prev = n; - }else{ - n->next= head; - n->prev= tail; - head->prev=n; - tail->next= n; - head= n; + } else { + n->next = head; + n->prev = tail; + head->prev = n; + tail->next = n; + head = n; } ++length; } void push_back(const T& value){ - Node* n =alloc_node(value); - if(!n) return; - if(!tail){ + Node* n = alloc_node(value); + if (!n) return; + + if (!tail){ head = tail = n; n->next = n->prev = n; - }else{ - n->prev = tail; - n->next = head; - tail->next = n; - head->prev = n; - tail = n; + } else { + n->prev = tail; + n->next = head; + tail->next = n; + head->prev = n; + tail = n; } ++length; } T pop_front(){ - if(!head) return T(); + if !head) return T(); + Node* n = head; T val = n->data; - if(head == tail){ - head =tail=nullptr; - }else{ + if (head == tail){ + head = tail=nullptr; + } else { head = head->next; head->prev = tail; tail->next = head; @@ -149,12 +157,13 @@ class LinkedList{ } T pop_back(){ - if(!tail) return T(); + if (!tail) return T(); + Node* n = tail; T val = n->data; - if(head == tail){ + if (head == tail){ head = tail = nullptr; - }else{ + } else { tail = tail->prev; tail->next = head; head->prev = tail; @@ -165,23 +174,25 @@ class LinkedList{ } Node* insert_after(Node* node, const T& value){ - if(!node){ + if (!node){ push_front(value); return head; } - Node* n= alloc_node(value); - if(!n) return nullptr; + + Node* n = alloc_node(value); + if (!n) return nullptr; + n->next=node->next; n->prev=node; node->next->prev = n; node->next= n; - if(tail==node) tail = n; + if (tail == node) tail = n; ++length; return n; } Node* insert_before(Node* node, const T& value){ - if(!node){ + if (!node){ push_back(value); return tail; } @@ -189,19 +200,20 @@ class LinkedList{ } T remove(Node* node){ - if(!node) return T(); - if(node == head) return pop_front(); - if(node == tail) return pop_back(); - node->prev->next=node->next; - node->next->prev=node->prev; - T val=node->data; + if (!node) return T(); + if (node == head) return pop_front(); + if (node == tail) return pop_back(); + + node->prev->next = node->next; + node->next->prev = node->prev; + T val = node->data; --length; free_node(node); return val; } void update(Node* node, const T& value){ - if(!node) return; + if (!node) return; node->data = value; } @@ -212,23 +224,25 @@ class LinkedList{ template Node* find(Predicate pred) const{ - if(!head) return nullptr; - Node* it=head; - do{ - if(pred(it->data)) return it; - it=it->next; - }while(it != head); + if (!head) return nullptr; + + Node* it = head; + do { + if (pred(it->data)) return it; + it = it->next; + } while (it != head); + return nullptr; } template void for_each(Func func) const{ - if(!head) return; + if (!head) return; Node* it = head; - do{ + do { func(it->data); it = it->next; - }while(it != head); + } while (it != head); } }; #endif From 3e0badc1274c248c37715b6d80f19afee96b295b Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:14:38 +0200 Subject: [PATCH 108/123] Update linked_list.cpp format --- shared/data_struct/linked_list.cpp | 65 ++++++++++++++++++------------ 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/shared/data_struct/linked_list.cpp b/shared/data_struct/linked_list.cpp index 83c6b307..8012bdc2 100644 --- a/shared/data_struct/linked_list.cpp +++ b/shared/data_struct/linked_list.cpp @@ -7,7 +7,8 @@ extern "C" { clinkedlist_t *clinkedlist_create(void){ uintptr_t mem = malloc(sizeof(clinkedlist_t)); - if((void *)mem == NULL) return NULL; + if ((void *)mem == NULL) return NULL; + clinkedlist_t *list = (clinkedlist_t *)mem; list->head = NULL; list->tail = NULL; @@ -16,9 +17,10 @@ clinkedlist_t *clinkedlist_create(void){ } void clinkedlist_destroy(clinkedlist_t *list){ - if(list == NULL) return; + if (list == NULL) return; + clinkedlist_node_t *node = list->head; - while(node){ + while (node){ clinkedlist_node_t *next = node->next; free(node, sizeof(clinkedlist_node_t)); node = next; @@ -27,19 +29,21 @@ void clinkedlist_destroy(clinkedlist_t *list){ } clinkedlist_t *clinkedlist_clone(const clinkedlist_t *list){ - if(list == NULL) return NULL; + if (list == NULL) return NULL; + clinkedlist_t *clone = clinkedlist_create(); - if(clone == NULL) return NULL; + if (clone == NULL) return NULL; + clinkedlist_node_t *it = list->head; - while(it){ - if(clone->tail){ + while (it){ + if (clone->tail){ clinkedlist_node_t *new_node = (clinkedlist_node_t *)malloc(sizeof(clinkedlist_node_t)); new_node->data = it->data; new_node->next = NULL; clone->tail->next = new_node; clone->tail = new_node; clone->length++; - }else{ + } else { clinkedlist_push_front(clone, it->data); } it = it->next; @@ -48,29 +52,33 @@ clinkedlist_t *clinkedlist_clone(const clinkedlist_t *list){ } void clinkedlist_push_front(clinkedlist_t *list, void *data){ - if(list == NULL) return; + if (list == NULL) return; + clinkedlist_node_t *node = (clinkedlist_node_t *)malloc(sizeof(clinkedlist_node_t)); node->data = data; node->next = list->head; list->head = node; - if(list->tail == NULL) list->tail = node; + if (list->tail == NULL) list->tail = node; list->length++; } void *clinkedlist_pop_front(clinkedlist_t *list){ - if(list == NULL || list->head== NULL) return NULL; + if (list == NULL || list->head== NULL) return NULL; + clinkedlist_node_t *node = list->head; void *data = node->data; list->head = node->next; if (list->head == NULL) list->tail = NULL; + list->length--; free(node, sizeof(clinkedlist_node_t)); return data; } clinkedlist_node_t *clinkedlist_insert_after(clinkedlist_t *list, clinkedlist_node_t *node, void *data) { - if(list == NULL) return NULL; - if(node == NULL){ + if (list == NULL) return NULL; + + if (node == NULL){ clinkedlist_push_front(list, data); return list->head; } @@ -78,23 +86,26 @@ clinkedlist_node_t *clinkedlist_insert_after(clinkedlist_t *list, clinkedlist_no new_node->data = data; new_node->next = node->next; node->next = new_node; - if(list->tail == node) list->tail = new_node; + if (list->tail == node) list->tail = new_node; + list->length++; return new_node; } void *clinkedlist_remove(clinkedlist_t *list, clinkedlist_node_t *node){ - if(list == NULL || node == NULL || list->head == NULL) return NULL; - if(node == list->head){ + if (list == NULL || node == NULL || list->head == NULL) return NULL; + + if (node == list->head){ return clinkedlist_pop_front(list); } clinkedlist_node_t *prev = list->head; - while(prev->next && prev->next != node){ + while (prev->next && prev->next != node){ prev = prev->next; } - if(prev->next != node) return NULL; + if (prev->next != node) return NULL; + prev->next = node->next; - if(node == list->tail) list->tail = prev; + if (node == list->tail) list->tail = prev; void *data = node->data; list->length--; free(node, sizeof(clinkedlist_node_t)); @@ -103,7 +114,7 @@ void *clinkedlist_remove(clinkedlist_t *list, clinkedlist_node_t *node){ void clinkedlist_update(clinkedlist_t *list, clinkedlist_node_t *node, void *new_data){ (void)list; - if(node) node->data = new_data; + if (node) node->data = new_data; } uint64_t clinkedlist_length(const clinkedlist_t *list){ @@ -115,19 +126,21 @@ uint64_t clinkedlist_size_bytes(const clinkedlist_t *list){ } clinkedlist_node_t *clinkedlist_find(clinkedlist_t *list, void *key, int (*cmp)(void *, void *)){ - if(list == NULL || cmp == NULL) return NULL; + if (list == NULL || cmp == NULL) return NULL; + clinkedlist_node_t *it = list->head; - while(it){ - if(cmp(it->data, key) == 0) return it; + while (it){ + if (cmp(it->data, key) == 0) return it; it = it->next; } return NULL; } void clinkedlist_for_each(const clinkedlist_t *list, void (*func)(void *)){ - if(list == NULL || func == NULL) return; + if (list == NULL || func == NULL) return; + clinkedlist_node_t *it = list->head; - while(it){ + while (it){ func(it->data); it = it->next; } @@ -135,4 +148,4 @@ void clinkedlist_for_each(const clinkedlist_t *list, void (*func)(void *)){ #ifdef __cplusplus } -#endif \ No newline at end of file +#endif From 31aa64439f814bb0bc6714e38e4967509c9b286b Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:16:30 +0200 Subject: [PATCH 109/123] Update linked_list.hpp format --- shared/data_struct/linked_list.hpp | 44 ++++++++++++++++++------------ 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/shared/data_struct/linked_list.hpp b/shared/data_struct/linked_list.hpp index c865d37a..2167ddfd 100644 --- a/shared/data_struct/linked_list.hpp +++ b/shared/data_struct/linked_list.hpp @@ -4,6 +4,7 @@ #ifdef __cplusplus extern "C" { #endif + typedef struct clinkedlist_node{ void *data; struct clinkedlist_node *next; @@ -15,9 +16,11 @@ typedef struct clinkedlist{ uint64_t length; }clinkedlist_t; + extern uintptr_t malloc(uint64_t size); extern void free(void *ptr, uint64_t size); + clinkedlist_t *clinkedlist_create(void); void clinkedlist_destroy(clinkedlist_t *list); clinkedlist_t *clinkedlist_clone(const clinkedlist_t *list); @@ -40,6 +43,7 @@ template class LinkedList{ T data; Node *next; }; + Node *head = nullptr; Node *tail = nullptr; uint64_t length = 0; @@ -51,6 +55,7 @@ template class LinkedList{ n->next = nullptr; return n; } + void free_node(Node *n){ free(n, sizeof(Node)); } @@ -59,28 +64,29 @@ template class LinkedList{ LinkedList() = default; LinkedList(const LinkedList &other){ - for(Node *it = other.head; it; it = it->next){ + for (Node *it = other.head; it; it = it->next){ push_front(it->data); } LinkedList tmp; - while(!empty()){ + while (!empty()){ tmp.push_front(pop_front()); } *this = tmp; } ~LinkedList(){ - while(!empty()) pop_front(); + while (!empty()) pop_front(); } LinkedList &operator=(const LinkedList &other){ - if(this != &other){ - while(!empty()) pop_front(); - for(Node *it = other.head; it; it = it->next){ + if (this != &other){ + while (!empty()) pop_front(); + for (Node *it = other.head; it; it = it->next){ push_front(it->data); } + LinkedList tmp; - while(!empty()){ + while (!empty()){ tmp.push_front(pop_front()); } head = tmp.head; @@ -104,6 +110,7 @@ template class LinkedList{ Node *n = head; head = head->next; if (head == nullptr) tail = nullptr; + T val = n->data; free_node(n); --length; @@ -111,26 +118,28 @@ template class LinkedList{ } Node *insert_after(Node *node, const T &value){ - if(node == nullptr){ + if (node == nullptr){ push_front(value); return head; } + Node *n = alloc_node(value); n->next = node->next; node->next = n; - if(tail == node) tail = n; + if (tail == node) tail = n; ++length; return n; } T remove(Node *node){ - if(node == nullptr) return T(); - if(node == head) return pop_front(); + if (node == nullptr) return T(); + if (node == head) return pop_front(); + Node *prev = head; - while(prev && prev->next != node) prev = prev->next; - if(prev == nullptr) return T(); + while (prev && prev->next != node) prev = prev->next; + if (prev == nullptr) return T(); prev->next = node->next; - if(node == tail) tail = prev; + if (node == tail) tail = prev; T val = node->data; free_node(node); --length; @@ -138,7 +147,7 @@ template class LinkedList{ } void update(Node *node, const T &value){ - if(node) node->data = value; + if (node) node->data = value; } uint64_t size() const{return length;} @@ -146,9 +155,10 @@ template class LinkedList{ Node *begin() const{ return head; } Node *end() const{ return nullptr;} template + Node *find(Predicate pred) const{ - for(Node *it = head; it; it = it->next){ - if(pred(it->data)) return it; + for (Node *it = head; it; it = it->next){ + if (pred(it->data)) return it; } return nullptr; } From 871110205a8ad297ebb01268742478deeec545d8 Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:18:29 +0200 Subject: [PATCH 110/123] Update queue.cpp format --- shared/data_struct/queue.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/shared/data_struct/queue.cpp b/shared/data_struct/queue.cpp index d5a9fa58..16374b06 100644 --- a/shared/data_struct/queue.cpp +++ b/shared/data_struct/queue.cpp @@ -1,3 +1,4 @@ + #include "queue.hpp" #include "std/memfunctions.h" @@ -7,44 +8,45 @@ void cqueue_init(CQueue* q,uint64_t max_capacity,uint64_t elem_size){ q->max_capacity = max_capacity; q->elem_size = elem_size; q->head = q->tail = q->length = 0; - if(max_capacity>0){ + if (max_capacity > 0){ uintptr_t b = malloc(max_capacity*elem_size); - if(b) q->buffer = (void*)b; + if (b) q->buffer = (void*)b; } } int32_t cqueue_enqueue(CQueue* q,const void* item){ - if(!q) return 0; - if(q->max_capacity>0){ - if(q->length==q->capacity) return 0; + if (!q) return 0; + if (q->max_capacity>0){ + if (q->length == q->capacity) return 0; } else { - if(q->length==q->capacity){ + if (q->length == q->capacity){ uint64_t nc = q->capacity>0 ? q->capacity*2 : 4; uintptr_t nb = malloc(nc*q->elem_size); - if(!nb) return 0; + if (!nb) return 0; + void* newb = (void*)nb; - for(uint64_t i=0;ilength;++i){ + for (uint64_t i=0; ilength; ++i){ uint64_t idx = (q->tail + i)%q->capacity; memcpy((uint8_t*)newb + i*q->elem_size, (uint8_t*)q->buffer + idx*q->elem_size, q->elem_size); } - if(q->buffer) free(q->buffer,q->capacity*q->elem_size); + if (q->buffer) free(q->buffer,q->capacity*q->elem_size); q->buffer=newb; q->capacity=nc; q->head=q->length; q->tail=0; } } - memcpy((uint8_t*)q->buffer + q->head*q->elem_size, - item,q->elem_size); + memcpy((uint8_t*)q->buffer + q->head*q->elem_size, item,q->elem_size); q->head = (q->head+1)%q->capacity; q->length++; return 1; } int32_t cqueue_dequeue(CQueue* q,void* out){ - if(!q||q->length==0) return 0; + if (!q || q->length == 0) return 0; + memcpy(out,(uint8_t*)q->buffer + q->tail*q->elem_size,q->elem_size); q->tail = (q->tail+1)%q->capacity; q->length--; @@ -60,11 +62,11 @@ uint64_t cqueue_size(const CQueue* q){ } void cqueue_clear(CQueue* q){ - if(!q) return; + if (!q) return; q->head=q->tail=q->length=0; } void cqueue_destroy(CQueue* q){ - if(!q) return; - if(q->buffer) free(q->buffer,q->capacity*q->elem_size); + if (!q) return; + if (q->buffer) free(q->buffer,q->capacity*q->elem_size); } From 6aaca80fcc0f370e8828eacc6a3a5ca0463c36ca Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:19:15 +0200 Subject: [PATCH 111/123] Update queue.hpp format --- shared/data_struct/queue.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/shared/data_struct/queue.hpp b/shared/data_struct/queue.hpp index d31dcda8..7f0bbe8f 100644 --- a/shared/data_struct/queue.hpp +++ b/shared/data_struct/queue.hpp @@ -5,7 +5,7 @@ extern "C" { #endif -typedef struct CQueue{ +typedef struct CQueue { void* buffer; uint64_t capacity; //curremt queue size uint64_t max_capacity; //0 is infinite @@ -15,9 +15,11 @@ typedef struct CQueue{ uint64_t length; }CQueue; + extern uintptr_t malloc(uint64_t); extern void free(void*,uint64_t); + void cqueue_init(CQueue* q,uint64_t max_capacity,uint64_t elem_size); int32_t cqueue_enqueue(CQueue* q,const void* item); int32_t cqueue_dequeue(CQueue* q,void* out); @@ -30,8 +32,9 @@ void cqueue_destroy(CQueue* q); } template -class Queue{ +class Queue { CQueue q_; + public: explicit Queue(uint64_t cap=0){cqueue_init(&q_,cap,sizeof(T));} ~Queue(){ cqueue_destroy(&q_); } From 065b9d1af3669ed2bcea44cdaed8ff8d525ca257 Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:19:53 +0200 Subject: [PATCH 112/123] Update ring_buffer.cpp format --- shared/data_struct/ring_buffer.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/shared/data_struct/ring_buffer.cpp b/shared/data_struct/ring_buffer.cpp index 281117f6..a1e7e946 100644 --- a/shared/data_struct/ring_buffer.cpp +++ b/shared/data_struct/ring_buffer.cpp @@ -10,16 +10,18 @@ void cring_init(struct CRingBuffer* rb, void* storage, uint64_t capacity, uint64 rb->tail = 0; rb->full = 0; } + uint64_t cring_capacity(const struct CRingBuffer* rb){ return rb->capacity; } + int32_t cring_push(struct CRingBuffer* rb, const void* item){ if (rb->full) return 0; uint8_t* base = (uint8_t*)rb->buffer; void* dest = base + (rb->head * rb->element_size); - for(uint32_t i = 0; i < rb->element_size; ++i){ + for (uint32_t i = 0; i < rb->element_size; ++i){ ((uint8_t*)dest)[i] =((const uint8_t*)item)[i]; } @@ -29,17 +31,17 @@ int32_t cring_push(struct CRingBuffer* rb, const void* item){ } int32_t cring_pop(struct CRingBuffer* rb, void* out){ - if(!rb->full && (rb->head == rb->tail)) return 0; + if (!rb->full && (rb->head == rb->tail)) return 0; uint8_t* base = (uint8_t*)rb->buffer; void* src = base + (rb->tail * rb->element_size); - for(uint64_t i = 0; i < rb->element_size; ++i){ + for (uint64_t i = 0; i < rb->element_size; ++i){ ((uint8_t*)out)[i] = ((uint8_t*)src)[i]; } - rb->tail =(rb->tail + 1) % rb->capacity; - rb->full =0; + rb->tail = (rb->tail + 1) % rb->capacity; + rb->full = 0; return 1; } From 1967c8f124831d2871e9efab08f14a8a159fb41d Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:21:10 +0200 Subject: [PATCH 113/123] Update ring_buffer.hpp format --- shared/data_struct/ring_buffer.hpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/shared/data_struct/ring_buffer.hpp b/shared/data_struct/ring_buffer.hpp index 73b09d5b..e7e8c983 100644 --- a/shared/data_struct/ring_buffer.hpp +++ b/shared/data_struct/ring_buffer.hpp @@ -2,7 +2,7 @@ #include "types.h" extern "C" { -struct CRingBuffer{ +struct CRingBuffer { void* buffer; uint64_t capacity; //TODO: define size_t as the same size of os architecture uint64_t element_size; @@ -18,9 +18,12 @@ int32_t cring_is_empty(const struct CRingBuffer* rb); int32_t cring_is_full(const struct CRingBuffer* rb); void cring_clear(struct CRingBuffer* rb); uint64_t cring_capacity(const struct CRingBuffer* rb); + } -template class RingBuffer{ +template +class RingBuffer{ + private: T data[Capacity]; uint64_t head = 0; @@ -29,15 +32,17 @@ template class RingBuffer{ public: int32_t push(const T& item){ - if(full) return 0; + if (full) return 0; + data[head] = item; head = (head + 1) % Capacity; - full =(head == tail); + full = (head == tail); return 1; } int32_t pop(T& out){ - if(is_empty()) return 0; + if (is_empty()) return 0; + out = data[tail]; tail = (tail + 1)% Capacity; full = 0; @@ -53,13 +58,15 @@ template class RingBuffer{ } void clear(){ - head = tail= 0; + head = tail = 0; full = 0; } uint64_t size() const{ - if(full) return Capacity; - if(head >= tail) return head - tail; + if (full) return Capacity; + + if (head >= tail) return head - tail; + return Capacity + head - tail; } @@ -74,5 +81,6 @@ template class RingBuffer{ T& at(uint32_t index){ return data[(tail + index)% Capacity]; } - static constexpr uint64_t capacity(){return Capacity;} + + static constexpr uint64_t capacity(){ return Capacity; } }; From 6cf11c569ac19cbee67254a7b6963a78e65111c4 Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:27:23 +0200 Subject: [PATCH 114/123] Update string.c format --- shared/std/string.c | 153 +++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 79 deletions(-) diff --git a/shared/std/string.c b/shared/std/string.c index d906302e..f67fbe0a 100644 --- a/shared/std/string.c +++ b/shared/std/string.c @@ -4,29 +4,23 @@ #include "std/memfunctions.h" static uint32_t compute_length(char *s, uint32_t max_length){ - if (s == NULL){ - return 0; - } + if (s == NULL) return 0; + uint32_t len = 0; - while ((max_length == 0 || len < max_length) && s[len] != '\0'){ - len++; - } + while ((max_length == 0 || len < max_length) && s[len] != '\0') len++; + return len; } string string_l(char *literal){ - if (literal == NULL){ - return (string){ .data = NULL, .length = 0, .mem_length = 0}; - } + if (literal == NULL) return (string){ .data = NULL, .length = 0, .mem_length = 0}; + uint32_t len = compute_length(literal, 0); char *buf = (char*)malloc(len + 1); - if (!buf) { - //manage malloc - return (string){ .data = NULL, .length = 0, .mem_length = 0 }; - } - for (uint32_t i = 0; i < len; i++){ - buf[i] = literal[i]; - } + if (!buf) return (string){ .data = NULL, .length = 0, .mem_length = 0 }; + + for (uint32_t i = 0; i < len; i++) buf[i] = literal[i]; + buf[len] = '\0'; return (string){ .data = buf, .length = len, .mem_length = len + 1 }; } @@ -39,38 +33,32 @@ string string_repeat(char symbol, uint32_t amount){ } string string_tail(char *array, uint32_t max_length){ - if (array == NULL){ - return (string){ .data = NULL, .length = 0, .mem_length = 0 }; - } + + if (array == NULL) return (string){ .data = NULL, .length = 0, .mem_length = 0 }; + uint32_t len = compute_length(array, 0); int offset = (int)len - (int)max_length; - if(offset < 0){ - offset = 0; - } + if (offset < 0) offset = 0; + uint32_t adjusted_len = len - offset; char *buf = (char*)malloc(adjusted_len + 1); - if(!buf){ - return (string){ .data = NULL, .length = 0, .mem_length = 0 }; - } - for (uint32_t i = 0; i < adjusted_len; i++){ - buf[i] = array[offset + i]; - } + if (!buf) return (string){ .data = NULL, .length = 0, .mem_length = 0 }; + + for (uint32_t i = 0; i < adjusted_len; i++) buf[i] = array[offset + i]; + buf[adjusted_len] = '\0'; return (string){.data = buf, .length = adjusted_len, .mem_length = adjusted_len + 1 }; } string string_ca_max(char *array, uint32_t max_length){ - if(array == NULL){ - return (string){.data = NULL, .length = 0, .mem_length= 0 }; - } + if (array == NULL) return (string){.data = NULL, .length = 0, .mem_length= 0 }; + uint32_t len = compute_length(array, max_length); char *buf = (char*)malloc(len + 1); - if(!buf){ - return (string){ .data = NULL, .length = 0, .mem_length=0 }; - } - for(uint32_t i = 0; i < len; i++){ - buf[i] = array[i]; - } + if(!buf) return (string){ .data = NULL, .length = 0, .mem_length=0 }; + + for (uint32_t i = 0; i < len; i++) buf[i] = array[i]; + buf[len] = '\0'; return (string){ .data = buf, .length = len, .mem_length = len+1}; } @@ -94,6 +82,7 @@ uint32_t parse_hex(uint64_t value, char* buf){ started = true; buf[len++] = curr_char; } + if (i == 0) break; } @@ -118,6 +107,7 @@ uint32_t parse_bin(uint64_t value, char* buf){ started = true; buf[len++] = bit; } + if (i == 0) break; } @@ -136,9 +126,8 @@ bool string_equals(string a, string b){ } string string_format(char *fmt, ...){ - if(fmt == NULL){ - return (string){ .data = NULL, .length = 0, .mem_length = 0}; - } + if (fmt == NULL) return (string){ .data = NULL, .length = 0, .mem_length = 0}; + va_list args; va_start(args, fmt); string result = string_format_va(fmt, args); @@ -150,45 +139,50 @@ string string_format_va(char *fmt, va_list args){ char *buf = (char*)malloc(256); uint32_t len = 0; uint32_t arg_index = 0; - for(uint32_t i = 0; fmt[i] && len < 255; i++){ - if(fmt[i] == '%' && fmt[i+1]){ + for (uint32_t i = 0; fmt[i] && len < 255; i++){ + if (fmt[i] == '%' && fmt[i+1]){ i++; - if(fmt[i] == 'x'){ + if (fmt[i] == 'x'){ uint64_t val = va_arg(args, uint64_t); len += parse_hex(val,(char*)(buf + len)); - }else if(fmt[i] == 'b') { + + } else if (fmt[i] == 'b') { uint64_t val = va_arg(args, uint64_t); string bin = string_from_bin(val); for(uint32_t j = 0; j < bin.length && len < 255; j++) buf[len++] = bin.data[j]; free(bin.data,bin.mem_length); - }else if(fmt[i] == 'c') { + + } else if (fmt[i] == 'c') { uint64_t val = va_arg(args, uint64_t); buf[len++] = (char)val; - }else if(fmt[i] == 's') { + + } else if (fmt[i] == 's') { char *str = ( char *)va_arg(args, uintptr_t); for (uint32_t j = 0; str[j] && len < 255; j++) buf[len++] = str[j]; - }else if(fmt[i] == 'i') { + + } else if (fmt[i] == 'i') { uint64_t val = va_arg(args, long int); char temp[21]; uint32_t temp_len = 0; bool negative = false; - if((int)val < 0) { + if ((int)val < 0) { negative = true; buf[len++] = '-'; val = (uint64_t)(-(int)val); } - do{ + + do { temp[temp_len++] = '0' + (val % 10); val /= 10; - }while(val && temp_len < 20); + } while (val && temp_len < 20); - for(int j = temp_len - 1; j >= 0 && len < 255; j--){ + for (int j = temp_len - 1; j >= 0 && len < 255; j--){ buf[len++] = temp[j]; } - }else if(fmt[i] == 'f' || fmt[i] == 'd') { + } else if (fmt[i] == 'f' || fmt[i] == 'd') { double val = va_arg(args, double); - if(val < 0){ + if (val < 0){ buf[len++] = '-'; val = -val; } @@ -197,26 +191,27 @@ string string_format_va(char *fmt, va_list args){ char temp[21]; uint32_t temp_len = 0; - do{ + do { temp[temp_len++] = '0' +(whole % 10); whole /= 10; - }while(whole && temp_len < 20); + } while(whole && temp_len < 20); - for(int j = temp_len - 1; j >= 0 && len < 255; j--){ + for (int j = temp_len - 1; j >= 0 && len < 255; j--){ buf[len++] = temp[j]; } - if(len < 255) buf[len++] = '.'; + if (len < 255) buf[len++] = '.'; + for (int d = 0; d < 6 && len < 255; d++) { frac *= 10; int digit = (int)frac; buf[len++] = '0' + digit; frac -= digit; } - }else{ + } else { buf[len++] = '%'; buf[len++] = fmt[i]; } - }else{ + } else { buf[len++] = fmt[i]; } } @@ -226,33 +221,33 @@ string string_format_va(char *fmt, va_list args){ } char tolower(char c){ - if(c >= 'A' && c <= 'Z') return c + 'a' - 'A'; + if (c >= 'A' && c <= 'Z') return c + 'a' - 'A'; return c; } int strcmp(char *a, char *b, bool case_insensitive){ - if(a == NULL && b == NULL)return 0; //i guess - if(a == NULL) return -1; - if(b == NULL) return 1; + if (a == NULL && b == NULL)return 0; //i guess + if (a == NULL) return -1; + if (b == NULL) return 1; - while(*a && *b){ + while (*a && *b){ char ca = *a; char cb = *b; - if(case_insensitive){ + if (case_insensitive){ ca = tolower((unsigned char)ca); cb = tolower((unsigned char)cb); } - if(ca != cb) return ca - cb; + if (ca != cb) return ca - cb; a++; b++; } - if(case_insensitive) - return tolower((unsigned char)*a) - tolower((unsigned char)*b); + if (case_insensitive) return tolower((unsigned char)*a) - tolower((unsigned char)*b); + return (unsigned char)*a - (unsigned char)*b; } int strstart(char *a, char *b, bool case_insensitive){ int index = 0; - while(*a && *b){ + while (*a && *b){ char ca = *a; char cb = *b; @@ -261,14 +256,14 @@ int strstart(char *a, char *b, bool case_insensitive){ cb = tolower(cb); } - if(ca != cb) return index; + if (ca != cb) return index; a++; b++; index++; } return 0; } int strindex( char *a, char *b){ - for(int i = 0; a[i]; i++){ + for (int i = 0; a[i]; i++){ int j = 0; while (b[j] && a[i + j] == b[j]) j++; if (!b[j]) return i; @@ -277,13 +272,13 @@ int strindex( char *a, char *b){ } int strend(char *a, char *b, bool case_insensitive){ - while(*a && *b){ + while (*a && *b){ char ca = case_insensitive ? tolower((unsigned char)*a) : *a; char cb = case_insensitive ? tolower((unsigned char)*b) : *b; - if(ca == cb){ + if (ca == cb){ char *pa = a, *pb = b; - while(1){ + while (1){ char cpa = case_insensitive ? tolower((unsigned char)*pa) : *pa; char cpb = case_insensitive ? tolower((unsigned char)*pb) : *pb; @@ -299,12 +294,12 @@ int strend(char *a, char *b, bool case_insensitive){ } bool strcont( char *a, char *b){ - while(*a){ + while (*a){ char *p = a, *q = b; - while(*p && *q && *p == *q){ + while (*p && *q && *p == *q){ p++; q++; } - if(*q == 0) return 1; + if (*q == 0) return 1; a++; } return 0; @@ -312,7 +307,7 @@ bool strcont( char *a, char *b){ bool utf16tochar(uint16_t* str_in, char* out_str, size_t max_len){ size_t out_i = 0; - for(int i = 0; i < max_len && str_in[i]; i++){ + for (int i = 0; i < max_len && str_in[i]; i++){ uint16_t wc = str_in[i]; out_str[out_i++] = (wc <= 0x7F) ? (char)(wc & 0xFF) : '?'; } @@ -322,7 +317,7 @@ bool utf16tochar(uint16_t* str_in, char* out_str, size_t max_len){ uint64_t parse_hex_u64(char* str, size_t size){ uint64_t result = 0; - for(uint32_t i = 0; i < size; i++){ + for (uint32_t i = 0; i < size; i++){ char c = str[i]; uint8_t digit = 0; if (c >= '0' && c <= '9') digit = c - '0'; From 1292655f9d02c89bb339e12ee5ed84b7dc6a0346 Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:28:16 +0200 Subject: [PATCH 115/123] Update doubly_linked_list.hpp format --- shared/data_struct/doubly_linked_list.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/data_struct/doubly_linked_list.hpp b/shared/data_struct/doubly_linked_list.hpp index 0bc71f34..15791ca1 100644 --- a/shared/data_struct/doubly_linked_list.hpp +++ b/shared/data_struct/doubly_linked_list.hpp @@ -140,7 +140,7 @@ class LinkedList{ } T pop_front(){ - if !head) return T(); + if (!head) return T(); Node* n = head; T val = n->data; From 38b796ca576c2273d7a8f52132aca15139c35e73 Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 19:38:57 +0200 Subject: [PATCH 116/123] Update Makefile --- kernel/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/Makefile b/kernel/Makefile index c16f18a0..ea3f3a96 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -8,6 +8,7 @@ endif LDFLAGS := $(LDFLAGS_BASE) -T $(shell ls *.ld) --defsym=LOAD_ADDR=$(LOAD_ADDR) +CLEAN_OBJS := $(shell find . -name '*.o') C_SRC := $(shell find . -name '*.c') ASM_SRC := $(shell find . -name '*.S') CPP_SRC := $(shell find . -name '*.cpp') @@ -31,4 +32,4 @@ $(TARGET): ../shared/libshared.a $(OBJ) $(CC) $(CFLAGS) -fno-rtti -c $< -o $@ clean: - rm -f $(OBJ) $(ELF) $(TARGET) \ No newline at end of file + rm -f $(CLEAN_OBJS) $(ELF) $(TARGET) From 4ac1ef8c475f3b0f21fce86d7423e9887059410e Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 19:49:34 +0200 Subject: [PATCH 117/123] Update Makefile --- shared/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shared/Makefile b/shared/Makefile index 8fe0d3d0..4c9fe9cd 100644 --- a/shared/Makefile +++ b/shared/Makefile @@ -1,6 +1,7 @@ #shared CFLAGS := $(CFLAGS_BASE) -I. -I../kernel -Wno-unused-parameter +CLEAN_OBJS := $(shell find . -name '*.o') C_SRC := $(shell find . -name '*.c') CPP_SRC := $(shell find . -name '*.cpp') ASM_SRC := $(shell find . -name '*.S') @@ -25,4 +26,4 @@ $(TARGET): $(OBJ) $(CC) $(CFLAGS) -fno-rtti -c $< -o $@ clean: - rm -f $(OBJ) $(TARGET) + rm -f $(CLEAN_OBJS) $(TARGET) From 4ad766f7dcec8fb160d264fc97a83e628138fd6c Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 19:50:37 +0200 Subject: [PATCH 118/123] Update Makefile --- user/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user/Makefile b/user/Makefile index e85c133e..a9799437 100644 --- a/user/Makefile +++ b/user/Makefile @@ -2,6 +2,7 @@ CFLAGS := $(CFLAGS_BASE) -I. -I../shared -Wno-unused-parameter LDFLAGS := -T $(shell ls *.ld) +CLEAN_OBJS := $(shell find . -name '*.o') C_SRC := $(shell find . -name '*.c') CPP_SRC := $(shell find . -name '*.cpp') OBJ := $(C_SRC:.c=.o) $(CPP_SRC:.cpp=.o) @@ -29,4 +30,4 @@ $(LOCATION)$(TARGET): $(OBJ) $(CC) $(CFLAGS) -fno-rtti -c $< -o $@ clean: - rm -f $(OBJ) $(TARGET) + rm -f $(CLEAN_OBJS) $(TARGET) From 5bd3dfeb15b3276c44bda163a28fb64301a0e10e Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 20:47:43 +0200 Subject: [PATCH 119/123] Update kconsole.cpp --- kernel/console/kconsole/kconsole.cpp | 78 ++++++++++++++-------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/kernel/console/kconsole/kconsole.cpp b/kernel/console/kconsole/kconsole.cpp index 3581472e..aaefe82d 100644 --- a/kernel/console/kconsole/kconsole.cpp +++ b/kernel/console/kconsole/kconsole.cpp @@ -17,9 +17,9 @@ bool KernelConsole::check_ready(){ } void KernelConsole::resize(){ - gpu_size s = gpu_get_screen_size(); - columns = s.width / char_width; - rows = s.height / char_height; + gpu_size screen_size = gpu_get_screen_size(); + columns = screen_size.width / char_width; + rows = screen_size.height / char_height; if (row_data) temp_free(row_data, buffer_data_size); buffer_data_size = rows * columns; @@ -31,7 +31,7 @@ void KernelConsole::resize(){ } row_ring.clear(); - for (uint32_t i=0;i= columns) newline(); - uint32_t ri; - if (row_ring.pop(ri)){ - row_ring.push(ri); - char* line = row_data + ri * columns; + uint32_t row_index; + if (row_ring.pop(row_index)){ + row_ring.push(row_index); + char* line = row_data + row_index * columns; line[cursor_x] = c; - gpu_draw_char({cursor_x * char_width,cursor_y*char_height}, c, 1, 0xFFFFFFFF); + gpu_draw_char({cursor_x * char_width, cursor_y * char_height}, c, 1, 0xFFFFFFFF); cursor_x++; } } -void KernelConsole::put_string(const char* s){ +void KernelConsole::put_string(const char* str){ if (!check_ready()) return; - for (uint32_t i=0; s[i]; i++) put_char(s[i]); + for (uint32_t i = 0; str[i]; i++) put_char(str[i]); gpu_flush(); } -void KernelConsole::put_hex(uint64_t v){ +void KernelConsole::put_hex(uint64_t value){ if (!check_ready()) return; put_char('0'); put_char('x'); bool started = false; - for(uint32_t i =60 ;; i-=4){ - uint8_t n = (v>>i)&0xF; - char c = n < 10 ? '0' + n : 'A' + (n - 10); - if (started || c!='0' || i==0){ - started = true; - put_char(c); + for (uint32_t i = 60 ;; i -= 4){ + uint8_t nibble = (value >> i) & 0xF; + char current_char = nibble < 10 ? '0' + nibble : 'A' + (nibble - 10); + if (started || current_char != '0' || i == 0){ + started = true; + put_char(current_char); } if (i == 0) break; } @@ -77,27 +77,27 @@ void KernelConsole::put_hex(uint64_t v){ void KernelConsole::newline(){ if (!check_ready()) return; - uint32_t ri; - if (row_ring.pop(ri)){ - char* line=row_data+ri*columns; - for (uint32_t x = cursor_x; x < columns; x++) line[x]=0; - row_ring.push(ri); + uint32_t row_index; + if (row_ring.pop(row_index)){ + char* line = row_data + row_index * columns; + for (uint32_t x = cursor_x; x < columns; x++) line[x] = 0; + row_ring.push(row_index); } cursor_x = 0; cursor_y++; if (cursor_y >= rows){ scroll(); - cursor_y = rows -1; + cursor_y = rows - 1; } } void KernelConsole::scroll(){ if (!check_ready()) return; - uint32_t ri; - if (row_ring.pop(ri)){ - char* line=row_data+ri*columns; - for(uint32_t x = 0; x < columns; x++) line[x]=0; - row_ring.push(ri); + uint32_t row_index; + if (row_ring.pop(row_index)){ + char* line = row_data + row_index * columns; + for (uint32_t x = 0; x < columns; x++) line[x] = 0; + row_ring.push(row_index); } redraw(); } @@ -105,10 +105,10 @@ void KernelConsole::scroll(){ void KernelConsole::redraw(){ screen_clear(); for (uint32_t y = 0; y < rows; y++){ - uint32_t ri; - if (row_ring.pop(ri)){ - row_ring.push(ri); - char* line = row_data + ri * columns; + uint32_t row_index; + if (row_ring.pop(row_index)){ + row_ring.push(row_index); + char* line = row_data + row_index * columns; for (uint32_t x = 0; x < columns; x++){ gpu_draw_char({x * char_width, y * char_height}, line[x], 1, 0xFFFFFFFF); } @@ -123,12 +123,12 @@ void KernelConsole::screen_clear(){ void KernelConsole::clear(){ screen_clear(); for (uint32_t i = 0; i < rows; i++){ - uint32_t ri; - if (row_ring.pop(ri)){ - char* line=row_data+ri*columns; - for (uint32_t x = 0; x < columns; x++) line[x]=0; - row_ring.push(ri); + uint32_t row_index; + if (row_ring.pop(row_index)){ + char* line = row_data + row_index * columns; + for (uint32_t x = 0; x < columns; x++) line[x] = 0; + row_ring.push(row_index); } } - cursor_x=cursor_y = 0; + cursor_x = cursor_y = 0; } From 067282e2072106e0069515e885a693fed928d3b5 Mon Sep 17 00:00:00 2001 From: CodeAnarchist <144830359+CodeAnarchist@users.noreply.github.com> Date: Fri, 25 Jul 2025 20:52:23 +0200 Subject: [PATCH 120/123] Update Makefile --- kernel/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index ea3f3a96..c6b00990 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -15,8 +15,8 @@ CPP_SRC := $(shell find . -name '*.cpp') OBJ := $(C_SRC:.c=.o) $(ASM_SRC:.S=.o) $(CPP_SRC:.cpp=.o) OBJL := $(filter-out ./boot.o,$(OBJ)) -ELF := kernel.elf -TARGET := kernel.img +ELF := ../kernel.elf +TARGET := ../kernel.img all: $(TARGET) From 0fb02c583c8c3e1068fba100e62dbc251e3d51ca Mon Sep 17 00:00:00 2001 From: CodeAnarchist Date: Fri, 25 Jul 2025 22:00:03 +0200 Subject: [PATCH 121/123] split data structures in .c/.h and .hpp --- kernel/input/xhci_types.h | 378 ++++++++++++++++++ .../{chunked_list.cpp => chunked_list.c} | 132 +++--- shared/data_struct/chunked_list.h | 40 ++ shared/data_struct/chunked_list.hpp | 180 ++++----- shared/data_struct/doubly_linked_list.c | 181 +++++++++ shared/data_struct/doubly_linked_list.cpp | 195 --------- shared/data_struct/doubly_linked_list.h | 40 ++ shared/data_struct/doubly_linked_list.hpp | 159 +++----- .../{linked_list.cpp => linked_list.c} | 74 ++-- shared/data_struct/linked_list.h | 37 ++ shared/data_struct/linked_list.hpp | 130 +++--- shared/data_struct/queue.c | 69 ++++ shared/data_struct/queue.cpp | 72 ---- shared/data_struct/queue.h | 31 ++ shared/data_struct/queue.hpp | 109 +++-- .../{ring_buffer.cpp => ring_buffer.c} | 29 +- shared/data_struct/ring_buffer.h | 27 ++ shared/data_struct/ring_buffer.hpp | 60 +-- 18 files changed, 1187 insertions(+), 756 deletions(-) create mode 100644 kernel/input/xhci_types.h rename shared/data_struct/{chunked_list.cpp => chunked_list.c} (61%) create mode 100644 shared/data_struct/chunked_list.h create mode 100644 shared/data_struct/doubly_linked_list.c delete mode 100644 shared/data_struct/doubly_linked_list.cpp create mode 100644 shared/data_struct/doubly_linked_list.h rename shared/data_struct/{linked_list.cpp => linked_list.c} (72%) create mode 100644 shared/data_struct/linked_list.h create mode 100644 shared/data_struct/queue.c delete mode 100644 shared/data_struct/queue.cpp create mode 100644 shared/data_struct/queue.h rename shared/data_struct/{ring_buffer.cpp => ring_buffer.c} (53%) create mode 100644 shared/data_struct/ring_buffer.h diff --git a/kernel/input/xhci_types.h b/kernel/input/xhci_types.h new file mode 100644 index 00000000..34484fac --- /dev/null +++ b/kernel/input/xhci_types.h @@ -0,0 +1,378 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "types.h" + +#define TRB_TYPE_NORMAL 1 +#define TRB_TYPE_LINK 6 +#define TRB_TYPE_EVENT_DATA 3 +#define TRB_TYPE_ENABLE_SLOT 9 +#define TRB_TYPE_ADDRESS_DEV 11 +#define TRB_TYPE_CONFIG_EP 12 +#define TRB_TYPE_SETUP 2 +#define TRB_TYPE_STATUS 4 +#define TRB_TYPE_INPUT 8 + +#define MAX_TRB_AMOUNT 256 +#define MAX_ERST_AMOUNT 1 + +#define TRB_TYPE_MASK 0xFC00 +#define TRB_ENDPOINT_MASK 0xF0000 +#define TRB_SLOT_MASK 0xF000000 + +#define TRB_TYPE_TRANSFER 0x20 +#define TRB_TYPE_COMMAND_COMPLETION 0x21 +#define TRB_TYPE_PORT_STATUS_CHANGE 0x22 + +#define TRB_TYPE_SETUP_STAGE 0x2 +#define TRB_TYPE_DATA_STAGE 0x3 +#define TRB_TYPE_STATUS_STAGE 0x4 + +#define XHCI_USBSTS_HSE (1 << 2) +#define XHCI_USBSTS_CE (1 << 12) + +#define XHCI_IRQ 31 + +typedef struct { + uint64_t parameter; + uint32_t status; + uint32_t control; +}__attribute__((packed)) trb; + +typedef struct { + uint8_t caplength; + uint8_t reserved; + uint16_t hciversion; + uint32_t hcsparams1; + uint32_t hcsparams2; + uint32_t hcsparams3; + uint32_t hccparams1; + uint32_t dboff; + uint32_t rtsoff; + uint32_t hccparams2; +}__attribute__((packed)) xhci_cap_regs; + +typedef struct { + uint32_t usbcmd; + uint32_t usbsts; + uint32_t pagesize; + uint64_t reserved0; + uint32_t dnctrl; + uint64_t crcr; + uint32_t reserved1[4]; + uint64_t dcbaap; + uint32_t config; +}__attribute__((packed)) xhci_op_regs; + +typedef union { + struct { + uint32_t ccs : 1; + uint32_t ped : 1; + uint32_t rsvd0 : 1; + uint32_t oca : 1; + uint32_t pr : 1; + uint32_t pls : 4; + uint32_t pp : 1; + uint32_t port_speed : 4; + uint32_t pic : 2; + uint32_t lws : 1; + uint32_t csc : 1; + uint32_t pec : 1; + uint32_t wrc : 1; + uint32_t occ : 1; + uint32_t prc : 1; + uint32_t plc : 1; + uint32_t cec : 1; + uint32_t cas : 1; + uint32_t wce : 1; + uint32_t wde : 1; + uint32_t woe : 1; + uint32_t rsvd1 : 2; + uint32_t dr : 1; + uint32_t wpr : 1; + }; + uint32_t value; +} portstatuscontrol; + +typedef struct { + portstatuscontrol portsc; + uint32_t portpmsc; + uint32_t portli; + uint32_t rsvd; +}__attribute__((packed, aligned(4))) xhci_port_regs; + +typedef struct { + uint32_t iman; + uint32_t imod; + uint32_t erstsz; + uint32_t reserved; + uint64_t erstba; + uint64_t erdp; +}__attribute__((packed)) xhci_interrupter; + +typedef struct { + uint64_t mmio; + uint64_t mmio_size; + xhci_cap_regs* cap; + xhci_op_regs* op; + xhci_port_regs* ports; + uint64_t db_base; + uint64_t rt_base; + trb* cmd_ring; + uint32_t cmd_index; + uint32_t event_index; + bool command_cycle_bit; + bool event_cycle_bit; + trb* event_ring; + uint8_t* key_buffer; + xhci_interrupter* interrupter; + uint64_t* dcbaa; + uint16_t max_device_slots; + uint16_t max_ports; +} xhci_device; + +typedef struct { + uint64_t ring_base; + uint32_t ring_size; + uint32_t reserved; +}__attribute__((packed)) erst_entry; + +typedef struct { + uint32_t drop_flags; + uint32_t add_flags; + uint64_t reserved[3]; +}__attribute__((packed)) xhci_input_control_context; + +typedef union +{ + struct + { + uint32_t route_string: 20; + uint32_t speed: 4; + uint32_t rsvd : 1; + uint32_t mtt : 1; + uint32_t hub : 1; + uint32_t context_entries : 5; + }; + uint32_t value; +} slot_field0; + +typedef union +{ + struct + { + uint16_t max_exit_latency; + uint8_t root_hub_port_num; + uint8_t port_count; + }; + uint32_t value; +} slot_field1; + +typedef union +{ + struct + { + uint32_t parent_hub_slot_id : 8; + uint32_t parent_port_number : 8; + uint32_t think_time : 2; + uint32_t rsvd : 4; + uint32_t interrupt_target : 10; + }; + uint32_t value; +} slot_field2; + +typedef union +{ + struct + { + uint32_t device_address : 8; + uint32_t rsvd : 19; + uint32_t state : 5;//0 disabled, 1 default, 2 addressed, 3 configured + }; + uint32_t value; +} slot_field3; + +typedef union +{ + struct { + uint32_t endpoint_state : 3; + uint32_t rsvd0 : 5; + uint32_t mult : 2; + uint32_t max_primary_streams : 5; + uint32_t linear_stream_array : 1; + uint32_t interval : 8; + uint32_t max_esit_payload_hi : 8; + }; + uint32_t value; +} endpoint_field0; + +typedef union +{ + struct { + uint32_t rsvd1 : 1; + uint32_t error_count : 2; + uint32_t endpoint_type : 3; + uint32_t rsvd2 : 1; + uint32_t host_initiate_disable : 1; + uint32_t max_burst_size : 8; + uint32_t max_packet_size : 16; + }; + uint32_t value; +} endpoint_field1; + +typedef union { + struct { + uint64_t dcs : 1; + uint64_t rsvd0 : 3; + uint64_t ring_ptr : 60; + }; + uint64_t value; +} endpoint_field23; + +typedef union +{ + struct { + uint16_t average_trb_length; + uint16_t max_esit_payload_lo; + }; + uint32_t value; +} endpoint_field4; + +typedef struct { + slot_field0 slot_f0; + slot_field1 slot_f1; + slot_field2 slot_f2; + slot_field3 slot_f3; + uint32_t slot_rsvd[4]; + struct { + endpoint_field0 endpoint_f0; + endpoint_field1 endpoint_f1; + endpoint_field23 endpoint_f23; + endpoint_field4 endpoint_f4; + uint32_t ep_rsvd[3]; + } endpoints[31]; +} xhci_device_context; + +typedef struct { + xhci_input_control_context control_context; + xhci_device_context device_context; +} xhci_input_context; + +typedef struct __attribute__((packed)) { + uint8_t bmRequestType; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; +} usb_setup_packet; + +typedef struct __attribute__((packed)) { + uint8_t bLength; + uint8_t bDescriptorType; +} usb_descriptor_header ; + +typedef struct __attribute__((packed)) { + usb_descriptor_header header; + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint16_t idVendor; + uint16_t idProduct; + uint16_t bcdDevice; + uint8_t iManufacturer; + uint8_t iProduct; + uint8_t iSerialNumber; + uint8_t bNumConfigurations; +} usb_device_descriptor; + +typedef struct __attribute__((packed)) { + usb_descriptor_header header; + uint16_t wTotalLength; + uint8_t bNumInterfaces; + uint8_t bConfigurationValue; + uint8_t iConfiguration; + uint8_t bmAttributes; + uint8_t bMaxPower; + uint8_t data[255]; +} usb_configuration_descriptor; + +typedef struct __attribute__((packed)) { + usb_descriptor_header header; + uint8_t bInterfaceNumber; + uint8_t bAlternateSetting; + uint8_t bNumEndpoints; + uint8_t bInterfaceClass; + uint8_t bInterfaceSubClass; + uint8_t bInterfaceProtocol; + uint8_t iInterface; +} usb_interface_descriptor; + +typedef struct __attribute__((packed)) { + usb_descriptor_header header; + uint16_t bcdHID; + uint8_t bCountryCode; + uint8_t bNumDescriptors; + struct { + uint8_t bDescriptorType; + uint8_t wDescriptorLength; + }__attribute__((packed)) descriptors[1]; +//TODO: wDescriptorLength is supposed to be 16, but for some reason the descriptor from usb-kbd is 8. Will need to fix this once we do a real device +} usb_hid_descriptor; + +typedef struct __attribute__((packed)) { + usb_descriptor_header header; + uint8_t bEndpointAddress; + uint8_t bmAttributes; + uint8_t wMaxPacketSize; + uint8_t bInterval; +//TODO: wMaxPacketSize is supposed to be 16, but for some reason the descriptor from usb-kbd is 8. Will need to fix this once we do a real device +} usb_endpoint_descriptor; + +typedef struct __attribute__((packed)) { + usb_descriptor_header header; + uint16_t lang_ids[126]; +} usb_string_language_descriptor; + +typedef struct __attribute__((packed)){ + usb_descriptor_header header; + uint16_t unicode_string[126]; +} usb_string_descriptor; + +typedef enum { + NONE, + KEYBOARD, + MOUSE +} xhci_device_types; + +typedef struct { + uint8_t transfer_cycle_bit; + uint32_t transfer_index; + trb* transfer_ring; + uint32_t slot_id; + xhci_input_context* ctx; +} xhci_usb_device; + +typedef struct { + xhci_device_types type; + trb* endpoint_transfer_ring; + uint32_t endpoint_transfer_index; + uint8_t endpoint_transfer_cycle_bit; + uint8_t poll_packetSize; + uint8_t *input_buffer; + uint8_t poll_endpoint; + uint16_t report_length; + uint8_t *report_descriptor; + } xhci_usb_device_endpoint; + +#define USB_DEVICE_DESCRIPTOR 1 +#define USB_CONFIGURATION_DESCRIPTOR 2 +#define USB_STRING_DESCRIPTOR 3 + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/shared/data_struct/chunked_list.cpp b/shared/data_struct/chunked_list.c similarity index 61% rename from shared/data_struct/chunked_list.cpp rename to shared/data_struct/chunked_list.c index af95e3d7..376feca5 100644 --- a/shared/data_struct/chunked_list.cpp +++ b/shared/data_struct/chunked_list.c @@ -1,66 +1,61 @@ -#include "chunked_list.hpp" -#include "console/kio.h" - -extern "C" { +#include "chunked_list.h" +#include "types.h" cchunked_list_t* cchunked_list_create(uint64_t chunkSize){ - uintptr_t raw = malloc(sizeof(cchunked_node_t)+chunkSize*sizeof(void*)); + uintptr_t raw = malloc(sizeof(cchunked_node_t) + chunkSize * sizeof(void*)); if (!raw) return NULL; - + cchunked_list_t* list = (cchunked_list_t*)malloc(sizeof(cchunked_list_t)); - if (!list){ - free((void*)raw,sizeof(cchunked_node_t)+chunkSize*sizeof(void*)); + if (!list) { + free((void*)raw, sizeof(cchunked_node_t) + chunkSize * sizeof(void*)); return NULL; } - - list->chunkSize=chunkSize; - list->length=0; - list->head=(cchunked_node_t*)raw; - list->head->count=0; - list->head->next=NULL; - list->tail=list->head; - + + list->chunkSize = chunkSize; + list->length = 0; + list->head = (cchunked_node_t*)raw; + list->head->count = 0; + list->head->next = NULL; + list->tail = list->head; return list; } void cchunked_list_destroy(cchunked_list_t* list){ if (!list) return; - - cchunked_node_t* node=list->head; - while (node){ - cchunked_node_t* next=node->next; - free(node,sizeof(cchunked_node_t)+list->chunkSize*sizeof(void*)); - node=next; + cchunked_node_t* node = list->head; + while (node) { + cchunked_node_t* next = node->next; + free(node, sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); + node = next; } - - free(list,sizeof(cchunked_list_t)); + free(list, sizeof(cchunked_list_t)); } + cchunked_list_t* cchunked_list_clone(const cchunked_list_t* list){ if (!list) return NULL; - - cchunked_list_t* clone=cchunked_list_create(list->chunkSize); + cchunked_list_t* clone = cchunked_list_create(list->chunkSize); if (!clone) return NULL; - - for (cchunked_node_t* it = list->head; it; it = it->next){ - for (uint64_t i = 0; icount; i++) - cchunked_list_push_back(clone,it->data[i]); + + for (cchunked_node_t* it = list->head; it; it = it->next) { + for (uint64_t i = 0; i < it->count; i++) + cchunked_list_push_back(clone, it->data[i]); } return clone; } void cchunked_list_push_back(cchunked_list_t* list, void* data){ if (!list) return; - //first mnode - if (list->tail == NULL){ + + if (!list->tail) { uintptr_t m = malloc(sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); if (!m) return; cchunked_node_t* node = (cchunked_node_t*)m; node->count = 0; node->next = NULL; - list->head=list->tail = node; + list->head = list->tail = node; } - - if (list->tail->count == list->chunkSize){ //last chunk + + if (list->tail->count == list->chunkSize) { uintptr_t m = malloc(sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); if (!m) return; cchunked_node_t* node = (cchunked_node_t*)m; @@ -69,25 +64,24 @@ void cchunked_list_push_back(cchunked_list_t* list, void* data){ list->tail->next = node; list->tail = node; } + list->tail->data[list->tail->count++] = data; list->length++; } -cchunked_node_t* cchunked_list_insert_after(cchunked_list_t* list,cchunked_node_t* node, void* data){ +cchunked_node_t* cchunked_list_insert_after(cchunked_list_t* list, cchunked_node_t* node, void* data){ if (!list) return NULL; - - if (!node){ + if (!node) { cchunked_list_push_back(list, data); return list->tail; } - - if(node->count < list->chunkSize){//chunk isnt completrly full + + if (node->count < list->chunkSize) { node->data[node->count++] = data; list->length++; return node; } - - //new node + uintptr_t m = malloc(sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); if (!m) return NULL; cchunked_node_t* new_node = (cchunked_node_t*)m; @@ -95,53 +89,51 @@ cchunked_node_t* cchunked_list_insert_after(cchunked_list_t* list,cchunked_node_ new_node->next = node->next; new_node->data[0] = data; - //linking new node node->next = new_node; if (list->tail == node) list->tail = new_node; - list->length++; return new_node; } + void* cchunked_list_pop_front(cchunked_list_t* list){ - if (!list || list->length == 0 || list->head == NULL) return NULL; - + if (!list || !list->head || list->length == 0) return NULL; + void* data = list->head->data[0]; - if (list->head->count > 1){ - for (uint64_t i = 1; i < list->head->count; ++i) list->head->data[i-1] = list->head->data[i]; + if (list->head->count > 1) { + for (uint64_t i = 1; i < list->head->count; ++i) + list->head->data[i-1] = list->head->data[i]; list->head->count--; } else { - //uniq element - cchunked_node_t* old =list->head; + cchunked_node_t* old = list->head; list->head = old->next; - if(list->head == NULL) list->tail = NULL; + if (!list->head) list->tail = NULL; free(old, sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); } - + list->length--; return data; } - - void* cchunked_list_remove_node(cchunked_list_t* list, cchunked_node_t* node){ if (!list || !node || !list->head) return NULL; - //delegate to pop_front - if (node == list->head) return cchunked_list_pop_front(list); + if (node == list->head) + return cchunked_list_pop_front(list); cchunked_node_t* prev = list->head; - while (prev->next && prev->next != node) prev= prev->next; + while (prev->next && prev->next != node) prev = prev->next; if (prev->next != node) return NULL; void* data = node->data[0]; - for (uint64_t i = 1; i < node->count; ++i) node->data[i-1] = node->data[i]; - + for (uint64_t i = 1; i < node->count; ++i) + node->data[i - 1] = node->data[i]; node->count--; list->length--; - if (node->count == 0){ + + if (node->count == 0) { prev->next = node->next; - if(list->tail == node) list->tail = prev; - free(node, sizeof(cchunked_node_t)+list->chunkSize * sizeof(void*)); + if (list->tail == node) list->tail = prev; + free(node, sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); } return data; @@ -149,7 +141,14 @@ void* cchunked_list_remove_node(cchunked_list_t* list, cchunked_node_t* node){ void cchunked_list_update(cchunked_list_t* list, cchunked_node_t* node, void* new_data){ (void)list; - if (node&&node->count) node->data[0] = new_data; + if (node && node->count) + node->data[0] = new_data; +} + +void cchunked_list_update_at(cchunked_list_t* list, cchunked_node_t* node, uint64_t offset, void* new_data){ + if (!list || !node || offset >= node->count) + return; + node->data[offset] = new_data; } uint64_t cchunked_list_length(const cchunked_list_t* list){ @@ -160,7 +159,6 @@ uint64_t cchunked_list_size_bytes(const cchunked_list_t* list){ if (!list) return 0; uint64_t nodes = 0; for (cchunked_node_t* it = list->head; it; it = it->next) nodes++; - return nodes * (sizeof(cchunked_node_t) + list->chunkSize * sizeof(void*)); } @@ -170,13 +168,7 @@ void cchunked_list_for_each(const cchunked_list_t* list, void (*func)(void*)){ for (uint64_t i = 0; i < it->count; ++i) func(it->data[i]); } -void cchunked_list_update_at(cchunked_list_t* list, cchunked_node_t* node,uint64_t offset,void* new_data){ - if(!list || !node || offset >= node->count)return; - - node->data[offset] = new_data; -} int cchunked_list_is_empty(const cchunked_list_t* list){ return (!list || list->length == 0) ? 1 : 0; } -} diff --git a/shared/data_struct/chunked_list.h b/shared/data_struct/chunked_list.h new file mode 100644 index 00000000..3d341c96 --- /dev/null +++ b/shared/data_struct/chunked_list.h @@ -0,0 +1,40 @@ +#pragma once +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct cchunked_node { + uint64_t count; + struct cchunked_node* next; + void* data[]; +} cchunked_node_t; + +typedef struct cchunked_list { + uint64_t chunkSize; + uint64_t length; + cchunked_node_t* head; + cchunked_node_t* tail; +} cchunked_list_t; + +uintptr_t malloc(uint64_t size); +void free(void* ptr, uint64_t size); + +cchunked_list_t* cchunked_list_create(uint64_t chunkSize); +void cchunked_list_destroy(cchunked_list_t* list); +cchunked_list_t* cchunked_list_clone(const cchunked_list_t* list); +void cchunked_list_push_back(cchunked_list_t* list, void* data); +void* cchunked_list_pop_front(cchunked_list_t* list); +cchunked_node_t* cchunked_list_insert_after(cchunked_list_t* list, cchunked_node_t* node, void* data); +void* cchunked_list_remove_node(cchunked_list_t* list, cchunked_node_t* node); +void cchunked_list_update(cchunked_list_t* list, cchunked_node_t* node, void* new_data); +void cchunked_list_update_at(cchunked_list_t* list, cchunked_node_t* node, uint64_t offset, void* new_data); +uint64_t cchunked_list_length(const cchunked_list_t* list); +uint64_t cchunked_list_size_bytes(const cchunked_list_t* list); +void cchunked_list_for_each(const cchunked_list_t* list, void (*func)(void*)); +int cchunked_list_is_empty(const cchunked_list_t* list); + +#ifdef __cplusplus +} +#endif diff --git a/shared/data_struct/chunked_list.hpp b/shared/data_struct/chunked_list.hpp index 41069f58..df5f04c1 100644 --- a/shared/data_struct/chunked_list.hpp +++ b/shared/data_struct/chunked_list.hpp @@ -1,90 +1,64 @@ #pragma once - #include "types.h" - -#ifdef __cplusplus extern "C" { -#endif - -extern uintptr_t malloc(uint64_t size); -extern void free(void *ptr, uint64_t size); - -typedef struct cchunked_node{ - uint64_t count; - struct cchunked_node* next; - void* data[]; -}cchunked_node_t; - -typedef struct cchunked_list{ - uint64_t chunkSize; - uint64_t length; - cchunked_node_t* head; - cchunked_node_t* tail; -}cchunked_list_t; - -cchunked_list_t* cchunked_list_create(uint64_t chunkSize); -void cchunked_list_destroy(cchunked_list_t* list); -cchunked_list_t* cchunked_list_clone(const cchunked_list_t* list); -void cchunked_list_push_back(cchunked_list_t* list, void* data); -void* cchunked_list_pop_front(cchunked_list_t* list); -cchunked_node_t* cchunked_list_insert_after(cchunked_list_t* list, cchunked_node_t* node, void* data); -void* cchunked_list_remove_node(cchunked_list_t* list, cchunked_node_t* node); -void cchunked_list_update(cchunked_list_t* list, cchunked_node_t* node, void* new_data); -void cchunked_list_update_at(cchunked_list_t* list, cchunked_node_t* node,uint64_t offset, void* new_data); -uint64_t cchunked_list_length(const cchunked_list_t* list); -uint64_t cchunked_list_size_bytes(const cchunked_list_t* list); -void cchunked_list_for_each(const cchunked_list_t* list, void (*func)(void*)); -int cchunked_list_is_empty(const cchunked_list_t* list); - -#ifdef __cplusplus +#include "chunked_list.h" } + template -class ChunkedList{ +class ChunkedList { public: - struct Node{ + struct Node { uint64_t count; Node* next; T data[]; }; - explicit ChunkedList(uint64_t cs): head(nullptr), tail(nullptr), length_(0), chunkSize(cs){} - ~ChunkedList(){ - while (head){ - Node* nx = head->next; + explicit ChunkedList(uint64_t cs) + : head(nullptr), tail(nullptr), length_(0), chunkSize(cs) {} + + ~ChunkedList() { + while (head) { + Node* next = head->next; ::free(head, sizeof(Node) + chunkSize * sizeof(T)); - head = nx; + head = next; } } - ChunkedList(const ChunkedList& other): head(nullptr), tail(nullptr), length_(0), chunkSize(other.chunkSize){ - for (Node* c = other.head; c; c = c->next) - for (uint64_t i = 0; i < c->count; ++i) + ChunkedList(const ChunkedList& other) + : head(nullptr), tail(nullptr), length_(0), chunkSize(other.chunkSize) { + for (Node* c = other.head; c; c = c->next) { + for (uint64_t i = 0; i < c->count; ++i) { push_back(c->data[i]); + } + } } - ChunkedList& operator=(const ChunkedList& other){ - if (this != &other){ + ChunkedList& operator=(const ChunkedList& other) { + if (this != &other) { clear(); chunkSize = other.chunkSize; - for (Node* c = other.head; c; c = c->next) - for (uint64_t i = 0; i < c->count; ++i) + for (Node* c = other.head; c; c = c->next) { + for (uint64_t i = 0; i < c->count; ++i) { push_back(c->data[i]); + } + } } return *this; } - void push_back(const T& value){ + void push_back(const T& value) { if (!tail) allocFirst(); if (tail->count == chunkSize) allocChunk(); tail->data[tail->count++] = value; ++length_; } - T pop_front(){ + T pop_front() { if (!head) return T(); T val = head->data[0]; - if (head->count > 1){ - for (uint64_t i = 1; i < head->count; ++i) head->data[i-1] = head->data[i]; + if (head->count > 1) { + for (uint64_t i = 1; i < head->count; ++i) + head->data[i - 1] = head->data[i]; --head->count; } else { Node* old = head; @@ -96,83 +70,87 @@ class ChunkedList{ return val; } - Node* insert_after(Node* node, const T& value){ - if (!node){ + Node* insert_after(Node* node, const T& value) { + if (!node) { push_back(value); return tail; } - if (node->count < chunkSize){ + if (node->count < chunkSize) { node->data[node->count++] = value; ++length_; return node; } - Node* n=allocNode(value); + Node* n = allocNode(value); n->next = node->next; node->next = n; - if (tail ==node) tail = n; + if (tail == node) tail = n; ++length_; return n; } -T remove_node(Node* node){ - if (!node|| !head) return T(); - if (node == head){ - T val = head->data[0]; - uint64_t removed = head->count; - Node* nxt = head->next; - ::free(head, sizeof(Node) + chunkSize * sizeof(T)); - head = nxt; - if(!head) tail = nullptr; + T remove_node(Node* node) { + if (!node || !head) return T(); + if (node == head) { + T val = head->data[0]; + uint64_t removed = head->count; + Node* nxt = head->next; + ::free(head, sizeof(Node) + chunkSize * sizeof(T)); + head = nxt; + if (!head) tail = nullptr; + length_ -= removed; + return val; + } + Node* prev = head; + while (prev->next && prev->next != node) prev = prev->next; + if (prev->next != node) return T(); + T val = node->data[0]; + uint64_t removed = node->count; + prev->next = node->next; + if (tail == node) tail = prev; + ::free(node, sizeof(Node) + chunkSize * sizeof(T)); length_ -= removed; return val; } - Node* prev = head; - while (prev->next && prev->next != node) prev = prev->next; - if (prev->next != node) return T(); - - T val = node->data[0]; - uint64_t removed = node->count; - prev->next = node->next; - if (tail==node) tail = prev; - - ::free(node, sizeof(Node) + chunkSize * sizeof(T)); - length_ -= removed; - return val; -} - void update(Node* node, const T& value){ + void update(Node* node, const T& value) { if (node && node->count) node->data[0] = value; } - void update_at(Node* node, uint64_t offset, const T& value){ + void update_at(Node* node, uint64_t offset, const T& value) { if (node && offset < node->count) node->data[offset] = value; } - uint64_t size() const noexcept{return length_;} + uint64_t size() const noexcept { + return length_; + } - uint64_t size_bytes() const noexcept{ + uint64_t size_bytes() const noexcept { uint64_t nodes = 0; for (Node* it = head; it; it = it->next) ++nodes; return nodes * (sizeof(Node) + chunkSize * sizeof(T)); } - bool empty() const noexcept{return length_ == 0; } + bool empty() const noexcept { + return length_ == 0; + } template - void for_each(Func f) const{ - for (Node* it = head; it; it = it->next) - for (uint64_t i = 0; i < it->count; ++i) + void for_each(Func f) const { + for (Node* it = head; it; it = it->next) { + for (uint64_t i = 0; i < it->count; ++i) { f(it->data[i]); + } + } } private: - Node* head = nullptr; - Node* tail = nullptr; - uint64_t length_ = 0; + Node* head; + Node* tail; + uint64_t length_; uint64_t chunkSize; - Node* allocNode(const T& value){ - uintptr_t raw= ::malloc(sizeof(Node) + chunkSize * sizeof(T)); + Node* allocNode(const T& value) { + uintptr_t raw = ::malloc(sizeof(Node) + chunkSize * sizeof(T)); Node* n = reinterpret_cast(raw); n->count = 1; n->next = nullptr; @@ -180,24 +158,24 @@ T remove_node(Node* node){ return n; } - void allocFirst(){ - uintptr_t raw = ::malloc(sizeof(Node) +chunkSize*sizeof(T)); + void allocFirst() { + uintptr_t raw = ::malloc(sizeof(Node) + chunkSize * sizeof(T)); head = tail = reinterpret_cast(raw); head->count = 0; head->next = nullptr; } - void allocChunk(){ - uintptr_t raw = ::malloc(sizeof(Node)+ chunkSize * sizeof(T)); - Node* n=reinterpret_cast(raw); + void allocChunk() { + uintptr_t raw = ::malloc(sizeof(Node) + chunkSize * sizeof(T)); + Node* n = reinterpret_cast(raw); n->count = 0; n->next = nullptr; tail->next = n; tail = n; } - void clear(){ + void clear() { while (head) pop_front(); } }; -#endif + diff --git a/shared/data_struct/doubly_linked_list.c b/shared/data_struct/doubly_linked_list.c new file mode 100644 index 00000000..d3707a85 --- /dev/null +++ b/shared/data_struct/doubly_linked_list.c @@ -0,0 +1,181 @@ +#include "doubly_linked_list.h" + +cdouble_linked_list_t* cdouble_linked_list_create(void) { + uintptr_t raw = malloc((uint64_t)sizeof(cdouble_linked_list_t)); + if (!raw) return NULL; + cdouble_linked_list_t* list = (cdouble_linked_list_t*)raw; + list->head = list->tail = NULL; + list->length = 0; + return list; +} + +void cdouble_linked_list_destroy(cdouble_linked_list_t* list) { + if (!list) return; + cdouble_linked_list_node_t* node = list->head; + for (uint64_t i = 0; i < list->length; ++i) { + cdouble_linked_list_node_t* next = node->next; + free(node, sizeof(cdouble_linked_list_node_t)); + node = next; + } + free(list, sizeof(cdouble_linked_list_t)); +} + +cdouble_linked_list_t* cdouble_linked_list_clone(const cdouble_linked_list_t* list) { + if (!list) return NULL; + cdouble_linked_list_t* clone = cdouble_linked_list_create(); + if (!clone) return NULL; + cdouble_linked_list_node_t* it = list->head; + for (uint64_t i = 0; i < list->length; ++i) { + uintptr_t raw = malloc(sizeof(cdouble_linked_list_node_t)); + if (raw) { + cdouble_linked_list_node_t* node = (cdouble_linked_list_node_t*)raw; + node->data = it->data; + if (clone->length == 0) { + node->next = node->prev = node; + clone->head = clone->tail = node; + } else { + node->prev = clone->tail; + node->next = clone->head; + clone->tail->next = node; + clone->head->prev = node; + clone->tail = node; + } + ++clone->length; + } + it = it->next; + } + return clone; +} + +void cdouble_linked_list_push_front(cdouble_linked_list_t* list, void* data) { + if (!list) return; + uintptr_t raw = malloc(sizeof(cdouble_linked_list_node_t)); + if (!raw) return; + cdouble_linked_list_node_t* node = (cdouble_linked_list_node_t*)raw; + node->data = data; + if (list->length == 0) { + node->next = node->prev = node; + list->head = list->tail = node; + } else { + node->next = list->head; + node->prev = list->tail; + list->head->prev = node; + list->tail->next = node; + list->head = node; + } + ++list->length; +} + +void cdouble_linked_list_push_back(cdouble_linked_list_t* list, void* data) { + if (!list) return; + uintptr_t raw = malloc(sizeof(cdouble_linked_list_node_t)); + if (!raw) return; + cdouble_linked_list_node_t* node = (cdouble_linked_list_node_t*)raw; + node->data = data; + if (list->length == 0) { + node->next = node->prev = node; + list->head = list->tail = node; + } else { + node->prev = list->tail; + node->next = list->head; + list->tail->next = node; + list->head->prev = node; + list->tail = node; + } + ++list->length; +} + +void* cdouble_linked_list_pop_front(cdouble_linked_list_t* list) { + if (!list || list->length == 0) return NULL; + cdouble_linked_list_node_t* node = list->head; + void* data = node->data; + if (list->length == 1) { + list->head = list->tail = NULL; + } else { + list->head = node->next; + list->head->prev = list->tail; + list->tail->next = list->head; + } + --list->length; + free(node, sizeof(cdouble_linked_list_node_t)); + return data; +} + +void* cdouble_linked_list_pop_back(cdouble_linked_list_t* list) { + if (!list || list->length == 0) return NULL; + cdouble_linked_list_node_t* node = list->tail; + void* data = node->data; + if (list->length == 1) { + list->head = list->tail = NULL; + } else { + list->tail = node->prev; + list->tail->next = list->head; + list->head->prev = list->tail; + } + --list->length; + free(node, sizeof(cdouble_linked_list_node_t)); + return data; +} + +cdouble_linked_list_node_t* cdouble_linked_list_insert_after(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* data) { + if (!list) return NULL; + if (!node) { + cdouble_linked_list_push_front(list, data); + return list->head; + } + uintptr_t raw = malloc(sizeof(cdouble_linked_list_node_t)); + if (!raw) return NULL; + cdouble_linked_list_node_t* new_node = (cdouble_linked_list_node_t*)raw; + new_node->data = data; + new_node->next = node->next; + new_node->prev = node; + node->next->prev = new_node; + node->next = new_node; + if (list->tail == node) list->tail = new_node; + ++list->length; + return new_node; +} + +cdouble_linked_list_node_t* cdouble_linked_list_insert_before(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* data) { + if (!list) return NULL; + if (!node) { + cdouble_linked_list_push_back(list, data); + return list->tail; + } + return cdouble_linked_list_insert_after(list, node->prev, data); +} + +void* cdouble_linked_list_remove(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node) { + if (!list || !node || list->length == 0) return NULL; + if (node == list->head) return cdouble_linked_list_pop_front(list); + if (node == list->tail) return cdouble_linked_list_pop_back(list); + node->prev->next = node->next; + node->next->prev = node->prev; + void* data = node->data; + --list->length; + free(node, sizeof(cdouble_linked_list_node_t)); + return data; +} + +void cdouble_linked_list_update(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* new_data) { + (void)list; + if (node) node->data = new_data; +} + +uint64_t cdouble_linked_list_length(const cdouble_linked_list_t* list) { + return list ? list->length : 0; +} + +uint64_t cdouble_linked_list_size_bytes(const cdouble_linked_list_t* list) { + return list ? list->length * sizeof(cdouble_linked_list_node_t) : 0; +} + +cdouble_linked_list_node_t* cdouble_linked_list_find(cdouble_linked_list_t* list, void* key, int (*cmp)(void*, void*)) { + if (!list || !cmp || list->length == 0) return NULL; + cdouble_linked_list_node_t* it = list->head; + for (uint64_t i = 0; i < list->length; ++i) { + if (cmp(it->data, key) == 0) return it; + it = it->next; + } + return NULL; +} diff --git a/shared/data_struct/doubly_linked_list.cpp b/shared/data_struct/doubly_linked_list.cpp deleted file mode 100644 index 2b01d051..00000000 --- a/shared/data_struct/doubly_linked_list.cpp +++ /dev/null @@ -1,195 +0,0 @@ -#include "doubly_linked_list.hpp" - -cdouble_linked_list_t* cdouble_linked_list_create(void){ - uintptr_t raw = malloc((uint64_t)sizeof(cdouble_linked_list_t));//i believe that casting sizeof is better until size_t is defined correctly - if (raw == 0) return NULL; - - cdouble_linked_list_t *list = (cdouble_linked_list_t*)raw; - list->head = list->tail = NULL; - list->length = 0; - return list; -} - -void cdouble_linked_list_destroy(cdouble_linked_list_t *list){ - if (!list) return; - - cdouble_linked_list_node_t *node=list->head; - for (uint64_t i = 0; i < list->length; ++i){ - cdouble_linked_list_node_t *next = node->next; - free(node,(uint64_t)sizeof(cdouble_linked_list_node_t)); - node = next; - } - free(list, (uint64_t)sizeof(cdouble_linked_list_t)); -} - -cdouble_linked_list_t* cdouble_linked_list_clone(const cdouble_linked_list_t *list){ //could create data aliasing. be careful. TODO - if (!list) return NULL; - - cdouble_linked_list_t *clone=cdouble_linked_list_create(); - if (!clone) return NULL; - - cdouble_linked_list_node_t *it =list->head; - for (uint64_t i = 0; ilength; ++i){ - uintptr_t raw =malloc((uint64_t)sizeof(cdouble_linked_list_node_t)); - if (raw) { - cdouble_linked_list_node_t *node =(cdouble_linked_list_node_t*)raw; - node->data = it->data; - - if (clone->length == 0){ - node->next=node->prev = node; - clone->head=clone->tail = node; - } else { - node->prev=clone->tail; - node->next=clone->head; - clone->tail->next=node; - clone->head->prev= node; - clone->tail =node; - } - ++clone->length; - } - it = it->next; - } - return clone; -} - -void cdouble_linked_list_push_front(cdouble_linked_list_t *list, void *data){ - if (!list) return; - uintptr_t raw= malloc((uint64_t)sizeof(cdouble_linked_list_node_t)); - if (raw == 0) return; - cdouble_linked_list_node_t *node=(cdouble_linked_list_node_t*)raw; - node->data = data; - - if (list->length == 0){ - node->next=node->prev = node; - list->head=list->tail = node; - } else { - node->next=list->head; - node->prev=list->tail; - list->head->prev= node; - list->tail->next= node; - list->head= node; - } - ++list->length; -} - -void cdouble_linked_list_push_back(cdouble_linked_list_t* list, void* data){ - if (!list) return; - uintptr_t raw=malloc((uint64_t)sizeof(cdouble_linked_list_node_t)); - if (raw ==0) return; - cdouble_linked_list_node_t* node=(cdouble_linked_list_node_t*)raw; - node->data = data; - - if (list->length==0){ - node->next=node->prev=node; - list->head=list->tail = node; - } else { - node->prev= list->tail; - node->next=list->head; - list->tail->next=node; - list->head->prev=node; - list->tail =node; - } - ++list->length; -} - -void* cdouble_linked_list_pop_front(cdouble_linked_list_t* list){ - if (!list||list->length==0) return NULL; - - cdouble_linked_list_node_t* node=list->head; - void* data=node->data; - if (list->length == 1){ - list->head=list->tail=NULL; - } else { - list->head=node->next; - list->head->prev =list->tail; - list->tail->next=list->head; - } - --list->length; - free(node,(uint64_t)sizeof(cdouble_linked_list_node_t)); - return data; -} - -void* cdouble_linked_list_pop_back(cdouble_linked_list_t* list){ - if (!list||list->length==0) return NULL; - - cdouble_linked_list_node_t* node=list->tail; - void* data=node->data; - if (list->length==1){ - list->head = list->tail=NULL; - } else { - list->tail=node->prev; - list->tail->next=list->head; - list->head->prev=list->tail; - } - --list->length; - free(node, (uint64_t)sizeof(cdouble_linked_list_node_t)); - return data; -} - -cdouble_linked_list_node_t* cdouble_linked_list_insert_after(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* data){ - if (!list) return NULL; - if (!node){ - cdouble_linked_list_push_front(list, data); - return list->head; - } - - uintptr_t raw=malloc((uint64_t)sizeof(cdouble_linked_list_node_t)); - if (raw==0) return NULL; - - cdouble_linked_list_node_t* new_node = (cdouble_linked_list_node_t*)raw; - new_node->data = data; - new_node->next = node->next; - new_node->prev = node; - node->next->prev = new_node; - node->next = new_node; - if (list->tail == node) list->tail = new_node; - ++list->length; - return new_node; -} - -cdouble_linked_list_node_t* cdouble_linked_list_insert_before(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* data){ - if (!list) return NULL; - - if (!node){ - cdouble_linked_list_push_back(list, data); - return list->tail; - } - return cdouble_linked_list_insert_after(list, node->prev, data); -} - -void* cdouble_linked_list_remove(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node){ - if (!list|| !node|| list->length==0) return NULL; - - if (node==list->head) return cdouble_linked_list_pop_front(list); - if (node==list->tail) return cdouble_linked_list_pop_back(list); - node->prev->next = node->next; - node->next->prev = node->prev; - void* data = node->data; - --list->length; - free(node,(uint64_t)sizeof(cdouble_linked_list_node_t)); - return data; -} - -void cdouble_linked_list_update(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* new_data){ - (void)list; - if (node) node->data=new_data; -} - -uint64_t cdouble_linked_list_length(const cdouble_linked_list_t* list){ - return list?list-> length:0; -} - -uint64_t cdouble_linked_list_size_bytes(const cdouble_linked_list_t* list){ - return list?list-> length * sizeof(cdouble_linked_list_node_t):0; -} - -cdouble_linked_list_node_t* cdouble_linked_list_find(cdouble_linked_list_t* list, void* key, int (*cmp)(void*,void*)){ - if (!list||!cmp|| list->length==0) return NULL; - - cdouble_linked_list_node_t* it=list->head; - for (uint64_t i=0; ilength; ++i){ - if (cmp(it->data,key)==0) return it; - it = it->next; - } - return NULL; -} diff --git a/shared/data_struct/doubly_linked_list.h b/shared/data_struct/doubly_linked_list.h new file mode 100644 index 00000000..aee049f5 --- /dev/null +++ b/shared/data_struct/doubly_linked_list.h @@ -0,0 +1,40 @@ +#pragma once +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct cdouble_linked_list_node { + void* data; + struct cdouble_linked_list_node* next; + struct cdouble_linked_list_node* prev; +} cdouble_linked_list_node_t; + +typedef struct cdouble_linked_list { + cdouble_linked_list_node_t* head; + cdouble_linked_list_node_t* tail; + uint64_t length; +} cdouble_linked_list_t; + +extern uintptr_t malloc(uint64_t size); +extern void free(void* ptr, uint64_t size); + +cdouble_linked_list_t* cdouble_linked_list_create(void); +void cdouble_linked_list_destroy(cdouble_linked_list_t* list); +cdouble_linked_list_t* cdouble_linked_list_clone(const cdouble_linked_list_t* list); +void cdouble_linked_list_push_front(cdouble_linked_list_t* list, void* data); +void cdouble_linked_list_push_back(cdouble_linked_list_t* list, void* data); +void* cdouble_linked_list_pop_front(cdouble_linked_list_t* list); +void* cdouble_linked_list_pop_back(cdouble_linked_list_t* list); +cdouble_linked_list_node_t* cdouble_linked_list_insert_after(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* data); +cdouble_linked_list_node_t* cdouble_linked_list_insert_before(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* data); +void* cdouble_linked_list_remove(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node); +void cdouble_linked_list_update(cdouble_linked_list_t* list, cdouble_linked_list_node_t* node, void* new_data); +uint64_t cdouble_linked_list_length(const cdouble_linked_list_t* list); +uint64_t cdouble_linked_list_size_bytes(const cdouble_linked_list_t* list); +cdouble_linked_list_node_t* cdouble_linked_list_find(cdouble_linked_list_t* list, void* key, int (*cmp)(void*, void*)); + +#ifdef __cplusplus +} +#endif diff --git a/shared/data_struct/doubly_linked_list.hpp b/shared/data_struct/doubly_linked_list.hpp index 15791ca1..2438e01d 100644 --- a/shared/data_struct/doubly_linked_list.hpp +++ b/shared/data_struct/doubly_linked_list.hpp @@ -1,90 +1,48 @@ #pragma once #include "types.h" -#ifdef __cplusplus extern "C" { -#endif - -typedef struct cdouble_linked_list_node{ - void *data; - struct cdouble_linked_list_node *next; - struct cdouble_linked_list_node *prev; -}cdouble_linked_list_node_t; - -typedef struct cdouble_linked_list{ - cdouble_linked_list_node_t *head; - cdouble_linked_list_node_t *tail; - uint64_t length; -}cdouble_linked_list_t; - - -extern uintptr_t malloc(uint64_t size); -extern void free(void *ptr, uint64_t size); - - -cdouble_linked_list_t *cdouble_linked_list_create(void); -void cdouble_linked_list_destroy(cdouble_linked_list_t *list); -cdouble_linked_list_t *cdouble_linked_list_clone(const cdouble_linked_list_t *list); -void cdouble_linked_list_push_front(cdouble_linked_list_t *list, void *data); -void cdouble_linked_list_push_back(cdouble_linked_list_t *list, void *data); -void *cdouble_linked_list_pop_front(cdouble_linked_list_t *list); -void *cdouble_linked_list_pop_back(cdouble_linked_list_t *list); -cdouble_linked_list_node_t *cdouble_linked_list_insert_after(cdouble_linked_list_t *list, cdouble_linked_list_node_t *node, void *data); -cdouble_linked_list_node_t *cdouble_linked_list_insert_before(cdouble_linked_list_t *list, cdouble_linked_list_node_t *node, void *data); -void *cdouble_linked_list_remove(cdouble_linked_list_t *list, cdouble_linked_list_node_t *node); -void cdouble_linked_list_update(cdouble_linked_list_t *list, cdouble_linked_list_node_t *node, void *new_data); -uint64_t cdouble_linked_list_length(const cdouble_linked_list_t *list); -uint64_t cdouble_linked_list_size_bytes(const cdouble_linked_list_t *list); -cdouble_linked_list_node_t* cdouble_linked_list_find(cdouble_linked_list_t *list, void *key, int (*cmp)(void *, void *)); - -#ifdef __cplusplus +#include "doubly_linked_list.h" } template -class LinkedList{ +class LinkedList { private: - struct Node{ + struct Node { T data; - Node *next; - Node *prev; + Node* next; + Node* prev; }; - Node *head; - Node *tail; + Node* head; + Node* tail; uint64_t length; - Node* alloc_node(const T& value){ - uintptr_t raw= malloc((uint64_t)sizeof(Node)); + Node* alloc_node(const T& value) { + uintptr_t raw = malloc(sizeof(Node)); if (raw == 0) return nullptr; - - Node* n = (Node*)raw; + Node* n = reinterpret_cast(raw); n->data = value; n->next = n->prev = nullptr; return n; } - void free_node(Node* n){ + void free_node(Node* n) { if (!n) return; - free(n,(uint64_t)sizeof(Node)); + free(n, sizeof(Node)); } - static void swap(LinkedList& a, LinkedList& b) noexcept{ - Node* tmp_head = a.head; - a.head = b.head; - b.head = tmp_head; - Node* tmp_tail = a.tail; - a.tail = b.tail; - b.tail = tmp_tail; - uint64_t tmp_length = a.length; - a.length = b.length; - b.length = tmp_length; + static void swap(LinkedList& a, LinkedList& b) noexcept { + std::swap(a.head, b.head); + std::swap(a.tail, b.tail); + std::swap(a.length, b.length); } public: - LinkedList() : head(nullptr), tail(nullptr), length(0){} + LinkedList() : head(nullptr), tail(nullptr), length(0) {} - LinkedList(const LinkedList& other):head(nullptr), tail(nullptr), length(0){ - if (other.head){ + LinkedList(const LinkedList& other) : head(nullptr), tail(nullptr), length(0) { + if (other.head) { Node* it = other.head; do { push_back(it->data); @@ -93,11 +51,11 @@ class LinkedList{ } } - ~LinkedList(){ + ~LinkedList() { while (!empty()) pop_front(); } - LinkedList& operator=(const LinkedList& other){ + LinkedList& operator=(const LinkedList& other) { if (this != &other) { LinkedList tmp(other); swap(*this, tmp); @@ -105,11 +63,10 @@ class LinkedList{ return *this; } - void push_front(const T& value){ + void push_front(const T& value) { Node* n = alloc_node(value); - if( !n) return; - - if (!head){ + if (!n) return; + if (!head) { head = tail = n; n->next = n->prev = n; } else { @@ -122,11 +79,10 @@ class LinkedList{ ++length; } - void push_back(const T& value){ + void push_back(const T& value) { Node* n = alloc_node(value); if (!n) return; - - if (!tail){ + if (!tail) { head = tail = n; n->next = n->prev = n; } else { @@ -139,13 +95,12 @@ class LinkedList{ ++length; } - T pop_front(){ + T pop_front() { if (!head) return T(); - Node* n = head; T val = n->data; - if (head == tail){ - head = tail=nullptr; + if (head == tail) { + head = tail = nullptr; } else { head = head->next; head->prev = tail; @@ -156,12 +111,11 @@ class LinkedList{ return val; } - T pop_back(){ + T pop_back() { if (!tail) return T(); - Node* n = tail; T val = n->data; - if (head == tail){ + if (head == tail) { head = tail = nullptr; } else { tail = tail->prev; @@ -173,37 +127,34 @@ class LinkedList{ return val; } - Node* insert_after(Node* node, const T& value){ - if (!node){ + Node* insert_after(Node* node, const T& value) { + if (!node) { push_front(value); return head; } - Node* n = alloc_node(value); if (!n) return nullptr; - - n->next=node->next; - n->prev=node; + n->next = node->next; + n->prev = node; node->next->prev = n; - node->next= n; + node->next = n; if (tail == node) tail = n; ++length; return n; } - Node* insert_before(Node* node, const T& value){ - if (!node){ + Node* insert_before(Node* node, const T& value) { + if (!node) { push_back(value); return tail; } return insert_after(node->prev, value); } - T remove(Node* node){ + T remove(Node* node) { if (!node) return T(); if (node == head) return pop_front(); if (node == tail) return pop_back(); - node->prev->next = node->next; node->next->prev = node->prev; T val = node->data; @@ -212,31 +163,39 @@ class LinkedList{ return val; } - void update(Node* node, const T& value){ - if (!node) return; - node->data = value; + void update(Node* node, const T& value) { + if (node) node->data = value; } - uint64_t size()const{return length;} - bool empty() const{return length==0;} - Node* begin() const{return head;} - Node* end() const{return nullptr;} + uint64_t size() const { + return length; + } + + bool empty() const { + return length == 0; + } + + Node* begin() const { + return head; + } + + Node* end() const { + return nullptr; + } template - Node* find(Predicate pred) const{ + Node* find(Predicate pred) const { if (!head) return nullptr; - Node* it = head; do { if (pred(it->data)) return it; it = it->next; } while (it != head); - return nullptr; } template - void for_each(Func func) const{ + void for_each(Func func) const { if (!head) return; Node* it = head; do { @@ -245,4 +204,4 @@ class LinkedList{ } while (it != head); } }; -#endif + diff --git a/shared/data_struct/linked_list.cpp b/shared/data_struct/linked_list.c similarity index 72% rename from shared/data_struct/linked_list.cpp rename to shared/data_struct/linked_list.c index 8012bdc2..0ffdd600 100644 --- a/shared/data_struct/linked_list.cpp +++ b/shared/data_struct/linked_list.c @@ -1,14 +1,8 @@ -#include "linked_list.hpp" -#include "types.h" - -#ifdef __cplusplus -extern "C" { -#endif +#include "linked_list.h" clinkedlist_t *clinkedlist_create(void){ uintptr_t mem = malloc(sizeof(clinkedlist_t)); - if ((void *)mem == NULL) return NULL; - + if((void *)mem == NULL) return NULL; clinkedlist_t *list = (clinkedlist_t *)mem; list->head = NULL; list->tail = NULL; @@ -17,10 +11,9 @@ clinkedlist_t *clinkedlist_create(void){ } void clinkedlist_destroy(clinkedlist_t *list){ - if (list == NULL) return; - + if(list == NULL) return; clinkedlist_node_t *node = list->head; - while (node){ + while(node){ clinkedlist_node_t *next = node->next; free(node, sizeof(clinkedlist_node_t)); node = next; @@ -29,14 +22,12 @@ void clinkedlist_destroy(clinkedlist_t *list){ } clinkedlist_t *clinkedlist_clone(const clinkedlist_t *list){ - if (list == NULL) return NULL; - + if(list == NULL) return NULL; clinkedlist_t *clone = clinkedlist_create(); - if (clone == NULL) return NULL; - + if(clone == NULL) return NULL; clinkedlist_node_t *it = list->head; - while (it){ - if (clone->tail){ + while(it){ + if(clone->tail){ clinkedlist_node_t *new_node = (clinkedlist_node_t *)malloc(sizeof(clinkedlist_node_t)); new_node->data = it->data; new_node->next = NULL; @@ -52,33 +43,29 @@ clinkedlist_t *clinkedlist_clone(const clinkedlist_t *list){ } void clinkedlist_push_front(clinkedlist_t *list, void *data){ - if (list == NULL) return; - + if(list == NULL) return; clinkedlist_node_t *node = (clinkedlist_node_t *)malloc(sizeof(clinkedlist_node_t)); node->data = data; node->next = list->head; list->head = node; - if (list->tail == NULL) list->tail = node; + if(list->tail == NULL) list->tail = node; list->length++; } void *clinkedlist_pop_front(clinkedlist_t *list){ - if (list == NULL || list->head== NULL) return NULL; - + if(list == NULL || list->head == NULL) return NULL; clinkedlist_node_t *node = list->head; void *data = node->data; list->head = node->next; if (list->head == NULL) list->tail = NULL; - list->length--; free(node, sizeof(clinkedlist_node_t)); return data; } -clinkedlist_node_t *clinkedlist_insert_after(clinkedlist_t *list, clinkedlist_node_t *node, void *data) { - if (list == NULL) return NULL; - - if (node == NULL){ +clinkedlist_node_t *clinkedlist_insert_after(clinkedlist_t *list, clinkedlist_node_t *node, void *data){ + if(list == NULL) return NULL; + if(node == NULL){ clinkedlist_push_front(list, data); return list->head; } @@ -86,26 +73,23 @@ clinkedlist_node_t *clinkedlist_insert_after(clinkedlist_t *list, clinkedlist_no new_node->data = data; new_node->next = node->next; node->next = new_node; - if (list->tail == node) list->tail = new_node; - + if(list->tail == node) list->tail = new_node; list->length++; return new_node; } void *clinkedlist_remove(clinkedlist_t *list, clinkedlist_node_t *node){ - if (list == NULL || node == NULL || list->head == NULL) return NULL; - - if (node == list->head){ + if(list == NULL || node == NULL || list->head == NULL) return NULL; + if(node == list->head){ return clinkedlist_pop_front(list); } clinkedlist_node_t *prev = list->head; - while (prev->next && prev->next != node){ + while(prev->next && prev->next != node){ prev = prev->next; } - if (prev->next != node) return NULL; - + if(prev->next != node) return NULL; prev->next = node->next; - if (node == list->tail) list->tail = prev; + if(node == list->tail) list->tail = prev; void *data = node->data; list->length--; free(node, sizeof(clinkedlist_node_t)); @@ -114,7 +98,7 @@ void *clinkedlist_remove(clinkedlist_t *list, clinkedlist_node_t *node){ void clinkedlist_update(clinkedlist_t *list, clinkedlist_node_t *node, void *new_data){ (void)list; - if (node) node->data = new_data; + if(node) node->data = new_data; } uint64_t clinkedlist_length(const clinkedlist_t *list){ @@ -126,26 +110,20 @@ uint64_t clinkedlist_size_bytes(const clinkedlist_t *list){ } clinkedlist_node_t *clinkedlist_find(clinkedlist_t *list, void *key, int (*cmp)(void *, void *)){ - if (list == NULL || cmp == NULL) return NULL; - + if(list == NULL || cmp == NULL) return NULL; clinkedlist_node_t *it = list->head; - while (it){ - if (cmp(it->data, key) == 0) return it; + while(it){ + if(cmp(it->data, key) == 0) return it; it = it->next; } return NULL; } void clinkedlist_for_each(const clinkedlist_t *list, void (*func)(void *)){ - if (list == NULL || func == NULL) return; - + if(list == NULL || func == NULL) return; clinkedlist_node_t *it = list->head; - while (it){ + while(it){ func(it->data); it = it->next; } } - -#ifdef __cplusplus -} -#endif diff --git a/shared/data_struct/linked_list.h b/shared/data_struct/linked_list.h new file mode 100644 index 00000000..4e27a8eb --- /dev/null +++ b/shared/data_struct/linked_list.h @@ -0,0 +1,37 @@ +#pragma once +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct clinkedlist_node { + void *data; + struct clinkedlist_node *next; +} clinkedlist_node_t; + +typedef struct clinkedlist { + clinkedlist_node_t *head; + clinkedlist_node_t *tail; + uint64_t length; +} clinkedlist_t; + +extern uintptr_t malloc(uint64_t size); +extern void free(void *ptr, uint64_t size); + +clinkedlist_t *clinkedlist_create(void); +void clinkedlist_destroy(clinkedlist_t *list); +clinkedlist_t *clinkedlist_clone(const clinkedlist_t *list); +void clinkedlist_push_front(clinkedlist_t *list, void *data); +void *clinkedlist_pop_front(clinkedlist_t *list); +clinkedlist_node_t *clinkedlist_insert_after(clinkedlist_t *list, clinkedlist_node_t *node, void *data); +void *clinkedlist_remove(clinkedlist_t *list, clinkedlist_node_t *node); +void clinkedlist_update(clinkedlist_t *list, clinkedlist_node_t *node, void *new_data); +uint64_t clinkedlist_length(const clinkedlist_t *list); +uint64_t clinkedlist_size_bytes(const clinkedlist_t *list); +clinkedlist_node_t *clinkedlist_find(clinkedlist_t *list, void *key, int (*cmp)(void *, void *)); +void clinkedlist_for_each(const clinkedlist_t *list, void (*func)(void *)); + +#ifdef __cplusplus +} +#endif diff --git a/shared/data_struct/linked_list.hpp b/shared/data_struct/linked_list.hpp index 2167ddfd..b4781fb1 100644 --- a/shared/data_struct/linked_list.hpp +++ b/shared/data_struct/linked_list.hpp @@ -1,94 +1,58 @@ #pragma once #include "types.h" -#ifdef __cplusplus extern "C" { -#endif - -typedef struct clinkedlist_node{ - void *data; - struct clinkedlist_node *next; -}clinkedlist_node_t; - -typedef struct clinkedlist{ - clinkedlist_node_t *head; - clinkedlist_node_t *tail; - uint64_t length; -}clinkedlist_t; - - -extern uintptr_t malloc(uint64_t size); -extern void free(void *ptr, uint64_t size); - - -clinkedlist_t *clinkedlist_create(void); -void clinkedlist_destroy(clinkedlist_t *list); -clinkedlist_t *clinkedlist_clone(const clinkedlist_t *list); -void clinkedlist_push_front(clinkedlist_t *list,void *data); -void *clinkedlist_pop_front(clinkedlist_t *list); -clinkedlist_node_t *clinkedlist_insert_after(clinkedlist_t *list, clinkedlist_node_t *node, void *data); -void *clinkedlist_remove(clinkedlist_t *list, clinkedlist_node_t *node); -void clinkedlist_update(clinkedlist_t *list, clinkedlist_node_t *node, void *new_data); -uint64_t clinkedlist_length(const clinkedlist_t *list); -uint64_t clinkedlist_size_bytes(const clinkedlist_t *list); -clinkedlist_node_t *clinkedlist_find(clinkedlist_t *list, void *key,int (*cmp)(void *, void *));//so not const function doesnt rise an annoyng warning -void clinkedlist_for_each(const clinkedlist_t *list, void (*func)(void *)); - -#ifdef __cplusplus +#include "linked_list.h" } -template class LinkedList{ +template +class LinkedList { private: - struct Node{ + struct Node { T data; - Node *next; + Node* next; }; - Node *head = nullptr; - Node *tail = nullptr; + Node* head = nullptr; + Node* tail = nullptr; uint64_t length = 0; - Node *alloc_node(const T &value){ + Node* alloc_node(const T& value) { uintptr_t mem = malloc(sizeof(Node)); - Node *n = reinterpret_cast(mem); + Node* n = reinterpret_cast(mem); n->data = value; n->next = nullptr; return n; } - void free_node(Node *n){ + void free_node(Node* n) { free(n, sizeof(Node)); } public: LinkedList() = default; - LinkedList(const LinkedList &other){ - for (Node *it = other.head; it; it = it->next){ + LinkedList(const LinkedList& other) { + for (Node* it = other.head; it; it = it->next) { push_front(it->data); } LinkedList tmp; - while (!empty()){ - tmp.push_front(pop_front()); - } + while (!empty()) tmp.push_front(pop_front()); *this = tmp; } - ~LinkedList(){ + ~LinkedList() { while (!empty()) pop_front(); } - LinkedList &operator=(const LinkedList &other){ - if (this != &other){ + LinkedList& operator=(const LinkedList& other) { + if (this != &other) { while (!empty()) pop_front(); - for (Node *it = other.head; it; it = it->next){ + for (Node* it = other.head; it; it = it->next) { push_front(it->data); } - LinkedList tmp; - while (!empty()){ - tmp.push_front(pop_front()); - } + while (!empty()) tmp.push_front(pop_front()); head = tmp.head; tail = tmp.tail; length = tmp.length; @@ -98,32 +62,31 @@ template class LinkedList{ return *this; } - void push_front(const T &value){ - Node *n = alloc_node(value); + void push_front(const T& value) { + Node* n = alloc_node(value); n->next = head; head = n; - if (tail == nullptr) tail = n; + if (!tail) tail = n; ++length; } - T pop_front(){ - Node *n = head; + T pop_front() { + if (!head) return T(); + Node* n = head; head = head->next; - if (head == nullptr) tail = nullptr; - + if (!head) tail = nullptr; T val = n->data; free_node(n); --length; return val; } - Node *insert_after(Node *node, const T &value){ - if (node == nullptr){ + Node* insert_after(Node* node, const T& value) { + if (!node) { push_front(value); return head; } - - Node *n = alloc_node(value); + Node* n = alloc_node(value); n->next = node->next; node->next = n; if (tail == node) tail = n; @@ -131,13 +94,12 @@ template class LinkedList{ return n; } - T remove(Node *node){ - if (node == nullptr) return T(); + T remove(Node* node) { + if (!node) return T(); if (node == head) return pop_front(); - - Node *prev = head; + Node* prev = head; while (prev && prev->next != node) prev = prev->next; - if (prev == nullptr) return T(); + if (!prev) return T(); prev->next = node->next; if (node == tail) tail = prev; T val = node->data; @@ -146,22 +108,32 @@ template class LinkedList{ return val; } - void update(Node *node, const T &value){ + void update(Node* node, const T& value) { if (node) node->data = value; } - uint64_t size() const{return length;} - bool empty() const{return length == 0; } - Node *begin() const{ return head; } - Node *end() const{ return nullptr;} - template + uint64_t size() const { + return length; + } + + bool empty() const { + return length == 0; + } - Node *find(Predicate pred) const{ - for (Node *it = head; it; it = it->next){ + Node* begin() const { + return head; + } + + Node* end() const { + return nullptr; + } + + template + Node* find(Predicate pred) const { + for (Node* it = head; it; it = it->next) { if (pred(it->data)) return it; } return nullptr; } }; -#endif diff --git a/shared/data_struct/queue.c b/shared/data_struct/queue.c new file mode 100644 index 00000000..957ea22d --- /dev/null +++ b/shared/data_struct/queue.c @@ -0,0 +1,69 @@ +#include "queue.h" +#include "std/memfunctions.h" + +void cqueue_init(CQueue* q, uint64_t max_capacity, uint64_t elem_size) { + q->buffer = NULL; + q->capacity = max_capacity; + q->max_capacity = max_capacity; + q->elem_size = elem_size; + q->head = q->tail = q->length = 0; + if (max_capacity > 0) { + uintptr_t b = malloc(max_capacity * elem_size); + if (b) q->buffer = (void*)b; + } +} + +int32_t cqueue_enqueue(CQueue* q, const void* item) { + if (!q) return 0; + if (q->max_capacity > 0) { + if (q->length == q->capacity) return 0; + } else { + if (q->length == q->capacity) { + uint64_t nc = q->capacity > 0 ? q->capacity * 2 : 4; + uintptr_t nb = malloc(nc * q->elem_size); + if (!nb) return 0; + void* newb = (void*)nb; + for (uint64_t i = 0; i < q->length; ++i) { + uint64_t idx = (q->tail + i) % q->capacity; + memcpy((uint8_t*)newb + i * q->elem_size, + (uint8_t*)q->buffer + idx * q->elem_size, + q->elem_size); + } + if (q->buffer) free(q->buffer, q->capacity * q->elem_size); + q->buffer = newb; + q->capacity = nc; + q->head = q->length; + q->tail = 0; + } + } + memcpy((uint8_t*)q->buffer + q->head * q->elem_size, item, q->elem_size); + q->head = (q->head + 1) % q->capacity; + q->length++; + return 1; +} + +int32_t cqueue_dequeue(CQueue* q, void* out) { + if (!q || q->length == 0) return 0; + memcpy(out, (uint8_t*)q->buffer + q->tail * q->elem_size, q->elem_size); + q->tail = (q->tail + 1) % q->capacity; + q->length--; + return 1; +} + +int32_t cqueue_is_empty(const CQueue* q) { + return (!q || q->length == 0) ? 1 : 0; +} + +uint64_t cqueue_size(const CQueue* q) { + return q ? q->length : 0; +} + +void cqueue_clear(CQueue* q) { + if (!q) return; + q->head = q->tail = q->length = 0; +} + +void cqueue_destroy(CQueue* q) { + if (!q) return; + if (q->buffer) free(q->buffer, q->capacity * q->elem_size); +} diff --git a/shared/data_struct/queue.cpp b/shared/data_struct/queue.cpp deleted file mode 100644 index 16374b06..00000000 --- a/shared/data_struct/queue.cpp +++ /dev/null @@ -1,72 +0,0 @@ - -#include "queue.hpp" -#include "std/memfunctions.h" - -void cqueue_init(CQueue* q,uint64_t max_capacity,uint64_t elem_size){ - q->buffer = NULL; - q->capacity = max_capacity; - q->max_capacity = max_capacity; - q->elem_size = elem_size; - q->head = q->tail = q->length = 0; - if (max_capacity > 0){ - uintptr_t b = malloc(max_capacity*elem_size); - if (b) q->buffer = (void*)b; - } -} - -int32_t cqueue_enqueue(CQueue* q,const void* item){ - if (!q) return 0; - if (q->max_capacity>0){ - if (q->length == q->capacity) return 0; - } else { - if (q->length == q->capacity){ - uint64_t nc = q->capacity>0 ? q->capacity*2 : 4; - uintptr_t nb = malloc(nc*q->elem_size); - if (!nb) return 0; - - void* newb = (void*)nb; - for (uint64_t i=0; ilength; ++i){ - uint64_t idx = (q->tail + i)%q->capacity; - memcpy((uint8_t*)newb + i*q->elem_size, - (uint8_t*)q->buffer + idx*q->elem_size, - q->elem_size); - } - if (q->buffer) free(q->buffer,q->capacity*q->elem_size); - q->buffer=newb; - q->capacity=nc; - q->head=q->length; - q->tail=0; - } - } - memcpy((uint8_t*)q->buffer + q->head*q->elem_size, item,q->elem_size); - q->head = (q->head+1)%q->capacity; - q->length++; - return 1; -} - -int32_t cqueue_dequeue(CQueue* q,void* out){ - if (!q || q->length == 0) return 0; - - memcpy(out,(uint8_t*)q->buffer + q->tail*q->elem_size,q->elem_size); - q->tail = (q->tail+1)%q->capacity; - q->length--; - return 1; -} - -int32_t cqueue_is_empty(const CQueue* q){ - return (!q || q->length==0) ? 1 : 0; -} - -uint64_t cqueue_size(const CQueue* q){ - return q ? q->length : 0; -} - -void cqueue_clear(CQueue* q){ - if (!q) return; - q->head=q->tail=q->length=0; -} - -void cqueue_destroy(CQueue* q){ - if (!q) return; - if (q->buffer) free(q->buffer,q->capacity*q->elem_size); -} diff --git a/shared/data_struct/queue.h b/shared/data_struct/queue.h new file mode 100644 index 00000000..531d3089 --- /dev/null +++ b/shared/data_struct/queue.h @@ -0,0 +1,31 @@ +#pragma once +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct CQueue { + void* buffer; + uint64_t capacity; // current queue size + uint64_t max_capacity; // 0 = infinite + uint64_t elem_size; + uint64_t head; + uint64_t tail; + uint64_t length; +} CQueue; + +extern uintptr_t malloc(uint64_t); +extern void free(void*, uint64_t); + +void cqueue_init(CQueue* q, uint64_t max_capacity, uint64_t elem_size); +int32_t cqueue_enqueue(CQueue* q, const void* item); +int32_t cqueue_dequeue(CQueue* q, void* out); +int32_t cqueue_is_empty(const CQueue* q); +uint64_t cqueue_size(const CQueue* q); +void cqueue_clear(CQueue* q); +void cqueue_destroy(CQueue* q); + +#ifdef __cplusplus +} +#endif diff --git a/shared/data_struct/queue.hpp b/shared/data_struct/queue.hpp index 7f0bbe8f..fe02fb9c 100644 --- a/shared/data_struct/queue.hpp +++ b/shared/data_struct/queue.hpp @@ -1,48 +1,87 @@ #pragma once #include "types.h" +#include "std/string.h" +#include "std/memfunctions.h" +#include "queue.h" -#ifdef __cplusplus -extern "C" { -#endif +template +class Queue { +public: + explicit Queue(uint64_t capacity = 0) { + max_capacity = capacity; + this->capacity = capacity; + if (capacity > 0) { + uintptr_t mem = malloc(capacity * sizeof(T)); + if (mem) { + buffer = reinterpret_cast(mem); + } + } + } -typedef struct CQueue { - void* buffer; - uint64_t capacity; //curremt queue size - uint64_t max_capacity; //0 is infinite - uint64_t elem_size; - uint64_t head; - uint64_t tail; - uint64_t length; -}CQueue; + ~Queue() { + if (buffer) { + free(buffer, capacity * sizeof(T)); + } + } + bool enqueue(const T& value) { + if (max_capacity > 0 && length == capacity) return false; + if (max_capacity == 0 && length == capacity) grow_if_needed(); + if (!buffer) return false; -extern uintptr_t malloc(uint64_t); -extern void free(void*,uint64_t); + buffer[head] = value; + head = (head + 1) % capacity; + ++length; + return true; + } + bool dequeue(T& out) { + if (length == 0 || !buffer) return false; + out = buffer[tail]; + tail = (tail + 1) % capacity; + --length; + return true; + } -void cqueue_init(CQueue* q,uint64_t max_capacity,uint64_t elem_size); -int32_t cqueue_enqueue(CQueue* q,const void* item); -int32_t cqueue_dequeue(CQueue* q,void* out); -int32_t cqueue_is_empty(const CQueue* q); -uint64_t cqueue_size(const CQueue* q); -void cqueue_clear(CQueue* q); -void cqueue_destroy(CQueue* q); + bool is_empty() const { + return length == 0; + } -#ifdef __cplusplus -} + uint64_t size() const { + return length; + } -template -class Queue { - CQueue q_; + void clear() { + head = tail = length = 0; + } -public: - explicit Queue(uint64_t cap=0){cqueue_init(&q_,cap,sizeof(T));} - ~Queue(){ cqueue_destroy(&q_); } - bool enqueue(const T& v){return cqueue_enqueue(&q_,&v);} - bool dequeue(T& out){return cqueue_dequeue(&q_,&out);} - bool isEmpty() const{return cqueue_is_empty(&q_);} - uint64_t size() const{return cqueue_size(&q_);} - void clear(){cqueue_clear(&q_);} +private: + T* buffer = nullptr; + uint64_t capacity = 0; + uint64_t max_capacity = 0; // 0 infinite + uint64_t head = 0; + uint64_t tail = 0; + uint64_t length = 0; + + void grow_if_needed() { + uint64_t new_cap = (capacity > 0) ? capacity * 2 : 4; + uintptr_t new_mem = malloc(new_cap * sizeof(T)); + if (!new_mem) return; + + T* new_buf = reinterpret_cast(new_mem); + for (uint64_t i = 0; i < length; ++i) { + uint64_t idx = (tail + i) % capacity; + new_buf[i] = buffer[idx]; + } + + if (buffer) { + free(buffer, capacity * sizeof(T)); + } + + buffer = new_buf; + capacity = new_cap; + tail = 0; + head = length; + } }; -#endif diff --git a/shared/data_struct/ring_buffer.cpp b/shared/data_struct/ring_buffer.c similarity index 53% rename from shared/data_struct/ring_buffer.cpp rename to shared/data_struct/ring_buffer.c index a1e7e946..67429799 100644 --- a/shared/data_struct/ring_buffer.cpp +++ b/shared/data_struct/ring_buffer.c @@ -1,28 +1,26 @@ -#include "types.h" -#include "ring_buffer.hpp" +#include "ring_buffer.h" #include "std/memfunctions.h" -void cring_init(struct CRingBuffer* rb, void* storage, uint64_t capacity, uint64_t elem_size){ +void cring_init(CRingBuffer* rb, void* storage, uint64_t capacity, uint64_t elem_size) { rb->buffer = storage; rb->capacity = capacity; rb->element_size = elem_size; - rb->head = 0; - rb->tail = 0; + rb->head = rb->tail = 0; rb->full = 0; } -uint64_t cring_capacity(const struct CRingBuffer* rb){ +uint64_t cring_capacity(const CRingBuffer* rb) { return rb->capacity; } -int32_t cring_push(struct CRingBuffer* rb, const void* item){ +int32_t cring_push(CRingBuffer* rb, const void* item) { if (rb->full) return 0; uint8_t* base = (uint8_t*)rb->buffer; void* dest = base + (rb->head * rb->element_size); - for (uint32_t i = 0; i < rb->element_size; ++i){ - ((uint8_t*)dest)[i] =((const uint8_t*)item)[i]; + for (uint64_t i = 0; i < rb->element_size; ++i) { + ((uint8_t*)dest)[i] = ((const uint8_t*)item)[i]; } rb->head = (rb->head + 1) % rb->capacity; @@ -30,13 +28,13 @@ int32_t cring_push(struct CRingBuffer* rb, const void* item){ return 1; } -int32_t cring_pop(struct CRingBuffer* rb, void* out){ +int32_t cring_pop(CRingBuffer* rb, void* out) { if (!rb->full && (rb->head == rb->tail)) return 0; uint8_t* base = (uint8_t*)rb->buffer; void* src = base + (rb->tail * rb->element_size); - for (uint64_t i = 0; i < rb->element_size; ++i){ + for (uint64_t i = 0; i < rb->element_size; ++i) { ((uint8_t*)out)[i] = ((uint8_t*)src)[i]; } @@ -45,16 +43,15 @@ int32_t cring_pop(struct CRingBuffer* rb, void* out){ return 1; } -int32_t cring_is_empty(const struct CRingBuffer* rb){ +int32_t cring_is_empty(const CRingBuffer* rb) { return (!rb->full && (rb->head == rb->tail)); } -int32_t cring_is_full(const struct CRingBuffer* rb){ +int32_t cring_is_full(const CRingBuffer* rb) { return rb->full; } -void cring_clear(struct CRingBuffer* rb){ - rb->head = 0; - rb->tail = 0; +void cring_clear(CRingBuffer* rb) { + rb->head = rb->tail = 0; rb->full = 0; } diff --git a/shared/data_struct/ring_buffer.h b/shared/data_struct/ring_buffer.h new file mode 100644 index 00000000..958b9da5 --- /dev/null +++ b/shared/data_struct/ring_buffer.h @@ -0,0 +1,27 @@ +#pragma once +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct CRingBuffer { + void* buffer; + uint64_t capacity; + uint64_t element_size; + uint64_t head; + uint64_t tail; + int32_t full; +} CRingBuffer; + +void cring_init(CRingBuffer* rb, void* storage, uint64_t capacity, uint64_t elem_size); +int32_t cring_push(CRingBuffer* rb, const void* item); +int32_t cring_pop(CRingBuffer* rb, void* out); +int32_t cring_is_empty(const CRingBuffer* rb); +int32_t cring_is_full(const CRingBuffer* rb); +void cring_clear(CRingBuffer* rb); +uint64_t cring_capacity(const CRingBuffer* rb); + +#ifdef __cplusplus +} +#endif diff --git a/shared/data_struct/ring_buffer.hpp b/shared/data_struct/ring_buffer.hpp index e7e8c983..c798f23f 100644 --- a/shared/data_struct/ring_buffer.hpp +++ b/shared/data_struct/ring_buffer.hpp @@ -1,29 +1,8 @@ #pragma once #include "types.h" -extern "C" { -struct CRingBuffer { - void* buffer; - uint64_t capacity; //TODO: define size_t as the same size of os architecture - uint64_t element_size; - uint64_t head; - uint64_t tail; - int32_t full; -}; - -void cring_init(struct CRingBuffer* rb, void* storage, uint64_t capacity, uint64_t elem_size); -int32_t cring_push(struct CRingBuffer* rb, const void* item); -int32_t cring_pop(struct CRingBuffer* rb, void* out); -int32_t cring_is_empty(const struct CRingBuffer* rb); -int32_t cring_is_full(const struct CRingBuffer* rb); -void cring_clear(struct CRingBuffer* rb); -uint64_t cring_capacity(const struct CRingBuffer* rb); - -} - template -class RingBuffer{ - +class RingBuffer { private: T data[Capacity]; uint64_t head = 0; @@ -31,56 +10,57 @@ class RingBuffer{ int32_t full = 0; public: - int32_t push(const T& item){ + RingBuffer() : head(0), tail(0), full(0) {} + + int32_t push(const T& item) { if (full) return 0; - data[head] = item; head = (head + 1) % Capacity; full = (head == tail); return 1; } - int32_t pop(T& out){ + int32_t pop(T& out) { if (is_empty()) return 0; - out = data[tail]; - tail = (tail + 1)% Capacity; + tail = (tail + 1) % Capacity; full = 0; return 1; } - int32_t is_empty() const{ - return (!full && (head == tail)); + int32_t is_empty() const { + return (!full && head == tail); } - int32_t is_full() const{ + int32_t is_full() const { return full; } - void clear(){ + void clear() { head = tail = 0; full = 0; } - uint64_t size() const{ + uint64_t size() const { if (full) return Capacity; - if (head >= tail) return head - tail; - return Capacity + head - tail; } - const T& peek() const{ + static constexpr uint64_t capacity() { + return Capacity; + } + + const T& peek() const { return data[tail]; } - const T& at(uint32_t index) const{ + const T& at(uint32_t index) const { return data[(tail + index) % Capacity]; } - T& at(uint32_t index){ - return data[(tail + index)% Capacity]; + T& at(uint32_t index) { + return data[(tail + index) % Capacity]; } - - static constexpr uint64_t capacity(){ return Capacity; } }; + From 0d2d55f73d8fb89406a4586bb062c4134985740d Mon Sep 17 00:00:00 2001 From: CodeAnarchist Date: Sat, 26 Jul 2025 00:20:31 +0200 Subject: [PATCH 122/123] rem xhci types h --- kernel/input/xhci_types.h | 378 -------------------------------------- 1 file changed, 378 deletions(-) delete mode 100644 kernel/input/xhci_types.h diff --git a/kernel/input/xhci_types.h b/kernel/input/xhci_types.h deleted file mode 100644 index 34484fac..00000000 --- a/kernel/input/xhci_types.h +++ /dev/null @@ -1,378 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#include "types.h" - -#define TRB_TYPE_NORMAL 1 -#define TRB_TYPE_LINK 6 -#define TRB_TYPE_EVENT_DATA 3 -#define TRB_TYPE_ENABLE_SLOT 9 -#define TRB_TYPE_ADDRESS_DEV 11 -#define TRB_TYPE_CONFIG_EP 12 -#define TRB_TYPE_SETUP 2 -#define TRB_TYPE_STATUS 4 -#define TRB_TYPE_INPUT 8 - -#define MAX_TRB_AMOUNT 256 -#define MAX_ERST_AMOUNT 1 - -#define TRB_TYPE_MASK 0xFC00 -#define TRB_ENDPOINT_MASK 0xF0000 -#define TRB_SLOT_MASK 0xF000000 - -#define TRB_TYPE_TRANSFER 0x20 -#define TRB_TYPE_COMMAND_COMPLETION 0x21 -#define TRB_TYPE_PORT_STATUS_CHANGE 0x22 - -#define TRB_TYPE_SETUP_STAGE 0x2 -#define TRB_TYPE_DATA_STAGE 0x3 -#define TRB_TYPE_STATUS_STAGE 0x4 - -#define XHCI_USBSTS_HSE (1 << 2) -#define XHCI_USBSTS_CE (1 << 12) - -#define XHCI_IRQ 31 - -typedef struct { - uint64_t parameter; - uint32_t status; - uint32_t control; -}__attribute__((packed)) trb; - -typedef struct { - uint8_t caplength; - uint8_t reserved; - uint16_t hciversion; - uint32_t hcsparams1; - uint32_t hcsparams2; - uint32_t hcsparams3; - uint32_t hccparams1; - uint32_t dboff; - uint32_t rtsoff; - uint32_t hccparams2; -}__attribute__((packed)) xhci_cap_regs; - -typedef struct { - uint32_t usbcmd; - uint32_t usbsts; - uint32_t pagesize; - uint64_t reserved0; - uint32_t dnctrl; - uint64_t crcr; - uint32_t reserved1[4]; - uint64_t dcbaap; - uint32_t config; -}__attribute__((packed)) xhci_op_regs; - -typedef union { - struct { - uint32_t ccs : 1; - uint32_t ped : 1; - uint32_t rsvd0 : 1; - uint32_t oca : 1; - uint32_t pr : 1; - uint32_t pls : 4; - uint32_t pp : 1; - uint32_t port_speed : 4; - uint32_t pic : 2; - uint32_t lws : 1; - uint32_t csc : 1; - uint32_t pec : 1; - uint32_t wrc : 1; - uint32_t occ : 1; - uint32_t prc : 1; - uint32_t plc : 1; - uint32_t cec : 1; - uint32_t cas : 1; - uint32_t wce : 1; - uint32_t wde : 1; - uint32_t woe : 1; - uint32_t rsvd1 : 2; - uint32_t dr : 1; - uint32_t wpr : 1; - }; - uint32_t value; -} portstatuscontrol; - -typedef struct { - portstatuscontrol portsc; - uint32_t portpmsc; - uint32_t portli; - uint32_t rsvd; -}__attribute__((packed, aligned(4))) xhci_port_regs; - -typedef struct { - uint32_t iman; - uint32_t imod; - uint32_t erstsz; - uint32_t reserved; - uint64_t erstba; - uint64_t erdp; -}__attribute__((packed)) xhci_interrupter; - -typedef struct { - uint64_t mmio; - uint64_t mmio_size; - xhci_cap_regs* cap; - xhci_op_regs* op; - xhci_port_regs* ports; - uint64_t db_base; - uint64_t rt_base; - trb* cmd_ring; - uint32_t cmd_index; - uint32_t event_index; - bool command_cycle_bit; - bool event_cycle_bit; - trb* event_ring; - uint8_t* key_buffer; - xhci_interrupter* interrupter; - uint64_t* dcbaa; - uint16_t max_device_slots; - uint16_t max_ports; -} xhci_device; - -typedef struct { - uint64_t ring_base; - uint32_t ring_size; - uint32_t reserved; -}__attribute__((packed)) erst_entry; - -typedef struct { - uint32_t drop_flags; - uint32_t add_flags; - uint64_t reserved[3]; -}__attribute__((packed)) xhci_input_control_context; - -typedef union -{ - struct - { - uint32_t route_string: 20; - uint32_t speed: 4; - uint32_t rsvd : 1; - uint32_t mtt : 1; - uint32_t hub : 1; - uint32_t context_entries : 5; - }; - uint32_t value; -} slot_field0; - -typedef union -{ - struct - { - uint16_t max_exit_latency; - uint8_t root_hub_port_num; - uint8_t port_count; - }; - uint32_t value; -} slot_field1; - -typedef union -{ - struct - { - uint32_t parent_hub_slot_id : 8; - uint32_t parent_port_number : 8; - uint32_t think_time : 2; - uint32_t rsvd : 4; - uint32_t interrupt_target : 10; - }; - uint32_t value; -} slot_field2; - -typedef union -{ - struct - { - uint32_t device_address : 8; - uint32_t rsvd : 19; - uint32_t state : 5;//0 disabled, 1 default, 2 addressed, 3 configured - }; - uint32_t value; -} slot_field3; - -typedef union -{ - struct { - uint32_t endpoint_state : 3; - uint32_t rsvd0 : 5; - uint32_t mult : 2; - uint32_t max_primary_streams : 5; - uint32_t linear_stream_array : 1; - uint32_t interval : 8; - uint32_t max_esit_payload_hi : 8; - }; - uint32_t value; -} endpoint_field0; - -typedef union -{ - struct { - uint32_t rsvd1 : 1; - uint32_t error_count : 2; - uint32_t endpoint_type : 3; - uint32_t rsvd2 : 1; - uint32_t host_initiate_disable : 1; - uint32_t max_burst_size : 8; - uint32_t max_packet_size : 16; - }; - uint32_t value; -} endpoint_field1; - -typedef union { - struct { - uint64_t dcs : 1; - uint64_t rsvd0 : 3; - uint64_t ring_ptr : 60; - }; - uint64_t value; -} endpoint_field23; - -typedef union -{ - struct { - uint16_t average_trb_length; - uint16_t max_esit_payload_lo; - }; - uint32_t value; -} endpoint_field4; - -typedef struct { - slot_field0 slot_f0; - slot_field1 slot_f1; - slot_field2 slot_f2; - slot_field3 slot_f3; - uint32_t slot_rsvd[4]; - struct { - endpoint_field0 endpoint_f0; - endpoint_field1 endpoint_f1; - endpoint_field23 endpoint_f23; - endpoint_field4 endpoint_f4; - uint32_t ep_rsvd[3]; - } endpoints[31]; -} xhci_device_context; - -typedef struct { - xhci_input_control_context control_context; - xhci_device_context device_context; -} xhci_input_context; - -typedef struct __attribute__((packed)) { - uint8_t bmRequestType; - uint8_t bRequest; - uint16_t wValue; - uint16_t wIndex; - uint16_t wLength; -} usb_setup_packet; - -typedef struct __attribute__((packed)) { - uint8_t bLength; - uint8_t bDescriptorType; -} usb_descriptor_header ; - -typedef struct __attribute__((packed)) { - usb_descriptor_header header; - uint16_t bcdUSB; - uint8_t bDeviceClass; - uint8_t bDeviceSubClass; - uint8_t bDeviceProtocol; - uint8_t bMaxPacketSize0; - uint16_t idVendor; - uint16_t idProduct; - uint16_t bcdDevice; - uint8_t iManufacturer; - uint8_t iProduct; - uint8_t iSerialNumber; - uint8_t bNumConfigurations; -} usb_device_descriptor; - -typedef struct __attribute__((packed)) { - usb_descriptor_header header; - uint16_t wTotalLength; - uint8_t bNumInterfaces; - uint8_t bConfigurationValue; - uint8_t iConfiguration; - uint8_t bmAttributes; - uint8_t bMaxPower; - uint8_t data[255]; -} usb_configuration_descriptor; - -typedef struct __attribute__((packed)) { - usb_descriptor_header header; - uint8_t bInterfaceNumber; - uint8_t bAlternateSetting; - uint8_t bNumEndpoints; - uint8_t bInterfaceClass; - uint8_t bInterfaceSubClass; - uint8_t bInterfaceProtocol; - uint8_t iInterface; -} usb_interface_descriptor; - -typedef struct __attribute__((packed)) { - usb_descriptor_header header; - uint16_t bcdHID; - uint8_t bCountryCode; - uint8_t bNumDescriptors; - struct { - uint8_t bDescriptorType; - uint8_t wDescriptorLength; - }__attribute__((packed)) descriptors[1]; -//TODO: wDescriptorLength is supposed to be 16, but for some reason the descriptor from usb-kbd is 8. Will need to fix this once we do a real device -} usb_hid_descriptor; - -typedef struct __attribute__((packed)) { - usb_descriptor_header header; - uint8_t bEndpointAddress; - uint8_t bmAttributes; - uint8_t wMaxPacketSize; - uint8_t bInterval; -//TODO: wMaxPacketSize is supposed to be 16, but for some reason the descriptor from usb-kbd is 8. Will need to fix this once we do a real device -} usb_endpoint_descriptor; - -typedef struct __attribute__((packed)) { - usb_descriptor_header header; - uint16_t lang_ids[126]; -} usb_string_language_descriptor; - -typedef struct __attribute__((packed)){ - usb_descriptor_header header; - uint16_t unicode_string[126]; -} usb_string_descriptor; - -typedef enum { - NONE, - KEYBOARD, - MOUSE -} xhci_device_types; - -typedef struct { - uint8_t transfer_cycle_bit; - uint32_t transfer_index; - trb* transfer_ring; - uint32_t slot_id; - xhci_input_context* ctx; -} xhci_usb_device; - -typedef struct { - xhci_device_types type; - trb* endpoint_transfer_ring; - uint32_t endpoint_transfer_index; - uint8_t endpoint_transfer_cycle_bit; - uint8_t poll_packetSize; - uint8_t *input_buffer; - uint8_t poll_endpoint; - uint16_t report_length; - uint8_t *report_descriptor; - } xhci_usb_device_endpoint; - -#define USB_DEVICE_DESCRIPTOR 1 -#define USB_CONFIGURATION_DESCRIPTOR 2 -#define USB_STRING_DESCRIPTOR 3 - -#ifdef __cplusplus -} -#endif \ No newline at end of file From e1694b6042d27388cd9207a2f68808672baa3541 Mon Sep 17 00:00:00 2001 From: differrari Date: Fri, 25 Jul 2025 00:00:00 +0000 Subject: [PATCH 123/123] [VIRT] wait function in virt intialization --- kernel/async.c | 13 ++++++++----- kernel/virtio/virtio_pci.c | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/kernel/async.c b/kernel/async.c index 8fc6cb42..8b37a2bf 100644 --- a/kernel/async.c +++ b/kernel/async.c @@ -17,17 +17,20 @@ void delay(uint32_t ms) { } } +#define WAIT_COND (*reg & expected_value) == expected_value +#define WAIT_CHECK (match > 0) ^ condition + bool wait(uint32_t *reg, uint32_t expected_value, bool match, uint32_t timeout){ - bool condition; - do { + bool condition = WAIT_COND; + while (WAIT_CHECK) { if (timeout != 0){ timeout--; delay(1); } - condition = (*reg & expected_value) == expected_value; + condition = WAIT_COND; if (timeout == 0) - return (match > 0) ^ condition; - } while ((match > 0) ^ condition); + return WAIT_CHECK; + } return true; } \ No newline at end of file diff --git a/kernel/virtio/virtio_pci.c b/kernel/virtio/virtio_pci.c index db3e48ad..59a1138e 100644 --- a/kernel/virtio/virtio_pci.c +++ b/kernel/virtio/virtio_pci.c @@ -3,6 +3,7 @@ #include "memory/memory_access.h" #include "memory/page_allocator.h" #include "virtio_pci.h" +#include "async.h" #define VIRTIO_STATUS_RESET 0x0 #define VIRTIO_STATUS_ACKNOWLEDGE 0x1 @@ -95,7 +96,7 @@ bool virtio_init_device(virtio_device *dev) { struct virtio_pci_common_cfg* cfg = dev->common_cfg; cfg->device_status = 0; - while (cfg->device_status != 0);//TODO: OPT + if (!wait((uint32_t*)&cfg->device_status, 0, false, 2000)) return false; cfg->device_status |= VIRTIO_STATUS_ACKNOWLEDGE; cfg->device_status |= VIRTIO_STATUS_DRIVER;