Release 4.7 drivers/char/agp/backend.c
  
  
/*
 * 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 <linux/slab.h>
#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
#define AGPGART_VERSION_MINOR 103
static const struct agp_version agp_current_version =
{
	.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;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dave jones | dave jones | 56 | 100.00% | 5 | 100.00% | 
 | Total | 56 | 100.00% | 5 | 100.00% | 
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);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dave jones | dave jones | 22 | 100.00% | 3 | 100.00% | 
 | Total | 22 | 100.00% | 3 | 100.00% | 
EXPORT_SYMBOL(agp_backend_release);
static const struct { int mem, agp; } maxes_table[] = {
	{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
	memory = totalram_pages >> (20 - PAGE_SHIFT);
#else
	memory = totalram_pages << (PAGE_SHIFT - 20);
#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;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dave jones | dave jones | 140 | 96.55% | 2 | 50.00% | 
| bjorn helgaas | bjorn helgaas | 3 | 2.07% | 1 | 25.00% | 
| jan beulich | jan beulich | 2 | 1.38% | 1 | 25.00% | 
 | Total | 145 | 100.00% | 4 | 100.00% | 
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) {
		struct page *page = bridge->driver->agp_alloc_page(bridge);
		if (!page) {
			dev_err(&bridge->dev->dev,
				"can't get memory for scratch page\n");
			return -ENOMEM;
		}
		bridge->scratch_page_page = page;
		bridge->scratch_page_dma = page_to_phys(page);
		bridge->scratch_page = bridge->driver->mask_memory(bridge,
						   bridge->scratch_page_dma, 0);
	}
	size_value = bridge->driver->fetch_size();
	if (size_value == 0) {
		dev_err(&bridge->dev->dev, "can't determine aperture size\n");
		rc = -EINVAL;
		goto err_out;
	}
	if (bridge->driver->create_gatt_table(bridge)) {
		dev_err(&bridge->dev->dev,
			"can't get memory for graphics translation table\n");
		rc = -ENOMEM;
		goto err_out;
	}
	got_gatt = 1;
	bridge->key_list = vzalloc(PAGE_SIZE * 4);
	if (bridge->key_list == NULL) {
		dev_err(&bridge->dev->dev,
			"can't allocate memory for key lists\n");
		rc = -ENOMEM;
		goto err_out;
	}
	got_keylist = 1;
	/* FIXME vmalloc'd memory not guaranteed contiguous */
	if (bridge->driver->configure()) {
		dev_err(&bridge->dev->dev, "error configuring host chipset\n");
		rc = -EINVAL;
		goto err_out;
	}
	INIT_LIST_HEAD(&bridge->mapped_list);
	spin_lock_init(&bridge->mapped_lock);
	return 0;
err_out:
	if (bridge->driver->needs_scratch_page) {
		struct page *page = bridge->scratch_page_page;
		bridge->driver->agp_destroy_page(page, AGP_PAGE_DESTROY_UNMAP);
		bridge->driver->agp_destroy_page(page, AGP_PAGE_DESTROY_FREE);
	}
	if (got_gatt)
		bridge->driver->free_gatt_table(bridge);
	if (got_keylist) {
		vfree(bridge->key_list);
		bridge->key_list = NULL;
	}
	return rc;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dave jones | dave jones | 236 | 64.31% | 7 | 41.18% | 
| bjorn helgaas | bjorn helgaas | 50 | 13.62% | 1 | 5.88% | 
| david woodhouse | david woodhouse | 31 | 8.45% | 2 | 11.76% | 
| dave airlie | dave airlie | 17 | 4.63% | 2 | 11.76% | 
| keith packard | keith packard | 16 | 4.36% | 1 | 5.88% | 
| jan beulich | jan beulich | 9 | 2.45% | 1 | 5.88% | 
| michal kubecek | michal kubecek | 5 | 1.36% | 1 | 5.88% | 
| alan hourihane | alan hourihane | 2 | 0.54% | 1 | 5.88% | 
| joe perches | joe perches | 1 | 0.27% | 1 | 5.88% | 
 | Total | 367 | 100.00% | 17 | 100.00% | 
