Submitted by: Wolfgang Stanglmeier <wolf@dentaro.GUN.de> + Stefan Esser <se>
Directory for PCI autoconfigure and device driver code.
This commit is contained in:
parent
2c57cee563
commit
37bd2c9c33
598
sys/dev/pci/pci.c
Normal file
598
sys/dev/pci/pci.c
Normal file
@ -0,0 +1,598 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** $Id: pci.c,v 2.0.0.8 94/08/21 19:57:39 wolf Exp $
|
||||
**
|
||||
** General subroutines for the PCI bus on 80*86 systems.
|
||||
** pci_configure ()
|
||||
**
|
||||
** 386bsd / FreeBSD
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** Copyright (c) 1994 Wolfgang Stanglmeier. 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.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** $Log: pci.c,v $
|
||||
** Revision 2.0.0.8 94/08/21 19:57:39 wolf
|
||||
** Unneeded declarations removed (FreeBSD2.0)
|
||||
**
|
||||
** Revision 2.0.0.7 94/08/21 19:25:54 wolf
|
||||
** pci_intr simplified.
|
||||
** new not_supported() function.
|
||||
** Vendor and device ids moved into tables.
|
||||
**
|
||||
** Revision 2.0.0.6 94/08/18 22:58:23 wolf
|
||||
** Symbolic names for pci configuration space registers.
|
||||
** last_device: from configuration mode
|
||||
** last_bus: from pcibios.
|
||||
** PCI_MAX_DPI: changed to 4 (settable by config)
|
||||
** interrupt configuration by line or pin
|
||||
**
|
||||
** Revision 2.0.0.5 94/08/11 19:04:10 wolf
|
||||
** display of interrupt line configuration register.
|
||||
**
|
||||
** Revision 2.0.0.4 94/08/01 20:36:28 wolf
|
||||
** Tiny clean up.
|
||||
**
|
||||
** Revision 2.0.0.3 94/08/01 18:52:33 wolf
|
||||
** New vendor entry: S3.
|
||||
** Scan pci busses #0..#255 as default.
|
||||
** Number of scanned busses and devices settable as option.
|
||||
** Show these numbers before starting the scan.
|
||||
**
|
||||
** Revision 2.0.0.2 94/07/27 09:27:19 wolf
|
||||
** New option PCI_QUIET: suppress log messages.
|
||||
**
|
||||
** Revision 2.0.0.1 94/07/19 19:06:44 wolf
|
||||
** New vendor entry: MATROX
|
||||
**
|
||||
** Revision 2.0 94/07/10 15:53:29 wolf
|
||||
** FreeBSD release.
|
||||
**
|
||||
** Revision 1.0 94/06/07 20:02:19 wolf
|
||||
** Beta release.
|
||||
**
|
||||
***************************************************************************
|
||||
*/
|
||||
|
||||
#include <pci.h>
|
||||
#if NPCI > 0
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** Configuration
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
** maximum number of devices which share one interrupt line
|
||||
*/
|
||||
|
||||
#ifndef PCI_MAX_DPI
|
||||
#define PCI_MAX_DPI (4)
|
||||
#endif /*PCI_MAX_DPI*/
|
||||
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** #includes and declarations
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
#include <types.h>
|
||||
#include <cdefs.h>
|
||||
#include <errno.h>
|
||||
#include <param.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_param.h>
|
||||
|
||||
#include <i386/isa/icu.h>
|
||||
#include <i386/isa/isa.h>
|
||||
#include <i386/isa/isa_device.h>
|
||||
|
||||
#include <i386/pci/pci.h>
|
||||
#include <i386/pci/pci_device.h>
|
||||
#include <i386/pci/pcibios.h>
|
||||
|
||||
|
||||
char ident_pci_c[] =
|
||||
"\n$Id: pci.c,v 2.0.0.8 94/08/21 19:57:39 wolf Exp $\n"
|
||||
"Copyright (c) 1994, Wolfgang Stanglmeier\n";
|
||||
|
||||
/*
|
||||
** Function prototypes missing in system headers
|
||||
*/
|
||||
|
||||
extern int printf();
|
||||
extern int ffs();
|
||||
#if ! (__FreeBSD__ >= 2)
|
||||
extern pmap_t pmap_kernel(void);
|
||||
#endif
|
||||
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** Autoconfiguration (of isa bus)
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
** per device (interrupt) data structure.
|
||||
*/
|
||||
|
||||
static struct {
|
||||
u_short number;
|
||||
u_short isanum;
|
||||
struct {
|
||||
int (*proc)(int dev);
|
||||
dev_t unit;
|
||||
} vector[PCI_MAX_DPI];
|
||||
} pcidata [NPCI];
|
||||
|
||||
/*
|
||||
** check device ready
|
||||
*/
|
||||
static int pciprobe (struct isa_device *dev)
|
||||
{
|
||||
if (dev->id_unit >= NPCI)
|
||||
return (0);
|
||||
|
||||
if (!pci_conf_mode())
|
||||
return (0);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
** initialize the driver structure
|
||||
*/
|
||||
static int pciattach (struct isa_device *isdp)
|
||||
{
|
||||
pcidata[isdp->id_unit].number = 0;
|
||||
pcidata[isdp->id_unit].isanum = ffs(isdp->id_irq)-1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
** ISA driver structure
|
||||
*/
|
||||
|
||||
struct isa_driver pcidriver = {
|
||||
pciprobe,
|
||||
pciattach,
|
||||
"pci"
|
||||
};
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** Interrupt forward from isa to pci devices.
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
|
||||
void pciintr (int unit)
|
||||
{
|
||||
u_short i;
|
||||
if (unit >= NPCI) return;
|
||||
for (i=0; i<pcidata[unit].number; i++) {
|
||||
(void)(*pcidata[unit].vector[i].proc)(pcidata[unit].vector[i].unit);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** Autoconfiguration of pci devices.
|
||||
**
|
||||
** This is reverse to the isa configuration.
|
||||
** (1) find a pci device.
|
||||
** (2) look for a driver.
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
/*--------------------------------------------------------
|
||||
**
|
||||
** The pci devices can be mapped to any address.
|
||||
** As default we start at the last gigabyte.
|
||||
**
|
||||
**--------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PCI_PMEM_START
|
||||
#define PCI_PMEM_START 0xc0000000
|
||||
#endif
|
||||
|
||||
static vm_offset_t pci_paddr = PCI_PMEM_START;
|
||||
|
||||
/*---------------------------------------------------------
|
||||
**
|
||||
** pci_configure ()
|
||||
**
|
||||
**---------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void not_supported (pcici_t tag, u_long type);
|
||||
|
||||
void pci_configure()
|
||||
{
|
||||
u_char device,last_device;
|
||||
u_short bus,last_bus;
|
||||
pcici_t tag;
|
||||
pcidi_t type;
|
||||
u_long data;
|
||||
int unit;
|
||||
int intpin;
|
||||
int isanum;
|
||||
int pci_mode;
|
||||
|
||||
struct pci_driver *drp;
|
||||
struct pci_device *dvp;
|
||||
|
||||
/*
|
||||
** check pci bus present
|
||||
*/
|
||||
|
||||
pci_mode = pci_conf_mode ();
|
||||
if (!pci_mode) return;
|
||||
last_bus = pci_last_bus ();
|
||||
last_device = pci_mode==1 ? 31 : 15;
|
||||
|
||||
/*
|
||||
** hello world ..
|
||||
*/
|
||||
|
||||
#ifndef PCI_QUIET
|
||||
printf ("PCI configuration mode %d.\n", pci_mode);
|
||||
printf ("Scanning device 0..%d on pci bus 0..%d "
|
||||
"($Revision: 2.0.0.8 $)\n",
|
||||
last_device, last_bus);
|
||||
#endif
|
||||
|
||||
for (bus=0;bus<=last_bus; bus++)
|
||||
for (device=0; device<=last_device; device ++) {
|
||||
tag = pcitag (bus, device, 0);
|
||||
type = pci_conf_read (tag, PCI_ID_REG);
|
||||
|
||||
if ((!type) || (type==0xfffffffful)) continue;
|
||||
|
||||
/*
|
||||
** lookup device in ioconfiguration:
|
||||
*/
|
||||
|
||||
for (dvp = pci_devtab; drp=dvp->pd_driver; dvp++) {
|
||||
if (drp->device_id == type) break;
|
||||
};
|
||||
|
||||
#ifdef PCI_QUIET
|
||||
if (!drp) continue;
|
||||
#endif
|
||||
printf ("on pci%d:%d ", bus, device);
|
||||
#ifndef PCI_QUIET
|
||||
if (!drp) {
|
||||
not_supported (tag, type);
|
||||
continue;
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
** found it.
|
||||
** probe returns the device unit.
|
||||
*/
|
||||
|
||||
printf ("<%s>", drp -> vendor);
|
||||
|
||||
unit = (*drp->probe) (tag);
|
||||
|
||||
if (unit<0) {
|
||||
printf (" probe failed.\n");
|
||||
continue;
|
||||
};
|
||||
|
||||
/*
|
||||
** install interrupts
|
||||
*/
|
||||
|
||||
data = pci_conf_read (tag, PCI_INTERRUPT_REG);
|
||||
intpin = PCI_INTERRUPT_PIN_EXTRACT(data);
|
||||
if (intpin) {
|
||||
int idx=NPCI;
|
||||
|
||||
/*
|
||||
** Usage of int line register (if set by bios)
|
||||
** Matt Thomas <thomas@lkg.dec.com>
|
||||
*/
|
||||
|
||||
isanum = PCI_INTERRUPT_LINE_EXTRACT(data);
|
||||
if (isanum) {
|
||||
printf (" il=%d", isanum);
|
||||
for (idx = 0; idx < NPCI; idx++) {
|
||||
if (pcidata[idx].isanum == isanum)
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
** Or believe to the interrupt pin register.
|
||||
*/
|
||||
|
||||
if (idx >= NPCI) idx = intpin-1;
|
||||
|
||||
/*
|
||||
** And install the interrupt.
|
||||
*/
|
||||
|
||||
if (idx<NPCI) {
|
||||
u_short entry = pcidata[idx].number;
|
||||
printf (" irq %c", 0x60+intpin);
|
||||
if (entry < PCI_MAX_DPI) {
|
||||
pcidata[idx].vector[entry].proc = drp->intr;
|
||||
pcidata[idx].vector[entry].unit = unit;
|
||||
entry++;
|
||||
};
|
||||
printf (" isa=%d [%d]",pcidata[idx].isanum, entry);
|
||||
pcidata[idx].number=entry;
|
||||
} else {
|
||||
printf (" not installed");
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
** enable memory access
|
||||
*/
|
||||
data = pci_conf_read (tag, PCI_COMMAND_STATUS_REG)
|
||||
& 0xffff | PCI_COMMAND_MEM_ENABLE;
|
||||
pci_conf_write (tag, (u_char) PCI_COMMAND_STATUS_REG, data);
|
||||
|
||||
/*
|
||||
** attach device
|
||||
** may produce additional log messages,
|
||||
** i.e. when installing subdevices.
|
||||
*/
|
||||
|
||||
printf (" as %s%d\n", drp->name,unit);
|
||||
(void) (*drp->attach) (tag);
|
||||
|
||||
};
|
||||
|
||||
printf ("pci uses physical addresses from %x to %x\n",
|
||||
PCI_PMEM_START, pci_paddr);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
**
|
||||
** Map device into port space.
|
||||
**
|
||||
** PCI-Specification: 6.2.5.1: address maps
|
||||
**
|
||||
**-----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
extern vm_map_t kernel_map;
|
||||
|
||||
int pci_map_port (pcici_t tag, u_long reg, u_short* pa)
|
||||
{
|
||||
/*
|
||||
** @MAPIO@ not yet implemented.
|
||||
*/
|
||||
return (ENOSYS);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
**
|
||||
** Map device into virtual and physical space
|
||||
**
|
||||
** PCI-Specification: 6.2.5.1: address maps
|
||||
**
|
||||
**-----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int pci_map_mem (pcici_t tag, u_long reg, vm_offset_t* va, vm_offset_t* pa)
|
||||
{
|
||||
u_long data, result;
|
||||
vm_size_t vsize;
|
||||
vm_offset_t vaddr;
|
||||
|
||||
/*
|
||||
** sanity check
|
||||
*/
|
||||
|
||||
if (reg <= PCI_MAP_REG_START || reg >= PCI_MAP_REG_END || (reg & 3))
|
||||
return (EINVAL);
|
||||
|
||||
/*
|
||||
** get size and type of memory
|
||||
**
|
||||
** type is in the lowest four bits.
|
||||
** If device requires 2^n bytes, the next
|
||||
** n-4 bits are read as 0.
|
||||
*/
|
||||
|
||||
pci_conf_write (tag, reg, 0xfffffffful);
|
||||
data = pci_conf_read (tag, reg);
|
||||
|
||||
switch (data & 0x0f) {
|
||||
|
||||
case PCI_MAP_MEMORY_TYPE_32BIT: /* 32 bit non cachable */
|
||||
break;
|
||||
|
||||
default: /* unknown */
|
||||
return (EINVAL);
|
||||
};
|
||||
|
||||
/*
|
||||
** mask out the type,
|
||||
** and round up to a page size
|
||||
*/
|
||||
|
||||
vsize = round_page (-(data & PCI_MAP_MEMORY_ADDRESS_MASK));
|
||||
|
||||
printf (" memory size=0x%x", vsize);
|
||||
|
||||
if (!vsize) return (EINVAL);
|
||||
|
||||
/*
|
||||
** try to map device to virtual space
|
||||
*/
|
||||
|
||||
vaddr = vm_map_min (kernel_map);
|
||||
|
||||
result = vm_map_find (kernel_map, (void*)0, (vm_offset_t) 0,
|
||||
&vaddr, vsize, TRUE);
|
||||
|
||||
if (result != KERN_SUCCESS) {
|
||||
printf (" vm_map_find failed(%d)\n", result);
|
||||
return (ENOMEM);
|
||||
};
|
||||
|
||||
/*
|
||||
** align physical address to virtual size
|
||||
*/
|
||||
|
||||
if (data = pci_paddr % vsize)
|
||||
pci_paddr += vsize - data;
|
||||
|
||||
/*
|
||||
** display values.
|
||||
*/
|
||||
|
||||
printf (" virtual=0x%x physical=0x%x\n", vaddr, pci_paddr);
|
||||
|
||||
/*
|
||||
** return them to the driver
|
||||
*/
|
||||
|
||||
*va = vaddr;
|
||||
*pa = pci_paddr;
|
||||
|
||||
/*
|
||||
** set device address
|
||||
*/
|
||||
|
||||
pci_conf_write (tag, reg, pci_paddr);
|
||||
|
||||
/*
|
||||
** map physical
|
||||
*/
|
||||
|
||||
while (vsize >= NBPG) {
|
||||
pmap_enter (pmap_kernel(), vaddr, pci_paddr,
|
||||
VM_PROT_READ|VM_PROT_WRITE, TRUE);
|
||||
vaddr += NBPG;
|
||||
pci_paddr += NBPG;
|
||||
vsize -= NBPG;
|
||||
};
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
struct vt {
|
||||
u_short ident;
|
||||
char* name;
|
||||
};
|
||||
|
||||
struct dt {
|
||||
u_long ident;
|
||||
char* name;
|
||||
};
|
||||
|
||||
static struct vt VendorTable[] = {
|
||||
{0x1002, "ATI TECHNOLOGIES INC"},
|
||||
{0x1011, "DIGITAL EQUIPMENT COMPANY"},
|
||||
{0x101A, "NCR"},
|
||||
{0x102B, "MATROX"},
|
||||
{0x1045, "OPTI"},
|
||||
{0x5333, "S3 INC."},
|
||||
{0x8086, "INTEL CORPORATION"},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
static struct dt DeviceTable[] = {
|
||||
{0x04848086, " 82378IB pci-isa bridge"},
|
||||
{0x04838086, " 82424ZX cache dram controller"},
|
||||
{0x04828086, " 82375EB pci-eisa bridge"},
|
||||
{0x04A38086, " 82434LX pci cache memory controller"},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
void not_supported (pcici_t tag, u_long type)
|
||||
{
|
||||
u_char reg;
|
||||
u_long data;
|
||||
struct vt * vp;
|
||||
struct dt * dp;
|
||||
|
||||
/*
|
||||
** lookup the names.
|
||||
*/
|
||||
|
||||
for (vp=VendorTable; vp->ident; vp++)
|
||||
if (vp->ident == (type & 0xffff))
|
||||
break;
|
||||
|
||||
for (dp=DeviceTable; dp->ident; dp++)
|
||||
if (dp->ident == type)
|
||||
break;
|
||||
|
||||
/*
|
||||
** and display them.
|
||||
*/
|
||||
|
||||
if (vp->ident) printf (vp->name);
|
||||
else printf ("vendor=%x", type & 0xffff);
|
||||
|
||||
if (dp->ident) printf (dp->name);
|
||||
else printf (", device=%x", type >> 16);
|
||||
|
||||
printf (" [not supported]\n");
|
||||
|
||||
for (reg=PCI_MAP_REG_START; reg<PCI_MAP_REG_END; reg+=4) {
|
||||
data = pci_conf_read (tag, reg);
|
||||
if (!data) continue;
|
||||
switch (data&7) {
|
||||
|
||||
case 1:
|
||||
case 5:
|
||||
printf (" map(%x): io(%x)\n", reg, data & ~3);
|
||||
break;
|
||||
case 0:
|
||||
printf (" map(%x): mem32(%x)\n", reg, data & ~7);
|
||||
break;
|
||||
case 2:
|
||||
printf (" map(%x): mem20(%x)\n", reg, data & ~7);
|
||||
break;
|
||||
case 4:
|
||||
printf (" map(%x): mem64(%x)\n", reg, data & ~7);
|
||||
break;
|
||||
};
|
||||
};
|
||||
}
|
||||
#endif
|
5695
sys/i386/pci/ncr.c
Normal file
5695
sys/i386/pci/ncr.c
Normal file
File diff suppressed because it is too large
Load Diff
521
sys/i386/pci/ncr_reg.h
Normal file
521
sys/i386/pci/ncr_reg.h
Normal file
@ -0,0 +1,521 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** $Id: ncr_reg.h,v 2.0.0.4 94/08/09 23:10:10 wolf Exp $
|
||||
**
|
||||
** Device driver for the NCR 53C810 PCI-SCSI-Controller.
|
||||
**
|
||||
** 386bsd / FreeBSD / NetBSD
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** Written for 386bsd and FreeBSD by
|
||||
** wolf@dentaro.gun.de Wolfgang Stanglmeier
|
||||
** se@mi.Uni-Koeln.de Stefan Esser
|
||||
**
|
||||
** Ported to NetBSD by
|
||||
** mycroft@gnu.ai.mit.edu
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** Copyright (c) 1994 Wolfgang Stanglmeier. 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.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** $Log: ncr_reg.h,v $
|
||||
** Revision 2.0.0.4 94/08/09 23:10:10 wolf
|
||||
** new message.
|
||||
**
|
||||
** Revision 2.0.0.3 94/07/24 08:59:19 wolf
|
||||
** bits of sstat0 defined.
|
||||
**
|
||||
** Revision 2.0 94/07/10 15:53:27 wolf
|
||||
** FreeBSD release.
|
||||
**
|
||||
** Revision 1.0 94/06/07 20:02:21 wolf
|
||||
** Beta release.
|
||||
**
|
||||
***************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __NCR_REG_H__
|
||||
#define __NCR_REG_H__
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------
|
||||
**
|
||||
** The ncr 53c810 register structure.
|
||||
**
|
||||
**-----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
struct ncr_reg {
|
||||
/*00*/ u_char nc_scntl0; /* full arb., ena parity, par->ATN */
|
||||
/*01*/ u_char nc_scntl1; /* no reset */
|
||||
#define ISCON 0x10 /* connected to scsi */
|
||||
#define CRST 0x08 /* force reset */
|
||||
/*02*/ u_char nc_scntl2; /* no disconnect expected */
|
||||
/*03*/ u_char nc_scntl3; /* cnf system clock dependent */
|
||||
/*04*/ u_char nc_scid; /* cnf host adapter scsi address */
|
||||
#define RRE 0x40 /* r/w:e enable response to resel. */
|
||||
#define SRE 0x20 /* r/w:e enable response to select */
|
||||
/*05*/ u_char nc_sxfer; /* ### Sync speed and count */
|
||||
/*06*/ u_char nc_sdid; /* ### Destination-ID */
|
||||
/*07*/ u_char nc_gpreg; /* ??? IO-Pins */
|
||||
/*08*/ u_char nc_sfbr; /* ### First byte in phase */
|
||||
/*09*/ u_char nc_socl;
|
||||
#define CREQ 0x80 /* r/w: SCSI-REQ */
|
||||
#define CACK 0x40 /* r/w: SCSI-ACK */
|
||||
#define CBSY 0x20 /* r/w: SCSI-BSY */
|
||||
#define CSEL 0x10 /* r/w: SCSI-SEL */
|
||||
#define CATN 0x08 /* r/w: SCSI-ATN */
|
||||
#define CMSG 0x04 /* r/w: SCSI-MSG */
|
||||
#define CC_D 0x02 /* r/w: SCSI-C_D */
|
||||
#define CI_O 0x01 /* r/w: SCSI-I_O */
|
||||
/*0a*/ u_char nc_ssid;
|
||||
/*0b*/ u_char nc_sbcl;
|
||||
/*0c*/ u_char nc_dstat;
|
||||
#define DFE 0x80 /* sta: dma fifo empty */
|
||||
#define MDPE 0x40 /* int: master data parity error */
|
||||
#define BF 0x20 /* int: script: bus fault */
|
||||
#define ABRT 0x10 /* int: script: command aborted */
|
||||
#define SSI 0x08 /* int: script: single step */
|
||||
#define SIR 0x04 /* int: script: interrupt instruct. */
|
||||
#define IID 0x01 /* int: script: illegal instruct. */
|
||||
/*0d*/ u_char nc_sstat0;
|
||||
#define ILF 0x80 /* sta: data in SIDL register */
|
||||
#define ORF 0x40 /* sta: data in SODR register */
|
||||
#define OLF 0x20 /* sta: data in SODL register */
|
||||
#define AIP 0x10 /* sta: arbitration in progress */
|
||||
#define LOA 0x08 /* sta: arbitration lost */
|
||||
#define WOA 0x04 /* sta: arbitration won */
|
||||
#define IRST 0x02 /* sta: scsi reset signal */
|
||||
#define SDP 0x01 /* sta: scsi parity signal */
|
||||
/*0e*/ u_char nc_sstat1;
|
||||
/*0f*/ u_char nc_sstat2;
|
||||
|
||||
/*10*/ u_long nc_dsa; /* --> Base page */
|
||||
/*14*/ u_char nc_istat; /* --> Main Command and status */
|
||||
#define CABRT 0x80 /* cmd: abort current operation */
|
||||
#define SRST 0x40 /* mod: reset chip */
|
||||
#define SIGP 0x20 /* r/w: message from host to ncr */
|
||||
#define SEM 0x10 /* r/w: message between host + ncr */
|
||||
#define CON 0x08 /* sta: connected to scsi */
|
||||
#define INTF 0x04 /* sta: int on the fly (reset by wr)*/
|
||||
#define SIP 0x02 /* sta: scsi-interupt */
|
||||
#define DIP 0x01 /* sta: host/script interupt */
|
||||
/*15*/ u_char nc_15_;
|
||||
/*16*/ u_char nc_16_;
|
||||
/*17*/ u_char nc_17_;
|
||||
/*18*/ u_char nc_ctest0;
|
||||
/*19*/ u_char nc_ctest1;
|
||||
/*1a*/ u_char nc_ctest2;
|
||||
#define CSIGP 0x40
|
||||
/*1b*/ u_char nc_ctest3;
|
||||
#define CLF 0x04 /* clear scsi fifo */
|
||||
/*1c*/ u_long nc_temp; /* ### Temporary stack */
|
||||
/*20*/ u_char nc_dfifo;
|
||||
/*21*/ u_char nc_ctest4;
|
||||
/*22*/ u_char nc_ctest5;
|
||||
/*23*/ u_char nc_ctest6;
|
||||
/*24*/ u_long nc_dbc; /* ### Byte count and command */
|
||||
/*28*/ u_long nc_dnad; /* ### Next command register */
|
||||
/*2c*/ u_long nc_dsp; /* --> Script Pointer */
|
||||
/*30*/ u_long nc_dsps; /* --> Script pointer save/opcode#2 */
|
||||
/*34*/ u_long nc_scratcha; /* ??? Temporary register a */
|
||||
/*38*/ u_char nc_dmode;
|
||||
/*39*/ u_char nc_dien;
|
||||
/*3a*/ u_char nc_dwt;
|
||||
/*3b*/ u_char nc_dcntl; /* --> Script execution control */
|
||||
#define SSM 0x10 /* mod: single step mode */
|
||||
#define STD 0x04 /* cmd: start dma mode */
|
||||
#define NOCOM 0x01 /* cmd: protect sfbr while reselect */
|
||||
/*3c*/ u_long nc_adder;
|
||||
|
||||
/*40*/ u_short nc_sien; /* -->: interupt enable */
|
||||
/*42*/ u_short nc_sist; /* <--: interupt status */
|
||||
#define STO 0x0400/* sta: timeout (select) */
|
||||
#define GEN 0x0200/* sta: timeout (general) */
|
||||
#define HTH 0x0100/* sta: timeout (handshake) */
|
||||
#define MA 0x80 /* sta: phase mismatch */
|
||||
#define CMP 0x40 /* sta: arbitration complete */
|
||||
#define SEL 0x20 /* sta: selected by another device */
|
||||
#define RSL 0x10 /* sta: reselected by another device*/
|
||||
#define SGE 0x08 /* sta: gross error (over/underflow)*/
|
||||
#define UDC 0x04 /* sta: unexpected disconnect */
|
||||
#define RST 0x02 /* sta: scsi bus reset detected */
|
||||
#define PAR 0x01 /* sta: scsi parity error */
|
||||
/*44*/ u_char nc_slpar;
|
||||
/*45*/ u_char nc_45_;
|
||||
/*46*/ u_char nc_macntl;
|
||||
/*47*/ u_char nc_gpcntl;
|
||||
/*48*/ u_char nc_stime0; /* cmd: timeout for select&handshake*/
|
||||
/*49*/ u_char nc_stime1; /* cmd: timeout user defined */
|
||||
/*4a*/ u_char nc_respid; /* sta: Reselect-IDs */
|
||||
/*4b*/ u_char nc_4b_;
|
||||
/*4c*/ u_char nc_stest0;
|
||||
/*4d*/ u_char nc_stest1;
|
||||
/*4e*/ u_char nc_stest2;
|
||||
#define ROF 0x40 /* reset scsi offset (after gross error!) */
|
||||
#define EXT 0x02 /* extended filtering */
|
||||
/*4f*/ u_char nc_stest3;
|
||||
#define TE 0x80 /* c: tolerAnt enable */
|
||||
#define CSF 0x02 /* c: clear scsi fifo */
|
||||
/*50*/ u_char nc_sidl; /* Lowlevel: latched from scsi data */
|
||||
/*51*/ u_char nc_51_;
|
||||
/*52*/ u_char nc_52_;
|
||||
/*53*/ u_char nc_53_;
|
||||
/*54*/ u_char nc_sodl; /* Lowlevel: data out to scsi data */
|
||||
/*55*/ u_char nc_55_;
|
||||
/*56*/ u_char nc_56_;
|
||||
/*57*/ u_char nc_57_;
|
||||
/*58*/ u_char nc_sbdl; /* Lowlevel: data from scsi data */
|
||||
/*59*/ u_char nc_59_;
|
||||
/*5a*/ u_char nc_5a_;
|
||||
/*5b*/ u_char nc_5b_;
|
||||
/*5c*/ u_char nc_scr0; /* Working register B */
|
||||
/*5d*/ u_char nc_scr1; /* */
|
||||
/*5e*/ u_char nc_scr2; /* */
|
||||
/*5f*/ u_char nc_scr3; /* */
|
||||
/*60*/
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
**
|
||||
** Utility macros for the script.
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define REGJ(p,r) (offsetof(struct ncr_reg, p ## r))
|
||||
#define REG(r) REGJ (nc_, r)
|
||||
|
||||
#ifndef TARGET_MODE
|
||||
#define TARGET_MODE 0
|
||||
#endif
|
||||
|
||||
typedef unsigned long ncrcmd;
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
**
|
||||
** SCSI phases
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define SCR_DATA_OUT 0x00000000
|
||||
#define SCR_DATA_IN 0x01000000
|
||||
#define SCR_COMMAND 0x02000000
|
||||
#define SCR_STATUS 0x03000000
|
||||
#define SCR_ILG_OUT 0x04000000
|
||||
#define SCR_ILG_IN 0x05000000
|
||||
#define SCR_MSG_OUT 0x06000000
|
||||
#define SCR_MSG_IN 0x07000000
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
**
|
||||
** Data transfer via SCSI.
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
**
|
||||
** MOVE_ABS (LEN)
|
||||
** <<start address>>
|
||||
**
|
||||
** MOVE_IND (LEN)
|
||||
** <<dnad_offset>>
|
||||
**
|
||||
** MOVE_TBL
|
||||
** <<dnad_offset>>
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define SCR_MOVE_ABS(l) ((0x08000000 ^ (TARGET_MODE << 1ul)) | (l))
|
||||
#define SCR_MOVE_IND(l) ((0x28000000 ^ (TARGET_MODE << 1ul)) | (l))
|
||||
#define SCR_MOVE_TBL (0x18000000 ^ (TARGET_MODE << 1ul))
|
||||
|
||||
struct scr_tblmove {
|
||||
u_long size;
|
||||
u_long addr;
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
**
|
||||
** Selection
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
**
|
||||
** SEL_ABS | SCR_ID (0..7) [ | REL_JMP]
|
||||
** <<alternate_address>>
|
||||
**
|
||||
** SEL_TBL | << dnad_offset>> [ | REL_JMP]
|
||||
** <<alternate_address>>
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define SCR_SEL_ABS 0x40000000
|
||||
#define SCR_SEL_ABS_ATN 0x41000000
|
||||
#define SCR_SEL_TBL 0x42000000
|
||||
#define SCR_SEL_TBL_ATN 0x43000000
|
||||
|
||||
struct scr_tblsel {
|
||||
u_char sel_0;
|
||||
u_char sel_sxfer;
|
||||
u_char sel_id;
|
||||
u_char sel_scntl3;
|
||||
};
|
||||
|
||||
#define SCR_JMP_REL 0x04000000
|
||||
#define SCR_ID(id) (((u_long)(id)) << 16)
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
**
|
||||
** Waiting for Disconnect or Reselect
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
**
|
||||
** WAIT_DISC
|
||||
** dummy: <<alternate_address>>
|
||||
**
|
||||
** WAIT_RESEL
|
||||
** <<alternate_address>>
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define SCR_WAIT_DISC 0x48000000
|
||||
#define SCR_WAIT_RESEL 0x50000000
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
**
|
||||
** Bit Set / Reset
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
**
|
||||
** SET (flags {|.. })
|
||||
**
|
||||
** CLR (flags {|.. })
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define SCR_SET(f) (0x58000000 | (f))
|
||||
#define SCR_CLR(f) (0x60000000 | (f))
|
||||
|
||||
#define SCR_CARRY 0x00000400
|
||||
#define SCR_TRG 0x00000200
|
||||
#define SCR_ACK 0x00000040
|
||||
#define SCR_ATN 0x00000008
|
||||
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
**
|
||||
** Memory to memory move
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
**
|
||||
** COPY (bytecount)
|
||||
** << source_address >>
|
||||
** << destination_address >>
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define SCR_COPY(n) (0xc0000000 | (n))
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
**
|
||||
** Register move and binary operations
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
**
|
||||
** SFBR_REG (reg, op, data) reg = SFBR op data
|
||||
** << 0 >>
|
||||
**
|
||||
** REG_SFBR (reg, op, data) SFBR = reg op data
|
||||
** << 0 >>
|
||||
**
|
||||
** REG_REG (reg, op, data) reg = reg op data
|
||||
** << 0 >>
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define SCR_SFBR_REG(reg,op,data) \
|
||||
(0x68000000 | (REG(reg) << 16ul) | (op) | ((data)<<8ul))
|
||||
|
||||
#define SCR_REG_SFBR(reg,op,data) \
|
||||
(0x70000000 | (REG(reg) << 16ul) | (op) | ((data)<<8ul))
|
||||
|
||||
#define SCR_REG_REG(reg,op,data) \
|
||||
(0x78000000 | (REG(reg) << 16ul) | (op) | ((data)<<8ul))
|
||||
|
||||
#define SCR_LOAD 0x00000000
|
||||
#define SCR_SHL 0x01000000
|
||||
#define SCR_OR 0x02000000
|
||||
#define SCR_XOR 0x03000000
|
||||
#define SCR_AND 0x04000000
|
||||
#define SCR_SHR 0x05000000
|
||||
#define SCR_ADD 0x06000000
|
||||
#define SCR_ADDC 0x07000000
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
**
|
||||
** FROM_REG (reg) reg = SFBR
|
||||
** << 0 >>
|
||||
**
|
||||
** TO_REG (reg) SFBR = reg
|
||||
** << 0 >>
|
||||
**
|
||||
** LOAD_REG (reg, data) reg = <data>
|
||||
** << 0 >>
|
||||
**
|
||||
** LOAD_SFBR(data) SFBR = <data>
|
||||
** << 0 >>
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define SCR_FROM_REG(reg) \
|
||||
SCR_REG_SFBR(reg,SCR_OR,0)
|
||||
|
||||
#define SCR_TO_REG(reg) \
|
||||
SCR_SFBR_REG(reg,SCR_OR,0)
|
||||
|
||||
#define SCR_LOAD_REG(reg,data) \
|
||||
SCR_REG_REG(reg,SCR_LOAD,data)
|
||||
|
||||
#define SCR_LOAD_SFBR(data) \
|
||||
(SCR_REG_SFBR (gpreg, SCR_LOAD, data))
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
**
|
||||
** Waiting for Disconnect or Reselect
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
**
|
||||
** JUMP [ | IFTRUE/IFFALSE ( ... ) ]
|
||||
** <<address>>
|
||||
**
|
||||
** JUMPR [ | IFTRUE/IFFALSE ( ... ) ]
|
||||
** <<distance>>
|
||||
**
|
||||
** CALL [ | IFTRUE/IFFALSE ( ... ) ]
|
||||
** <<address>>
|
||||
**
|
||||
** CALLR [ | IFTRUE/IFFALSE ( ... ) ]
|
||||
** <<distance>>
|
||||
**
|
||||
** RETURN [ | IFTRUE/IFFALSE ( ... ) ]
|
||||
** <<dummy>>
|
||||
**
|
||||
** INT [ | IFTRUE/IFFALSE ( ... ) ]
|
||||
** <<ident>>
|
||||
**
|
||||
** INT_FLY [ | IFTRUE/IFFALSE ( ... ) ]
|
||||
** <<ident>>
|
||||
**
|
||||
** Conditions:
|
||||
** WHEN (phase)
|
||||
** IF (phase)
|
||||
** CARRY
|
||||
** DATA (data, mask)
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define SCR_JUMP 0x80080000
|
||||
#define SCR_JUMPR 0x80880000
|
||||
#define SCR_CALL 0x88080000
|
||||
#define SCR_CALLR 0x88880000
|
||||
#define SCR_RETURN 0x90080000
|
||||
#define SCR_INT 0x98080000
|
||||
#define SCR_INT_FLY 0x98180000
|
||||
|
||||
#define IFFALSE(arg) (0x00080000 | (arg))
|
||||
#define IFTRUE(arg) (0x00000000 | (arg))
|
||||
|
||||
#define WHEN(phase) (0x00030000 | (phase))
|
||||
#define IF(phase) (0x00020000 | (phase))
|
||||
|
||||
#define DATA(D) (0x00040000 | ((D) & 0xff))
|
||||
#define MASK(D,M) (0x00040000 | (((M ^ 0xff) & 0xff) << 8ul)|((D) & 0xff))
|
||||
|
||||
#define CARRYSET (0x00200000)
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
**
|
||||
** SCSI constants.
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
** Messages
|
||||
*/
|
||||
|
||||
#define M_COMPLETE (0x00)
|
||||
#define M_EXTENDED (0x01)
|
||||
#define M_SAVE_DP (0x02)
|
||||
#define M_RESTORE_DP (0x03)
|
||||
#define M_DISCONNECT (0x04)
|
||||
#define M_ID_ERROR (0x05)
|
||||
#define M_ABORT (0x06)
|
||||
#define M_REJECT (0x07)
|
||||
#define M_NOOP (0x08)
|
||||
#define M_PARITY (0x09)
|
||||
#define M_LCOMPLETE (0x0a)
|
||||
#define M_FCOMPLETE (0x0b)
|
||||
#define M_RESET (0x0c)
|
||||
#define M_ABORT_TAG (0x0d)
|
||||
#define M_CLEAR_QUEUE (0x0e)
|
||||
#define M_INIT_REC (0x0f)
|
||||
#define M_REL_REC (0x10)
|
||||
#define M_TERMINATE (0x11)
|
||||
#define M_SIMPLE_TAG (0x20)
|
||||
#define M_HEAD_TAG (0x21)
|
||||
#define M_ORDERED_TAG (0x22)
|
||||
#define M_IDENTIFY (0x80)
|
||||
|
||||
#define M_X_SDTR (0x01)
|
||||
|
||||
/*
|
||||
** Status
|
||||
*/
|
||||
|
||||
#define S_GOOD (0x00)
|
||||
#define S_CHECK_COND (0x02)
|
||||
#define S_COND_MET (0x04)
|
||||
#define S_BUSY (0x08)
|
||||
#define S_INT (0x10)
|
||||
#define S_INT_COND_MET (0x14)
|
||||
#define S_CONFLICT (0x18)
|
||||
#define S_TERMINATED (0x20)
|
||||
#define S_QUEUE_FULL (0x28)
|
||||
#define S_ILLEGAL (0xff)
|
||||
|
||||
#endif /*__NCR_REG_H__*/
|
1630
sys/i386/pci/ncrstat.c
Normal file
1630
sys/i386/pci/ncrstat.c
Normal file
File diff suppressed because it is too large
Load Diff
598
sys/i386/pci/pci.c
Normal file
598
sys/i386/pci/pci.c
Normal file
@ -0,0 +1,598 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** $Id: pci.c,v 2.0.0.8 94/08/21 19:57:39 wolf Exp $
|
||||
**
|
||||
** General subroutines for the PCI bus on 80*86 systems.
|
||||
** pci_configure ()
|
||||
**
|
||||
** 386bsd / FreeBSD
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** Copyright (c) 1994 Wolfgang Stanglmeier. 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.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** $Log: pci.c,v $
|
||||
** Revision 2.0.0.8 94/08/21 19:57:39 wolf
|
||||
** Unneeded declarations removed (FreeBSD2.0)
|
||||
**
|
||||
** Revision 2.0.0.7 94/08/21 19:25:54 wolf
|
||||
** pci_intr simplified.
|
||||
** new not_supported() function.
|
||||
** Vendor and device ids moved into tables.
|
||||
**
|
||||
** Revision 2.0.0.6 94/08/18 22:58:23 wolf
|
||||
** Symbolic names for pci configuration space registers.
|
||||
** last_device: from configuration mode
|
||||
** last_bus: from pcibios.
|
||||
** PCI_MAX_DPI: changed to 4 (settable by config)
|
||||
** interrupt configuration by line or pin
|
||||
**
|
||||
** Revision 2.0.0.5 94/08/11 19:04:10 wolf
|
||||
** display of interrupt line configuration register.
|
||||
**
|
||||
** Revision 2.0.0.4 94/08/01 20:36:28 wolf
|
||||
** Tiny clean up.
|
||||
**
|
||||
** Revision 2.0.0.3 94/08/01 18:52:33 wolf
|
||||
** New vendor entry: S3.
|
||||
** Scan pci busses #0..#255 as default.
|
||||
** Number of scanned busses and devices settable as option.
|
||||
** Show these numbers before starting the scan.
|
||||
**
|
||||
** Revision 2.0.0.2 94/07/27 09:27:19 wolf
|
||||
** New option PCI_QUIET: suppress log messages.
|
||||
**
|
||||
** Revision 2.0.0.1 94/07/19 19:06:44 wolf
|
||||
** New vendor entry: MATROX
|
||||
**
|
||||
** Revision 2.0 94/07/10 15:53:29 wolf
|
||||
** FreeBSD release.
|
||||
**
|
||||
** Revision 1.0 94/06/07 20:02:19 wolf
|
||||
** Beta release.
|
||||
**
|
||||
***************************************************************************
|
||||
*/
|
||||
|
||||
#include <pci.h>
|
||||
#if NPCI > 0
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** Configuration
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
** maximum number of devices which share one interrupt line
|
||||
*/
|
||||
|
||||
#ifndef PCI_MAX_DPI
|
||||
#define PCI_MAX_DPI (4)
|
||||
#endif /*PCI_MAX_DPI*/
|
||||
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** #includes and declarations
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
#include <types.h>
|
||||
#include <cdefs.h>
|
||||
#include <errno.h>
|
||||
#include <param.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_param.h>
|
||||
|
||||
#include <i386/isa/icu.h>
|
||||
#include <i386/isa/isa.h>
|
||||
#include <i386/isa/isa_device.h>
|
||||
|
||||
#include <i386/pci/pci.h>
|
||||
#include <i386/pci/pci_device.h>
|
||||
#include <i386/pci/pcibios.h>
|
||||
|
||||
|
||||
char ident_pci_c[] =
|
||||
"\n$Id: pci.c,v 2.0.0.8 94/08/21 19:57:39 wolf Exp $\n"
|
||||
"Copyright (c) 1994, Wolfgang Stanglmeier\n";
|
||||
|
||||
/*
|
||||
** Function prototypes missing in system headers
|
||||
*/
|
||||
|
||||
extern int printf();
|
||||
extern int ffs();
|
||||
#if ! (__FreeBSD__ >= 2)
|
||||
extern pmap_t pmap_kernel(void);
|
||||
#endif
|
||||
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** Autoconfiguration (of isa bus)
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
** per device (interrupt) data structure.
|
||||
*/
|
||||
|
||||
static struct {
|
||||
u_short number;
|
||||
u_short isanum;
|
||||
struct {
|
||||
int (*proc)(int dev);
|
||||
dev_t unit;
|
||||
} vector[PCI_MAX_DPI];
|
||||
} pcidata [NPCI];
|
||||
|
||||
/*
|
||||
** check device ready
|
||||
*/
|
||||
static int pciprobe (struct isa_device *dev)
|
||||
{
|
||||
if (dev->id_unit >= NPCI)
|
||||
return (0);
|
||||
|
||||
if (!pci_conf_mode())
|
||||
return (0);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
** initialize the driver structure
|
||||
*/
|
||||
static int pciattach (struct isa_device *isdp)
|
||||
{
|
||||
pcidata[isdp->id_unit].number = 0;
|
||||
pcidata[isdp->id_unit].isanum = ffs(isdp->id_irq)-1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
** ISA driver structure
|
||||
*/
|
||||
|
||||
struct isa_driver pcidriver = {
|
||||
pciprobe,
|
||||
pciattach,
|
||||
"pci"
|
||||
};
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** Interrupt forward from isa to pci devices.
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
|
||||
void pciintr (int unit)
|
||||
{
|
||||
u_short i;
|
||||
if (unit >= NPCI) return;
|
||||
for (i=0; i<pcidata[unit].number; i++) {
|
||||
(void)(*pcidata[unit].vector[i].proc)(pcidata[unit].vector[i].unit);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** Autoconfiguration of pci devices.
|
||||
**
|
||||
** This is reverse to the isa configuration.
|
||||
** (1) find a pci device.
|
||||
** (2) look for a driver.
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
/*--------------------------------------------------------
|
||||
**
|
||||
** The pci devices can be mapped to any address.
|
||||
** As default we start at the last gigabyte.
|
||||
**
|
||||
**--------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PCI_PMEM_START
|
||||
#define PCI_PMEM_START 0xc0000000
|
||||
#endif
|
||||
|
||||
static vm_offset_t pci_paddr = PCI_PMEM_START;
|
||||
|
||||
/*---------------------------------------------------------
|
||||
**
|
||||
** pci_configure ()
|
||||
**
|
||||
**---------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void not_supported (pcici_t tag, u_long type);
|
||||
|
||||
void pci_configure()
|
||||
{
|
||||
u_char device,last_device;
|
||||
u_short bus,last_bus;
|
||||
pcici_t tag;
|
||||
pcidi_t type;
|
||||
u_long data;
|
||||
int unit;
|
||||
int intpin;
|
||||
int isanum;
|
||||
int pci_mode;
|
||||
|
||||
struct pci_driver *drp;
|
||||
struct pci_device *dvp;
|
||||
|
||||
/*
|
||||
** check pci bus present
|
||||
*/
|
||||
|
||||
pci_mode = pci_conf_mode ();
|
||||
if (!pci_mode) return;
|
||||
last_bus = pci_last_bus ();
|
||||
last_device = pci_mode==1 ? 31 : 15;
|
||||
|
||||
/*
|
||||
** hello world ..
|
||||
*/
|
||||
|
||||
#ifndef PCI_QUIET
|
||||
printf ("PCI configuration mode %d.\n", pci_mode);
|
||||
printf ("Scanning device 0..%d on pci bus 0..%d "
|
||||
"($Revision: 2.0.0.8 $)\n",
|
||||
last_device, last_bus);
|
||||
#endif
|
||||
|
||||
for (bus=0;bus<=last_bus; bus++)
|
||||
for (device=0; device<=last_device; device ++) {
|
||||
tag = pcitag (bus, device, 0);
|
||||
type = pci_conf_read (tag, PCI_ID_REG);
|
||||
|
||||
if ((!type) || (type==0xfffffffful)) continue;
|
||||
|
||||
/*
|
||||
** lookup device in ioconfiguration:
|
||||
*/
|
||||
|
||||
for (dvp = pci_devtab; drp=dvp->pd_driver; dvp++) {
|
||||
if (drp->device_id == type) break;
|
||||
};
|
||||
|
||||
#ifdef PCI_QUIET
|
||||
if (!drp) continue;
|
||||
#endif
|
||||
printf ("on pci%d:%d ", bus, device);
|
||||
#ifndef PCI_QUIET
|
||||
if (!drp) {
|
||||
not_supported (tag, type);
|
||||
continue;
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
** found it.
|
||||
** probe returns the device unit.
|
||||
*/
|
||||
|
||||
printf ("<%s>", drp -> vendor);
|
||||
|
||||
unit = (*drp->probe) (tag);
|
||||
|
||||
if (unit<0) {
|
||||
printf (" probe failed.\n");
|
||||
continue;
|
||||
};
|
||||
|
||||
/*
|
||||
** install interrupts
|
||||
*/
|
||||
|
||||
data = pci_conf_read (tag, PCI_INTERRUPT_REG);
|
||||
intpin = PCI_INTERRUPT_PIN_EXTRACT(data);
|
||||
if (intpin) {
|
||||
int idx=NPCI;
|
||||
|
||||
/*
|
||||
** Usage of int line register (if set by bios)
|
||||
** Matt Thomas <thomas@lkg.dec.com>
|
||||
*/
|
||||
|
||||
isanum = PCI_INTERRUPT_LINE_EXTRACT(data);
|
||||
if (isanum) {
|
||||
printf (" il=%d", isanum);
|
||||
for (idx = 0; idx < NPCI; idx++) {
|
||||
if (pcidata[idx].isanum == isanum)
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
** Or believe to the interrupt pin register.
|
||||
*/
|
||||
|
||||
if (idx >= NPCI) idx = intpin-1;
|
||||
|
||||
/*
|
||||
** And install the interrupt.
|
||||
*/
|
||||
|
||||
if (idx<NPCI) {
|
||||
u_short entry = pcidata[idx].number;
|
||||
printf (" irq %c", 0x60+intpin);
|
||||
if (entry < PCI_MAX_DPI) {
|
||||
pcidata[idx].vector[entry].proc = drp->intr;
|
||||
pcidata[idx].vector[entry].unit = unit;
|
||||
entry++;
|
||||
};
|
||||
printf (" isa=%d [%d]",pcidata[idx].isanum, entry);
|
||||
pcidata[idx].number=entry;
|
||||
} else {
|
||||
printf (" not installed");
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
** enable memory access
|
||||
*/
|
||||
data = pci_conf_read (tag, PCI_COMMAND_STATUS_REG)
|
||||
& 0xffff | PCI_COMMAND_MEM_ENABLE;
|
||||
pci_conf_write (tag, (u_char) PCI_COMMAND_STATUS_REG, data);
|
||||
|
||||
/*
|
||||
** attach device
|
||||
** may produce additional log messages,
|
||||
** i.e. when installing subdevices.
|
||||
*/
|
||||
|
||||
printf (" as %s%d\n", drp->name,unit);
|
||||
(void) (*drp->attach) (tag);
|
||||
|
||||
};
|
||||
|
||||
printf ("pci uses physical addresses from %x to %x\n",
|
||||
PCI_PMEM_START, pci_paddr);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
**
|
||||
** Map device into port space.
|
||||
**
|
||||
** PCI-Specification: 6.2.5.1: address maps
|
||||
**
|
||||
**-----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
extern vm_map_t kernel_map;
|
||||
|
||||
int pci_map_port (pcici_t tag, u_long reg, u_short* pa)
|
||||
{
|
||||
/*
|
||||
** @MAPIO@ not yet implemented.
|
||||
*/
|
||||
return (ENOSYS);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
**
|
||||
** Map device into virtual and physical space
|
||||
**
|
||||
** PCI-Specification: 6.2.5.1: address maps
|
||||
**
|
||||
**-----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int pci_map_mem (pcici_t tag, u_long reg, vm_offset_t* va, vm_offset_t* pa)
|
||||
{
|
||||
u_long data, result;
|
||||
vm_size_t vsize;
|
||||
vm_offset_t vaddr;
|
||||
|
||||
/*
|
||||
** sanity check
|
||||
*/
|
||||
|
||||
if (reg <= PCI_MAP_REG_START || reg >= PCI_MAP_REG_END || (reg & 3))
|
||||
return (EINVAL);
|
||||
|
||||
/*
|
||||
** get size and type of memory
|
||||
**
|
||||
** type is in the lowest four bits.
|
||||
** If device requires 2^n bytes, the next
|
||||
** n-4 bits are read as 0.
|
||||
*/
|
||||
|
||||
pci_conf_write (tag, reg, 0xfffffffful);
|
||||
data = pci_conf_read (tag, reg);
|
||||
|
||||
switch (data & 0x0f) {
|
||||
|
||||
case PCI_MAP_MEMORY_TYPE_32BIT: /* 32 bit non cachable */
|
||||
break;
|
||||
|
||||
default: /* unknown */
|
||||
return (EINVAL);
|
||||
};
|
||||
|
||||
/*
|
||||
** mask out the type,
|
||||
** and round up to a page size
|
||||
*/
|
||||
|
||||
vsize = round_page (-(data & PCI_MAP_MEMORY_ADDRESS_MASK));
|
||||
|
||||
printf (" memory size=0x%x", vsize);
|
||||
|
||||
if (!vsize) return (EINVAL);
|
||||
|
||||
/*
|
||||
** try to map device to virtual space
|
||||
*/
|
||||
|
||||
vaddr = vm_map_min (kernel_map);
|
||||
|
||||
result = vm_map_find (kernel_map, (void*)0, (vm_offset_t) 0,
|
||||
&vaddr, vsize, TRUE);
|
||||
|
||||
if (result != KERN_SUCCESS) {
|
||||
printf (" vm_map_find failed(%d)\n", result);
|
||||
return (ENOMEM);
|
||||
};
|
||||
|
||||
/*
|
||||
** align physical address to virtual size
|
||||
*/
|
||||
|
||||
if (data = pci_paddr % vsize)
|
||||
pci_paddr += vsize - data;
|
||||
|
||||
/*
|
||||
** display values.
|
||||
*/
|
||||
|
||||
printf (" virtual=0x%x physical=0x%x\n", vaddr, pci_paddr);
|
||||
|
||||
/*
|
||||
** return them to the driver
|
||||
*/
|
||||
|
||||
*va = vaddr;
|
||||
*pa = pci_paddr;
|
||||
|
||||
/*
|
||||
** set device address
|
||||
*/
|
||||
|
||||
pci_conf_write (tag, reg, pci_paddr);
|
||||
|
||||
/*
|
||||
** map physical
|
||||
*/
|
||||
|
||||
while (vsize >= NBPG) {
|
||||
pmap_enter (pmap_kernel(), vaddr, pci_paddr,
|
||||
VM_PROT_READ|VM_PROT_WRITE, TRUE);
|
||||
vaddr += NBPG;
|
||||
pci_paddr += NBPG;
|
||||
vsize -= NBPG;
|
||||
};
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
struct vt {
|
||||
u_short ident;
|
||||
char* name;
|
||||
};
|
||||
|
||||
struct dt {
|
||||
u_long ident;
|
||||
char* name;
|
||||
};
|
||||
|
||||
static struct vt VendorTable[] = {
|
||||
{0x1002, "ATI TECHNOLOGIES INC"},
|
||||
{0x1011, "DIGITAL EQUIPMENT COMPANY"},
|
||||
{0x101A, "NCR"},
|
||||
{0x102B, "MATROX"},
|
||||
{0x1045, "OPTI"},
|
||||
{0x5333, "S3 INC."},
|
||||
{0x8086, "INTEL CORPORATION"},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
static struct dt DeviceTable[] = {
|
||||
{0x04848086, " 82378IB pci-isa bridge"},
|
||||
{0x04838086, " 82424ZX cache dram controller"},
|
||||
{0x04828086, " 82375EB pci-eisa bridge"},
|
||||
{0x04A38086, " 82434LX pci cache memory controller"},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
void not_supported (pcici_t tag, u_long type)
|
||||
{
|
||||
u_char reg;
|
||||
u_long data;
|
||||
struct vt * vp;
|
||||
struct dt * dp;
|
||||
|
||||
/*
|
||||
** lookup the names.
|
||||
*/
|
||||
|
||||
for (vp=VendorTable; vp->ident; vp++)
|
||||
if (vp->ident == (type & 0xffff))
|
||||
break;
|
||||
|
||||
for (dp=DeviceTable; dp->ident; dp++)
|
||||
if (dp->ident == type)
|
||||
break;
|
||||
|
||||
/*
|
||||
** and display them.
|
||||
*/
|
||||
|
||||
if (vp->ident) printf (vp->name);
|
||||
else printf ("vendor=%x", type & 0xffff);
|
||||
|
||||
if (dp->ident) printf (dp->name);
|
||||
else printf (", device=%x", type >> 16);
|
||||
|
||||
printf (" [not supported]\n");
|
||||
|
||||
for (reg=PCI_MAP_REG_START; reg<PCI_MAP_REG_END; reg+=4) {
|
||||
data = pci_conf_read (tag, reg);
|
||||
if (!data) continue;
|
||||
switch (data&7) {
|
||||
|
||||
case 1:
|
||||
case 5:
|
||||
printf (" map(%x): io(%x)\n", reg, data & ~3);
|
||||
break;
|
||||
case 0:
|
||||
printf (" map(%x): mem32(%x)\n", reg, data & ~7);
|
||||
break;
|
||||
case 2:
|
||||
printf (" map(%x): mem20(%x)\n", reg, data & ~7);
|
||||
break;
|
||||
case 4:
|
||||
printf (" map(%x): mem64(%x)\n", reg, data & ~7);
|
||||
break;
|
||||
};
|
||||
};
|
||||
}
|
||||
#endif
|
82
sys/i386/pci/pci.h
Normal file
82
sys/i386/pci/pci.h
Normal file
@ -0,0 +1,82 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** $Id: pci.h,v 2.0.0.1 94/08/18 23:09:26 wolf Exp $
|
||||
**
|
||||
** #define for pci bus device drivers
|
||||
**
|
||||
** 386bsd / FreeBSD
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** Copyright (c) 1994 Wolfgang Stanglmeier. 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.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** $Log: pci.h,v $
|
||||
** Revision 2.0.0.1 94/08/18 23:09:26 wolf
|
||||
** Copyright message.
|
||||
**
|
||||
** Revision 2.0 94/07/10 15:53:30 wolf
|
||||
** FreeBSD release.
|
||||
**
|
||||
** Revision 1.0 94/06/07 20:02:21 wolf
|
||||
** Beta release.
|
||||
**
|
||||
***************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __PCI_H__
|
||||
#define __PCI_H__
|
||||
|
||||
/*
|
||||
** main pci initialization function.
|
||||
** called at boot time from autoconf.c
|
||||
*/
|
||||
|
||||
void pci_configure(void);
|
||||
|
||||
/*
|
||||
** pci configuration id
|
||||
**
|
||||
** is constructed from: bus, device & function numbers.
|
||||
*/
|
||||
|
||||
typedef union {
|
||||
u_long cfg1;
|
||||
struct {
|
||||
u_char enable;
|
||||
u_char forward;
|
||||
u_short port;
|
||||
} cfg2;
|
||||
} pcici_t;
|
||||
|
||||
/*
|
||||
** Each pci device has an unique device id.
|
||||
** It is used to find a matching driver.
|
||||
*/
|
||||
|
||||
typedef u_long pcidi_t;
|
||||
|
||||
#endif /*__PCI_H__*/
|
74
sys/i386/pci/pci_config.c
Normal file
74
sys/i386/pci/pci_config.c
Normal file
@ -0,0 +1,74 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** $Id: pci_config.c,v 2.0.0.1 94/08/18 23:07:28 wolf Exp $
|
||||
**
|
||||
** @PCI@ this should be part of "ioconf.c".
|
||||
**
|
||||
** The config-utility should build it!
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** Copyright (c) 1994 Wolfgang Stanglmeier. 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.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** $Log: pci_config.c,v $
|
||||
** Revision 2.0.0.1 94/08/18 23:07:28 wolf
|
||||
** Copyright message.
|
||||
** Hook for DEC ethernet driver "de".
|
||||
**
|
||||
** Revision 2.0 94/07/10 15:53:30 wolf
|
||||
** FreeBSD release.
|
||||
**
|
||||
** Revision 1.0 94/06/07 20:04:37 wolf
|
||||
** Beta release.
|
||||
**
|
||||
***************************************************************************
|
||||
*/
|
||||
|
||||
#include "types.h"
|
||||
#include "i386/pci/pci.h"
|
||||
#include "i386/pci/pci_device.h"
|
||||
|
||||
#include "ncr.h"
|
||||
#if NNCR>0
|
||||
extern struct pci_driver ncrdevice;
|
||||
#endif
|
||||
|
||||
#include "de.h"
|
||||
#if NDE > 0
|
||||
extern struct pci_driver dedevice;
|
||||
#endif
|
||||
|
||||
struct pci_device pci_devtab[] = {
|
||||
|
||||
#if NNCR>0
|
||||
{&ncrdevice},
|
||||
#endif
|
||||
#if NDE>0
|
||||
{&dedevice},
|
||||
#endif
|
||||
{0}
|
||||
};
|
112
sys/i386/pci/pci_device.h
Normal file
112
sys/i386/pci/pci_device.h
Normal file
@ -0,0 +1,112 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** $Id: pci_device.h,v 2.0.0.1 94/08/18 23:06:43 wolf Exp $
|
||||
**
|
||||
** #define for pci based device drivers
|
||||
**
|
||||
** 386bsd / FreeBSD
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** Copyright (c) 1994 Wolfgang Stanglmeier. 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.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** $Log: pci_device.h,v $
|
||||
** Revision 2.0.0.1 94/08/18 23:06:43 wolf
|
||||
** Copyright message.
|
||||
**
|
||||
** Revision 2.0 94/07/10 15:53:31 wolf
|
||||
** FreeBSD release.
|
||||
**
|
||||
** Revision 1.0 94/06/07 20:02:22 wolf
|
||||
** Beta release.
|
||||
**
|
||||
***************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __PCI_DEVICE_H__
|
||||
#define __PCI_DEVICE_H__
|
||||
|
||||
/*------------------------------------------------------------
|
||||
**
|
||||
** Per driver structure.
|
||||
**
|
||||
**------------------------------------------------------------
|
||||
*/
|
||||
|
||||
struct pci_driver {
|
||||
int (*probe )(pcici_t pci_ident); /* test whether device is present */
|
||||
int (*attach)(pcici_t pci_ident); /* setup driver for a device */
|
||||
pcidi_t device_id; /* device pci id */
|
||||
char *name; /* device name */
|
||||
char *vendor; /* device long name */
|
||||
int (*intr)(int); /* interupt handler */
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
**
|
||||
** Per device structure.
|
||||
**
|
||||
** It is initialized by the config utility and should live in
|
||||
** "ioconf.c". At the moment there is only one field.
|
||||
**
|
||||
** This is a first attempt to include the pci bus to 386bsd.
|
||||
** So this structure may grow ..
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
struct pci_device {
|
||||
struct pci_driver * pd_driver;
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
**
|
||||
** This table should be generated in file "ioconf.c"
|
||||
** by the config program.
|
||||
** It is used at boot time by the configuration function
|
||||
** pci_configure()
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
extern struct pci_device pci_devtab[];
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
**
|
||||
** This functions may be used by drivers to map devices
|
||||
** to virtual and physical addresses. The va and pa
|
||||
** addresses are "in/out" parameters. If they are 0
|
||||
** on entry, the mapping function assigns an address.
|
||||
**
|
||||
**-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
int pci_map_mem (pcici_t tag, u_long entry, u_long * va, u_long * pa);
|
||||
|
||||
int pci_map_port(pcici_t tag, u_long entry, u_short * pa);
|
||||
|
||||
#endif /*__PCI_DEVICE_H__*/
|
316
sys/i386/pci/pcibios.c
Normal file
316
sys/i386/pci/pcibios.c
Normal file
@ -0,0 +1,316 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** $Id: pcibios.c,v 2.0.0.2 94/08/18 23:04:11 wolf Exp $
|
||||
**
|
||||
** #define for pci-bus bios functions.
|
||||
**
|
||||
** 386bsd / FreeBSD
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** Copyright (c) 1994 Wolfgang Stanglmeier. 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.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** $Log: pcibios.c,v $
|
||||
** Revision 2.0.0.2 94/08/18 23:04:11 wolf
|
||||
** Copyright message.
|
||||
** New function pci_last_bus().
|
||||
**
|
||||
** Revision 2.0.0.1 94/08/01 20:35:29 wolf
|
||||
** Option: PCI_CONF_MODE to disable pci autodetect code.
|
||||
** Flipped code for mode1 and mode2.
|
||||
**
|
||||
** Revision 2.0 94/07/10 15:53:31 wolf
|
||||
** FreeBSD release.
|
||||
**
|
||||
** Revision 1.0 94/06/07 20:02:20 wolf
|
||||
** Beta release.
|
||||
**
|
||||
***************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#include "types.h"
|
||||
#include "i386/isa/isa.h"
|
||||
#include "i386/pci/pci.h"
|
||||
#include "i386/pci/pcibios.h"
|
||||
|
||||
|
||||
extern int printf();
|
||||
|
||||
static char pci_mode;
|
||||
|
||||
char ident_pcibios_c[] =
|
||||
"\n$Id: pcibios.c,v 2.0.0.2 94/08/18 23:04:11 wolf Exp $\n"
|
||||
"Copyright (c) 1994, Wolfgang Stanglmeier\n";
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
**
|
||||
** Port access
|
||||
**
|
||||
**--------------------------------------------------------------------
|
||||
**
|
||||
** @FREEBSD@ inl() and outl() functions are not defined
|
||||
*/
|
||||
|
||||
#define DIRTY
|
||||
|
||||
#ifdef DIRTY
|
||||
|
||||
#undef inl
|
||||
#define inl(port) \
|
||||
({ u_long data; \
|
||||
__asm __volatile("inl %1, %0": "=a" (data): "d" ((u_short)(port))); \
|
||||
data; })
|
||||
|
||||
|
||||
#undef outl
|
||||
#define outl(port, data) \
|
||||
{__asm __volatile("outl %0, %1"::"a" ((u_long)(data)), "d" ((u_short)(port)));}
|
||||
|
||||
|
||||
#undef inb
|
||||
#define inb(port) \
|
||||
({ u_char data; \
|
||||
__asm __volatile("inb %1, %0": "=a" (data): "d" ((u_short)(port))); \
|
||||
data; })
|
||||
|
||||
|
||||
#undef outb
|
||||
#define outb(port, data) \
|
||||
{__asm __volatile("outb %0, %1"::"a" ((u_char)(data)), "d" ((u_short)(port)));}
|
||||
|
||||
#endif
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
**
|
||||
** Determine configuration mode
|
||||
**
|
||||
**--------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#define CONF1_ENABLE 0x80000000ul
|
||||
#define CONF1_ADDR_PORT 0x0cf8
|
||||
#define CONF1_DATA_PORT 0x0cfc
|
||||
|
||||
|
||||
#define CONF2_ENABLE_PORT 0x0cf8
|
||||
#define CONF2_FORWARD_PORT 0x0cfa
|
||||
|
||||
|
||||
int pci_conf_mode (void)
|
||||
{
|
||||
#ifdef PCI_CONF_MODE
|
||||
return (PCI_CONF_MODE)
|
||||
#else /* PCI_CONF_MODE */
|
||||
u_long result, oldval;
|
||||
|
||||
/*---------------------------------------
|
||||
** Configuration mode 2 ?
|
||||
**---------------------------------------
|
||||
*/
|
||||
|
||||
outb (CONF2_ENABLE_PORT, 0);
|
||||
outb (CONF2_FORWARD_PORT, 0);
|
||||
if (!inb (CONF2_ENABLE_PORT) && !inb (CONF2_FORWARD_PORT)) {
|
||||
pci_mode = 2;
|
||||
return (2);
|
||||
};
|
||||
|
||||
/*---------------------------------------
|
||||
** Configuration mode 1 ?
|
||||
**---------------------------------------
|
||||
*/
|
||||
|
||||
oldval = inl (CONF1_ADDR_PORT);
|
||||
outl (CONF1_ADDR_PORT, CONF1_ENABLE);
|
||||
result = inl (CONF1_ADDR_PORT);
|
||||
outl (CONF1_ADDR_PORT, oldval);
|
||||
|
||||
if (result == CONF1_ENABLE) {
|
||||
pci_mode = 1;
|
||||
return (1);
|
||||
};
|
||||
|
||||
/*---------------------------------------
|
||||
** No PCI bus available.
|
||||
**---------------------------------------
|
||||
*/
|
||||
return (0);
|
||||
#endif /* PCI_CONF_MODE */
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
**
|
||||
** Build a pcitag from bus, device and function number
|
||||
**
|
||||
**--------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
pcici_t pcitag (unsigned char bus,
|
||||
unsigned char device,
|
||||
unsigned char func)
|
||||
{
|
||||
pcici_t tag;
|
||||
|
||||
tag.cfg1 = 0;
|
||||
if (device >= 32) return tag;
|
||||
if (func >= 8) return tag;
|
||||
|
||||
switch (pci_mode) {
|
||||
|
||||
case 1:
|
||||
tag.cfg1 = CONF1_ENABLE
|
||||
| (((u_long) bus ) << 16ul)
|
||||
| (((u_long) device) << 11ul)
|
||||
| (((u_long) func ) << 8ul);
|
||||
break;
|
||||
case 2:
|
||||
if (device >= 16) break;
|
||||
tag.cfg2.port = 0xc000 | (device << 8ul);
|
||||
tag.cfg2.enable = 0xf1 | (func << 1ul);
|
||||
tag.cfg2.forward = bus;
|
||||
break;
|
||||
};
|
||||
return tag;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
**
|
||||
** Read register from configuration space.
|
||||
**
|
||||
**--------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
u_long pci_conf_read (pcici_t tag, u_long reg)
|
||||
{
|
||||
u_long addr, data = 0;
|
||||
|
||||
if (!tag.cfg1) return (0xfffffffful);
|
||||
|
||||
switch (pci_mode) {
|
||||
|
||||
case 1:
|
||||
addr = tag.cfg1 | reg & 0xfc;
|
||||
#ifdef PCI_DEBUG
|
||||
printf ("pci_conf_read(1): addr=%x ", addr);
|
||||
#endif
|
||||
outl (CONF1_ADDR_PORT, addr);
|
||||
data = inl (CONF1_DATA_PORT);
|
||||
outl (CONF1_ADDR_PORT, 0 );
|
||||
break;
|
||||
|
||||
case 2:
|
||||
addr = tag.cfg2.port | reg & 0xfc;
|
||||
#ifdef PCI_DEBUG
|
||||
printf ("pci_conf_read(2): addr=%x ", addr);
|
||||
#endif
|
||||
outb (CONF2_ENABLE_PORT , tag.cfg2.enable );
|
||||
outb (CONF2_FORWARD_PORT, tag.cfg2.forward);
|
||||
|
||||
data = inl ((u_short) addr);
|
||||
|
||||
outb (CONF2_ENABLE_PORT, 0);
|
||||
outb (CONF2_FORWARD_PORT, 0);
|
||||
break;
|
||||
};
|
||||
|
||||
#ifdef PCI_DEBUG
|
||||
printf ("data=%x\n", data);
|
||||
#endif
|
||||
|
||||
return (data);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
**
|
||||
** Write register into configuration space.
|
||||
**
|
||||
**--------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
void pci_conf_write (pcici_t tag, u_long reg, u_long data)
|
||||
{
|
||||
u_long addr;
|
||||
|
||||
if (!tag.cfg1) return;
|
||||
|
||||
switch (pci_mode) {
|
||||
|
||||
case 1:
|
||||
addr = tag.cfg1 | reg & 0xfc;
|
||||
#ifdef PCI_DEBUG
|
||||
printf ("pci_conf_write(1): addr=%x data=%x\n",
|
||||
addr, data);
|
||||
#endif
|
||||
outl (CONF1_ADDR_PORT, addr);
|
||||
outl (CONF1_DATA_PORT, data);
|
||||
outl (CONF1_ADDR_PORT, 0 );
|
||||
break;
|
||||
|
||||
case 2:
|
||||
addr = tag.cfg2.port | reg & 0xfc;
|
||||
#ifdef PCI_DEBUG
|
||||
printf ("pci_conf_write(2): addr=%x data=%x\n",
|
||||
addr, data);
|
||||
#endif
|
||||
outb (CONF2_ENABLE_PORT, tag.cfg2.enable);
|
||||
outb (CONF2_FORWARD_PORT, tag.cfg2.forward);
|
||||
|
||||
outl ((u_short) addr, data);
|
||||
|
||||
outb (CONF2_ENABLE_PORT, 0);
|
||||
outb (CONF2_FORWARD_PORT, 0);
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
**
|
||||
** Get the number of available PCI busses.
|
||||
**
|
||||
**--------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
** A certain chipset seems to ignore the bus number.
|
||||
** Until fixed, check only bus 0.
|
||||
** Maybe it's a good idea to ask the real pci bios
|
||||
** if available.
|
||||
*/
|
||||
|
||||
#ifndef PCI_LAST_BUS
|
||||
#define PCI_LAST_BUS (0)
|
||||
#endif /* PCI_LAST_BUS */
|
||||
|
||||
int pci_last_bus (void)
|
||||
{
|
||||
return (PCI_LAST_BUS);
|
||||
}
|
114
sys/i386/pci/pcibios.h
Normal file
114
sys/i386/pci/pcibios.h
Normal file
@ -0,0 +1,114 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** $Id: pcibios.h,v 2.0.0.1 94/08/18 23:05:36 wolf Exp $
|
||||
**
|
||||
** #define for pci-bus bios functions.
|
||||
**
|
||||
** 386bsd / FreeBSD
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** Copyright (c) 1994 Wolfgang Stanglmeier. 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.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** $Log: pcibios.h,v $
|
||||
** Revision 2.0.0.1 94/08/18 23:05:36 wolf
|
||||
**
|
||||
** Copyright message.
|
||||
** New function: pci_last_bus().
|
||||
** Symbolic names for pci configuration space registers.
|
||||
**
|
||||
** Revision 2.0 94/07/10 15:53:32 wolf
|
||||
** FreeBSD release.
|
||||
**
|
||||
** Revision 1.0 94/06/07 20:02:23 wolf
|
||||
** Beta release.
|
||||
**
|
||||
***************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __PCIBIOS_H__
|
||||
#define __PCIBIOS_H__
|
||||
|
||||
/*
|
||||
** the availability of a pci bus.
|
||||
** configuration mode (1 or 2)
|
||||
** 0 if no pci bus found.
|
||||
*/
|
||||
|
||||
int pci_conf_mode (void);
|
||||
|
||||
/*
|
||||
** The number of the last available pci bus.
|
||||
*/
|
||||
|
||||
int pci_last_bus (void);
|
||||
|
||||
/*
|
||||
** get a "ticket" for accessing a pci device
|
||||
** configuration space.
|
||||
*/
|
||||
|
||||
pcici_t pcitag (unsigned char bus,
|
||||
unsigned char device,
|
||||
unsigned char func);
|
||||
|
||||
/*
|
||||
** read or write the configuration space.
|
||||
*/
|
||||
|
||||
u_long pci_conf_read (pcici_t tag, u_long reg );
|
||||
void pci_conf_write (pcici_t tag, u_long reg, u_long data);
|
||||
|
||||
|
||||
/*
|
||||
** Names for PCI configuration space registers.
|
||||
** Copied from pcireg.h
|
||||
*/
|
||||
|
||||
#define PCI_ID_REG 0x00
|
||||
|
||||
#define PCI_COMMAND_STATUS_REG 0x04
|
||||
#define PCI_COMMAND_MEM_ENABLE 0x00000002
|
||||
|
||||
#define PCI_MAP_REG_START 0x10
|
||||
#define PCI_MAP_REG_END 0x28
|
||||
#define PCI_MAP_MEMORY 0x00000000
|
||||
#define PCI_MAP_IO 0x00000001
|
||||
#define PCI_MAP_MEMORY_TYPE_32BIT 0x00000000
|
||||
#define PCI_MAP_MEMORY_TYPE_32BIT_1M 0x00000002
|
||||
#define PCI_MAP_MEMORY_TYPE_64BIT 0x00000004
|
||||
#define PCI_MAP_MEMORY_TYPE_MASK 0x00000006
|
||||
#define PCI_MAP_MEMORY_CACHABLE 0x00000008
|
||||
#define PCI_MAP_MEMORY_ADDRESS_MASK 0xfffffff0
|
||||
|
||||
#define PCI_INTERRUPT_REG 0x3c
|
||||
#define PCI_INTERRUPT_PIN_MASK 0x0000ff00
|
||||
#define PCI_INTERRUPT_PIN_EXTRACT(x) ((((x) & PCI_INTERRUPT_PIN_MASK) >> 8) & 0xff)
|
||||
#define PCI_INTERRUPT_LINE_MASK 0x000000ff
|
||||
#define PCI_INTERRUPT_LINE_EXTRACT(x) ((((x) & PCI_INTERRUPT_LINE_MASK) >> 0) & 0xff)
|
||||
|
||||
#endif
|
5695
sys/pci/ncr.c
Normal file
5695
sys/pci/ncr.c
Normal file
File diff suppressed because it is too large
Load Diff
598
sys/pci/pci.c
Normal file
598
sys/pci/pci.c
Normal file
@ -0,0 +1,598 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** $Id: pci.c,v 2.0.0.8 94/08/21 19:57:39 wolf Exp $
|
||||
**
|
||||
** General subroutines for the PCI bus on 80*86 systems.
|
||||
** pci_configure ()
|
||||
**
|
||||
** 386bsd / FreeBSD
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** Copyright (c) 1994 Wolfgang Stanglmeier. 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.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
**
|
||||
**-------------------------------------------------------------------------
|
||||
**
|
||||
** $Log: pci.c,v $
|
||||
** Revision 2.0.0.8 94/08/21 19:57:39 wolf
|
||||
** Unneeded declarations removed (FreeBSD2.0)
|
||||
**
|
||||
** Revision 2.0.0.7 94/08/21 19:25:54 wolf
|
||||
** pci_intr simplified.
|
||||
** new not_supported() function.
|
||||
** Vendor and device ids moved into tables.
|
||||
**
|
||||
** Revision 2.0.0.6 94/08/18 22:58:23 wolf
|
||||
** Symbolic names for pci configuration space registers.
|
||||
** last_device: from configuration mode
|
||||
** last_bus: from pcibios.
|
||||
** PCI_MAX_DPI: changed to 4 (settable by config)
|
||||
** interrupt configuration by line or pin
|
||||
**
|
||||
** Revision 2.0.0.5 94/08/11 19:04:10 wolf
|
||||
** display of interrupt line configuration register.
|
||||
**
|
||||
** Revision 2.0.0.4 94/08/01 20:36:28 wolf
|
||||
** Tiny clean up.
|
||||
**
|
||||
** Revision 2.0.0.3 94/08/01 18:52:33 wolf
|
||||
** New vendor entry: S3.
|
||||
** Scan pci busses #0..#255 as default.
|
||||
** Number of scanned busses and devices settable as option.
|
||||
** Show these numbers before starting the scan.
|
||||
**
|
||||
** Revision 2.0.0.2 94/07/27 09:27:19 wolf
|
||||
** New option PCI_QUIET: suppress log messages.
|
||||
**
|
||||
** Revision 2.0.0.1 94/07/19 19:06:44 wolf
|
||||
** New vendor entry: MATROX
|
||||
**
|
||||
** Revision 2.0 94/07/10 15:53:29 wolf
|
||||
** FreeBSD release.
|
||||
**
|
||||
** Revision 1.0 94/06/07 20:02:19 wolf
|
||||
** Beta release.
|
||||
**
|
||||
***************************************************************************
|
||||
*/
|
||||
|
||||
#include <pci.h>
|
||||
#if NPCI > 0
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** Configuration
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
** maximum number of devices which share one interrupt line
|
||||
*/
|
||||
|
||||
#ifndef PCI_MAX_DPI
|
||||
#define PCI_MAX_DPI (4)
|
||||
#endif /*PCI_MAX_DPI*/
|
||||
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** #includes and declarations
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
#include <types.h>
|
||||
#include <cdefs.h>
|
||||
#include <errno.h>
|
||||
#include <param.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_param.h>
|
||||
|
||||
#include <i386/isa/icu.h>
|
||||
#include <i386/isa/isa.h>
|
||||
#include <i386/isa/isa_device.h>
|
||||
|
||||
#include <i386/pci/pci.h>
|
||||
#include <i386/pci/pci_device.h>
|
||||
#include <i386/pci/pcibios.h>
|
||||
|
||||
|
||||
char ident_pci_c[] =
|
||||
"\n$Id: pci.c,v 2.0.0.8 94/08/21 19:57:39 wolf Exp $\n"
|
||||
"Copyright (c) 1994, Wolfgang Stanglmeier\n";
|
||||
|
||||
/*
|
||||
** Function prototypes missing in system headers
|
||||
*/
|
||||
|
||||
extern int printf();
|
||||
extern int ffs();
|
||||
#if ! (__FreeBSD__ >= 2)
|
||||
extern pmap_t pmap_kernel(void);
|
||||
#endif
|
||||
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** Autoconfiguration (of isa bus)
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
** per device (interrupt) data structure.
|
||||
*/
|
||||
|
||||
static struct {
|
||||
u_short number;
|
||||
u_short isanum;
|
||||
struct {
|
||||
int (*proc)(int dev);
|
||||
dev_t unit;
|
||||
} vector[PCI_MAX_DPI];
|
||||
} pcidata [NPCI];
|
||||
|
||||
/*
|
||||
** check device ready
|
||||
*/
|
||||
static int pciprobe (struct isa_device *dev)
|
||||
{
|
||||
if (dev->id_unit >= NPCI)
|
||||
return (0);
|
||||
|
||||
if (!pci_conf_mode())
|
||||
return (0);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
** initialize the driver structure
|
||||
*/
|
||||
static int pciattach (struct isa_device *isdp)
|
||||
{
|
||||
pcidata[isdp->id_unit].number = 0;
|
||||
pcidata[isdp->id_unit].isanum = ffs(isdp->id_irq)-1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
** ISA driver structure
|
||||
*/
|
||||
|
||||
struct isa_driver pcidriver = {
|
||||
pciprobe,
|
||||
pciattach,
|
||||
"pci"
|
||||
};
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** Interrupt forward from isa to pci devices.
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
|
||||
void pciintr (int unit)
|
||||
{
|
||||
u_short i;
|
||||
if (unit >= NPCI) return;
|
||||
for (i=0; i<pcidata[unit].number; i++) {
|
||||
(void)(*pcidata[unit].vector[i].proc)(pcidata[unit].vector[i].unit);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/*========================================================
|
||||
**
|
||||
** Autoconfiguration of pci devices.
|
||||
**
|
||||
** This is reverse to the isa configuration.
|
||||
** (1) find a pci device.
|
||||
** (2) look for a driver.
|
||||
**
|
||||
**========================================================
|
||||
*/
|
||||
|
||||
/*--------------------------------------------------------
|
||||
**
|
||||
** The pci devices can be mapped to any address.
|
||||
** As default we start at the last gigabyte.
|
||||
**
|
||||
**--------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PCI_PMEM_START
|
||||
#define PCI_PMEM_START 0xc0000000
|
||||
#endif
|
||||
|
||||
static vm_offset_t pci_paddr = PCI_PMEM_START;
|
||||
|
||||
/*---------------------------------------------------------
|
||||
**
|
||||
** pci_configure ()
|
||||
**
|
||||
**---------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void not_supported (pcici_t tag, u_long type);
|
||||
|
||||
void pci_configure()
|
||||
{
|
||||
u_char device,last_device;
|
||||
u_short bus,last_bus;
|
||||
pcici_t tag;
|
||||
pcidi_t type;
|
||||
u_long data;
|
||||
int unit;
|
||||
int intpin;
|
||||
int isanum;
|
||||
int pci_mode;
|
||||
|
||||
struct pci_driver *drp;
|
||||
struct pci_device *dvp;
|
||||
|
||||
/*
|
||||
** check pci bus present
|
||||
*/
|
||||
|
||||
pci_mode = pci_conf_mode ();
|
||||
if (!pci_mode) return;
|
||||
last_bus = pci_last_bus ();
|
||||
last_device = pci_mode==1 ? 31 : 15;
|
||||
|
||||
/*
|
||||
** hello world ..
|
||||
*/
|
||||
|
||||
#ifndef PCI_QUIET
|
||||
printf ("PCI configuration mode %d.\n", pci_mode);
|
||||
printf ("Scanning device 0..%d on pci bus 0..%d "
|
||||
"($Revision: 2.0.0.8 $)\n",
|
||||
last_device, last_bus);
|
||||
#endif
|
||||
|
||||
for (bus=0;bus<=last_bus; bus++)
|
||||
for (device=0; device<=last_device; device ++) {
|
||||
tag = pcitag (bus, device, 0);
|
||||
type = pci_conf_read (tag, PCI_ID_REG);
|
||||
|
||||
if ((!type) || (type==0xfffffffful)) continue;
|
||||
|
||||
/*
|
||||
** lookup device in ioconfiguration:
|
||||
*/
|
||||
|
||||
for (dvp = pci_devtab; drp=dvp->pd_driver; dvp++) {
|
||||
if (drp->device_id == type) break;
|
||||
};
|
||||
|
||||
#ifdef PCI_QUIET
|
||||
if (!drp) continue;
|
||||
#endif
|
||||
printf ("on pci%d:%d ", bus, device);
|
||||
#ifndef PCI_QUIET
|
||||
if (!drp) {
|
||||
not_supported (tag, type);
|
||||
continue;
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
** found it.
|
||||
** probe returns the device unit.
|
||||
*/
|
||||
|
||||
printf ("<%s>", drp -> vendor);
|
||||
|
||||
unit = (*drp->probe) (tag);
|
||||
|
||||
if (unit<0) {
|
||||
printf (" probe failed.\n");
|
||||
continue;
|
||||
};
|
||||
|
||||
/*
|
||||
** install interrupts
|
||||
*/
|
||||
|
||||
data = pci_conf_read (tag, PCI_INTERRUPT_REG);
|
||||
intpin = PCI_INTERRUPT_PIN_EXTRACT(data);
|
||||
if (intpin) {
|
||||
int idx=NPCI;
|
||||
|
||||
/*
|
||||
** Usage of int line register (if set by bios)
|
||||
** Matt Thomas <thomas@lkg.dec.com>
|
||||
*/
|
||||
|
||||
isanum = PCI_INTERRUPT_LINE_EXTRACT(data);
|
||||
if (isanum) {
|
||||
printf (" il=%d", isanum);
|
||||
for (idx = 0; idx < NPCI; idx++) {
|
||||
if (pcidata[idx].isanum == isanum)
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
** Or believe to the interrupt pin register.
|
||||
*/
|
||||
|
||||
if (idx >= NPCI) idx = intpin-1;
|
||||
|
||||
/*
|
||||
** And install the interrupt.
|
||||
*/
|
||||
|
||||
if (idx<NPCI) {
|
||||
u_short entry = pcidata[idx].number;
|
||||
printf (" irq %c", 0x60+intpin);
|
||||
if (entry < PCI_MAX_DPI) {
|
||||
pcidata[idx].vector[entry].proc = drp->intr;
|
||||
pcidata[idx].vector[entry].unit = unit;
|
||||
entry++;
|
||||
};
|
||||
printf (" isa=%d [%d]",pcidata[idx].isanum, entry);
|
||||
pcidata[idx].number=entry;
|
||||
} else {
|
||||
printf (" not installed");
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
** enable memory access
|
||||
*/
|
||||
data = pci_conf_read (tag, PCI_COMMAND_STATUS_REG)
|
||||
& 0xffff | PCI_COMMAND_MEM_ENABLE;
|
||||
pci_conf_write (tag, (u_char) PCI_COMMAND_STATUS_REG, data);
|
||||
|
||||
/*
|
||||
** attach device
|
||||
** may produce additional log messages,
|
||||
** i.e. when installing subdevices.
|
||||
*/
|
||||
|
||||
printf (" as %s%d\n", drp->name,unit);
|
||||
(void) (*drp->attach) (tag);
|
||||
|
||||
};
|
||||
|
||||
printf ("pci uses physical addresses from %x to %x\n",
|
||||
PCI_PMEM_START, pci_paddr);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
**
|
||||
** Map device into port space.
|
||||
**
|
||||
** PCI-Specification: 6.2.5.1: address maps
|
||||
**
|
||||
**-----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
extern vm_map_t kernel_map;
|
||||
|
||||
int pci_map_port (pcici_t tag, u_long reg, u_short* pa)
|
||||
{
|
||||
/*
|
||||
** @MAPIO@ not yet implemented.
|
||||
*/
|
||||
return (ENOSYS);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
**
|
||||
** Map device into virtual and physical space
|
||||
**
|
||||
** PCI-Specification: 6.2.5.1: address maps
|
||||
**
|
||||
**-----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int pci_map_mem (pcici_t tag, u_long reg, vm_offset_t* va, vm_offset_t* pa)
|
||||
{
|
||||
u_long data, result;
|
||||
vm_size_t vsize;
|
||||
vm_offset_t vaddr;
|
||||
|
||||
/*
|
||||
** sanity check
|
||||
*/
|
||||
|
||||
if (reg <= PCI_MAP_REG_START || reg >= PCI_MAP_REG_END || (reg & 3))
|
||||
return (EINVAL);
|
||||
|
||||
/*
|
||||
** get size and type of memory
|
||||
**
|
||||
** type is in the lowest four bits.
|
||||
** If device requires 2^n bytes, the next
|
||||
** n-4 bits are read as 0.
|
||||
*/
|
||||
|
||||
pci_conf_write (tag, reg, 0xfffffffful);
|
||||
data = pci_conf_read (tag, reg);
|
||||
|
||||
switch (data & 0x0f) {
|
||||
|
||||
case PCI_MAP_MEMORY_TYPE_32BIT: /* 32 bit non cachable */
|
||||
break;
|
||||
|
||||
default: /* unknown */
|
||||
return (EINVAL);
|
||||
};
|
||||
|
||||
/*
|
||||
** mask out the type,
|
||||
** and round up to a page size
|
||||
*/
|
||||
|
||||
vsize = round_page (-(data & PCI_MAP_MEMORY_ADDRESS_MASK));
|
||||
|
||||
printf (" memory size=0x%x", vsize);
|
||||
|
||||
if (!vsize) return (EINVAL);
|
||||
|
||||
/*
|
||||
** try to map device to virtual space
|
||||
*/
|
||||
|
||||
vaddr = vm_map_min (kernel_map);
|
||||
|
||||
result = vm_map_find (kernel_map, (void*)0, (vm_offset_t) 0,
|
||||
&vaddr, vsize, TRUE);
|
||||
|
||||
if (result != KERN_SUCCESS) {
|
||||
printf (" vm_map_find failed(%d)\n", result);
|
||||
return (ENOMEM);
|
||||
};
|
||||
|
||||
/*
|
||||
** align physical address to virtual size
|
||||
*/
|
||||
|
||||
if (data = pci_paddr % vsize)
|
||||
pci_paddr += vsize - data;
|
||||
|
||||
/*
|
||||
** display values.
|
||||
*/
|
||||
|
||||
printf (" virtual=0x%x physical=0x%x\n", vaddr, pci_paddr);
|
||||
|
||||
/*
|
||||
** return them to the driver
|
||||
*/
|
||||
|
||||
*va = vaddr;
|
||||
*pa = pci_paddr;
|
||||
|
||||
/*
|
||||
** set device address
|
||||
*/
|
||||
|
||||
pci_conf_write (tag, reg, pci_paddr);
|
||||
|
||||
/*
|
||||
** map physical
|
||||
*/
|
||||
|
||||
while (vsize >= NBPG) {
|
||||
pmap_enter (pmap_kernel(), vaddr, pci_paddr,
|
||||
VM_PROT_READ|VM_PROT_WRITE, TRUE);
|
||||
vaddr += NBPG;
|
||||
pci_paddr += NBPG;
|
||||
vsize -= NBPG;
|
||||
};
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
struct vt {
|
||||
u_short ident;
|
||||
char* name;
|
||||
};
|
||||
|
||||
struct dt {
|
||||
u_long ident;
|
||||
char* name;
|
||||
};
|
||||
|
||||
static struct vt VendorTable[] = {
|
||||
{0x1002, "ATI TECHNOLOGIES INC"},
|
||||
{0x1011, "DIGITAL EQUIPMENT COMPANY"},
|
||||
{0x101A, "NCR"},
|
||||
{0x102B, "MATROX"},
|
||||
{0x1045, "OPTI"},
|
||||
{0x5333, "S3 INC."},
|
||||
{0x8086, "INTEL CORPORATION"},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
static struct dt DeviceTable[] = {
|
||||
{0x04848086, " 82378IB pci-isa bridge"},
|
||||
{0x04838086, " 82424ZX cache dram controller"},
|
||||
{0x04828086, " 82375EB pci-eisa bridge"},
|
||||
{0x04A38086, " 82434LX pci cache memory controller"},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
void not_supported (pcici_t tag, u_long type)
|
||||
{
|
||||
u_char reg;
|
||||
u_long data;
|
||||
struct vt * vp;
|
||||
struct dt * dp;
|
||||
|
||||
/*
|
||||
** lookup the names.
|
||||
*/
|
||||
|
||||
for (vp=VendorTable; vp->ident; vp++)
|
||||
if (vp->ident == (type & 0xffff))
|
||||
break;
|
||||
|
||||
for (dp=DeviceTable; dp->ident; dp++)
|
||||
if (dp->ident == type)
|
||||
break;
|
||||
|
||||
/*
|
||||
** and display them.
|
||||
*/
|
||||
|
||||
if (vp->ident) printf (vp->name);
|
||||
else printf ("vendor=%x", type & 0xffff);
|
||||
|
||||
if (dp->ident) printf (dp->name);
|
||||
else printf (", device=%x", type >> 16);
|
||||
|
||||
printf (" [not supported]\n");
|
||||
|
||||
for (reg=PCI_MAP_REG_START; reg<PCI_MAP_REG_END; reg+=4) {
|
||||
data = pci_conf_read (tag, reg);
|
||||
if (!data) continue;
|
||||
switch (data&7) {
|
||||
|
||||
case 1:
|
||||
case 5:
|
||||
printf (" map(%x): io(%x)\n", reg, data & ~3);
|
||||
break;
|
||||
case 0:
|
||||
printf (" map(%x): mem32(%x)\n", reg, data & ~7);
|
||||
break;
|
||||
case 2:
|
||||
printf (" map(%x): mem20(%x)\n", reg, data & ~7);
|
||||
break;
|
||||
case 4:
|
||||
printf (" map(%x): mem64(%x)\n", reg, data & ~7);
|
||||
break;
|
||||
};
|
||||
};
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user