1*e6a4e4ebSskrll /* $NetBSD: bus_private.h,v 1.16 2022/01/22 15:10:32 skrll Exp $ */
21d12c531Syamt /* NetBSD: bus.h,v 1.8 2005/03/09 19:04:46 matt Exp */
31d12c531Syamt
41d12c531Syamt /*-
51d12c531Syamt * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
61d12c531Syamt * All rights reserved.
71d12c531Syamt *
81d12c531Syamt * This code is derived from software contributed to The NetBSD Foundation
91d12c531Syamt * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
101d12c531Syamt * NASA Ames Research Center.
111d12c531Syamt *
121d12c531Syamt * Redistribution and use in source and binary forms, with or without
131d12c531Syamt * modification, are permitted provided that the following conditions
141d12c531Syamt * are met:
151d12c531Syamt * 1. Redistributions of source code must retain the above copyright
161d12c531Syamt * notice, this list of conditions and the following disclaimer.
171d12c531Syamt * 2. Redistributions in binary form must reproduce the above copyright
181d12c531Syamt * notice, this list of conditions and the following disclaimer in the
191d12c531Syamt * documentation and/or other materials provided with the distribution.
201d12c531Syamt *
211d12c531Syamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
221d12c531Syamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
231d12c531Syamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
241d12c531Syamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
251d12c531Syamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
261d12c531Syamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
271d12c531Syamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
281d12c531Syamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
291d12c531Syamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
301d12c531Syamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
311d12c531Syamt * POSSIBILITY OF SUCH DAMAGE.
321d12c531Syamt */
331d12c531Syamt
341d12c531Syamt /*
351d12c531Syamt * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
361d12c531Syamt * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
371d12c531Syamt *
381d12c531Syamt * Redistribution and use in source and binary forms, with or without
391d12c531Syamt * modification, are permitted provided that the following conditions
401d12c531Syamt * are met:
411d12c531Syamt * 1. Redistributions of source code must retain the above copyright
421d12c531Syamt * notice, this list of conditions and the following disclaimer.
431d12c531Syamt * 2. Redistributions in binary form must reproduce the above copyright
441d12c531Syamt * notice, this list of conditions and the following disclaimer in the
451d12c531Syamt * documentation and/or other materials provided with the distribution.
461d12c531Syamt * 3. All advertising materials mentioning features or use of this software
471d12c531Syamt * must display the following acknowledgement:
481d12c531Syamt * This product includes software developed by Christopher G. Demetriou
491d12c531Syamt * for the NetBSD Project.
501d12c531Syamt * 4. The name of the author may not be used to endorse or promote products
511d12c531Syamt * derived from this software without specific prior written permission
521d12c531Syamt *
531d12c531Syamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
541d12c531Syamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
551d12c531Syamt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
561d12c531Syamt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
571d12c531Syamt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
581d12c531Syamt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
591d12c531Syamt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
601d12c531Syamt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
611d12c531Syamt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
621d12c531Syamt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
631d12c531Syamt */
641d12c531Syamt
651d12c531Syamt #if !defined(_X86_BUS_PRIVATE_H_)
661d12c531Syamt #define _X86_BUS_PRIVATE_H_
671d12c531Syamt
681d12c531Syamt /*
691d12c531Syamt * Cookie used for bounce buffers. A pointer to one of these it stashed in
701d12c531Syamt * the DMA map.
711d12c531Syamt */
721d12c531Syamt struct x86_bus_dma_cookie {
731d12c531Syamt int id_flags; /* flags; see below */
741d12c531Syamt
751d12c531Syamt /*
761d12c531Syamt * Information about the original buffer used during
771d12c531Syamt * DMA map syncs. Note that origibuflen is only used
781d12c531Syamt * for ID_BUFTYPE_LINEAR.
791d12c531Syamt */
801d12c531Syamt void *id_origbuf; /* pointer to orig buffer if
811d12c531Syamt bouncing */
821d12c531Syamt bus_size_t id_origbuflen; /* ...and size */
831d12c531Syamt int id_buftype; /* type of buffer */
841d12c531Syamt
851d12c531Syamt void *id_bouncebuf; /* pointer to the bounce buffer */
861d12c531Syamt bus_size_t id_bouncebuflen; /* ...and size */
871d12c531Syamt int id_nbouncesegs; /* number of valid bounce segs */
881d12c531Syamt bus_dma_segment_t id_bouncesegs[0]; /* array of bounce buffer
891d12c531Syamt physical memory segments */
901d12c531Syamt };
911d12c531Syamt
921d12c531Syamt /* id_flags */
931d12c531Syamt #define X86_DMA_MIGHT_NEED_BOUNCE 0x01 /* may need bounce buffers */
941d12c531Syamt #define X86_DMA_HAS_BOUNCE 0x02 /* has bounce buffers */
951d12c531Syamt #define X86_DMA_IS_BOUNCING 0x04 /* is bouncing current xfer */
961d12c531Syamt
971d12c531Syamt /* id_buftype */
981d12c531Syamt #define X86_DMA_BUFTYPE_INVALID 0
991d12c531Syamt #define X86_DMA_BUFTYPE_LINEAR 1
1001d12c531Syamt #define X86_DMA_BUFTYPE_MBUF 2
1011d12c531Syamt #define X86_DMA_BUFTYPE_UIO 3
1021d12c531Syamt #define X86_DMA_BUFTYPE_RAW 4
1031d12c531Syamt
1041d12c531Syamt /*
1051d12c531Syamt * default address translation macros, which are appropriate where
1061d12c531Syamt * paddr_t == bus_addr_t.
1071d12c531Syamt */
1081d12c531Syamt
1091d12c531Syamt #if !defined(_BUS_PHYS_TO_BUS)
1101d12c531Syamt #define _BUS_PHYS_TO_BUS(pa) ((bus_addr_t)(pa))
1111d12c531Syamt #endif /* !defined(_BUS_PHYS_TO_BUS) */
1121d12c531Syamt
113aeeb0b33Sbouyer #if !defined(_BUS_BUS_TO_PHYS)
114aeeb0b33Sbouyer #define _BUS_BUS_TO_PHYS(ba) ((paddr_t)(ba))
115aeeb0b33Sbouyer #endif /* !defined(_BUS_BUS_TO_PHYS) */
116aeeb0b33Sbouyer
1171d12c531Syamt #if !defined(_BUS_VM_PAGE_TO_BUS)
1181d12c531Syamt #define _BUS_VM_PAGE_TO_BUS(pg) _BUS_PHYS_TO_BUS(VM_PAGE_TO_PHYS(pg))
1191d12c531Syamt #endif /* !defined(_BUS_VM_PAGE_TO_BUS) */
1201d12c531Syamt
121aeeb0b33Sbouyer #if !defined(_BUS_BUS_TO_VM_PAGE)
122aeeb0b33Sbouyer #define _BUS_BUS_TO_VM_PAGE(ba) PHYS_TO_VM_PAGE(ba)
123aeeb0b33Sbouyer #endif /* !defined(_BUS_BUS_TO_VM_PAGE) */
124aeeb0b33Sbouyer
125aeeb0b33Sbouyer #if !defined(_BUS_PMAP_ENTER)
126aeeb0b33Sbouyer #define _BUS_PMAP_ENTER(pmap, va, ba, prot, flags) \
127aeeb0b33Sbouyer pmap_enter(pmap, va, ba, prot, flags)
128aeeb0b33Sbouyer #endif /* _BUS_PMAP_ENTER */
129aeeb0b33Sbouyer
1301d12c531Syamt #if !defined(_BUS_VIRT_TO_BUS)
1315d4d9a20Schs #include <uvm/uvm_extern.h>
1321d12c531Syamt
133fbae48b9Sperry static __inline bus_addr_t _bus_virt_to_bus(struct pmap *, vaddr_t);
1341d12c531Syamt #define _BUS_VIRT_TO_BUS(pm, va) _bus_virt_to_bus((pm), (va))
1351d12c531Syamt
136fbae48b9Sperry static __inline bus_addr_t
_bus_virt_to_bus(struct pmap * pm,vaddr_t va)1371d12c531Syamt _bus_virt_to_bus(struct pmap *pm, vaddr_t va)
1381d12c531Syamt {
1391d12c531Syamt paddr_t pa;
1401d12c531Syamt
1411d12c531Syamt if (!pmap_extract(pm, va, &pa)) {
1421d12c531Syamt panic("_bus_virt_to_bus");
1431d12c531Syamt }
1441d12c531Syamt
1451d12c531Syamt return _BUS_PHYS_TO_BUS(pa);
1461d12c531Syamt }
1471d12c531Syamt #endif /* !defined(_BUS_VIRT_TO_BUS) */
1481d12c531Syamt
1497ce7159cSbouyer /*
1507ce7159cSbouyer * by default, the end address of RAM visible on bus is the same as the
1517ce7159cSbouyer * largest physical address.
1527ce7159cSbouyer */
1537ce7159cSbouyer #ifndef _BUS_AVAIL_END
154*e6a4e4ebSskrll #define _BUS_AVAIL_END (avail_end - 1)
1557ce7159cSbouyer #endif
1567ce7159cSbouyer
1579c412e0cSad struct x86_bus_dma_tag {
1584f4f4d2eSdyoung bus_dma_tag_t bdt_super;
1594f4f4d2eSdyoung /* bdt_present: bitmap indicating overrides present (1) in *this* tag,
1604f4f4d2eSdyoung * bdt_exists: bitmap indicating overrides present (1) in *this* tag
1614f4f4d2eSdyoung * or in an ancestor's tag (follow bdt_super to ancestors)
1624f4f4d2eSdyoung */
1634f4f4d2eSdyoung uint64_t bdt_present;
1644f4f4d2eSdyoung uint64_t bdt_exists;
1654f4f4d2eSdyoung const struct bus_dma_overrides *bdt_ov;
1664f4f4d2eSdyoung void *bdt_ctx;
1679c412e0cSad /*
1689c412e0cSad * The `bounce threshold' is checked while we are loading
1699c412e0cSad * the DMA map. If the physical address of the segment
1709c412e0cSad * exceeds the threshold, an error will be returned. The
1719c412e0cSad * caller can then take whatever action is necessary to
1729c412e0cSad * bounce the transfer. If this value is 0, it will be
1739c412e0cSad * ignored.
1749c412e0cSad */
1759c412e0cSad int _tag_needs_free;
1769c412e0cSad bus_addr_t _bounce_thresh;
1779c412e0cSad bus_addr_t _bounce_alloc_lo;
1789c412e0cSad bus_addr_t _bounce_alloc_hi;
1799c412e0cSad int (*_may_bounce)(bus_dma_tag_t, bus_dmamap_t, int, int *);
1809c412e0cSad };
1817ce7159cSbouyer
1821d12c531Syamt #endif /* !defined(_X86_BUS_PRIVATE_H_) */
183