/*
* AGPGART driver.
- * Copyright (C) 2002-2003 Dave Jones.
+ * Copyright (C) 2004 Silicon Graphics, Inc.
+ * Copyright (C) 2002-2005 Dave Jones.
* Copyright (C) 1999 Jeff Hartmann.
* Copyright (C) 1999 Precision Insight, Inc.
* Copyright (C) 1999 Xi Graphics, Inc.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * TODO:
+ * TODO:
* - Allocate more than order 0 pages to avoid too much linear map splitting.
*/
#include <linux/config.h>
#include <linux/pm.h>
#include <linux/agp_backend.h>
#include <linux/vmalloc.h>
+#include <linux/dma-mapping.h>
+#include <linux/mm.h>
+#include <asm/io.h>
+#include <asm/cacheflush.h>
+#include <asm/pgtable.h>
#include "agp.h"
-__u32 *agp_gatt_table;
+__u32 *agp_gatt_table;
int agp_memory_reserved;
/*
*/
EXPORT_SYMBOL_GPL(agp_memory_reserved);
-/*
+#if defined(CONFIG_X86)
+int map_page_into_agp(struct page *page)
+{
+ int i;
+ i = change_page_attr(page, 1, PAGE_KERNEL_NOCACHE);
+ /* Caller's responsibility to call global_flush_tlb() for
+ * performance reasons */
+ return i;
+}
+EXPORT_SYMBOL_GPL(map_page_into_agp);
+
+int unmap_page_from_agp(struct page *page)
+{
+ int i;
+ i = change_page_attr(page, 1, PAGE_KERNEL);
+ /* Caller's responsibility to call global_flush_tlb() for
+ * performance reasons */
+ return i;
+}
+EXPORT_SYMBOL_GPL(unmap_page_from_agp);
+#endif
+
+/*
* Generic routines for handling agp_memory structures -
* They use the basic page allocation routines to do the brunt of the work.
*/
{
struct agp_memory *new;
- new = kmalloc(sizeof(struct agp_memory), GFP_KERNEL);
-
+ new = kzalloc(sizeof(struct agp_memory), GFP_KERNEL);
if (new == NULL)
return NULL;
- memset(new, 0, sizeof(struct agp_memory));
new->key = agp_get_key();
if (new->key < 0) {
{
size_t i;
- if ((agp_bridge->type == NOT_SUPPORTED) || (curr == NULL))
+ if (curr == NULL)
return;
if (curr->is_bound == TRUE)
agp_unbind_memory(curr);
if (curr->type != 0) {
- agp_bridge->driver->free_by_type(curr);
+ curr->bridge->driver->free_by_type(curr);
return;
}
if (curr->page_count != 0) {
for (i = 0; i < curr->page_count; i++) {
- agp_bridge->driver->agp_destroy_page(phys_to_virt(curr->memory[i]));
+ curr->bridge->driver->agp_destroy_page(gart_to_virt(curr->memory[i]));
}
+ flush_agp_mappings();
}
agp_free_key(curr->key);
vfree(curr->memory);
* agp_allocate_memory - allocate a group of pages of a certain type.
*
* @page_count: size_t argument of the number of pages
- * @type: u32 argument of the type of memory to be allocated.
+ * @type: u32 argument of the type of memory to be allocated.
*
* Every agp bridge device will allow you to allocate AGP_NORMAL_MEMORY which
* maps to physical ram. Any other type is device dependent.
*
- * It returns NULL whenever memory is unavailable.
+ * It returns NULL whenever memory is unavailable.
*/
-struct agp_memory *agp_allocate_memory(size_t page_count, u32 type)
+struct agp_memory *agp_allocate_memory(struct agp_bridge_data *bridge,
+ size_t page_count, u32 type)
{
int scratch_pages;
struct agp_memory *new;
size_t i;
- if (agp_bridge->type == NOT_SUPPORTED)
+ if (!bridge)
return NULL;
- if ((atomic_read(&agp_bridge->current_memory_agp) + page_count) > agp_bridge->max_memory_agp)
+ if ((atomic_read(&bridge->current_memory_agp) + page_count) > bridge->max_memory_agp)
return NULL;
if (type != 0) {
- new = agp_bridge->driver->alloc_by_type(page_count, type);
+ new = bridge->driver->alloc_by_type(page_count, type);
+ if (new)
+ new->bridge = bridge;
return new;
}
return NULL;
for (i = 0; i < page_count; i++) {
- void *addr = agp_bridge->driver->agp_alloc_page();
+ void *addr = bridge->driver->agp_alloc_page(bridge);
if (addr == NULL) {
agp_free_memory(new);
return NULL;
}
- new->memory[i] =
- agp_bridge->driver->mask_memory(virt_to_phys(addr), type);
+ new->memory[i] = virt_to_gart(addr);
new->page_count++;
}
+ new->bridge = bridge;
flush_agp_mappings();
* This function copies information about the agp bridge device and the state of
* the agp backend into an agp_kern_info pointer.
*/
-int agp_copy_info(struct agp_kern_info *info)
+int agp_copy_info(struct agp_bridge_data *bridge, struct agp_kern_info *info)
{
memset(info, 0, sizeof(struct agp_kern_info));
- if (!agp_bridge || agp_bridge->type == NOT_SUPPORTED ||
- !agp_bridge->version) {
+ if (!bridge) {
info->chipset = NOT_SUPPORTED;
return -EIO;
}
- info->version.major = agp_bridge->version->major;
- info->version.minor = agp_bridge->version->minor;
- info->chipset = agp_bridge->type;
- info->device = agp_bridge->dev;
- info->mode = agp_bridge->mode;
- info->aper_base = agp_bridge->gart_bus_addr;
+ info->version.major = bridge->version->major;
+ info->version.minor = bridge->version->minor;
+ info->chipset = SUPPORTED;
+ info->device = bridge->dev;
+ if (bridge->mode & AGPSTAT_MODE_3_0)
+ info->mode = bridge->mode & ~AGP3_RESERVED_MASK;
+ else
+ info->mode = bridge->mode & ~AGP2_RESERVED_MASK;
+ info->aper_base = bridge->gart_bus_addr;
info->aper_size = agp_return_size();
- info->max_memory = agp_bridge->max_memory_agp;
- info->current_memory = atomic_read(&agp_bridge->current_memory_agp);
- info->cant_use_aperture = agp_bridge->driver->cant_use_aperture;
- info->vm_ops = agp_bridge->vm_ops;
+ info->max_memory = bridge->max_memory_agp;
+ info->current_memory = atomic_read(&bridge->current_memory_agp);
+ info->cant_use_aperture = bridge->driver->cant_use_aperture;
+ info->vm_ops = bridge->vm_ops;
info->page_mask = ~0UL;
return 0;
}
EXPORT_SYMBOL(agp_copy_info);
-
/* End - Routine to copy over information structure */
-
/*
* Routines for handling swapping of agp_memory into the GATT -
* These routines take agp_memory and insert them into the GATT.
/**
* agp_bind_memory - Bind an agp_memory structure into the GATT.
- *
+ *
* @curr: agp_memory pointer
* @pg_start: an offset into the graphics aperture translation table
*
{
int ret_val;
- if ((agp_bridge->type == NOT_SUPPORTED) || (curr == NULL))
+ if (curr == NULL)
return -EINVAL;
if (curr->is_bound == TRUE) {
- printk (KERN_INFO PFX "memory %p is already bound!\n", curr);
+ printk(KERN_INFO PFX "memory %p is already bound!\n", curr);
return -EINVAL;
}
if (curr->is_flushed == FALSE) {
- agp_bridge->driver->cache_flush();
+ curr->bridge->driver->cache_flush();
curr->is_flushed = TRUE;
}
- ret_val = agp_bridge->driver->insert_memory(curr, pg_start, curr->type);
+ ret_val = curr->bridge->driver->insert_memory(curr, pg_start, curr->type);
if (ret_val != 0)
return ret_val;
/**
* agp_unbind_memory - Removes an agp_memory structure from the GATT
- *
+ *
* @curr: agp_memory pointer to be removed from the GATT.
- *
+ *
* It returns -EINVAL if this piece of agp_memory is not currently bound to
* the graphics aperture translation table or if the agp_memory pointer == NULL
*/
{
int ret_val;
- if ((agp_bridge->type == NOT_SUPPORTED) || (curr == NULL))
+ if (curr == NULL)
return -EINVAL;
if (curr->is_bound != TRUE) {
- printk (KERN_INFO PFX "memory %p was not bound!\n", curr);
+ printk(KERN_INFO PFX "memory %p was not bound!\n", curr);
return -EINVAL;
}
- ret_val = agp_bridge->driver->remove_memory(curr, curr->pg_start, curr->type);
+ ret_val = curr->bridge->driver->remove_memory(curr, curr->pg_start, curr->type);
if (ret_val != 0)
return ret_val;
/* Generic Agp routines - Start */
-static void agp_v2_parse_one(u32 *mode, u32 *cmd, u32 *tmp)
+static void agp_v2_parse_one(u32 *requested_mode, u32 *bridge_agpstat, u32 *vga_agpstat)
{
+ u32 tmp;
+
+ if (*requested_mode & AGP2_RESERVED_MASK) {
+ printk(KERN_INFO PFX "reserved bits set (%x) in mode 0x%x. Fixed.\n",
+ *requested_mode & AGP2_RESERVED_MASK, *requested_mode);
+ *requested_mode &= ~AGP2_RESERVED_MASK;
+ }
+
+ /* Check the speed bits make sense. Only one should be set. */
+ tmp = *requested_mode & 7;
+ switch (tmp) {
+ case 0:
+ printk(KERN_INFO PFX "%s tried to set rate=x0. Setting to x1 mode.\n", current->comm);
+ *requested_mode |= AGPSTAT2_1X;
+ break;
+ case 1:
+ case 2:
+ break;
+ case 3:
+ *requested_mode &= ~(AGPSTAT2_1X); /* rate=2 */
+ break;
+ case 4:
+ break;
+ case 5:
+ case 6:
+ case 7:
+ *requested_mode &= ~(AGPSTAT2_1X|AGPSTAT2_2X); /* rate=4*/
+ break;
+ }
+
/* disable SBA if it's not supported */
- if (!((*cmd & AGPSTAT_SBA) && (*tmp & AGPSTAT_SBA) && (*mode & AGPSTAT_SBA)))
- *cmd &= ~AGPSTAT_SBA;
+ if (!((*bridge_agpstat & AGPSTAT_SBA) && (*vga_agpstat & AGPSTAT_SBA) && (*requested_mode & AGPSTAT_SBA)))
+ *bridge_agpstat &= ~AGPSTAT_SBA;
- /* Set speed */
- if (!((*cmd & AGPSTAT2_4X) && (*tmp & AGPSTAT2_4X) && (*mode & AGPSTAT2_4X)))
- *cmd &= ~AGPSTAT2_4X;
+ /* Set rate */
+ if (!((*bridge_agpstat & AGPSTAT2_4X) && (*vga_agpstat & AGPSTAT2_4X) && (*requested_mode & AGPSTAT2_4X)))
+ *bridge_agpstat &= ~AGPSTAT2_4X;
- if (!((*cmd & AGPSTAT2_2X) && (*tmp & AGPSTAT2_2X) && (*mode & AGPSTAT2_2X)))
- *cmd &= ~AGPSTAT2_2X;
+ if (!((*bridge_agpstat & AGPSTAT2_2X) && (*vga_agpstat & AGPSTAT2_2X) && (*requested_mode & AGPSTAT2_2X)))
+ *bridge_agpstat &= ~AGPSTAT2_2X;
- if (!((*cmd & AGPSTAT2_1X) && (*tmp & AGPSTAT2_1X) && (*mode & AGPSTAT2_1X)))
- *cmd &= ~AGPSTAT2_1X;
+ if (!((*bridge_agpstat & AGPSTAT2_1X) && (*vga_agpstat & AGPSTAT2_1X) && (*requested_mode & AGPSTAT2_1X)))
+ *bridge_agpstat &= ~AGPSTAT2_1X;
/* Now we know what mode it should be, clear out the unwanted bits. */
- if (*cmd & AGPSTAT2_4X)
- *cmd &= ~(AGPSTAT2_1X | AGPSTAT2_2X); /* 4X */
+ if (*bridge_agpstat & AGPSTAT2_4X)
+ *bridge_agpstat &= ~(AGPSTAT2_1X | AGPSTAT2_2X); /* 4X */
- if (*cmd & AGPSTAT2_2X)
- *cmd &= ~(AGPSTAT2_1X | AGPSTAT2_4X); /* 2X */
+ if (*bridge_agpstat & AGPSTAT2_2X)
+ *bridge_agpstat &= ~(AGPSTAT2_1X | AGPSTAT2_4X); /* 2X */
- if (*cmd & AGPSTAT2_1X)
- *cmd &= ~(AGPSTAT2_2X | AGPSTAT2_4X); /* 1Xf */
-}
+ if (*bridge_agpstat & AGPSTAT2_1X)
+ *bridge_agpstat &= ~(AGPSTAT2_2X | AGPSTAT2_4X); /* 1X */
+
+ /* Apply any errata. */
+ if (agp_bridge->flags & AGP_ERRATA_FASTWRITES)
+ *bridge_agpstat &= ~AGPSTAT_FW;
+ if (agp_bridge->flags & AGP_ERRATA_SBA)
+ *bridge_agpstat &= ~AGPSTAT_SBA;
-static void agp_v3_parse_one(u32 *mode, u32 *cmd, u32 *tmp)
+ if (agp_bridge->flags & AGP_ERRATA_1X) {
+ *bridge_agpstat &= ~(AGPSTAT2_2X | AGPSTAT2_4X);
+ *bridge_agpstat |= AGPSTAT2_1X;
+ }
+
+ /* If we've dropped down to 1X, disable fast writes. */
+ if (*bridge_agpstat & AGPSTAT2_1X)
+ *bridge_agpstat &= ~AGPSTAT_FW;
+}
+
+/*
+ * requested_mode = Mode requested by (typically) X.
+ * bridge_agpstat = PCI_AGP_STATUS from agp bridge.
+ * vga_agpstat = PCI_AGP_STATUS from graphic card.
+ */
+static void agp_v3_parse_one(u32 *requested_mode, u32 *bridge_agpstat, u32 *vga_agpstat)
{
+ u32 origbridge=*bridge_agpstat, origvga=*vga_agpstat;
+ u32 tmp;
+
+ if (*requested_mode & AGP3_RESERVED_MASK) {
+ printk(KERN_INFO PFX "reserved bits set (%x) in mode 0x%x. Fixed.\n",
+ *requested_mode & AGP3_RESERVED_MASK, *requested_mode);
+ *requested_mode &= ~AGP3_RESERVED_MASK;
+ }
+
+ /* Check the speed bits make sense. */
+ tmp = *requested_mode & 7;
+ if (tmp == 0) {
+ printk(KERN_INFO PFX "%s tried to set rate=x0. Setting to AGP3 x4 mode.\n", current->comm);
+ *requested_mode |= AGPSTAT3_4X;
+ }
+ if (tmp >= 3) {
+ printk(KERN_INFO PFX "%s tried to set rate=x%d. Setting to AGP3 x8 mode.\n", current->comm, tmp * 4);
+ *requested_mode = (*requested_mode & ~7) | AGPSTAT3_8X;
+ }
+
/* ARQSZ - Set the value to the maximum one.
* Don't allow the mode register to override values. */
- *cmd = ((*cmd & ~AGPSTAT_ARQSZ) |
- max_t(u32,(*cmd & AGPSTAT_ARQSZ),(*tmp & AGPSTAT_ARQSZ)));
+ *bridge_agpstat = ((*bridge_agpstat & ~AGPSTAT_ARQSZ) |
+ max_t(u32,(*bridge_agpstat & AGPSTAT_ARQSZ),(*vga_agpstat & AGPSTAT_ARQSZ)));
/* Calibration cycle.
* Don't allow the mode register to override values. */
- *cmd = ((*cmd & ~AGPSTAT_CAL_MASK) |
- min_t(u32,(*cmd & AGPSTAT_CAL_MASK),(*tmp & AGPSTAT_CAL_MASK)));
+ *bridge_agpstat = ((*bridge_agpstat & ~AGPSTAT_CAL_MASK) |
+ min_t(u32,(*bridge_agpstat & AGPSTAT_CAL_MASK),(*vga_agpstat & AGPSTAT_CAL_MASK)));
/* SBA *must* be supported for AGP v3 */
- *cmd |= AGPSTAT_SBA;
+ *bridge_agpstat |= AGPSTAT_SBA;
/*
* Set speed.
* Check for invalid speeds. This can happen when applications
* written before the AGP 3.0 standard pass AGP2.x modes to AGP3 hardware
*/
- if (*mode & AGPSTAT_MODE_3_0) {
+ if (*requested_mode & AGPSTAT_MODE_3_0) {
/*
- * Caller hasn't a clue what its doing. We are in 3.0 mode,
+ * Caller hasn't a clue what it is doing. Bridge is in 3.0 mode,
* have been passed a 3.0 mode, but with 2.x speed bits set.
* AGP2.x 4x -> AGP3.0 4x.
*/
- if (*mode & AGPSTAT2_4X) {
- printk (KERN_INFO PFX "%s passes broken AGP3 flags (%x). Fixed.\n",
- current->comm, *mode);
- *mode &= ~AGPSTAT2_4X;
- *mode |= AGPSTAT3_4X;
+ if (*requested_mode & AGPSTAT2_4X) {
+ printk(KERN_INFO PFX "%s passes broken AGP3 flags (%x). Fixed.\n",
+ current->comm, *requested_mode);
+ *requested_mode &= ~AGPSTAT2_4X;
+ *requested_mode |= AGPSTAT3_4X;
}
} else {
/*
* but have been passed an AGP 2.x mode.
* Convert AGP 1x,2x,4x -> AGP 3.0 4x.
*/
- printk (KERN_INFO PFX "%s passes broken AGP2 flags (%x) in AGP3 mode. Fixed.\n",
- current->comm, *mode);
- *mode &= ~(AGPSTAT2_4X | AGPSTAT2_2X | AGPSTAT2_1X);
- *mode |= AGPSTAT3_4X;
+ printk(KERN_INFO PFX "%s passes broken AGP2 flags (%x) in AGP3 mode. Fixed.\n",
+ current->comm, *requested_mode);
+ *requested_mode &= ~(AGPSTAT2_4X | AGPSTAT2_2X | AGPSTAT2_1X);
+ *requested_mode |= AGPSTAT3_4X;
}
- if (!((*cmd & AGPSTAT3_8X) && (*tmp & AGPSTAT3_8X) && (*mode & AGPSTAT3_8X)))
- *cmd &= ~AGPSTAT3_8X;
+ if (*requested_mode & AGPSTAT3_8X) {
+ if (!(*bridge_agpstat & AGPSTAT3_8X)) {
+ *bridge_agpstat &= ~(AGPSTAT3_8X | AGPSTAT3_RSVD);
+ *bridge_agpstat |= AGPSTAT3_4X;
+ printk(KERN_INFO PFX "%s requested AGPx8 but bridge not capable.\n", current->comm);
+ return;
+ }
+ if (!(*vga_agpstat & AGPSTAT3_8X)) {
+ *bridge_agpstat &= ~(AGPSTAT3_8X | AGPSTAT3_RSVD);
+ *bridge_agpstat |= AGPSTAT3_4X;
+ printk(KERN_INFO PFX "%s requested AGPx8 but graphic card not capable.\n", current->comm);
+ return;
+ }
+ /* All set, bridge & device can do AGP x8*/
+ *bridge_agpstat &= ~(AGPSTAT3_4X | AGPSTAT3_RSVD);
+ goto done;
+
+ } else {
+
+ /*
+ * If we didn't specify AGPx8, we can only do x4.
+ * If the hardware can't do x4, we're up shit creek, and never
+ * should have got this far.
+ */
+ *bridge_agpstat &= ~(AGPSTAT3_8X | AGPSTAT3_RSVD);
+ if ((*bridge_agpstat & AGPSTAT3_4X) && (*vga_agpstat & AGPSTAT3_4X))
+ *bridge_agpstat |= AGPSTAT3_4X;
+ else {
+ printk(KERN_INFO PFX "Badness. Don't know which AGP mode to set. "
+ "[bridge_agpstat:%x vga_agpstat:%x fell back to:- bridge_agpstat:%x vga_agpstat:%x]\n",
+ origbridge, origvga, *bridge_agpstat, *vga_agpstat);
+ if (!(*bridge_agpstat & AGPSTAT3_4X))
+ printk(KERN_INFO PFX "Bridge couldn't do AGP x4.\n");
+ if (!(*vga_agpstat & AGPSTAT3_4X))
+ printk(KERN_INFO PFX "Graphic card couldn't do AGP x4.\n");
+ return;
+ }
+ }
- if (!((*cmd & AGPSTAT3_4X) && (*tmp & AGPSTAT3_4X) && (*mode & AGPSTAT3_4X)))
- *cmd &= ~AGPSTAT3_4X;
+done:
+ /* Apply any errata. */
+ if (agp_bridge->flags & AGP_ERRATA_FASTWRITES)
+ *bridge_agpstat &= ~AGPSTAT_FW;
- /* Clear out unwanted bits. */
- if (*cmd & AGPSTAT3_8X)
- *cmd &= ~(AGPSTAT3_4X | AGPSTAT3_RSVD);
- if (*cmd & AGPSTAT3_4X)
- *cmd &= ~(AGPSTAT3_8X | AGPSTAT3_RSVD);
+ if (agp_bridge->flags & AGP_ERRATA_SBA)
+ *bridge_agpstat &= ~AGPSTAT_SBA;
+
+ if (agp_bridge->flags & AGP_ERRATA_1X) {
+ *bridge_agpstat &= ~(AGPSTAT2_2X | AGPSTAT2_4X);
+ *bridge_agpstat |= AGPSTAT2_1X;
+ }
}
-//FIXME: This doesn't smell right.
-//We need a function we pass an agp_device to.
-u32 agp_collect_device_status(u32 mode, u32 cmd)
+
+/**
+ * agp_collect_device_status - determine correct agp_cmd from various agp_stat's
+ * @bridge: an agp_bridge_data struct allocated for the AGP host bridge.
+ * @requested_mode: requested agp_stat from userspace (Typically from X)
+ * @bridge_agpstat: current agp_stat from AGP bridge.
+ *
+ * This function will hunt for an AGP graphics card, and try to match
+ * the requested mode to the capabilities of both the bridge and the card.
+ */
+u32 agp_collect_device_status(struct agp_bridge_data *bridge, u32 requested_mode, u32 bridge_agpstat)
{
struct pci_dev *device = NULL;
+ u32 vga_agpstat;
u8 cap_ptr;
- u32 tmp;
- u32 agp3;
- while ((device = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, device)) != NULL) {
- cap_ptr = pci_find_capability(device, PCI_CAP_ID_AGP);
- if (!cap_ptr)
- continue;
-
- /*
- * Ok, here we have a AGP device. Disable impossible
- * settings, and adjust the readqueue to the minimum.
- */
- pci_read_config_dword(device, cap_ptr+PCI_AGP_STATUS, &tmp);
-
- /* adjust RQ depth */
- cmd = ((cmd & ~AGPSTAT_RQ_DEPTH) |
- min_t(u32, (mode & AGPSTAT_RQ_DEPTH),
- min_t(u32, (cmd & AGPSTAT_RQ_DEPTH), (tmp & AGPSTAT_RQ_DEPTH))));
-
- /* disable FW if it's not supported */
- if (!((cmd & AGPSTAT_FW) && (tmp & AGPSTAT_FW) && (mode & AGPSTAT_FW)))
- cmd &= ~AGPSTAT_FW;
-
- /* Check to see if we are operating in 3.0 mode */
- pci_read_config_dword(device, cap_ptr+AGPSTAT, &agp3);
- if (agp3 & AGPSTAT_MODE_3_0) {
- agp_v3_parse_one(&mode, &cmd, &tmp);
- } else {
- agp_v2_parse_one(&mode, &cmd, &tmp);
+ for (;;) {
+ device = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, device);
+ if (!device) {
+ printk(KERN_INFO PFX "Couldn't find an AGP VGA controller.\n");
+ return 0;
}
+ cap_ptr = pci_find_capability(device, PCI_CAP_ID_AGP);
+ if (cap_ptr)
+ break;
}
- return cmd;
+
+ /*
+ * Ok, here we have a AGP device. Disable impossible
+ * settings, and adjust the readqueue to the minimum.
+ */
+ pci_read_config_dword(device, cap_ptr+PCI_AGP_STATUS, &vga_agpstat);
+
+ /* adjust RQ depth */
+ bridge_agpstat = ((bridge_agpstat & ~AGPSTAT_RQ_DEPTH) |
+ min_t(u32, (requested_mode & AGPSTAT_RQ_DEPTH),
+ min_t(u32, (bridge_agpstat & AGPSTAT_RQ_DEPTH), (vga_agpstat & AGPSTAT_RQ_DEPTH))));
+
+ /* disable FW if it's not supported */
+ if (!((bridge_agpstat & AGPSTAT_FW) &&
+ (vga_agpstat & AGPSTAT_FW) &&
+ (requested_mode & AGPSTAT_FW)))
+ bridge_agpstat &= ~AGPSTAT_FW;
+
+ /* Check to see if we are operating in 3.0 mode */
+ if (agp_bridge->mode & AGPSTAT_MODE_3_0)
+ agp_v3_parse_one(&requested_mode, &bridge_agpstat, &vga_agpstat);
+ else
+ agp_v2_parse_one(&requested_mode, &bridge_agpstat, &vga_agpstat);
+
+ pci_dev_put(device);
+ return bridge_agpstat;
}
EXPORT_SYMBOL(agp_collect_device_status);
-void agp_device_command(u32 command, int agp_v3)
+void agp_device_command(u32 bridge_agpstat, int agp_v3)
{
struct pci_dev *device = NULL;
int mode;
- mode = command & 0x7;
+ mode = bridge_agpstat & 0x7;
if (agp_v3)
mode *= 4;
- while ((device = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, device)) != NULL) {
+ for_each_pci_dev(device) {
u8 agp = pci_find_capability(device, PCI_CAP_ID_AGP);
if (!agp)
continue;
printk(KERN_INFO PFX "Putting AGP V%d device at %s into %dx mode\n",
agp_v3 ? 3 : 2, pci_name(device), mode);
- pci_write_config_dword(device, agp + PCI_AGP_COMMAND, command);
+ pci_write_config_dword(device, agp + PCI_AGP_COMMAND, bridge_agpstat);
}
}
EXPORT_SYMBOL(agp_device_command);
u32 ncapid;
/* Exit early if already set by errata workarounds. */
- if (agp_bridge->major_version != 0)
+ if (bridge->major_version != 0)
return;
- pci_read_config_dword(agp_bridge->dev, agp_bridge->capndx, &ncapid);
- agp_bridge->major_version = (ncapid >> AGP_MAJOR_VERSION_SHIFT) & 0xf;
- agp_bridge->minor_version = (ncapid >> AGP_MINOR_VERSION_SHIFT) & 0xf;
+ pci_read_config_dword(bridge->dev, bridge->capndx, &ncapid);
+ bridge->major_version = (ncapid >> AGP_MAJOR_VERSION_SHIFT) & 0xf;
+ bridge->minor_version = (ncapid >> AGP_MINOR_VERSION_SHIFT) & 0xf;
}
EXPORT_SYMBOL(get_agp_version);
-void agp_generic_enable(u32 mode)
+void agp_generic_enable(struct agp_bridge_data *bridge, u32 requested_mode)
{
- u32 command, temp;
- u32 agp3;
+ u32 bridge_agpstat, temp;
get_agp_version(agp_bridge);
printk(KERN_INFO PFX "Found an AGP %d.%d compliant device at %s.\n",
agp_bridge->major_version,
agp_bridge->minor_version,
- agp_bridge->dev->slot_name);
+ pci_name(agp_bridge->dev));
pci_read_config_dword(agp_bridge->dev,
- agp_bridge->capndx + PCI_AGP_STATUS, &command);
+ agp_bridge->capndx + PCI_AGP_STATUS, &bridge_agpstat);
- command = agp_collect_device_status(mode, command);
- command |= AGPSTAT_AGP_ENABLE;
+ bridge_agpstat = agp_collect_device_status(agp_bridge, requested_mode, bridge_agpstat);
+ if (bridge_agpstat == 0)
+ /* Something bad happened. FIXME: Return error code? */
+ return;
- /* Do AGP version specific frobbing. */
- if(agp_bridge->major_version >= 3) {
- pci_read_config_dword(agp_bridge->dev,
- agp_bridge->capndx+AGPSTAT, &agp3);
+ bridge_agpstat |= AGPSTAT_AGP_ENABLE;
- /* Check to see if we are operating in 3.0 mode */
- if (agp3 & AGPSTAT_MODE_3_0) {
+ /* Do AGP version specific frobbing. */
+ if (bridge->major_version >= 3) {
+ if (bridge->mode & AGPSTAT_MODE_3_0) {
/* If we have 3.5, we can do the isoch stuff. */
- if (agp_bridge->minor_version >= 5)
- agp_3_5_enable(agp_bridge);
- agp_device_command(command, TRUE);
+ if (bridge->minor_version >= 5)
+ agp_3_5_enable(bridge);
+ agp_device_command(bridge_agpstat, TRUE);
return;
} else {
/* Disable calibration cycle in RX91<1> when not in AGP3.0 mode of operation.*/
- command &= ~(7<<10) ;
- pci_read_config_dword(agp_bridge->dev, agp_bridge->capndx+AGPCTRL, &temp);
+ bridge_agpstat &= ~(7<<10) ;
+ pci_read_config_dword(bridge->dev,
+ bridge->capndx+AGPCTRL, &temp);
temp |= (1<<9);
- pci_write_config_dword(agp_bridge->dev, agp_bridge->capndx+AGPCTRL, temp);
+ pci_write_config_dword(bridge->dev,
+ bridge->capndx+AGPCTRL, temp);
- printk (KERN_INFO PFX "Device is in legacy mode,"
+ printk(KERN_INFO PFX "Device is in legacy mode,"
" falling back to 2.x\n");
}
}
/* AGP v<3 */
- agp_device_command(command, FALSE);
+ agp_device_command(bridge_agpstat, FALSE);
}
EXPORT_SYMBOL(agp_generic_enable);
-int agp_generic_create_gatt_table(void)
+int agp_generic_create_gatt_table(struct agp_bridge_data *bridge)
{
char *table;
char *table_end;
struct page *page;
/* The generic routines can't handle 2 level gatt's */
- if (agp_bridge->driver->size_type == LVL2_APER_SIZE)
+ if (bridge->driver->size_type == LVL2_APER_SIZE)
return -EINVAL;
table = NULL;
- i = agp_bridge->aperture_size_idx;
- temp = agp_bridge->current_size;
+ i = bridge->aperture_size_idx;
+ temp = bridge->current_size;
size = page_order = num_entries = 0;
- if (agp_bridge->driver->size_type != FIXED_APER_SIZE) {
+ if (bridge->driver->size_type != FIXED_APER_SIZE) {
do {
- switch (agp_bridge->driver->size_type) {
+ switch (bridge->driver->size_type) {
case U8_APER_SIZE:
size = A_SIZE_8(temp)->size;
page_order =
break;
}
- table = (char *) __get_free_pages(GFP_KERNEL,
- page_order);
+ table = alloc_gatt_pages(page_order);
if (table == NULL) {
i++;
- switch (agp_bridge->driver->size_type) {
+ switch (bridge->driver->size_type) {
case U8_APER_SIZE:
- agp_bridge->current_size = A_IDX8(agp_bridge);
+ bridge->current_size = A_IDX8(bridge);
break;
case U16_APER_SIZE:
- agp_bridge->current_size = A_IDX16(agp_bridge);
+ bridge->current_size = A_IDX16(bridge);
break;
case U32_APER_SIZE:
- agp_bridge->current_size = A_IDX32(agp_bridge);
+ bridge->current_size = A_IDX32(bridge);
break;
/* This case will never really happen. */
case FIXED_APER_SIZE:
case LVL2_APER_SIZE:
default:
- agp_bridge->current_size =
- agp_bridge->current_size;
+ bridge->current_size =
+ bridge->current_size;
break;
}
- temp = agp_bridge->current_size;
+ temp = bridge->current_size;
} else {
- agp_bridge->aperture_size_idx = i;
+ bridge->aperture_size_idx = i;
}
- } while (!table && (i < agp_bridge->driver->num_aperture_sizes));
+ } while (!table && (i < bridge->driver->num_aperture_sizes));
} else {
size = ((struct aper_size_info_fixed *) temp)->size;
page_order = ((struct aper_size_info_fixed *) temp)->page_order;
num_entries = ((struct aper_size_info_fixed *) temp)->num_entries;
- table = (char *) __get_free_pages(GFP_KERNEL, page_order);
+ table = alloc_gatt_pages(page_order);
}
if (table == NULL)
for (page = virt_to_page(table); page <= virt_to_page(table_end); page++)
SetPageReserved(page);
- agp_bridge->gatt_table_real = (u32 *) table;
- agp_gatt_table = (void *)table;
+ bridge->gatt_table_real = (u32 *) table;
+ agp_gatt_table = (void *)table;
- agp_bridge->driver->cache_flush();
- agp_bridge->gatt_table = ioremap_nocache(virt_to_phys(table),
+ bridge->driver->cache_flush();
+ bridge->gatt_table = ioremap_nocache(virt_to_gart(table),
(PAGE_SIZE * (1 << page_order)));
- agp_bridge->driver->cache_flush();
+ bridge->driver->cache_flush();
- if (agp_bridge->gatt_table == NULL) {
+ if (bridge->gatt_table == NULL) {
for (page = virt_to_page(table); page <= virt_to_page(table_end); page++)
ClearPageReserved(page);
- free_pages((unsigned long) table, page_order);
+ free_gatt_pages(table, page_order);
return -ENOMEM;
}
- agp_bridge->gatt_bus_addr = virt_to_phys(agp_bridge->gatt_table_real);
+ bridge->gatt_bus_addr = virt_to_gart(bridge->gatt_table_real);
/* AK: bogus, should encode addresses > 4GB */
- for (i = 0; i < num_entries; i++)
- agp_bridge->gatt_table[i] = (unsigned long) agp_bridge->scratch_page;
+ for (i = 0; i < num_entries; i++) {
+ writel(bridge->scratch_page, bridge->gatt_table+i);
+ readl(bridge->gatt_table+i); /* PCI Posting. */
+ }
return 0;
}
EXPORT_SYMBOL(agp_generic_create_gatt_table);
-int agp_generic_free_gatt_table(void)
+int agp_generic_free_gatt_table(struct agp_bridge_data *bridge)
{
int page_order;
char *table, *table_end;
void *temp;
struct page *page;
- temp = agp_bridge->current_size;
+ temp = bridge->current_size;
- switch (agp_bridge->driver->size_type) {
+ switch (bridge->driver->size_type) {
case U8_APER_SIZE:
page_order = A_SIZE_8(temp)->page_order;
break;
* called, then all agp memory is deallocated and removed
* from the table. */
- iounmap(agp_bridge->gatt_table);
- table = (char *) agp_bridge->gatt_table_real;
+ iounmap(bridge->gatt_table);
+ table = (char *) bridge->gatt_table_real;
table_end = table + ((PAGE_SIZE * (1 << page_order)) - 1);
for (page = virt_to_page(table); page <= virt_to_page(table_end); page++)
ClearPageReserved(page);
- free_pages((unsigned long) agp_bridge->gatt_table_real, page_order);
+ free_gatt_pages(bridge->gatt_table_real, page_order);
agp_gatt_table = NULL;
- agp_bridge->gatt_table = NULL;
- agp_bridge->gatt_table_real = NULL;
- agp_bridge->gatt_bus_addr = 0;
+ bridge->gatt_table = NULL;
+ bridge->gatt_table_real = NULL;
+ bridge->gatt_bus_addr = 0;
return 0;
}
size_t i;
off_t j;
void *temp;
+ struct agp_bridge_data *bridge;
- temp = agp_bridge->current_size;
+ bridge = mem->bridge;
+ if (!bridge)
+ return -EINVAL;
- switch (agp_bridge->driver->size_type) {
+ temp = bridge->current_size;
+
+ switch (bridge->driver->size_type) {
case U8_APER_SIZE:
num_entries = A_SIZE_8(temp)->num_entries;
break;
j = pg_start;
while (j < (pg_start + mem->page_count)) {
- if (!PGE_EMPTY(agp_bridge, agp_bridge->gatt_table[j])) {
+ if (!PGE_EMPTY(bridge, readl(bridge->gatt_table+j)))
return -EBUSY;
- }
j++;
}
if (mem->is_flushed == FALSE) {
- agp_bridge->driver->cache_flush();
+ bridge->driver->cache_flush();
mem->is_flushed = TRUE;
}
- for (i = 0, j = pg_start; i < mem->page_count; i++, j++)
- agp_bridge->gatt_table[j] =
- agp_bridge->driver->mask_memory(
- mem->memory[i], mem->type);
+ for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
+ writel(bridge->driver->mask_memory(bridge, mem->memory[i], mem->type), bridge->gatt_table+j);
+ readl(bridge->gatt_table+j); /* PCI Posting. */
+ }
- agp_bridge->driver->tlb_flush(mem);
+ bridge->driver->tlb_flush(mem);
return 0;
}
EXPORT_SYMBOL(agp_generic_insert_memory);
int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
{
size_t i;
+ struct agp_bridge_data *bridge;
+
+ bridge = mem->bridge;
+ if (!bridge)
+ return -EINVAL;
if (type != 0 || mem->type != 0) {
/* The generic routines know nothing of memory types */
/* AK: bogus, should encode addresses > 4GB */
for (i = pg_start; i < (mem->page_count + pg_start); i++) {
- agp_bridge->gatt_table[i] =
- (unsigned long) agp_bridge->scratch_page;
+ writel(bridge->scratch_page, bridge->gatt_table+i);
+ readl(bridge->gatt_table+i); /* PCI Posting. */
}
- agp_bridge->driver->tlb_flush(mem);
+ global_cache_flush();
+ bridge->driver->tlb_flush(mem);
return 0;
}
EXPORT_SYMBOL(agp_generic_remove_memory);
void agp_generic_free_by_type(struct agp_memory *curr)
{
- if (curr->memory != NULL)
- vfree(curr->memory);
-
+ vfree(curr->memory);
agp_free_key(curr->key);
kfree(curr);
}
EXPORT_SYMBOL(agp_generic_free_by_type);
-/*
+/*
* Basic Page Allocation Routines -
- * These routines handle page allocation and by default they reserve the allocated
+ * These routines handle page allocation and by default they reserve the allocated
* memory. They also handle incrementing the current_memory_agp value, Which is checked
* against a maximum value.
*/
-void *agp_generic_alloc_page(void)
+void *agp_generic_alloc_page(struct agp_bridge_data *bridge)
{
struct page * page;
- page = alloc_page(GFP_KERNEL);
+ page = alloc_page(GFP_KERNEL | GFP_DMA32);
if (page == NULL)
- return 0;
+ return NULL;
map_page_into_agp(page);
/* End Basic Page Allocation Routines */
-/**
+/**
* agp_enable - initialise the agp point-to-point connection.
- *
+ *
* @mode: agp mode register value to configure with.
*/
-void agp_enable(u32 mode)
+void agp_enable(struct agp_bridge_data *bridge, u32 mode)
{
- if (agp_bridge->type == NOT_SUPPORTED)
+ if (!bridge)
return;
- agp_bridge->driver->agp_enable(mode);
+ bridge->driver->agp_enable(bridge, mode);
}
EXPORT_SYMBOL(agp_enable);
+/* When we remove the global variable agp_bridge from all drivers
+ * then agp_alloc_bridge and agp_generic_find_bridge need to be updated
+ */
+
+struct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev)
+{
+ if (list_empty(&agp_bridges))
+ return NULL;
+
+ return agp_bridge;
+}
-#ifdef CONFIG_SMP
static void ipi_handler(void *null)
{
flush_agp_cache();
}
-#endif
void global_cache_flush(void)
{
-#ifdef CONFIG_SMP
if (on_each_cpu(ipi_handler, NULL, 1, 1) != 0)
panic(PFX "timed out waiting for the other CPUs!\n");
-#else
- flush_agp_cache();
-#endif
}
EXPORT_SYMBOL(global_cache_flush);
-unsigned long agp_generic_mask_memory(unsigned long addr, int type)
+unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,
+ unsigned long addr, int type)
{
/* memory type is ignored in the generic routine */
- if (agp_bridge->driver->masks)
- return addr | agp_bridge->driver->masks[0].mask;
+ if (bridge->driver->masks)
+ return addr | bridge->driver->masks[0].mask;
else
return addr;
}