summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2002-08-31 18:38:43 +0000
committerphk <phk@FreeBSD.org>2002-08-31 18:38:43 +0000
commitedb326987a5bb0cfd6fa035f67e4a1ae144d17f8 (patch)
tree0809b3ca64dfcae9b798e20a8fee0f253effc70d /sys
parent480c5ff48a7e64b7c4abfd66f91740ed53f078b9 (diff)
downloadFreeBSD-src-edb326987a5bb0cfd6fa035f67e4a1ae144d17f8.zip
FreeBSD-src-edb326987a5bb0cfd6fa035f67e4a1ae144d17f8.tar.gz
Split the puc driver in pci specific and generic parts.
Add a pccard frontend for it as well. The PCcard stuff does not work yet because there is still some PCImagic left in puc.c
Diffstat (limited to 'sys')
-rw-r--r--sys/conf/files4
-rw-r--r--sys/dev/puc/puc.c114
-rw-r--r--sys/dev/puc/puc_pccard.c106
-rw-r--r--sys/dev/puc/puc_pci.c139
-rw-r--r--sys/dev/puc/pucvar.h38
5 files changed, 302 insertions, 99 deletions
diff --git a/sys/conf/files b/sys/conf/files
index 1f3e83a..2f86cec 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -526,7 +526,9 @@ dev/ppbus/ppi.c optional ppi
dev/ppbus/pps.c optional pps
dev/ppbus/vpo.c optional vpo
dev/ppbus/vpoio.c optional vpo
-dev/puc/puc.c optional puc pci
+dev/puc/puc.c optional puc
+dev/puc/puc_pci.c optional puc pci
+dev/puc/puc_pccard.c optional puc pccard
dev/puc/pucdata.c optional puc pci
dev/random/harvest.c standard
dev/random/randomdev.c optional random
diff --git a/sys/dev/puc/puc.c b/sys/dev/puc/puc.c
index f3a21f3..764c0c7c 100644
--- a/sys/dev/puc/puc.c
+++ b/sys/dev/puc/puc.c
@@ -1,3 +1,4 @@
+#define PUC_DEBUG
/* $NetBSD: puc.c,v 1.7 2000/07/29 17:43:38 jlam Exp $ */
/*-
@@ -94,54 +95,20 @@ __FBSDID("$FreeBSD$");
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
+
+#define PUC_ENTRAILS 1
#include <dev/puc/pucvar.h>
#include <opt_puc.h>
-struct puc_softc {
- const struct puc_device_description *sc_desc;
-
- /* card-global dynamic data */
- int barmuxed;
- int irqrid;
- struct resource *irqres;
- void *intr_cookie;
-
- struct {
- struct resource *res;
- } sc_bar_mappings[PUC_MAX_BAR];
-
- /* per-port dynamic data */
- struct {
- struct device *dev;
- /* filled in by bus_setup_intr() */
- void (*ihand)(void *);
- void *ihandarg;
- } sc_ports[PUC_MAX_PORTS];
-};
struct puc_device {
struct resource_list resources;
u_int serialfreq;
};
-static int puc_pci_probe(device_t dev);
-static int puc_pci_attach(device_t dev);
static void puc_intr(void *arg);
-static struct resource *puc_alloc_resource(device_t, device_t, int, int *,
- u_long, u_long, u_long, u_int);
-static int puc_release_resource(device_t, device_t, int, int,
- struct resource *);
-static int puc_get_resource(device_t, device_t, int, int, u_long *, u_long *);
-static int puc_setup_intr(device_t, device_t, struct resource *, int,
- void (*)(void *), void *, void **);
-static int puc_teardown_intr(device_t, device_t, struct resource *,
- void *);
-static int puc_read_ivar(device_t, device_t, int, uintptr_t *);
-
-static const struct puc_device_description *puc_find_description(uint32_t,
- uint32_t, uint32_t, uint32_t);
static void puc_config_superio(device_t);
static void puc_config_win877(struct resource *);
static int puc_find_free_unit(char *);
@@ -151,33 +118,11 @@ static void puc_print_win877(bus_space_tag_t, bus_space_handle_t, u_int,
static void puc_print_resource_list(struct resource_list *);
#endif
-static int
-puc_pci_probe(device_t dev)
-{
- uint32_t v1, v2, d1, d2;
- const struct puc_device_description *desc;
-
- if ((pci_read_config(dev, PCIR_HEADERTYPE, 1) & 0x7f) != 0)
- return (ENXIO);
-
- v1 = pci_read_config(dev, PCIR_VENDOR, 2);
- d1 = pci_read_config(dev, PCIR_DEVICE, 2);
- v2 = pci_read_config(dev, PCIR_SUBVEND_0, 2);
- d2 = pci_read_config(dev, PCIR_SUBDEV_0, 2);
-
- desc = puc_find_description(v1, d1, v2, d2);
- if (desc == NULL)
- return (ENXIO);
- device_set_desc(dev, desc->name);
- return (0);
-}
-
-static int
-puc_pci_attach(device_t dev)
+int
+puc_attach(device_t dev, const struct puc_device_description *desc)
{
char *typestr;
int bidx, childunit, i, irq_setup, rid;
- uint32_t v1, v2, d1, d2;
struct puc_softc *sc;
struct puc_device *pdev;
struct resource *res;
@@ -185,11 +130,8 @@ puc_pci_attach(device_t dev)
sc = (struct puc_softc *)device_get_softc(dev);
bzero(sc, sizeof(*sc));
- v1 = pci_read_config(dev, PCIR_VENDOR, 2);
- d1 = pci_read_config(dev, PCIR_DEVICE, 2);
- v2 = pci_read_config(dev, PCIR_SUBVEND_0, 2);
- d2 = pci_read_config(dev, PCIR_SUBDEV_0, 2);
- sc->sc_desc = puc_find_description(v1, d1, v2, d2);
+ sc->sc_desc = desc;
+
if (sc->sc_desc == NULL)
return (ENXIO);
@@ -320,7 +262,7 @@ puc_pci_attach(device_t dev)
sc->sc_desc->ports[i].type,
sc->sc_desc->ports[i].bar,
sc->sc_desc->ports[i].offset);
- print_resource_list(&pdev->resources);
+ puc_print_resource_list(&pdev->resources);
#endif
if (device_probe_and_attach(sc->sc_ports[i].dev) != 0) {
if (sc->barmuxed) {
@@ -358,7 +300,7 @@ puc_intr(void *arg)
(sc->sc_ports[i].ihand)(sc->sc_ports[i].ihandarg);
}
-static const struct puc_device_description *
+const struct puc_device_description *
puc_find_description(uint32_t vend, uint32_t prod, uint32_t svend,
uint32_t sprod)
{
@@ -550,7 +492,7 @@ puc_print_resource_list(struct resource_list *rl)
}
#endif
-static struct resource *
+struct resource *
puc_alloc_resource(device_t dev, device_t child, int type, int *rid,
u_long start, u_long end, u_long count, u_int flags)
{
@@ -583,14 +525,14 @@ puc_alloc_resource(device_t dev, device_t child, int type, int *rid,
return (retval);
}
-static int
+int
puc_release_resource(device_t dev, device_t child, int type, int rid,
struct resource *res)
{
return (0);
}
-static int
+int
puc_get_resource(device_t dev, device_t child, int type, int rid,
u_long *startp, u_long *countp)
{
@@ -624,7 +566,7 @@ puc_get_resource(device_t dev, device_t child, int type, int rid,
return (ENXIO);
}
-static int
+int
puc_setup_intr(device_t dev, device_t child, struct resource *r, int flags,
void (*ihand)(void *), void *arg, void **cookiep)
{
@@ -645,7 +587,7 @@ puc_setup_intr(device_t dev, device_t child, struct resource *r, int flags,
return (ENXIO);
}
-static int
+int
puc_teardown_intr(device_t dev, device_t child, struct resource *r,
void *cookie)
{
@@ -663,7 +605,7 @@ puc_teardown_intr(device_t dev, device_t child, struct resource *r,
return (ENXIO);
}
-static int
+int
puc_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
{
struct puc_device *pdev;
@@ -682,29 +624,5 @@ puc_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
return (0);
}
-static device_method_t puc_pci_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, puc_pci_probe),
- DEVMETHOD(device_attach, puc_pci_attach),
-
- DEVMETHOD(bus_alloc_resource, puc_alloc_resource),
- DEVMETHOD(bus_release_resource, puc_release_resource),
- DEVMETHOD(bus_get_resource, puc_get_resource),
- DEVMETHOD(bus_read_ivar, puc_read_ivar),
- DEVMETHOD(bus_setup_intr, puc_setup_intr),
- DEVMETHOD(bus_teardown_intr, puc_teardown_intr),
- DEVMETHOD(bus_print_child, bus_generic_print_child),
- DEVMETHOD(bus_driver_added, bus_generic_driver_added),
- { 0, 0 }
-};
-
-static driver_t puc_pci_driver = {
- "puc",
- puc_pci_methods,
- sizeof(struct puc_softc),
-};
-
-static devclass_t puc_devclass;
+devclass_t puc_devclass;
-DRIVER_MODULE(puc, pci, puc_pci_driver, puc_devclass, 0, 0);
-DRIVER_MODULE(puc, cardbus, puc_pci_driver, puc_devclass, 0, 0);
diff --git a/sys/dev/puc/puc_pccard.c b/sys/dev/puc/puc_pccard.c
new file mode 100644
index 0000000..ede1a76
--- /dev/null
+++ b/sys/dev/puc/puc_pccard.c
@@ -0,0 +1,106 @@
+/*-
+ * Copyright (c) 2002 Poul-Henning Kamp. 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 unmodified, 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.
+ *
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/malloc.h>
+
+#include <machine/bus.h>
+#include <machine/resource.h>
+#include <sys/rman.h>
+
+#define PUC_ENTRAILS 1
+#include <dev/puc/pucvar.h>
+
+#include <dev/pccard/pccardvar.h>
+
+#include <opt_puc.h>
+
+const struct puc_device_description rscom_devices = {
+
+ "RS-com 2 port",
+ { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 },
+ {
+ { PUC_PORT_TYPE_COM, 0x0, 0x00, 0 },
+ { PUC_PORT_TYPE_COM, 0x1, 0x00, 0 },
+ }
+};
+
+
+static int
+puc_pccard_probe(device_t dev)
+{
+ char *vendor, *product;
+ int error;
+
+ error = pccard_get_vendor_str(dev, &vendor);
+ if (error)
+ return(error);
+ error = pccard_get_product_str(dev, &product);
+ if (error)
+ return(error);
+ printf("puc_pccard_probe <%s><%s>\n", vendor, product);
+ if (!strcmp(vendor, "PCMCIA") && !strcmp(product, "RS-COM 2P"))
+ return (0);
+
+ return (ENXIO);
+}
+
+static int
+puc_pccard_attach(device_t dev)
+{
+
+ return (puc_attach(dev, &rscom_devices));
+}
+
+static device_method_t puc_pccard_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, puc_pccard_probe),
+ DEVMETHOD(device_attach, puc_pccard_attach),
+
+ DEVMETHOD(bus_alloc_resource, puc_alloc_resource),
+ DEVMETHOD(bus_release_resource, puc_release_resource),
+ DEVMETHOD(bus_get_resource, puc_get_resource),
+ DEVMETHOD(bus_read_ivar, puc_read_ivar),
+ DEVMETHOD(bus_setup_intr, puc_setup_intr),
+ DEVMETHOD(bus_teardown_intr, puc_teardown_intr),
+ DEVMETHOD(bus_print_child, bus_generic_print_child),
+ DEVMETHOD(bus_driver_added, bus_generic_driver_added),
+ { 0, 0 }
+};
+
+static driver_t puc_pccard_driver = {
+ "puc",
+ puc_pccard_methods,
+ sizeof(struct puc_softc),
+};
+
+DRIVER_MODULE(puc, pccard, puc_pccard_driver, puc_devclass, 0, 0);
diff --git a/sys/dev/puc/puc_pci.c b/sys/dev/puc/puc_pci.c
new file mode 100644
index 0000000..711bd8c
--- /dev/null
+++ b/sys/dev/puc/puc_pci.c
@@ -0,0 +1,139 @@
+#define PUC_DEBUG
+/* $NetBSD: puc.c,v 1.7 2000/07/29 17:43:38 jlam Exp $ */
+
+/*-
+ * Copyright (c) 2002 JF Hay. All rights reserved.
+ * Copyright (c) 2000 M. Warner Losh. 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 unmodified, 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.
+ *
+ * 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.
+ */
+
+/*
+ * Copyright (c) 1996, 1998, 1999
+ * Christopher G. Demetriou. 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 Christopher G. Demetriou
+ * for the NetBSD Project.
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/malloc.h>
+
+#include <machine/bus.h>
+#include <machine/resource.h>
+#include <sys/rman.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+
+#define PUC_ENTRAILS 1
+#include <dev/puc/pucvar.h>
+
+#include <opt_puc.h>
+
+static int
+puc_pci_probe(device_t dev)
+{
+ uint32_t v1, v2, d1, d2;
+ const struct puc_device_description *desc;
+
+ if ((pci_read_config(dev, PCIR_HEADERTYPE, 1) & 0x7f) != 0)
+ return (ENXIO);
+
+ v1 = pci_read_config(dev, PCIR_VENDOR, 2);
+ d1 = pci_read_config(dev, PCIR_DEVICE, 2);
+ v2 = pci_read_config(dev, PCIR_SUBVEND_0, 2);
+ d2 = pci_read_config(dev, PCIR_SUBDEV_0, 2);
+
+ desc = puc_find_description(v1, d1, v2, d2);
+ if (desc == NULL)
+ return (ENXIO);
+ device_set_desc(dev, desc->name);
+ return (0);
+}
+
+static int
+puc_pci_attach(device_t dev)
+{
+ uint32_t v1, v2, d1, d2;
+
+ v1 = pci_read_config(dev, PCIR_VENDOR, 2);
+ d1 = pci_read_config(dev, PCIR_DEVICE, 2);
+ v2 = pci_read_config(dev, PCIR_SUBVEND_0, 2);
+ d2 = pci_read_config(dev, PCIR_SUBDEV_0, 2);
+ return (puc_attach(dev, puc_find_description(v1, d1, v2, d2)));
+}
+
+static device_method_t puc_pci_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, puc_pci_probe),
+ DEVMETHOD(device_attach, puc_pci_attach),
+
+ DEVMETHOD(bus_alloc_resource, puc_alloc_resource),
+ DEVMETHOD(bus_release_resource, puc_release_resource),
+ DEVMETHOD(bus_get_resource, puc_get_resource),
+ DEVMETHOD(bus_read_ivar, puc_read_ivar),
+ DEVMETHOD(bus_setup_intr, puc_setup_intr),
+ DEVMETHOD(bus_teardown_intr, puc_teardown_intr),
+ DEVMETHOD(bus_print_child, bus_generic_print_child),
+ DEVMETHOD(bus_driver_added, bus_generic_driver_added),
+ { 0, 0 }
+};
+
+static driver_t puc_pci_driver = {
+ "puc",
+ puc_pci_methods,
+ sizeof(struct puc_softc),
+};
+
+DRIVER_MODULE(puc, pci, puc_pci_driver, puc_devclass, 0, 0);
+DRIVER_MODULE(puc, cardbus, puc_pci_driver, puc_devclass, 0, 0);
diff --git a/sys/dev/puc/pucvar.h b/sys/dev/puc/pucvar.h
index 4dd68cc..441bb09 100644
--- a/sys/dev/puc/pucvar.h
+++ b/sys/dev/puc/pucvar.h
@@ -97,4 +97,42 @@ enum puc_device_ivars {
PUC_IVAR_FREQ
};
+#ifdef PUC_ENTRAILS
+int puc_attach(device_t dev, const struct puc_device_description *desc);
+extern devclass_t puc_devclass;
+struct resource *puc_alloc_resource(device_t, device_t, int, int *,
+ u_long, u_long, u_long, u_int);
+int puc_release_resource(device_t, device_t, int, int, struct resource *);
+int puc_get_resource(device_t, device_t, int, int, u_long *, u_long *);
+int puc_read_ivar(device_t, device_t, int, uintptr_t *);
+int puc_setup_intr(device_t, device_t, struct resource *, int,
+ void (*)(void *), void *, void **);
+int puc_teardown_intr(device_t, device_t, struct resource *,
+ void *);
+const struct puc_device_description *puc_find_description(uint32_t,
+ uint32_t, uint32_t, uint32_t);
+
+struct puc_softc {
+ const struct puc_device_description *sc_desc;
+
+ /* card-global dynamic data */
+ int barmuxed;
+ int irqrid;
+ struct resource *irqres;
+ void *intr_cookie;
+
+ struct {
+ struct resource *res;
+ } sc_bar_mappings[PUC_MAX_BAR];
+
+ /* per-port dynamic data */
+ struct {
+ struct device *dev;
+ /* filled in by bus_setup_intr() */
+ void (*ihand)(void *);
+ void *ihandarg;
+ } sc_ports[PUC_MAX_PORTS];
+};
+
+#endif /* PUC_ENTRAILS */
extern const struct puc_device_description puc_devices[];
OpenPOWER on IntegriCloud