X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fnvram.c;h=7a1617fe38f1a837032d78635edba232cab75bdc;hb=e26f7efb461ea8fba7eb0fd14809618c22dd475b;hp=8c8830b565be2c99a53aaef5ee7dd3689698891f;hpb=b7093fd3602ef2c796a1f8a0daded9d6aad0b756;p=palacios.git diff --git a/palacios/src/devices/nvram.c b/palacios/src/devices/nvram.c index 8c8830b..7a1617f 100644 --- a/palacios/src/devices/nvram.c +++ b/palacios/src/devices/nvram.c @@ -98,6 +98,11 @@ typedef enum {NVRAM_READY, NVRAM_REG_POSTED} nvram_state_t; #define CHECKSUM_REGION_FIRST_BYTE 0x10 #define CHECKSUM_REGION_LAST_BYTE 0x2d +// Following fields are used by SEABIOS +#define NVRAM_REG_HIGHMEM_LOW 0x5b +#define NVRAM_REG_HIGHMEM_MID 0x5c +#define NVRAM_REG_HIGHMEM_HIGH 0x5d +#define NVRAM_REG_SMPCPUS 0x5f struct nvram_internal { nvram_state_t dev_state; @@ -302,7 +307,7 @@ static void update_time(struct nvram_internal * data, uint64_t period_us) { uint8_t nextday = 0; uint32_t periodic_period; - PrintDebug("nvram: update_time by %llu microseocnds\n",period_us); + PrintDebug(VM_NONE, VCORE_NONE, "nvram: update_time by %llu microseocnds\n",period_us); // We will set these flags on exit statc->irq = 0; @@ -320,7 +325,7 @@ static void update_time(struct nvram_internal * data, uint64_t period_us) { carry = add_to(sec, &carry, bcd); if (carry) { - PrintError("nvram: somehow managed to get a carry in second update\n"); + PrintError(VM_NONE, VCORE_NONE, "nvram: somehow managed to get a carry in second update\n"); } if ( (bcd && (*sec == 0x60)) || @@ -331,7 +336,7 @@ static void update_time(struct nvram_internal * data, uint64_t period_us) { carry = 1; carry = add_to(min, &carry, bcd); if (carry) { - PrintError("nvram: somehow managed to get a carry in minute update\n"); + PrintError(VM_NONE, VCORE_NONE, "nvram: somehow managed to get a carry in minute update\n"); } if ( (bcd && (*min == 0x60)) || @@ -352,7 +357,7 @@ static void update_time(struct nvram_internal * data, uint64_t period_us) { carry = 1; carry = add_to(&hour24, &carry, bcd); if (carry) { - PrintError("nvram: somehow managed to get a carry in hour update\n"); + PrintError(VM_NONE, VCORE_NONE, "nvram: somehow managed to get a carry in hour update\n"); } if ( (bcd && (hour24 == 0x24)) || @@ -432,7 +437,7 @@ static void update_time(struct nvram_internal * data, uint64_t period_us) { if (statb->ai) { if ((*sec == *seca) && (*min == *mina) && (*hour == *houra)) { statc->af = 1; - PrintDebug("nvram: interrupt on alarm\n"); + PrintDebug(VM_NONE, VCORE_NONE, "nvram: interrupt on alarm\n"); } } } @@ -442,22 +447,22 @@ static void update_time(struct nvram_internal * data, uint64_t period_us) { if (data->pus >= periodic_period) { statc->pf = 1; data->pus -= periodic_period; - PrintDebug("nvram: interrupt on periodic\n"); + PrintDebug(VM_NONE, VCORE_NONE, "nvram: interrupt on periodic\n"); } } if (statb->ui) { statc->uf = 1; - PrintDebug("nvram: interrupt on update\n"); + PrintDebug(VM_NONE, VCORE_NONE, "nvram: interrupt on update\n"); } statc->irq = (statc->pf || statc->af || statc->uf); - PrintDebug("nvram: time is now: YMDHMS: 0x%x:0x%x:0x%x:0x%x:0x%x,0x%x bcd=%d\n", *year, *month, *monthday, *hour, *min, *sec,bcd); + PrintDebug(VM_NONE, VCORE_NONE, "nvram: time is now: YMDHMS: 0x%x:0x%x:0x%x:0x%x:0x%x,0x%x bcd=%d\n", *year, *month, *monthday, *hour, *min, *sec,bcd); // Interrupt associated VM, if needed if (statc->irq) { - PrintDebug("nvram: injecting interrupt\n"); + PrintDebug(VM_NONE, VCORE_NONE, "nvram: injecting interrupt\n"); v3_raise_irq(data->vm, NVRAM_RTC_IRQ); } } @@ -484,43 +489,63 @@ static void set_memory_size(struct nvram_internal * nvram, addr_t bytes) { // 1. Conventional Mem: 0-640k in K // 2. Extended Mem: 0-16MB in K // 3. Big Mem: 0-4G in 64K - uint16_t memk; - uint16_t mem_chunks; + // 4. High Mem: 4G-... in 64K // at most 640K of conventional memory - if (bytes > 640 * 1024) { - memk=640; - } else { - memk = bytes/1024; + { + uint16_t memk = 0; + + if (bytes > (640 * 1024)) { + memk = 640; + } else { + memk = bytes / 1024; + } + + set_memory(nvram, NVRAM_REG_BASE_MEMORY_HIGH, (memk >> 8) & 0x00ff); + set_memory(nvram, NVRAM_REG_BASE_MEMORY_LOW, memk & 0x00ff); } - set_memory(nvram, NVRAM_REG_BASE_MEMORY_HIGH, (memk >> 8) & 0x00ff); - set_memory(nvram, NVRAM_REG_BASE_MEMORY_LOW, memk & 0x00ff); - // set extended memory - first 1 MB is lost to 640K chunk - // extended memory is min(0MB, bytes-1MB) - if (bytes < 1024*1024) { - // no extended memory - memk = 0; - } else { - memk = (bytes - 1024 * 1024 ) / 1024; + // extended memory is min(0MB, bytes - 1MB) + { + uint16_t memk = 0; + + if (bytes >= (1024 * 1024)) { + memk = (bytes - (1024 * 1024)) / 1024; + } + + set_memory(nvram, NVRAM_REG_EXT_MEMORY_HIGH, (memk >> 8) & 0x00ff); + set_memory(nvram, NVRAM_REG_EXT_MEMORY_LOW, memk & 0x00ff); + set_memory(nvram, NVRAM_REG_EXT_MEMORY_2ND_HIGH, (memk >> 8) & 0x00ff); + set_memory(nvram, NVRAM_REG_EXT_MEMORY_2ND_LOW, memk & 0x00ff); } - set_memory(nvram, NVRAM_REG_EXT_MEMORY_HIGH, (memk >> 8) & 0x00ff); - set_memory(nvram, NVRAM_REG_EXT_MEMORY_LOW, memk & 0x00ff); - set_memory(nvram, NVRAM_REG_EXT_MEMORY_2ND_HIGH, (memk >> 8) & 0x00ff); - set_memory(nvram, NVRAM_REG_EXT_MEMORY_2ND_LOW, memk & 0x00ff); - // Set the extended memory beyond 16 MB in 64k chunks - // this is min(0, bytes-16MB) - if (bytes<(1024*1024*16)) { - mem_chunks=0; - } else { - mem_chunks = (bytes - (1024 * 1024 * 16)) / (1024 * 64); + // this is min(0, bytes - 16MB) + { + uint16_t mem_chunks = 0; + + if (bytes >= (1024 * 1024 * 16)) { + mem_chunks = (bytes - (1024 * 1024 * 16)) / (1024 * 64); + } + + set_memory(nvram, NVRAM_REG_AMI_BIG_MEMORY_HIGH, (mem_chunks >> 8) & 0x00ff); + set_memory(nvram, NVRAM_REG_AMI_BIG_MEMORY_LOW, mem_chunks & 0x00ff); } - set_memory(nvram, NVRAM_REG_AMI_BIG_MEMORY_HIGH, (mem_chunks >> 8) & 0x00ff); - set_memory(nvram, NVRAM_REG_AMI_BIG_MEMORY_LOW, mem_chunks & 0x00ff); + // Set high (>4GB) memory size + { + + uint32_t high_mem_chunks = 0; + + if (bytes >= (1024LL * 1024LL * 1024LL * 4LL)) { + high_mem_chunks = (bytes - (1024LL * 1024LL * 1024LL * 4LL)) / (1024 * 64); + } + + set_memory(nvram, NVRAM_REG_HIGHMEM_LOW, high_mem_chunks & 0xff); + set_memory(nvram, NVRAM_REG_HIGHMEM_MID, (high_mem_chunks >> 8) & 0xff); + set_memory(nvram, NVRAM_REG_HIGHMEM_HIGH, (high_mem_chunks >> 16) & 0xff); + } return; } @@ -692,6 +717,8 @@ static int init_nvram_state(struct v3_vm_info * vm, struct nvram_internal * nvra set_memory_size(nvram, vm->mem_size); init_harddrives(nvram); + + set_memory(nvram, NVRAM_REG_SMPCPUS, vm->num_cores - 1); /* compute checksum (must follow all assignments here) */ checksum = compute_checksum(nvram); @@ -720,7 +747,7 @@ static int nvram_write_reg_port(struct guest_info * core, uint16_t port, data->thereg = reg & 0x7f; //discard NMI bit if it's there - PrintDebug("nvram: Writing To NVRAM reg: 0x%x (NMI_disable=%d)\n", data->thereg,reg>>7); + PrintDebug(core->vm_info, core, "nvram: Writing To NVRAM reg: 0x%x (NMI_disable=%d)\n", data->thereg,reg>>7); return 1; } @@ -733,11 +760,11 @@ static int nvram_read_data_port(struct guest_info * core, uint16_t port, addr_t irq_state = v3_lock_irqsave(data->nvram_lock); if (get_memory(data, data->thereg, (uint8_t *)dst) == -1) { - PrintError("nvram: Register %d (0x%x) Not set - POSSIBLE BUG IN MACHINE INIT - CONTINUING\n", data->thereg, data->thereg); + PrintError(core->vm_info, core, "nvram: Register %d (0x%x) Not set - POSSIBLE BUG IN MACHINE INIT - CONTINUING\n", data->thereg, data->thereg); } - PrintDebug("nvram: nvram_read_data_port(0x%x) = 0x%x\n", data->thereg, *(uint8_t *)dst); + PrintDebug(core->vm_info, core, "nvram: nvram_read_data_port(0x%x) = 0x%x\n", data->thereg, *(uint8_t *)dst); // hack if (data->thereg == NVRAM_REG_STAT_A) { @@ -761,7 +788,7 @@ static int nvram_write_data_port(struct guest_info * core, uint16_t port, v3_unlock_irqrestore(data->nvram_lock, irq_state); - PrintDebug("nvram: nvram_write_data_port(0x%x) = 0x%x\n", + PrintDebug(core->vm_info, core, "nvram: nvram_write_data_port(0x%x) = 0x%x\n", data->thereg, data->mem_state[data->thereg]); return 1; @@ -779,6 +806,8 @@ static int nvram_free(struct nvram_internal * nvram_state) { v3_remove_timer(info,nvram_state->timer); } + v3_lock_deinit(&(nvram_state->nvram_lock)); + V3_Free(nvram_state); return 0; } @@ -805,19 +834,19 @@ static int nvram_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { int ret = 0; if (!ide) { - PrintError("nvram: Could not find IDE device\n"); + PrintError(vm, VCORE_NONE, "nvram: Could not find IDE device\n"); return -1; } - PrintDebug("nvram: init_device\n"); + PrintDebug(vm, VCORE_NONE, "nvram: init_device\n"); nvram_state = (struct nvram_internal *)V3_Malloc(sizeof(struct nvram_internal) + 1000); if (!nvram_state) { - PrintError("Cannot allocate in init\n"); + PrintError(vm, VCORE_NONE, "Cannot allocate in init\n"); return -1; } - PrintDebug("nvram: internal at %p\n", (void *)nvram_state); + PrintDebug(vm, VCORE_NONE, "nvram: internal at %p\n", (void *)nvram_state); nvram_state->ide = ide; nvram_state->vm = vm; @@ -825,7 +854,7 @@ static int nvram_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, nvram_state); if (dev == NULL) { - PrintError("nvram: Could not attach device %s\n", dev_id); + PrintError(vm, VCORE_NONE, "nvram: Could not attach device %s\n", dev_id); V3_Free(nvram_state); return -1; } @@ -837,7 +866,7 @@ static int nvram_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { ret |= v3_dev_hook_io(dev, NVRAM_DATA_PORT, &nvram_read_data_port, &nvram_write_data_port); if (ret != 0) { - PrintError("nvram: Error hooking NVRAM IO ports\n"); + PrintError(vm, VCORE_NONE, "nvram: Error hooking NVRAM IO ports\n"); v3_remove_device(dev); return -1; }