161452Sdfr/*-
261452Sdfr * Copyright (c) 2000 Doug Rabson
361452Sdfr * All rights reserved.
461452Sdfr *
561452Sdfr * Redistribution and use in source and binary forms, with or without
661452Sdfr * modification, are permitted provided that the following conditions
761452Sdfr * are met:
861452Sdfr * 1. Redistributions of source code must retain the above copyright
961452Sdfr *    notice, this list of conditions and the following disclaimer.
1061452Sdfr * 2. Redistributions in binary form must reproduce the above copyright
1161452Sdfr *    notice, this list of conditions and the following disclaimer in the
1261452Sdfr *    documentation and/or other materials provided with the distribution.
1361452Sdfr *
1461452Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1561452Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1661452Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1761452Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1861452Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1961452Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2061452Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2161452Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2261452Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2361452Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2461452Sdfr * SUCH DAMAGE.
2561452Sdfr *
2661452Sdfr *	$FreeBSD$
2761452Sdfr */
2861452Sdfr
2961452Sdfr#ifndef _PCI_AGPVAR_H_
3061452Sdfr#define _PCI_AGPVAR_H_
3161452Sdfr
3261452Sdfr/*
3361452Sdfr * The AGP chipset can be acquired by user or kernel code. If the
3461452Sdfr * chipset has already been acquired, it cannot be acquired by another
3561452Sdfr * user until the previous user has released it.
3661452Sdfr */
3761452Sdfrenum agp_acquire_state {
3861452Sdfr	AGP_ACQUIRE_FREE,
3961452Sdfr	AGP_ACQUIRE_USER,
4061452Sdfr	AGP_ACQUIRE_KERNEL
4161452Sdfr};
4261452Sdfr
4361452Sdfr/*
4461452Sdfr * This structure is used to query the state of the AGP system.
4561452Sdfr */
4661452Sdfrstruct agp_info {
4761452Sdfr	u_int32_t	ai_mode;
4861452Sdfr	vm_offset_t	ai_aperture_base;
4961452Sdfr	vm_size_t	ai_aperture_size;
5061452Sdfr	vm_size_t	ai_memory_allowed;
5161452Sdfr	vm_size_t	ai_memory_used;
5261452Sdfr	u_int32_t	ai_devid;
5361452Sdfr};
5461452Sdfr
5561452Sdfrstruct agp_memory_info {
5661452Sdfr	vm_size_t	ami_size;	/* size in bytes */
5761452Sdfr	vm_offset_t	ami_physical;	/* bogus hack for i810 */
5861452Sdfr	vm_offset_t	ami_offset;	/* page offset if bound */
5961452Sdfr	int		ami_is_bound;	/* non-zero if bound */
6061452Sdfr};
6161452Sdfr
6261452Sdfr/*
6361452Sdfr * Find the AGP device and return it.
6461452Sdfr */
6561452Sdfrdevice_t agp_find_device(void);
6661452Sdfr
6761452Sdfr/*
6861452Sdfr * Return the current owner of the AGP chipset.
6961452Sdfr */
7061452Sdfrenum agp_acquire_state agp_state(device_t dev);
7161452Sdfr
7261452Sdfr/*
7361452Sdfr * Query the state of the AGP system.
7461452Sdfr */
7561452Sdfrvoid agp_get_info(device_t dev, struct agp_info *info);
7661452Sdfr
7761452Sdfr/*
7861452Sdfr * Acquire the AGP chipset for use by the kernel. Returns EBUSY if the
7961452Sdfr * AGP chipset is already acquired by another user.
8061452Sdfr */
8161452Sdfrint agp_acquire(device_t dev);
8261452Sdfr
8361452Sdfr/*
8461452Sdfr * Release the AGP chipset.
8561452Sdfr */
8661452Sdfrint agp_release(device_t dev);
8761452Sdfr
8861452Sdfr/*
8961452Sdfr * Enable the agp hardware with the relavent mode. The mode bits are
90173573Sjhb * defined in <dev/agp/agpreg.h>
9161452Sdfr */
9261452Sdfrint agp_enable(device_t dev, u_int32_t mode);
9361452Sdfr
9461452Sdfr/*
9561452Sdfr * Allocate physical memory suitable for mapping into the AGP
9661452Sdfr * aperture.  The value returned is an opaque handle which can be
9761452Sdfr * passed to agp_bind(), agp_unbind() or agp_deallocate().
9861452Sdfr */
9961452Sdfrvoid *agp_alloc_memory(device_t dev, int type, vm_size_t bytes);
10061452Sdfr
10161452Sdfr/*
10261452Sdfr * Free memory which was allocated with agp_allocate().
10361452Sdfr */
10461452Sdfrvoid agp_free_memory(device_t dev, void *handle);
10561452Sdfr
10661452Sdfr/*
10761452Sdfr * Bind memory allocated with agp_allocate() at a given offset within
10861452Sdfr * the AGP aperture. Returns EINVAL if the memory is already bound or
10961452Sdfr * the offset is not at an AGP page boundary.
11061452Sdfr */
11161452Sdfrint agp_bind_memory(device_t dev, void *handle, vm_offset_t offset);
11261452Sdfr
11361452Sdfr/*
11461452Sdfr * Unbind memory from the AGP aperture. Returns EINVAL if the memory
11561452Sdfr * is not bound.
11661452Sdfr */
11761452Sdfrint agp_unbind_memory(device_t dev, void *handle);
11861452Sdfr
11961452Sdfr/*
12061452Sdfr * Retrieve information about a memory block allocated with
12161452Sdfr * agp_alloc_memory().
12261452Sdfr */
12361452Sdfrvoid agp_memory_info(device_t dev, void *handle, struct agp_memory_info *mi);
12461452Sdfr
125273856Stijl/*
126273856Stijl * Bind a set of pages at a given offset within the AGP aperture.
127273856Stijl * Returns EINVAL if the given size or offset is not at an AGP page boundary.
128273856Stijl */
129273856Stijlint agp_bind_pages(device_t dev, vm_page_t *pages, vm_size_t size,
130273856Stijl		   vm_offset_t offset);
131273856Stijl
132273856Stijl/*
133273856Stijl * Unbind a set of pages from the AGP aperture.
134273856Stijl * Returns EINVAL if the given size or offset is not at an AGP page boundary.
135273856Stijl */
136273856Stijlint agp_unbind_pages(device_t dev, vm_size_t size, vm_offset_t offset);
137273856Stijl
138235782Skib#define AGP_NORMAL_MEMORY 0
139235782Skib
140235782Skib#define AGP_USER_TYPES (1 << 16)
141235782Skib#define AGP_USER_MEMORY (AGP_USER_TYPES)
142235782Skib#define AGP_USER_CACHED_MEMORY (AGP_USER_TYPES + 1)
143235782Skib
14461452Sdfr#endif /* !_PCI_AGPVAR_H_ */
145