xref: /netbsd/sys/arch/hp300/dev/intiovar.h (revision bf9ec67e)
1 /*	$NetBSD: intiovar.h,v 1.5 2001/11/17 23:33:22 gmcgarry Exp $	*/
2 
3 /*-
4  * Copyright (c) 1996, 1998, 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Autoconfiguration definitions and prototypes for the hp300
41  * internal i/o space.
42  */
43 
44 #include <machine/bus.h>
45 #include <machine/cpu.h>
46 
47 #include <arch/hp300/dev/intioreg.h>
48 
49 #define INTIO_MOD_LEN	8
50 
51 /*
52  * Arguments used to attach a device to the internal i/o space.
53  */
54 struct intio_attach_args {
55 	char ia_modname[INTIO_MOD_LEN+1];	/* module name */
56 	bus_space_tag_t ia_bst;			/* bus space tag */
57 	bus_addr_t ia_addr;			/* physical address */
58 	bus_size_t ia_iobase;			/* intio iobase */
59 	int ia_ipl;				/* interrupt priority level */
60 };
61 
62 struct intio_builtins {
63 	char *ib_modname;			/* module name */
64 	bus_size_t ib_offset;			/* intio offset */
65 	int ib_ipl;				/* interrupt priority level */
66 };
67 
68 /*
69  * Devices such as the HIL and RTC chips are wired in a consistent
70  * fashion.  These routines provide a uniform mechanism for accessing
71  * the devices that are wired to the machine.  Doesn't include
72  * memory-mapped devices such as framebuffers.
73  */
74 
75 #define WAIT(bst,bsh)		\
76 	while (bus_space_read_1(bst,bsh,INTIO_DEV_3xx_STAT) \
77 		& INTIO_DEV_BUSY)
78 #define DATAWAIT(bst,bsh)	\
79 	while (!(bus_space_read_1(bst, bsh, INTIO_DEV_3xx_STAT) \
80 		& INTIO_DEV_DATA_READY))
81 
82 static __inline int
83 intio_device_readcmd(bus_space_tag_t bst, bus_space_handle_t bsh, int cmd,
84 	u_int8_t *datap)
85 {
86         u_int8_t status;
87 
88 	if (cmd != 0) {
89 		WAIT(bst, bsh);
90 		bus_space_write_1(bst, bsh, INTIO_DEV_3xx_CMD, cmd);
91 	}
92         do {
93 		DATAWAIT(bst, bsh);
94 		status = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_STAT);
95 		*datap = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_DATA);
96 	} while (((status >> INTIO_DEV_SRSHIFT) & INTIO_DEV_SRMASK)
97 		!= INTIO_DEV_SR_DATAAVAIL);
98 	return (0);
99 }
100 
101 static __inline int
102 intio_device_writecmd(bus_space_tag_t bst, bus_space_handle_t bsh,
103 	int cmd, u_int8_t *datap, int len)
104 {
105         WAIT(bst,bsh);
106 	bus_space_write_1(bst, bsh, INTIO_DEV_3xx_CMD, cmd);
107         while (len--) {
108                 WAIT(bst,bsh);
109 		bus_space_write_1(bst, bsh, INTIO_DEV_3xx_DATA, *datap++);
110         }
111 	return (0);
112 }
113 
114 static __inline int
115 intio_device_readstate(bus_space_tag_t bst, bus_space_handle_t bsh,
116 	u_int8_t *statusp, u_int8_t *datap)
117 {
118 	*statusp = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_STAT);
119 	*datap = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_DATA);
120 	return (0);
121 }
122 #undef WAIT
123 #undef DATAWAIT
124 
125 #define INTIO_DEVSIZE	4096	/* large enough for all machines */
126 
127 #define intio_intr_establish(func, arg, ipl, priority)			\
128 	intr_establish((func),(arg),(ipl),(priority))
129