1 /* $NetBSD: obmem.c,v 1.29 2021/08/07 16:19:06 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1996 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Adam Glass and Gordon W. Ross. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * On-board MEMory (OBMEM) 34 * Used by frame buffers... 35 */ 36 37 #include <sys/cdefs.h> 38 __KERNEL_RCSID(0, "$NetBSD: obmem.c,v 1.29 2021/08/07 16:19:06 thorpej Exp $"); 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/device.h> 43 44 #include <uvm/uvm_extern.h> 45 46 #include <machine/autoconf.h> 47 #include <machine/bus.h> 48 #include <sun3/sun3/obmem.h> 49 50 static int obmem_match(device_t, cfdata_t, void *); 51 static void obmem_attach(device_t, device_t, void *); 52 53 struct obmem_softc { 54 device_t sc_dev; 55 bus_space_tag_t sc_bustag; 56 bus_dma_tag_t sc_dmatag; 57 }; 58 59 CFATTACH_DECL_NEW(obmem, sizeof(struct obmem_softc), 60 obmem_match, obmem_attach, NULL, NULL); 61 62 static int obmem_attached; 63 64 static int obmem_bus_map(bus_space_tag_t, bus_type_t, bus_addr_t, bus_size_t, 65 int, vaddr_t, bus_space_handle_t *); 66 static paddr_t obmem_bus_mmap(bus_space_tag_t, bus_type_t, bus_addr_t, off_t, 67 int, int); 68 69 static struct sun68k_bus_space_tag obmem_space_tag = { 70 NULL, /* cookie */ 71 NULL, /* parent bus space tag */ 72 obmem_bus_map, /* bus_space_map */ 73 NULL, /* bus_space_unmap */ 74 NULL, /* bus_space_subregion */ 75 NULL, /* bus_space_barrier */ 76 obmem_bus_mmap, /* bus_space_mmap */ 77 NULL, /* bus_intr_establish */ 78 NULL, /* bus_space_peek_N */ 79 NULL /* bus_space_poke_N */ 80 }; 81 82 static int 83 obmem_match(device_t parent, cfdata_t cf, void *aux) 84 { 85 struct confargs *ca = aux; 86 87 if (obmem_attached) 88 return 0; 89 90 if (ca->ca_bustype != BUS_OBMEM) 91 return 0; 92 93 if (ca->ca_name != NULL && strcmp(cf->cf_name, ca->ca_name) != 0) 94 return 0; 95 96 return 1; 97 } 98 99 static void 100 obmem_attach(device_t parent, device_t self, void *aux) 101 { 102 struct confargs *ca = aux; 103 struct obmem_softc *sc = device_private(self); 104 struct confargs obma; 105 106 obmem_attached = 1; 107 sc->sc_dev = self; 108 109 aprint_normal("\n"); 110 111 sc->sc_bustag = ca->ca_bustag; 112 sc->sc_dmatag = ca->ca_dmatag; 113 114 obmem_space_tag.cookie = sc; 115 obmem_space_tag.parent = sc->sc_bustag; 116 117 obma = *ca; 118 obma.ca_bustag = &obmem_space_tag; 119 120 /* We know ca_bustype == BUS_OBMEM */ 121 config_search(self, &obma, 122 CFARGS(.search = bus_scan)); 123 } 124 125 int 126 obmem_bus_map(bus_space_tag_t t, bus_type_t btype, bus_addr_t paddr, 127 bus_size_t size, int flags, vaddr_t vaddr, bus_space_handle_t *hp) 128 { 129 struct obmem_softc *sc = t->cookie; 130 131 return bus_space_map2(sc->sc_bustag, PMAP_OBMEM, paddr, size, flags, 132 vaddr, hp); 133 } 134 135 paddr_t 136 obmem_bus_mmap(bus_space_tag_t t, bus_type_t btype, bus_addr_t paddr, off_t off, 137 int prot, int flags) 138 { 139 struct obmem_softc *sc = t->cookie; 140 141 return bus_space_mmap2(sc->sc_bustag, PMAP_OBMEM, paddr, off, prot, 142 flags); 143 } 144