1 1.10 andvar /* $NetBSD: jensenio_dma.c,v 1.10 2021/08/17 22:00:27 andvar Exp $ */ 2 1.1 thorpej 3 1.1 thorpej /*- 4 1.7 thorpej * Copyright (c) 2000, 2020 The NetBSD Foundation, Inc. 5 1.1 thorpej * All rights reserved. 6 1.1 thorpej * 7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation 8 1.1 thorpej * by Jason R. Thorpe. 9 1.1 thorpej * 10 1.1 thorpej * Redistribution and use in source and binary forms, with or without 11 1.1 thorpej * modification, are permitted provided that the following conditions 12 1.1 thorpej * are met: 13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright 14 1.1 thorpej * notice, this list of conditions and the following disclaimer. 15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the 17 1.1 thorpej * documentation and/or other materials provided with the distribution. 18 1.1 thorpej * 19 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE. 30 1.1 thorpej */ 31 1.1 thorpej 32 1.1 thorpej /* 33 1.1 thorpej * DMA support for the Jensen system. 34 1.1 thorpej * 35 1.1 thorpej * The Jensen uses direct-mapped DMA with a window base of 0, i.e. 36 1.10 andvar * a page of physical memory has the same PCI address as CPU address. 37 1.1 thorpej * There is no support for SGMAPs on the Jensen. This means that for 38 1.1 thorpej * ISA DMA, we must employ bounce buffers for DMA transactions over 39 1.1 thorpej * 16MB ISA limit (due to ISA's 24-bit address space limitation). 40 1.1 thorpej * 41 1.1 thorpej * Furthermore, the H_BUS will not respond to DMA transactions between 42 1.1 thorpej * 512KB and 1MB. This is to allow for the ISA `hole'. However, the 43 1.1 thorpej * ISA `hole' typically exists only between 640KB and 1MB. We must 44 1.1 thorpej * therefore bounce transactions that fall within this region, as well. 45 1.1 thorpej * XXX Should we prevent having managed memory in this region, instead? 46 1.1 thorpej */ 47 1.1 thorpej 48 1.1 thorpej #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 49 1.1 thorpej 50 1.10 andvar __KERNEL_RCSID(0, "$NetBSD: jensenio_dma.c,v 1.10 2021/08/17 22:00:27 andvar Exp $"); 51 1.1 thorpej 52 1.1 thorpej #include <sys/param.h> 53 1.1 thorpej #include <sys/systm.h> 54 1.1 thorpej #include <sys/kernel.h> 55 1.1 thorpej #include <sys/device.h> 56 1.1 thorpej #include <sys/mbuf.h> 57 1.1 thorpej 58 1.1 thorpej #define _ALPHA_BUS_DMA_PRIVATE 59 1.4 dyoung #include <sys/bus.h> 60 1.1 thorpej 61 1.1 thorpej #include <dev/eisa/eisavar.h> 62 1.1 thorpej 63 1.1 thorpej #include <dev/isa/isavar.h> 64 1.1 thorpej 65 1.1 thorpej #include <alpha/jensenio/jenseniovar.h> 66 1.1 thorpej 67 1.7 thorpej #include <machine/alpha.h> 68 1.7 thorpej 69 1.8 thorpej static bus_dma_tag_t jensenio_dma_get_tag(bus_dma_tag_t, alpha_bus_t); 70 1.1 thorpej 71 1.1 thorpej void 72 1.7 thorpej jensenio_page_physload(unsigned long const start_pfn, 73 1.7 thorpej unsigned long const end_pfn) 74 1.7 thorpej { 75 1.7 thorpej /* 76 1.7 thorpej * The Jensen does not have SGMAP DMA. For this reason, we 77 1.7 thorpej * need to protect the first 16MB of RAM from random allocations 78 1.7 thorpej * in order to give ISA DMA a snowball's chance of working. 79 1.7 thorpej */ 80 1.7 thorpej alpha_page_physload_sheltered(start_pfn, end_pfn, 81 1.7 thorpej 0, alpha_btop(0x1000000)); 82 1.7 thorpej } 83 1.7 thorpej 84 1.7 thorpej void 85 1.1 thorpej jensenio_dma_init(struct jensenio_config *jcp) 86 1.1 thorpej { 87 1.1 thorpej bus_dma_tag_t t; 88 1.1 thorpej 89 1.1 thorpej /* 90 1.1 thorpej * Initialize the DMA tag used for EISA DMA. 91 1.1 thorpej */ 92 1.1 thorpej t = &jcp->jc_dmat_eisa; 93 1.1 thorpej t->_cookie = jcp; 94 1.1 thorpej t->_wbase = 0; 95 1.1 thorpej t->_wsize = 0x100000000UL; 96 1.1 thorpej t->_next_window = NULL; 97 1.1 thorpej t->_boundary = 0; 98 1.1 thorpej t->_sgmap = NULL; 99 1.1 thorpej t->_get_tag = jensenio_dma_get_tag; 100 1.1 thorpej t->_dmamap_create = _bus_dmamap_create; 101 1.1 thorpej t->_dmamap_destroy = _bus_dmamap_destroy; 102 1.1 thorpej t->_dmamap_load = _bus_dmamap_load_direct; 103 1.1 thorpej t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct; 104 1.1 thorpej t->_dmamap_load_uio = _bus_dmamap_load_uio_direct; 105 1.1 thorpej t->_dmamap_load_raw = _bus_dmamap_load_raw_direct; 106 1.1 thorpej t->_dmamap_unload = _bus_dmamap_unload; 107 1.1 thorpej t->_dmamap_sync = _bus_dmamap_sync; 108 1.1 thorpej 109 1.1 thorpej t->_dmamem_alloc = _bus_dmamem_alloc; 110 1.1 thorpej t->_dmamem_free = _bus_dmamem_free; 111 1.1 thorpej t->_dmamem_map = _bus_dmamem_map; 112 1.1 thorpej t->_dmamem_unmap = _bus_dmamem_unmap; 113 1.1 thorpej t->_dmamem_mmap = _bus_dmamem_mmap; 114 1.1 thorpej 115 1.1 thorpej /* 116 1.1 thorpej * Initialize the DMA tag used for ISA DMA. 117 1.1 thorpej */ 118 1.1 thorpej t = &jcp->jc_dmat_isa; 119 1.1 thorpej t->_cookie = jcp; 120 1.1 thorpej t->_wbase = 0; 121 1.1 thorpej t->_wsize = 0x1000000; 122 1.1 thorpej t->_next_window = NULL; 123 1.1 thorpej t->_boundary = 0; 124 1.1 thorpej t->_sgmap = NULL; 125 1.5 matt t->_get_tag = jensenio_dma_get_tag; 126 1.1 thorpej t->_dmamap_create = isadma_bounce_dmamap_create; 127 1.1 thorpej t->_dmamap_destroy = isadma_bounce_dmamap_destroy; 128 1.1 thorpej t->_dmamap_load = isadma_bounce_dmamap_load; 129 1.1 thorpej t->_dmamap_load_mbuf = isadma_bounce_dmamap_load_mbuf; 130 1.1 thorpej t->_dmamap_load_uio = isadma_bounce_dmamap_load_uio; 131 1.1 thorpej t->_dmamap_load_raw = isadma_bounce_dmamap_load_raw; 132 1.1 thorpej t->_dmamap_unload = isadma_bounce_dmamap_unload; 133 1.1 thorpej t->_dmamap_sync = isadma_bounce_dmamap_sync; 134 1.1 thorpej 135 1.1 thorpej t->_dmamem_alloc = isadma_bounce_dmamem_alloc; 136 1.1 thorpej t->_dmamem_free = _bus_dmamem_free; 137 1.1 thorpej t->_dmamem_map = _bus_dmamem_map; 138 1.1 thorpej t->_dmamem_unmap = _bus_dmamem_unmap; 139 1.1 thorpej t->_dmamem_mmap = _bus_dmamem_mmap; 140 1.1 thorpej } 141 1.1 thorpej 142 1.1 thorpej /* 143 1.3 skrll * Return the bus dma tag to be used for the specified bus type. 144 1.1 thorpej * INTERNAL USE ONLY! 145 1.1 thorpej */ 146 1.8 thorpej static bus_dma_tag_t 147 1.1 thorpej jensenio_dma_get_tag(bus_dma_tag_t t, alpha_bus_t bustype) 148 1.1 thorpej { 149 1.1 thorpej struct jensenio_config *jcp = t->_cookie; 150 1.1 thorpej 151 1.1 thorpej switch (bustype) { 152 1.1 thorpej case ALPHA_BUS_EISA: 153 1.1 thorpej /* 154 1.1 thorpej * Busses capable of 32-bit DMA get the EISA DMA tag. 155 1.1 thorpej */ 156 1.1 thorpej return (&jcp->jc_dmat_eisa); 157 1.1 thorpej 158 1.1 thorpej case ALPHA_BUS_ISA: 159 1.1 thorpej /* 160 1.1 thorpej * Lame 24-bit busses have to bounce. 161 1.1 thorpej */ 162 1.1 thorpej return (&jcp->jc_dmat_isa); 163 1.1 thorpej 164 1.1 thorpej default: 165 1.1 thorpej panic("jensenio_dma_get_tag: shouldn't be here, really..."); 166 1.1 thorpej } 167 1.1 thorpej } 168