From e0cd8f9c44808642b2f4ebb17202e1ec477db78a Mon Sep 17 00:00:00 2001 From: Lunaixsky Date: Sun, 15 Dec 2024 01:36:31 +0000 Subject: [PATCH] make irq specifier to be provided when assigining irq * general fix around. --- lunaix-os/arch/x86/hal/apic_timer.c | 2 +- lunaix-os/arch/x86/hal/mc146818a.c | 4 ++-- lunaix-os/arch/x86/hal/ps2kbd.c | 4 ++-- lunaix-os/hal/ahci/ahci_pci.c | 4 ++-- lunaix-os/hal/bus/pci.c | 9 ++++----- lunaix-os/hal/char/uart/16x50_isa.c | 4 ++-- lunaix-os/hal/char/uart/16x50_pci.c | 4 ++-- lunaix-os/hal/devtree/LBuild | 2 +- lunaix-os/hal/devtree/devtree.h | 8 +++++++- lunaix-os/hal/devtree/dt.c | 4 +++- lunaix-os/hal/irq.c | 8 +++----- lunaix-os/includes/hal/devtree.h | 10 +++++----- lunaix-os/includes/hal/irq.h | 15 +++++++-------- lunaix-os/includes/hal/pci.h | 5 ++--- lunaix-os/tests/units/device-tree/makefile | 2 +- 15 files changed, 44 insertions(+), 41 deletions(-) diff --git a/lunaix-os/arch/x86/hal/apic_timer.c b/lunaix-os/arch/x86/hal/apic_timer.c index 9a42e82..178928c 100644 --- a/lunaix-os/arch/x86/hal/apic_timer.c +++ b/lunaix-os/arch/x86/hal/apic_timer.c @@ -46,7 +46,7 @@ __apic_timer_calibrate(struct hwtimer_pot* pot, u32_t hertz) irq = irq_declare_direct(apic_timer_count_stop); irq_set_payload(irq, pot); - irq_assign(irq_get_default_domain(), irq); + irq_assign(irq_get_default_domain(), irq, NULL); // Setup a one-shot timer, we will use this to measure the bus speed. So we // can then calibrate apic timer to work at *nearly* accurate hz diff --git a/lunaix-os/arch/x86/hal/mc146818a.c b/lunaix-os/arch/x86/hal/mc146818a.c index d6d931d..fcb5d7f 100644 --- a/lunaix-os/arch/x86/hal/mc146818a.c +++ b/lunaix-os/arch/x86/hal/mc146818a.c @@ -184,10 +184,10 @@ __rtc_calibrate(struct hwrtc_potens* pot) state = (struct mc146818*)rtc_dev->underlay; - state->irq = irq_declare_line(__rtc_tick, PC_AT_IRQ_RTC, NULL); + state->irq = irq_declare_line(__rtc_tick, PC_AT_IRQ_RTC); irq_set_payload(state->irq, state); - irq_assign(irq_owning_domain(rtc_dev), state->irq); + irq_assign(irq_owning_domain(rtc_dev), state->irq, NULL); return 0; } diff --git a/lunaix-os/arch/x86/hal/ps2kbd.c b/lunaix-os/arch/x86/hal/ps2kbd.c index 4460291..1df42bd 100644 --- a/lunaix-os/arch/x86/hal/ps2kbd.c +++ b/lunaix-os/arch/x86/hal/ps2kbd.c @@ -311,8 +311,8 @@ ps2_kbd_create(struct device_def* devdef, morph_t* obj) * 所以,保险的方法是:在初始化后才去设置ioapic,这样一来我们就能有一个稳定的IRQ#1以放心使用。 */ - irq_t irq = irq_declare_line(intr_ps2_kbd_handler, PC_AT_IRQ_KBD, NULL); - irq_assign(irq_owning_domain(kbd_idev->dev_if), irq); + irq_t irq = irq_declare_line(intr_ps2_kbd_handler, PC_AT_IRQ_KBD); + irq_assign(irq_owning_domain(kbd_idev->dev_if), irq, NULL); return 0; diff --git a/lunaix-os/hal/ahci/ahci_pci.c b/lunaix-os/hal/ahci/ahci_pci.c index 6c4fdde..2bc0ad9 100644 --- a/lunaix-os/hal/ahci/ahci_pci.c +++ b/lunaix-os/hal/ahci/ahci_pci.c @@ -29,8 +29,8 @@ ahci_pci_create(struct device_def* def, morph_t* morphed) assert(pci_capability_msi(probe)); - irq = pci_declare_msi_irq(ahci_hba_isr, probe, NULL); - pci_assign_msi(probe, irq); + irq = pci_declare_msi_irq(ahci_hba_isr, probe); + pci_assign_msi(probe, irq, NULL); struct ahci_driver_param param = { .mmio_base = bar6->start, diff --git a/lunaix-os/hal/bus/pci.c b/lunaix-os/hal/bus/pci.c index 3e940e0..0543d0a 100644 --- a/lunaix-os/hal/bus/pci.c +++ b/lunaix-os/hal/bus/pci.c @@ -308,20 +308,19 @@ __pci_config_msi(struct pci_probe* probe, irq_t irq) } irq_t -pci_declare_msi_irq(irq_servant callback, - struct pci_probe* probe, void *irq_extra) +pci_declare_msi_irq(irq_servant callback, struct pci_probe* probe) { - return irq_declare_msg(callback, probe->loc, probe->loc, irq_extra); + return irq_declare_msg(callback, probe->loc, probe->loc); } int -pci_assign_msi(struct pci_probe* probe, irq_t irq) +pci_assign_msi(struct pci_probe* probe, irq_t irq, void* irq_spec) { int err = 0; assert(irq->type == IRQ_MESSAGE); - err = irq_assign(probe->irq_domain, irq); + err = irq_assign(probe->irq_domain, irq, irq_spec); if (err) { return err; } diff --git a/lunaix-os/hal/char/uart/16x50_isa.c b/lunaix-os/hal/char/uart/16x50_isa.c index 7c82367..152317a 100644 --- a/lunaix-os/hal/char/uart/16x50_isa.c +++ b/lunaix-os/hal/char/uart/16x50_isa.c @@ -44,8 +44,8 @@ isa16x50_create_once(struct device_def* def) * Since these irqs are overlapped, this particular setup is needed * to avoid double-bind */ - uart->irq = irq_declare_line(com_irq_handler, irq, NULL); - irq_assign(irq_owning_domain(sdev->dev), uart->irq); + uart->irq = irq_declare_line(com_irq_handler, irq); + irq_assign(irq_owning_domain(sdev->dev), uart->irq, NULL); *((volatile int*)irqs[i]) = 0; } diff --git a/lunaix-os/hal/char/uart/16x50_pci.c b/lunaix-os/hal/char/uart/16x50_pci.c index 43e5326..bba016f 100644 --- a/lunaix-os/hal/char/uart/16x50_pci.c +++ b/lunaix-os/hal/char/uart/16x50_pci.c @@ -92,9 +92,9 @@ pci16x50_pci_create(struct device_def* def, morph_t* obj) sdev = uart_create_serial(uart, &def->class, &pci_ports, "PCI"); - irq = pci_declare_msi_irq(uart_msi_irq_handler, probe, NULL); + irq = pci_declare_msi_irq(uart_msi_irq_handler, probe); irq_set_payload(irq, uart); - pci_assign_msi(probe, irq); + pci_assign_msi(probe, irq, NULL); INFO("base: 0x%x (%s), %s", bar->start, diff --git a/lunaix-os/hal/devtree/LBuild b/lunaix-os/hal/devtree/LBuild index 97f3109..000d52b 100644 --- a/lunaix-os/hal/devtree/LBuild +++ b/lunaix-os/hal/devtree/LBuild @@ -1,6 +1,6 @@ sources([ "dt_interrupt.c", "dt.c", - "dtm.c" + "dtm.c", "dtspec.c" ]) \ No newline at end of file diff --git a/lunaix-os/hal/devtree/devtree.h b/lunaix-os/hal/devtree/devtree.h index 1bfe891..66fe7dc 100644 --- a/lunaix-os/hal/devtree/devtree.h +++ b/lunaix-os/hal/devtree/devtree.h @@ -11,10 +11,16 @@ propeq(struct fdt_blob* fdt, fdt_loc_t loc, const char* key) return streq(fdt_prop_key(fdt, loc), key); } +static inline ptr_t +__prop_val_ptr(struct fdt_prop* prop) +{ + return __ptr(prop) + sizeof(struct fdt_prop); +} + static inline void __mkprop_ptr(fdt_loc_t loc, struct dtp_val* val) { - val->ptr_val = __ptr(loc.prop->val); + val->ptr_val = __prop_val_ptr(loc.prop); val->size = loc.prop->len; } diff --git a/lunaix-os/hal/devtree/dt.c b/lunaix-os/hal/devtree/dt.c index a426551..63286b1 100644 --- a/lunaix-os/hal/devtree/dt.c +++ b/lunaix-os/hal/devtree/dt.c @@ -121,7 +121,7 @@ fdt_find_prop(const struct fdt_blob* fdt, fdt_loc_t loc, } if (likely(val)) { - val->encoded = (dt_enc_t)loc.prop->val; + val->encoded = (dt_enc_t)__prop_val_ptr(loc.prop); val->size = loc.prop->len; } return true; @@ -152,6 +152,8 @@ fdt_memscan_begin(struct fdt_memscan* mscan, const struct fdt_blob* fdt) mscan->loc = loc; mscan->node_type = FDT_MEM_FREE; + + return true; } #define get_size(mscan, val) \ diff --git a/lunaix-os/hal/irq.c b/lunaix-os/hal/irq.c index 97bbb79..cee6767 100644 --- a/lunaix-os/hal/irq.c +++ b/lunaix-os/hal/irq.c @@ -84,8 +84,7 @@ __irq_create_msi(irq_t irq, ptr_t message) } irq_t -irq_declare(enum irq_type type, irq_servant callback, - ptr_t data, void* irq_extra) +irq_declare(enum irq_type type, irq_servant callback, ptr_t data) { irq_t irq; @@ -93,7 +92,6 @@ irq_declare(enum irq_type type, irq_servant callback, *irq = (struct irq_object) { .type = type, .serve = callback ?: __default_servant, - .irq_extra = irq_extra, .vector = IRQ_VECTOR_UNSET }; @@ -118,11 +116,11 @@ irq_revoke(irq_t irq) } int -irq_assign(struct irq_domain* domain, irq_t irq) +irq_assign(struct irq_domain* domain, irq_t irq, void* irq_spec) { int err = 0; if (domain->ops->map_irq) { - err = domain->ops->map_irq(domain, irq, irq->irq_extra); + err = domain->ops->map_irq(domain, irq, irq_spec); if (err) { return err; } diff --git a/lunaix-os/includes/hal/devtree.h b/lunaix-os/includes/hal/devtree.h index ae18e31..111617e 100644 --- a/lunaix-os/includes/hal/devtree.h +++ b/lunaix-os/includes/hal/devtree.h @@ -47,14 +47,14 @@ struct dtp_val { union { - union { - const char* str_val; - const char* str_lst; - }; ptr_t ptr_val; dt_enc_t encoded; union dtp_baseval* ref; + union { + const char* str_val; + const char* str_lst; + }; }; unsigned int size; }; @@ -670,7 +670,7 @@ static inline void dtpi_init_empty(struct dtpropi* dtpi) { *dtpi = (struct dtpropi) { - .prop = { 0, 0 }, + .prop = { {0}, 0 }, .loc = 0 }; } diff --git a/lunaix-os/includes/hal/irq.h b/lunaix-os/includes/hal/irq.h index fc01e94..41be4b0 100644 --- a/lunaix-os/includes/hal/irq.h +++ b/lunaix-os/includes/hal/irq.h @@ -70,7 +70,6 @@ struct irq_object void* payload; struct irq_domain* domain; - void* irq_extra; int ref; }; @@ -84,13 +83,13 @@ int irq_attach_domain(struct irq_domain* parent, struct irq_domain* child); irq_t -irq_declare(enum irq_type, irq_servant, ptr_t, void*); +irq_declare(enum irq_type, irq_servant, ptr_t); void irq_revoke(irq_t); int -irq_assign(struct irq_domain* domain, irq_t); +irq_assign(struct irq_domain* domain, irq_t, void*); irq_t irq_find(struct irq_domain* domain, int local_irq); @@ -141,17 +140,17 @@ irq_set_domain_object(struct irq_domain* domain, void* obj) #define irq_domain_obj(domain, type) ((type*)(domain)->object) static inline irq_t -irq_declare_line(irq_servant callback, int local_irq, void* irq_extra) +irq_declare_line(irq_servant callback, int local_irq) { - return irq_declare(IRQ_LINE, callback, (int)local_irq, irq_extra); + return irq_declare(IRQ_LINE, callback, (int)local_irq); } static inline irq_t irq_declare_msg(irq_servant callback, - ptr_t message, ptr_t sideband, void* irq_extra) + ptr_t message, ptr_t sideband) { irq_t irq; - irq = irq_declare(IRQ_MESSAGE, callback, message, irq_extra); + irq = irq_declare(IRQ_MESSAGE, callback, message); irq->msi->sideband = sideband; return irq; @@ -160,7 +159,7 @@ irq_declare_msg(irq_servant callback, static inline irq_t irq_declare_direct(irq_servant callback) { - return irq_declare(IRQ_DIRECT, callback, 0, NULL); + return irq_declare(IRQ_DIRECT, callback, 0); } static inline struct irq_domain* diff --git a/lunaix-os/includes/hal/pci.h b/lunaix-os/includes/hal/pci.h index 81853c4..22b3dd9 100644 --- a/lunaix-os/includes/hal/pci.h +++ b/lunaix-os/includes/hal/pci.h @@ -117,11 +117,10 @@ size_t pci_bar_sizing(struct pci_probe* probe, u32_t* bar_out, u32_t bar_num); irq_t -pci_declare_msi_irq(irq_servant callback, - struct pci_probe* probe, void *irq_extra); +pci_declare_msi_irq(irq_servant callback, struct pci_probe* probe); int -pci_assign_msi(struct pci_probe* probe, irq_t irq); +pci_assign_msi(struct pci_probe* probe, irq_t irq, void* irq_spec); /** * @brief Bind an abstract device instance to the pci device diff --git a/lunaix-os/tests/units/device-tree/makefile b/lunaix-os/tests/units/device-tree/makefile index c88c2f6..b008c5f 100644 --- a/lunaix-os/tests/units/device-tree/makefile +++ b/lunaix-os/tests/units/device-tree/makefile @@ -4,7 +4,7 @@ obj-dut := dut/dt_interrupt.o \ dut/changeling.o BIN_DEPS += load.%.o -CFLAGS += -DCONFIG_USE_DEVICETREE +CFLAGS += -DCONFIG_USE_DEVICETREE -Wp,-w .PRECIOUS: %.dtb %.dtb: %.dts -- 2.27.0