Page 2 of 3
Re:Secondary VGA card booting
Posted: Mon Apr 11, 2005 2:42 pm
by Curufir
Looked into this some more (The X code is a PITA to try and read. Comments...what comments?).
The sequence of events runs something like this.
X uses x86emu to provide a vm86 environment that looks (To the card) like a working BIOS. The video card's BIOS is copied into RAM , then initialised the same way it would be in POST (A jump). As part of its initialisation the video card's BIOS will fill in the int10 vectors in the emulated real mode. The nv driver doesn't actually use the interrupts for anything, everything gets done using IO ports.
The reason it needs the int10 code is to set up an emulated environment in which the card can initialise itself, and in which IO ports/device memory are given mappings which the device can use.
So to get your 2nd card up and running you're going to need to provide the same functionality (IMHO just use the same mechanisms X uses) to get the thing to boot and give your driver the correct mappings.
http://wiki.linuxbios.org/data/vgabios/ gives some good information.
If x86emu doesn't cut it then
http://sourceforge.net/projects/lrmi/ might be an alternative (Haven't looked deeply at it so YMMV).
Re:Secondary VGA card booting
Posted: Mon Apr 11, 2005 6:40 pm
by Brendan
Hi,
The video card's ROM initialization code would use IO ports, etc to initialize the video card ready for use. This initialization code will not be present in X or in any other Linux software. The final product (the mobile phone) will not be able to run 80x86 opcodes (or the video card's ROM code), and therefore details of exactly what this ROM code does to initialize the video card will be needed for the end product.
While you could avoid the problem for now by using the video card's ROM code to initialize it, you're not solving the problem - all it would do is provide the temporary illusion of progress and leave you with the same problem when your finished with the test machine.
By avoiding the use of the video card's ROM code you will solve the initialization problem (and the hassles of trying to get the resource conflict/PCI initialization issues resolved).
IMHO this leaves you with 3 options - get information out of NVidea, pay NVidea to supply code, or reverse engineer the video card's BIOS code.
I assume your end product can't run 80x86 opcodes (otherwise you wouldn't need the FPGA and could use VBE 3 to initialize video modes, etc). I may have assumed something that isn't right, but I still think your screwed...
Cheers,
Brendan
Re:Secondary VGA card booting
Posted: Tue Apr 12, 2005 1:40 am
by LowRider
Curufir wrote:
Looked into this some more (The X code is a PITA to try and read. Comments...what comments?).
Uhu, I know, I think that's because it used to be copyrighted by Scitechsoft. Not?
Curufir wrote:The sequence of events runs something like this.
X uses x86emu to provide a vm86 environment that looks (To the card) like a working BIOS. The video card's BIOS is copied into RAM , then initialised the same way it would be in POST (A jump). As part of its initialisation the video card's BIOS will fill in the int10 vectors in the emulated real mode. The nv driver doesn't actually use the interrupts for anything, everything gets done using IO ports.
The reason it needs the int10 code is to set up an emulated environment in which the card can initialise itself, and in which IO ports/device memory are given mappings which the device can use.
So to get your 2nd card up and running you're going to need to provide the same functionality (IMHO just use the same mechanisms X uses) to get the thing to boot and give your driver the correct mappings.
http://wiki.linuxbios.org/data/vgabios/ gives some good information.
If x86emu doesn't cut it then
http://sourceforge.net/projects/lrmi/ might be an alternative (Haven't looked deeply at it so YMMV).
Aha, a clue! So
that's what x86emu does...
Always wondered why they'd use it, I figured, hey I've
got a x86, so why emulate it...
Well, very good explanation. Thanks for that. I'll certainly look into the x86emu stuff. Now all I have to do is convince the guys to let me use it (and not roll my own, argh...)
Concerning LRMI, I read that it doesn't support secondary VGA cards.
But now at least I'm starting to believe Brendan's wise words: I'm screwed

Re:Secondary VGA card booting
Posted: Tue Apr 12, 2005 4:26 am
by tom1000000
Hello,
Why don't you reverse engineer the video VGA BIOS????
Especially as it seems you are getting paid to do this, here is an opportunity to slightly uncover the veil of secrecy around nVidia / ATI hardware.
Work out what the video BIOS does - it must simply do a bunch of IO or memory writes. The VGA bios is limited in size so it can't be Einstein material (unless it is self encrypted or something ridiculous!).
If you do reverse engineer the BIOS please make your code or documentation public!
Re:Secondary VGA card booting
Posted: Tue Apr 12, 2005 5:54 am
by Pype.Clicker
i fear it will take him more than the 6 weeks ...
btw, tom, are you aware that the 'secrecy' about what the nvidia bios does is almost already unveiled by the BeOS/linux/freebe drivers ?
what remains a complete mystery is all the rest

