From OSDev Wiki
Jump to: navigation, search

AGP is the name of a expansion slot and corresponding standard designed to improve upon the PCI standard. Since AGP is an extension on top of the PCI specification, AGP cards can be used as any other PCI cards. However in their normal state they will work without the improvements they were designed with.



While AGP cards can run normally without special support, it would be nice if one had a 4X AGP card and be able to run it at full speed. All AGP cards run at 33Mhz if they're not set up properly. And when you're trying to extend the 'prettyness' of your OS speed to screen is everything.

Documentation on AGP is very difficult to find and the information here is taken from a rather large book called "PCI System Architecture" from Addison Wesley. In the section entitled "Configuration Registers" they provide an example of how to control a PCI card using what is termed a 'capabilities list', which demonstrated AGP.

AGP Tutorial

I assume that you have access to the PCI specs and can read/write PCI configuration registers. If you don't, what follows isn't going to be much use. I'm assuming PCI Spec 2.2 or higher. Have no idea if these work on the PCI Ex cards coming onto the market, somehow I doubt it. If you don't have PCI Spec 2.2 in your computer (most after 1998 have) I'm afraid you'll have to do the old device detection thing and have a list of known capabilities.

I'm pretty sure it will work on PCI Express. PCI Express is said to be "software compatible", however I am unsure of the extent of this. --Cjmovie

Firstly, detect the AGP card using standard PCI interrogation. The device ID should be 03h with a subclass code of 02h indicating: display controller - 3D controller. Some cards use a code of 80h ("other display controller"), so you should search for both and then perform the checking.

Next check that the 'capabilities available' bit is set. This is bit 4, byte 06h of the status register in the PCI header. Remember that numbering starts with 0 (zero). If this bit is set then you can follow the linked list of capabilities. If not it's a matter of finding the information the hard way.

Next from uint32_t 13h (byte 52, 0x34) you will find the capabilities pointer. This points to a linked list of 'capabilities' a device may have. This pointer is an 'absolute' pointer; there are no offsets to add. Just alter the uint32_t section of the PCI Address register and read the new uint32_t from the data register. Everything is uint32_t aligned.

At the uint32_t pointed by the pointer you'll find another uint32_t with the following format:

 0- 7   Capability ID
 8-15   Pointer to next capability (points directly to the next capability in the list)
16-31   Feature Specific

The pointer to the next capability is also an absolute address, and the address 0x00 signifies the end of the list.

So what you do is, follow the list until you come to an entry with the capability ID of 02h or "AGP". By the way, power management (0x01), vital product data (0x03) slot id (0x04), message signaled interrupts (0x05), CompactPCI (0x06) - no information provided.

Once you have the appropriate capability, you can now check which AGP version you have.

Stored in the same uint32_t holding the Capability ID, the following bits have the following meaning: Bits 16 - 19 Minor revision Bits 20 - 23 Major revision

This is basically a byte with two nibbles indicating the version numbers.

Now what happens next depends on your version numbers returned (thank you to Cemre for providing the info) Depending on a bit set in the status register, your card will function in AGP 2 or 3 mode. I'll mention the differences when we get to them.

Now that you're satisfied that you've got an AGP of the appropriate revision in custody, the next uint32_t holds the AGP status register(read-only unimplemented bits are 0's):

If you have an AGP 3 card - test bit 3. If the bit is 0, your video card is in AGP 2.0 mode. If set, your video card is in AGP 3.0 mode.

AGP 2.0 mode This indicates the data transfer rates supported by the AGP card. All data rates supported are indicated by set bits.

   Bit     Transfer rate
   0       1X
   1       2X
   2       4X

AGP 3.0 mode

   Bits    Transfer rate
   001     4X
   010     8X
   011     4X and 8X

Bit 3      Reserved and useless on an AGP 2 card, but on an AGP 3.0 card
           indicates whether the card is using AGP 2 or 3 register conventions.
           This is set on start up. I suppose it's useful when an 8X AGP is put into a 4X APG slot.

Bit 4      Fast Writes supported. (1 - Yes) 

Bit 5      Addresses > 4Gbytes. (1 - Yes)
          This one's for 64 bit systems Mips, Sparc, PowerPC etc.

Bit 6      Forces image data to go through the graphics processor, not directly to video memory.
           Reserved bit under AGP 2.0

Bits 8 - 7   Reserved 

Bit 9      Side Band Addressing supported. (1 - Yes)
           If supported (and activated) increases the speed of AGP accesses. This bit is
           set always under AGP 3.

Bits 10 - 12   Reserved under AGP 2.0.
               Under AGP 3 specifies the amount of time needed to calibrate I/O buffers

I'm adding this info for completeness.
000            4ms
001            16ms
010            64ms
011            256ms
111            No calibration time required 

Bits 13 - 15   Reserved under AGP 2.0.
               Under AGP 3, specifies the optimum request size to be sent from the
               master to the target. Unless you're into the 3D stuff - this is useless.

Bits 16 - 23   Reserved

Bits 24 - 31   Maximum depth of the AGP request queue supported. Unless you're into the
               3D stuff - this is useless.

OK, now we know the rates supported and the AGP's capabilities, time to speed things up.

The next uint32_t is the AGP Command Register where all the good stuff resides and it's format is exactly the same as the status register. Bits in the status resister are now settable in the command register except where the feature is mandatory. The bit we are interested in is bit 8 - the activate AGP bit. To increase speed, flip one (and only one) bit in the data rate section to select the data rate you need. For example to enable 4x AGP under AGP 2, set bit 2 of the configuration register then turn on bit 8 and

ZIPPPP, ZAPPPP, KAPOWWWW ***** 4X the data rate *****

Under AGP 3, setting the same bit will give you 8X the data rate.

Set the Fast-write and side-band addressing bits (if applicable and you can) to get a little bit more speed. Be warned, some cards do not like these enabled when installed on particular chipsets (some VIA boards I believe).

AGP 3 specs indicate that multiple AGP buses may exist in a single system. My recommendation is therefore that you set ALL the speed rates to the same speed in ALL the AGP devices you detect and turn them ALL on. I'm not sure if there's some kind of configuration 'dribbling' feature, but just to be on the safe side. Of course in a system with an 8X and a 4X you'll have to set the 8X to 4X unless they're on different buses otherwise the clocking would be out of sync, but then again maybe not.

So there, a quick and easy way to boost video speed. Many thanks to Tom Shanley, Don Anderson, Addison Wesley and Cemre for providing the information. "PCI SYSTEM ARCHITECTURE, Fourth Edition, ISBN 0-201-30974-2"

Further ramblings

I also noticed there's an "AGP ARCHITECTURE, ISBN 0-201-37964-3", Currently unavailable (like all the other AGP programming info)* - Is this some sort of conspiracy? Is there a secret government agency determined to suppress all AGP information? It's not like the PCI hardware specs or anything to do with actual AGP hardware implementation.

All I want to do is know how to program the blasted thing!

P.S. If you use the above for GUI/graphics/whatever development, I'd really be interested in the results obtained. Not necessarily a detailed analysis, just a - "Everything speeded up - happy".

P.P.S. I don't know how 'feature specific' the 3-D side of AGP is, The AGP 3.0 docs include a section on GART programming which somehow "pages" information around. Best get the OS working first. If you want to know more about the advanced video functions I suggest looking at the AGP Specs yourself.

Thanks again to all who have contributed.


Personal tools
In other languages