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