From: Lunaixsky Date: Tue, 8 Oct 2024 20:24:25 +0000 (+0100) Subject: Merge branch 'master' into isa/arm64 X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/commitdiff_plain/e9fda657d5cb6f6619605766618aa78edd97f6a9?hp=c50ef1526a29f29b65cf353a590ea36b9d2e963a Merge branch 'master' into isa/arm64 --- diff --git a/lunaix-os/arch/generic/includes/asm-generic/isrm.h b/lunaix-os/arch/generic/includes/asm-generic/isrm.h index 7e319b5..e8117bb 100644 --- a/lunaix-os/arch/generic/includes/asm-generic/isrm.h +++ b/lunaix-os/arch/generic/includes/asm-generic/isrm.h @@ -14,8 +14,19 @@ #include #include +#include + typedef void (*isr_cb)(const struct hart_state*); +typedef struct { + ptr_t msi_addr; + reg_t msi_data; + int mapped_iv; +} msi_vector_t; +#define msi_addr(msiv) ((msiv).msi_addr) +#define msi_data(msiv) ((msiv).msi_data) +#define msi_vect(msiv) ((msiv).mapped_iv) + void isrm_init(); @@ -44,21 +55,20 @@ int isrm_ivexalloc(isr_cb handler); /** - * @brief Bind a given irq and associated handler to an iv + * @brief Allocate an iv resource for MSI use * - * @param iv iv allocated by system + * @param iv */ -int -isrm_bindirq(int irq, isr_cb irq_handler); +msi_vector_t +isrm_msialloc(isr_cb handler); /** - * @brief Bind given iv with it's associated handler + * @brief Bind the iv according to given device tree node * - * @param iv - * @param handler + * @param node */ -void -isrm_bindiv(int iv, isr_cb handler); +int +isrm_bind_dtnode(struct dt_intr_node* node); /** * @brief Get the handler associated with the given iv @@ -75,9 +85,6 @@ isrm_get_payload(const struct hart_state*); void isrm_set_payload(int iv, ptr_t); -void -isrm_irq_attach(int irq, int iv, cpu_t dest, u32_t flags); - /** * @brief Notify end of interrupt event * diff --git a/lunaix-os/arch/x86/arch.c b/lunaix-os/arch/x86/arch.c index 533ded9..f29b598 100644 --- a/lunaix-os/arch/x86/arch.c +++ b/lunaix-os/arch/x86/arch.c @@ -1,9 +1,10 @@ #include -#include #include #include +#include + #include "asm/x86.h" #include "asm/hart.h" diff --git a/lunaix-os/arch/x86/exceptions/interrupts.c b/lunaix-os/arch/x86/exceptions/interrupts.c index 6a9ff81..ceb3853 100644 --- a/lunaix-os/arch/x86/exceptions/interrupts.c +++ b/lunaix-os/arch/x86/exceptions/interrupts.c @@ -1,13 +1,13 @@ #include #include "asm/x86.h" -#include - #include #include #include #include +#include + LOG_MODULE("INTR") static inline void diff --git a/lunaix-os/arch/x86/exceptions/intr_routines.c b/lunaix-os/arch/x86/exceptions/intr_routines.c index 8bc1ca5..5e18496 100644 --- a/lunaix-os/arch/x86/exceptions/intr_routines.c +++ b/lunaix-os/arch/x86/exceptions/intr_routines.c @@ -1,6 +1,5 @@ #include -#include #include #include #include @@ -10,6 +9,7 @@ #include +#include #include "asm/soc/apic.h" #include "asm/x86.h" diff --git a/lunaix-os/arch/x86/exceptions/isrm.c b/lunaix-os/arch/x86/exceptions/isrm.c index dea130c..a3c223d 100644 --- a/lunaix-os/arch/x86/exceptions/isrm.c +++ b/lunaix-os/arch/x86/exceptions/isrm.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include "asm/x86.h" #include "asm/soc/ioapic.h" @@ -165,6 +165,24 @@ isrm_notify_eos(cpu_t id) isrm_notify_eoi(id, LUNAIX_SCHED); } +msi_vector_t +isrm_msialloc(isr_cb handler) +{ + unsigned int iv = isrm_ivexalloc(handler); + + return (msi_vector_t){ + .msi_addr = 0xfee00000, + .msi_data = iv, + .mapped_iv = iv + }; +} + +int +isrm_bind_dtnode(struct dt_intr_node* node) +{ + fail("not supported"); +} + static void __intc_init() diff --git a/lunaix-os/arch/x86/hal/apic_timer.c b/lunaix-os/arch/x86/hal/apic_timer.c index eae4c3f..56cd410 100644 --- a/lunaix-os/arch/x86/hal/apic_timer.c +++ b/lunaix-os/arch/x86/hal/apic_timer.c @@ -3,10 +3,10 @@ #include #include -#include #include #include +#include #include "asm/soc/apic.h" LOG_MODULE("APIC_TIMER") diff --git a/lunaix-os/arch/x86/hal/mc146818a.c b/lunaix-os/arch/x86/hal/mc146818a.c index 879b4f5..9c788f9 100644 --- a/lunaix-os/arch/x86/hal/mc146818a.c +++ b/lunaix-os/arch/x86/hal/mc146818a.c @@ -10,7 +10,6 @@ * */ -#include #include #include #include @@ -19,6 +18,7 @@ #include +#include #include #define RTC_INDEX_PORT 0x70 diff --git a/lunaix-os/arch/x86/hal/pci.c b/lunaix-os/arch/x86/hal/pci.c index d871790..599abf7 100644 --- a/lunaix-os/arch/x86/hal/pci.c +++ b/lunaix-os/arch/x86/hal/pci.c @@ -19,15 +19,4 @@ pci_write_cspace(ptr_t base, int offset, pci_reg_t data) port_wrdword(PCI_CONFIG_DATA, data); } -#endif - -u16_t -pci_config_msi_data(int vector) { - return vector; -} - -ptr_t -pci_get_msi_base() { - return 0xFEE00000; -} - +#endif \ No newline at end of file diff --git a/lunaix-os/arch/x86/hal/ps2kbd.c b/lunaix-os/arch/x86/hal/ps2kbd.c index cd5518d..02e98d1 100644 --- a/lunaix-os/arch/x86/hal/ps2kbd.c +++ b/lunaix-os/arch/x86/hal/ps2kbd.c @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -12,6 +11,7 @@ #include #include "asm/x86_cpu.h" +#include #include #define PS2_PORT_ENC_DATA 0x60 diff --git a/lunaix-os/arch/x86/includes/asm/x86_isrm.h b/lunaix-os/arch/x86/includes/asm/x86_isrm.h new file mode 100644 index 0000000..a2bcacd --- /dev/null +++ b/lunaix-os/arch/x86/includes/asm/x86_isrm.h @@ -0,0 +1,27 @@ +#ifndef __LUNAIX_X86_ISRM_H +#define __LUNAIX_X86_ISRM_H + +#include + +/** + * @brief Bind a given irq and associated handler to an iv + * + * @param iv iv allocated by system + */ +int +isrm_bindirq(int irq, isr_cb irq_handler); + +/** + * @brief Bind given iv with it's associated handler + * + * @param iv + * @param handler + */ +void +isrm_bindiv(int iv, isr_cb handler); + +void +isrm_irq_attach(int irq, int iv, cpu_t dest, u32_t flags); + + +#endif /* __LUNAIX_X86_ISRM_H */ diff --git a/lunaix-os/hal/ahci/ahci_pci.c b/lunaix-os/hal/ahci/ahci_pci.c index 6c59cf8..7c9288f 100644 --- a/lunaix-os/hal/ahci/ahci_pci.c +++ b/lunaix-os/hal/ahci/ahci_pci.c @@ -9,6 +9,7 @@ ahci_pci_bind(struct device_def* def, struct device* dev) struct pci_device* ahci_dev; struct pci_base_addr* bar6; struct ahci_driver* ahci_drv; + msi_vector_t msiv; ahci_dev = PCI_DEVICE(dev); bar6 = pci_device_bar(ahci_dev, 5); @@ -19,21 +20,16 @@ ahci_pci_bind(struct device_def* def, struct device* dev) pci_cmd_set_mmio(&cmd); pci_cmd_set_msi(&cmd); pci_apply_command(ahci_dev, cmd); + + assert(pci_capability_msi(ahci_dev)); - int iv; - if (pci_capability_msi(ahci_dev)) { - iv = isrm_ivexalloc(ahci_hba_isr); - pci_setup_msi(ahci_dev, iv); - } - else { - iv = pci_intr_irq(ahci_dev); - iv = isrm_bindirq(iv, ahci_hba_isr); - } + msiv = isrm_msialloc(ahci_hba_isr); + pci_setup_msi(ahci_dev, msiv); struct ahci_driver_param param = { .mmio_base = bar6->start, .mmio_size = bar6->size, - .ahci_iv = iv, + .ahci_iv = msi_vect(msiv), }; ahci_drv = ahci_driver_init(¶m); diff --git a/lunaix-os/hal/bus/pci.c b/lunaix-os/hal/bus/pci.c index 6d26d09..6b13b94 100644 --- a/lunaix-os/hal/bus/pci.c +++ b/lunaix-os/hal/bus/pci.c @@ -210,12 +210,12 @@ pci_probe_bar_info(struct pci_device* device) } void -pci_setup_msi(struct pci_device* device, int vector) +pci_setup_msi(struct pci_device* device, msi_vector_t msiv) { // PCI LB Spec. (Rev 3) Section 6.8 & 6.8.1 - ptr_t msi_addr = pci_get_msi_base(); - u32_t msi_data = pci_config_msi_data(vector); + ptr_t msi_addr = msi_addr(msiv); + u32_t msi_data = msi_data(msiv); pci_reg_t reg1 = pci_read_cspace(device->cspace_base, device->msi_loc); pci_reg_t msg_ctl = reg1 >> 16; diff --git a/lunaix-os/hal/char/uart/16x50_isa.c b/lunaix-os/hal/char/uart/16x50_isa.c index 128803e..414dc33 100644 --- a/lunaix-os/hal/char/uart/16x50_isa.c +++ b/lunaix-os/hal/char/uart/16x50_isa.c @@ -1,8 +1,8 @@ #include -#include #include #include +#include #include "16x50.h" @@ -58,7 +58,7 @@ upiom_init(struct device_def* def) static struct device_def uart_pmio_def = { .class = DEVCLASS(DEVIF_SOC, DEVFN_CHAR, DEV_UART16550), - .name = "16550 UART (PIO)", + .name = "16550 UART (pmio, isa-bus)", .init = upiom_init }; EXPORT_DEVICE(uart16550_pmio, &uart_pmio_def, load_onboot); \ No newline at end of file diff --git a/lunaix-os/hal/char/uart/16x50_pci.c b/lunaix-os/hal/char/uart/16x50_pci.c index 1d8afd8..59aac6c 100644 --- a/lunaix-os/hal/char/uart/16x50_pci.c +++ b/lunaix-os/hal/char/uart/16x50_pci.c @@ -52,11 +52,11 @@ pci16650_check_compat(struct pci_device_def* def, static int pci16650_binder(struct device_def* def, struct device* dev) { - int irq; struct pci_base_addr* bar; struct pci_device* pcidev; struct uart16550* uart; struct serial_dev* sdev; + msi_vector_t msiv; pcidev = PCI_DEVICE(dev); @@ -71,14 +71,19 @@ pci16650_binder(struct device_def* def, struct device* dev) if (bar->size == 0) { continue; } - + if (!pci_bar_mmio_space(bar)) { +#ifdef CONFIG_PCI_PMIO pci_cmd_set_pmio(&cmd); pci_apply_command(pcidev, cmd); uart = uart16x50_pmio_create(bar->start); - } - else { +#else + WARN("plaform configured to not support pmio access.") + continue; +#endif + } else + { pci_cmd_set_mmio(&cmd); pci_apply_command(pcidev, cmd); @@ -90,23 +95,22 @@ pci16650_binder(struct device_def* def, struct device* dev) continue; } - if (pci_capability_msi(pcidev)) { - irq = isrm_ivexalloc(uart_msi_irq_handler); - isrm_set_payload(irq, __ptr(uart)); - pci_setup_msi(pcidev, irq); - } - else { - irq = pci_intr_irq(pcidev); - irq = isrm_bindirq(irq, uart_intx_irq_handler); + if (!pci_capability_msi(pcidev)) { + WARN("failed to fallback to legacy INTx: not supported."); + continue; } + msiv = isrm_msialloc(uart_msi_irq_handler); + isrm_set_payload(msi_vect(msiv), __ptr(uart)); + pci_setup_msi(pcidev, msiv); + INFO("base: 0x%x (%s), irq=%d (%s)", bar->start, pci_bar_mmio_space(bar) ? "mmio" : "pmio", - irq, + msi_vect(msiv), pci_capability_msi(pcidev) ? "msi" : "intx, re-routed"); - uart->iv = irq; + uart->iv = msi_vect(msiv); sdev = uart_create_serial(uart, &def->class, &pci_ports, "PCI"); pci_bind_instance(pcidev, sdev); diff --git a/lunaix-os/hal/char/uart/LConfig b/lunaix-os/hal/char/uart/LConfig index 4b59141..bbb019d 100644 --- a/lunaix-os/hal/char/uart/LConfig +++ b/lunaix-os/hal/char/uart/LConfig @@ -12,11 +12,11 @@ def uart_16x50(): type(bool) + default(True) + is_x86 = v(arch) in ["i386", "x86_64"] if not is_x86: set_value(False) - else: - default(is_x86) return is_x86 diff --git a/lunaix-os/includes/hal/pci.h b/lunaix-os/includes/hal/pci.h index d457a1e..95ed7fd 100644 --- a/lunaix-os/includes/hal/pci.h +++ b/lunaix-os/includes/hal/pci.h @@ -6,6 +6,8 @@ #include #include +#include + #define EXPORT_PCI_DEVICE(id, pci_devdef, stage) \ EXPORT_DEVICE(id, &(pci_devdef)->devdef, stage) @@ -170,7 +172,7 @@ void pci_probe_bar_info(struct pci_device* device); void -pci_setup_msi(struct pci_device* device, int vector); +pci_setup_msi(struct pci_device* device, msi_vector_t msiv); void pci_probe_msi_info(struct pci_device* device); @@ -263,11 +265,4 @@ pci_read_cspace(ptr_t base, int offset); void pci_write_cspace(ptr_t base, int offset, pci_reg_t data); -u16_t -pci_config_msi_data(int vector); - -ptr_t -pci_get_msi_base(); - - #endif /* __LUNAIX_PCI_H */ diff --git a/lunaix-os/kernel/exe/elf-generic/elfbfmt.c b/lunaix-os/kernel/exe/elf-generic/elfbfmt.c index 1dbfd45..575ff3f 100644 --- a/lunaix-os/kernel/exe/elf-generic/elfbfmt.c +++ b/lunaix-os/kernel/exe/elf-generic/elfbfmt.c @@ -24,6 +24,10 @@ elf_do_open(struct elf* elf, struct v_file* elf_file) return status; } + if (!elf_check_arch(elf)) { + return EINVAL; + } + if ((status = elf_read_phdr(elf)) < 0) { elf_close(elf); return status; diff --git a/lunaix-os/kernel/exe/elf-generic/ldelf.c b/lunaix-os/kernel/exe/elf-generic/ldelf.c index 124f916..1f76dad 100644 --- a/lunaix-os/kernel/exe/elf-generic/ldelf.c +++ b/lunaix-os/kernel/exe/elf-generic/ldelf.c @@ -66,11 +66,6 @@ load_executable(struct load_context* context, const struct v_file* exefile) goto done; } - if (!elf_check_arch(&elf)) { - errno = EINVAL; - goto done; - } - if (!(elf_check_exec(&elf, ET_EXEC) || elf_check_exec(&elf, ET_DYN))) { errno = ENOEXEC; goto done; diff --git a/lunaix-os/makefile b/lunaix-os/makefile index 12cc1f5..5b339d6 100644 --- a/lunaix-os/makefile +++ b/lunaix-os/makefile @@ -50,7 +50,7 @@ tool: .NOTPARALLEL: export KCMD=$(CMDLINE) export LBUILD ARCH MODE -all: $(kbuild_dir) tool kernel usr/build +all: $(kbuild_dir) tool kernel rootfs: usr/build $(call status,TASK,$(notdir $@))