1 /* $NetBSD: promdev.c,v 1.2 2002/05/15 04:07:43 lukem Exp $ */ 2 3 /* 4 * Copyright (c) 1995 Gordon W. Ross 5 * Copyright (c) 1993 Paul Kranenburg 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Paul Kranenburg. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include <sys/types.h> 35 #include <machine/mon.h> 36 37 #include <stand.h> 38 39 #include "libsa.h" 40 #include "dvma.h" 41 #include "saio.h" 42 43 int promdev_inuse; 44 45 /* 46 * Note: caller sets the fields: 47 * si->si_boottab 48 * si->si_ctlr 49 * si->si_unit 50 * si->si_boff 51 */ 52 53 int 54 prom_iopen(si) 55 struct saioreq *si; 56 { 57 struct boottab *ops; 58 struct devinfo *dip; 59 int i, ctlr, error; 60 61 if (promdev_inuse) 62 return(EMFILE); 63 64 ops = si->si_boottab; 65 dip = ops->b_devinfo; 66 ctlr = si->si_ctlr; 67 68 #ifdef DEBUG_PROM 69 if (debug) { 70 printf("Boot device type: %s\n", ops->b_desc); 71 } 72 #endif 73 74 if (!_is2) { 75 #ifdef DEBUG_PROM 76 if (debug) { 77 printf("d_devbytes=%d\n", dip->d_devbytes); 78 printf("d_dmabytes=%d\n", dip->d_dmabytes); 79 printf("d_localbytes=%d\n", dip->d_localbytes); 80 printf("d_devtype=%d\n", dip->d_devtype); 81 printf("d_maxiobytes=%d\n", dip->d_maxiobytes); 82 printf("d_stdcount=%d\n", dip->d_stdcount); 83 for (i = 0; i < dip->d_stdcount; i++) 84 printf("d_stdaddrs[i]=0x%x\n", 85 i, dip->d_stdaddrs[0]); 86 } 87 #endif 88 89 if (dip->d_devbytes && dip->d_stdcount) { 90 if (ctlr >= dip->d_stdcount) { 91 putstr("Invalid controller number\n"); 92 return(ENXIO); 93 } 94 si->si_devaddr = dev_mapin(dip->d_devtype, 95 dip->d_stdaddrs[ctlr], dip->d_devbytes); 96 #ifdef DEBUG_PROM 97 if (debug) 98 printf("prom_iopen: devaddr=0x%x\n", si->si_devaddr); 99 #endif 100 } 101 102 if (dip->d_dmabytes) { 103 si->si_dmaaddr = dvma_alloc(dip->d_dmabytes); 104 #ifdef DEBUG_PROM 105 if (debug) 106 printf("prom_iopen: dmaaddr=0x%x\n", si->si_dmaaddr); 107 #endif 108 } 109 110 if (dip->d_localbytes) { 111 si->si_devdata = alloc(dip->d_localbytes); 112 #ifdef DEBUG_PROM 113 if (debug) 114 printf("prom_iopen: devdata=0x%x\n", si->si_devdata); 115 #endif 116 } 117 } 118 119 /* OK, call the PROM device open routine. */ 120 #ifdef DEBUG_PROM 121 if (debug) 122 printf("prom_iopen: calling prom open...\n"); 123 #endif 124 error = (*ops->b_open)(si); 125 #ifdef DEBUG_PROM 126 if (debug) 127 printf("prom_iopen: prom open returned %d\n", error); 128 #endif 129 if (error != 0) { 130 #if 0 /* XXX: printf is too big for bootxx */ 131 printf("prom_iopen: \"%s\" error=%d\n", 132 ops->b_desc, error); 133 #else 134 putstr("prom_iopen: prom open failed"); 135 #endif 136 return (ENXIO); 137 } 138 139 promdev_inuse++; 140 return (0); 141 } 142 143 void 144 prom_iclose(si) 145 struct saioreq *si; 146 { 147 struct boottab *ops; 148 struct devinfo *dip; 149 150 if (promdev_inuse == 0) 151 return; 152 153 ops = si->si_boottab; 154 dip = ops->b_devinfo; 155 156 #ifdef DEBUG_PROM 157 if (debug) 158 printf("prom_iclose: calling prom close...\n"); 159 #endif 160 (*ops->b_close)(si); 161 162 promdev_inuse = 0; 163 } 164 165