Added bus probing to avoid bus error.

This commit is contained in:
takemura 2002-04-14 07:59:56 +00:00
parent a3f3f844dc
commit e63e3c0ed4
6 changed files with 130 additions and 23 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: com_hpcio.c,v 1.2 2002/01/05 00:40:38 takemura Exp $ */
/* $NetBSD: com_hpcio.c,v 1.3 2002/04/14 07:59:56 takemura Exp $ */
/*-
* Copyright (c) 2002 TAKEMRUA Shin. All rights reserved.
@ -101,6 +101,10 @@ struct bus_space_ops com_hpcio_bs_ops = {
/* barrier */
bs_through_bs_barrier,
/* probe */
bs_through_bs_peek,
bs_through_bs_poke,
/* read (single) */
com_hpcio_bs_r_1,
bs_notimpl_bs_r_2,

View File

@ -1,4 +1,4 @@
/* $NetBSD: bus_space.c,v 1.17 2001/12/02 10:37:53 uch Exp $ */
/* $NetBSD: bus_space.c,v 1.18 2002/04/14 07:59:57 takemura Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -88,6 +88,10 @@ static struct bus_space_tag_hpcmips __sys_bus_space = {
/* barrier */
__bs_barrier,
/* probe */
__bs_peek,
__bs_poke,
/* read (single) */
__bs_r_1,
__bs_r_2,
@ -266,9 +270,12 @@ __bs_map(bus_space_tag_t tx, bus_addr_t bpa, bus_size_t size, int flags,
int err;
int cacheable = flags & BUS_SPACE_MAP_CACHEABLE;
DPRINTF(("\tbus_space_map:%#lx(%#lx)+%#lx\n",
bpa, bpa - t->base, size));
if (!t->extent) { /* Before autoconfiguration, can't use extent */
DPRINTF(("bus_space_map: map temporary region:"
"0x%08x-0x%08x\n", bpa, bpa+size));
"0x%08lx-0x%08lx\n", bpa, bpa+size));
bpa += t->base;
} else {
bpa += t->base;
@ -279,9 +286,6 @@ __bs_map(bus_space_tag_t tx, bus_addr_t bpa, bus_size_t size, int flags,
}
*bshp = __hpcmips_cacheable(t, bpa, size, cacheable);
DPRINTF(("\tbus_space_map:%#x(%#x)+%#x\n",
bpa, bpa - t->base, size));
return (0);
}
@ -304,7 +308,7 @@ __bs_unmap(bus_space_tag_t tx, bus_space_handle_t bsh, bus_size_t size)
}
if ((err = extent_free(t->extent, addr, size, EX_NOWAIT))) {
DPRINTF(("warning: %#x-%#x of %s space lost\n",
DPRINTF(("warning: %#lx-%#lx of %s space lost\n",
bsh, bsh+size, t->name));
}
}
@ -334,6 +338,9 @@ __bs_alloc(bus_space_tag_t tx, bus_addr_t rstart, bus_addr_t rend,
if (!t->extent)
panic("bus_space_alloc: no extent");
DPRINTF(("\tbus_space_alloc:%#lx(%#lx)+%#lx\n", bpa,
bpa - t->base, size));
rstart += t->base;
rend += t->base;
if ((err = extent_alloc_subregion(t->extent, rstart, rend, size,
@ -347,9 +354,6 @@ __bs_alloc(bus_space_tag_t tx, bus_addr_t rstart, bus_addr_t rend,
*bpap = bpa;
}
DPRINTF(("\tbus_space_alloc:%#x(%#x)+%#x\n", (unsigned)bpa,
(unsigned)(bpa - t->base), size));
return (0);
}
@ -368,6 +372,60 @@ __bs_barrier(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t offset,
wbflush();
}
int
__bs_peek(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t offset,
size_t size, void *ptr)
{
u_int32_t tmp;
if (badaddr((void *)(bsh + offset), size))
return (-1);
if (ptr == NULL)
ptr = &tmp;
switch(size) {
case 1:
*((u_int8_t *)ptr) = bus_space_read_1(t, bsh, offset);
break;
case 2:
*((u_int16_t *)ptr) = bus_space_read_2(t, bsh, offset);
break;
case 4:
*((u_int32_t *)ptr) = bus_space_read_4(t, bsh, offset);
break;
default:
panic("bus_space_peek: bad size, %d\n", size);
}
return (0);
}
int
__bs_poke(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t offset,
size_t size, u_int32_t val)
{
if (badaddr((void *)(bsh + offset), size))
return (-1);
switch(size) {
case 1:
bus_space_write_1(t, bsh, offset, val);
break;
case 2:
bus_space_write_2(t, bsh, offset, val);
break;
case 4:
bus_space_write_4(t, bsh, offset, val);
break;
default:
panic("bus_space_poke: bad size, %d\n", size);
}
return (0);
}
u_int8_t
__bs_r_1(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t offset)
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: bus_space_notimpl.c,v 1.2 2002/01/02 13:11:02 uch Exp $ */
/* $NetBSD: bus_space_notimpl.c,v 1.3 2002/04/14 07:59:59 takemura Exp $ */
/*-
* Copyright (c) 2001 TAKEMURA Shin. All rights reserved.
@ -48,6 +48,8 @@ __NOTIMPL(free)
__NOTIMPL(vaddr)
__NOTIMPL(mmap)
__NOTIMPL(barrier)
__NOTIMPL(peek)
__NOTIMPL(poke)
__NOTIMPL(r_1)
__NOTIMPL(r_2)
__NOTIMPL(r_4)

View File

@ -1,4 +1,4 @@
/* $NetBSD: bus_space_through.c,v 1.1 2001/12/23 13:32:34 takemura Exp $ */
/* $NetBSD: bus_space_through.c,v 1.2 2002/04/14 07:59:59 takemura Exp $ */
/*-
* Copyright (c) 2001 TAKEMRUA Shin. All rights reserved.
@ -108,6 +108,24 @@ bs_through_bs_barrier(bus_space_tag_t t, bus_space_handle_t bsh,
}
/*
* Bus probe operations.
*/
int
bs_through_bs_peek(bus_space_tag_t t, bus_space_handle_t bsh,
bus_size_t offset, size_t size, void *ptr)
{
return bus_space_peek(t->bs_base, bsh, offset, size, ptr);
}
int
bs_through_bs_poke(bus_space_tag_t t, bus_space_handle_t bsh,
bus_size_t offset, size_t size, u_int32_t val)
{
return bus_space_poke(t->bs_base, bsh, offset, size, val);
}
/*
* Bus read (single) operations.
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: bus.h,v 1.14 2001/11/18 08:19:40 takemura Exp $ */
/* $NetBSD: bus.h,v 1.15 2002/04/14 07:59:59 takemura Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
@ -117,6 +117,12 @@ struct bus_space_ops {
void (*bs_barrier)(bus_space_tag_t, bus_space_handle_t,
bus_size_t, bus_size_t, int);
/* probe */
int (*bs_peek)(bus_space_tag_t, bus_space_handle_t,
bus_size_t, size_t, void *);
int (*bs_poke)(bus_space_tag_t, bus_space_handle_t,
bus_size_t, size_t, u_int32_t);
/* read (single) */
u_int8_t (*bs_r_1)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
u_int16_t (*bs_r_2)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
@ -330,6 +336,15 @@ struct bus_space_ops {
(*__bs_ops(t).bs_barrier)(t, (h), (o), (l), (f))
/*
* Bus probe operations.
*/
#define bus_space_peek(t, h, o, s, p) \
(*__bs_ops(t).bs_peek)(t, (h), (o), (s), (p))
#define bus_space_poke(t, h, o, s, v) \
(*__bs_ops(t).bs_poke)(t, (h), (o), (s), (v))
/*
* Bus read (single) operations.
*/
@ -576,6 +591,13 @@ paddr_t __bs_c(f,_bs_mmap)(bus_space_tag_t t, bus_addr_t addr, \
void __bs_c(f,_bs_barrier)(bus_space_tag_t t, bus_space_handle_t bsh,\
bus_size_t offset, bus_size_t len, int flags)
#define bs_peek_proto(f) \
int __bs_c(f,_bs_peek)(bus_space_tag_t t, bus_space_handle_t bsh, \
bus_size_t offset, size_t len, void *ptr)
#define bs_poke_proto(f) \
int __bs_c(f,_bs_poke)(bus_space_tag_t t, bus_space_handle_t bsh, \
bus_size_t offset, size_t len, u_int32_t val)
#define bs_r_1_proto(f) \
u_int8_t __bs_c(f,_bs_r_1)(bus_space_tag_t t, \
bus_space_handle_t bsh, bus_size_t offset)
@ -812,6 +834,8 @@ bs_free_proto(f); \
bs_vaddr_proto(f); \
bs_mmap_proto(f); \
bs_barrier_proto(f); \
bs_peek_proto(f); \
bs_poke_proto(f); \
bs_r_1_proto(f); \
bs_r_2_proto(f); \
bs_r_4_proto(f); \

View File

@ -1,4 +1,4 @@
/* $NetBSD: vrc4172pci.c,v 1.1 2002/03/22 09:18:09 takemura Exp $ */
/* $NetBSD: vrc4172pci.c,v 1.2 2002/04/14 08:00:00 takemura Exp $ */
/*-
* Copyright (c) 2002 TAKEMURA Shin
@ -103,8 +103,13 @@ vrc4172pci_write(struct vrc4172pci_softc *sc, int offset, u_int32_t val)
static inline u_int32_t
vrc4172pci_read(struct vrc4172pci_softc *sc, int offset)
{
u_int32_t res;
return (bus_space_read_4(sc->sc_iot, sc->sc_ioh, offset));
if (bus_space_peek(sc->sc_iot, sc->sc_ioh, offset, 4, &res) < 0) {
res = 0xffffffff;
}
return (res);
}
static int
@ -245,10 +250,8 @@ vrc4172pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
vrc4172pci_write(sc, VRC4172PCI_CONFAREG, tag | reg);
val = vrc4172pci_read(sc, VRC4172PCI_CONFDREG);
#if 0
printf("%s: conf_read: tag = 0x%08x, reg = 0x%x, val = 0x%08x\n",
sc->sc_dev.dv_xname, (u_int32_t)tag, reg, val);
#endif
DPRINTF(("%s: conf_read: tag = 0x%08x, reg = 0x%x, val = 0x%08x\n",
sc->sc_dev.dv_xname, (u_int32_t)tag, reg, val));
return (val);
}
@ -259,10 +262,8 @@ vrc4172pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg,
{
struct vrc4172pci_softc *sc = (struct vrc4172pci_softc *)pc->pc_dev;
#if 0
printf("%s: conf_write: tag = 0x%08x, reg = 0x%x, val = 0x%08x\n",
sc->sc_dev.dv_xname, (u_int32_t)tag, reg, (u_int32_t)data);
#endif
DPRINTF(("%s: conf_write: tag = 0x%08x, reg = 0x%x, val = 0x%08x\n",
sc->sc_dev.dv_xname, (u_int32_t)tag, reg, (u_int32_t)data));
tag |= VRC4172PCI_CONFADDR_CONFIGEN;
vrc4172pci_write(sc, VRC4172PCI_CONFAREG, tag | reg);