Overhaul the intio device attachment. Devices are direct connected and

attached based on machine id.
This commit is contained in:
gmcgarry 2001-11-17 23:33:22 +00:00
parent 3acacb5fc1
commit 224cd45a75
3 changed files with 238 additions and 33 deletions

View File

@ -1,7 +1,7 @@
/* $NetBSD: intio.c,v 1.6 1998/01/12 18:31:00 thorpej Exp $ */
/* $NetBSD: intio.c,v 1.7 2001/11/17 23:33:22 gmcgarry Exp $ */
/*-
* Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
* Copyright (c) 1996, 1998, 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -43,26 +43,51 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <machine/hp300spu.h>
#include <hp300/dev/intioreg.h>
#include <hp300/dev/intiovar.h>
int intiomatch __P((struct device *, struct cfdata *, void *));
void intioattach __P((struct device *, struct device *, void *));
int intioprint __P((void *, const char *));
int intiosearch __P((struct device *, struct cfdata *, void *));
int intiomatch(struct device *, struct cfdata *, void *);
void intioattach(struct device *, struct device *, void *);
int intioprint(void *, const char *);
struct cfattach intio_ca = {
const struct cfattach intio_ca = {
sizeof(struct device), intiomatch, intioattach
};
#if defined(HP320) || defined(HP330) || defined(HP340) || defined(HP345) || \
defined(HP350) || defined(HP360) || defined(HP370) || defined(HP375) || \
defined(HP380) || defined(HP385)
const struct intio_builtins intio_3xx_builtins[] = {
{ "rtc ", 0x020000, -1},
{ "hil ", 0x028000, 1},
{ "fb ", 0x160000, -1},
};
#define nintio_3xx_builtins \
(sizeof(intio_3xx_builtins) / sizeof(intio_3xx_builtins[0]))
#endif
#if defined(HP400) || defined(HP425) || defined(HP433)
const struct intio_builtins intio_4xx_builtins[] = {
{ "rtc ", 0x020000, -1},
{ "frodo ", 0x01c000, 5},
{ "hil ", 0x028000, 1},
{ "fb ", 0x160000, -1},
};
#define nintio_4xx_builtins \
(sizeof(intio_4xx_builtins) / sizeof(intio_4xx_builtins[0]))
#endif
static int intio_matched = 0;
int
intiomatch(parent, match, aux)
struct device *parent;
struct cfdata *match;
void *aux;
{
static int intio_matched = 0;
/* Allow only one instance. */
if (intio_matched)
return (0);
@ -76,11 +101,54 @@ intioattach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct intio_attach_args ia;
const struct intio_builtins *ib;
int ndevs;
int i;
printf("\n");
/* Search for and attach children. */
config_search(intiosearch, self, NULL);
switch (machineid) {
#if defined(HP320) || defined(HP330) || defined(HP340) || defined(HP345) || \
defined(HP350) || defined(HP360) || defined(HP370) || defined(HP375) || \
defined(HP380) || defined(HP385)
case HP_320:
case HP_330:
case HP_340:
case HP_345:
case HP_350:
case HP_360:
case HP_370:
case HP_375:
case HP_380:
case HP_385:
ib = intio_3xx_builtins;
ndevs = nintio_3xx_builtins;
break;
#endif
#if defined(HP400) || defined(HP425) || defined(HP433)
case HP_400:
case HP_425:
case HP_433:
ib = intio_4xx_builtins;
ndevs = nintio_4xx_builtins;
break;
#endif
default:
return;
}
memset(&ia, 0, sizeof(ia));
for (i=0; i<ndevs; i++) {
strncpy(ia.ia_modname, ib[i].ib_modname, INTIO_MOD_LEN);
ia.ia_modname[INTIO_MOD_LEN] = '\0';
ia.ia_bst = HP300_BUS_SPACE_INTIO;
ia.ia_iobase = ib[i].ib_offset;
ia.ia_addr = (bus_addr_t)(intiobase + ib[i].ib_offset);
ia.ia_ipl = ib[i].ib_ipl;
config_found(self, &ia, intioprint);
}
}
int
@ -90,22 +158,12 @@ intioprint(aux, pnp)
{
struct intio_attach_args *ia = aux;
if (ia->ia_addr != 0)
printf(" addr 0x%lx", ia->ia_addr);
if (pnp)
printf("%s at %s", ia->ia_modname, pnp);
if (ia->ia_addr != 0) {
printf(" addr 0x%lx", INTIOBASE + ia->ia_iobase);
if (ia->ia_ipl != -1)
printf(" ipl %d", ia->ia_ipl);
}
return (UNCONF);
}
int
intiosearch(parent, cf, aux)
struct device *parent;
struct cfdata *cf;
void *aux;
{
struct intio_attach_args ia;
bzero(&ia, sizeof(ia));
ia.ia_bst = HP300_BUS_SPACE_INTIO;
if ((*cf->cf_attach->ca_match)(parent, cf, &ia) > 0)
config_attach(parent, cf, &ia, intioprint);
return (0);
}

