1 /* $NetBSD: intiovar.h,v 1.13 2008/04/28 20:23:19 martin 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * Autoconfiguration definitions and prototypes for the hp300 34 * internal i/o space. 35 */ 36 37 #include <machine/bus.h> 38 #include <machine/cpu.h> 39 40 #include <arch/hp300/dev/intioreg.h> 41 42 #define INTIO_MOD_LEN 8 43 44 /* 45 * Arguments used to attach a device to the internal i/o space. 46 */ 47 struct intio_attach_args { 48 char ia_modname[INTIO_MOD_LEN]; /* module name */ 49 bus_space_tag_t ia_bst; /* bus space tag */ 50 bus_addr_t ia_addr; /* physical address */ 51 bus_size_t ia_iobase; /* intio iobase */ 52 int ia_ipl; /* interrupt priority level */ 53 }; 54 55 struct intio_builtins { 56 const char *ib_modname; /* module name */ 57 bus_size_t ib_offset; /* intio offset */ 58 int ib_ipl; /* interrupt priority level */ 59 }; 60 61 /* 62 * Devices such as the HIL and RTC chips are wired in a consistent 63 * fashion. These routines provide a uniform mechanism for accessing 64 * the devices that are wired to the machine. Doesn't include 65 * memory-mapped devices such as framebuffers. 66 */ 67 68 #define WAIT(bst,bsh) \ 69 while (bus_space_read_1(bst,bsh,INTIO_DEV_3xx_STAT) \ 70 & INTIO_DEV_BUSY) 71 #define DATAWAIT(bst,bsh) \ 72 while (!(bus_space_read_1(bst, bsh, INTIO_DEV_3xx_STAT) \ 73 & INTIO_DEV_DATA_READY)) 74 75 static inline int 76 intio_device_readcmd(bus_space_tag_t bst, bus_space_handle_t bsh, int cmd, 77 uint8_t *datap) 78 { 79 uint8_t status; 80 81 if (cmd != 0) { 82 WAIT(bst, bsh); 83 bus_space_write_1(bst, bsh, INTIO_DEV_3xx_CMD, cmd); 84 } 85 do { 86 DATAWAIT(bst, bsh); 87 status = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_STAT); 88 *datap = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_DATA); 89 } while (((status >> INTIO_DEV_SRSHIFT) & INTIO_DEV_SRMASK) 90 != INTIO_DEV_SR_DATAAVAIL); 91 return (0); 92 } 93 94 static inline int 95 intio_device_writecmd(bus_space_tag_t bst, bus_space_handle_t bsh, 96 int cmd, uint8_t *datap, int len) 97 { 98 99 WAIT(bst, bsh); 100 bus_space_write_1(bst, bsh, INTIO_DEV_3xx_CMD, cmd); 101 while (len--) { 102 WAIT(bst, bsh); 103 bus_space_write_1(bst, bsh, INTIO_DEV_3xx_DATA, *datap++); 104 } 105 return (0); 106 } 107 108 static inline int 109 intio_device_readstate(bus_space_tag_t bst, bus_space_handle_t bsh, 110 uint8_t *statusp, uint8_t *datap) 111 { 112 *statusp = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_STAT); 113 *datap = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_DATA); 114 return (0); 115 } 116 #undef WAIT 117 #undef DATAWAIT 118 119 #define INTIO_DEVSIZE 4096 /* large enough for all machines */ 120 121 #define intio_intr_establish(func, arg, ipl, priority) \ 122 intr_establish((func),(arg),(ipl),(priority)) 123