Ignore:
Timestamp:
Jun 28, 2017, 1:23:51 PM (5 years ago)
Author:
max@…
Message:

Rename a certain number of things, and improve the APIC support.

File:
1 moved

Legend:

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

    r81 r82  
    11/*
    2  * hal_lapic.c - Local APIC
     2 * hal_apic.c - Advanced Programmable Interrupt Controller
    33 *
    44 * Copyright (c) 2017 Maxime Villard
     
    2121
    2222#include <hal_types.h>
     23#include <hal_register.h>
    2324#include <hal_segmentation.h>
    24 #include <hal_lapic.h>
     25#include <hal_apic.h>
    2526#include <hal_internal.h>
    2627
     
    3435#include <cluster.h>
    3536
     37/* -------------------------------------------------------------------------- */
     38
     39#define PIC1_CMD        0x0020
     40#define PIC1_DATA       0x0021
     41#define PIC2_CMD        0x00a0
     42#define PIC2_DATA       0x00a1
     43
     44static void hal_pic_init()
     45{
     46        /*
     47         * Disable the PIC (8259A). We are going to use IOAPIC instead.
     48         */
     49        out8(PIC1_DATA, 0xff);
     50        out8(PIC2_DATA, 0xff);
     51}
     52
     53/* -------------------------------------------------------------------------- */
     54
    3655paddr_t lapic_pa __in_kdata = 0;
    3756vaddr_t lapic_va __in_kdata = 0;
     
    3958void hal_lapic_write(uint32_t reg, uint32_t val)
    4059{
    41         *((volatile uint32_t *)(lapic_va + reg)) = val;
     60        *((volatile uint32_t *)((uint8_t *)lapic_va + reg)) = val;
    4261}
    4362
    4463uint32_t hal_lapic_read(uint32_t reg)
    4564{
    46         return *((volatile uint32_t *)(lapic_va + reg));
     65        return *((volatile uint32_t *)((uint8_t *)lapic_va + reg));
    4766}
    4867
     
    5271}
    5372
    54 void hal_lapic_init()
     73/*
     74 * We have 8 interrupt sources:
     75 *  - Spurious
     76 *  - APIC Timer (TMR)
     77 *  - Local Interrupt 0 (LINT0)
     78 *  - Local Interrupt 1 (LINT1)
     79 *  - Performance Monitor Counters (PMC)
     80 *  - Thermal Sensors (THM)
     81 *  - APIC internal error (ERR)
     82 *  - Extended (Implementation dependent)
     83 */
     84static void hal_lapic_init()
    5585{
    5686        lapic_va = hal_gpt_bootstrap_valloc(1); // XXX: should be shared
     87
     88        if ((rdmsr(MSR_APICBASE) & APICBASE_PHYSADDR) != lapic_pa) {
     89                x86_panic("APICBASE and ACPI don't match!\n");
     90        }
     91        wrmsr(MSR_APICBASE, lapic_pa | APICBASE_EN);
    5792
    5893        hal_gpt_enter(lapic_va, lapic_pa);
    5994
    6095        hal_lapic_write(LAPIC_TPR, 0);
     96        hal_lapic_write(LAPIC_EOI, 0);
    6197        hal_lapic_write(LAPIC_SVR, LAPIC_SVR_ENABLE|LAPIC_SPURIOUS_VECTOR);
     98
     99        /* Explicitly disable (mask) each vector */
     100        hal_lapic_write(LAPIC_LVT_TMR, LAPIC_TMR_M);
     101        hal_lapic_write(LAPIC_LVT_LINT0, LAPIC_LINT_M);
     102        hal_lapic_write(LAPIC_LVT_LINT1, LAPIC_LINT_M);
     103        hal_lapic_write(LAPIC_LVT_PMC, LAPIC_PMC_M);
     104        hal_lapic_write(LAPIC_LVT_THM, LAPIC_THM_M);
     105        hal_lapic_write(LAPIC_LVT_ERR, LAPIC_ERR_M);
    62106}
    63107
     108/* -------------------------------------------------------------------------- */
     109
     110void hal_apic_init()
     111{
     112        /* Disable the PIC */
     113        hal_pic_init();
     114
     115        /* Enable the LAPIC */
     116        hal_lapic_init();
     117}
     118
Note: See TracChangeset for help on using the changeset viewer.