xref: /freebsd/sys/dev/agp/agpvar.h (revision 3c4ba5f55438f7afd4f4b0b56f88f2bb505fd6a6)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2000 Doug Rabson
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  *	$FreeBSD$
29  */
30 
31 #ifndef _PCI_AGPVAR_H_
32 #define _PCI_AGPVAR_H_
33 
34 /*
35  * The AGP chipset can be acquired by user or kernel code. If the
36  * chipset has already been acquired, it cannot be acquired by another
37  * user until the previous user has released it.
38  */
39 enum agp_acquire_state {
40 	AGP_ACQUIRE_FREE,
41 	AGP_ACQUIRE_USER,
42 	AGP_ACQUIRE_KERNEL
43 };
44 
45 /*
46  * This structure is used to query the state of the AGP system.
47  */
48 struct agp_info {
49 	u_int32_t	ai_mode;
50 	vm_offset_t	ai_aperture_base;
51 	vm_size_t	ai_aperture_size;
52 	vm_size_t	ai_memory_allowed;
53 	vm_size_t	ai_memory_used;
54 	u_int32_t	ai_devid;
55 };
56 
57 struct agp_memory_info {
58 	vm_size_t	ami_size;	/* size in bytes */
59 	vm_offset_t	ami_physical;	/* bogus hack for i810 */
60 	vm_offset_t	ami_offset;	/* page offset if bound */
61 	int		ami_is_bound;	/* non-zero if bound */
62 };
63 
64 /*
65  * Find the AGP device and return it.
66  */
67 device_t agp_find_device(void);
68 
69 /*
70  * Return the current owner of the AGP chipset.
71  */
72 enum agp_acquire_state agp_state(device_t dev);
73 
74 /*
75  * Query the state of the AGP system.
76  */
77 void agp_get_info(device_t dev, struct agp_info *info);
78 
79 /*
80  * Acquire the AGP chipset for use by the kernel. Returns EBUSY if the
81  * AGP chipset is already acquired by another user.
82  */
83 int agp_acquire(device_t dev);
84 
85 /*
86  * Release the AGP chipset.
87  */
88 int agp_release(device_t dev);
89 
90 /*
91  * Enable the agp hardware with the relavent mode. The mode bits are
92  * defined in <dev/agp/agpreg.h>
93  */
94 int agp_enable(device_t dev, u_int32_t mode);
95 
96 /*
97  * Allocate physical memory suitable for mapping into the AGP
98  * aperture.  The value returned is an opaque handle which can be
99  * passed to agp_bind(), agp_unbind() or agp_deallocate().
100  */
101 void *agp_alloc_memory(device_t dev, int type, vm_size_t bytes);
102 
103 /*
104  * Free memory which was allocated with agp_allocate().
105  */
106 void agp_free_memory(device_t dev, void *handle);
107 
108 /*
109  * Bind memory allocated with agp_allocate() at a given offset within
110  * the AGP aperture. Returns EINVAL if the memory is already bound or
111  * the offset is not at an AGP page boundary.
112  */
113 int agp_bind_memory(device_t dev, void *handle, vm_offset_t offset);
114 
115 /*
116  * Unbind memory from the AGP aperture. Returns EINVAL if the memory
117  * is not bound.
118  */
119 int agp_unbind_memory(device_t dev, void *handle);
120 
121 /*
122  * Retrieve information about a memory block allocated with
123  * agp_alloc_memory().
124  */
125 void agp_memory_info(device_t dev, void *handle, struct agp_memory_info *mi);
126 
127 /*
128  * Bind a set of pages at a given offset within the AGP aperture.
129  * Returns EINVAL if the given size or offset is not at an AGP page boundary.
130  */
131 int agp_bind_pages(device_t dev, vm_page_t *pages, vm_size_t size,
132 		   vm_offset_t offset);
133 
134 /*
135  * Unbind a set of pages from the AGP aperture.
136  * Returns EINVAL if the given size or offset is not at an AGP page boundary.
137  */
138 int agp_unbind_pages(device_t dev, vm_size_t size, vm_offset_t offset);
139 
140 #define AGP_NORMAL_MEMORY 0
141 
142 #define AGP_USER_TYPES (1 << 16)
143 #define AGP_USER_MEMORY (AGP_USER_TYPES)
144 #define AGP_USER_CACHED_MEMORY (AGP_USER_TYPES + 1)
145 
146 #endif /* !_PCI_AGPVAR_H_ */
147