xref: /netbsd-src/sys/arch/hp300/dev/dioreg.h (revision 094e0e9bb011ad94c760943efc379d133341c17d)
1*094e0e9bStsutsui /*	$NetBSD: dioreg.h,v 1.8 2011/03/06 14:51:21 tsutsui Exp $	*/
2838edf78Sthorpej 
3838edf78Sthorpej /*-
4838edf78Sthorpej  * Copyright (c) 1996 The NetBSD Foundation, Inc.
5838edf78Sthorpej  * All rights reserved.
6838edf78Sthorpej  *
7838edf78Sthorpej  * This code is derived from software contributed to The NetBSD Foundation
8838edf78Sthorpej  * by Jason R. Thorpe.
9838edf78Sthorpej  *
10838edf78Sthorpej  * Portions of this file are derived from software contributed to Berkeley
11838edf78Sthorpej  * by the Systems Programming Group of the University of Utah Computer
12838edf78Sthorpej  * Science Department.
13838edf78Sthorpej  *
14838edf78Sthorpej  * Redistribution and use in source and binary forms, with or without
15838edf78Sthorpej  * modification, are permitted provided that the following conditions
16838edf78Sthorpej  * are met:
17838edf78Sthorpej  * 1. Redistributions of source code must retain the above copyright
18838edf78Sthorpej  *    notice, this list of conditions and the following disclaimer.
19838edf78Sthorpej  * 2. Redistributions in binary form must reproduce the above copyright
20838edf78Sthorpej  *    notice, this list of conditions and the following disclaimer in the
21838edf78Sthorpej  *    documentation and/or other materials provided with the distribution.
22838edf78Sthorpej  *
23838edf78Sthorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24838edf78Sthorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25838edf78Sthorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
264c9d6e4dSjtc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
274c9d6e4dSjtc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28838edf78Sthorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29838edf78Sthorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30838edf78Sthorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31838edf78Sthorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32838edf78Sthorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33838edf78Sthorpej  * POSSIBILITY OF SUCH DAMAGE.
34838edf78Sthorpej  */
35838edf78Sthorpej 
36838edf78Sthorpej /*
37838edf78Sthorpej  * Register definitions for the DIO and DIO-II bus.
38838edf78Sthorpej  */
39838edf78Sthorpej 
40838edf78Sthorpej /*
41838edf78Sthorpej  * DIO/DIO-II device registers, offsets from base of device.  All
42838edf78Sthorpej  * registers are 8-bit.
43838edf78Sthorpej  */
44838edf78Sthorpej #define	DIO_IDOFF		0x01	/* primary device id */
45838edf78Sthorpej #define	DIO_IPLOFF		0x03	/* interrupt level */
46838edf78Sthorpej #define DIO_SECIDOFF		0x15	/* secondary device id */
47838edf78Sthorpej #define	DIOII_SIZEOFF		0x101	/* device size */
48838edf78Sthorpej 
49838edf78Sthorpej /*
50838edf78Sthorpej  * System physical addresses of some `special' DIO devices.
51838edf78Sthorpej  */
52838edf78Sthorpej #define	DIO_IHPIBADDR		0x478000 /* internal HP-IB; select code 7 */
53838edf78Sthorpej 
54838edf78Sthorpej /*
55838edf78Sthorpej  * DIO ranges from select codes 0-63 at physical addresses given by:
56838edf78Sthorpej  *	0x600000 + (sc - 32) * 0x10000
57838edf78Sthorpej  * DIO cards are addressed in the range 0-31 [0x600000-0x800000) for
58838edf78Sthorpej  * their control space and the remaining areas, [0x200000-0x400000) and
59838edf78Sthorpej  * [0x800000-0x1000000), are for additional space required by a card;
60838edf78Sthorpej  * e.g. a display framebuffer.
61838edf78Sthorpej  *
62838edf78Sthorpej  * DIO-II ranges from select codes 132-255 at physical addresses given by:
63838edf78Sthorpej  *	0x1000000 + (sc - 132) * 0x400000
64838edf78Sthorpej  * The address range of DIO-II space is thus [0x1000000-0x20000000).
65838edf78Sthorpej  *
66838edf78Sthorpej  * DIO/DIO-II space is too large to map in its entirety, instead devices
67838edf78Sthorpej  * are mapped into kernel virtual address space allocated from a range
68838edf78Sthorpej  * of EIOMAPSIZE pages (vmparam.h) starting at ``extiobase''.
69838edf78Sthorpej  */
70838edf78Sthorpej #define	DIO_BASE		0x600000	/* start of DIO space */
71838edf78Sthorpej #define	DIO_END			0x1000000	/* end of DIO space */
72838edf78Sthorpej #define	DIO_DEVSIZE		0x10000		/* size of a DIO device */
73838edf78Sthorpej 
74838edf78Sthorpej #define	DIOII_BASE		0x01000000	/* start of DIO-II space */
75838edf78Sthorpej #define	DIOII_END		0x20000000	/* end of DIO-II space */
76838edf78Sthorpej #define	DIOII_DEVSIZE		0x00400000	/* size of a DIO-II device */
77838edf78Sthorpej 
78838edf78Sthorpej /*
79838edf78Sthorpej  * Find the highest select code for a given machine; HP320 doesn't
80838edf78Sthorpej  * have DIO-II.
81838edf78Sthorpej  */
82838edf78Sthorpej #define	DIO_SCMAX(machineid)	((machineid) == HP_320 ? 32 : 256)
83838edf78Sthorpej 
84838edf78Sthorpej /*
85112e338dSthorpej  * Base of DIO-II select codes.
86112e338dSthorpej  */
87112e338dSthorpej #define	DIOII_SCBASE		132
88112e338dSthorpej 
89112e338dSthorpej /*
90838edf78Sthorpej  * Macro that returns true if a select code lies within
91838edf78Sthorpej  * the select code `hole'.
92838edf78Sthorpej  */
93838edf78Sthorpej #define	DIO_INHOLE(scode)	((scode) >= 32 && (scode) < 132)
94838edf78Sthorpej 
95838edf78Sthorpej /*
96838edf78Sthorpej  * Macros to determine if device is DIO or DIO-II.
97838edf78Sthorpej  */
98838edf78Sthorpej #define	DIO_ISDIO(scode)	((scode) >= 0 && (scode) < 32)
99112e338dSthorpej #define	DIO_ISDIOII(scode)	((scode) >= DIOII_SCBASE && (scode) < 256)
100838edf78Sthorpej 
101838edf78Sthorpej /*
102838edf78Sthorpej  * Macro to determine if device is a framebuffer, given the
103838edf78Sthorpej  * primary id of the device.  We key off this to determine if
104838edf78Sthorpej  * we should look at secondary id and ignore interrupt level.
105838edf78Sthorpej  */
106838edf78Sthorpej #define	DIO_ISFRAMEBUFFER(id)		\
107838edf78Sthorpej 	((id) == DIO_DEVICE_ID_FRAMEBUFFER)
108838edf78Sthorpej 
109838edf78Sthorpej /*
110838edf78Sthorpej  * Macro to extract primary and decondary device ids, given
111838edf78Sthorpej  * the base address of the device.
112838edf78Sthorpej  */
113838edf78Sthorpej #define	DIO_ID(base)			\
1142be3acc2Stsutsui 	(*((uint8_t *)((u_long)(base) + DIO_IDOFF)))
115838edf78Sthorpej #define	DIO_SECID(base)			\
1162be3acc2Stsutsui 	(*((uint8_t *)((u_long)(base) + DIO_SECIDOFF)))
117838edf78Sthorpej 
118838edf78Sthorpej /*
119838edf78Sthorpej  * Macro to extract the interrupt level, given the
120838edf78Sthorpej  * base address of the device.
121838edf78Sthorpej  */
122838edf78Sthorpej #define	DIO_IPL(base)			\
1232be3acc2Stsutsui 	((((*((uint8_t *)((u_long)(base) + DIO_IPLOFF))) >> 4) & 0x03) + 3)
124838edf78Sthorpej 
125838edf78Sthorpej /*
126838edf78Sthorpej  * Macro to compute the size of a DIO-II device's address
127838edf78Sthorpej  * space, given the base address of the device.
128838edf78Sthorpej  */
129838edf78Sthorpej #define DIOII_SIZE(base)		\
1302be3acc2Stsutsui 	((int)((*((uint8_t *)((u_long)(base) + DIOII_SIZEOFF)) + 1)	\
131838edf78Sthorpej 	    * 0x100000))
132838edf78Sthorpej 
133838edf78Sthorpej /*
134838edf78Sthorpej  * Given a select code and device base address, compute
135838edf78Sthorpej  * the size of the DIO/DIO-II device.
136838edf78Sthorpej  */
137838edf78Sthorpej #define	DIO_SIZE(scode, base)		\
138838edf78Sthorpej 	(DIO_ISDIOII((scode)) ? DIOII_SIZE((base)) : DIO_DEVSIZE)
139