The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/pci/cy_pci.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 1996, David Greenman
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice unmodified, this list of conditions, and the following
   10  *    disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  *
   15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   25  * SUCH DAMAGE.
   26  */
   27 
   28 /*
   29  * Cyclades Y PCI serial interface driver
   30  */
   31 
   32 #include <sys/cdefs.h>
   33 __FBSDID("$FreeBSD: releng/5.2/sys/pci/cy_pci.c 123105 2003-12-02 12:47:08Z bde $");
   34 
   35 #include "opt_cy_pci_fastintr.h"
   36 
   37 #include <sys/param.h>
   38 #include <sys/systm.h>
   39 #include <sys/kernel.h>
   40 #include <sys/bus.h>
   41 
   42 #include <machine/bus.h>
   43 #include <sys/rman.h>
   44 #include <machine/resource.h>
   45 
   46 #include <vm/vm.h>
   47 #include <vm/pmap.h>
   48 
   49 #include <dev/pci/pcivar.h>
   50 
   51 #define CY_PCI_BASE_ADDR0               0x10
   52 #define CY_PCI_BASE_ADDR1               0x14
   53 #define CY_PCI_BASE_ADDR2               0x18
   54 
   55 #define CY_PLX_9050_ICS                 0x4c
   56 #define CY_PLX_9060_ICS                 0x68
   57 #define CY_PLX_9050_ICS_IENABLE         0x040
   58 #define CY_PLX_9050_ICS_LOCAL_IENABLE   0x001
   59 #define CY_PLX_9050_ICS_LOCAL_IPOLARITY 0x002
   60 #define CY_PLX_9060_ICS_IENABLE         0x100
   61 #define CY_PLX_9060_ICS_LOCAL_IENABLE   0x800
   62 
   63 /* Cyclom-Y Custom Register for PLX ID. */
   64 #define PLX_VER                         0x3400
   65 #define PLX_9050                        0x0b
   66 #define PLX_9060                        0x0c
   67 #define PLX_9080                        0x0d
   68 
   69 void    *cyattach_common(u_char volatile *iobase, int cy_align);
   70 driver_intr_t   cyintr;
   71 
   72 static int      cy_pci_attach(device_t dev);
   73 static int      cy_pci_probe(device_t dev);
   74 
   75 static device_method_t cy_pci_methods[] = {
   76         /* Device interface. */
   77         DEVMETHOD(device_probe,         cy_pci_probe),
   78         DEVMETHOD(device_attach,        cy_pci_attach),
   79 
   80         { 0, 0 }
   81 };
   82 
   83 static driver_t cy_pci_driver = {
   84         "cy",
   85         cy_pci_methods,
   86         0,
   87 };
   88 
   89 static devclass_t       cy_devclass;
   90 
   91 DRIVER_MODULE(cy, pci, cy_pci_driver, cy_devclass, 0, 0);
   92 MODULE_DEPEND(cy, pci, 1, 1, 1);
   93 
   94 static int
   95 cy_pci_probe(dev)
   96         device_t dev;
   97 {
   98         u_int32_t device_id;
   99 
  100         device_id = pci_get_devid(dev);
  101         device_id &= ~0x00060000;
  102         if (device_id != 0x0100120e && device_id != 0x0101120e)
  103                 return (ENXIO);
  104         device_set_desc(dev, "Cyclades Cyclom-Y Serial Adapter");
  105         return (0);
  106 }
  107 
  108 static int
  109 cy_pci_attach(dev)
  110         device_t dev;
  111 {
  112         struct resource *ioport_res, *irq_res, *mem_res;
  113         void *irq_cookie, *vaddr, *vsc;
  114         u_int32_t ioport;
  115         int irq_setup, ioport_rid, irq_rid, mem_rid;
  116         u_char plx_ver;
  117 
  118         ioport_res = NULL;
  119         irq_res = NULL;
  120         mem_res = NULL;
  121 
  122         ioport_rid = CY_PCI_BASE_ADDR1;
  123         ioport_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &ioport_rid,
  124             0ul, ~0ul, 0ul, RF_ACTIVE);
  125         if (ioport_res == NULL) {
  126                 device_printf(dev, "ioport resource allocation failed\n");
  127                 goto fail;
  128         }
  129         ioport = rman_get_start(ioport_res);
  130 
  131         mem_rid = CY_PCI_BASE_ADDR2;
  132         mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &mem_rid,
  133             0ul, ~0ul, 0ul, RF_ACTIVE);
  134         if (mem_res == NULL) {
  135                 device_printf(dev, "memory resource allocation failed\n");
  136                 goto fail;
  137         }
  138         vaddr = rman_get_virtual(mem_res);
  139 
  140         vsc = cyattach_common(vaddr, 1);
  141         if (vsc == NULL) {
  142                 device_printf(dev, "no ports found!\n");
  143                 goto fail;
  144         }
  145 
  146         irq_rid = 0;
  147         irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &irq_rid, 0ul, ~0ul, 0ul,
  148             RF_SHAREABLE | RF_ACTIVE);
  149         if (irq_res == NULL) {
  150                 device_printf(dev, "interrupt resource allocation failed\n");
  151                 goto fail;
  152         }
  153 #ifdef CY_PCI_FASTINTR
  154         irq_setup = bus_setup_intr(dev, irq_res, INTR_TYPE_TTY | INTR_FAST,
  155             cyintr, vsc, &irq_cookie);
  156 #else
  157         irq_setup = ENXIO;
  158 #endif
  159         if (irq_setup != 0)
  160                 irq_setup = bus_setup_intr(dev, irq_res, INTR_TYPE_TTY,
  161                     cyintr, vsc, &irq_cookie);
  162         if (irq_setup != 0) {
  163                 device_printf(dev, "interrupt setup failed\n");
  164                 goto fail;
  165         }
  166 
  167         /*
  168          * Enable the "local" interrupt input to generate a
  169          * PCI interrupt.
  170          */
  171         plx_ver = *((u_char *)vaddr + PLX_VER) & 0x0f;
  172         switch (plx_ver) {
  173         case PLX_9050:
  174                 outw(ioport + CY_PLX_9050_ICS,
  175                     CY_PLX_9050_ICS_IENABLE | CY_PLX_9050_ICS_LOCAL_IENABLE |
  176                     CY_PLX_9050_ICS_LOCAL_IPOLARITY);
  177                 break;
  178         case PLX_9060:
  179         case PLX_9080:
  180         default:                /* Old board, use PLX_9060 values. */
  181                 outw(ioport + CY_PLX_9060_ICS,
  182                     inw(ioport + CY_PLX_9060_ICS) | CY_PLX_9060_ICS_IENABLE |
  183                     CY_PLX_9060_ICS_LOCAL_IENABLE);
  184                 break;
  185         }
  186 
  187         return (0);
  188 
  189 fail:
  190         if (ioport_res != NULL)
  191                 bus_release_resource(dev, SYS_RES_IOPORT, ioport_rid,
  192                     ioport_res);
  193         if (irq_res != NULL)
  194                 bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
  195         if (mem_res != NULL)
  196                 bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);
  197         return (ENXIO);
  198 }

Cache object: 6937851f7d5adeccb2a00594f54934ed


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.