PERFORCE change 95465 for review
Marcel Moolenaar
marcel at FreeBSD.org
Tue Apr 18 00:55:57 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=95465
Change 95465 by marcel at marcel_nfs on 2006/04/18 00:54:57
o Remove pucvar.h. Split up its contents into
puc_bfe.h and puc.c. This avoids bus frontends
from having to pull in unnecessary headers.
o Various renaming to improve greppability.
o Manage and allocate interrupt resources.
o Add an empty detach function. We want that
too.
o Bring puc_pccard.c in sync with the new world
order.
o Slight shuffling to improve consistency.
Affected files ...
.. //depot/projects/uart/dev/puc/puc.c#24 edit
.. //depot/projects/uart/dev/puc/puc_pccard.c#4 edit
.. //depot/projects/uart/dev/puc/puc_pci.c#12 edit
.. //depot/projects/uart/dev/puc/pucdata.c#23 edit
.. //depot/projects/uart/dev/puc/pucvar.h#20 delete
Differences ...
==== //depot/projects/uart/dev/puc/puc.c#24 (text+ko) ====
@@ -41,12 +41,28 @@
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
+#include <dev/puc/puc_bfe.h>
#include <dev/puc/puc_bus.h>
#include <dev/puc/puc_cfg.h>
-#include <dev/puc/pucvar.h>
+
+#define PUC_ISRCCNT 5
+
+struct puc_port {
+ struct puc_bar *p_bar;
+ struct resource *p_rres;
+ struct resource *p_ires;
+ device_t p_dev;
+ int p_nr;
+ int p_type;
+ int p_rclk;
+
+ driver_intr_t *p_ih;
+ serdev_intr_t *p_ihsrc[PUC_ISRCCNT];
+ void *p_iharg;
+};
devclass_t puc_devclass;
-char puc_driver_name[] = "puc";
+const char puc_driver_name[] = "puc";
MALLOC_DEFINE(M_PUC, "PUC", "PUC driver");
@@ -110,7 +126,7 @@
}
int
-puc_attach(device_t dev)
+puc_bfe_attach(device_t dev)
{
struct puc_bar *bar;
struct puc_port *port;
@@ -140,6 +156,14 @@
rman_fini(&sc->sc_ioport);
return (error);
}
+ sc->sc_irq.rm_type = RMAN_ARRAY;
+ sc->sc_irq.rm_descr = "Interrupt vector space";
+ error = rman_init(&sc->sc_irq);
+ if (error) {
+ rman_fini(&sc->sc_iomem);
+ rman_fini(&sc->sc_ioport);
+ return (error);
+ }
error = puc_query(sc->sc_cfg, PUC_QUERY_NPORTS, 0, &res);
KASSERT(error == 0, ("%s %d", __func__, __LINE__));
@@ -147,6 +171,10 @@
sc->sc_port = malloc(sc->sc_nports * sizeof(struct puc_port),
M_PUC, M_WAITOK|M_ZERO);
+ error = rman_manage_region(&sc->sc_irq, 1, sc->sc_nports);
+ if (error)
+ goto fail;
+
for (idx = 0; idx < sc->sc_nports; idx++) {
port = &sc->sc_port[idx];
port->p_nr = idx + 1;
@@ -174,15 +202,19 @@
size = res;
rm = (bar->b_type == SYS_RES_IOPORT)
? &sc->sc_ioport: &sc->sc_iomem;
- port->p_res = rman_reserve_resource(rm, start + ofs,
+ port->p_rres = rman_reserve_resource(rm, start + ofs,
start + ofs + size - 1, size, 0, sc->sc_dev);
- if (port->p_res != NULL) {
+ if (port->p_rres != NULL) {
bsh = rman_get_bushandle(bar->b_res);
bst = rman_get_bustag(bar->b_res);
bus_space_subregion(bst, bsh, ofs, size, &bsh);
- rman_set_bushandle(port->p_res, bsh);
- rman_set_bustag(port->p_res, bst);
+ rman_set_bushandle(port->p_rres, bsh);
+ rman_set_bustag(port->p_rres, bst);
}
+ port->p_ires = rman_reserve_resource(&sc->sc_irq, port->p_nr,
+ port->p_nr, 1, 0, sc->sc_dev);
+ if (port->p_ires == NULL)
+ goto fail;
port->p_dev = device_add_child(dev, NULL, -1);
if (port->p_dev != NULL)
@@ -233,8 +265,10 @@
port = &sc->sc_port[idx];
if (port->p_dev != NULL)
device_delete_child(dev, port->p_dev);
- if (port->p_res != NULL)
- rman_release_resource(port->p_res);
+ if (port->p_rres != NULL)
+ rman_release_resource(port->p_rres);
+ if (port->p_ires != NULL)
+ rman_release_resource(port->p_ires);
}
for (idx = 0; idx < PUC_PCI_BARS; idx++) {
bar = &sc->sc_bar[idx];
@@ -242,6 +276,7 @@
bus_release_resource(sc->sc_dev, bar->b_type,
bar->b_rid, bar->b_res);
}
+ rman_fini(&sc->sc_irq);
rman_fini(&sc->sc_iomem);
rman_fini(&sc->sc_ioport);
free(sc->sc_port, M_PUC);
@@ -249,7 +284,13 @@
}
int
-puc_probe(device_t dev, const struct puc_cfg *cfg)
+puc_bfe_detach(device_t dev)
+{
+ return (ENXIO);
+}
+
+int
+puc_bfe_probe(device_t dev, const struct puc_cfg *cfg)
{
struct puc_softc *sc;
intptr_t res;
@@ -272,104 +313,184 @@
}
struct resource *
-puc_alloc_resource(device_t dev, device_t child, int type, int *rid,
+puc_bus_alloc_resource(device_t dev, device_t child, int type, int *rid,
u_long start, u_long end, u_long count, u_int flags)
{
struct puc_port *port;
- u_int fl;
+ struct resource *res;
+ device_t assigned, originator;
int error;
/* Get our immediate child. */
+ originator = child;
while (child != NULL && device_get_parent(child) != dev)
child = device_get_parent(child);
if (child == NULL)
return (NULL);
+ port = device_get_ivars(child);
+ KASSERT(port != NULL, ("%s %d", __func__, __LINE__));
+
+ if (rid == NULL || *rid != 0)
+ return (NULL);
+
/* We only support default allocations. */
- if (*rid != 0 || start != 0UL || end != ~0UL)
+ if (start != 0UL || end != ~0UL)
+ return (NULL);
+
+ if (type == port->p_bar->b_type)
+ res = port->p_rres;
+ else if (type == SYS_RES_IRQ)
+ res = port->p_ires;
+ else
return (NULL);
- port = device_get_ivars(child);
- if (port->p_res == NULL)
+ if (res == NULL)
return (NULL);
- if (rman_get_device(port->p_res) == dev)
- rman_set_device(port->p_res, child);
- else if (rman_get_device(port->p_res) != child)
+
+ assigned = rman_get_device(res);
+ if (assigned == dev) /* Not allocated */
+ rman_set_device(res, originator);
+ else if (assigned != originator)
return (NULL);
- fl = rman_get_flags(port->p_res);
- if ((flags & RF_ACTIVE) != 0 && (fl & RF_ACTIVE) == 0) {
- error = rman_activate_resource(port->p_res);
+
+ if (flags & RF_ACTIVE) {
+ error = rman_activate_resource(res);
if (error) {
- rman_set_device(port->p_res, dev);
+ if (assigned == dev)
+ rman_set_device(res, dev);
return (NULL);
}
}
- return (port->p_res);
+
+ return (res);
}
int
-puc_release_resource(device_t dev, device_t child, int type, int rid,
+puc_bus_release_resource(device_t dev, device_t child, int type, int rid,
struct resource *res)
{
- struct puc_port *p;
+ struct puc_port *port;
+ device_t originator;
/* Get our immediate child. */
+ originator = child;
while (child != NULL && device_get_parent(child) != dev)
child = device_get_parent(child);
if (child == NULL)
return (EINVAL);
- p = device_get_ivars(child);
+ port = device_get_ivars(child);
+ KASSERT(port != NULL, ("%s %d", __func__, __LINE__));
+
+ if (rid != 0 || res == NULL)
+ return (EINVAL);
+
+ if (type == port->p_bar->b_type) {
+ if (res != port->p_rres)
+ return (EINVAL);
+ } else if (type == SYS_RES_IRQ) {
+ if (res != port->p_ires)
+ return (EINVAL);
+ } else
+ return (EINVAL);
+
+ if (rman_get_device(res) != originator)
+ return (ENXIO);
+ if (rman_get_flags(res) & RF_ACTIVE)
+ rman_deactivate_resource(res);
+ rman_set_device(res, dev);
return (0);
}
int
-puc_get_resource(device_t dev, device_t child, int type, int rid,
+puc_bus_get_resource(device_t dev, device_t child, int type, int rid,
u_long *startp, u_long *countp)
{
- struct puc_port *p;
+ struct puc_port *port;
+ struct resource *res;
+ u_long start;
+ /* Get our immediate child. */
while (child != NULL && device_get_parent(child) != dev)
child = device_get_parent(child);
if (child == NULL)
return (EINVAL);
- p = device_get_ivars(child);
- return (ENXIO);
+ port = device_get_ivars(child);
+ KASSERT(port != NULL, ("%s %d", __func__, __LINE__));
+
+ if (type == port->p_bar->b_type)
+ res = port->p_rres;
+ else if (type == SYS_RES_IRQ)
+ res = port->p_ires;
+ else
+ return (ENXIO);
+
+ if (rid != 0 || res == NULL)
+ return (ENXIO);
+
+ start = rman_get_start(res);
+ if (startp != NULL)
+ *startp = start;
+ if (countp != NULL)
+ *countp = rman_get_end(res) - start + 1;
+ return (0);
}
int
-puc_setup_intr(device_t dev, device_t child, struct resource *r, int flags,
- void (*ihand)(void *), void *arg, void **cookiep)
+puc_bus_setup_intr(device_t dev, device_t child, struct resource *res,
+ int flags, void (*ihand)(void *), void *arg, void **cookiep)
{
- struct puc_port *p;
+ struct puc_port *port;
+ struct puc_softc *sc;
+ device_t originator;
+
+ sc = device_get_softc(dev);
+ /* Get our immediate child. */
+ originator = child;
while (child != NULL && device_get_parent(child) != dev)
child = device_get_parent(child);
if (child == NULL)
return (EINVAL);
- p = device_get_ivars(child);
- return (ENXIO);
+ port = device_get_ivars(child);
+ KASSERT(port != NULL, ("%s %d", __func__, __LINE__));
+
+ if (ihand == NULL || cookiep == NULL || res != port->p_ires)
+ return (EINVAL);
+ if (rman_get_device(port->p_ires) != originator)
+ return (ENXIO);
+
+ return (0);
}
int
-puc_teardown_intr(device_t dev, device_t child, struct resource *r,
+puc_bus_teardown_intr(device_t dev, device_t child, struct resource *res,
void *cookie)
{
- struct puc_port *p;
+ struct puc_port *port;
+ device_t originator;
+ /* Get our immediate child. */
+ originator = child;
while (child != NULL && device_get_parent(child) != dev)
child = device_get_parent(child);
if (child == NULL)
return (EINVAL);
- p = device_get_ivars(child);
+ port = device_get_ivars(child);
+ KASSERT(port != NULL, ("%s %d", __func__, __LINE__));
+
+ if (res == NULL || cookie == NULL)
+ return (EINVAL);
+
return (ENXIO);
}
int
-puc_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
+puc_bus_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
{
struct puc_port *port;
@@ -380,6 +501,10 @@
return (EINVAL);
port = device_get_ivars(child);
+ KASSERT(port != NULL, ("%s %d", __func__, __LINE__));
+
+ if (result == NULL)
+ return (EINVAL);
switch(index) {
case PUC_IVAR_CLOCK:
==== //depot/projects/uart/dev/puc/puc_pccard.c#4 (text+ko) ====
@@ -27,8 +27,6 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: src/sys/dev/puc/puc_pccard.c,v 1.9 2004/05/30 20:08:38 phk Exp $");
-#include "opt_puc.h"
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
@@ -41,25 +39,19 @@
#include <machine/resource.h>
#include <sys/rman.h>
-#define PUC_ENTRAILS 1
-#include <dev/puc/pucvar.h>
-
-#include <dev/sio/sioreg.h>
#include <dev/pccard/pccardvar.h>
-const struct puc_device_description rscom_devices = {
+#include <dev/puc/puc_bfe.h>
+#include <dev/puc/puc_cfg.h>
+/* http://www.argosy.com.tw/product/sp320.htm */
+const struct puc_cfg puc_pccard_rscom = {
+ 0, 0, 0, 0,
"ARGOSY SP320 Dual port serial PCMCIA",
- /* http://www.argosy.com.tw/product/sp320.htm */
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 },
- {
- { PUC_PORT_TYPE_COM, 0x0, 0x00, DEFAULT_RCLK, 0x100000 },
- { PUC_PORT_TYPE_COM, 0x1, 0x00, DEFAULT_RCLK, 0 },
- }
+ DEFAULT_RCLK,
+ PUC_PORT_2S, 0, 1, 0,
};
-
static int
puc_pccard_probe(device_t dev)
{
@@ -72,39 +64,31 @@
error = pccard_get_product_str(dev, &product);
if (error)
return(error);
- if (!strcmp(vendor, "PCMCIA") && !strcmp(product, "RS-COM 2P")) {
- device_set_desc(dev, rscom_devices.name);
- return (0);
- }
+ if (!strcmp(vendor, "PCMCIA") && !strcmp(product, "RS-COM 2P"))
+ return (puc_bfe_probe(dev, &puc_pccard_rscom));
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(device_attach, puc_bfe_attach),
+ DEVMETHOD(device_detach, puc_bfe_detach),
- 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_alloc_resource, puc_bus_alloc_resource),
+ DEVMETHOD(bus_release_resource, puc_bus_release_resource),
+ DEVMETHOD(bus_get_resource, puc_bus_get_resource),
+ DEVMETHOD(bus_read_ivar, puc_bus_read_ivar),
+ DEVMETHOD(bus_setup_intr, puc_bus_setup_intr),
+ DEVMETHOD(bus_teardown_intr, puc_bus_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_driver_name,
puc_pccard_methods,
sizeof(struct puc_softc),
};
==== //depot/projects/uart/dev/puc/puc_pci.c#12 (text+ko) ====
@@ -75,10 +75,8 @@
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
+#include <dev/puc/puc_bfe.h>
#include <dev/puc/puc_cfg.h>
-#include <dev/puc/pucvar.h>
-
-extern const struct puc_cfg puc_devices[];
static const struct puc_cfg *
puc_pci_match(device_t dev, const struct puc_cfg *desc)
@@ -111,23 +109,24 @@
if ((pci_read_config(dev, PCIR_HDRTYPE, 1) & PCIM_HDRTYPE) != 0)
return (ENXIO);
- desc = puc_pci_match(dev, puc_devices);
+ desc = puc_pci_match(dev, puc_pci_devices);
if (desc == NULL)
return (ENXIO);
- return (puc_probe(dev, desc));
+ return (puc_bfe_probe(dev, desc));
}
static device_method_t puc_pci_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, puc_pci_probe),
- DEVMETHOD(device_attach, puc_attach),
+ DEVMETHOD(device_attach, puc_bfe_attach),
+ DEVMETHOD(device_detach, puc_bfe_detach),
- 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_alloc_resource, puc_bus_alloc_resource),
+ DEVMETHOD(bus_release_resource, puc_bus_release_resource),
+ DEVMETHOD(bus_get_resource, puc_bus_get_resource),
+ DEVMETHOD(bus_read_ivar, puc_bus_read_ivar),
+ DEVMETHOD(bus_setup_intr, puc_bus_setup_intr),
+ DEVMETHOD(bus_teardown_intr, puc_bus_teardown_intr),
DEVMETHOD(bus_print_child, bus_generic_print_child),
DEVMETHOD(bus_driver_added, bus_generic_driver_added),
{ 0, 0 }
==== //depot/projects/uart/dev/puc/pucdata.c#23 (text+ko) ====
@@ -49,7 +49,7 @@
static puc_query_f puc_query_siig;
static puc_query_f puc_query_titan;
-const struct puc_cfg puc_devices[] = {
+const struct puc_cfg puc_pci_devices[] = {
{ 0x0009, 0x7168, 0xffff, 0,
"Sunix SUN1889",
More information about the p4-projects
mailing list