Changeset 89 for trunk/hal/x86_64/core


Ignore:
Timestamp:
Jun 29, 2017, 9:54:01 AM (7 years ago)
Author:
max@…
Message:

Parse the IOAPIC structure in ACPI, map the IOAPIC, and enable
the keyboard interrupt. Its queue is not flushed yet.

Location:
trunk/hal/x86_64/core
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/x86_64/core/hal_acpi.c

    r51 r89  
    109109/* -------------------------------------------------------------------------- */
    110110
     111static void hal_acpi_parse_ioapic(madt_ioapic_t *ioapic)
     112{
     113        extern paddr_t ioapic_pa;
     114        ioapic_pa = ioapic->Address;
     115        x86_printf("-> IOAPIC address: %Z\n", ioapic_pa);
     116}
     117
    111118static void hal_acpi_parse_madt(madt_t *madt)
    112119{
     120        void *ptr, *end;
     121        subheader_t *sub;
     122
    113123        extern paddr_t lapic_pa;
    114124        lapic_pa = (paddr_t)madt->Address;
     125
     126        ptr = (void *)(madt + 1);
     127        end = (void *)madt + madt->Header.Length;
     128
     129        while (ptr < end) {
     130                sub = (subheader_t *)ptr;
     131                if (sub->Type == ACPI_MADT_TYPE_IO_APIC) {
     132                        hal_acpi_parse_ioapic((madt_ioapic_t *)sub);
     133                }
     134                // XXX: handle lapic override
     135                ptr += sub->Length;
     136        }
     137
    115138        x86_printf("-> LAPIC address: %Z\n", lapic_pa);
    116139}
  • trunk/hal/x86_64/core/hal_acpi.h

    r51 r89  
    179179        uint64_t Address;  /* APIC physical address */
    180180} __packed;
    181 typedef struct acpi_madt_local_apic_override madt_lapic_override;
     181typedef struct acpi_madt_local_apic_override madt_lapic_override_t;
    182182
     183struct acpi_madt_io_apic {
     184        subheader_t Header;
     185        uint8_t Id;             /* I/O APIC ID */
     186        uint8_t Reserved;       /* Reserved - must be zero */
     187        uint32_t Address;       /* APIC physical address */
     188        uint32_t GlobalIrqBase; /* Global system interrupt where INTI lines start */
     189} __packed;
     190typedef struct acpi_madt_io_apic madt_ioapic_t;
     191
  • trunk/hal/x86_64/core/hal_apic.c

    r86 r89  
    5050        out8(PIC1_DATA, 0xff);
    5151        out8(PIC2_DATA, 0xff);
     52}
     53
     54/* -------------------------------------------------------------------------- */
     55
     56paddr_t ioapic_pa __in_kdata = 0;
     57vaddr_t ioapic_va __in_kdata = 0;
     58
     59#define IRQ_TIMER       0x00
     60#define IRQ_KEYBOARD    0x01
     61#define IRQ_COM2        0x03
     62#define IRQ_COM1        0x04
     63#define IRQ_FLOPPY      0x06
     64#define IRQ_ATA0        0x0e
     65#define IRQ_ATA1        0x0f
     66
     67#define IOREGSEL        0x00
     68#define IOWIN   0x10
     69
     70#define IOAPICID        0x00
     71#define IOAPICVER       0x01
     72#define IOAPICARB       0x02
     73#define IOREDTBL        0x10
     74
     75#define IOENTRY_DISABLE 0x10000
     76
     77void hal_ioapic_write(uint8_t reg, uint32_t val)
     78{
     79        *((volatile uint32_t *)((uint8_t *)ioapic_va + IOREGSEL)) = reg;
     80        *((volatile uint32_t *)((uint8_t *)ioapic_va + IOWIN)) = val;
     81}
     82
     83uint32_t hal_ioapic_read(uint8_t reg)
     84{
     85        *((volatile uint32_t *)((uint8_t *)ioapic_va + IOREGSEL)) = reg;
     86        return *((volatile uint32_t *)((uint8_t *)ioapic_va + IOWIN));
     87}
     88
     89void hal_ioapic_set_entry(uint8_t index, uint64_t data)
     90{
     91        hal_ioapic_write(IOREDTBL + index * 2, (uint32_t)(data & 0xFFFFFFFF));
     92        hal_ioapic_write(IOREDTBL + index * 2 + 1, (uint32_t)(data >> 32));
     93}
     94
     95static void hal_ioapic_init()
     96{
     97        size_t i, pins;
     98        uint32_t ver;
     99
     100        ioapic_va = hal_gpt_bootstrap_valloc(1); // XXX: should be shared
     101
     102        hal_gpt_enter(ioapic_va, ioapic_pa, PG_V|PG_KW|PG_NX|PG_N);
     103
     104        ver = hal_ioapic_read(IOAPICVER);
     105        pins = ((ver >> 16) & 0xFF) + 1;
     106
     107        /* Explicitly disable (mask) each vector */
     108        for (i = 0; i < pins; i++) {
     109                hal_ioapic_set_entry(i, IOENTRY_DISABLE);
     110        }
     111
     112        /* Now, enable the keyboard */
     113        hal_ioapic_set_entry(IRQ_KEYBOARD, IOAPIC_KEYBOARD_VECTOR);
    52114}
    53115
     
    122184        /* Enable the LAPIC */
    123185        hal_lapic_init();
     186
     187        /* Enable the IOAPIC */
     188        hal_ioapic_init();
    124189}
    125190
  • trunk/hal/x86_64/core/hal_apic.h

    r86 r89  
    2727#define LAPIC_SPURIOUS_VECTOR   LAPICVEC_MIN
    2828#define LAPIC_TIMER_VECTOR      (LAPICVEC_MIN + 1)
     29#define IOAPIC_KEYBOARD_VECTOR  (LAPICVEC_MIN + 2)
    2930
    3031#define LAPIC_ID                0x020   /* ID. RW */
  • trunk/hal/x86_64/core/hal_kentry.S

    r86 r89  
    3636        .globl  hal_trap_entry
    3737        .globl  hal_timer_intr
     38        .globl  hal_keyboard_intr
    3839        .type   hal_trap_entry, @function
    3940        .type   hal_timer_intr, @function
     41        .type   hal_keyboard_intr, @function
    4042
    4143        /*
     
    119121
    120122        /*
    121          * LAPIC interrupts.
     123         * APIC interrupts.
    122124         */
    123125ASM_ENTRY(x86_lapic_spurious)
     
    131133        movq    %rsp,%rdi
    132134        call    hal_timer_intr
     135
     136        movq    lapic_va(%rip),%rax
     137        movl    $0,LAPIC_EOI(%rax)
     138
     139        INTR_RESTORE_REGS
     140        addq    $16,%rsp
     141        iretq
     142
     143ASM_ENTRY(x86_ioapic_keyboard)
     144        pushq   $0
     145        pushq   $T_ASTFLT
     146        INTR_SAVE_REGS
     147
     148        movq    %rsp,%rdi
     149        call    hal_keyboard_intr
    133150
    134151        movq    lapic_va(%rip),%rax
     
    182199        .quad   x86_lapic_spurious
    183200        .quad   x86_lapic_timer
    184 
     201        .quad   x86_ioapic_keyboard
     202
  • trunk/hal/x86_64/core/hal_segmentation.h

    r80 r89  
    194194#define CPUVEC_MAX      32      /* reserved entries for CPU exceptions */
    195195#define LAPICVEC_MIN    CPUVEC_MAX
    196 #define LAPICVEC_MAX    (LAPICVEC_MIN + 2)
     196#define LAPICVEC_MAX    (LAPICVEC_MIN + 3)
    197197
    198198#define NIDT    256     /* total number of IDT entries */
  • trunk/hal/x86_64/core/hal_trap.c

    r86 r89  
    8282}
    8383
     84/*
     85 * Keyboard interrupt
     86 */
     87void hal_keyboard_intr(struct trapframe *tf)
     88{
     89        x86_printf("-> got keyboard: rip=%Z\n", tf->tf_rip);
     90        return;
     91}
     92
Note: See TracChangeset for help on using the changeset viewer.