Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * AGPGART driver backend routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2004 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2002-2003 Dave Jones.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 1999 Jeff Hartmann.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 1999 Precision Insight, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 1999 Xi Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Permission is hereby granted, free of charge, to any person obtaining a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * copy of this software and associated documentation files (the "Software"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * to deal in the Software without restriction, including without limitation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * and/or sell copies of the Software, and to permit persons to whom the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * Software is furnished to do so, subject to the following conditions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * The above copyright notice and this permission notice shall be included
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * in all copies or substantial portions of the Software.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * JEFF HARTMANN, DAVE JONES, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * TODO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * - Allocate more than order 0 pages to avoid too much linear map splitting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/agp_backend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/agpgart.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include "agp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) /* Due to XFree86 brain-damage, we can't go to 1.0 until they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * fix some real stupidity. It's only by chance we can bump
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * past 0.99 at all due to some boolean logic error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define AGPGART_VERSION_MAJOR 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define AGPGART_VERSION_MINOR 103
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static const struct agp_version agp_current_version =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.major = AGPGART_VERSION_MAJOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.minor = AGPGART_VERSION_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) struct agp_bridge_data *(*agp_find_bridge)(struct pci_dev *) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	&agp_generic_find_bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) struct agp_bridge_data *agp_bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) LIST_HEAD(agp_bridges);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) EXPORT_SYMBOL(agp_bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) EXPORT_SYMBOL(agp_bridges);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) EXPORT_SYMBOL(agp_find_bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  *	agp_backend_acquire  -  attempt to acquire an agp backend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) struct agp_bridge_data *agp_backend_acquire(struct pci_dev *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct agp_bridge_data *bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	bridge = agp_find_bridge(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (!bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (atomic_read(&bridge->agp_in_use))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	atomic_inc(&bridge->agp_in_use);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) EXPORT_SYMBOL(agp_backend_acquire);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  *	agp_backend_release  -  release the lock on the agp backend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  *	The caller must insure that the graphics aperture translation table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  *	is read for use by another entity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  *	(Ensure that all memory it bound is unbound.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) void agp_backend_release(struct agp_bridge_data *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		atomic_dec(&bridge->agp_in_use);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) EXPORT_SYMBOL(agp_backend_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static const struct { int mem, agp; } maxes_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	{0, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	{32, 4},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	{64, 28},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	{128, 96},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	{256, 204},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	{512, 440},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	{1024, 942},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	{2048, 1920},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	{4096, 3932}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int agp_find_max(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	long memory, index, result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #if PAGE_SHIFT < 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	memory = totalram_pages() >> (20 - PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	memory = totalram_pages() << (PAGE_SHIFT - 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	while ((memory > maxes_table[index].mem) && (index < 8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	result = maxes_table[index - 1].agp +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	   ( (memory - maxes_table[index - 1].mem)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	     (maxes_table[index].agp - maxes_table[index - 1].agp)) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	   (maxes_table[index].mem - maxes_table[index - 1].mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	result = result << (20 - PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static int agp_backend_initialize(struct agp_bridge_data *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	int size_value, rc, got_gatt=0, got_keylist=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	bridge->max_memory_agp = agp_find_max();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	bridge->version = &agp_current_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (bridge->driver->needs_scratch_page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		struct page *page = bridge->driver->agp_alloc_page(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		if (!page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			dev_err(&bridge->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 				"can't get memory for scratch page\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		bridge->scratch_page_page = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		bridge->scratch_page_dma = page_to_phys(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		bridge->scratch_page = bridge->driver->mask_memory(bridge,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 						   bridge->scratch_page_dma, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	size_value = bridge->driver->fetch_size();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (size_value == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		dev_err(&bridge->dev->dev, "can't determine aperture size\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (bridge->driver->create_gatt_table(bridge)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		dev_err(&bridge->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			"can't get memory for graphics translation table\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	got_gatt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	bridge->key_list = vzalloc(PAGE_SIZE * 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (bridge->key_list == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		dev_err(&bridge->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			"can't allocate memory for key lists\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	got_keylist = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	/* FIXME vmalloc'd memory not guaranteed contiguous */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (bridge->driver->configure()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		dev_err(&bridge->dev->dev, "error configuring host chipset\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	INIT_LIST_HEAD(&bridge->mapped_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	spin_lock_init(&bridge->mapped_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (bridge->driver->needs_scratch_page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		struct page *page = bridge->scratch_page_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		bridge->driver->agp_destroy_page(page, AGP_PAGE_DESTROY_UNMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		bridge->driver->agp_destroy_page(page, AGP_PAGE_DESTROY_FREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (got_gatt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		bridge->driver->free_gatt_table(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (got_keylist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		vfree(bridge->key_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		bridge->key_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /* cannot be __exit b/c as it could be called from __init code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static void agp_backend_cleanup(struct agp_bridge_data *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (bridge->driver->cleanup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		bridge->driver->cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (bridge->driver->free_gatt_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		bridge->driver->free_gatt_table(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	vfree(bridge->key_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	bridge->key_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (bridge->driver->agp_destroy_page &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	    bridge->driver->needs_scratch_page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		struct page *page = bridge->scratch_page_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		bridge->driver->agp_destroy_page(page, AGP_PAGE_DESTROY_UNMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		bridge->driver->agp_destroy_page(page, AGP_PAGE_DESTROY_FREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /* When we remove the global variable agp_bridge from all drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * then agp_alloc_bridge and agp_generic_find_bridge need to be updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct agp_bridge_data *agp_alloc_bridge(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	struct agp_bridge_data *bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (!bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	atomic_set(&bridge->agp_in_use, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	atomic_set(&bridge->current_memory_agp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (list_empty(&agp_bridges))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		agp_bridge = bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	return bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) EXPORT_SYMBOL(agp_alloc_bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) void agp_put_bridge(struct agp_bridge_data *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)         kfree(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)         if (list_empty(&agp_bridges))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)                 agp_bridge = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) EXPORT_SYMBOL(agp_put_bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) int agp_add_bridge(struct agp_bridge_data *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (agp_off) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		goto err_put_bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (!bridge->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		printk (KERN_DEBUG PFX "Erk, registering with no pci_dev!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		goto err_put_bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	/* Grab reference on the chipset driver. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if (!try_module_get(bridge->driver->owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		dev_info(&bridge->dev->dev, "can't lock chipset driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		goto err_put_bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	error = agp_backend_initialize(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		dev_info(&bridge->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			 "agp_backend_initialize() failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (list_empty(&agp_bridges)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		error = agp_frontend_initialize();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			dev_info(&bridge->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 				 "agp_frontend_initialize() failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			goto frontend_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		dev_info(&bridge->dev->dev, "AGP aperture is %dM @ 0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			 bridge->driver->fetch_size(), bridge->gart_bus_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	list_add(&bridge->list, &agp_bridges);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) frontend_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	agp_backend_cleanup(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	module_put(bridge->driver->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) err_put_bridge:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	agp_put_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) EXPORT_SYMBOL_GPL(agp_add_bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) void agp_remove_bridge(struct agp_bridge_data *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	agp_backend_cleanup(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	list_del(&bridge->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (list_empty(&agp_bridges))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		agp_frontend_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	module_put(bridge->driver->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) EXPORT_SYMBOL_GPL(agp_remove_bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) int agp_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) int agp_try_unsupported_boot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) EXPORT_SYMBOL(agp_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) EXPORT_SYMBOL(agp_try_unsupported_boot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) static int __init agp_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	if (!agp_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		printk(KERN_INFO "Linux agpgart interface v%d.%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			AGPGART_VERSION_MAJOR, AGPGART_VERSION_MINOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static void __exit agp_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) #ifndef MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static __init int agp_setup(char *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (!strcmp(s,"off"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		agp_off = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (!strcmp(s,"try_unsupported"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		agp_try_unsupported_boot = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) __setup("agp=", agp_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) MODULE_AUTHOR("Dave Jones, Jeff Hartmann");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) MODULE_DESCRIPTION("AGP GART driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) MODULE_LICENSE("GPL and additional rights");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) MODULE_ALIAS_MISCDEV(AGPGART_MINOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) module_init(agp_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) module_exit(agp_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)