Annotation of sys/arch/mvmeppc/mvmeppc/bus_space.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: bus_space.c,v 1.6 2004/01/29 12:00:32 miod Exp $ */
! 2: /* $NetBSD: bus_space.c,v 1.4 2001/06/15 15:50:05 nonaka Exp $ */
! 3:
! 4: /*-
! 5: * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
! 6: * All rights reserved.
! 7: *
! 8: * This code is derived from software contributed to The NetBSD Foundation
! 9: * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
! 10: * Simulation Facility, NASA Ames Research Center.
! 11: *
! 12: * Redistribution and use in source and binary forms, with or without
! 13: * modification, are permitted provided that the following conditions
! 14: * are met:
! 15: * 1. Redistributions of source code must retain the above copyright
! 16: * notice, this list of conditions and the following disclaimer.
! 17: * 2. Redistributions in binary form must reproduce the above copyright
! 18: * notice, this list of conditions and the following disclaimer in the
! 19: * documentation and/or other materials provided with the distribution.
! 20: * 3. All advertising materials mentioning features or use of this software
! 21: * must display the following acknowledgement:
! 22: * This product includes software developed by the NetBSD
! 23: * Foundation, Inc. and its contributors.
! 24: * 4. Neither the name of The NetBSD Foundation nor the names of its
! 25: * contributors may be used to endorse or promote products derived
! 26: * from this software without specific prior written permission.
! 27: *
! 28: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
! 29: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
! 30: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
! 31: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
! 32: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
! 33: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
! 34: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
! 35: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
! 36: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
! 37: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! 38: * POSSIBILITY OF SUCH DAMAGE.
! 39: */
! 40:
! 41: #include <sys/param.h>
! 42: #include <sys/systm.h>
! 43: #include <sys/kernel.h>
! 44: #include <sys/extent.h>
! 45: #include <sys/mbuf.h>
! 46:
! 47: #include <uvm/uvm_extern.h>
! 48:
! 49: #include <machine/bus.h>
! 50:
! 51: static int prep_memio_map(bus_space_tag_t, bus_addr_t, bus_size_t, int,
! 52: bus_space_handle_t *);
! 53: static void prep_memio_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t);
! 54: static int prep_memio_alloc(bus_space_tag_t, bus_addr_t, bus_addr_t,
! 55: bus_size_t, bus_size_t, bus_size_t, int, bus_addr_t *,
! 56: bus_space_handle_t *);
! 57: static void prep_memio_free(bus_space_tag_t, bus_space_handle_t, bus_size_t);
! 58:
! 59: const struct ppc_bus_space prep_io_space_tag = {
! 60: PREP_BUS_SPACE_IO, 0x80000000, 0x80000000, 0x3f800000,
! 61: prep_memio_map, prep_memio_unmap, prep_memio_alloc, prep_memio_free
! 62: };
! 63: const struct ppc_bus_space prep_isa_io_space_tag = {
! 64: PREP_BUS_SPACE_IO, 0x80000000, 0x80000000, 0x00010000,
! 65: prep_memio_map, prep_memio_unmap, prep_memio_alloc, prep_memio_free
! 66: };
! 67: const struct ppc_bus_space prep_mem_space_tag = {
! 68: PREP_BUS_SPACE_MEM, 0xC0000000, 0xC0000000, 0x3f000000,
! 69: prep_memio_map, prep_memio_unmap, prep_memio_alloc, prep_memio_free
! 70: };
! 71: const struct ppc_bus_space prep_isa_mem_space_tag = {
! 72: PREP_BUS_SPACE_MEM, 0xC0000000, 0xC0000000, 0x01000000,
! 73: prep_memio_map, prep_memio_unmap, prep_memio_alloc, prep_memio_free
! 74: };
! 75: static long ioport_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long)];
! 76: static long iomem_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long)];
! 77:
! 78: struct extent *ioport_ex;
! 79: struct extent *iomem_ex;
! 80:
! 81: static int ioport_malloc_safe;
! 82:
! 83: void
! 84: prep_bus_space_init()
! 85: {
! 86: int error;
! 87:
! 88: ioport_ex = extent_create("ioport", 0, 0x3f7fffff, M_DEVBUF,
! 89: (caddr_t)ioport_ex_storage, sizeof(ioport_ex_storage),
! 90: EX_NOCOALESCE|EX_NOWAIT);
! 91: error = extent_alloc_region(ioport_ex, 0x10000, 0x7F0000, EX_NOWAIT);
! 92: if (error)
! 93: panic("prep_bus_space_init: can't block out reserved I/O space 0x10000-0x7fffff: error=%d", error);
! 94: iomem_ex = extent_create("iomem", 0, 0x3effffff, M_DEVBUF,
! 95: (caddr_t)iomem_ex_storage, sizeof(iomem_ex_storage),
! 96: EX_NOCOALESCE|EX_NOWAIT);
! 97: }
! 98:
! 99: void
! 100: prep_bus_space_mallocok()
! 101: {
! 102:
! 103: ioport_malloc_safe = 1;
! 104: }
! 105:
! 106: static int
! 107: prep_memio_map(t, bpa, size, flags, bshp)
! 108: bus_space_tag_t t;
! 109: bus_addr_t bpa;
! 110: bus_size_t size;
! 111: int flags;
! 112: bus_space_handle_t *bshp;
! 113: {
! 114: int error;
! 115: struct extent *ex;
! 116:
! 117: if (bpa + size > t->pbs_limit)
! 118: return (EINVAL);
! 119: /*
! 120: * Pick the appropriate extent map.
! 121: */
! 122: if (t->pbs_type == PREP_BUS_SPACE_IO) {
! 123: if (flags & BUS_SPACE_MAP_LINEAR)
! 124: return (EOPNOTSUPP);
! 125: ex = ioport_ex;
! 126: } else if (t->pbs_type == PREP_BUS_SPACE_MEM) {
! 127: ex = iomem_ex;
! 128: } else
! 129: panic("prep_memio_map: bad bus space tag");
! 130:
! 131: /*
! 132: * Before we go any further, let's make sure that this
! 133: * region is available.
! 134: */
! 135: if ((error = extent_alloc_region(ex, bpa, size,
! 136: EX_NOWAIT | (ioport_malloc_safe ? EX_MALLOCOK : 0))) != 0)
! 137: return (error);
! 138:
! 139: *bshp = (bus_space_handle_t)mapiodev(t->pbs_base + bpa, size);
! 140:
! 141: return (0);
! 142: }
! 143:
! 144: static void
! 145: prep_memio_unmap(t, bsh, size)
! 146: bus_space_tag_t t;
! 147: bus_space_handle_t bsh;
! 148: bus_size_t size;
! 149: {
! 150: struct extent *ex;
! 151: bus_addr_t bpa;
! 152:
! 153: /*
! 154: * Find the correct extent and bus physical address.
! 155: */
! 156: if (t->pbs_type == PREP_BUS_SPACE_IO)
! 157: ex = ioport_ex;
! 158: else if (t->pbs_type == PREP_BUS_SPACE_MEM)
! 159: ex = iomem_ex;
! 160: else
! 161: panic("prep_memio_unmap: bad bus space tag");
! 162:
! 163: pmap_extract(pmap_kernel(), (vaddr_t)bsh, (paddr_t *)&bpa);
! 164: unmapiodev((void *)bsh, size);
! 165:
! 166: if (extent_free(ex, bpa, size,
! 167: EX_NOWAIT | (ioport_malloc_safe ? EX_MALLOCOK : 0))) {
! 168: printf("prep_memio_unmap: %s 0x%lx, size 0x%lx\n",
! 169: (t->pbs_type == PREP_BUS_SPACE_IO) ? "port" : "mem",
! 170: (unsigned long)bpa, (unsigned long)size);
! 171: printf("prep_memio_unmap: can't free region\n");
! 172: }
! 173: }
! 174:
! 175: static int
! 176: prep_memio_alloc(t, rstart, rend, size, alignment, boundary, flags,
! 177: bpap, bshp)
! 178: bus_space_tag_t t;
! 179: bus_addr_t rstart, rend;
! 180: bus_size_t size, alignment, boundary;
! 181: int flags;
! 182: bus_addr_t *bpap;
! 183: bus_space_handle_t *bshp;
! 184: {
! 185: struct extent *ex;
! 186: u_long bpa;
! 187: int error;
! 188:
! 189: if (rstart + size > t->pbs_limit)
! 190: return (EINVAL);
! 191:
! 192: if (t->pbs_type == PREP_BUS_SPACE_IO) {
! 193: if (flags & BUS_SPACE_MAP_LINEAR)
! 194: return (EOPNOTSUPP);
! 195: ex = ioport_ex;
! 196: } else if (t->pbs_type == PREP_BUS_SPACE_MEM) {
! 197: ex = iomem_ex;
! 198: } else
! 199: panic("prep_memio_alloc: bad bus space tag");
! 200:
! 201: if (rstart < ex->ex_start || rend > ex->ex_end)
! 202: panic("prep_memio_alloc: bad region start/end");
! 203:
! 204: error = extent_alloc_subregion(ex, rstart, rend, size, alignment, 0,
! 205: boundary,
! 206: EX_FAST | EX_NOWAIT | (ioport_malloc_safe ? EX_MALLOCOK : 0),
! 207: &bpa);
! 208:
! 209: if (error)
! 210: return (error);
! 211:
! 212: *bpap = bpa;
! 213: *bshp = t->pbs_base + bpa;
! 214:
! 215: return (0);
! 216: }
! 217:
! 218: static void
! 219: prep_memio_free(t, bsh, size)
! 220: bus_space_tag_t t;
! 221: bus_space_handle_t bsh;
! 222: bus_size_t size;
! 223: {
! 224:
! 225: /* prep_memio_unmap() does all that we need to do. */
! 226: prep_memio_unmap(t, bsh, size);
! 227: }
CVSweb