1995-11-23 05:33:17 +03:00
|
|
|
/* $NetBSD: apecs_pci.c,v 1.4 1995/11/23 02:37:16 cgd Exp $ */
|
1995-06-28 05:24:50 +04:00
|
|
|
|
|
|
|
/*
|
1995-08-03 05:12:15 +04:00
|
|
|
* Copyright (c) 1995 Carnegie-Mellon University.
|
1995-06-28 05:24:50 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Chris G. Demetriou
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this software and
|
|
|
|
* its documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <vm/vm.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <alpha/pci/apecsreg.h>
|
1995-11-23 05:33:17 +03:00
|
|
|
#include <alpha/pci/apecsvar.h>
|
1995-06-28 05:24:50 +04:00
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
pci_confreg_t apecs_conf_read __P((void *, pci_conftag_t, pci_confoffset_t));
|
|
|
|
void apecs_conf_write __P((void *, pci_conftag_t,
|
|
|
|
pci_confoffset_t, pci_confreg_t));
|
|
|
|
int apecs_find_io __P((void *, pci_conftag_t,
|
|
|
|
pci_confoffset_t, pci_iooffset_t *, pci_iosize_t *));
|
|
|
|
int apecs_find_mem __P((void *, pci_conftag_t,
|
|
|
|
pci_confoffset_t, pci_moffset_t *, pci_msize_t *, int *));
|
1995-06-28 05:24:50 +04:00
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
__const struct pci_conf_fns apecs_conf_fns = {
|
1995-06-28 05:24:50 +04:00
|
|
|
apecs_conf_read,
|
|
|
|
apecs_conf_write,
|
1995-11-23 05:33:17 +03:00
|
|
|
apecs_find_io,
|
|
|
|
apecs_find_mem,
|
1995-06-28 05:24:50 +04:00
|
|
|
};
|
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
pci_confreg_t
|
|
|
|
apecs_conf_read(cpv, tag, offset)
|
|
|
|
void *cpv;
|
|
|
|
pci_conftag_t tag;
|
|
|
|
pci_confoffset_t offset;
|
1995-06-28 05:24:50 +04:00
|
|
|
{
|
1995-11-23 05:33:17 +03:00
|
|
|
struct apecs_config *acp = cpv;
|
|
|
|
pci_confreg_t *datap, data;
|
|
|
|
int s, secondary, ba;
|
|
|
|
int32_t old_haxr2; /* XXX */
|
|
|
|
|
|
|
|
secondary = PCI_TAG_BUS(tag) != 0;
|
|
|
|
if (secondary) {
|
|
|
|
s = splhigh();
|
|
|
|
old_haxr2 = REGVAL(EPIC_HAXR2);
|
|
|
|
wbflush();
|
|
|
|
REGVAL(EPIC_HAXR2) = old_haxr2 | 0x1;
|
|
|
|
wbflush();
|
|
|
|
}
|
1995-06-28 05:24:50 +04:00
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
datap = (pci_confreg_t *)phystok0seg(APECS_PCI_CONF |
|
|
|
|
tag << 5UL | /* XXX */
|
|
|
|
(offset & ~0x03) << 5 | /* XXX */
|
|
|
|
0 << 5 | /* XXX */
|
|
|
|
0x3 << 3); /* XXX */
|
|
|
|
data = (pci_confreg_t)-1;
|
|
|
|
if (!(ba = badaddr(datap, sizeof *datap)))
|
|
|
|
data = *datap;
|
|
|
|
|
|
|
|
if (secondary) {
|
|
|
|
wbflush();
|
|
|
|
REGVAL(EPIC_HAXR2) = old_haxr2;
|
|
|
|
wbflush();
|
|
|
|
splx(s);
|
1995-06-28 05:24:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
1995-11-23 05:33:17 +03:00
|
|
|
printf("apecs_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg,
|
|
|
|
data, datap, ba ? " (badaddr)" : "");
|
1995-06-28 05:24:50 +04:00
|
|
|
#endif
|
1995-11-23 05:33:17 +03:00
|
|
|
|
1995-06-28 05:24:50 +04:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1995-11-23 05:33:17 +03:00
|
|
|
apecs_conf_write(cpv, tag, offset, data)
|
|
|
|
void *cpv;
|
|
|
|
pci_conftag_t tag;
|
|
|
|
pci_confoffset_t offset;
|
|
|
|
pci_confreg_t data;
|
1995-06-28 05:24:50 +04:00
|
|
|
{
|
1995-11-23 05:33:17 +03:00
|
|
|
struct apecs_config *acp = cpv;
|
|
|
|
pci_confreg_t *datap;
|
|
|
|
int s, secondary;
|
|
|
|
int32_t old_haxr2; /* XXX */
|
|
|
|
|
|
|
|
secondary = PCI_TAG_BUS(tag) != 0;
|
|
|
|
if (secondary) {
|
|
|
|
s = splhigh();
|
|
|
|
old_haxr2 = REGVAL(EPIC_HAXR2);
|
|
|
|
wbflush();
|
|
|
|
REGVAL(EPIC_HAXR2) = old_haxr2 | 0x1;
|
|
|
|
wbflush();
|
|
|
|
}
|
1995-06-28 05:24:50 +04:00
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
datap = (pci_confreg_t *)phystok0seg(APECS_PCI_CONF |
|
|
|
|
tag << 5UL | /* XXX */
|
|
|
|
(offset & ~0x03) << 5 | /* XXX */
|
|
|
|
0 << 5 | /* XXX */
|
|
|
|
0x3 << 3); /* XXX */
|
|
|
|
*datap = data;
|
|
|
|
|
|
|
|
if (secondary) {
|
|
|
|
wbflush();
|
|
|
|
REGVAL(EPIC_HAXR2) = old_haxr2;
|
|
|
|
wbflush();
|
|
|
|
splx(s);
|
1995-06-28 05:24:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
printf("apecs_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag,
|
|
|
|
reg, data, datap);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1995-08-03 04:42:25 +04:00
|
|
|
int
|
1995-11-23 05:33:17 +03:00
|
|
|
apecs_find_io(cpv, tag, reg, iobasep, sizep)
|
|
|
|
void *cpv;
|
|
|
|
pci_conftag_t tag;
|
|
|
|
pci_confoffset_t reg;
|
|
|
|
pci_iooffset_t *iobasep;
|
|
|
|
pci_iosize_t *sizep;
|
1995-08-03 04:42:25 +04:00
|
|
|
{
|
1995-11-23 05:33:17 +03:00
|
|
|
struct apecs_config *acp = cpv;
|
|
|
|
pci_confreg_t addrdata, sizedata;
|
|
|
|
pci_iooffset_t pci_iobase;
|
1995-08-03 04:42:25 +04:00
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
if (reg < PCI_MAPREG_START || reg >= PCI_MAPREG_END || (reg & 3))
|
1995-08-03 04:42:25 +04:00
|
|
|
panic("apecs_map_io: bad request");
|
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
addrdata = PCI_CONF_READ(acp->ac_conffns, acp->ac_confarg, tag, reg);
|
1995-06-28 05:24:50 +04:00
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
PCI_CONF_WRITE(acp->ac_conffns, acp->ac_confarg, tag, reg, 0xffffffff);
|
|
|
|
sizedata = PCI_CONF_READ(acp->ac_conffns, acp->ac_confarg, tag, reg);
|
|
|
|
PCI_CONF_WRITE(acp->ac_conffns, acp->ac_confarg, tag, reg, addrdata);
|
|
|
|
|
|
|
|
if (PCI_MAPREG_TYPE(addrdata) == PCI_MAPREG_TYPE_MEM)
|
1995-08-03 04:42:25 +04:00
|
|
|
panic("apecs_map_io: attempt to I/O map an memory region");
|
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
if (iobasep != NULL)
|
|
|
|
*iobasep = PCI_MAPREG_IO_ADDRESS(addrdata);
|
|
|
|
if (sizep != NULL)
|
|
|
|
*sizep = ~PCI_MAPREG_IO_ADDRESS(sizedata) + 1;
|
1995-08-03 04:42:25 +04:00
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
return (0);
|
1995-08-03 04:42:25 +04:00
|
|
|
}
|
1995-06-28 05:24:50 +04:00
|
|
|
|
|
|
|
int
|
1995-11-23 05:33:17 +03:00
|
|
|
apecs_find_mem(cpv, tag, reg, paddrp, sizep, cacheablep)
|
|
|
|
void *cpv;
|
|
|
|
pci_conftag_t tag;
|
|
|
|
pci_confoffset_t reg;
|
|
|
|
pci_moffset_t *paddrp;
|
|
|
|
pci_msize_t *sizep;
|
|
|
|
int *cacheablep;
|
1995-06-28 05:24:50 +04:00
|
|
|
{
|
1995-11-23 05:33:17 +03:00
|
|
|
struct apecs_config *acp = cpv;
|
|
|
|
pci_confreg_t addrdata, sizedata;
|
1995-06-28 05:24:50 +04:00
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
if (reg < PCI_MAPREG_START || reg >= PCI_MAPREG_END || (reg & 3))
|
1995-06-28 05:24:50 +04:00
|
|
|
panic("apecs_map_mem: bad request");
|
|
|
|
|
|
|
|
/*
|
1995-11-23 05:33:17 +03:00
|
|
|
* The PROM has mapped the device for us. We take the address
|
|
|
|
* that's been assigned to the register, and figure out what
|
|
|
|
* physical and virtual addresses go with it...
|
1995-06-28 05:24:50 +04:00
|
|
|
*/
|
1995-11-23 05:33:17 +03:00
|
|
|
addrdata = PCI_CONF_READ(acp->ac_conffns, acp->ac_confarg, tag, reg);
|
|
|
|
|
|
|
|
PCI_CONF_WRITE(acp->ac_conffns, acp->ac_confarg, tag, reg, 0xffffffff);
|
|
|
|
sizedata = PCI_CONF_READ(acp->ac_conffns, acp->ac_confarg, tag, reg);
|
|
|
|
PCI_CONF_WRITE(acp->ac_conffns, acp->ac_confarg, tag, reg, addrdata);
|
1995-06-28 05:24:50 +04:00
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
if (PCI_MAPREG_TYPE(addrdata) == PCI_MAPREG_TYPE_IO)
|
1995-06-28 05:24:50 +04:00
|
|
|
panic("apecs_map_mem: attempt to memory map an I/O region");
|
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
switch (PCI_MAPREG_MEM_TYPE(addrdata)) {
|
|
|
|
case PCI_MAPREG_MEM_TYPE_32BIT:
|
|
|
|
case PCI_MAPREG_MEM_TYPE_32BIT_1M:
|
1995-06-28 05:24:50 +04:00
|
|
|
break;
|
1995-11-23 05:33:17 +03:00
|
|
|
case PCI_MAPREG_MEM_TYPE_64BIT:
|
|
|
|
/* XXX */ printf("apecs_map_mem: attempt to map 64-bit region\n");
|
|
|
|
/* XXX */ break;
|
1995-06-28 05:24:50 +04:00
|
|
|
default:
|
|
|
|
printf("apecs_map_mem: reserved mapping type\n");
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
if (paddrp != NULL)
|
|
|
|
*paddrp = PCI_MAPREG_MEM_ADDRESS(addrdata); /* PCI addr */
|
|
|
|
if (sizep != NULL)
|
|
|
|
*sizep = ~PCI_MAPREG_MEM_ADDRESS(sizedata) + 1;
|
|
|
|
if (cacheablep != NULL)
|
|
|
|
*cacheablep = PCI_MAPREG_MEM_CACHEABLE(addrdata);
|
1995-06-28 05:24:50 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|