Home | History | Annotate | Line # | Download | only in pnpbus
      1  1.6   andvar /*	$NetBSD: fdc_pnpbus.c,v 1.6 2021/07/24 21:31:34 andvar Exp $	*/
      2  1.1  garbled 
      3  1.1  garbled /*-
      4  1.1  garbled  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      5  1.1  garbled  * All rights reserved.
      6  1.1  garbled  *
      7  1.1  garbled  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  garbled  * by Tim Rightnour
      9  1.1  garbled  *
     10  1.1  garbled  * Redistribution and use in source and binary forms, with or without
     11  1.1  garbled  * modification, are permitted provided that the following conditions
     12  1.1  garbled  * are met:
     13  1.1  garbled  * 1. Redistributions of source code must retain the above copyright
     14  1.1  garbled  *    notice, this list of conditions and the following disclaimer.
     15  1.1  garbled  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  garbled  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  garbled  *    documentation and/or other materials provided with the distribution.
     18  1.1  garbled  *
     19  1.1  garbled  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  garbled  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  garbled  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  garbled  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  garbled  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  garbled  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  garbled  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  garbled  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  garbled  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  garbled  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  garbled  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  garbled  */
     31  1.1  garbled 
     32  1.1  garbled /*
     33  1.1  garbled  * PNPBIOS attachment for the PC Floppy Controller driver.
     34  1.1  garbled  */
     35  1.1  garbled 
     36  1.1  garbled #include <sys/cdefs.h>
     37  1.6   andvar __KERNEL_RCSID(0, "$NetBSD: fdc_pnpbus.c,v 1.6 2021/07/24 21:31:34 andvar Exp $");
     38  1.1  garbled 
     39  1.1  garbled #include <sys/param.h>
     40  1.1  garbled #include <sys/systm.h>
     41  1.1  garbled #include <sys/callout.h>
     42  1.1  garbled #include <sys/device.h>
     43  1.1  garbled #include <sys/buf.h>
     44  1.1  garbled #include <sys/queue.h>
     45  1.1  garbled 
     46  1.3   dyoung #include <sys/bus.h>
     47  1.1  garbled #include <machine/intr.h>
     48  1.1  garbled #include <machine/isa_machdep.h>
     49  1.1  garbled 
     50  1.1  garbled #include <dev/isa/isavar.h>
     51  1.1  garbled #include <dev/isa/isadmavar.h>
     52  1.1  garbled 
     53  1.1  garbled #include <dev/isa/fdcvar.h>
     54  1.1  garbled 
     55  1.1  garbled #include <prep/pnpbus/pnpbusvar.h>
     56  1.1  garbled 
     57  1.1  garbled static int	fdc_pnpbus_match(device_t, cfdata_t, void *);
     58  1.1  garbled static void	fdc_pnpbus_attach(device_t, device_t, void *);
     59  1.1  garbled 
     60  1.1  garbled struct fdc_pnpbus_softc {
     61  1.1  garbled         struct fdc_softc sc_fdc;        /* base fdc device */
     62  1.1  garbled 
     63  1.1  garbled         bus_space_handle_t sc_baseioh;  /* base I/O handle */
     64  1.1  garbled };
     65  1.1  garbled 
     66  1.1  garbled CFATTACH_DECL2_NEW(fdc_pnpbus, sizeof(struct fdc_pnpbus_softc),
     67  1.1  garbled     fdc_pnpbus_match, fdc_pnpbus_attach, NULL, NULL, NULL, NULL);
     68  1.1  garbled 
     69  1.1  garbled static int
     70  1.1  garbled fdc_pnpbus_match(device_t parent, cfdata_t match, void *aux)
     71  1.1  garbled {
     72  1.1  garbled 	struct pnpbus_dev_attach_args *pna = aux;
     73  1.1  garbled 	int ret = 0;
     74  1.1  garbled 
     75  1.1  garbled 	if (strcmp(pna->pna_devid, "PNP0700") == 0)
     76  1.1  garbled 		ret = 1;
     77  1.1  garbled 
     78  1.1  garbled 	if (ret)
     79  1.1  garbled 		pnpbus_scan(pna, pna->pna_ppc_dev);
     80  1.1  garbled 
     81  1.1  garbled 	return ret;
     82  1.1  garbled }
     83  1.1  garbled 
     84  1.1  garbled static void
     85  1.1  garbled fdc_pnpbus_attach(device_t parent, device_t self, void *aux)
     86  1.1  garbled {
     87  1.1  garbled         struct fdc_pnpbus_softc *pdc = device_private(self);
     88  1.1  garbled 	struct fdc_softc *fdc = &pdc->sc_fdc;
     89  1.1  garbled 	struct pnpbus_dev_attach_args *pna = aux;
     90  1.1  garbled         int size, base;
     91  1.1  garbled 
     92  1.1  garbled 	fdc->sc_dev = self;
     93  1.1  garbled 	fdc->sc_ic = pna->pna_ic;
     94  1.1  garbled 
     95  1.1  garbled 	if (pnpbus_io_map(&pna->pna_res, 0, &fdc->sc_iot, &pdc->sc_baseioh)) {
     96  1.1  garbled 		aprint_error_dev(self, "unable to map I/O space\n");
     97  1.1  garbled 		return;
     98  1.1  garbled 	}
     99  1.1  garbled 
    100  1.1  garbled 	/*
    101  1.1  garbled          * Start accounting for "odd" pnpbus's. Some probe as 4 ports,
    102  1.1  garbled          * some as 6 and some don't give the ctl port back.
    103  1.1  garbled          */
    104  1.1  garbled 
    105  1.1  garbled         if (pnpbus_getioport(&pna->pna_res, 0, &base, &size)) {
    106  1.1  garbled                 aprint_error_dev(self, "can't get iobase size\n");
    107  1.1  garbled                 return;
    108  1.1  garbled         }
    109  1.1  garbled 
    110  1.1  garbled         switch (size) {
    111  1.1  garbled 
    112  1.1  garbled         /* Easy case. This matches right up with what the fdc code expects. */
    113  1.1  garbled         case 4:
    114  1.1  garbled                 fdc->sc_ioh = pdc->sc_baseioh;
    115  1.1  garbled                 break;
    116  1.1  garbled 
    117  1.1  garbled         /* Map a subregion so this all lines up with the fdc code. */
    118  1.1  garbled         case 6:
    119  1.1  garbled                 if (bus_space_subregion(fdc->sc_iot, pdc->sc_baseioh, 2, 4,
    120  1.1  garbled                     &fdc->sc_ioh)) {
    121  1.1  garbled                         aprint_error_dev(self,
    122  1.1  garbled 			    "unable to subregion I/O space\n");
    123  1.1  garbled                         return;
    124  1.1  garbled                 }
    125  1.1  garbled                 break;
    126  1.1  garbled         default:
    127  1.1  garbled                 aprint_error_dev(self, "unknown size: %d of io mapping\n", size);
    128  1.1  garbled                 return;
    129  1.1  garbled         }
    130  1.1  garbled 
    131  1.1  garbled         /*
    132  1.1  garbled          * XXX: This is bad. If the pnpbus claims only 1 I/O range then it's
    133  1.1  garbled          * omitting the controller I/O port. (One has to exist for there to
    134  1.1  garbled          * be a working fdc). Just try and force the mapping in.
    135  1.1  garbled          */
    136  1.1  garbled 
    137  1.1  garbled         if (pna->pna_res.numio == 1) {
    138  1.1  garbled                 if (bus_space_map(fdc->sc_iot, base + size + 1, 1, 0,
    139  1.1  garbled                     &fdc->sc_fdctlioh)) {
    140  1.1  garbled                         aprint_error_dev(self,
    141  1.1  garbled 			    "unable to force map CTL I/O space\n");
    142  1.1  garbled                         return;
    143  1.1  garbled                 }
    144  1.1  garbled         } else if (pnpbus_io_map(&pna->pna_res, 1, &fdc->sc_iot,
    145  1.1  garbled 		   &fdc->sc_fdctlioh)) {
    146  1.1  garbled                 aprint_error_dev(self, "unable to map CTL I/O space\n");
    147  1.1  garbled 		return;
    148  1.1  garbled 	}
    149  1.1  garbled 
    150  1.1  garbled 	if (pnpbus_getdmachan(&pna->pna_res, 0, &fdc->sc_drq)) {
    151  1.1  garbled 		aprint_error_dev(self, "unable to get DMA channel\n");
    152  1.1  garbled 		return;
    153  1.1  garbled 	}
    154  1.1  garbled 
    155  1.1  garbled         if (pna->pna_res.numio == 1)
    156  1.1  garbled                 aprint_normal_dev(self,
    157  1.1  garbled 		    "ctl io %x didn't probe. Forced attach\n", base + size + 1);
    158  1.1  garbled 
    159  1.1  garbled 	aprint_normal("\n");
    160  1.1  garbled 
    161  1.6   andvar 	/* The 7043-140 gets the type wrong, so override to edge always */
    162  1.1  garbled 	fdc->sc_ih = pnpbus_intr_establish(0, IPL_BIO, IST_EDGE, fdcintr, fdc,
    163  1.1  garbled 	    &pna->pna_res);
    164  1.1  garbled 
    165  1.1  garbled 	fdcattach(fdc);
    166  1.1  garbled }
    167