Home | History | Annotate | Line # | Download | only in pnpbios
fdc_pnpbios.c revision 1.11.52.1
      1 /*	$NetBSD: fdc_pnpbios.c,v 1.11.52.1 2008/04/03 12:42:19 mjf Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2000 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  * PNPBIOS attachment for the PC Floppy Controller driver.
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: fdc_pnpbios.c,v 1.11.52.1 2008/04/03 12:42:19 mjf Exp $");
     45 
     46 #include "rnd.h"
     47 
     48 #include <sys/param.h>
     49 #include <sys/systm.h>
     50 #include <sys/callout.h>
     51 #include <sys/device.h>
     52 #include <sys/buf.h>
     53 #include <sys/queue.h>
     54 #if NRND > 0
     55 #include <sys/rnd.h>
     56 #endif
     57 
     58 #include <machine/bus.h>
     59 #include <machine/intr.h>
     60 
     61 #include <dev/isa/isavar.h>
     62 #include <dev/isa/isadmavar.h>
     63 
     64 #include <dev/isa/fdcvar.h>
     65 
     66 #include <i386/pnpbios/pnpbiosvar.h>
     67 
     68 int	fdc_pnpbios_match(device_t, cfdata_t, void *);
     69 void	fdc_pnpbios_attach(device_t, device_t, void *);
     70 
     71 struct fdc_pnpbios_softc {
     72         struct fdc_softc sc_fdc;        /* base fdc device */
     73 
     74         bus_space_handle_t sc_baseioh;  /* base I/O handle */
     75 };
     76 
     77 
     78 CFATTACH_DECL_NEW(fdc_pnpbios, sizeof(struct fdc_pnpbios_softc),
     79     fdc_pnpbios_match, fdc_pnpbios_attach, NULL, NULL);
     80 
     81 int
     82 fdc_pnpbios_match(device_t parent, cfdata_t match, void *aux)
     83 {
     84 	struct pnpbiosdev_attach_args *aa = aux;
     85 
     86 	if (strcmp(aa->idstr, "PNP0700") == 0)
     87 		return (1);
     88 
     89 	return (0);
     90 }
     91 
     92 void
     93 fdc_pnpbios_attach(device_t parent, device_t self, void *aux)
     94 {
     95         struct fdc_pnpbios_softc *pdc = device_private(self);
     96 	struct fdc_softc *fdc = &pdc->sc_fdc;
     97 	struct pnpbiosdev_attach_args *aa = aux;
     98         int size, base;
     99 
    100 	aprint_normal("\n");
    101 
    102 	fdc->sc_ic = aa->ic;
    103 
    104 	if (pnpbios_io_map(aa->pbt, aa->resc, 0, &fdc->sc_iot,
    105             &pdc->sc_baseioh)) {
    106 		aprint_error_dev(self, "unable to map I/O space\n");
    107 		return;
    108 	}
    109 
    110 	/*
    111          * Start accounting for "odd" pnpbios's. Some probe as 4 ports,
    112          * some as 6 and some don't give the ctl port back.
    113          */
    114 
    115         if (pnpbios_getiosize(aa->pbt, aa->resc, 0, &size)) {
    116                 aprint_error_dev(self, "can't get iobase size\n");
    117                 return;
    118         }
    119 
    120         switch (size) {
    121 
    122         /* Easy case. This matches right up with what the fdc code expects. */
    123         case 4:
    124                 fdc->sc_ioh = pdc->sc_baseioh;
    125                 break;
    126 
    127         /* Map a subregion so this all lines up with the fdc code. */
    128         case 6:
    129                 if (bus_space_subregion(fdc->sc_iot, pdc->sc_baseioh, 2, 4,
    130                     &fdc->sc_ioh)) {
    131                         aprint_error_dev(self,
    132 			    "unable to subregion I/O space\n");
    133                         return;
    134                 }
    135                 break;
    136         default:
    137                 aprint_error_dev(self, "unknown size: %d of io mapping\n", size);
    138                 return;
    139         }
    140 
    141         /*
    142          * XXX: This is bad. If the pnpbios claims only 1 I/O range then it's
    143          * omitting the controller I/O port. (One has to exist for there to
    144          * be a working fdc). Just try and force the mapping in.
    145          */
    146 
    147         if (aa->resc->numio == 1) {
    148 
    149                 if (pnpbios_getiobase(aa->pbt, aa->resc, 0, 0, &base)) {
    150                         aprint_error_dev(self, "can't get iobase\n");
    151                         return;
    152                 }
    153                 if (bus_space_map(fdc->sc_iot, base + size + 1, 1, 0,
    154                     &fdc->sc_fdctlioh)) {
    155                         aprint_error_dev(self,
    156 			    "unable to force map CTL I/O space\n");
    157                         return;
    158                 }
    159         } else if (pnpbios_io_map(aa->pbt, aa->resc, 1, &fdc->sc_iot,
    160             &fdc->sc_fdctlioh)) {
    161                 aprint_error_dev(self, "unable to map CTL I/O space\n");
    162 		return;
    163 	}
    164 
    165 	if (pnpbios_getdmachan(aa->pbt, aa->resc, 0, &fdc->sc_drq)) {
    166 		aprint_error_dev(self, "unable to get DMA channel\n");
    167 		return;
    168 	}
    169 
    170 	pnpbios_print_devres(self, aa);
    171         if (aa->resc->numio == 1)
    172                 aprint_error_dev(self,
    173 		    "ctl io %x didn't probe. Forced attach\n",
    174 		    base + size + 1);
    175 
    176 	fdc->sc_ih = pnpbios_intr_establish(aa->pbt, aa->resc, 0, IPL_BIO,
    177 	    fdcintr, fdc);
    178 
    179 	fdcattach(fdc);
    180 }
    181