modify these to provide a new, better-specified PCI interface
(soon to be documented on mailing lists; eventually in section 9 manual pages), most importantly: (1) support interrupt pin swizzling on non-i386 systems with PCI-PCI bridges (per PPB spec; done, but meaningless, on i386). (2) provide pci_{io,mem}_find(), to determine what I/O or memory space is described by a given PCI configuration space mapping register. (3) provide pci_intr_map(), pci_intr_string(), and pci_intr_{,dis}establish() to manipulate and print info about PCI interrupts. (4) deprecate the pci_map_* functions, and provide them only as compatibility interfaces (in pci_compat.c) which will eventually go away, implemented as wrappers around the functions described above. (5) make pci functions take as an argument a machine-dependent cookie, to allow more flexibility in implementation.
This commit is contained in:
parent
360590468a
commit
da3136aba8
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: files.i386,v 1.69 1996/03/25 18:44:29 perry Exp $
|
||||
# $NetBSD: files.i386,v 1.70 1996/03/27 04:01:10 cgd Exp $
|
||||
#
|
||||
# new style config file for i386 architecture
|
||||
#
|
||||
|
@ -64,6 +64,7 @@ file arch/i386/i386/mainbus.c mainbus
|
|||
|
||||
include "../../../dev/pci/files.pci"
|
||||
file arch/i386/pci/pci_machdep.c pci
|
||||
file arch/i386/pci/pci_compat.c pci # XXX compatibility
|
||||
|
||||
#
|
||||
# ISA and mixed ISA+EISA or ISA+PCI drivers
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
/* $NetBSD: pci_compat.c,v 1.1 1996/03/27 04:01:13 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
|
||||
* Copyright (c) 1994 Charles Hannum. 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Charles Hannum.
|
||||
* 4. 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Compatibility functions, for use with old NetBSD/i386 PCI code.
|
||||
*
|
||||
* These should go away when all drivers are converted to the new
|
||||
* interfaces.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
|
||||
#include <dev/pci/pcivar.h>
|
||||
#include <dev/pci/pcireg.h>
|
||||
|
||||
__warn_references(pci_map_int,
|
||||
"uses pci_map_int() compatibility interface");
|
||||
|
||||
void *
|
||||
pci_map_int(tag, level, func, arg)
|
||||
pcitag_t tag;
|
||||
int level;
|
||||
int (*func) __P((void *));
|
||||
void *arg;
|
||||
{
|
||||
pci_intr_handle_t ih;
|
||||
pcireg_t data;
|
||||
int pin, line;
|
||||
const char *intrstr;
|
||||
void *rv;
|
||||
|
||||
data = pci_conf_read(NULL, tag, PCI_INTERRUPT_REG);
|
||||
|
||||
pin = PCI_INTERRUPT_PIN(data);
|
||||
line = PCI_INTERRUPT_LINE(data);
|
||||
|
||||
if (pci_intr_map(NULL, tag, pin, line, &ih))
|
||||
return NULL;
|
||||
intrstr = pci_intr_string(NULL, ih);
|
||||
rv = pci_intr_establish(NULL, ih, level, func, arg);
|
||||
if (rv == NULL)
|
||||
printf("pci_map_int: failed to map interrupt\n");
|
||||
else if (intrstr != NULL)
|
||||
printf("pci_map_int: interrupting at %s\n", intrstr);
|
||||
return (rv);
|
||||
}
|
||||
|
||||
__warn_references(pci_map_io,
|
||||
"uses pci_map_io() compatibility interface");
|
||||
|
||||
int
|
||||
pci_map_io(tag, reg, iobasep)
|
||||
pcitag_t tag;
|
||||
int reg;
|
||||
int *iobasep;
|
||||
{
|
||||
bus_io_addr_t ioaddr;
|
||||
bus_io_size_t iosize;
|
||||
bus_io_handle_t ioh;
|
||||
|
||||
if (pci_io_find(NULL, tag, reg, &ioaddr, &iosize))
|
||||
return (1);
|
||||
if (bus_io_map(NULL, ioaddr, iosize, &ioh))
|
||||
return (1);
|
||||
|
||||
*iobasep = ioh;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__warn_references(pci_map_mem,
|
||||
"uses pci_map_mem() compatibility interface");
|
||||
|
||||
int
|
||||
pci_map_mem(tag, reg, vap, pap)
|
||||
pcitag_t tag;
|
||||
int reg;
|
||||
vm_offset_t *vap, *pap;
|
||||
{
|
||||
bus_mem_addr_t memaddr;
|
||||
bus_mem_size_t memsize;
|
||||
bus_mem_handle_t memh;
|
||||
int cacheable;
|
||||
|
||||
if (pci_mem_find(NULL, tag, reg, &memaddr, &memsize, &cacheable))
|
||||
return (1);
|
||||
if (bus_mem_map(NULL, memaddr, memsize, cacheable, &memh))
|
||||
return (1);
|
||||
|
||||
*vap = (vm_offset_t)memh;
|
||||
*pap = memaddr;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
/* $NetBSD: pci_machdep.c,v 1.20 1996/03/04 19:39:31 cgd Exp $ */
|
||||
/* $NetBSD: pci_machdep.c,v 1.21 1996/03/27 04:01:14 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
|
||||
* Copyright (c) 1994 Charles Hannum. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -67,8 +68,37 @@ int pci_mode = -1;
|
|||
#define PCI_MODE2_ENABLE_REG 0x0cf8
|
||||
#define PCI_MODE2_FORWARD_REG 0x0cfa
|
||||
|
||||
void
|
||||
pci_attach_hook(parent, self, pba)
|
||||
struct device *parent, *self;
|
||||
struct pcibus_attach_args *pba;
|
||||
{
|
||||
|
||||
if (pba->pba_bus == 0)
|
||||
printf(": configuration mode %d", pci_mode);
|
||||
}
|
||||
|
||||
int
|
||||
pci_bus_maxdevs(pc, busno)
|
||||
pci_chipset_tag_t pc;
|
||||
int busno;
|
||||
{
|
||||
|
||||
/*
|
||||
* Bus number is irrelevant. If Configuration Mechanism 2 is in
|
||||
* use, can only have devices 0-15 on any bus. If Configuration
|
||||
* Mechanism 1 is in use, can have devices 0-32 (i.e. the `normal'
|
||||
* range).
|
||||
*/
|
||||
if (pci_mode == 2)
|
||||
return (16);
|
||||
else
|
||||
return (32);
|
||||
}
|
||||
|
||||
pcitag_t
|
||||
pci_make_tag(bus, device, function)
|
||||
pci_make_tag(pc, bus, device, function)
|
||||
pci_chipset_tag_t pc;
|
||||
int bus, device, function;
|
||||
{
|
||||
pcitag_t tag;
|
||||
|
@ -107,7 +137,8 @@ mode2:
|
|||
}
|
||||
|
||||
pcireg_t
|
||||
pci_conf_read(tag, reg)
|
||||
pci_conf_read(pc, tag, reg)
|
||||
pci_chipset_tag_t pc;
|
||||
pcitag_t tag;
|
||||
int reg;
|
||||
{
|
||||
|
@ -143,7 +174,8 @@ mode2:
|
|||
}
|
||||
|
||||
void
|
||||
pci_conf_write(tag, reg, data)
|
||||
pci_conf_write(pc, tag, reg, data)
|
||||
pci_chipset_tag_t pc;
|
||||
pcitag_t tag;
|
||||
int reg;
|
||||
pcireg_t data;
|
||||
|
@ -221,137 +253,22 @@ not1:
|
|||
}
|
||||
|
||||
int
|
||||
pci_map_io(tag, reg, iobasep)
|
||||
pcitag_t tag;
|
||||
int reg;
|
||||
int *iobasep;
|
||||
{
|
||||
pcireg_t address;
|
||||
int iobase;
|
||||
|
||||
if (reg < PCI_MAPREG_START || reg >= PCI_MAPREG_END || (reg & 3))
|
||||
panic("pci_map_io: bad request");
|
||||
|
||||
address = pci_conf_read(tag, reg);
|
||||
|
||||
if (PCI_MAPREG_TYPE(address) != PCI_MAPREG_TYPE_IO)
|
||||
panic("pci_map_io: not an I/O mapping register");
|
||||
|
||||
iobase = PCI_MAPREG_IO_ADDR(address);
|
||||
*iobasep = iobase;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pci_map_mem(tag, reg, vap, pap)
|
||||
pcitag_t tag;
|
||||
int reg;
|
||||
vm_offset_t *vap, *pap;
|
||||
{
|
||||
pcireg_t address, mask;
|
||||
int cachable;
|
||||
vm_size_t size;
|
||||
vm_offset_t va, pa;
|
||||
|
||||
if (reg < PCI_MAPREG_START || reg >= PCI_MAPREG_END || (reg & 3))
|
||||
panic("pci_map_mem: bad request");
|
||||
|
||||
/*
|
||||
* Section 6.2.5.1, `Address Maps', tells us that:
|
||||
*
|
||||
* 1) The builtin software should have already mapped the device in a
|
||||
* reasonable way.
|
||||
*
|
||||
* 2) A device which wants 2^n bytes of memory will hardwire the bottom
|
||||
* n bits of the address to 0. As recommended, we write all 1s and see
|
||||
* what we get back.
|
||||
*/
|
||||
address = pci_conf_read(tag, reg);
|
||||
pci_conf_write(tag, reg, 0xffffffff);
|
||||
mask = pci_conf_read(tag, reg);
|
||||
pci_conf_write(tag, reg, address);
|
||||
|
||||
if (PCI_MAPREG_TYPE(address) == PCI_MAPREG_TYPE_IO)
|
||||
panic("pci_map_mem: I/O mapping register");
|
||||
|
||||
switch (address & PCI_MAPREG_MEM_TYPE_MASK) {
|
||||
case PCI_MAPREG_MEM_TYPE_32BIT:
|
||||
case PCI_MAPREG_MEM_TYPE_32BIT_1M:
|
||||
break;
|
||||
case PCI_MAPREG_MEM_TYPE_64BIT:
|
||||
printf("pci_map_mem: 64-bit memory mapping register\n");
|
||||
return EOPNOTSUPP;
|
||||
default:
|
||||
printf("pci_map_mem: reserved mapping register type\n");
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
pa = PCI_MAPREG_MEM_ADDR(address);
|
||||
size = ~PCI_MAPREG_MEM_ADDR(mask) + 1;
|
||||
if (size < NBPG)
|
||||
size = NBPG;
|
||||
|
||||
va = kmem_alloc_pageable(kernel_map, size);
|
||||
if (va == 0) {
|
||||
printf("pci_map_mem: not enough memory\n");
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
/*
|
||||
* Tell the driver where we mapped it.
|
||||
*
|
||||
* If the region is smaller than one page, adjust the virtual address
|
||||
* to the same page offset as the physical address.
|
||||
*/
|
||||
*vap = va + (pa & PGOFSET);
|
||||
*pap = pa;
|
||||
|
||||
#if 1
|
||||
printf("pci_map_mem: mapping memory at virtual %08x, physical %08x\n", *vap, *pap);
|
||||
#endif
|
||||
|
||||
/* Map the space into the kernel page table. */
|
||||
cachable = PCI_MAPREG_MEM_CACHEABLE(address);
|
||||
pa &= ~PGOFSET;
|
||||
while (size) {
|
||||
pmap_enter(pmap_kernel(), va, pa, VM_PROT_READ | VM_PROT_WRITE,
|
||||
TRUE);
|
||||
if (!cachable)
|
||||
pmap_changebit(pa, PG_N, ~0);
|
||||
else
|
||||
pmap_changebit(pa, 0, ~PG_N);
|
||||
va += NBPG;
|
||||
pa += NBPG;
|
||||
size -= NBPG;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
pci_map_int(tag, level, func, arg)
|
||||
pcitag_t tag;
|
||||
int level;
|
||||
int (*func) __P((void *));
|
||||
void *arg;
|
||||
{
|
||||
pcireg_t data;
|
||||
pci_intr_map(pc, intrtag, pin, line, ihp)
|
||||
pci_chipset_tag_t pc;
|
||||
pcitag_t intrtag;
|
||||
int pin, line;
|
||||
pci_intr_handle_t *ihp;
|
||||
{
|
||||
|
||||
data = pci_conf_read(tag, PCI_INTERRUPT_REG);
|
||||
|
||||
pin = PCI_INTERRUPT_PIN(data);
|
||||
line = PCI_INTERRUPT_LINE(data);
|
||||
|
||||
#define BAD { *ihp = -1; return 1; }
|
||||
if (pin == 0) {
|
||||
/* No IRQ used. */
|
||||
return 0;
|
||||
BAD;
|
||||
}
|
||||
|
||||
if (pin > 4) {
|
||||
printf("pci_map_int: bad interrupt pin %d\n", pin);
|
||||
return NULL;
|
||||
printf("pci_intr_map: bad interrupt pin %d\n", pin);
|
||||
BAD;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -369,22 +286,58 @@ pci_map_int(tag, level, func, arg)
|
|||
* the BIOS has not configured the device.
|
||||
*/
|
||||
if (line == 0 || line == 255) {
|
||||
printf("pci_map_int: no mapping for pin %c\n", '@' + pin);
|
||||
return NULL;
|
||||
printf("pci_intr_map: no mapping for pin %c\n", '@' + pin);
|
||||
BAD;
|
||||
} else {
|
||||
if (line >= ICU_LEN) {
|
||||
printf("pci_map_int: bad interrupt line %d\n", line);
|
||||
return NULL;
|
||||
printf("pci_intr_map: bad interrupt line %d\n", line);
|
||||
BAD;
|
||||
}
|
||||
if (line == 2) {
|
||||
printf("pci_map_int: changed line 2 to line 9\n");
|
||||
printf("pci_intr_map: changed line 2 to line 9\n");
|
||||
line = 9;
|
||||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
printf("pci_map_int: pin %c mapped to line %d\n", '@' + pin, line);
|
||||
#endif
|
||||
|
||||
return isa_intr_establish(line, IST_LEVEL, level, func, arg);
|
||||
*ihp = line;
|
||||
return 0;
|
||||
#undef BAD
|
||||
}
|
||||
|
||||
const char *
|
||||
pci_intr_string(pc, ih)
|
||||
pci_chipset_tag_t pc;
|
||||
pci_intr_handle_t ih;
|
||||
{
|
||||
static char irqstr[8]; /* 4 + 2 + NULL + sanity */
|
||||
|
||||
if (ih == 0 || ih >= ICU_LEN || ih == 2)
|
||||
panic("pci_intr_string: bogus handle 0x%x\n", ih);
|
||||
|
||||
sprintf(irqstr, "irq %d", ih);
|
||||
return (irqstr);
|
||||
|
||||
}
|
||||
|
||||
void *
|
||||
pci_intr_establish(pc, ih, level, func, arg)
|
||||
pci_chipset_tag_t pc;
|
||||
pci_intr_handle_t ih;
|
||||
int level, (*func) __P((void *));
|
||||
void *arg;
|
||||
{
|
||||
|
||||
if (ih == 0 || ih >= ICU_LEN || ih == 2)
|
||||
panic("pci_intr_establish: bogus handle 0x%x\n", ih);
|
||||
|
||||
return isa_intr_establish(ih, IST_LEVEL, level, func, arg);
|
||||
}
|
||||
|
||||
void
|
||||
pci_intr_disestablish(pc, cookie)
|
||||
pci_chipset_tag_t pc;
|
||||
void *cookie;
|
||||
{
|
||||
|
||||
return isa_intr_disestablish(cookie);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* $NetBSD: pci_machdep.h,v 1.4 1996/03/14 02:37:59 cgd Exp $ */
|
||||
/* $NetBSD: pci_machdep.h,v 1.5 1996/03/27 04:01:16 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
|
||||
* Copyright (c) 1994 Charles Hannum. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -31,54 +32,63 @@
|
|||
|
||||
/*
|
||||
* Machine-specific definitions for PCI autoconfiguration.
|
||||
*
|
||||
* See the comments in pci_machdep.c for more explanation.
|
||||
*/
|
||||
|
||||
/*
|
||||
* i386-specific PCI structure and type definitions.
|
||||
* NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
|
||||
*
|
||||
* Configuration tag; created from a {bus,device,function} triplet by
|
||||
* pci_make_tag(), and passed to pci_conf_read() and pci_conf_write().
|
||||
* We could instead always pass the {bus,device,function} triplet to
|
||||
* the read and write routines, but this would cause extra overhead.
|
||||
*
|
||||
* Machines other than PCs are likely to use the equivalent of mode 1
|
||||
* tags always. Mode 2 is historical and deprecated by the Revision
|
||||
* 2.0 specification.
|
||||
* Mode 2 is historical and deprecated by the Revision 2.0 specification.
|
||||
*/
|
||||
typedef union {
|
||||
u_long mode1;
|
||||
union i386_pci_tag_u {
|
||||
u_int32_t mode1;
|
||||
struct {
|
||||
u_short port;
|
||||
u_char enable;
|
||||
u_char forward;
|
||||
u_int16_t port;
|
||||
u_int8_t enable;
|
||||
u_int8_t forward;
|
||||
} mode2;
|
||||
} pcitag_t;
|
||||
};
|
||||
|
||||
/*
|
||||
* Type of a value read from or written to a configuration register.
|
||||
* Always 32 bits.
|
||||
* Types provided to machine-independent PCI code
|
||||
*/
|
||||
typedef u_int32_t pcireg_t;
|
||||
typedef void *pci_chipset_tag_t;
|
||||
typedef union i386_pci_tag_u pcitag_t;
|
||||
typedef int pci_intr_handle_t;
|
||||
|
||||
/*
|
||||
* PCs which use Configuration Mechanism #2 are limited to 16
|
||||
* devices per bus.
|
||||
*/
|
||||
#define PCI_MAX_DEVICE_NUMBER (pci_mode == 2 ? 16 : 32)
|
||||
|
||||
/*
|
||||
* Hook for PCI bus attach function to do any necessary machine-specific
|
||||
* operations.
|
||||
*/
|
||||
|
||||
#define pci_md_attach_hook(parent, sc, pba) \
|
||||
do { \
|
||||
if (pba->pba_bus == 0) \
|
||||
printf(": configuration mode %d", pci_mode); \
|
||||
} while (0);
|
||||
|
||||
/*
|
||||
* Miscellaneous variables and functions.
|
||||
* i386-specific PCI variables and functions.
|
||||
* NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
|
||||
*/
|
||||
extern int pci_mode;
|
||||
extern int pci_mode_detect __P((void));
|
||||
int pci_mode_detect __P((void));
|
||||
|
||||
/*
|
||||
* Functions provided to machine-independent PCI code.
|
||||
*/
|
||||
void pci_attach_hook __P((struct device *, struct device *,
|
||||
struct pcibus_attach_args *));
|
||||
int pci_bus_maxdevs __P((pci_chipset_tag_t, int));
|
||||
pcitag_t pci_make_tag __P((pci_chipset_tag_t, int, int, int));
|
||||
pcireg_t pci_conf_read __P((pci_chipset_tag_t, pcitag_t, int));
|
||||
void pci_conf_write __P((pci_chipset_tag_t, pcitag_t, int,
|
||||
pcireg_t));
|
||||
int pci_intr_map __P((pci_chipset_tag_t, pcitag_t, int, int,
|
||||
pci_intr_handle_t *));
|
||||
const char *pci_intr_string __P((pci_chipset_tag_t, pci_intr_handle_t));
|
||||
void *pci_intr_establish __P((pci_chipset_tag_t, pci_intr_handle_t,
|
||||
int, int (*)(void *), void *));
|
||||
void pci_intr_disestablish __P((pci_chipset_tag_t, void *));
|
||||
|
||||
/*
|
||||
* Compatibility functions, to map the old i386 PCI functions to the new ones.
|
||||
* NOT TO BE USED BY NEW CODE.
|
||||
*/
|
||||
void *pci_map_int __P((pcitag_t, int, int (*)(void *), void *));
|
||||
int pci_map_io __P((pcitag_t, int, int *));
|
||||
int pci_map_mem __P((pcitag_t, int, vm_offset_t *, vm_offset_t *));
|
||||
|
|
Loading…
Reference in New Issue