xref: /freebsd-src/sys/dev/agp/agpvar.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
159747216SDoug Rabson /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
459747216SDoug Rabson  * Copyright (c) 2000 Doug Rabson
559747216SDoug Rabson  * All rights reserved.
659747216SDoug Rabson  *
759747216SDoug Rabson  * Redistribution and use in source and binary forms, with or without
859747216SDoug Rabson  * modification, are permitted provided that the following conditions
959747216SDoug Rabson  * are met:
1059747216SDoug Rabson  * 1. Redistributions of source code must retain the above copyright
1159747216SDoug Rabson  *    notice, this list of conditions and the following disclaimer.
1259747216SDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
1359747216SDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
1459747216SDoug Rabson  *    documentation and/or other materials provided with the distribution.
1559747216SDoug Rabson  *
1659747216SDoug Rabson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1759747216SDoug Rabson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1859747216SDoug Rabson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1959747216SDoug Rabson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2059747216SDoug Rabson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2159747216SDoug Rabson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2259747216SDoug Rabson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2359747216SDoug Rabson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2459747216SDoug Rabson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2559747216SDoug Rabson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2659747216SDoug Rabson  * SUCH DAMAGE.
2759747216SDoug Rabson  */
2859747216SDoug Rabson 
2959747216SDoug Rabson #ifndef _PCI_AGPVAR_H_
3059747216SDoug Rabson #define _PCI_AGPVAR_H_
3159747216SDoug Rabson 
3259747216SDoug Rabson /*
3359747216SDoug Rabson  * The AGP chipset can be acquired by user or kernel code. If the
3459747216SDoug Rabson  * chipset has already been acquired, it cannot be acquired by another
3559747216SDoug Rabson  * user until the previous user has released it.
3659747216SDoug Rabson  */
3759747216SDoug Rabson enum agp_acquire_state {
3859747216SDoug Rabson 	AGP_ACQUIRE_FREE,
3959747216SDoug Rabson 	AGP_ACQUIRE_USER,
4059747216SDoug Rabson 	AGP_ACQUIRE_KERNEL
4159747216SDoug Rabson };
4259747216SDoug Rabson 
4359747216SDoug Rabson /*
4459747216SDoug Rabson  * This structure is used to query the state of the AGP system.
4559747216SDoug Rabson  */
4659747216SDoug Rabson struct agp_info {
4759747216SDoug Rabson 	u_int32_t	ai_mode;
4859747216SDoug Rabson 	vm_offset_t	ai_aperture_base;
4959747216SDoug Rabson 	vm_size_t	ai_aperture_size;
5059747216SDoug Rabson 	vm_size_t	ai_memory_allowed;
5159747216SDoug Rabson 	vm_size_t	ai_memory_used;
5259747216SDoug Rabson 	u_int32_t	ai_devid;
5359747216SDoug Rabson };
5459747216SDoug Rabson 
5559747216SDoug Rabson struct agp_memory_info {
5659747216SDoug Rabson 	vm_size_t	ami_size;	/* size in bytes */
5759747216SDoug Rabson 	vm_offset_t	ami_physical;	/* bogus hack for i810 */
5859747216SDoug Rabson 	vm_offset_t	ami_offset;	/* page offset if bound */
5959747216SDoug Rabson 	int		ami_is_bound;	/* non-zero if bound */
6059747216SDoug Rabson };
6159747216SDoug Rabson 
6259747216SDoug Rabson /*
6359747216SDoug Rabson  * Find the AGP device and return it.
6459747216SDoug Rabson  */
6559747216SDoug Rabson device_t agp_find_device(void);
6659747216SDoug Rabson 
6759747216SDoug Rabson /*
6859747216SDoug Rabson  * Return the current owner of the AGP chipset.
6959747216SDoug Rabson  */
7059747216SDoug Rabson enum agp_acquire_state agp_state(device_t dev);
7159747216SDoug Rabson 
7259747216SDoug Rabson /*
7359747216SDoug Rabson  * Query the state of the AGP system.
7459747216SDoug Rabson  */
7559747216SDoug Rabson void agp_get_info(device_t dev, struct agp_info *info);
7659747216SDoug Rabson 
7759747216SDoug Rabson /*
7859747216SDoug Rabson  * Acquire the AGP chipset for use by the kernel. Returns EBUSY if the
7959747216SDoug Rabson  * AGP chipset is already acquired by another user.
8059747216SDoug Rabson  */
8159747216SDoug Rabson int agp_acquire(device_t dev);
8259747216SDoug Rabson 
8359747216SDoug Rabson /*
8459747216SDoug Rabson  * Release the AGP chipset.
8559747216SDoug Rabson  */
8659747216SDoug Rabson int agp_release(device_t dev);
8759747216SDoug Rabson 
8859747216SDoug Rabson /*
8959747216SDoug Rabson  * Enable the agp hardware with the relavent mode. The mode bits are
90dbac8ff4SJohn Baldwin  * defined in <dev/agp/agpreg.h>
9159747216SDoug Rabson  */
9259747216SDoug Rabson int agp_enable(device_t dev, u_int32_t mode);
9359747216SDoug Rabson 
9459747216SDoug Rabson /*
9559747216SDoug Rabson  * Allocate physical memory suitable for mapping into the AGP
9659747216SDoug Rabson  * aperture.  The value returned is an opaque handle which can be
9759747216SDoug Rabson  * passed to agp_bind(), agp_unbind() or agp_deallocate().
9859747216SDoug Rabson  */
9959747216SDoug Rabson void *agp_alloc_memory(device_t dev, int type, vm_size_t bytes);
10059747216SDoug Rabson 
10159747216SDoug Rabson /*
10259747216SDoug Rabson  * Free memory which was allocated with agp_allocate().
10359747216SDoug Rabson  */
10459747216SDoug Rabson void agp_free_memory(device_t dev, void *handle);
10559747216SDoug Rabson 
10659747216SDoug Rabson /*
10759747216SDoug Rabson  * Bind memory allocated with agp_allocate() at a given offset within
10859747216SDoug Rabson  * the AGP aperture. Returns EINVAL if the memory is already bound or
10959747216SDoug Rabson  * the offset is not at an AGP page boundary.
11059747216SDoug Rabson  */
11159747216SDoug Rabson int agp_bind_memory(device_t dev, void *handle, vm_offset_t offset);
11259747216SDoug Rabson 
11359747216SDoug Rabson /*
11459747216SDoug Rabson  * Unbind memory from the AGP aperture. Returns EINVAL if the memory
11559747216SDoug Rabson  * is not bound.
11659747216SDoug Rabson  */
11759747216SDoug Rabson int agp_unbind_memory(device_t dev, void *handle);
11859747216SDoug Rabson 
11959747216SDoug Rabson /*
12059747216SDoug Rabson  * Retrieve information about a memory block allocated with
12159747216SDoug Rabson  * agp_alloc_memory().
12259747216SDoug Rabson  */
12359747216SDoug Rabson void agp_memory_info(device_t dev, void *handle, struct agp_memory_info *mi);
12459747216SDoug Rabson 
125903fb143STijl Coosemans /*
126903fb143STijl Coosemans  * Bind a set of pages at a given offset within the AGP aperture.
127903fb143STijl Coosemans  * Returns EINVAL if the given size or offset is not at an AGP page boundary.
128903fb143STijl Coosemans  */
129903fb143STijl Coosemans int agp_bind_pages(device_t dev, vm_page_t *pages, vm_size_t size,
130903fb143STijl Coosemans 		   vm_offset_t offset);
131903fb143STijl Coosemans 
132903fb143STijl Coosemans /*
133903fb143STijl Coosemans  * Unbind a set of pages from the AGP aperture.
134903fb143STijl Coosemans  * Returns EINVAL if the given size or offset is not at an AGP page boundary.
135903fb143STijl Coosemans  */
136903fb143STijl Coosemans int agp_unbind_pages(device_t dev, vm_size_t size, vm_offset_t offset);
137903fb143STijl Coosemans 
13828d86329SKonstantin Belousov #define AGP_NORMAL_MEMORY 0
13928d86329SKonstantin Belousov 
14028d86329SKonstantin Belousov #define AGP_USER_TYPES (1 << 16)
14128d86329SKonstantin Belousov #define AGP_USER_MEMORY (AGP_USER_TYPES)
14228d86329SKonstantin Belousov #define AGP_USER_CACHED_MEMORY (AGP_USER_TYPES + 1)
14328d86329SKonstantin Belousov 
14459747216SDoug Rabson #endif /* !_PCI_AGPVAR_H_ */
145