1998-09-15 07:25:33 +00:00
|
|
|
/*
|
2000-09-16 20:02:28 +00:00
|
|
|
* FreeBSD, PCI product support functions
|
1998-09-15 07:25:33 +00:00
|
|
|
*
|
2000-01-07 22:53:37 +00:00
|
|
|
* Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 Justin T. Gibbs
|
1998-09-15 07:25:33 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions, and the following disclaimer,
|
|
|
|
* without modification, immediately at the beginning of the file.
|
|
|
|
* 2. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
2000-07-18 20:12:14 +00:00
|
|
|
* Alternatively, this software may be distributed under the terms of the
|
|
|
|
* GNU Public License ("GPL").
|
1998-09-15 07:25:33 +00:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
2000-09-16 20:02:28 +00:00
|
|
|
* $Id$
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1998-09-15 07:25:33 +00:00
|
|
|
*/
|
|
|
|
|
2000-09-16 20:02:28 +00:00
|
|
|
#include <dev/aic7xxx/aic7xxx_freebsd.h>
|
1999-05-14 05:09:24 +00:00
|
|
|
|
2000-09-16 20:02:28 +00:00
|
|
|
#define AHC_PCI_IOADDR PCIR_MAPS /* I/O Address */
|
|
|
|
#define AHC_PCI_MEMADDR (PCIR_MAPS + 4) /* Mem I/O Address */
|
1998-09-15 07:25:33 +00:00
|
|
|
|
1999-04-23 23:30:22 +00:00
|
|
|
static int ahc_pci_probe(device_t dev);
|
|
|
|
static int ahc_pci_attach(device_t dev);
|
1998-09-15 07:25:33 +00:00
|
|
|
|
1999-04-23 23:30:22 +00:00
|
|
|
static device_method_t ahc_pci_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, ahc_pci_probe),
|
|
|
|
DEVMETHOD(device_attach, ahc_pci_attach),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t ahc_pci_driver = {
|
1998-09-15 07:25:33 +00:00
|
|
|
"ahc",
|
1999-04-23 23:30:22 +00:00
|
|
|
ahc_pci_methods,
|
|
|
|
sizeof(struct ahc_softc)
|
1998-09-15 07:25:33 +00:00
|
|
|
};
|
|
|
|
|
1999-04-23 23:30:22 +00:00
|
|
|
static devclass_t ahc_devclass;
|
|
|
|
|
|
|
|
DRIVER_MODULE(ahc, pci, ahc_pci_driver, ahc_devclass, 0, 0);
|
1998-09-15 07:25:33 +00:00
|
|
|
|
1999-05-17 21:53:09 +00:00
|
|
|
static int
|
|
|
|
ahc_pci_probe(device_t dev)
|
|
|
|
{
|
2000-09-16 20:02:28 +00:00
|
|
|
struct ahc_pci_identity *entry;
|
1999-05-17 21:53:09 +00:00
|
|
|
|
|
|
|
entry = ahc_find_pci_device(dev);
|
|
|
|
if (entry != NULL) {
|
|
|
|
device_set_desc(dev, entry->name);
|
|
|
|
return (0);
|
1999-04-23 23:30:22 +00:00
|
|
|
}
|
|
|
|
return (ENXIO);
|
1998-09-15 07:25:33 +00:00
|
|
|
}
|
|
|
|
|
1999-04-23 23:30:22 +00:00
|
|
|
static int
|
|
|
|
ahc_pci_attach(device_t dev)
|
1998-09-15 07:25:33 +00:00
|
|
|
{
|
2000-09-16 20:02:28 +00:00
|
|
|
struct ahc_pci_identity *entry;
|
|
|
|
struct ahc_softc *ahc;
|
|
|
|
char *name;
|
|
|
|
int error;
|
1999-04-23 23:30:22 +00:00
|
|
|
|
1999-05-17 21:53:09 +00:00
|
|
|
entry = ahc_find_pci_device(dev);
|
|
|
|
if (entry == NULL)
|
|
|
|
return (ENXIO);
|
1998-09-15 07:25:33 +00:00
|
|
|
|
2000-09-16 20:02:28 +00:00
|
|
|
/*
|
|
|
|
* Allocate a softc for this card and
|
|
|
|
* set it up for attachment by our
|
|
|
|
* common detect routine.
|
|
|
|
*/
|
|
|
|
name = malloc(strlen(device_get_nameunit(dev)) + 1, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (name == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
strcpy(name, device_get_nameunit(dev));
|
|
|
|
ahc = ahc_alloc(NULL, name);
|
|
|
|
if (ahc == NULL)
|
1999-04-23 23:30:22 +00:00
|
|
|
return (ENOMEM);
|
1998-09-15 07:25:33 +00:00
|
|
|
|
|
|
|
/* Allocate a dmatag for our SCB DMA maps */
|
|
|
|
/* XXX Should be a child of the PCI bus dma tag */
|
1999-08-16 02:33:46 +00:00
|
|
|
error = bus_dma_tag_create(/*parent*/NULL, /*alignment*/1,
|
1998-09-15 07:25:33 +00:00
|
|
|
/*boundary*/0,
|
|
|
|
/*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
|
|
|
|
/*highaddr*/BUS_SPACE_MAXADDR,
|
|
|
|
/*filter*/NULL, /*filterarg*/NULL,
|
|
|
|
/*maxsize*/MAXBSIZE, /*nsegments*/AHC_NSEG,
|
|
|
|
/*maxsegsz*/AHC_MAXTRANSFER_SIZE,
|
2000-09-16 20:02:28 +00:00
|
|
|
/*flags*/BUS_DMA_ALLOCNOW,
|
|
|
|
&ahc->parent_dmat);
|
1998-09-15 07:25:33 +00:00
|
|
|
|
|
|
|
if (error != 0) {
|
1999-04-23 23:30:22 +00:00
|
|
|
printf("ahc_pci_attach: Could not allocate DMA tag "
|
|
|
|
"- error %d\n", error);
|
1998-09-15 07:25:33 +00:00
|
|
|
ahc_free(ahc);
|
1999-04-23 23:30:22 +00:00
|
|
|
return (ENOMEM);
|
1998-09-15 07:25:33 +00:00
|
|
|
}
|
2000-09-16 20:02:28 +00:00
|
|
|
ahc->dev_softc = dev;
|
|
|
|
error = ahc_pci_config(ahc, entry);
|
|
|
|
if (error != 0) {
|
1998-09-15 07:25:33 +00:00
|
|
|
ahc_free(ahc);
|
2000-09-16 20:02:28 +00:00
|
|
|
return (error);
|
1998-09-15 07:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ahc_attach(ahc);
|
1999-04-23 23:30:22 +00:00
|
|
|
return (0);
|
1998-09-15 07:25:33 +00:00
|
|
|
}
|
|
|
|
|
2000-09-16 20:02:28 +00:00
|
|
|
int
|
|
|
|
ahc_pci_map_registers(struct ahc_softc *ahc)
|
1998-09-15 07:25:33 +00:00
|
|
|
{
|
2000-09-16 20:02:28 +00:00
|
|
|
struct resource *regs;
|
|
|
|
u_int command;
|
|
|
|
int regs_type;
|
|
|
|
int regs_id;
|
1998-09-15 07:25:33 +00:00
|
|
|
|
2000-09-16 20:02:28 +00:00
|
|
|
command = ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/1);
|
|
|
|
regs = NULL;
|
|
|
|
regs_type = 0;
|
|
|
|
regs_id = 0;
|
2000-09-22 22:18:05 +00:00
|
|
|
#ifdef AHC_ALLOW_MEMIO
|
2000-09-16 20:02:28 +00:00
|
|
|
if ((command & PCIM_CMD_MEMEN) != 0) {
|
|
|
|
regs_type = SYS_RES_MEMORY;
|
|
|
|
regs_id = AHC_PCI_MEMADDR;
|
|
|
|
regs = bus_alloc_resource(ahc->dev_softc, regs_type,
|
|
|
|
®s_id, 0, ~0, 1, RF_ACTIVE);
|
|
|
|
if (regs != NULL) {
|
|
|
|
ahc->tag = rman_get_bustag(regs);
|
|
|
|
ahc->bsh = rman_get_bushandle(regs);
|
1998-09-15 07:25:33 +00:00
|
|
|
|
2000-01-07 22:53:37 +00:00
|
|
|
/*
|
2000-09-16 20:02:28 +00:00
|
|
|
* Do a quick test to see if memory mapped
|
|
|
|
* I/O is functioning correctly.
|
2000-01-07 22:53:37 +00:00
|
|
|
*/
|
2000-09-16 20:02:28 +00:00
|
|
|
if (ahc_inb(ahc, HCNTRL) == 0xFF) {
|
|
|
|
device_printf(ahc->dev_softc,
|
|
|
|
"PCI Device %d:%d:%d failed memory "
|
|
|
|
"mapped test. Using PIO.\n",
|
|
|
|
ahc_get_pci_bus(ahc->dev_softc),
|
|
|
|
ahc_get_pci_slot(ahc->dev_softc),
|
|
|
|
ahc_get_pci_function(ahc->dev_softc));
|
|
|
|
bus_release_resource(ahc->dev_softc, regs_type,
|
|
|
|
regs_id, regs);
|
|
|
|
regs = NULL;
|
2000-01-07 22:53:37 +00:00
|
|
|
}
|
1998-09-15 07:25:33 +00:00
|
|
|
}
|
|
|
|
}
|
2000-09-22 22:18:05 +00:00
|
|
|
#endif
|
2000-09-16 20:02:28 +00:00
|
|
|
if (regs == NULL && (command & PCIM_CMD_PORTEN) != 0) {
|
|
|
|
regs_type = SYS_RES_IOPORT;
|
|
|
|
regs_id = AHC_PCI_IOADDR;
|
|
|
|
regs = bus_alloc_resource(ahc->dev_softc, regs_type,
|
|
|
|
®s_id, 0, ~0, 1, RF_ACTIVE);
|
|
|
|
ahc->tag = rman_get_bustag(regs);
|
|
|
|
ahc->bsh = rman_get_bushandle(regs);
|
1998-09-15 07:25:33 +00:00
|
|
|
}
|
2000-09-16 20:02:28 +00:00
|
|
|
ahc->platform_data->regs_res_type = regs_type;
|
|
|
|
ahc->platform_data->regs_res_id = regs_id;
|
|
|
|
ahc->platform_data->regs = regs;
|
|
|
|
|
|
|
|
if (regs == NULL) {
|
|
|
|
device_printf(ahc->dev_softc,
|
|
|
|
"can't allocate register resources\n");
|
|
|
|
return (ENOMEM);
|
1999-05-14 17:38:07 +00:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-09-16 20:02:28 +00:00
|
|
|
int
|
|
|
|
ahc_pci_map_int(struct ahc_softc *ahc)
|
1999-05-14 17:38:07 +00:00
|
|
|
{
|
2000-09-16 20:02:28 +00:00
|
|
|
int zero;
|
2000-07-18 20:12:14 +00:00
|
|
|
|
2000-09-16 20:02:28 +00:00
|
|
|
zero = 0;
|
|
|
|
ahc->platform_data->irq =
|
|
|
|
bus_alloc_resource(ahc->dev_softc, SYS_RES_IRQ, &zero,
|
|
|
|
0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
|
|
|
|
if (ahc->platform_data->irq == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
ahc->platform_data->irq_res_type = SYS_RES_IRQ;
|
1999-05-14 17:38:07 +00:00
|
|
|
return (0);
|
|
|
|
}
|