[45] | 1 | /* |
---|
[82] | 2 | * hal_apic.h - APIC values (for LAPIC and IOAPIC) |
---|
| 3 | * |
---|
[45] | 4 | * Copyright (c) 2017 Maxime Villard |
---|
[82] | 5 | * |
---|
[45] | 6 | * This file is part of ALMOS-MKH. |
---|
| 7 | * |
---|
| 8 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 9 | * under the terms of the GNU General Public License as published by |
---|
| 10 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 11 | * |
---|
| 12 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 15 | * General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
[234] | 18 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
[45] | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 20 | */ |
---|
| 21 | |
---|
[86] | 22 | #ifndef x86_ASM |
---|
[482] | 23 | char hal_com_read( void ); |
---|
[154] | 24 | void hal_com_send(uint8_t chan, char c); |
---|
[482] | 25 | void hal_com_init_early( void ); |
---|
[152] | 26 | |
---|
[203] | 27 | void hal_ioapic_bind_irq(uint8_t irq, uint8_t vec, uint8_t dest); |
---|
| 28 | void hal_ioapic_enable_irq(uint8_t irq); |
---|
| 29 | void hal_ioapic_disable_irq(uint8_t irq); |
---|
[135] | 30 | |
---|
[203] | 31 | void hal_ioapic_disable_entry(uint8_t irq); |
---|
| 32 | void hal_ioapic_set_entry(uint8_t irq, uint8_t vec, uint8_t dest); |
---|
| 33 | |
---|
[482] | 34 | uint32_t hal_lapic_gid( void ); |
---|
| 35 | void cpu_lapic_init( void ); |
---|
| 36 | void hal_apic_init( void ); |
---|
[236] | 37 | |
---|
| 38 | int boot_cpuN(uint32_t gid, paddr_t pa); |
---|
| 39 | |
---|
[86] | 40 | #endif |
---|
[45] | 41 | |
---|
[135] | 42 | /* |
---|
| 43 | ******************************************************************************* |
---|
| 44 | * LAPIC |
---|
| 45 | ******************************************************************************* |
---|
| 46 | */ |
---|
| 47 | |
---|
[45] | 48 | #define LAPIC_ID 0x020 /* ID. RW */ |
---|
| 49 | # define LAPIC_ID_MASK 0xff000000 |
---|
| 50 | # define LAPIC_ID_SHIFT 24 |
---|
| 51 | |
---|
| 52 | #define LAPIC_VERS 0x030 /* Version. RO */ |
---|
| 53 | # define LAPIC_VERSION_MASK 0x000000ff |
---|
| 54 | # define LAPIC_VERSION_LVT_MASK 0x00ff0000 |
---|
| 55 | # define LAPIC_VERSION_LVT_SHIFT 16 |
---|
| 56 | # define LAPIC_VERSION_DIRECTED_EOI 0x01000000 |
---|
| 57 | # define LAPIC_VERSION_EXTAPIC_SPACE 0x80000000 |
---|
| 58 | |
---|
| 59 | #define LAPIC_TPR 0x080 /* Task Prio. RW */ |
---|
| 60 | # define LAPIC_TPR_MASK 0x000000ff |
---|
| 61 | # define LAPIC_TPR_INT_MASK 0x000000f0 |
---|
| 62 | # define LAPIC_TPR_SUB_MASK 0x0000000f |
---|
| 63 | |
---|
| 64 | #define LAPIC_APRI 0x090 /* Arbitration prio. RO */ |
---|
| 65 | # define LAPIC_APRI_MASK 0x000000ff |
---|
| 66 | |
---|
| 67 | #define LAPIC_PPRI 0x0a0 /* Processor prio. RO */ |
---|
| 68 | #define LAPIC_EOI 0x0b0 /* End Int. W */ |
---|
| 69 | #define LAPIC_RRR 0x0c0 /* Remote read. RO */ |
---|
| 70 | #define LAPIC_LDR 0x0d0 /* Logical dest. RW */ |
---|
| 71 | |
---|
| 72 | #define LAPIC_DFR 0x0e0 /* Dest. format. RW */ |
---|
| 73 | # define LAPIC_DFR_MASK 0xf0000000 |
---|
| 74 | # define LAPIC_DFR_FLAT 0xf0000000 |
---|
| 75 | # define LAPIC_DFR_CLUSTER 0x00000000 |
---|
| 76 | |
---|
| 77 | #define LAPIC_SVR 0x0f0 /* Spurious intvec. RW */ |
---|
| 78 | # define LAPIC_SVR_VECTOR_MASK 0x000000ff |
---|
| 79 | # define LAPIC_SVR_VEC_FIX 0x0000000f |
---|
| 80 | # define LAPIC_SVR_VEC_PROG 0x000000f0 |
---|
| 81 | # define LAPIC_SVR_ENABLE 0x00000100 |
---|
| 82 | # define LAPIC_SVR_FOCUS 0x00000200 |
---|
| 83 | # define LAPIC_SVR_FDIS 0x00000200 |
---|
| 84 | # define LAPIC_SVR_EOI_BC_DIS 0x00001000 |
---|
| 85 | |
---|
| 86 | #define LAPIC_ISR 0x100 /* In-Service Status RO */ |
---|
| 87 | #define LAPIC_TMR 0x180 /* Trigger Mode RO */ |
---|
| 88 | #define LAPIC_IRR 0x200 /* Interrupt Req RO */ |
---|
| 89 | #define LAPIC_ESR 0x280 /* Err status. RW */ |
---|
| 90 | |
---|
| 91 | #define LAPIC_LVT_CMCI 0x2f0 /* LVT CMCI RW */ |
---|
| 92 | |
---|
| 93 | #define LAPIC_ICRLO 0x300 /* Int. cmd. RW */ |
---|
| 94 | # define LAPIC_DLMODE_MASK 0x00000700 /* Delivery Mode */ |
---|
| 95 | # define LAPIC_DLMODE_FIXED 0x00000000 |
---|
| 96 | # define LAPIC_DLMODE_LOW 0x00000100 |
---|
| 97 | # define LAPIC_DLMODE_SMI 0x00000200 |
---|
| 98 | # define LAPIC_DLMODE_NMI 0x00000400 |
---|
| 99 | # define LAPIC_DLMODE_INIT 0x00000500 |
---|
| 100 | # define LAPIC_DLMODE_STARTUP 0x00000600 |
---|
| 101 | # define LAPIC_DLMODE_EXTINT 0x00000700 |
---|
| 102 | |
---|
| 103 | # define LAPIC_DSTMODE_PHYS 0x00000000 |
---|
| 104 | # define LAPIC_DSTMODE_LOG 0x00000800 |
---|
| 105 | |
---|
| 106 | # define LAPIC_DLSTAT_BUSY 0x00001000 |
---|
| 107 | # define LAPIC_DLSTAT_IDLE 0x00000000 |
---|
| 108 | |
---|
| 109 | # define LAPIC_LEVEL_MASK 0x00004000 |
---|
| 110 | # define LAPIC_LEVEL_ASSERT 0x00004000 |
---|
| 111 | # define LAPIC_LEVEL_DEASSERT 0x00000000 |
---|
| 112 | |
---|
| 113 | # define LAPIC_TRIGGER_MASK 0x00008000 |
---|
| 114 | # define LAPIC_TRIGGER_EDGE 0x00000000 |
---|
| 115 | # define LAPIC_TRIGGER_LEVEL 0x00008000 |
---|
| 116 | |
---|
| 117 | # define LAPIC_DEST_MASK 0x000c0000 |
---|
| 118 | # define LAPIC_DEST_DEFAULT 0x00000000 |
---|
| 119 | # define LAPIC_DEST_SELF 0x00040000 |
---|
| 120 | # define LAPIC_DEST_ALLINCL 0x00080000 |
---|
| 121 | # define LAPIC_DEST_ALLEXCL 0x000c0000 |
---|
| 122 | |
---|
| 123 | #define LAPIC_ICRHI 0x310 /* Int. cmd. RW */ |
---|
| 124 | |
---|
[82] | 125 | #define LAPIC_LVT_TMR 0x320 /* Loc.vec.(timer) RW */ |
---|
| 126 | # define LAPIC_TMR_VEC_MASK 0x000000ff |
---|
| 127 | # define LAPIC_TMR_DS 0x00001000 |
---|
| 128 | # define LAPIC_TMR_M 0x00010000 |
---|
| 129 | # define LAPIC_TMR_TM 0x00020000 |
---|
[45] | 130 | |
---|
[82] | 131 | #define LAPIC_LVT_THM 0x330 /* Loc.vec (Thermal) RW */ |
---|
| 132 | # define LAPIC_THM_MT_MASK 0x00000700 |
---|
| 133 | # define LAPIC_THM_MT_FIXED 0x00000000 |
---|
| 134 | # define LAPIC_THM_MT_SMI 0x00000200 |
---|
| 135 | # define LAPIC_THM_MT_NMI 0x00000400 |
---|
| 136 | # define LAPIC_THM_MT_INIT 0x00000500 |
---|
| 137 | # define LAPIC_THM_MT_EXTINT 0x00000700 |
---|
| 138 | # define LAPIC_THM_DS 0x00001000 |
---|
| 139 | # define LAPIC_THM_M 0x00010000 |
---|
[45] | 140 | |
---|
[82] | 141 | #define LAPIC_LVT_PMC 0x340 /* Loc.vec (Perf Mon) RW */ |
---|
| 142 | # define LAPIC_PMC_MT_MASK 0x00000700 |
---|
| 143 | # define LAPIC_PMC_MT_FIXED 0x00000000 |
---|
| 144 | # define LAPIC_PMC_MT_SMI 0x00000200 |
---|
| 145 | # define LAPIC_PMC_MT_NMI 0x00000400 |
---|
| 146 | # define LAPIC_PMC_MT_INIT 0x00000500 |
---|
| 147 | # define LAPIC_PMC_MT_EXTINT 0x00000700 |
---|
| 148 | # define LAPIC_PMC_DS 0x00001000 |
---|
| 149 | # define LAPIC_PMC_M 0x00010000 |
---|
| 150 | |
---|
| 151 | #define LAPIC_LVT_LINT0 0x350 /* Loc.vec (LINT0) RW */ |
---|
| 152 | #define LAPIC_LVT_LINT1 0x360 /* Loc.vec (LINT1) RW */ |
---|
| 153 | # define LAPIC_LINT_MT_MASK 0x00000700 |
---|
| 154 | # define LAPIC_LINT_MT_FIXED 0x00000000 |
---|
| 155 | # define LAPIC_LINT_MT_SMI 0x00000200 |
---|
| 156 | # define LAPIC_LINT_MT_NMI 0x00000400 |
---|
| 157 | # define LAPIC_LINT_MT_INIT 0x00000500 |
---|
| 158 | # define LAPIC_LINT_MT_EXTINT 0x00000700 |
---|
| 159 | # define LAPIC_LINT_DS 0x00001000 |
---|
| 160 | # define LAPIC_LINT_RIR 0x00004000 |
---|
| 161 | # define LAPIC_LINT_TGM 0x00008000 |
---|
| 162 | # define LAPIC_LINT_M 0x00010000 |
---|
| 163 | |
---|
| 164 | #define LAPIC_LVT_ERR 0x370 /* Loc.vec (ERROR) RW */ |
---|
| 165 | # define LAPIC_ERR_MT_MASK 0x00000700 |
---|
| 166 | # define LAPIC_ERR_MT_FIXED 0x00000000 |
---|
| 167 | # define LAPIC_ERR_MT_SMI 0x00000200 |
---|
| 168 | # define LAPIC_ERR_MT_NMI 0x00000400 |
---|
| 169 | # define LAPIC_ERR_MT_INIT 0x00000500 |
---|
| 170 | # define LAPIC_ERR_MT_EXTINT 0x00000700 |
---|
| 171 | # define LAPIC_ERR_DS 0x00001000 |
---|
| 172 | # define LAPIC_ERR_M 0x00010000 |
---|
| 173 | |
---|
[45] | 174 | #define LAPIC_ICR_TIMER 0x380 /* Initial count RW */ |
---|
| 175 | #define LAPIC_CCR_TIMER 0x390 /* Current count RO */ |
---|
| 176 | |
---|
| 177 | #define LAPIC_DCR_TIMER 0x3e0 /* Divisor config RW */ |
---|
| 178 | # define LAPIC_DCRT_DIV1 0x0b |
---|
| 179 | # define LAPIC_DCRT_DIV2 0x00 |
---|
| 180 | # define LAPIC_DCRT_DIV4 0x01 |
---|
| 181 | # define LAPIC_DCRT_DIV8 0x02 |
---|
| 182 | # define LAPIC_DCRT_DIV16 0x03 |
---|
| 183 | # define LAPIC_DCRT_DIV32 0x08 |
---|
| 184 | # define LAPIC_DCRT_DIV64 0x09 |
---|
| 185 | # define LAPIC_DCRT_DIV128 0x0a |
---|
| 186 | |
---|
[202] | 187 | /* |
---|
| 188 | ******************************************************************************* |
---|
| 189 | * IRQ numbers |
---|
| 190 | ******************************************************************************* |
---|
| 191 | */ |
---|
| 192 | |
---|
| 193 | #define IRQ_TIMER 0 |
---|
| 194 | #define IRQ_KEYBOARD 1 |
---|
| 195 | #define IRQ_COM2 3 |
---|
| 196 | #define IRQ_COM1 4 |
---|
| 197 | #define IRQ_FLOPPY 6 |
---|
| 198 | #define IRQ_ATA0 14 |
---|
| 199 | #define IRQ_ATA1 15 |
---|
| 200 | |
---|