- device/softc split

This commit is contained in:
joerg 2008-07-09 14:46:15 +00:00
parent b5d2f044e1
commit 18f2c24945
2 changed files with 45 additions and 50 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: puc.c,v 1.30 2008/04/10 19:13:37 cegger Exp $ */
/* $NetBSD: puc.c,v 1.31 2008/07/09 14:46:15 joerg Exp $ */
/*
* Copyright (c) 1996, 1998, 1999
@ -53,7 +53,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: puc.c,v 1.30 2008/04/10 19:13:37 cegger Exp $");
__KERNEL_RCSID(0, "$NetBSD: puc.c,v 1.31 2008/07/09 14:46:15 joerg Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -70,8 +70,6 @@ __KERNEL_RCSID(0, "$NetBSD: puc.c,v 1.30 2008/04/10 19:13:37 cegger Exp $");
#include "opt_puccn.h"
struct puc_softc {
struct device sc_dev;
/* static configuration data */
const struct puc_device_description *sc_desc;
@ -87,7 +85,7 @@ struct puc_softc {
/* per-port dynamic data */
struct {
struct device *dev;
device_t dev;
/* filled in by port attachments */
int (*ihand)(void *);
@ -100,8 +98,7 @@ static int puc_print(void *, const char *);
static const char *puc_port_type_name(int);
static int
puc_match(struct device *parent, struct cfdata *match,
void *aux)
puc_match(device_t parent, cfdata_t match, void *aux)
{
struct pci_attach_args *pa = aux;
const struct puc_device_description *desc;
@ -141,9 +138,9 @@ puc_match(struct device *parent, struct cfdata *match,
}
static void
puc_attach(struct device *parent, struct device *self, void *aux)
puc_attach(device_t parent, device_t self, void *aux)
{
struct puc_softc *sc = (struct puc_softc *)self;
struct puc_softc *sc = device_private(self);
struct pci_attach_args *pa = aux;
struct puc_attach_args paa;
pci_intr_handle_t intrhandle;
@ -170,11 +167,11 @@ puc_attach(struct device *parent, struct device *self, void *aux)
#else
printf(": unknown PCI communications device\n");
printf("%s: compile kernel with PUC_PRINT_REGS and larger\n",
device_xname(&sc->sc_dev));
device_xname(self));
printf("%s: mesage buffer (via 'options MSGBUFSIZE=...'),\n",
device_xname(&sc->sc_dev));
device_xname(self));
printf("%s: and report the result with send-pr\n",
device_xname(&sc->sc_dev));
device_xname(self));
#endif
return;
}
@ -223,13 +220,13 @@ puc_attach(struct device *parent, struct device *self, void *aux)
if (sc->sc_bar_mappings[i].mapped)
continue;
aprint_error_dev(&sc->sc_dev, "couldn't map BAR at offset 0x%lx\n",
aprint_error_dev(self, "couldn't map BAR at offset 0x%lx\n",
(long)(PCI_MAPREG_START + 4 * i));
}
/* Map interrupt. */
if (pci_intr_map(pa, &intrhandle)) {
aprint_error_dev(&sc->sc_dev, "couldn't map interrupt\n");
aprint_error_dev(self, "couldn't map interrupt\n");
return;
}
/*
@ -256,7 +253,7 @@ puc_attach(struct device *parent, struct device *self, void *aux)
barindex = PUC_PORT_BAR_INDEX(sc->sc_desc->ports[i].bar);
if (!sc->sc_bar_mappings[barindex].mapped) {
printf("%s: %s port uses unmapped BAR (0x%x)\n",
device_xname(&sc->sc_dev),
device_xname(self),
puc_port_type_name(sc->sc_desc->ports[i].type),
sc->sc_desc->ports[i].bar);
continue;
@ -286,14 +283,14 @@ puc_attach(struct device *parent, struct device *self, void *aux)
sc->sc_bar_mappings[barindex].s -
sc->sc_desc->ports[i].offset,
&subregion_handle) != 0) {
aprint_error_dev(&sc->sc_dev, "couldn't get subregion for port %d\n", i);
aprint_error_dev(self, "couldn't get subregion for port %d\n", i);
continue;
}
paa.h = subregion_handle;
#if 0
printf("%s: port %d: %s @ (index %d) 0x%x (0x%lx, 0x%lx)\n",
device_xname(&sc->sc_dev), paa.port,
device_xname(self), paa.port,
puc_port_type_name(paa.type), barindex, (int)paa.a,
(long)paa.t, (long)paa.h);
#endif
@ -306,7 +303,7 @@ puc_attach(struct device *parent, struct device *self, void *aux)
}
}
CFATTACH_DECL(puc, sizeof(struct puc_softc),
CFATTACH_DECL_NEW(puc, sizeof(struct puc_softc),
puc_match, puc_attach, NULL, NULL);
static int

View File

@ -1,4 +1,4 @@
/* $NetBSD: weasel_pci.c,v 1.12 2008/04/28 20:23:55 martin Exp $ */
/* $NetBSD: weasel_pci.c,v 1.13 2008/07/09 14:51:11 joerg Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: weasel_pci.c,v 1.12 2008/04/28 20:23:55 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: weasel_pci.c,v 1.13 2008/07/09 14:51:11 joerg Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -58,8 +58,7 @@ __KERNEL_RCSID(0, "$NetBSD: weasel_pci.c,v 1.12 2008/04/28 20:23:55 martin Exp $
#include <dev/sysmon/sysmonvar.h>
struct weasel_softc {
struct device sc_dev; /* generic device glue */
device_t sc_dev;
bus_space_tag_t sc_st;
bus_space_handle_t sc_sh;
@ -84,8 +83,7 @@ static int weasel_pci_wdog_disarm(struct weasel_softc *);
static int weasel_pci_wdog_query_state(struct weasel_softc *);
static int
weasel_pci_match(struct device *parent, struct cfdata *cf,
void *aux)
weasel_pci_match(device_t parent, cfdata_t cf, void *aux)
{
struct pci_attach_args *pa = aux;
@ -97,10 +95,9 @@ weasel_pci_match(struct device *parent, struct cfdata *cf,
}
static void
weasel_pci_attach(struct device *parent, struct device *self,
void *aux)
weasel_pci_attach(device_t parent, device_t self, void *aux)
{
struct weasel_softc *sc = (void *) self;
struct weasel_softc *sc = device_private(self);
struct pci_attach_args *pa = aux;
struct weasel_config_block cfg;
const char *vers, *mode;
@ -108,43 +105,45 @@ weasel_pci_attach(struct device *parent, struct device *self,
uint16_t cfg_size;
uint8_t buf[8];
sc->sc_dev = self;
printf(": PCI-Weasel watchdog timer\n");
if (pci_mapreg_map(pa, PCI_MAPREG_START,
PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
&sc->sc_st, &sc->sc_sh, NULL, NULL) != 0) {
aprint_error_dev(&sc->sc_dev, "unable to map device registers\n");
aprint_error_dev(self, "unable to map device registers\n");
return;
}
/* Ping the Weasel to see if it's alive. */
if (weasel_issue_command(sc, OS_CMD_PING)) {
aprint_error_dev(&sc->sc_dev, "Weasel didn't respond to PING\n");
aprint_error_dev(self, "Weasel didn't respond to PING\n");
return;
}
bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
if ((v = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD)) !=
OS_RET_PONG) {
aprint_error_dev(&sc->sc_dev, "unexpected PING response from Weasel: 0x%02x\n", v);
aprint_error_dev(self, "unexpected PING response from Weasel: 0x%02x\n", v);
return;
}
/* Read the config block. */
if (weasel_issue_command(sc, OS_CMD_SHOW_CONFIG)) {
aprint_error_dev(&sc->sc_dev, "Weasel didn't respond to SHOW_CONFIG\n");
aprint_error_dev(self, "Weasel didn't respond to SHOW_CONFIG\n");
return;
}
cfg_size = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
if (++cfg_size != sizeof(cfg)) {
aprint_error_dev(&sc->sc_dev, "weird config block size from Weasel: 0x%03x\n", cfg_size);
aprint_error_dev(self, "weird config block size from Weasel: 0x%03x\n", cfg_size);
return;
}
for (cp = (uint8_t *) &cfg; cfg_size != 0; cfg_size--) {
if (weasel_wait_response(sc)) {
aprint_error_dev(&sc->sc_dev, "Weasel stopped providing config block(%d)\n", cfg_size);
aprint_error_dev(self, "Weasel stopped providing config block(%d)\n", cfg_size);
return;
}
*cp++ = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
@ -174,41 +173,40 @@ weasel_pci_attach(struct device *parent, struct device *self,
}
if (vers != NULL)
printf("%s: %s mode\n", device_xname(&sc->sc_dev),
mode);
printf("%s: %s mode\n", device_xname(self), mode);
else
printf("%s: unknown config version 0x%02x\n", device_xname(&sc->sc_dev),
printf("%s: unknown config version 0x%02x\n", device_xname(self),
cfg.cfg_version);
/*
* Fetch sw version.
*/
if (weasel_issue_command(sc, OS_CMD_QUERY_SW_VER)) {
aprint_error_dev(&sc->sc_dev, "didn't reply to software version query.\n");
aprint_error_dev(self, "didn't reply to software version query.\n");
}
else {
v = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
if (v>7)
printf("%s: weird length for version string(%d).\n",
device_xname(&sc->sc_dev), v);
device_xname(self), v);
bzero(buf, sizeof(buf));
for (cp = buf; v != 0; v--) {
if (weasel_wait_response(sc)) {
printf("%s: Weasel stopped providing version\n",
device_xname(&sc->sc_dev));
device_xname(self));
}
*cp++ = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
}
printf("%s: sw: %s", device_xname(&sc->sc_dev), buf);
printf("%s: sw: %s", device_xname(self), buf);
}
/*
* Fetch logic version.
*/
if (weasel_issue_command(sc, OS_CMD_QUERY_L_VER)) {
aprint_normal("\n");
aprint_error_dev(&sc->sc_dev, "didn't reply to logic version query.\n");
aprint_error_dev(self, "didn't reply to logic version query.\n");
}
bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
v = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
@ -218,7 +216,7 @@ weasel_pci_attach(struct device *parent, struct device *self,
*/
if (weasel_issue_command(sc, OS_CMD_QUERY_VB_VER)) {
aprint_normal("\n");
aprint_error_dev(&sc->sc_dev, "didn't reply to vga bios version query.\n");
aprint_error_dev(self, "didn't reply to vga bios version query.\n");
}
v = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
@ -228,13 +226,13 @@ weasel_pci_attach(struct device *parent, struct device *self,
*/
if (weasel_issue_command(sc, OS_CMD_QUERY_HW_VER)) {
aprint_normal("\n");
aprint_error_dev(&sc->sc_dev, "didn't reply to hardware version query.\n");
aprint_error_dev(self, "didn't reply to hardware version query.\n");
}
v = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
printf(" hw: %d.%d", (v>>4), (v&0x0f));
printf("\n%s: break passthrough %s", device_xname(&sc->sc_dev),
printf("\n%s: break passthrough %s", device_xname(self),
cfg.break_passthru ? "enabled" : "disabled");
if ((sc->sc_wdog_armed = weasel_pci_wdog_query_state(sc)) == -1)
@ -251,11 +249,11 @@ weasel_pci_attach(struct device *parent, struct device *self,
sc->sc_smw.smw_period = sc->sc_wdog_period;
if (sysmon_wdog_register(&sc->sc_smw) != 0)
aprint_error_dev(&sc->sc_dev, "unable to register PC-Weasel watchdog "
aprint_error_dev(self, "unable to register PC-Weasel watchdog "
"with sysmon\n");
}
CFATTACH_DECL(weasel_pci, sizeof(struct weasel_softc),
CFATTACH_DECL_NEW(weasel_pci, sizeof(struct weasel_softc),
weasel_pci_match, weasel_pci_attach, NULL, NULL);
static int
@ -332,7 +330,7 @@ weasel_pci_wdog_tickle(struct sysmon_wdog *smw)
error = 0;
} else {
printf("%s: Watchdog timer disabled on PC/Weasel! Disarming wdog.\n",
device_xname(&sc->sc_dev));
device_xname(sc->sc_dev));
sc->sc_wdog_armed = 0;
sysmon_wdog_setmode(smw, WDOG_MODE_DISARMED, 0);
error = 1;
@ -353,7 +351,7 @@ weasel_pci_wdog_arm(struct weasel_softc *sc)
s = splhigh();
if (weasel_issue_command(sc, OS_CMD_WDT_ENABLE)) {
printf("%s: no reply to watchdog enable. Check Weasel \"Allow Watchdog\" setting.\n",
device_xname(&sc->sc_dev));
device_xname(sc->sc_dev));
error = EIO;
}
reg = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
@ -395,7 +393,7 @@ weasel_pci_wdog_disarm(struct weasel_softc *sc)
if (weasel_issue_command(sc, OS_CMD_WDT_DISABLE)) {
printf("%s: didn't reply to watchdog disable.\n",
device_xname(&sc->sc_dev));
device_xname(sc->sc_dev));
error = EIO;
}
reg = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
@ -432,7 +430,7 @@ weasel_pci_wdog_query_state(struct weasel_softc *sc)
if (weasel_issue_command(sc, OS_CMD_WDT_QUERY)) {
printf("%s: didn't reply to watchdog state query.\n",
device_xname(&sc->sc_dev));
device_xname(sc->sc_dev));
bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
return(-1);
}