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