LCOV - code coverage report
Current view: top level - dev/cardbus - uhci_cardbus.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 78 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*      $OpenBSD: uhci_cardbus.c,v 1.15 2015/03/14 03:38:47 jsg Exp $   */
       2             : 
       3             : /*
       4             :  * Copyright (c) 1998 The NetBSD Foundation, Inc.
       5             :  * All rights reserved.
       6             :  *
       7             :  * This code is derived from software contributed to The NetBSD Foundation
       8             :  * by Lennart Augustsson (lennart@augustsson.net) at
       9             :  * Carlstedt Research & Technology.
      10             :  *
      11             :  * Redistribution and use in source and binary forms, with or without
      12             :  * modification, are permitted provided that the following conditions
      13             :  * are met:
      14             :  * 1. Redistributions of source code must retain the above copyright
      15             :  *    notice, this list of conditions and the following disclaimer.
      16             :  * 2. Redistributions in binary form must reproduce the above copyright
      17             :  *    notice, this list of conditions and the following disclaimer in the
      18             :  *    documentation and/or other materials provided with the distribution.
      19             :  *
      20             :  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
      21             :  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
      22             :  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
      23             :  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
      24             :  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      25             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
      26             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
      27             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      28             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
      29             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      30             :  * POSSIBILITY OF SUCH DAMAGE.
      31             :  */
      32             : 
      33             : #include <sys/param.h>
      34             : #include <sys/systm.h>
      35             : #include <sys/kernel.h>
      36             : #include <sys/device.h>
      37             : 
      38             : #include <machine/bus.h>
      39             : 
      40             : #include <dev/cardbus/cardbusvar.h>
      41             : 
      42             : #include <dev/usb/usb.h>
      43             : #include <dev/usb/usbdi.h>
      44             : #include <dev/usb/usbdivar.h>
      45             : #include <dev/usb/usb_mem.h>
      46             : 
      47             : #include <dev/usb/uhcireg.h>
      48             : #include <dev/usb/uhcivar.h>
      49             : 
      50             : int     uhci_cardbus_match(struct device *, void *, void *);
      51             : void    uhci_cardbus_attach(struct device *, struct device *, void *);
      52             : int     uhci_cardbus_detach(struct device *, int);
      53             : 
      54             : struct uhci_cardbus_softc {
      55             :         struct uhci_softc       sc;
      56             :         cardbus_chipset_tag_t   sc_cc;
      57             :         cardbus_function_tag_t  sc_cf;
      58             :         cardbus_devfunc_t       sc_ct;
      59             :         void                    *sc_ih;         /* interrupt vectoring */
      60             : };
      61             : 
      62             : struct cfattach uhci_cardbus_ca = {
      63             :         sizeof(struct uhci_cardbus_softc), uhci_cardbus_match,
      64             :             uhci_cardbus_attach, uhci_cardbus_detach, uhci_activate
      65             : };
      66             : 
      67             : #define cardbus_findvendor pci_findvendor
      68             : 
      69             : int
      70           0 : uhci_cardbus_match(struct device *parent, void *match, void *aux)
      71             : {
      72           0 :         struct cardbus_attach_args *ca = (struct cardbus_attach_args *)aux;
      73             : 
      74           0 :         if (PCI_CLASS(ca->ca_class) == PCI_CLASS_SERIALBUS &&
      75           0 :             PCI_SUBCLASS(ca->ca_class) == PCI_SUBCLASS_SERIALBUS_USB &&
      76           0 :             PCI_INTERFACE(ca->ca_class) == PCI_INTERFACE_UHCI)
      77           0 :                 return (1);
      78             :  
      79           0 :         return (0);
      80           0 : }
      81             : 
      82             : void
      83           0 : uhci_cardbus_attach(struct device *parent, struct device *self, void *aux)
      84             : {
      85           0 :         struct uhci_cardbus_softc *sc = (struct uhci_cardbus_softc *)self;
      86           0 :         struct cardbus_attach_args *ca = aux;
      87           0 :         cardbus_devfunc_t ct = ca->ca_ct;
      88           0 :         cardbus_chipset_tag_t cc = ct->ct_cc;
      89           0 :         pci_chipset_tag_t pc = ca->ca_pc;
      90           0 :         cardbus_function_tag_t cf = ct->ct_cf;
      91             :         pcireg_t csr;
      92             :         usbd_status r;
      93             :         const char *vendor;
      94           0 :         const char *devname = sc->sc.sc_bus.bdev.dv_xname;
      95             : 
      96             :         /* Map I/O registers */
      97           0 :         if (Cardbus_mapreg_map(ct, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
      98             :                            &sc->sc.iot, &sc->sc.ioh, NULL, &sc->sc.sc_size)) {
      99           0 :                 printf(": can't map io space\n");
     100           0 :                 return;
     101             :         }
     102             : 
     103             :         /* Disable interrupts, so we don't get any spurious ones. */
     104           0 :         bus_space_write_2(sc->sc.iot, sc->sc.ioh, UHCI_INTR, 0);
     105             : 
     106           0 :         sc->sc_cc = cc;
     107           0 :         sc->sc_cf = cf;
     108           0 :         sc->sc_ct = ct;
     109           0 :         sc->sc.sc_bus.dmatag = ca->ca_dmat;
     110             : 
     111           0 :         (ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_IO_ENABLE);
     112           0 :         (ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE);
     113             : 
     114             :         /* Enable the device. */
     115           0 :         csr = pci_conf_read(pc, ca->ca_tag,
     116             :                                 PCI_COMMAND_STATUS_REG);
     117           0 :         pci_conf_write(pc, ca->ca_tag, PCI_COMMAND_STATUS_REG,
     118           0 :                        csr | PCI_COMMAND_MASTER_ENABLE
     119           0 :                            | PCI_COMMAND_IO_ENABLE);
     120             : 
     121           0 :         sc->sc_ih = cardbus_intr_establish(cc, cf, ca->ca_intrline,
     122           0 :                                            IPL_USB, uhci_intr, sc, devname);
     123           0 :         if (sc->sc_ih == NULL) {
     124           0 :                 printf(": couldn't establish interrupt\n");
     125           0 :                 return;
     126             :         }
     127           0 :         printf(": irq %d\n", ca->ca_intrline);
     128             : 
     129             :         /* Set LEGSUP register to its default value. */
     130           0 :         pci_conf_write(pc, ca->ca_tag, PCI_LEGSUP,
     131             :                            PCI_LEGSUP_USBPIRQDEN);
     132             : 
     133           0 :         switch(pci_conf_read(pc, ca->ca_tag, PCI_USBREV) & PCI_USBREV_MASK) {
     134             :         case PCI_USBREV_PRE_1_0:
     135           0 :                 sc->sc.sc_bus.usbrev = USBREV_PRE_1_0;
     136           0 :                 break;
     137             :         case PCI_USBREV_1_0:
     138           0 :                 sc->sc.sc_bus.usbrev = USBREV_1_0;
     139           0 :                 break;
     140             :         case PCI_USBREV_1_1:
     141           0 :                 sc->sc.sc_bus.usbrev = USBREV_1_1;
     142           0 :                 break;
     143             :         default:
     144           0 :                 sc->sc.sc_bus.usbrev = USBREV_UNKNOWN;
     145           0 :                 break;
     146             :         }
     147             : 
     148           0 :         uhci_run(&sc->sc, 0);                    /* stop the controller */
     149             :                                                 /* disable interrupts */
     150           0 :         bus_space_barrier(sc->sc.iot, sc->sc.ioh, 0, sc->sc.sc_size,
     151             :             BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE);
     152           0 :         bus_space_write_2(sc->sc.iot, sc->sc.ioh, UHCI_INTR, 0);
     153             : 
     154             :         /* Figure out vendor for root hub descriptor. */
     155           0 :         vendor = cardbus_findvendor(ca->ca_id);
     156           0 :         sc->sc.sc_id_vendor = PCI_VENDOR(ca->ca_id);
     157           0 :         if (vendor)
     158           0 :                 strlcpy(sc->sc.sc_vendor, vendor, sizeof (sc->sc.sc_vendor));
     159             :         else
     160           0 :                 snprintf(sc->sc.sc_vendor, sizeof(sc->sc.sc_vendor),
     161           0 :                     "vendor 0x%04x", PCI_VENDOR(ca->ca_id));
     162             :         
     163           0 :         r = uhci_init(&sc->sc);
     164           0 :         if (r != USBD_NORMAL_COMPLETION) {
     165           0 :                 printf("%s: init failed, error=%d\n", devname, r);
     166           0 :                 bus_space_unmap(sc->sc.iot, sc->sc.ioh, sc->sc.sc_size);
     167           0 :                 return;
     168             :         }
     169             : 
     170             :         /* Attach usb device. */
     171           0 :         config_found(self, &sc->sc.sc_bus, usbctlprint);
     172           0 : }
     173             : 
     174             : int
     175           0 : uhci_cardbus_detach(struct device *self, int flags)
     176             : {
     177           0 :         struct uhci_cardbus_softc *sc = (struct uhci_cardbus_softc *)self;
     178           0 :         struct cardbus_devfunc *ct = sc->sc_ct;
     179             :         int rv;
     180             : 
     181           0 :         rv = uhci_detach(self, flags);
     182           0 :         if (rv)
     183           0 :                 return (rv);
     184             : 
     185           0 :         if (sc->sc_ih != NULL) {
     186           0 :                 cardbus_intr_disestablish(sc->sc_cc, sc->sc_cf, sc->sc_ih);
     187           0 :                 sc->sc_ih = NULL;
     188           0 :         }
     189             : 
     190           0 :         if (sc->sc.sc_size) {
     191           0 :                 Cardbus_mapreg_unmap(ct, PCI_CBIO, sc->sc.iot,
     192             :                     sc->sc.ioh, sc->sc.sc_size);
     193           0 :                 sc->sc.sc_size = 0;
     194           0 :         }
     195             : 
     196           0 :         return (0);
     197           0 : }

Generated by: LCOV version 1.13