Home | History | Annotate | Line # | Download | only in pnpbios
fdc_pnpbios.c revision 1.2.6.2
      1 /*	$NetBSD: fdc_pnpbios.c,v 1.2.6.2 2002/10/10 18:33:36 jdolecek 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.2.6.2 2002/10/10 18:33:36 jdolecek 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(struct device *, struct cfdata *, void *);
     69 void	fdc_pnpbios_attach(struct device *, struct device *, 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(fdc_pnpbios, sizeof(struct fdc_pnpbios_softc),
     79     fdc_pnpbios_match, fdc_pnpbios_attach, NULL, NULL);
     80 
     81 int
     82 fdc_pnpbios_match(struct device *parent,
     83     struct cfdata *match,
     84     void *aux)
     85 {
     86 	struct pnpbiosdev_attach_args *aa = aux;
     87 
     88 	if (strcmp(aa->idstr, "PNP0700") == 0)
     89 		return (1);
     90 
     91 	return (0);
     92 }
     93 
     94 void
     95 fdc_pnpbios_attach(struct device *parent,
     96     struct device *self,
     97     void *aux)
     98 {
     99 	struct fdc_softc *fdc = (void *) self;
    100         struct fdc_pnpbios_softc *pdc = (void *) self;
    101 	struct pnpbiosdev_attach_args *aa = aux;
    102         int size, base;
    103 
    104 	printf("\n");
    105 
    106 	fdc->sc_ic = aa->ic;
    107 
    108 	if (pnpbios_io_map(aa->pbt, aa->resc, 0, &fdc->sc_iot,
    109             &pdc->sc_baseioh)) {
    110 		printf("%s: unable to map I/O space\n", fdc->sc_dev.dv_xname);
    111 		return;
    112 	}
    113 
    114 	/*
    115          * Start accounting for "odd" pnpbios's. Some probe as 4 ports,
    116          * some as 6 and some don't give the ctl port back.
    117          */
    118 
    119         if (pnpbios_getiosize(aa->pbt, aa->resc, 0, &size)) {
    120                 printf("%s: can't get iobase size\n", fdc->sc_dev.dv_xname);
    121                 return;
    122         }
    123 
    124         switch (size) {
    125 
    126         /* Easy case. This matches right up with what the fdc code expects. */
    127         case 4:
    128                 fdc->sc_ioh = pdc->sc_baseioh;
    129                 break;
    130 
    131         /* Map a subregion so this all lines up with the fdc code. */
    132         case 6:
    133                 if (bus_space_subregion(fdc->sc_iot, pdc->sc_baseioh, 2, 4,
    134                     &fdc->sc_ioh)) {
    135                         printf("%s: unable to subregion I/O space\n",
    136                             fdc->sc_dev.dv_xname);
    137                         return;
    138                 }
    139                 break;
    140         default:
    141                 printf ("%s: unknown size: %d of io mapping\n",
    142                     fdc->sc_dev.dv_xname, size);
    143                 return;
    144         }
    145 
    146         /*
    147          * XXX: This is bad. If the pnpbios claims only 1 I/O range then it's
    148          * omitting the controller I/O port. (One has to exist for there to
    149          * be a working fdc). Just try and force the mapping in.
    150          */
    151 
    152         if (aa->resc->numio == 1) {
    153 
    154                 if (pnpbios_getiobase(aa->pbt, aa->resc, 0, 0, &base)) {
    155                         printf ("%s: can't get iobase\n",
    156                             fdc->sc_dev.dv_xname);
    157                         return;
    158                 }
    159                 if (bus_space_map(fdc->sc_iot, base + size + 1, 1, 0,
    160                     &fdc->sc_fdctlioh)) {
    161                         printf("%s: unable to force map CTL I/O space\n",
    162                             fdc->sc_dev.dv_xname);
    163                         return;
    164                 }
    165         } else if (pnpbios_io_map(aa->pbt, aa->resc, 1, &fdc->sc_iot,
    166             &fdc->sc_fdctlioh)) {
    167                 printf("%s: unable to map CTL I/O space\n",
    168 		    fdc->sc_dev.dv_xname);
    169 		return;
    170 	}
    171 
    172 	if (pnpbios_getdmachan(aa->pbt, aa->resc, 0, &fdc->sc_drq)) {
    173 		printf("%s: unable to get DMA channel\n",
    174 		    fdc->sc_dev.dv_xname);
    175 		return;
    176 	}
    177 
    178 	pnpbios_print_devres(self, aa);
    179         if (aa->resc->numio == 1)
    180                 printf("%s: ctl io %x didn't probe. Forced attach\n",
    181                     fdc->sc_dev.dv_xname, base + size + 1);
    182 
    183 	fdc->sc_ih = pnpbios_intr_establish(aa->pbt, aa->resc, 0, IPL_BIO,
    184 	    fdcintr, fdc);
    185 
    186 	fdcattach(fdc);
    187 }
    188