View File

@ -0,0 +1,71 @@
/* $NetBSD: intioreg.h,v 1.1 2001/11/17 23:33:22 gmcgarry Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Gregory McGarry.
*
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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.
*/
/*
* Registers for interface to the wired devices.
*/
/* HP3xx/4xx registers */
#define INTIO_DEV_3xx_PAD0 0
#define INTIO_DEV_3xx_DATA 1
#define INTIO_DEV_3xx_PAD1 2
#define INTIO_DEV_3xx_CMD 3
#define INTIO_DEV_3xx_STAT 3
/* HP7xx registers - XXX check these */
#define INTIO_DEV_7xx_RSTHOLD 0
#define INTIO_DEV_7xx_DATA 2048
#define INTIO_DEV_7xx_CMD 2049
#define INTIO_DEV_7xx_STAT 2049
#define INTIO_DEV_7xx_RSTREL 3072
/* HP8xx registers - XXX check these */
#define INTIO_DEV_8xx_DATA 3
#define INTIO_DEV_8xx_CMD 11
#define INTIO_DEV_8xx_STAT 11
/* Status bits */
#define INTIO_DEV_DATA_READY 0x01
#define INTIO_DEV_BUSY 0x02
/* the top four bits specify a "service request" status code */
#define INTIO_DEV_SRSHIFT 4
#define INTIO_DEV_SRMASK 0x0f
/* Valid "service request" status codes */
#define INTIO_DEV_SR_DATAAVAIL 0x04
/* the specific wired device will overload the remaining bits */

View File

@ -1,7 +1,7 @@
/* $NetBSD: intiovar.h,v 1.4 1998/01/11 21:53:06 thorpej Exp $ */
/* $NetBSD: intiovar.h,v 1.5 2001/11/17 23:33:22 gmcgarry Exp $ */
/*-
* Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
* Copyright (c) 1996, 1998, 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -42,11 +42,87 @@
*/
#include <machine/bus.h>
#include <machine/cpu.h>
#include <arch/hp300/dev/intioreg.h>
#define INTIO_MOD_LEN 8
/*
* Arguments used to attach a device to the internal i/o space.
*/
struct intio_attach_args {
bus_space_tag_t ia_bst; /* bus space tag */
bus_addr_t ia_addr; /* physical address */
char ia_modname[INTIO_MOD_LEN+1]; /* module name */
bus_space_tag_t ia_bst; /* bus space tag */
bus_addr_t ia_addr; /* physical address */
bus_size_t ia_iobase; /* intio iobase */
int ia_ipl; /* interrupt priority level */
};
struct intio_builtins {
char *ib_modname; /* module name */
bus_size_t ib_offset; /* intio offset */
int ib_ipl; /* interrupt priority level */
};
/*
* Devices such as the HIL and RTC chips are wired in a consistent
* fashion. These routines provide a uniform mechanism for accessing
* the devices that are wired to the machine. Doesn't include
* memory-mapped devices such as framebuffers.
*/
#define WAIT(bst,bsh) \
while (bus_space_read_1(bst,bsh,INTIO_DEV_3xx_STAT) \
& INTIO_DEV_BUSY)
#define DATAWAIT(bst,bsh) \
while (!(bus_space_read_1(bst, bsh, INTIO_DEV_3xx_STAT) \
& INTIO_DEV_DATA_READY))
static __inline int
intio_device_readcmd(bus_space_tag_t bst, bus_space_handle_t bsh, int cmd,
u_int8_t *datap)
{
u_int8_t status;
if (cmd != 0) {
WAIT(bst, bsh);
bus_space_write_1(bst, bsh, INTIO_DEV_3xx_CMD, cmd);
}
do {
DATAWAIT(bst, bsh);
status = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_STAT);
*datap = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_DATA);
} while (((status >> INTIO_DEV_SRSHIFT) & INTIO_DEV_SRMASK)
!= INTIO_DEV_SR_DATAAVAIL);
return (0);
}
static __inline int
intio_device_writecmd(bus_space_tag_t bst, bus_space_handle_t bsh,
int cmd, u_int8_t *datap, int len)
{
WAIT(bst,bsh);
bus_space_write_1(bst, bsh, INTIO_DEV_3xx_CMD, cmd);
while (len--) {
WAIT(bst,bsh);
bus_space_write_1(bst, bsh, INTIO_DEV_3xx_DATA, *datap++);
}
return (0);
}
static __inline int
intio_device_readstate(bus_space_tag_t bst, bus_space_handle_t bsh,
u_int8_t *statusp, u_int8_t *datap)
{
*statusp = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_STAT);
*datap = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_DATA);
return (0);
}
#undef WAIT
#undef DATAWAIT
#define INTIO_DEVSIZE 4096 /* large enough for all machines */
#define intio_intr_establish(func, arg, ipl, priority) \
intr_establish((func),(arg),(ipl),(priority))