Add an internal bus space method alpha_bus_space_translate(), which

provides a method to translate an address on an I/O bus into a sysBus
address, along with acccess method information.
This commit is contained in:
thorpej 2000-02-25 00:45:04 +00:00
parent 108b65903a
commit de974ff82d
6 changed files with 202 additions and 57 deletions

View File

@ -1,7 +1,7 @@
/* $NetBSD: bus.h,v 1.32 2000/02/06 01:23:34 thorpej Exp $ */
/* $NetBSD: bus.h,v 1.33 2000/02/25 00:45:04 thorpej Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
* Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -100,6 +100,8 @@
#define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
#endif /* BUS_SPACE_DEBUG */
struct alpha_bus_space_translation;
/*
* Addresses (in bus space).
*/
@ -124,6 +126,10 @@ struct alpha_bus_space {
int (*abs_subregion) __P((void *, bus_space_handle_t,
bus_size_t, bus_size_t, bus_space_handle_t *));
/* ALPHA SPECIFIC MAPPING METHOD */
int (*abs_translate) __P((void *, bus_addr_t, bus_size_t,
int, struct alpha_bus_space_translation *));
/* allocation/deallocation */
int (*abs_alloc) __P((void *, bus_addr_t, bus_addr_t,
bus_size_t, bus_size_t, bus_size_t, int,
@ -226,6 +232,21 @@ struct alpha_bus_space {
bus_space_handle_t, bus_size_t, bus_size_t));
};
/*
* Translation of an Alpha bus address; INTERNAL USE ONLY.
*/
struct alpha_bus_space_translation {
bus_addr_t abst_bus_start; /* start of bus window */
bus_addr_t abst_bus_end; /* end of bus window */
paddr_t abst_sys_start; /* start of sysBus window */
paddr_t abst_sys_end; /* end of sysBus window */
int abst_addr_shift;/* address shift */
int abst_size_shift;/* size shift */
int abst_flags; /* flags; see below */
};
#define ABST_BWX 0x01 /* use BWX to access the bus */
#define ABST_DENSE 0x02 /* space is dense */
/*
* Utility macros; INTERNAL USE ONLY.
@ -278,6 +299,10 @@ do { \
#define bus_space_subregion(t, h, o, s, hp) \
(*(t)->abs_subregion)((t)->abs_cookie, (h), (o), (s), (hp))
#define alpha_bus_space_translate(t, a, s, d, bs, be, ss, se, sh) \
(*(t)->abs_translate)((t)->abs_cookie, (a), (s), (d), (bs), (be), \
(ss), (se), (sh))
#define BUS_SPACE_MAP_CACHEABLE 0x01
#define BUS_SPACE_MAP_LINEAR 0x02
#define BUS_SPACE_MAP_PREFETCHABLE 0x04

View File

@ -1,7 +1,7 @@
/* $NetBSD: pci_bwx_bus_io_chipdep.c,v 1.6 1999/12/02 19:44:49 thorpej Exp $ */
/* $NetBSD: pci_bwx_bus_io_chipdep.c,v 1.7 2000/02/25 00:45:05 thorpej Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
* Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -97,6 +97,9 @@ void __C(CHIP,_io_unmap) __P((void *, bus_space_handle_t,
int __C(CHIP,_io_subregion) __P((void *, bus_space_handle_t,
bus_size_t, bus_size_t, bus_space_handle_t *));
int __C(CHIP,_io_translate) __P((void *, bus_addr_t, bus_size_t,
int, struct alpha_bus_space_translation *));
/* allocation/deallocation */
int __C(CHIP,_io_alloc) __P((void *, bus_addr_t, bus_addr_t,
bus_size_t, bus_size_t, bus_addr_t, int, bus_addr_t *,
@ -224,6 +227,8 @@ __C(CHIP,_bus_io_init)(t, v)
t->abs_unmap = __C(CHIP,_io_unmap);
t->abs_subregion = __C(CHIP,_io_subregion);
t->abs_translate = __C(CHIP,_io_translate);
/* allocation/deallocation */
t->abs_alloc = __C(CHIP,_io_alloc);
t->abs_free = __C(CHIP,_io_free);
@ -292,6 +297,32 @@ __C(CHIP,_bus_io_init)(t, v)
CHIP_IO_EXTENT(v) = ex;
}
int
__C(CHIP,_io_translate)(v, ioaddr, iolen, flags, abst)
void *v;
bus_addr_t ioaddr;
bus_size_t iolen;
int flags;
struct alpha_bus_space_translation *abst;
{
int linear = flags & BUS_SPACE_MAP_LINEAR;
/*
* Can't map i/o space linearly.
*/
if (linear)
return (EOPNOTSUPP);
abst->abst_bus_start = 0;
abst->abst_bus_end = 0xffffffffUL;
abst->abst_sys_start = CHIP_IO_SYS_START(v);
abst->abst_sys_end = CHIP_IO_SYS_START(v) + abst->abst_bus_end;
abst->abst_addr_shift = 0;
abst->abst_size_shift = 0;
abst->abst_flags = ABST_DENSE|ABST_BWX;
return (0);
}
int
__C(CHIP,_io_map)(v, ioaddr, iosize, flags, iohp, acct)
void *v;
@ -301,14 +332,15 @@ __C(CHIP,_io_map)(v, ioaddr, iosize, flags, iohp, acct)
bus_space_handle_t *iohp;
int acct;
{
int linear = flags & BUS_SPACE_MAP_LINEAR;
struct alpha_bus_space_translation abst;
int error;
/*
* Can't map i/o space linearly.
* Get the translation for this address.
*/
if (linear)
return (EOPNOTSUPP);
error = __C(CHIP,_io_translate)(v, ioaddr, iosize, flags, &abst);
if (error)
return (error);
if (acct == 0)
goto mapit;
@ -327,7 +359,7 @@ __C(CHIP,_io_map)(v, ioaddr, iosize, flags, iohp, acct)
}
mapit:
*iohp = ALPHA_PHYS_TO_K0SEG(CHIP_IO_SYS_START(v)) + ioaddr;
*iohp = ALPHA_PHYS_TO_K0SEG(abst.abst_sys_start + ioaddr);
return (0);
}
@ -386,6 +418,7 @@ __C(CHIP,_io_alloc)(v, rstart, rend, size, align, boundary, flags,
int flags;
bus_space_handle_t *bshp;
{
struct alpha_bus_space_translation abst;
int linear = flags & BUS_SPACE_MAP_LINEAR;
bus_addr_t ioaddr;
int error;
@ -418,8 +451,15 @@ __C(CHIP,_io_alloc)(v, rstart, rend, size, align, boundary, flags,
printf("io: allocated 0x%lx to 0x%lx\n", ioaddr, ioaddr + size - 1);
#endif
error = __C(CHIP,_io_translate)(v, ioaddr, size, flags, &abst);
if (error) {
(void) extent_free(CHIP_IO_EXTENT(v), ioaddr, size,
EX_NOWAIT | (CHIP_EX_MALLOC_SAFE(v) ? EX_MALLOCOK : 0));
return (error);
}
*addrp = ioaddr;
*bshp = ALPHA_PHYS_TO_K0SEG(CHIP_IO_SYS_START(v)) + ioaddr;
*bshp = ALPHA_PHYS_TO_K0SEG(abst.abst_sys_start + ioaddr);
return (0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pci_bwx_bus_mem_chipdep.c,v 1.7 2000/02/06 04:07:18 thorpej Exp $ */
/* $NetBSD: pci_bwx_bus_mem_chipdep.c,v 1.8 2000/02/25 00:45:05 thorpej Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@ -97,6 +97,9 @@ void __C(CHIP,_mem_unmap) __P((void *, bus_space_handle_t,
int __C(CHIP,_mem_subregion) __P((void *, bus_space_handle_t,
bus_size_t, bus_size_t, bus_space_handle_t *));
int __C(CHIP,_mem_translate) __P((void *, bus_addr_t, bus_size_t,
int, struct alpha_bus_space_translation *));
/* allocation/deallocation */
int __C(CHIP,_mem_alloc) __P((void *, bus_addr_t, bus_addr_t,
bus_size_t, bus_size_t, bus_addr_t, int, bus_addr_t *,
@ -224,6 +227,8 @@ __C(CHIP,_bus_mem_init)(t, v)
t->abs_unmap = __C(CHIP,_mem_unmap);
t->abs_subregion = __C(CHIP,_mem_subregion);
t->abs_translate = __C(CHIP,_mem_translate);
/* allocation/deallocation */
t->abs_alloc = __C(CHIP,_mem_alloc);
t->abs_free = __C(CHIP,_mem_free);
@ -292,6 +297,19 @@ __C(CHIP,_bus_mem_init)(t, v)
CHIP_MEM_EXTENT(v) = ex;
}
int
__C(CHIP,_mem_translate)(v, memaddr, memlen, flags, abst)
void *v;
bus_addr_t memaddr;
bus_size_t memlen;
int flags;
struct alpha_bus_space_translation *abst;
{
/* XXX */
return (EOPNOTSUPP);
}
int
__C(CHIP,_mem_map)(v, memaddr, memsize, flags, memhp, acct)
void *v;

View File

@ -1,7 +1,7 @@
/* $NetBSD: pci_swiz_bus_io_chipdep.c,v 1.28 1999/12/07 05:44:57 thorpej Exp $ */
/* $NetBSD: pci_swiz_bus_io_chipdep.c,v 1.29 2000/02/25 00:45:05 thorpej Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -95,6 +95,9 @@ void __C(CHIP,_io_unmap) __P((void *, bus_space_handle_t,
int __C(CHIP,_io_subregion) __P((void *, bus_space_handle_t,
bus_size_t, bus_size_t, bus_space_handle_t *));
int __C(CHIP,_io_translate) __P((void *, bus_addr_t, bus_size_t,
int, struct alpha_bus_space_translation *));
/* allocation/deallocation */
int __C(CHIP,_io_alloc) __P((void *, bus_addr_t, bus_addr_t,
bus_size_t, bus_size_t, bus_addr_t, int, bus_addr_t *,
@ -196,10 +199,6 @@ void __C(CHIP,_io_copy_region_4) __P((void *, bus_space_handle_t,
void __C(CHIP,_io_copy_region_8) __P((void *, bus_space_handle_t,
bus_size_t, bus_space_handle_t, bus_size_t, bus_size_t));
/* Internal */
void __C(CHIP,_io_mapit) __P((void *, bus_addr_t,
bus_space_handle_t *));
#ifndef CHIP_IO_EX_STORE
static long
__C(CHIP,_io_ex_storage)[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long)];
@ -234,6 +233,8 @@ __C(CHIP,_bus_io_init)(t, v)
t->abs_unmap = __C(CHIP,_io_unmap);
t->abs_subregion = __C(CHIP,_io_subregion);
t->abs_translate = __C(CHIP,_io_translate);
/* allocation/deallocation */
t->abs_alloc = __C(CHIP,_io_alloc);
t->abs_free = __C(CHIP,_io_free);
@ -324,42 +325,64 @@ __C(CHIP,_bus_io_init)(t, v)
CHIP_IO_EXTENT(v) = ex;
}
void
__C(CHIP,_io_mapit)(v, ioaddr, iohp)
int
__C(CHIP,_io_translate)(v, ioaddr, iolen, flags, abst)
void *v;
bus_addr_t ioaddr;
bus_space_handle_t *iohp;
bus_size_t iolen;
int flags;
struct alpha_bus_space_translation *abst;
{
bus_addr_t ioend = ioaddr + (iolen - 1);
int linear = flags & BUS_SPACE_MAP_LINEAR;
/*
* Can't map i/o space linearly.
*/
if (linear)
return (EOPNOTSUPP);
#ifdef CHIP_IO_W1_BUS_START
if (ioaddr >= CHIP_IO_W1_BUS_START(v) &&
ioaddr <= CHIP_IO_W1_BUS_END(v)) {
*iohp = (ALPHA_PHYS_TO_K0SEG(CHIP_IO_W1_SYS_START(v)) >>
CHIP_ADDR_SHIFT) + (ioaddr - CHIP_IO_W1_BUS_START(v));
} else
ioend <= CHIP_IO_W1_BUS_END(v)) {
abst->abst_bus_start = CHIP_IO_W1_BUS_START(v);
abst->abst_bus_end = CHIP_IO_W1_BUS_END(v);
abst->abst_sys_start = CHIP_IO_W1_SYS_START(v);
abst->abst_sys_end = CHIP_IO_W1_SYS_END(v);
abst->abst_addr_shift = CHIP_ADDR_SHIFT;
abst->abst_size_shift = CHIP_SIZE_SHIFT;
abst->abst_flags = 0;
return (0);
}
#endif
#ifdef CHIP_IO_W2_BUS_START
if (ioaddr >= CHIP_IO_W2_BUS_START(v) &&
ioaddr <= CHIP_IO_W2_BUS_END(v)) {
*iohp = (ALPHA_PHYS_TO_K0SEG(CHIP_IO_W2_SYS_START(v)) >>
CHIP_ADDR_SHIFT) + (ioaddr - CHIP_IO_W2_BUS_START(v));
} else
ioend <= CHIP_IO_W2_BUS_END(v)) {
abst->abst_bus_start = CHIP_IO_W2_BUS_START(v);
abst->abst_bus_end = CHIP_IO_W2_BUS_END(v);
abst->abst_sys_start = CHIP_IO_W2_SYS_START(v);
abst->abst_sys_end = CHIP_IO_W2_SYS_END(v);
abst->abst_addr_shift = CHIP_ADDR_SHIFT;
abst->abst_size_shift = CHIP_SIZE_SHIFT;
abst->abst_flags = 0;
return (0);
}
#endif
{
printf("\n");
#ifdef EXTENT_DEBUG
printf("\n");
#ifdef CHIP_IO_W1_BUS_START
printf("%s: window[1]=0x%lx-0x%lx\n",
__S(__C(CHIP,_io_map)), CHIP_IO_W1_BUS_START(v),
CHIP_IO_W1_BUS_END(v));
printf("%s: window[1]=0x%lx-0x%lx\n",
__S(__C(CHIP,_io_map)), CHIP_IO_W1_BUS_START(v),
CHIP_IO_W1_BUS_END(v));
#endif
#ifdef CHIP_IO_W2_BUS_START
printf("%s: window[2]=0x%lx-0x%lx\n",
__S(__C(CHIP,_io_map)), CHIP_IO_W2_BUS_START(v),
CHIP_IO_W2_BUS_END(v));
printf("%s: window[2]=0x%lx-0x%lx\n",
__S(__C(CHIP,_io_map)), CHIP_IO_W2_BUS_START(v),
CHIP_IO_W2_BUS_END(v));
#endif
panic("%s: don't know how to map %lx",
__S(__C(CHIP,_io_mapit)), ioaddr);
}
#endif /* EXTENT_DEBUG */
/* No translation. */
return (EINVAL);
}
int
@ -371,25 +394,18 @@ __C(CHIP,_io_map)(v, ioaddr, iosize, flags, iohp, acct)
bus_space_handle_t *iohp;
int acct;
{
int linear = flags & BUS_SPACE_MAP_LINEAR;
struct alpha_bus_space_translation abst;
int error;
/*
* Can't map i/o space linearly.
* Get the translation for this address.
*/
if (linear)
return (EOPNOTSUPP);
error = __C(CHIP,_io_translate)(v, ioaddr, iosize, flags, &abst);
if (error)
return (error);
if (acct == 0) {
/*
* XXX We should ensure that the region is actually
* XXX mappable, but nothing should really be using
* XXX this interface (only ISA PnP does, and only
* XXX via a machine-dependent hook), so we don't
* XXX bother.
*/
if (acct == 0)
goto mapit;
}
#ifdef EXTENT_DEBUG
printf("io: allocating 0x%lx to 0x%lx\n", ioaddr, ioaddr + iosize - 1);
@ -405,7 +421,8 @@ __C(CHIP,_io_map)(v, ioaddr, iosize, flags, iohp, acct)
}
mapit:
__C(CHIP,_io_mapit)(v, ioaddr, iohp);
*iohp = (ALPHA_PHYS_TO_K0SEG(abst.abst_sys_start) >>
CHIP_ADDR_SHIFT) + (ioaddr - abst.abst_bus_start);
return (0);
}
@ -494,6 +511,7 @@ __C(CHIP,_io_alloc)(v, rstart, rend, size, align, boundary, flags,
int flags;
bus_space_handle_t *bshp;
{
struct alpha_bus_space_translation abst;
int linear = flags & BUS_SPACE_MAP_LINEAR;
bus_addr_t ioaddr;
int error;
@ -526,8 +544,16 @@ __C(CHIP,_io_alloc)(v, rstart, rend, size, align, boundary, flags,
printf("io: allocated 0x%lx to 0x%lx\n", ioaddr, ioaddr + size - 1);
#endif
error = __C(CHIP,_io_translate)(v, ioaddr, size, flags, &abst);
if (error) {
(void) extent_free(CHIP_IO_EXTENT(v), ioaddr, size,
EX_NOWAIT | (CHIP_EX_MALLOC_SAFE(v) ? EX_MALLOCOK : 0));
return (error);
}
*addrp = ioaddr;
__C(CHIP,_io_mapit)(v, ioaddr, bshp);
*bshp = (ALPHA_PHYS_TO_K0SEG(abst.abst_sys_start) >>
CHIP_ADDR_SHIFT) + (ioaddr - abst.abst_bus_start);
return (0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pci_swiz_bus_mem_chipdep.c,v 1.32 2000/02/06 03:52:27 elric Exp $ */
/* $NetBSD: pci_swiz_bus_mem_chipdep.c,v 1.33 2000/02/25 00:45:06 thorpej Exp $ */
/*
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
@ -68,6 +68,9 @@ void __C(CHIP,_mem_unmap) __P((void *, bus_space_handle_t,
int __C(CHIP,_mem_subregion) __P((void *, bus_space_handle_t,
bus_size_t, bus_size_t, bus_space_handle_t *));
int __C(CHIP,_mem_translate) __P((void *, bus_addr_t, bus_size_t,
int, struct alpha_bus_space_translation *));
/* allocation/deallocation */
int __C(CHIP,_mem_alloc) __P((void *, bus_addr_t, bus_addr_t,
bus_size_t, bus_size_t, bus_addr_t, int, bus_addr_t *,
@ -215,6 +218,8 @@ __C(CHIP,_bus_mem_init)(t, v)
t->abs_unmap = __C(CHIP,_mem_unmap);
t->abs_subregion = __C(CHIP,_mem_subregion);
t->abs_translate = __C(CHIP,_mem_translate);
/* allocation/deallocation */
t->abs_alloc = __C(CHIP,_mem_alloc);
t->abs_free = __C(CHIP,_mem_free);
@ -487,6 +492,19 @@ __C(CHIP,_xlate_sparse_handle_to_addr)(v, memh, memaddrp)
return (0);
}
int
__C(CHIP,_mem_translate)(v, memaddr, memlen, flags, abst)
void *v;
bus_addr_t memaddr;
bus_size_t memlen;
int flags;
struct alpha_bus_space_translation *abst;
{
/* XXX */
return (EOPNOTSUPP);
}
int
__C(CHIP,_mem_map)(v, memaddr, memsize, flags, memhp, acct)
void *v;

View File

@ -1,4 +1,4 @@
/* $NetBSD: tc_bus_mem.c,v 1.19 1999/03/12 22:59:23 perry Exp $ */
/* $NetBSD: tc_bus_mem.c,v 1.20 2000/02/25 00:45:06 thorpej Exp $ */
/*
* Copyright (c) 1996 Carnegie-Mellon University.
@ -33,7 +33,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: tc_bus_mem.c,v 1.19 1999/03/12 22:59:23 perry Exp $");
__KERNEL_RCSID(0, "$NetBSD: tc_bus_mem.c,v 1.20 2000/02/25 00:45:06 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -54,6 +54,9 @@ void tc_mem_unmap __P((void *, bus_space_handle_t, bus_size_t, int));
int tc_mem_subregion __P((void *, bus_space_handle_t, bus_size_t,
bus_size_t, bus_space_handle_t *));
int tc_mem_translate __P((void *, bus_addr_t, bus_size_t,
int, struct alpha_bus_space_translation *));
/* allocation/deallocation */
int tc_mem_alloc __P((void *, bus_addr_t, bus_addr_t, bus_size_t,
bus_size_t, bus_addr_t, int, bus_addr_t *,
@ -159,6 +162,8 @@ static struct alpha_bus_space tc_mem_space = {
tc_mem_unmap,
tc_mem_subregion,
tc_mem_translate,
/* allocation/deallocation */
tc_mem_alloc,
tc_mem_free,
@ -231,6 +236,19 @@ tc_bus_mem_init(memv)
return (h);
}
/* ARGSUSED */
int
tc_mem_translate(v, memaddr, memlen, flags, abst)
void *v;
bus_addr_t memaddr;
bus_size_t memlen;
int flags;
struct alpha_bus_space_translation *abst;
{
return (EOPNOTSUPP);
}
/* ARGSUSED */
int
tc_mem_map(v, memaddr, memsize, flags, memhp, acct)