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

This tutorial assumes that you have access to the PCI specs and can read/write PCI configuration registers. If you do not, what follows is not going to be much use. This tutorial also assumes PCI Spec 2.2 or higher. If your computer does not have PCI Spec 2.2, you will have to use device detection and have a list of known capabilities.

First, detect the AGP card using standard PCI interrogation. The device ID should be 03h with a subclass code of 02h indicating that the device is a "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 byte 06h bit 4 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 32bit integer pointed by the pointer you'll find another 32bit integer 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.

Now that you are satisfied that you have gotten an AGP of the appropriate revision in custody, the next 32bit integer 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. It is 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 is 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

Possible values for bits 10 - 12:

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 are into 3D, this is useless.

Bits 16 - 23   Reserved

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

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

The next 32bit integer 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 you will be 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 you will get 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).

AGP 3 specs indicate that multiple AGP buses may exist in a single system. It is recommended that you set all the speed rates to the same speed in all the AGP devices you detect and turn them ALL on. This possibly could be some kind of configuration 'dribbling' feature. Of course in a system with an 8X and a 4X you will have to set the 8X to 4X unless they are on different buses otherwise the clocking would be out of sync, but then again maybe not.


Personal tools
In other languages