2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* AGPGART driver backend routines.
|
|
|
|
* Copyright (C) 2004 Silicon Graphics, Inc.
|
|
|
|
* Copyright (C) 2002-2003 Dave Jones.
|
|
|
|
* Copyright (C) 1999 Jeff Hartmann.
|
|
|
|
* Copyright (C) 1999 Precision Insight, Inc.
|
|
|
|
* Copyright (C) 1999 Xi Graphics, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* 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, DAVE JONES, 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:
|
|
|
|
* - Allocate more than order 0 pages to avoid too much linear map splitting.
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/init.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/pm.h>
|
|
|
|
#include <linux/agp_backend.h>
|
|
|
|
#include <linux/agpgart.h>
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include "agp.h"
|
|
|
|
|
|
|
|
/* Due to XFree86 brain-damage, we can't go to 1.0 until they
|
|
|
|
* fix some real stupidity. It's only by chance we can bump
|
|
|
|
* past 0.99 at all due to some boolean logic error. */
|
|
|
|
#define AGPGART_VERSION_MAJOR 0
|
2007-10-29 05:14:03 +00:00
|
|
|
#define AGPGART_VERSION_MINOR 103
|
2006-08-11 22:02:27 +00:00
|
|
|
static const struct agp_version agp_current_version =
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
.major = AGPGART_VERSION_MAJOR,
|
|
|
|
.minor = AGPGART_VERSION_MINOR,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct agp_bridge_data *(*agp_find_bridge)(struct pci_dev *) =
|
|
|
|
&agp_generic_find_bridge;
|
|
|
|
|
|
|
|
struct agp_bridge_data *agp_bridge;
|
|
|
|
LIST_HEAD(agp_bridges);
|
|
|
|
EXPORT_SYMBOL(agp_bridge);
|
|
|
|
EXPORT_SYMBOL(agp_bridges);
|
|
|
|
EXPORT_SYMBOL(agp_find_bridge);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* agp_backend_acquire - attempt to acquire an agp backend.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct agp_bridge_data *agp_backend_acquire(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct agp_bridge_data *bridge;
|
|
|
|
|
|
|
|
bridge = agp_find_bridge(pdev);
|
|
|
|
|
|
|
|
if (!bridge)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (atomic_read(&bridge->agp_in_use))
|
|
|
|
return NULL;
|
|
|
|
atomic_inc(&bridge->agp_in_use);
|
|
|
|
return bridge;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(agp_backend_acquire);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* agp_backend_release - release the lock on the agp backend.
|
|
|
|
*
|
|
|
|
* The caller must insure that the graphics aperture translation table
|
|
|
|
* is read for use by another entity.
|
|
|
|
*
|
|
|
|
* (Ensure that all memory it bound is unbound.)
|
|
|
|
*/
|
|
|
|
void agp_backend_release(struct agp_bridge_data *bridge)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (bridge)
|
|
|
|
atomic_dec(&bridge->agp_in_use);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(agp_backend_release);
|
|
|
|
|
|
|
|
|
2005-11-17 00:05:49 +00:00
|
|
|
static const struct { int mem, agp; } maxes_table[] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{0, 0},
|
|
|
|
{32, 4},
|
|
|
|
{64, 28},
|
|
|
|
{128, 96},
|
|
|
|
{256, 204},
|
|
|
|
{512, 440},
|
|
|
|
{1024, 942},
|
|
|
|
{2048, 1920},
|
|
|
|
{4096, 3932}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int agp_find_max(void)
|
|
|
|
{
|
|
|
|
long memory, index, result;
|
|
|
|
|
|
|
|
#if PAGE_SHIFT < 20
|
2009-09-22 00:03:05 +00:00
|
|
|
memory = totalram_pages >> (20 - PAGE_SHIFT);
|
2005-04-16 22:20:36 +00:00
|
|
|
#else
|
2009-09-22 00:03:05 +00:00
|
|
|
memory = totalram_pages << (PAGE_SHIFT - 20);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
index = 1;
|
|
|
|
|
|
|
|
while ((memory > maxes_table[index].mem) && (index < 8))
|
|
|
|
index++;
|
|
|
|
|
|
|
|
result = maxes_table[index - 1].agp +
|
|
|
|
( (memory - maxes_table[index - 1].mem) *
|
|
|
|
(maxes_table[index].agp - maxes_table[index - 1].agp)) /
|
|
|
|
(maxes_table[index].mem - maxes_table[index - 1].mem);
|
|
|
|
|
|
|
|
result = result << (20 - PAGE_SHIFT);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int agp_backend_initialize(struct agp_bridge_data *bridge)
|
|
|
|
{
|
|
|
|
int size_value, rc, got_gatt=0, got_keylist=0;
|
|
|
|
|
|
|
|
bridge->max_memory_agp = agp_find_max();
|
|
|
|
bridge->version = &agp_current_version;
|
|
|
|
|
|
|
|
if (bridge->driver->needs_scratch_page) {
|
2009-06-12 04:11:41 +00:00
|
|
|
struct page *page = bridge->driver->agp_alloc_page(bridge);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-06-12 04:11:41 +00:00
|
|
|
if (!page) {
|
2008-07-30 19:26:51 +00:00
|
|
|
dev_err(&bridge->dev->dev,
|
|
|
|
"can't get memory for scratch page\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2009-07-29 07:39:26 +00:00
|
|
|
bridge->scratch_page_page = page;
|
2010-09-09 16:17:34 +00:00
|
|
|
bridge->scratch_page_dma = page_to_phys(page);
|
2009-07-27 15:44:32 +00:00
|
|
|
|
|
|
|
bridge->scratch_page = bridge->driver->mask_memory(bridge,
|
|
|
|
bridge->scratch_page_dma, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_value = bridge->driver->fetch_size();
|
|
|
|
if (size_value == 0) {
|
2008-07-30 19:26:51 +00:00
|
|
|
dev_err(&bridge->dev->dev, "can't determine aperture size\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
if (bridge->driver->create_gatt_table(bridge)) {
|
2008-07-30 19:26:51 +00:00
|
|
|
dev_err(&bridge->dev->dev,
|
|
|
|
"can't get memory for graphics translation table\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
got_gatt = 1;
|
|
|
|
|
2011-05-28 17:36:25 +00:00
|
|
|
bridge->key_list = vzalloc(PAGE_SIZE * 4);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (bridge->key_list == NULL) {
|
2008-07-30 19:26:51 +00:00
|
|
|
dev_err(&bridge->dev->dev,
|
|
|
|
"can't allocate memory for key lists\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
got_keylist = 1;
|
|
|
|
|
|
|
|
/* FIXME vmalloc'd memory not guaranteed contiguous */
|
|
|
|
|
|
|
|
if (bridge->driver->configure()) {
|
2008-07-30 19:26:51 +00:00
|
|
|
dev_err(&bridge->dev->dev, "error configuring host chipset\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto err_out;
|
|
|
|
}
|
2008-07-31 05:48:07 +00:00
|
|
|
INIT_LIST_HEAD(&bridge->mapped_list);
|
|
|
|
spin_lock_init(&bridge->mapped_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_out:
|
2005-11-07 07:35:34 +00:00
|
|
|
if (bridge->driver->needs_scratch_page) {
|
2012-01-25 15:51:05 +00:00
|
|
|
struct page *page = bridge->scratch_page_page;
|
2008-06-18 08:28:00 +00:00
|
|
|
|
2012-01-25 15:51:05 +00:00
|
|
|
bridge->driver->agp_destroy_page(page, AGP_PAGE_DESTROY_UNMAP);
|
|
|
|
bridge->driver->agp_destroy_page(page, AGP_PAGE_DESTROY_FREE);
|
2005-11-07 07:35:34 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
if (got_gatt)
|
|
|
|
bridge->driver->free_gatt_table(bridge);
|
|
|
|
if (got_keylist) {
|
|
|
|
vfree(bridge->key_list);
|
|
|
|
bridge->key_list = NULL;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cannot be __exit b/c as it could be called from __init code */
|
|
|
|
static void agp_backend_cleanup(struct agp_bridge_data *bridge)
|
|
|
|
{
|
|
|
|
if (bridge->driver->cleanup)
|
|
|
|
bridge->driver->cleanup();
|
|
|
|
if (bridge->driver->free_gatt_table)
|
|
|
|
bridge->driver->free_gatt_table(bridge);
|
2005-09-10 07:26:54 +00:00
|
|
|
|
|
|
|
vfree(bridge->key_list);
|
|
|
|
bridge->key_list = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (bridge->driver->agp_destroy_page &&
|
2005-11-07 07:35:34 +00:00
|
|
|
bridge->driver->needs_scratch_page) {
|
2012-01-25 15:51:05 +00:00
|
|
|
struct page *page = bridge->scratch_page_page;
|
2008-06-18 08:28:00 +00:00
|
|
|
|
2012-01-25 15:51:05 +00:00
|
|
|
bridge->driver->agp_destroy_page(page, AGP_PAGE_DESTROY_UNMAP);
|
|
|
|
bridge->driver->agp_destroy_page(page, AGP_PAGE_DESTROY_FREE);
|
2005-11-07 07:35:34 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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_alloc_bridge(void)
|
|
|
|
{
|
2005-10-20 22:12:16 +00:00
|
|
|
struct agp_bridge_data *bridge;
|
2006-02-28 05:54:25 +00:00
|
|
|
|
2005-10-20 22:12:16 +00:00
|
|
|
bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!bridge)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
atomic_set(&bridge->agp_in_use, 0);
|
|
|
|
atomic_set(&bridge->current_memory_agp, 0);
|
|
|
|
|
|
|
|
if (list_empty(&agp_bridges))
|
|
|
|
agp_bridge = bridge;
|
|
|
|
|
|
|
|
return bridge;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(agp_alloc_bridge);
|
|
|
|
|
|
|
|
|
|
|
|
void agp_put_bridge(struct agp_bridge_data *bridge)
|
|
|
|
{
|
|
|
|
kfree(bridge);
|
|
|
|
|
|
|
|
if (list_empty(&agp_bridges))
|
|
|
|
agp_bridge = NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(agp_put_bridge);
|
|
|
|
|
|
|
|
|
|
|
|
int agp_add_bridge(struct agp_bridge_data *bridge)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2009-11-17 22:38:45 +00:00
|
|
|
if (agp_off) {
|
|
|
|
error = -ENODEV;
|
|
|
|
goto err_put_bridge;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!bridge->dev) {
|
|
|
|
printk (KERN_DEBUG PFX "Erk, registering with no pci_dev!\n");
|
2009-11-17 22:38:45 +00:00
|
|
|
error = -EINVAL;
|
|
|
|
goto err_put_bridge;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Grab reference on the chipset driver. */
|
|
|
|
if (!try_module_get(bridge->driver->owner)) {
|
2008-07-30 19:26:51 +00:00
|
|
|
dev_info(&bridge->dev->dev, "can't lock chipset driver\n");
|
2009-11-17 22:38:45 +00:00
|
|
|
error = -EINVAL;
|
|
|
|
goto err_put_bridge;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error = agp_backend_initialize(bridge);
|
|
|
|
if (error) {
|
2008-07-30 19:26:51 +00:00
|
|
|
dev_info(&bridge->dev->dev,
|
|
|
|
"agp_backend_initialize() failed\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list_empty(&agp_bridges)) {
|
|
|
|
error = agp_frontend_initialize();
|
|
|
|
if (error) {
|
2008-07-30 19:26:51 +00:00
|
|
|
dev_info(&bridge->dev->dev,
|
|
|
|
"agp_frontend_initialize() failed\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto frontend_err;
|
|
|
|
}
|
|
|
|
|
2008-07-30 19:26:51 +00:00
|
|
|
dev_info(&bridge->dev->dev, "AGP aperture is %dM @ 0x%lx\n",
|
|
|
|
bridge->driver->fetch_size(), bridge->gart_bus_addr);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add(&bridge->list, &agp_bridges);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
frontend_err:
|
|
|
|
agp_backend_cleanup(bridge);
|
|
|
|
err_out:
|
|
|
|
module_put(bridge->driver->owner);
|
2009-11-17 22:38:45 +00:00
|
|
|
err_put_bridge:
|
2005-04-16 22:20:36 +00:00
|
|
|
agp_put_bridge(bridge);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(agp_add_bridge);
|
|
|
|
|
|
|
|
|
|
|
|
void agp_remove_bridge(struct agp_bridge_data *bridge)
|
|
|
|
{
|
|
|
|
agp_backend_cleanup(bridge);
|
|
|
|
list_del(&bridge->list);
|
|
|
|
if (list_empty(&agp_bridges))
|
|
|
|
agp_frontend_cleanup();
|
|
|
|
module_put(bridge->driver->owner);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(agp_remove_bridge);
|
|
|
|
|
|
|
|
int agp_off;
|
|
|
|
int agp_try_unsupported_boot;
|
|
|
|
EXPORT_SYMBOL(agp_off);
|
|
|
|
EXPORT_SYMBOL(agp_try_unsupported_boot);
|
|
|
|
|
|
|
|
static int __init agp_init(void)
|
|
|
|
{
|
|
|
|
if (!agp_off)
|
2007-07-10 00:23:50 +00:00
|
|
|
printk(KERN_INFO "Linux agpgart interface v%d.%d\n",
|
2005-04-16 22:20:36 +00:00
|
|
|
AGPGART_VERSION_MAJOR, AGPGART_VERSION_MINOR);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-01 15:59:29 +00:00
|
|
|
static void __exit agp_exit(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef MODULE
|
|
|
|
static __init int agp_setup(char *s)
|
|
|
|
{
|
|
|
|
if (!strcmp(s,"off"))
|
|
|
|
agp_off = 1;
|
|
|
|
if (!strcmp(s,"try_unsupported"))
|
|
|
|
agp_try_unsupported_boot = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("agp=", agp_setup);
|
|
|
|
#endif
|
|
|
|
|
2014-12-19 16:23:50 +00:00
|
|
|
MODULE_AUTHOR("Dave Jones, Jeff Hartmann");
|
2005-04-16 22:20:36 +00:00
|
|
|
MODULE_DESCRIPTION("AGP GART driver");
|
|
|
|
MODULE_LICENSE("GPL and additional rights");
|
|
|
|
MODULE_ALIAS_MISCDEV(AGPGART_MINOR);
|
|
|
|
|
|
|
|
module_init(agp_init);
|
|
|
|
module_exit(agp_exit);
|
|
|
|
|