Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci Allow this file to be used in userspace, as well.
details: https://anonhg.NetBSD.org/src/rev/a0afa26de655
branches: trunk
changeset: 514910:a0afa26de655
user: thorpej <thorpej%NetBSD.org@localhost>
date: Thu Sep 13 21:42:57 2001 +0000
description:
Allow this file to be used in userspace, as well.
diffstat:
sys/dev/pci/pci_subr.c | 156 +++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 132 insertions(+), 24 deletions(-)
diffs (truncated from 347 to 300 lines):
diff -r fd8180814c88 -r a0afa26de655 sys/dev/pci/pci_subr.c
--- a/sys/dev/pci/pci_subr.c Thu Sep 13 21:41:01 2001 +0000
+++ b/sys/dev/pci/pci_subr.c Thu Sep 13 21:42:57 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_subr.c,v 1.44 2001/09/13 18:25:45 thorpej Exp $ */
+/* $NetBSD: pci_subr.c,v 1.45 2001/09/13 21:42:57 thorpej Exp $ */
/*
* Copyright (c) 1997 Zubin D. Dittia. All rights reserved.
@@ -34,18 +34,28 @@
/*
* PCI autoconfiguration support functions.
+ *
+ * Note: This file is also built into a userland library (libpci).
+ * Pay attention to this when you make modifications.
*/
+#ifdef _KERNEL_OPT
#include "opt_pci.h"
+#endif
#include <sys/param.h>
#include <sys/systm.h>
-#include <sys/device.h>
+#ifdef _KERNEL
#include <machine/intr.h>
+#else
+#include <pci.h>
+#endif
#include <dev/pci/pcireg.h>
+#ifdef _KERNEL
#include <dev/pci/pcivar.h>
+#endif
#ifdef PCIVERBOSE
#include <dev/pci/pcidevs.h>
#endif
@@ -407,7 +417,11 @@
printf(" %s: %s\n", (str), (rval & (bit)) ? "on" : "off");
static void
-pci_conf_print_common(pci_chipset_tag_t pc, pcitag_t tag, const pcireg_t *regs)
+pci_conf_print_common(
+#ifdef _KERNEL
+ pci_chipset_tag_t pc, pcitag_t tag,
+#endif
+ const pcireg_t *regs)
{
#ifdef PCIVERBOSE
const struct pci_knowndev *kdp;
@@ -519,13 +533,23 @@
}
static int
-pci_conf_print_bar(pci_chipset_tag_t pc, pcitag_t tag, const pcireg_t *regs,
- int reg, const char *name, int sizebar)
+pci_conf_print_bar(
+#ifdef _KERNEL
+ pci_chipset_tag_t pc, pcitag_t tag,
+#endif
+ const pcireg_t *regs, int reg, const char *name
+#ifdef _KERNEL
+ , int sizebar
+#endif
+ )
{
- int s, width;
- pcireg_t mask, rval;
- pcireg_t mask64h, rval64h;
-
+ int width;
+ pcireg_t rval, rval64h;
+#ifdef _KERNEL
+ int s;
+ pcireg_t mask, mask64h;
+#endif
+
width = 4;
/*
@@ -538,7 +562,16 @@
* the bottom n bits of the address to 0. As recommended,
* we write all 1s and see what we get back.
*/
+
rval = regs[o2i(reg)];
+ if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM &&
+ PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) {
+ rval64h = regs[o2i(reg + 4)];
+ width = 8;
+ } else
+ rval64h = 0;
+
+#ifdef _KERNEL
/* XXX don't size unknown memory type? */
if (rval != 0 && sizebar) {
/*
@@ -556,15 +589,14 @@
pci_conf_write(pc, tag, reg, rval);
if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM &&
PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) {
- rval64h = regs[o2i(reg + 4)];
pci_conf_write(pc, tag, reg + 4, 0xffffffff);
mask64h = pci_conf_read(pc, tag, reg + 4);
pci_conf_write(pc, tag, reg + 4, rval64h);
- width = 8;
}
splx(s);
} else
mask = 0;
+#endif /* _KERNEL */
printf(" Base address register at 0x%02x", reg);
if (name)
@@ -602,11 +634,13 @@
printf(" base: 0x%016llx, ",
PCI_MAPREG_MEM64_ADDR(
((((long long) rval64h) << 32) | rval)));
+#ifdef _KERNEL
if (sizebar)
printf("size: 0x%016llx",
PCI_MAPREG_MEM64_SIZE(
((((long long) mask64h) << 32) | mask)));
else
+#endif /* _KERNEL */
printf("not sized");
printf("\n");
break;
@@ -615,22 +649,28 @@
default:
printf(" base: 0x%08x, ",
PCI_MAPREG_MEM_ADDR(rval));
+#ifdef _KERNEL
if (sizebar)
printf("size: 0x%08x",
PCI_MAPREG_MEM_SIZE(mask));
else
+#endif /* _KERNEL */
printf("not sized");
printf("\n");
break;
}
} else {
+#ifdef _KERNEL
if (sizebar)
printf("%d-bit ", mask & ~0x0000ffff ? 32 : 16);
+#endif /* _KERNEL */
printf("i/o\n");
printf(" base: 0x%08x, ", PCI_MAPREG_IO_ADDR(rval));
+#ifdef _KERNEL
if (sizebar)
printf("size: 0x%08x", PCI_MAPREG_IO_SIZE(mask));
else
+#endif /* _KERNEL */
printf("not sized");
printf("\n");
}
@@ -662,14 +702,26 @@
}
static void
-pci_conf_print_type0(pci_chipset_tag_t pc, pcitag_t tag, const pcireg_t *regs,
- int sizebars)
+pci_conf_print_type0(
+#ifdef _KERNEL
+ pci_chipset_tag_t pc, pcitag_t tag,
+#endif
+ const pcireg_t *regs
+#ifdef _KERNEL
+ , int sizebars
+#endif
+ )
{
int off, width;
pcireg_t rval;
- for (off = PCI_MAPREG_START; off < PCI_MAPREG_END; off += width)
+ for (off = PCI_MAPREG_START; off < PCI_MAPREG_END; off += width) {
+#ifdef _KERNEL
width = pci_conf_print_bar(pc, tag, regs, off, NULL, sizebars);
+#else
+ width = pci_conf_print_bar(regs, off, NULL);
+#endif
+ }
printf(" Cardbus CIS Pointer: 0x%08x\n", regs[o2i(0x28)]);
@@ -775,8 +827,15 @@
}
static void
-pci_conf_print_type1(pci_chipset_tag_t pc, pcitag_t tag, const pcireg_t *regs,
- int sizebars)
+pci_conf_print_type1(
+#ifdef _KERNEL
+ pci_chipset_tag_t pc, pcitag_t tag,
+#endif
+ const pcireg_t *regs
+#ifdef _KERNEL
+ , int sizebars
+#endif
+ )
{
int off, width;
pcireg_t rval;
@@ -790,8 +849,13 @@
* respect to various standards. (XXX)
*/
- for (off = 0x10; off < 0x18; off += width)
+ for (off = 0x10; off < 0x18; off += width) {
+#ifdef _KERNEL
width = pci_conf_print_bar(pc, tag, regs, off, NULL, sizebars);
+#else
+ width = pci_conf_print_bar(regs, off, NULL);
+#endif
+ }
printf(" Primary bus number: 0x%02x\n",
(regs[o2i(0x18)] >> 0) & 0xff);
@@ -898,8 +962,15 @@
}
static void
-pci_conf_print_type2(pci_chipset_tag_t pc, pcitag_t tag, const pcireg_t *regs,
- int sizebars)
+pci_conf_print_type2(
+#ifdef _KERNEL
+ pci_chipset_tag_t pc, pcitag_t tag,
+#endif
+ const pcireg_t *regs
+#ifdef _KERNEL
+ , int sizebars
+#endif
+ )
{
pcireg_t rval;
@@ -912,8 +983,12 @@
* respect to various standards. (XXX)
*/
+#ifdef _KERNEL
pci_conf_print_bar(pc, tag, regs, 0x10,
"CardBus socket/ExCA registers", sizebars);
+#else
+ pci_conf_print_bar(regs, 0x10, "CardBus socket/ExCA registers");
+#endif
printf(" Reserved @ 0x14: 0x%04x\n",
(regs[o2i(0x14)] >> 0) & 0xffff);
@@ -1014,36 +1089,63 @@
printf(" Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval));
printf(" Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval));
+#ifdef _KERNEL
pci_conf_print_bar(pc, tag, regs, 0x44, "legacy-mode registers",
sizebars);
+#else
+ pci_conf_print_bar(regs, 0x44, "legacy-mode registers");
+#endif
}
void
-pci_conf_print(pci_chipset_tag_t pc, pcitag_t tag,
- void (*printfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *))
+pci_conf_print(
+#ifdef _KERNEL
+ pci_chipset_tag_t pc, pcitag_t tag,
+ void (*printfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *)
+#else
+ int pcifd, u_int bus, u_int dev, u_int func
+#endif
+ )
{
pcireg_t regs[o2i(256)];
int off, endoff, hdrtype;
const char *typename;
+#ifdef _KERNEL
void (*typeprintfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *, int);
int sizebars;
+#else
+ void (*typeprintfn)(const pcireg_t *);
+#endif
printf("PCI configuration registers:\n");
- for (off = 0; off < 256; off += 4)
+ for (off = 0; off < 256; off += 4) {
+#ifdef _KERNEL
regs[o2i(off)] = pci_conf_read(pc, tag, off);
+#else
+ if (pcibus_conf_read(pcifd, bus, dev, func, off,
+ ®s[o2i(off)]) == -1)
+ regs[o2i(off)] = 0;
+#endif
+ }
Home |
Main Index |
Thread Index |
Old Index