hi,
i want to map the videomemory of my gfx card into the address space of my device driver.so i go to the device manager and show the properties of my gfx card (NVIDIA GeForce 6600 GT) it has the following memory areas:
D7000000-D7FFFFFF
C0000000-CFFFFFFF
D8000000-D8FFFFFF

C0000000 is the right physical address for the videomemory (i tried all 3 and it seems to be the correct one) so my asm code looks like this:

invoke MmMapIoSpace, 0C0000000h, 0, 1024*768*4, 2 ;resolution 1024x768x32
mov vidmem, eax

everything works fine and i can read/write to the videomemory but the problem is that i cant use a hardcoded physical address for the videomemory because it will change for every gfx card/os i suppose.so my question is how can i find out which physical address is the right one for the videomemory ?

thanks in advance!
Posted on 2005-11-18 17:56:52 by sHice
Good question - making your code OS independent would be a tough one (although it should be possible to target at least win2k and XP with the same code :)).

I looked into this stuff some years ago, but gave up. Even with querying adapters, finding the video adapter, and querying it's memory ranges, I couldn't find a way of detecting which range was the framebuffer.

Then there were the additional problems of detecting/setting video mode.

I think the proper approach to this would be hooking into the low-level DirectX support routines, called "DDI" if I'm not mistaken.
Posted on 2005-11-19 00:40:16 by f0dder
heres something else i found out.when i enter pci in softice it gives me the following information for my display controller:

Bus 03  Device 00  Function 00                                                 
      Vendor: 10DE                                                             
      Device: 00F1                                                             
      Revision: A2                                                             
      Device class:    03 Display controller                                   
      Device subclass: 00 VGA-compatible controller                           
      Device sub-subclass: 00                                                 
      Base address 0: D7000000  16MB  Memory  32-bit                           
      Base address 1: C0000000  256MB  Memory  32-bit  Prefetchable 
      Base address 2: D8000000  16MB  Memory  32-bit                           
      ROM base: 00000000  128K  Disabled                                       
      Interrupt line:  13  Interrupt pin: 01  Min_Gnt: 05      MaxLat: 01     
      Cache line size: 00  Latency timer: 20  Header type: 00  BIST: 00       
      Command Register:                                                       
          I/O:1    Mem:1  BusMast:1  Special:0    MemInv:0                   
          Parity:0  Wait:0  SERR:0    Back2Back:0  Snoop:0                   
      Status Register:                                                         
          Caps:1    66MHz Cap:1  UDF:0  FB2B Cap:1  DevSel: Medium             
          PERRDet:0 PERRRcvd:0 TASgnld:0  TARcvd:0  MARcvd:0  SERRSgnld:0 

i dont know if it is a coincidence but softice says the memory at C0000000 is prefetchable (what does that mean?) could this be a method to detect the right physical address for the vidmem? another idea would be to map all 3 possible physical address ranges and write a message or sth into the mapped memory and if it appears on the screen the user could tell me for which range he sees the message.
thx for your help so far f0dder!
Posted on 2005-11-19 06:27:15 by sHice

i dont know if it is a coincidence but softice says the memory at C0000000 is prefetchable (what does that mean?) could this be a method to detect the right physical address for the vidmem? another idea would be to map all 3 possible physical address ranges and write a message or sth into the mapped memory and if it appears on the screen the user could tell me for which range he sees the

Dunno what the prefetchable means, but trying all three ranges is NOT a good idea - those ranges could be used for other stuff, like GPU commands or whatever. Dunno if writing wrong commands could crash your system, but it might set the card in a weird state requiring a reboot to fix...

I guess it would take some video card device drivers to give a bit of info... I think (but this is a complete guess!) that finding out which range is the framebuffer would be queried from the card, device-specific.
Posted on 2005-11-19 06:33:50 by f0dder
The first region (region 0) is almost certainly the cards control space registers. The second & third are up to the device manufacturer. In this case I'm guessing region 1 is the frame buffer, and 2 is possibly the byteswapped CSRs.

Mirno
Posted on 2005-11-19 10:09:33 by Mirno
Might help a bit:
Sapphire Radeon 9200SE 128MB, latest drivers from ATi

MR = Memory Range
IO = Input/Output range

MR: D8000000 - DFFFFFFF
IO: 9000 - 90FF
MR: E9000000 - E900FFFF
IO: 03B0 - 03BB
IO: 03C0 - 03DF
MR: 000A0000 - 000BFFFF

IRQ = 11
Posted on 2005-11-19 15:57:43 by Ultrano
I have

memory: D6000000 - D6FFFFFF
memory: D8000000 - DFFFFFFF
IRQ:  16
IO: 03B0-03BB
IO: 03C0-03DF
memory: 000A0000 - 000BFFFF

So maybe the "IO" thing will tell you something somehow (don't ask me :P )?
Posted on 2005-11-19 20:15:13 by ti_mo_n

Dunno what the prefetchable means, but trying all three ranges is NOT a good idea - those ranges could be used for other stuff, like GPU commands or whatever. Dunno if writing wrong commands could crash your system, but it might set the card in a weird state requiring a reboot to fix...

hmm yeah you are right thats not a good idea.but i have another one :) if i map 000A0000 i also get the videomemory but only the first 64kb of it but thats enough! i could then write sth to the mapped memory and it will be displayed on the screen then i map all the other possible memory ranges that could be the vidmem and compare the first 64kb with the mapped memory of address 000A0000 and if they are equal i have the right videomemory :) the only assumption i have to make is that 000A0000 is the physical address of the first 64kb of the vidmem independent of the gfx card/os but i think that assumption is correct ?!
thx for posting all your card specs and your help!
Posted on 2005-11-20 07:31:43 by sHice