1*a68d7a25Spatrick /* $OpenBSD: smmuvar.h,v 1.8 2022/09/11 10:18:54 patrick Exp $ */ 21a30e4e7Spatrick /* 31a30e4e7Spatrick * Copyright (c) 2021 Patrick Wildt <patrick@blueri.se> 41a30e4e7Spatrick * 51a30e4e7Spatrick * Permission to use, copy, modify, and distribute this software for any 61a30e4e7Spatrick * purpose with or without fee is hereby granted, provided that the above 71a30e4e7Spatrick * copyright notice and this permission notice appear in all copies. 81a30e4e7Spatrick * 91a30e4e7Spatrick * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 101a30e4e7Spatrick * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 111a30e4e7Spatrick * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 121a30e4e7Spatrick * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 131a30e4e7Spatrick * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 141a30e4e7Spatrick * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 151a30e4e7Spatrick * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 161a30e4e7Spatrick */ 171a30e4e7Spatrick 181a30e4e7Spatrick struct smmu_softc; 191a30e4e7Spatrick struct smmu_domain { 201a30e4e7Spatrick struct smmu_softc *sd_sc; 211a30e4e7Spatrick uint32_t sd_sid; 22c6c0a1deSpatrick bus_dma_tag_t sd_dmat; 231a30e4e7Spatrick int sd_cb_idx; 241a30e4e7Spatrick int sd_smr_idx; 251a30e4e7Spatrick int sd_stage; 261a30e4e7Spatrick int sd_4level; 271a30e4e7Spatrick char sd_exname[32]; 281a30e4e7Spatrick struct extent *sd_iovamap; 291a30e4e7Spatrick union { 301a30e4e7Spatrick struct smmuvp0 *l0; /* virtual to physical table 4 lvl */ 311a30e4e7Spatrick struct smmuvp1 *l1; /* virtual to physical table 3 lvl */ 321a30e4e7Spatrick } sd_vp; 330aa222ffSpatrick struct mutex sd_iova_mtx; 340aa222ffSpatrick struct mutex sd_pmap_mtx; 351a30e4e7Spatrick SIMPLEQ_ENTRY(smmu_domain) sd_list; 361a30e4e7Spatrick }; 371a30e4e7Spatrick 381a30e4e7Spatrick struct smmu_cb { 391a30e4e7Spatrick }; 401a30e4e7Spatrick 411a30e4e7Spatrick struct smmu_cb_irq { 421a30e4e7Spatrick struct smmu_softc *cbi_sc; 431a30e4e7Spatrick int cbi_idx; 441a30e4e7Spatrick }; 451a30e4e7Spatrick 461a30e4e7Spatrick struct smmu_smr { 47*a68d7a25Spatrick struct smmu_domain *ss_dom; 48*a68d7a25Spatrick uint16_t ss_id; 49*a68d7a25Spatrick uint16_t ss_mask; 501a30e4e7Spatrick }; 511a30e4e7Spatrick 521a30e4e7Spatrick struct smmu_softc { 531a30e4e7Spatrick struct device sc_dev; 541a30e4e7Spatrick bus_space_tag_t sc_iot; 551a30e4e7Spatrick bus_space_handle_t sc_ioh; 561a30e4e7Spatrick bus_dma_tag_t sc_dmat; 571a30e4e7Spatrick int sc_is_mmu500; 581a30e4e7Spatrick int sc_is_ap806; 59d0fbdf68Spatrick int sc_is_qcom; 60d0fbdf68Spatrick int sc_bypass_quirk; 611a30e4e7Spatrick size_t sc_pagesize; 621a30e4e7Spatrick int sc_numpage; 631a30e4e7Spatrick int sc_num_context_banks; 641a30e4e7Spatrick int sc_num_s2_context_banks; 651a30e4e7Spatrick int sc_has_s1; 661a30e4e7Spatrick int sc_has_s2; 671a30e4e7Spatrick int sc_has_exids; 681a30e4e7Spatrick int sc_has_vmid16s; 691a30e4e7Spatrick int sc_num_streams; 701a30e4e7Spatrick uint16_t sc_stream_mask; 711a30e4e7Spatrick int sc_ipa_bits; 721a30e4e7Spatrick int sc_pa_bits; 731a30e4e7Spatrick int sc_va_bits; 741a30e4e7Spatrick struct smmu_smr **sc_smr; 751a30e4e7Spatrick struct smmu_cb **sc_cb; 761a30e4e7Spatrick int sc_coherent; 771a30e4e7Spatrick struct pool sc_vp_pool; 782322545bSpatrick struct pool sc_vp3_pool; 791a30e4e7Spatrick SIMPLEQ_HEAD(, smmu_domain) sc_domains; 801a30e4e7Spatrick }; 811a30e4e7Spatrick 821a30e4e7Spatrick int smmu_attach(struct smmu_softc *); 831a30e4e7Spatrick int smmu_global_irq(void *); 841a30e4e7Spatrick int smmu_context_irq(void *); 8588933a1fSpatrick bus_dma_tag_t smmu_device_map(void *, uint32_t, bus_dma_tag_t); 86415019ceSpatrick void smmu_reserve_region(void *, uint32_t, bus_addr_t, bus_size_t); 87