commit 445e576f33ebe6b1b89a221691935eb6c6374001
parent 44eeb7383c50634972ec5998b702256830fff02b
Author: Brian Swetland <swetland@frotz.net>
Date: Thu, 2 Jan 2014 20:13:17 -0800
macro-ize access to device address space
Provide IO2V(phys) which works like P2V(phys) for the FE000000..FFFFFFFF
device io space, which is 1:1 mapped in 32bit, but mapped up near the
top of virtual memory in 64bit.
Update ioapic and lapic code to use this macro instead of assuming
the physical and virtual addresses are identical.
Diffstat:
4 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/include/memlayout.h b/include/memlayout.h
@@ -7,8 +7,10 @@
// Key addresses for address space layout (see kmap in vm.c for layout)
#if X64
#define KERNBASE 0xFFFFFFFF80000000 // First kernel virtual address
+#define DEVBASE 0xFFFFFFFF40000000 // First device virtual address
#else
#define KERNBASE 0x80000000 // First kernel virtual address
+#define DEVBASE 0xFE000000 // First device virtual address
#endif
#define KERNLINK (KERNBASE+EXTMEM) // Address where kernel is linked
@@ -21,6 +23,7 @@ static inline void *p2v(uintp a) { return (void *) ((a) + ((uintp)KERNBASE)); }
#define V2P(a) (((uintp) (a)) - KERNBASE)
#define P2V(a) (((void *) (a)) + KERNBASE)
+#define IO2V(a) (((void *) (a)) + DEVBASE - DEVSPACE)
#define V2P_WO(x) ((x) - KERNBASE) // same as V2P, but without casts
#define P2V_WO(x) ((x) + KERNBASE) // same as V2P, but without casts
diff --git a/kernel/ioapic.c b/kernel/ioapic.c
@@ -5,6 +5,7 @@
#include "types.h"
#include "defs.h"
#include "traps.h"
+#include "memlayout.h"
#define IOAPIC 0xFEC00000 // Default physical address of IO APIC
@@ -53,7 +54,7 @@ ioapicinit(void)
if(!ismp)
return;
- ioapic = (volatile struct ioapic*)IOAPIC;
+ ioapic = (volatile struct ioapic*) IO2V(IOAPIC);
maxintr = (ioapicread(REG_VER) >> 16) & 0xFF;
id = ioapicread(REG_ID) >> 24;
if(id != ioapicid)
diff --git a/kernel/mp.c b/kernel/mp.c
@@ -109,7 +109,7 @@ mpinit(void)
if((conf = mpconfig(&mp)) == 0)
return;
ismp = 1;
- lapic = (uint*)conf->lapicaddr;
+ lapic = IO2V((uintp)conf->lapicaddr);
for(p=(uchar*)(conf+1), e=(uchar*)conf+conf->length; p<e; ){
switch(*p){
case MPPROC:
diff --git a/kernel/vm.c b/kernel/vm.c
@@ -121,7 +121,7 @@ static struct kmap {
{ (void*)KERNBASE, 0, EXTMEM, PTE_W}, // I/O space
{ (void*)KERNLINK, V2P(KERNLINK), V2P(data), 0}, // kern text+rodata
{ (void*)data, V2P(data), PHYSTOP, PTE_W}, // kern data+memory
- { (void*)DEVSPACE, DEVSPACE, 0, PTE_W}, // more devices
+ { (void*)DEVBASE, DEVSPACE, 0, PTE_W}, // more devices
};
// Set up kernel part of a page table.