Subject: vga initialization

From: Zhang Fuxin <[email-masked]>
Date: Wed, 24 Apr 2002 9:11:38 +0800

hi,
  I find most code is already there in scitech's x86emu-0.8.
in one day it is adapted into linux kernel.

  If anybody is interested,my code can be fetched from
ftp://ftp.gnuchina.org/incoming/mips-vga-init/freebiosvga.tar.gz

For a short description,the READ in the package is paste here:

This is x86/bios emulator adapted for used in 2.4 kernel
to do initialize pc VGA cards.

Port it to pmon/yamon should be easy,if you want an userland
executable,please download the original x86emu-0.8 from SciTech 
Software, Inc.

Usage:
 here is my choice:
  1.add code in new directory arch/mips/freebiosvga/
  2.arch/mips/config.in:
     add config option CONFIG_VGA_POST to proper place
         bool '  Support for VGA POST' CONFIG_VGA_POST

  3.arch/mips/Makefile
     add directory and target objects of freevgabios

     ifdef CONFIG_VGA_POST
     SUBDIRS      += arch/mips/freebiosvga
     LIBS         += arch/mips/freebiosvga/vga.o
     SUBDIRS      += arch/mips/freebiosvga/x86emu
     LIBS         += arch/mips/freebiosvga/x86emu/x86emu.o
     endif

  4.init/main.c:
    add call to vgabios_init (right after pci_init)
    #ifdef CONFIG_VGA_POST
      vgabios_init();
    #endif

  5.select 'VGA text console' or proper framebuffer, you may need to
  slightly modify the code,because many of them is for x86

    for 'VGA text console',the file is drivers/video/vgacon.c,propably
  you need to comment out the check for card's presence in vgacon_startup.
  Because card initialization is later than console_init,so at that time
  pci address 0xa0000-0xc0000 may not response to your requests.

Problems & limits:
  1.currently the code rely on system's pci resource allocator to assign
    a valid address to rom base register(offset 0x30 in pci header).
    I have modified the pci_auto.c to handle rom. Patch is here:

     diff -r1.2 pci_auto.c
     107a108,110
     >       u32 bases[7] = {PCI_BASE_ADDRESS_0,PCI_BASE_ADDRESS_1,PCI_BASE_ADDRESS_2,
     >                         PCI_BASE_ADDRESS_3,PCI_BASE_ADDRESS_4,PCI_BASE_ADDRESS_5,
     >                       PCI_ROM_ADDRESS};
     110c113,116
     <       for (bar = PCI_BASE_ADDRESS_0; bar <= PCI_BASE_ADDRESS_5; bar+=4) {
     ---
     >       for (bar_nr=0; bar_nr<7; bar_nr++) {
     > 
     >               bar = bases[bar_nr];
     > 
     137c143
     <               if (bar_response & PCI_BASE_ADDRESS_SPACE) {
     ---
     >               if (bar_nr != 6 && (bar_response & PCI_BASE_ADDRESS_SPACE)) {
     209d214
     <               bar_nr++;
     349,350d353
     < 
     <                       DBG("Skipping legacy mode IDE controller\n");

   if you don't use pci_auto,then make sure your pmon/yamon do it.

   Of course,you can write an absolute,safe value for your specific platform
   to see it works:)

   If the base address read from your card is invalid,you will get message 
   like:
     "No address assigned to rom" or "No valid bios found"
    
 2. i am assuming ioremap(a_pci_address) will return a valid cpu virtue 
   address for accessing memory located at 'a_pci_address'.

 3. Multiple cards are not supported currently,though it may be a piece of
 cake.Complex cards,e.g. those contain bridges,may fail.

 4. cards tested here include: 
   trident 3Dimage9750,S3virge,Riva TNT2

DISCLAIMER:
  It is provided "as is" without express or implied warranty.

  Any problems you can contact [email-masked].

Happy hacking and good luck.

--
Zhang Fuxin
System Architecture Lab
Institute of Computing Technology
Chinese Academy of Sciences,China
http://www.ict.ac.cn

Regards
            Zhang Fuxin
            [email-masked]

---

From: James Simmons <[email-masked]>
Date: Wed, 24 Apr 2002 15:22:20 -0700 (PDT)

> in one day it is adapted into linux kernel.

Yipes!!! It has been discussed before and no x86 emulator will go into the
kernel. Now what I really love to ses is a way to trace threw the bios
code so we can write video drivers that don't need the BIOS to work.

---

From: Jim Paris <[email-masked]>
Date: Wed, 24 Apr 2002 18:39:28 -0400

> code so we can write video drivers that don't need the BIOS to work. 

If you mean "trace through" as in automatically, well, that's an x86
emulator. :) If you mean manually, there's a problem, because every
card is going to be entirely different.

-jim

---

From: Geert Uytterhoeven <[email-masked]>
Date: Thu, 25 Apr 2002 10:10:53 +0200 (MEST)

> card is going to be entirely different.

I think he means a BIOS `compiler' instead of an `interpreter' or `emulator'.
I.e. something that generates C code which can be compiled and used to
initialize the card later, without caring about the BIOS.

Some caveats:
  - BIOS code frequently uses the timers found in a typical PC-architecture box
  - The BIOS code copyright holder may consider this as a `translation' of
    his work, i.e. copyright infringement.

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email-masked]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds