fdc_pnpbios.c revision 1.3.2.2       1  1.3.2.2  lukem /*	$NetBSD: fdc_pnpbios.c,v 1.3.2.2 2001/11/15 07:03:36 lukem Exp $	*/
      2  1.3.2.2  lukem 
      3  1.3.2.2  lukem /*-
      4  1.3.2.2  lukem  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  1.3.2.2  lukem  * All rights reserved.
      6  1.3.2.2  lukem  *
      7  1.3.2.2  lukem  * This code is derived from software contributed to The NetBSD Foundation
      8  1.3.2.2  lukem  * by Jason R. Thorpe.
      9  1.3.2.2  lukem  *
     10  1.3.2.2  lukem  * Redistribution and use in source and binary forms, with or without
     11  1.3.2.2  lukem  * modification, are permitted provided that the following conditions
     12  1.3.2.2  lukem  * are met:
     13  1.3.2.2  lukem  * 1. Redistributions of source code must retain the above copyright
     14  1.3.2.2  lukem  *    notice, this list of conditions and the following disclaimer.
     15  1.3.2.2  lukem  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.3.2.2  lukem  *    notice, this list of conditions and the following disclaimer in the
     17  1.3.2.2  lukem  *    documentation and/or other materials provided with the distribution.
     18  1.3.2.2  lukem  * 3. All advertising materials mentioning features or use of this software
     19  1.3.2.2  lukem  *    must display the following acknowledgement:
     20  1.3.2.2  lukem  *	This product includes software developed by the NetBSD
     21  1.3.2.2  lukem  *	Foundation, Inc. and its contributors.
     22  1.3.2.2  lukem  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.3.2.2  lukem  *    contributors may be used to endorse or promote products derived
     24  1.3.2.2  lukem  *    from this software without specific prior written permission.
     25  1.3.2.2  lukem  *
     26  1.3.2.2  lukem  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.3.2.2  lukem  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.3.2.2  lukem  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.3.2.2  lukem  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.3.2.2  lukem  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.3.2.2  lukem  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.3.2.2  lukem  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.3.2.2  lukem  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.3.2.2  lukem  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.3.2.2  lukem  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.3.2.2  lukem  * POSSIBILITY OF SUCH DAMAGE.
     37  1.3.2.2  lukem  */
     38  1.3.2.2  lukem 
     39  1.3.2.2  lukem /*
     40  1.3.2.2  lukem  * PNPBIOS attachment for the PC Floppy Controller driver.
     41  1.3.2.2  lukem  */
     42  1.3.2.2  lukem 
     43  1.3.2.2  lukem #include <sys/cdefs.h>
     44  1.3.2.2  lukem __KERNEL_RCSID(0, "$NetBSD: fdc_pnpbios.c,v 1.3.2.2 2001/11/15 07:03:36 lukem Exp $");
     45  1.3.2.2  lukem 
     46  1.3.2.2  lukem #include "rnd.h"
     47  1.3.2.2  lukem 
     48  1.3.2.2  lukem #include <sys/param.h>
     49  1.3.2.2  lukem #include <sys/systm.h>
     50  1.3.2.2  lukem #include <sys/callout.h>
     51  1.3.2.2  lukem #include <sys/device.h>
     52  1.3.2.2  lukem #include <sys/buf.h>
     53  1.3.2.2  lukem #include <sys/queue.h>
     54  1.3.2.2  lukem #if NRND > 0
     55  1.3.2.2  lukem #include <sys/rnd.h>
     56  1.3.2.2  lukem #endif
     57  1.3.2.2  lukem 
     58  1.3.2.2  lukem #include <machine/bus.h>
     59  1.3.2.2  lukem #include <machine/intr.h>
     60  1.3.2.2  lukem 
     61  1.3.2.2  lukem #include <dev/isa/isavar.h>
     62  1.3.2.2  lukem #include <dev/isa/isadmavar.h>
     63  1.3.2.2  lukem 
     64  1.3.2.2  lukem #include <dev/isa/fdcvar.h>
     65  1.3.2.2  lukem 
     66  1.3.2.2  lukem #include <i386/pnpbios/pnpbiosvar.h>
     67  1.3.2.2  lukem 
     68  1.3.2.2  lukem int	fdc_pnpbios_match(struct device *, struct cfdata *, void *);
     69  1.3.2.2  lukem void	fdc_pnpbios_attach(struct device *, struct device *, void *);
     70  1.3.2.2  lukem 
     71  1.3.2.2  lukem struct fdc_pnpbios_softc {
     72  1.3.2.2  lukem         struct fdc_softc sc_fdc;        /* base fdc device */
     73  1.3.2.2  lukem 
     74  1.3.2.2  lukem         bus_space_handle_t sc_baseioh;  /* base I/O handle */
     75  1.3.2.2  lukem };
     76  1.3.2.2  lukem 
     77  1.3.2.2  lukem 
     78  1.3.2.2  lukem struct cfattach fdc_pnpbios_ca = {
     79  1.3.2.2  lukem 	sizeof(struct fdc_pnpbios_softc), fdc_pnpbios_match,
     80  1.3.2.2  lukem 	    fdc_pnpbios_attach,
     81  1.3.2.2  lukem };
     82  1.3.2.2  lukem 
     83  1.3.2.2  lukem int
     84  1.3.2.2  lukem fdc_pnpbios_match(struct device *parent,
     85  1.3.2.2  lukem     struct cfdata *match,
     86  1.3.2.2  lukem     void *aux)
     87  1.3.2.2  lukem {
     88  1.3.2.2  lukem 	struct pnpbiosdev_attach_args *aa = aux;
     89  1.3.2.2  lukem 
     90  1.3.2.2  lukem 	if (strcmp(aa->idstr, "PNP0700") == 0)
     91  1.3.2.2  lukem 		return (1);
     92  1.3.2.2  lukem 
     93  1.3.2.2  lukem 	return (0);
     94  1.3.2.2  lukem }
     95  1.3.2.2  lukem 
     96  1.3.2.2  lukem void
     97  1.3.2.2  lukem fdc_pnpbios_attach(struct device *parent,
     98  1.3.2.2  lukem     struct device *self,
     99  1.3.2.2  lukem     void *aux)
    100  1.3.2.2  lukem {
    101  1.3.2.2  lukem 	struct fdc_softc *fdc = (void *) self;
    102  1.3.2.2  lukem         struct fdc_pnpbios_softc *pdc = (void *) self;
    103  1.3.2.2  lukem 	struct pnpbiosdev_attach_args *aa = aux;
    104  1.3.2.2  lukem         int size, base;
    105  1.3.2.2  lukem 
    106  1.3.2.2  lukem 	printf("\n");
    107  1.3.2.2  lukem 
    108  1.3.2.2  lukem 	fdc->sc_ic = aa->ic;
    109  1.3.2.2  lukem 
    110  1.3.2.2  lukem 	if (pnpbios_io_map(aa->pbt, aa->resc, 0, &fdc->sc_iot,
    111  1.3.2.2  lukem             &pdc->sc_baseioh)) {
    112  1.3.2.2  lukem 		printf("%s: unable to map I/O space\n", fdc->sc_dev.dv_xname);
    113  1.3.2.2  lukem 		return;
    114  1.3.2.2  lukem 	}
    115  1.3.2.2  lukem 
    116  1.3.2.2  lukem 	/*
    117  1.3.2.2  lukem          * Start accounting for "odd" pnpbios's. Some probe as 4 ports,
    118  1.3.2.2  lukem          * some as 6 and some don't give the ctl port back.
    119  1.3.2.2  lukem          */
    120  1.3.2.2  lukem 
    121  1.3.2.2  lukem         if (pnpbios_getiosize(aa->pbt, aa->resc, 0, &size)) {
    122  1.3.2.2  lukem                 printf("%s: can't get iobase size\n", fdc->sc_dev.dv_xname);
    123  1.3.2.2  lukem                 return;
    124  1.3.2.2  lukem         }
    125  1.3.2.2  lukem 
    126  1.3.2.2  lukem         switch (size) {
    127  1.3.2.2  lukem 
    128  1.3.2.2  lukem         /* Easy case. This matches right up with what the fdc code expects. */
    129  1.3.2.2  lukem         case 4:
    130  1.3.2.2  lukem                 fdc->sc_ioh = pdc->sc_baseioh;
    131  1.3.2.2  lukem                 break;
    132  1.3.2.2  lukem 
    133  1.3.2.2  lukem         /* Map a subregion so this all lines up with the fdc code. */
    134  1.3.2.2  lukem         case 6:
    135  1.3.2.2  lukem                 if (bus_space_subregion(fdc->sc_iot, pdc->sc_baseioh, 2, 4,
    136  1.3.2.2  lukem                     &fdc->sc_ioh)) {
    137  1.3.2.2  lukem                         printf("%s: unable to subregion I/O space\n",
    138  1.3.2.2  lukem                             fdc->sc_dev.dv_xname);
    139  1.3.2.2  lukem                         return;
    140  1.3.2.2  lukem                 }
    141  1.3.2.2  lukem                 break;
    142  1.3.2.2  lukem         default:
    143  1.3.2.2  lukem                 printf ("%s: unknown size: %d of io mapping\n",
    144  1.3.2.2  lukem                     fdc->sc_dev.dv_xname, size);
    145  1.3.2.2  lukem                 return;
    146  1.3.2.2  lukem         }
    147  1.3.2.2  lukem 
    148  1.3.2.2  lukem         /*
    149  1.3.2.2  lukem          * XXX: This is bad. If the pnpbios claims only 1 I/O range then it's
    150  1.3.2.2  lukem          * omitting the controller I/O port. (One has to exist for there to
    151  1.3.2.2  lukem          * be a working fdc). Just try and force the mapping in.
    152  1.3.2.2  lukem          */
    153  1.3.2.2  lukem 
    154  1.3.2.2  lukem         if (aa->resc->numio == 1) {
    155  1.3.2.2  lukem 
    156  1.3.2.2  lukem                 if (pnpbios_getiobase(aa->pbt, aa->resc, 0, 0, &base)) {
    157  1.3.2.2  lukem                         printf ("%s: can't get iobase\n",
    158  1.3.2.2  lukem                             fdc->sc_dev.dv_xname);
    159  1.3.2.2  lukem                         return;
    160  1.3.2.2  lukem                 }
    161  1.3.2.2  lukem                 if (bus_space_map(fdc->sc_iot, base + size + 1, 1, 0,
    162  1.3.2.2  lukem                     &fdc->sc_fdctlioh)) {
    163  1.3.2.2  lukem                         printf("%s: unable to force map CTL I/O space\n",
    164  1.3.2.2  lukem                             fdc->sc_dev.dv_xname);
    165  1.3.2.2  lukem                         return;
    166  1.3.2.2  lukem                 }
    167  1.3.2.2  lukem         } else if (pnpbios_io_map(aa->pbt, aa->resc, 1, &fdc->sc_iot,
    168  1.3.2.2  lukem             &fdc->sc_fdctlioh)) {
    169  1.3.2.2  lukem                 printf("%s: unable to map CTL I/O space\n",
    170  1.3.2.2  lukem 		    fdc->sc_dev.dv_xname);
    171  1.3.2.2  lukem 		return;
    172  1.3.2.2  lukem 	}
    173  1.3.2.2  lukem 
    174  1.3.2.2  lukem 	if (pnpbios_getdmachan(aa->pbt, aa->resc, 0, &fdc->sc_drq)) {
    175  1.3.2.2  lukem 		printf("%s: unable to get DMA channel\n",
    176  1.3.2.2  lukem 		    fdc->sc_dev.dv_xname);
    177  1.3.2.2  lukem 		return;
    178  1.3.2.2  lukem 	}
    179  1.3.2.2  lukem 
    180  1.3.2.2  lukem 	pnpbios_print_devres(self, aa);
    181  1.3.2.2  lukem         if (aa->resc->numio == 1)
    182  1.3.2.2  lukem                 printf("%s: ctl io %x didn't probe. Forced attach\n",
    183  1.3.2.2  lukem                     fdc->sc_dev.dv_xname, base + size + 1);
    184  1.3.2.2  lukem 
    185  1.3.2.2  lukem 	fdc->sc_ih = pnpbios_intr_establish(aa->pbt, aa->resc, 0, IPL_BIO,
    186  1.3.2.2  lukem 	    fdcintr, fdc);
    187  1.3.2.2  lukem 
    188  1.3.2.2  lukem 	fdcattach(fdc);
    189  1.3.2.2  lukem }
    190