2 * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
7 * NASA Ames Research Center.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 * Copyright (c) 1992, 1993
32 * The Regents of the University of California. All rights reserved.
34 * This software was developed by the Computer Systems Engineering group
35 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
36 * contributed to Berkeley.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * Copyright (c) 1997, 1998 Justin T. Gibbs.
64 * All rights reserved.
65 * Copyright 2001 by Thomas Moestl <tmm@FreeBSD.org>. All rights reserved.
67 * Redistribution and use in source and binary forms, with or without
68 * modification, are permitted provided that the following conditions
70 * 1. Redistributions of source code must retain the above copyright
71 * notice, this list of conditions, and the following disclaimer,
72 * without modification, immediately at the beginning of the file.
73 * 2. The name of the author may not be used to endorse or promote products
74 * derived from this software without specific prior written permission.
76 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
77 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
78 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
79 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
80 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
81 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
82 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
83 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
84 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
85 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
88 * from: @(#)machdep.c 8.6 (Berkeley) 1/14/94
89 * from: NetBSD: machdep.c,v 1.221 2008/04/28 20:23:37 martin Exp
91 * from: FreeBSD: src/sys/i386/i386/busdma_machdep.c,v 1.24 2001/08/15
94 #include <sys/cdefs.h>
95 __FBSDID("$FreeBSD$");
97 #include <sys/param.h>
100 #include <sys/malloc.h>
101 #include <sys/mbuf.h>
102 #include <sys/mutex.h>
103 #include <sys/proc.h>
104 #include <sys/rman.h>
106 #include <sys/systm.h>
110 #include <vm/vm_extern.h>
111 #include <vm/vm_kern.h>
112 #include <vm/vm_page.h>
113 #include <vm/vm_param.h>
114 #include <vm/vm_map.h>
116 #include <machine/asi.h>
117 #include <machine/atomic.h>
118 #include <machine/bus.h>
119 #include <machine/bus_private.h>
120 #include <machine/cache.h>
121 #include <machine/smp.h>
122 #include <machine/tlb.h>
124 static void nexus_bus_barrier(bus_space_tag_t, bus_space_handle_t,
125 bus_size_t, bus_size_t, int);
127 /* ASIs for bus access */
128 const int bus_type_asi[] = {
129 ASI_PHYS_BYPASS_EC_WITH_EBIT, /* nexus */
130 ASI_PHYS_BYPASS_EC_WITH_EBIT, /* SBus */
131 ASI_PHYS_BYPASS_EC_WITH_EBIT_L, /* PCI configuration space */
132 ASI_PHYS_BYPASS_EC_WITH_EBIT_L, /* PCI memory space */
133 ASI_PHYS_BYPASS_EC_WITH_EBIT_L, /* PCI I/O space */
137 const int bus_stream_asi[] = {
138 ASI_PHYS_BYPASS_EC_WITH_EBIT, /* nexus */
139 ASI_PHYS_BYPASS_EC_WITH_EBIT, /* SBus */
140 ASI_PHYS_BYPASS_EC_WITH_EBIT, /* PCI configuration space */
141 ASI_PHYS_BYPASS_EC_WITH_EBIT, /* PCI memory space */
142 ASI_PHYS_BYPASS_EC_WITH_EBIT, /* PCI I/O space */
147 * Convenience function for manipulating driver locks from busdma (during
148 * busdma_swi, for example). Drivers that don't provide their own locks
149 * should specify &Giant to dmat->lockfuncarg. Drivers that use their own
150 * non-mutex locking scheme don't have to use this at all.
153 busdma_lock_mutex(void *arg, bus_dma_lock_op_t op)
157 dmtx = (struct mtx *)arg;
166 panic("Unknown operation 0x%x for busdma_lock_mutex!", op);
171 * dflt_lock should never get called. It gets put into the dma tag when
172 * lockfunc == NULL, which is only valid if the maps that are associated
173 * with the tag are meant to never be defered.
174 * XXX Should have a way to identify which driver is responsible here.
177 dflt_lock(void *arg, bus_dma_lock_op_t op)
180 panic("driver error: busdma dflt_lock called");
184 * Allocate a device specific dma_tag.
187 bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment,
188 bus_addr_t boundary, bus_addr_t lowaddr, bus_addr_t highaddr,
189 bus_dma_filter_t *filter, void *filterarg, bus_size_t maxsize,
190 int nsegments, bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc,
191 void *lockfuncarg, bus_dma_tag_t *dmat)
193 bus_dma_tag_t newtag;
195 /* Return a NULL tag on failure */
198 /* Enforce the usage of BUS_GET_DMA_TAG(). */
200 panic("%s: parent DMA tag NULL", __func__);
202 newtag = (bus_dma_tag_t)malloc(sizeof(*newtag), M_DEVBUF, M_NOWAIT);
207 * The method table pointer and the cookie need to be taken over from
210 newtag->dt_cookie = parent->dt_cookie;
211 newtag->dt_mt = parent->dt_mt;
213 newtag->dt_parent = parent;
214 newtag->dt_alignment = alignment;
215 newtag->dt_boundary = boundary;
216 newtag->dt_lowaddr = trunc_page((vm_offset_t)lowaddr) + (PAGE_SIZE - 1);
217 newtag->dt_highaddr = trunc_page((vm_offset_t)highaddr) +
219 newtag->dt_filter = filter;
220 newtag->dt_filterarg = filterarg;
221 newtag->dt_maxsize = maxsize;
222 newtag->dt_nsegments = nsegments;
223 newtag->dt_maxsegsz = maxsegsz;
224 newtag->dt_flags = flags;
225 newtag->dt_ref_count = 1; /* Count ourselves */
226 newtag->dt_map_count = 0;
228 if (lockfunc != NULL) {
229 newtag->dt_lockfunc = lockfunc;
230 newtag->dt_lockfuncarg = lockfuncarg;
232 newtag->dt_lockfunc = dflt_lock;
233 newtag->dt_lockfuncarg = NULL;
236 newtag->dt_segments = NULL;
238 /* Take into account any restrictions imposed by our parent tag. */
239 newtag->dt_lowaddr = ulmin(parent->dt_lowaddr, newtag->dt_lowaddr);
240 newtag->dt_highaddr = ulmax(parent->dt_highaddr, newtag->dt_highaddr);
241 if (newtag->dt_boundary == 0)
242 newtag->dt_boundary = parent->dt_boundary;
243 else if (parent->dt_boundary != 0)
244 newtag->dt_boundary = ulmin(parent->dt_boundary,
245 newtag->dt_boundary);
246 atomic_add_int(&parent->dt_ref_count, 1);
248 if (newtag->dt_boundary > 0)
249 newtag->dt_maxsegsz = ulmin(newtag->dt_maxsegsz,
250 newtag->dt_boundary);
257 bus_dma_tag_destroy(bus_dma_tag_t dmat)
259 bus_dma_tag_t parent;
262 if (dmat->dt_map_count != 0)
264 while (dmat != NULL) {
265 parent = dmat->dt_parent;
266 atomic_subtract_int(&dmat->dt_ref_count, 1);
267 if (dmat->dt_ref_count == 0) {
268 if (dmat->dt_segments != NULL)
269 free(dmat->dt_segments, M_DEVBUF);
270 free(dmat, M_DEVBUF);
272 * Last reference count, so
273 * release our reference
274 * count on our parent.
284 /* Allocate/free a tag, and do the necessary management work. */
286 sparc64_dma_alloc_map(bus_dma_tag_t dmat, bus_dmamap_t *mapp)
289 if (dmat->dt_segments == NULL) {
290 dmat->dt_segments = (bus_dma_segment_t *)malloc(
291 sizeof(bus_dma_segment_t) * dmat->dt_nsegments, M_DEVBUF,
293 if (dmat->dt_segments == NULL)
296 *mapp = malloc(sizeof(**mapp), M_DEVBUF, M_NOWAIT | M_ZERO);
300 SLIST_INIT(&(*mapp)->dm_reslist);
301 dmat->dt_map_count++;
306 sparc64_dma_free_map(bus_dma_tag_t dmat, bus_dmamap_t map)
310 dmat->dt_map_count--;
314 nexus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
317 return (sparc64_dma_alloc_map(dmat, mapp));
321 nexus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map)
324 sparc64_dma_free_map(dmat, map);
329 * Utility function to load a linear buffer. lastaddrp holds state
330 * between invocations (for multiple-buffer loads). segp contains
331 * the starting segment on entrace, and the ending segment on exit.
332 * first indicates if this is the first invocation of this function.
335 _nexus_dmamap_load_buffer(bus_dma_tag_t dmat, void *buf, bus_size_t buflen,
336 struct thread *td, int flags, bus_addr_t *lastaddrp,
337 bus_dma_segment_t *segs, int *segp, int first)
340 bus_addr_t curaddr, lastaddr, baddr, bmask;
341 vm_offset_t vaddr = (vm_offset_t)buf;
346 pmap = vmspace_pmap(td->td_proc->p_vmspace);
350 lastaddr = *lastaddrp;
351 bmask = ~(dmat->dt_boundary - 1);
353 for (seg = *segp; buflen > 0 ; ) {
355 * Get the physical address for this segment.
358 curaddr = pmap_extract(pmap, vaddr);
360 curaddr = pmap_kextract(vaddr);
363 * Compute the segment size, and adjust counts.
365 sgsize = PAGE_SIZE - ((u_long)curaddr & PAGE_MASK);
366 if (sgsize > dmat->dt_maxsegsz)
367 sgsize = dmat->dt_maxsegsz;
372 * Make sure we don't cross any boundaries.
374 if (dmat->dt_boundary > 0) {
375 baddr = (curaddr + dmat->dt_boundary) & bmask;
376 if (sgsize > (baddr - curaddr))
377 sgsize = (baddr - curaddr);
381 * Insert chunk into a segment, coalescing with
382 * previous segment if possible.
385 segs[seg].ds_addr = curaddr;
386 segs[seg].ds_len = sgsize;
389 if (curaddr == lastaddr &&
390 (segs[seg].ds_len + sgsize) <= dmat->dt_maxsegsz &&
391 (dmat->dt_boundary == 0 ||
392 (segs[seg].ds_addr & bmask) == (curaddr & bmask)))
393 segs[seg].ds_len += sgsize;
395 if (++seg >= dmat->dt_nsegments)
397 segs[seg].ds_addr = curaddr;
398 segs[seg].ds_len = sgsize;
402 lastaddr = curaddr + sgsize;
408 *lastaddrp = lastaddr;
413 return (buflen != 0 ? EFBIG : 0); /* XXX better return value here? */
417 * Common function for loading a DMA map with a linear buffer. May
418 * be called by bus-specific DMA map load functions.
420 * Most SPARCs have IOMMUs in the bus controllers. In those cases
421 * they only need one segment and will use virtual addresses for DVMA.
422 * Those bus controllers should intercept these vectors and should
423 * *NEVER* call nexus_dmamap_load() which is used only by devices that
427 nexus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
428 bus_size_t buflen, bus_dmamap_callback_t *callback, void *callback_arg,
434 error = _nexus_dmamap_load_buffer(dmat, buf, buflen, NULL, flags,
435 &lastaddr, dmat->dt_segments, &nsegs, 1);
438 (*callback)(callback_arg, dmat->dt_segments, nsegs + 1, 0);
439 map->dm_flags |= DMF_LOADED;
441 (*callback)(callback_arg, NULL, 0, error);
447 * Like nexus_dmamap_load(), but for mbufs.
450 nexus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map, struct mbuf *m0,
451 bus_dmamap_callback2_t *callback, void *callback_arg, int flags)
459 if (m0->m_pkthdr.len <= dmat->dt_maxsize) {
461 bus_addr_t lastaddr = 0;
464 for (m = m0; m != NULL && error == 0; m = m->m_next) {
466 error = _nexus_dmamap_load_buffer(dmat,
467 m->m_data, m->m_len,NULL, flags, &lastaddr,
468 dmat->dt_segments, &nsegs, first);
477 /* force "no valid mappings" in callback */
478 (*callback)(callback_arg, dmat->dt_segments, 0, 0, error);
480 map->dm_flags |= DMF_LOADED;
481 (*callback)(callback_arg, dmat->dt_segments, nsegs + 1,
482 m0->m_pkthdr.len, error);
488 nexus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map, struct mbuf *m0,
489 bus_dma_segment_t *segs, int *nsegs, int flags)
497 if (m0->m_pkthdr.len <= dmat->dt_maxsize) {
499 bus_addr_t lastaddr = 0;
502 for (m = m0; m != NULL && error == 0; m = m->m_next) {
504 error = _nexus_dmamap_load_buffer(dmat,
505 m->m_data, m->m_len,NULL, flags, &lastaddr,
519 * Like nexus_dmamap_load(), but for uios.
522 nexus_dmamap_load_uio(bus_dma_tag_t dmat, bus_dmamap_t map, struct uio *uio,
523 bus_dmamap_callback2_t *callback, void *callback_arg, int flags)
526 int nsegs, error, first, i;
529 struct thread *td = NULL;
531 resid = uio->uio_resid;
534 if (uio->uio_segflg == UIO_USERSPACE) {
536 KASSERT(td != NULL, ("%s: USERSPACE but no proc", __func__));
542 for (i = 0; i < uio->uio_iovcnt && resid != 0 && !error; i++) {
544 * Now at the first iovec to load. Load each iovec
545 * until we have exhausted the residual count.
548 resid < iov[i].iov_len ? resid : iov[i].iov_len;
549 caddr_t addr = (caddr_t) iov[i].iov_base;
552 error = _nexus_dmamap_load_buffer(dmat, addr, minlen,
553 td, flags, &lastaddr, dmat->dt_segments, &nsegs,
562 /* force "no valid mappings" in callback */
563 (*callback)(callback_arg, dmat->dt_segments, 0, 0, error);
565 map->dm_flags |= DMF_LOADED;
566 (*callback)(callback_arg, dmat->dt_segments, nsegs + 1,
567 uio->uio_resid, error);
573 * Common function for unloading a DMA map. May be called by
574 * bus-specific DMA map unload functions.
577 nexus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
580 map->dm_flags &= ~DMF_LOADED;
584 * Common function for DMA map synchronization. May be called
585 * by bus-specific DMA map synchronization functions.
588 nexus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
592 * We sync out our caches, but the bus must do the same.
594 * Actually a #Sync is expensive. We should optimize.
596 if ((op & BUS_DMASYNC_PREREAD) || (op & BUS_DMASYNC_PREWRITE)) {
598 * Don't really need to do anything, but flush any pending
603 if (op & BUS_DMASYNC_POSTWRITE) {
604 /* Nothing to do. Handled by the bus controller. */
609 * Common function for DMA-safe memory allocation. May be called
610 * by bus-specific DMA memory allocation functions.
613 nexus_dmamem_alloc(bus_dma_tag_t dmat, void **vaddr, int flags,
618 if (flags & BUS_DMA_NOWAIT)
622 if (flags & BUS_DMA_ZERO)
627 * (dmat->dt_alignment < dmat->dt_maxsize) is just a quick hack; the
628 * exact alignment guarantees of malloc need to be nailed down, and
629 * the code below should be rewritten to take that into account.
631 * In the meantime, we'll warn the user if malloc gets it wrong.
633 if (dmat->dt_maxsize <= PAGE_SIZE &&
634 dmat->dt_alignment < dmat->dt_maxsize)
635 *vaddr = malloc(dmat->dt_maxsize, M_DEVBUF, mflags);
638 * XXX use contigmalloc until it is merged into this
639 * facility and handles multi-seg allocations. Nobody
640 * is doing multi-seg allocations yet though.
642 *vaddr = contigmalloc(dmat->dt_maxsize, M_DEVBUF, mflags,
643 0ul, dmat->dt_lowaddr,
644 dmat->dt_alignment ? dmat->dt_alignment : 1UL,
649 if (vtophys(*vaddr) % dmat->dt_alignment)
650 printf("%s: failed to align memory properly.\n", __func__);
655 * Common function for freeing DMA-safe memory. May be called by
656 * bus-specific DMA memory free functions.
659 nexus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
662 if (dmat->dt_maxsize <= PAGE_SIZE &&
663 dmat->dt_alignment < dmat->dt_maxsize)
664 free(vaddr, M_DEVBUF);
666 contigfree(vaddr, dmat->dt_maxsize, M_DEVBUF);
669 static struct bus_dma_methods nexus_dma_methods = {
671 nexus_dmamap_destroy,
673 nexus_dmamap_load_mbuf,
674 nexus_dmamap_load_mbuf_sg,
675 nexus_dmamap_load_uio,
682 struct bus_dma_tag nexus_dmatag = {
704 * Helpers to map/unmap bus memory
707 bus_space_map(bus_space_tag_t tag, bus_addr_t address, bus_size_t size,
708 int flags, bus_space_handle_t *handlep)
711 return (sparc64_bus_mem_map(tag, address, size, flags, 0, handlep));
715 sparc64_bus_mem_map(bus_space_tag_t tag, bus_addr_t addr, bus_size_t size,
716 int flags, vm_offset_t vaddr, bus_space_handle_t *hp)
725 * Given that we use physical access for bus_space(9) there's no need
726 * need to map anything in unless BUS_SPACE_MAP_LINEAR is requested.
728 if ((flags & BUS_SPACE_MAP_LINEAR) == 0) {
733 if (tag->bst_cookie == NULL) {
734 printf("%s: resource cookie not set\n", __func__);
738 size = round_page(size);
740 printf("%s: zero size\n", __func__);
744 switch (tag->bst_type) {
745 case PCI_CONFIG_BUS_SPACE:
746 case PCI_IO_BUS_SPACE:
747 case PCI_MEMORY_BUS_SPACE:
755 if ((flags & BUS_SPACE_MAP_CACHEABLE) == 0)
759 sva = trunc_page(vaddr);
761 if ((sva = kmem_alloc_nofault(kernel_map, size)) == 0)
762 panic("%s: cannot allocate virtual memory", __func__);
765 pa = trunc_page(addr);
766 if ((flags & BUS_SPACE_MAP_READONLY) == 0)
772 pmap_kenter_flags(va, pa, pm_flags);
775 } while ((vsz -= PAGE_SIZE) > 0);
776 tlb_range_demap(kernel_pmap, sva, sva + size - 1);
778 /* Note: we preserve the page offset. */
779 rman_set_virtual(tag->bst_cookie, (void *)(sva | (addr & PAGE_MASK)));
784 bus_space_unmap(bus_space_tag_t tag, bus_space_handle_t handle,
788 sparc64_bus_mem_unmap(tag, handle, size);
792 sparc64_bus_mem_unmap(bus_space_tag_t tag, bus_space_handle_t handle,
799 if (tag->bst_cookie == NULL ||
800 (sva = (vm_offset_t)rman_get_virtual(tag->bst_cookie)) == 0)
802 sva = trunc_page(sva);
803 endva = sva + round_page(size);
804 for (va = sva; va < endva; va += PAGE_SIZE)
805 pmap_kremove_flags(va);
806 tlb_range_demap(kernel_pmap, sva, sva + size - 1);
807 kmem_free(kernel_map, sva, size);
812 * Fake up a bus tag, for use by console drivers in early boot when the
813 * regular means to allocate resources are not yet available.
814 * Addr is the physical address of the desired start of the handle.
817 sparc64_fake_bustag(int space, bus_addr_t addr, struct bus_space_tag *ptag)
820 ptag->bst_cookie = NULL;
821 ptag->bst_parent = NULL;
822 ptag->bst_type = space;
823 ptag->bst_bus_barrier = nexus_bus_barrier;
828 * Allocate a bus tag.
831 sparc64_alloc_bus_tag(void *cookie, struct bus_space_tag *ptag, int type,
836 bt = malloc(sizeof(struct bus_space_tag), M_DEVBUF, M_NOWAIT);
839 bt->bst_cookie = cookie;
840 bt->bst_parent = ptag;
842 bt->bst_bus_barrier = barrier;
847 * Base bus space handlers.
851 nexus_bus_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset,
852 bus_size_t size, int flags)
856 * We have lots of alternatives depending on whether we're
857 * synchronizing loads with loads, loads with stores, stores
858 * with loads, or stores with stores. The only ones that seem
859 * generic are #Sync and #MemIssue. I'll use #Sync for safety.
862 case BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE:
863 case BUS_SPACE_BARRIER_READ:
864 case BUS_SPACE_BARRIER_WRITE:
868 panic("%s: unknown flags", __func__);
873 struct bus_space_tag nexus_bustag = {
875 NULL, /* parent bus tag */
876 NEXUS_BUS_SPACE, /* type */
877 nexus_bus_barrier, /* bus_space_barrier */