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 _SYS_AGPIO_H_
3061452Sdfr#define _SYS_AGPIO_H_
3161452Sdfr
3261452Sdfr/*
3361452Sdfr * The AGP gatt uses 4k pages irrespective of the host page size.
3461452Sdfr */
3561452Sdfr#define AGP_PAGE_SIZE		4096
3661452Sdfr#define AGP_PAGE_SHIFT		12
3761452Sdfr
3861452Sdfr/*
3961452Sdfr * Macros to manipulate AGP mode words.
40110568Smdodd *
41110568Smdodd * SBA = Sideband Address Port
42110568Smdodd * FW  = Fast Writes
4361452Sdfr */
4461452Sdfr#define AGP_MODE_GET_RQ(x)		(((x) & 0xff000000U) >> 24)
45121440Sjhb#define AGP_MODE_GET_ARQSZ(x)		(((x) & 0x0000e000U) >> 13)
46121440Sjhb#define AGP_MODE_GET_CAL(x)		(((x) & 0x00001c00U) >> 10)
4761452Sdfr#define AGP_MODE_GET_SBA(x)		(((x) & 0x00000200U) >> 9)
4861452Sdfr#define AGP_MODE_GET_AGP(x)		(((x) & 0x00000100U) >> 8)
49121440Sjhb#define AGP_MODE_GET_GART_64(x)		(((x) & 0x00000080U) >> 7)
50121440Sjhb#define AGP_MODE_GET_OVER_4G(x)		(((x) & 0x00000020U) >> 5)
5161452Sdfr#define AGP_MODE_GET_FW(x)		(((x) & 0x00000010U) >> 4)
52121440Sjhb#define AGP_MODE_GET_MODE_3(x)		(((x) & 0x00000008U) >> 3)
5386711Sru#define AGP_MODE_GET_RATE(x)		((x) & 0x00000007U)
5461452Sdfr#define AGP_MODE_SET_RQ(x,v)		(((x) & ~0xff000000U) | ((v) << 24))
55121440Sjhb#define AGP_MODE_SET_ARQSZ(x,v)		(((x) & ~0x0000e000U) | ((v) << 13))
56121440Sjhb#define AGP_MODE_SET_CAL(x,v)		(((x) & ~0x00001c00U) | ((v) << 10))
5761452Sdfr#define AGP_MODE_SET_SBA(x,v)		(((x) & ~0x00000200U) | ((v) << 9))
5861452Sdfr#define AGP_MODE_SET_AGP(x,v)		(((x) & ~0x00000100U) | ((v) << 8))
59121440Sjhb#define AGP_MODE_SET_GART_64(x,v)	(((x) & ~0x00000080U) | ((v) << 7))
60121440Sjhb#define AGP_MODE_SET_OVER_4G(x,v)	(((x) & ~0x00000020U) | ((v) << 5))
6161452Sdfr#define AGP_MODE_SET_FW(x,v)		(((x) & ~0x00000010U) | ((v) << 4))
62121440Sjhb#define AGP_MODE_SET_MODE_3(x,v)	(((x) & ~0x00000008U) | ((v) << 3))
6386711Sru#define AGP_MODE_SET_RATE(x,v)		(((x) & ~0x00000007U) | (v))
64121440Sjhb#define AGP_MODE_V2_RATE_1x		0x00000001
65121440Sjhb#define AGP_MODE_V2_RATE_2x		0x00000002
66121440Sjhb#define AGP_MODE_V2_RATE_4x		0x00000004
67121440Sjhb#define AGP_MODE_V3_RATE_4x		0x00000001
68121440Sjhb#define AGP_MODE_V3_RATE_8x		0x00000002
69121440Sjhb#define AGP_MODE_V3_RATE_RSVD		0x00000004
7061452Sdfr
71121440Sjhb/* XXX: Compat */
72121440Sjhb#define AGP_MODE_GET_4G(x)		AGP_MODE_GET_OVER_4G(x)
73121440Sjhb#define AGP_MODE_SET_4G(x)		AGP_MODE_SET_OVER_4G(x)
74121440Sjhb#define AGP_MODE_RATE_1x		AGP_MODE_V2_RATE_1x
75121440Sjhb#define AGP_MODE_RATE_2x		AGP_MODE_V2_RATE_2x
76121440Sjhb#define AGP_MODE_RATE_4x		AGP_MODE_V2_RATE_4x
77121440Sjhb
7861452Sdfr#define AGPIOC_BASE       'A'
7961452Sdfr#define AGPIOC_INFO       _IOR (AGPIOC_BASE, 0, agp_info)
8061452Sdfr#define AGPIOC_ACQUIRE    _IO  (AGPIOC_BASE, 1)
8161452Sdfr#define AGPIOC_RELEASE    _IO  (AGPIOC_BASE, 2)
8261452Sdfr#define AGPIOC_SETUP      _IOW (AGPIOC_BASE, 3, agp_setup)
8361452Sdfr#if 0
8461452Sdfr#define AGPIOC_RESERVE    _IOW (AGPIOC_BASE, 4, agp_region)
8561452Sdfr#define AGPIOC_PROTECT    _IOW (AGPIOC_BASE, 5, agp_region)
8661452Sdfr#endif
8761452Sdfr#define AGPIOC_ALLOCATE   _IOWR(AGPIOC_BASE, 6, agp_allocate)
8861452Sdfr#define AGPIOC_DEALLOCATE _IOW (AGPIOC_BASE, 7, int)
8961452Sdfr#define AGPIOC_BIND       _IOW (AGPIOC_BASE, 8, agp_bind)
9061452Sdfr#define AGPIOC_UNBIND     _IOW (AGPIOC_BASE, 9, agp_unbind)
91235782Skib#define AGPIOC_CHIPSET_FLUSH _IO (AGPIOC_BASE, 10)
9261452Sdfr
9361452Sdfrtypedef struct _agp_version {
9461452Sdfr	u_int16_t major;
9561452Sdfr	u_int16_t minor;
9661452Sdfr} agp_version;
9761452Sdfr
9861452Sdfrtypedef struct _agp_info {
9961452Sdfr	agp_version version;	/* version of the driver        */
10061452Sdfr	u_int32_t bridge_id;	/* bridge vendor/device         */
10161452Sdfr	u_int32_t agp_mode;	/* mode info of bridge          */
10261452Sdfr	off_t aper_base;	/* base of aperture             */
10361452Sdfr	size_t aper_size;	/* size of aperture             */
10461452Sdfr	size_t pg_total;	/* max pages (swap + system)    */
10561452Sdfr	size_t pg_system;	/* max pages (system)           */
10661452Sdfr	size_t pg_used;		/* current pages used           */
10761452Sdfr} agp_info;
10861452Sdfr
10961452Sdfrtypedef struct _agp_setup {
11061452Sdfr	u_int32_t agp_mode;		/* mode info of bridge          */
11161452Sdfr} agp_setup;
11261452Sdfr
11361452Sdfr#if 0
11461452Sdfr/*
11561452Sdfr * The "prot" down below needs still a "sleep" flag somehow ...
11661452Sdfr */
11761452Sdfrtypedef struct _agp_segment {
11861452Sdfr	off_t pg_start;		/* starting page to populate    */
11961452Sdfr	size_t pg_count;	/* number of pages              */
12061452Sdfr	int prot;		/* prot flags for mmap          */
12161452Sdfr} agp_segment;
12261452Sdfr
12361452Sdfrtypedef struct _agp_region {
12461452Sdfr	pid_t pid;		/* pid of process               */
12561452Sdfr	size_t seg_count;	/* number of segments           */
12661452Sdfr	struct _agp_segment *seg_list;
12761452Sdfr} agp_region;
12861452Sdfr#endif
12961452Sdfr
13061452Sdfrtypedef struct _agp_allocate {
13161452Sdfr	int key;		/* tag of allocation            */
13261452Sdfr	size_t pg_count;	/* number of pages              */
13361452Sdfr	u_int32_t type;		/* 0 == normal, other devspec   */
13461452Sdfr   	u_int32_t physical;     /* device specific (some devices
13561452Sdfr				 * need a phys address of the
13661452Sdfr				 * actual page behind the gatt
13761452Sdfr				 * table)                        */
13861452Sdfr} agp_allocate;
13961452Sdfr
14061452Sdfrtypedef struct _agp_bind {
14161452Sdfr	int key;		/* tag of allocation            */
14261452Sdfr	off_t pg_start;		/* starting page to populate    */
14361452Sdfr} agp_bind;
14461452Sdfr
14561452Sdfrtypedef struct _agp_unbind {
14661452Sdfr	int key;		/* tag of allocation            */
14761452Sdfr	u_int32_t priority;	/* priority for paging out      */
14861452Sdfr} agp_unbind;
14961452Sdfr
15061452Sdfr#endif /* !_SYS_AGPIO_H_ */
151