/* 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);
	vfree(bridge->key_list);
	bridge->key_list = NULL;
	if (bridge->driver->agp_destroy_page &&
	    bridge->driver->needs_scratch_page) {
		struct page *page = bridge->scratch_page_page;
		bridge->driver->agp_destroy_page(page, AGP_PAGE_DESTROY_UNMAP);
		bridge->driver->agp_destroy_page(page, AGP_PAGE_DESTROY_FREE);
	}
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dave jones | dave jones | 74 | 71.84% | 7 | 58.33% | 
| dave airlie | dave airlie | 12 | 11.65% | 1 | 8.33% | 
| jan beulich | jan beulich | 9 | 8.74% | 1 | 8.33% | 
| michal kubecek | michal kubecek | 5 | 4.85% | 1 | 8.33% | 
| alan hourihane | alan hourihane | 2 | 1.94% | 1 | 8.33% | 
| david woodhouse | david woodhouse | 1 | 0.97% | 1 | 8.33% | 
 | Total | 103 | 100.00% | 12 | 100.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)
{
	struct agp_bridge_data *bridge;
	bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
	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;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dave jones | dave jones | 70 | 100.00% | 3 | 100.00% | 
 | Total | 70 | 100.00% | 3 | 100.00% | 
EXPORT_SYMBOL(agp_alloc_bridge);
void agp_put_bridge(struct agp_bridge_data *bridge)
{
        kfree(bridge);
        if (list_empty(&agp_bridges))
                agp_bridge = NULL;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dave jones | dave jones | 27 | 100.00% | 2 | 100.00% | 
 | Total | 27 | 100.00% | 2 | 100.00% | 
EXPORT_SYMBOL(agp_put_bridge);
int agp_add_bridge(struct agp_bridge_data *bridge)
{
	int error;
	if (agp_off) {
		error = -ENODEV;
		goto err_put_bridge;
	}
	if (!bridge->dev) {
		printk (KERN_DEBUG PFX "Erk, registering with no pci_dev!\n");
		error = -EINVAL;
		goto err_put_bridge;
	}
	/* Grab reference on the chipset driver. */
	if (!try_module_get(bridge->driver->owner)) {
		dev_info(&bridge->dev->dev, "can't lock chipset driver\n");
		error = -EINVAL;
		goto err_put_bridge;
	}
	error = agp_backend_initialize(bridge);
	if (error) {
		dev_info(&bridge->dev->dev,
			 "agp_backend_initialize() failed\n");
		goto err_out;
	}
	if (list_empty(&agp_bridges)) {
		error = agp_frontend_initialize();
		if (error) {
			dev_info(&bridge->dev->dev,
				 "agp_frontend_initialize() failed\n");
			goto frontend_err;
		}
		dev_info(&bridge->dev->dev, "AGP aperture is %dM @ 0x%lx\n",
			 bridge->driver->fetch_size(), bridge->gart_bus_addr);
	}
	list_add(&bridge->list, &agp_bridges);
	return 0;
frontend_err:
	agp_backend_cleanup(bridge);
err_out:
	module_put(bridge->driver->owner);
err_put_bridge:
	agp_put_bridge(bridge);
	return error;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dave jones | dave jones | 144 | 67.29% | 7 | 77.78% | 
| bjorn helgaas | bjorn helgaas | 48 | 22.43% | 1 | 11.11% | 
| kevin winchester | kevin winchester | 22 | 10.28% | 1 | 11.11% | 
 | Total | 214 | 100.00% | 9 | 100.00% | 
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);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dave jones | dave jones | 43 | 100.00% | 5 | 100.00% | 
 | Total | 43 | 100.00% | 5 | 100.00% | 
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)
		printk(KERN_INFO "Linux agpgart interface v%d.%d\n",
			AGPGART_VERSION_MAJOR, AGPGART_VERSION_MINOR);
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dave jones | dave jones | 27 | 100.00% | 4 | 100.00% | 
 | Total | 27 | 100.00% | 4 | 100.00% | 
static void __exit agp_exit(void)
{
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dave jones | dave jones | 7 | 87.50% | 1 | 50.00% | 
| adrian bunk | adrian bunk | 1 | 12.50% | 1 | 50.00% | 
 | Total | 8 | 100.00% | 2 | 100.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;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dave jones | dave jones | 42 | 100.00% | 1 | 100.00% | 
 | Total | 42 | 100.00% | 1 | 100.00% | 
__setup("agp=", agp_setup);
#endif
MODULE_AUTHOR("Dave Jones, Jeff Hartmann");
MODULE_DESCRIPTION("AGP GART driver");
MODULE_LICENSE("GPL and additional rights");
MODULE_ALIAS_MISCDEV(AGPGART_MINOR);
module_init(agp_init);
module_exit(agp_exit);
Overall Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dave jones | dave jones | 1128 | 81.15% | 27 | 56.25% | 
| bjorn helgaas | bjorn helgaas | 101 | 7.27% | 2 | 4.17% | 
| dave airlie | dave airlie | 35 | 2.52% | 4 | 8.33% | 
| david woodhouse | david woodhouse | 32 | 2.30% | 2 | 4.17% | 
| kevin winchester | kevin winchester | 22 | 1.58% | 1 | 2.08% | 
| jan beulich | jan beulich | 20 | 1.44% | 2 | 4.17% | 
| keith packard | keith packard | 16 | 1.15% | 1 | 2.08% | 
| michal kubecek | michal kubecek | 10 | 0.72% | 1 | 2.08% | 
| andrew morton | andrew morton | 10 | 0.72% | 3 | 6.25% | 
| falk huffner | falk huffner | 6 | 0.43% | 1 | 2.08% | 
| alan hourihane | alan hourihane | 4 | 0.29% | 1 | 2.08% | 
| tejun heo | tejun heo | 3 | 0.22% | 1 | 2.08% | 
| adrian bunk | adrian bunk | 2 | 0.14% | 1 | 2.08% | 
| joe perches | joe perches | 1 | 0.07% | 1 | 2.08% | 
 | Total | 1390 | 100.00% | 48 | 100.00% | 
  
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.