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  * $FreeBSD: releng/5.1/sys/pci/cy_pci.c 113506 2003-04-15 06:37:30Z mdodd $
   28  */
   29 
   30 /*
   31  * Cyclades Y PCI serial interface driver
   32  */
   33 
   34 #include "opt_cy_pci_fastintr.h"
   35 
   36 #include <sys/param.h>
   37 #include <sys/systm.h>
   38 #include <sys/kernel.h>
   39 #include <sys/bus.h>
   40 
   41 #include <machine/bus.h>
   42 #include <sys/rman.h>
   43 #include <machine/resource.h>
   44 
   45 #include <vm/vm.h>
   46 #include <vm/pmap.h>
   47 
   48 #include <dev/pci/pcivar.h>
   49 
   50 #define CY_PCI_BASE_ADDR0               0x10
   51 #define CY_PCI_BASE_ADDR1               0x14
   52 #define CY_PCI_BASE_ADDR2               0x18
   53 
   54 #define CY_PLX_9050_ICS                 0x4c
   55 #define CY_PLX_9060_ICS                 0x68
   56 #define CY_PLX_9050_ICS_IENABLE         0x040
   57 #define CY_PLX_9050_ICS_LOCAL_IENABLE   0x001
   58 #define CY_PLX_9050_ICS_LOCAL_IPOLARITY 0x002
   59 #define CY_PLX_9060_ICS_IENABLE         0x100
   60 #define CY_PLX_9060_ICS_LOCAL_IENABLE   0x800
   61 
   62 /* Cyclom-Y Custom Register for PLX ID. */
   63 #define PLX_VER                         0x3400
   64 #define PLX_9050                        0x0b
   65 #define PLX_9060                        0x0c
   66 #define PLX_9080                        0x0d
   67 
   68 extern int cyattach_common(void *, int); /* Not exactly correct */
   69 extern void cyintr(int);
   70 
   71 static int      cy_pci_attach(device_t dev);
   72 static int      cy_pci_probe(device_t dev);
   73 
   74 static device_method_t cy_pci_methods[] = {
   75         /* Device interface. */
   76         DEVMETHOD(device_probe,         cy_pci_probe),
   77         DEVMETHOD(device_attach,        cy_pci_attach),
   78 
   79         { 0, 0 }
   80 };
   81 
   82 static driver_t cy_pci_driver = {
   83         "cy",
   84         cy_pci_methods,
   85         0,
   86 };
   87 
   88 static devclass_t       cy_devclass;
   89 
   90 DRIVER_MODULE(cy, pci, cy_pci_driver, cy_devclass, 0, 0);
   91 MODULE_DEPEND(cy, pci, 1, 1, 1);
   92 
   93 static int
   94 cy_pci_probe(dev)
   95         device_t dev;
   96 {
   97         u_int32_t device_id;
   98 
   99         device_id = pci_get_devid(dev);
  100         device_id &= ~0x00060000;
  101         if (device_id != 0x0100120e && device_id != 0x0101120e)
  102                 return (ENXIO);
  103         device_set_desc(dev, "Cyclades Cyclom-Y Serial Adapter");
  104         return (0);
  105 }
  106 
  107 static int
  108 cy_pci_attach(dev)
  109         device_t dev;
  110 {
  111         struct resource *ioport_res, *irq_res, *mem_res;
  112         void *irq_cookie, *vaddr;
  113         u_int32_t ioport;
  114         int adapter, irq_setup, ioport_rid, irq_rid, mem_rid;
  115         u_char plx_ver;
  116 
  117         ioport_res = NULL;
  118         irq_res = NULL;
  119         mem_res = NULL;
  120 
  121         ioport_rid = CY_PCI_BASE_ADDR1;
  122         ioport_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &ioport_rid,
  123             0ul, ~0ul, 0ul, RF_ACTIVE);
  124         if (ioport_res == NULL) {
  125                 device_printf(dev, "ioport resource allocation failed\n");
  126                 goto fail;
  127         }
  128         ioport = rman_get_start(ioport_res);
  129 
  130         mem_rid = CY_PCI_BASE_ADDR2;
  131         mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &mem_rid,
  132              0ul, ~0ul, 0ul, RF_ACTIVE);
  133         if (mem_res == NULL) {
  134                 device_printf(dev, "memory resource allocation failed\n");
  135                 goto fail;
  136         }
  137         vaddr = rman_get_virtual(mem_res);
  138 
  139         adapter = cyattach_common(vaddr, 1);
  140         if (adapter < 0) {
  141                 device_printf(dev, "no ports found!\n");
  142                 goto fail;
  143         }
  144 
  145         /*
  146          * Allocate our interrupt.
  147          * XXX  Using the ISA interrupt handler directly is a bit of a violation
  148          *      since it doesn't actually take the same argument. For PCI, the
  149          *      argument is a void * token, but for ISA it is a unit. Since
  150          *      there is no overlap in PCI/ISA unit numbers for this driver, and
  151          *      since the ISA driver must handle the interrupt anyway, we use
  152          *      the unit number as the token even for PCI.
  153          */
  154         irq_rid = 0;
  155         irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &irq_rid, 0ul, ~0ul, 0ul,
  156             RF_SHAREABLE | RF_ACTIVE);
  157         if (irq_res == NULL) {
  158                 device_printf(dev, "interrupt resource allocation failed\n");
  159                 goto fail;
  160         }
  161 #ifdef CY_PCI_FASTINTR
  162         irq_setup = bus_setup_intr(dev, irq_res, INTR_TYPE_TTY | INTR_FAST,
  163             (driver_intr_t *)cyintr, (void *)adapter, &irq_cookie);
  164 #else
  165         irq_setup = ENXIO;
  166 #endif
  167         if (irq_setup != 0)
  168                 irq_setup = bus_setup_intr(dev, irq_res, INTR_TYPE_TTY,
  169                     (driver_intr_t *)cyintr, (void *)adapter, &irq_cookie);
  170         if (irq_setup != 0) {
  171                 device_printf(dev, "interrupt setup failed\n");
  172                 goto fail;
  173         }
  174 
  175         /*
  176          * Enable the "local" interrupt input to generate a
  177          * PCI interrupt.
  178          */
  179         plx_ver = *((u_char *)vaddr + PLX_VER) & 0x0f;
  180         switch (plx_ver) {
  181         case PLX_9050:
  182                 outw(ioport + CY_PLX_9050_ICS,
  183                     CY_PLX_9050_ICS_IENABLE | CY_PLX_9050_ICS_LOCAL_IENABLE |
  184                     CY_PLX_9050_ICS_LOCAL_IPOLARITY);
  185                 break;
  186         case PLX_9060:
  187         case PLX_9080:
  188         default:                /* Old board, use PLX_9060 values. */
  189                 outw(ioport + CY_PLX_9060_ICS,
  190                     inw(ioport + CY_PLX_9060_ICS) | CY_PLX_9060_ICS_IENABLE |
  191                     CY_PLX_9060_ICS_LOCAL_IENABLE);
  192                 break;
  193         }
  194 
  195         return (0);
  196 
  197 fail:
  198         if (ioport_res != NULL)
  199                 bus_release_resource(dev, SYS_RES_IOPORT, ioport_rid,
  200                     ioport_res);
  201         if (irq_res != NULL)
  202                 bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
  203         if (mem_res != NULL)
  204                 bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);
  205         return (ENXIO);
  206 }

Cache object: e65b89193c97e707cab58b50badd27cd


[ 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.