Commit f753ff16382643e4e8917d36d07c41ba8705af21

Authored by pbrook
1 parent dcac9679

Register a single area for vga bios and option roms

Those guys are not different in nature. They're all roms,
not blessed with the graces of being written to. So there's
not need to issue multiple requests to memory registration areas:
just treat them as brothers, and put them all in the same
region.

It also has the nice side effect of improving the loading code
a little bit. Besides some of the ugliness going away, we're now
avoiding phys_ram_base dependencies in option rom code.

Signed-off-by: Glauber Costa <glommer@redhat.com>
Signed-off-by: Paul Brook <paul@codesourcery.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7057 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 53 additions and 68 deletions
... ... @@ -754,6 +754,27 @@ static void pc_init_ne2k_isa(NICInfo *nd, qemu_irq *pic)
754 754 nb_ne2k++;
755 755 }
756 756  
  757 +static int load_option_rom(const char *oprom, target_phys_addr_t start,
  758 + target_phys_addr_t end)
  759 +{
  760 + int size;
  761 +
  762 + size = get_image_size(oprom);
  763 + if (size > 0 && start + size > end) {
  764 + fprintf(stderr, "Not enough space to load option rom '%s'\n",
  765 + oprom);
  766 + exit(1);
  767 + }
  768 + size = load_image_targphys(oprom, start, end - start);
  769 + if (size < 0) {
  770 + fprintf(stderr, "Could not load option rom '%s'\n", oprom);
  771 + exit(1);
  772 + }
  773 + /* Round up optiom rom size to the next 2k boundary */
  774 + size = (size + 2047) & ~2047;
  775 + return size;
  776 +}
  777 +
757 778 /* PC hardware initialisation */
758 779 static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
759 780 const char *boot_device,
... ... @@ -763,9 +784,9 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
763 784 {
764 785 char buf[1024];
765 786 int ret, linux_boot, i;
766   - ram_addr_t ram_addr, vga_ram_addr, bios_offset, vga_bios_offset, option_rom_start = 0;
  787 + ram_addr_t ram_addr, vga_ram_addr, bios_offset, option_rom_offset;
767 788 ram_addr_t below_4g_mem_size, above_4g_mem_size = 0;
768   - int bios_size, isa_bios_size, vga_bios_size;
  789 + int bios_size, isa_bios_size, oprom_area_size;
769 790 PCIBus *pci_bus;
770 791 int piix3_devfn = -1;
771 792 CPUState *env;
... ... @@ -856,40 +877,6 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
856 877 fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", buf);
857 878 exit(1);
858 879 }
859   -
860   - if (using_vga) {
861   - /* VGA BIOS load */
862   - if (cirrus_vga_enabled) {
863   - snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_CIRRUS_FILENAME);
864   - } else {
865   - snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME);
866   - }
867   - vga_bios_size = get_image_size(buf);
868   - if (vga_bios_size <= 0 || vga_bios_size > 65536)
869   - goto vga_bios_error;
870   - vga_bios_offset = qemu_ram_alloc(65536);
871   -
872   - ret = load_image(buf, phys_ram_base + vga_bios_offset);
873   - if (ret != vga_bios_size) {
874   -vga_bios_error:
875   - fprintf(stderr, "qemu: could not load VGA BIOS '%s'\n", buf);
876   - exit(1);
877   - }
878   - /* Round up vga bios size to the next 2k boundary */
879   - vga_bios_size = (vga_bios_size + 2047) & ~2047;
880   - option_rom_start = 0xc0000 + vga_bios_size;
881   -
882   - /* setup basic memory access */
883   - cpu_register_physical_memory(0xc0000, vga_bios_size,
884   - vga_bios_offset | IO_MEM_ROM);
885   - }
886   -
887   - /* No point in placing option roms before this address, since bochs bios
888   - * will only start looking for it at 0xc8000 */
889   - if (option_rom_start < 0xc8000)
890   - option_rom_start = 0xc8000;
891   -
892   -
893 880 /* map the last 128KB of the BIOS in ISA space */
894 881 isa_bios_size = bios_size;
895 882 if (isa_bios_size > (128 * 1024))
... ... @@ -898,40 +885,38 @@ vga_bios_error:
898 885 isa_bios_size,
899 886 (bios_offset + bios_size - isa_bios_size) | IO_MEM_ROM);
900 887  
901   - {
902   - ram_addr_t option_rom_offset;
903   - int size, offset;
904   -
905   - offset = option_rom_start;
906   - if (linux_boot) {
907   - option_rom_offset = qemu_ram_alloc(TARGET_PAGE_SIZE);
908   - load_linux(phys_ram_base + option_rom_offset,
909   - kernel_filename, initrd_filename, kernel_cmdline);
910   - cpu_register_physical_memory(option_rom_start, TARGET_PAGE_SIZE,
911   - option_rom_offset | IO_MEM_ROM);
912   - offset += TARGET_PAGE_SIZE;
913   - }
914 888  
915   - for (i = 0; i < nb_option_roms; i++) {
916   - size = get_image_size(option_rom[i]);
917   - if (size < 0) {
918   - fprintf(stderr, "Could not load option rom '%s'\n",
919   - option_rom[i]);
920   - exit(1);
921   - }
922   - if (size > (0xe0000 - offset))
923   - goto option_rom_error;
924   - option_rom_offset = qemu_ram_alloc(size);
925   - ret = load_image(option_rom[i], phys_ram_base + option_rom_offset);
926   - if (ret != size) {
927   - option_rom_error:
928   - fprintf(stderr, "Could not fit %soption roms in available space\n", using_vga ? "VGA bios and " : "");
929   - exit(1);
930   - }
931   - size = (size + 4095) & ~4095;
932   - cpu_register_physical_memory(offset, size, option_rom_offset | IO_MEM_ROM);
933   - offset += size;
  889 +
  890 + option_rom_offset = qemu_ram_alloc(0x20000);
  891 + oprom_area_size = 0;
  892 + cpu_register_physical_memory(0xc0000, 0x20000,
  893 + option_rom_offset | IO_MEM_ROM);
  894 +
  895 + if (using_vga) {
  896 + /* VGA BIOS load */
  897 + if (cirrus_vga_enabled) {
  898 + snprintf(buf, sizeof(buf), "%s/%s", bios_dir,
  899 + VGABIOS_CIRRUS_FILENAME);
  900 + } else {
  901 + snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME);
934 902 }
  903 + oprom_area_size = load_option_rom(buf, 0xc0000, 0xe0000);
  904 + }
  905 + /* Although video roms can grow larger than 0x8000, the area between
  906 + * 0xc0000 - 0xc8000 is reserved for them. It means we won't be looking
  907 + * for any other kind of option rom inside this area */
  908 + if (oprom_area_size < 0x8000)
  909 + oprom_area_size = 0x8000;
  910 +
  911 + if (linux_boot) {
  912 + load_linux(phys_ram_base + option_rom_offset + oprom_area_size,
  913 + kernel_filename, initrd_filename, kernel_cmdline);
  914 + oprom_area_size += 2048;
  915 + }
  916 +
  917 + for (i = 0; i < nb_option_roms; i++) {
  918 + oprom_area_size += load_option_rom(option_rom[i],
  919 + 0xc0000 + oprom_area_size, 0xe0000);
935 920 }
936 921  
937 922 /* map all the bios at the top of memory */
... ...