Skip to content

Commit 445e576

Browse files
committed
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.
1 parent 44eeb73 commit 445e576

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

include/memlayout.h

+3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
// Key addresses for address space layout (see kmap in vm.c for layout)
88
#if X64
99
#define KERNBASE 0xFFFFFFFF80000000 // First kernel virtual address
10+
#define DEVBASE 0xFFFFFFFF40000000 // First device virtual address
1011
#else
1112
#define KERNBASE 0x80000000 // First kernel virtual address
13+
#define DEVBASE 0xFE000000 // First device virtual address
1214
#endif
1315
#define KERNLINK (KERNBASE+EXTMEM) // Address where kernel is linked
1416

@@ -21,6 +23,7 @@ static inline void *p2v(uintp a) { return (void *) ((a) + ((uintp)KERNBASE)); }
2123

2224
#define V2P(a) (((uintp) (a)) - KERNBASE)
2325
#define P2V(a) (((void *) (a)) + KERNBASE)
26+
#define IO2V(a) (((void *) (a)) + DEVBASE - DEVSPACE)
2427

2528
#define V2P_WO(x) ((x) - KERNBASE) // same as V2P, but without casts
2629
#define P2V_WO(x) ((x) + KERNBASE) // same as V2P, but without casts

kernel/ioapic.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "types.h"
66
#include "defs.h"
77
#include "traps.h"
8+
#include "memlayout.h"
89

910
#define IOAPIC 0xFEC00000 // Default physical address of IO APIC
1011

@@ -53,7 +54,7 @@ ioapicinit(void)
5354
if(!ismp)
5455
return;
5556

56-
ioapic = (volatile struct ioapic*)IOAPIC;
57+
ioapic = (volatile struct ioapic*) IO2V(IOAPIC);
5758
maxintr = (ioapicread(REG_VER) >> 16) & 0xFF;
5859
id = ioapicread(REG_ID) >> 24;
5960
if(id != ioapicid)

kernel/mp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ mpinit(void)
109109
if((conf = mpconfig(&mp)) == 0)
110110
return;
111111
ismp = 1;
112-
lapic = (uint*)conf->lapicaddr;
112+
lapic = IO2V((uintp)conf->lapicaddr);
113113
for(p=(uchar*)(conf+1), e=(uchar*)conf+conf->length; p<e; ){
114114
switch(*p){
115115
case MPPROC:

kernel/vm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static struct kmap {
121121
{ (void*)KERNBASE, 0, EXTMEM, PTE_W}, // I/O space
122122
{ (void*)KERNLINK, V2P(KERNLINK), V2P(data), 0}, // kern text+rodata
123123
{ (void*)data, V2P(data), PHYSTOP, PTE_W}, // kern data+memory
124-
{ (void*)DEVSPACE, DEVSPACE, 0, PTE_W}, // more devices
124+
{ (void*)DEVBASE, DEVSPACE, 0, PTE_W}, // more devices
125125
};
126126

127127
// Set up kernel part of a page table.

0 commit comments

Comments
 (0)