aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHoward Mao <zhehao.mao@gmail.com>2015-12-06 15:32:00 -0800
committerHoward Mao <zhehao.mao@gmail.com>2015-12-06 15:32:00 -0800
commit864210aa88db999d49b7bfec3d3c03bda18864a8 (patch)
treec9dcc09d88435db4f01baf5619467d6a0b5c37fa
parentdd7fc844c4059a18ffaeeb3a9573a8d27d30923b (diff)
downloadpk-device-files.zip
pk-device-files.tar.gz
pk-device-files.tar.bz2
cache device type strings in memorydevice-files
-rw-r--r--pk/devicetree.c14
-rw-r--r--pk/devicetree.h6
-rw-r--r--pk/pk.h2
-rw-r--r--pk/vm.c1
4 files changed, 10 insertions, 13 deletions
diff --git a/pk/devicetree.c b/pk/devicetree.c
index 797f937..10e1ca4 100644
--- a/pk/devicetree.c
+++ b/pk/devicetree.c
@@ -11,9 +11,6 @@
struct fdt_table_entry fdt_table[FDT_TABLE_CAP];
int fdt_table_size = 0;
-uintptr_t fdt_base;
-size_t fdt_size;
-
static uintptr_t max_hart_id;
static uint64_t fdt_read_uint64(uint32_t* addr) {
@@ -50,19 +47,21 @@ static void fdt_handle_device(const char *dev_type,
uint32_t *reg_addr, uint32_t reg_len, int prot)
{
struct fdt_table_entry *entry;
+ int dev_type_len = strlen(dev_type);
kassert(reg_len == 16);
+ kassert(dev_type_len < FDT_DEV_NAME_SIZE);
kassert(fdt_table_size < FDT_TABLE_CAP);
entry = &fdt_table[fdt_table_size];
- entry->dev_type = dev_type;
+ strcpy(entry->dev_type, dev_type);
entry->base = fdt_read_uint64(reg_addr);
entry->size = fdt_read_uint64(reg_addr + 2);
entry->prot = prot;
debug_printk("found device %s@%lx (size: %ld, prot: %d)\n",
- dev_type, entry->base, entry->size, prot);
+ entry->dev_type, entry->base, entry->size, prot);
fdt_table_size++;
}
@@ -137,11 +136,10 @@ out:
void parse_device_tree()
{
- fdt_base = read_csr(miobase);
- struct fdt_header* hdr = (struct fdt_header*) fdt_base;
+ uintptr_t iobase = read_csr(miobase);
+ struct fdt_header* hdr = (struct fdt_header*) iobase;
debug_printk("reading device tree at %p\n", hdr);
kassert(ntohl(hdr->magic) == FDT_MAGIC);
- fdt_size = ntohl(hdr->totalsize);
char* strings = (char*)hdr + ntohl(hdr->off_dt_strings);
uint32_t* root = (uint32_t*)((char*)hdr + ntohl(hdr->off_dt_struct));
while (ntohl(*root++) != FDT_BEGIN_NODE);
diff --git a/pk/devicetree.h b/pk/devicetree.h
index ceebaa3..c7f97cd 100644
--- a/pk/devicetree.h
+++ b/pk/devicetree.h
@@ -32,11 +32,13 @@ struct fdt_reserve_entry {
uint64_t size;
};
+#define FDT_DEV_NAME_SIZE 12
+
struct fdt_table_entry {
- const char *dev_type;
+ char dev_type[FDT_DEV_NAME_SIZE];
+ int prot;
uint64_t base;
uint64_t size;
- int prot;
};
void parse_device_tree();
diff --git a/pk/pk.h b/pk/pk.h
index ced0ca3..b8e9772 100644
--- a/pk/pk.h
+++ b/pk/pk.h
@@ -51,8 +51,6 @@ extern uintptr_t mem_size;
extern int have_vm;
extern uint32_t num_harts;
extern volatile uint32_t booted_harts_mask;
-extern uintptr_t fdt_base;
-extern size_t fdt_size;
struct mainvars* parse_args(struct mainvars*);
void printk(const char* s, ...);
diff --git a/pk/vm.c b/pk/vm.c
index 5dc1ada..fb21d48 100644
--- a/pk/vm.c
+++ b/pk/vm.c
@@ -504,7 +504,6 @@ uintptr_t pk_vm_init()
__map_kernel_range(0, 0, current.first_free_paddr, PROT_READ|PROT_WRITE|PROT_EXEC);
__map_kernel_range(first_free_page, first_free_page, free_pages * RISCV_PGSIZE, PROT_READ|PROT_WRITE);
- __map_kernel_range(fdt_base, fdt_base, fdt_size, PROT_READ);
size_t stack_size = RISCV_PGSIZE * CLAMP(mem_size/(RISCV_PGSIZE*32), 1, 256);
current.stack_bottom = __do_mmap(current.mmap_max - stack_size, stack_size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, 0, 0);