Re:Secondary VGA card booting
Posted: Mon Apr 18, 2005 7:29 am
by LowRider
Pype.Clicker wrote:
btw, tom, are you aware that the 'secrecy' about what the nvidia bios does is almost already unveiled by the BeOS/linux/freebe drivers ?
Well, yes indeedy!! I've been studying the code of the `Haiku' nVidia driver (BeOS) and it contains a section to `soft-boot' the card. They call it a coldstart.
Here's the link:
http://bebits.com/app/3636#download
I've been trying to adapt the code (partially succesful) to my needs and I can hear the monitor click when I execute it. Problem now is this:
I'm using a VGA BIOS image I found somewhere on the internet. While I
should be using the image stored on the card (it's an image for AGP and I have PCI)
So, any ideas how I can squeeze the ROM out of my adapter?
My PCI book tells me this:
- assign a base address to the register's Base Address field
- enable its decoder (by setting bit 0 in the register to 1)
- set the Memory Space bit in the function's Command register
- and then attempt to read the first two locations from the ROM
Question: what base address? Should I just pick one?
Does the ROM then just magically `appear' at that location?
Nicolas
Re:Secondary VGA card booting
Posted: Mon Apr 18, 2005 9:58 am
by Pype.Clicker
LowRider wrote:
Question: what base address? Should I just pick one?
No, just 'picking one' would defeat the whole purpose of plug-and-play and could harm other devices. If operating from a base PC, i suggest you let the base PC tell you what should be the base address (e.g. because it has knowledge of what other device picked and what's still available, etc).
If your component needs to be completely standalone, i suggest you make the BIOS believe you need memory for your own needs and then use that memory as the ROM base address for the video card you control.
Does the ROM then just magically `appear' at that location?
afaik, yes.
Re:Secondary VGA card booting
Posted: Mon Apr 18, 2005 10:21 am
by LowRider
Pype.Clicker wrote:
If your component needs to be completely standalone, i suggest you make the BIOS believe you need memory for your own needs and then use that memory as the ROM base address for the video card you control.
And how exactly does one do this? Right now I have something like this:
[tt]
unsigned char *rom=(unsigned char*)kmalloc(ROMSIZE);
pci_write_config_dword(dev,0x30,(int)rom);
[/tt]
So basically I'm allocating some memory (e.g. 0xE3CC0000) and I'm telling the PCI device to use that address.
But that doesn't seem to work. (you're probably pounding your head against the wall right now and screaming "DUH!!!")
Does the ROM then just magically `appear' at that location?
afaik, yes.
cool

Re:Secondary VGA card booting
Posted: Mon Apr 18, 2005 10:53 am
by Brendan
Hi,
LowRider wrote:
So basically I'm allocating some memory (e.g. 0xE3CC0000) and I'm telling the PCI device to use that address.
But that doesn't seem to work. (you're probably pounding your head against the wall right now and screaming "DUH!!!")
Firstly, the address you choose shouldn't conflict with addresses used by anything else (but you knew that).
Secondly (AFAIK), you'll probably need to reprogram the PCI bridges to allow addresses within that range to pass through to the device. This would include the host bridge (the PCI/AGP controller) and any PCI to PCI bridges between it and the video card. Often they're setup to minimize redundant bus traffic...
Cheers,
Brendan
Re:Secondary VGA card booting
Posted: Mon Apr 18, 2005 11:00 am
by LowRider
Brendan wrote:Secondly (AFAIK), you'll probably need to reprogram the PCI bridges to allow addresses within that range to pass through to the device. This would include the host bridge (the PCI/AGP controller) and any PCI to PCI bridges between it and the video card. Often they're setup to minimize redundant bus traffic...
Well, that sounds logic. I'll have a look (don't know how to do this) and let you know...
Thanks!
Nicolas
Re:Secondary VGA card booting
Posted: Mon Apr 18, 2005 11:28 am
by Pype.Clicker
LowRider wrote:
Right now I have something like this:
[tt]
unsigned char *rom=(unsigned char*)kmalloc(ROMSIZE);
pci_write_config_dword(dev,0x30,(int)rom);
[/tt]
But that doesn't seem to work.
Not much surprising:
- kmalloc gets
virtual memory while your base address should be a
physical address.
- the physical memory returned by
kmalloc is some "real" physical memory, so it is "owned" by the system RAM and cannot be safely used to access PCI devices.
For testing purposes, i'd suggest you get a look at "lspci" and check what addresses are already busy there. Then manually pick some 'known-to-be-free' physical address and use that.
Ideally, after you checked how much system ram the hosting Linux has (as you appear to be operating from the hosting linux), you should scan through the kernel-stored PCI devices and select some "not-yet-used" region for your ROM address.
Re:Secondary VGA card booting
Posted: Mon Apr 18, 2005 12:24 pm
by LowRider
Great! Works beautifully!
I'm currently using 0xF9000000, ioremapped it and created a character device in /dev to talk to the ROM from outer space. (kernel-space, that is)
Now the darn program gives me Segmentation fault while coldstarting...
*sigh*
to be continued (I guess)...
Re:Secondary VGA card booting
Posted: Fri Apr 22, 2005 5:39 am
by LowRider
Well, as you might have guessed, the 0xf9000000 memory region isn't the best choice. I really need a way to get this address from the kernel.
Any ideas how to do this?
Secondly, I have a question about VBE3's `Protected Mode Entry Point'. The nVidia cores seem to support this. It's supposed to be a way to run some of the `int 10h' calls from protected mode by making a `far call' to the address at which the shadowed VGA BIOS resides.
Only problem I seem to have is that the addresses you have to fill in in the struct are 16bit. So I can't use 32bit addresses? How does this work? Do I have to put a "mem=" line in my GRUB loader and use the top memory? Or am I missing something? (with that whole `segmented memory' stuff, very confusing)
Re:Secondary VGA card booting
Posted: Fri Apr 22, 2005 5:57 am
by Pype.Clicker
the 'PM Bios VBE' thing is rather obscure. Among other things, it expects you to prepare two segments which will map what the bios could need to access. Thing is the selectors for those segments will be used instead of hard-coded 0xC000 and 0xB800, for instance.
Problem is there are various reports of "buggy implementation" of Pmode VBE bios by some vendors (sorry, i don't have more precise info).
Re:Secondary VGA card booting
Posted: Fri Apr 22, 2005 6:33 am
by LowRider
Pype.Clicker wrote:Problem is there are various reports of "buggy implementation" of Pmode VBE bios by some vendors (sorry, i don't have more precise info).
No problem, as long as I can quote you as a professional in my final report on the topic
Right now I'm trying to convince them to give up the nVidia board and go for something more `open'.
Any ideas which manufacturers have their info freely for download?