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