Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) /* Glue code to lib/swiotlb-xen.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) #include <linux/dma-map-ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <xen/swiotlb-xen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <asm/xen/hypervisor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <xen/xen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/iommu_table.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/xen/swiotlb-xen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/iommu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/dma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) int xen_swiotlb __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)  * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)  * This returns non-zero if we are forced to use xen_swiotlb (by the boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)  * option).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) int __init pci_xen_swiotlb_detect(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	if (!xen_pv_domain())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	/* If running as PV guest, either iommu=soft, or swiotlb=force will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	 * activate this IOMMU. If running as PV privileged, activate it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	 * irregardless.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		xen_swiotlb = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	/* If we are running under Xen, we MUST disable the native SWIOTLB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	 * Don't worry about swiotlb_force flag activating the native, as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	 * the 'swiotlb' flag is the only one turning it on. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	swiotlb = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	/* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	 * (so no iommu=X command line over-writes).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	 * Considering that PV guests do not want the *native SWIOTLB* but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	if (max_pfn > MAX_DMA32_PFN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 		no_iommu = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	return xen_swiotlb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) void __init pci_xen_swiotlb_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	if (xen_swiotlb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 		xen_swiotlb_init(1, true /* early */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 		dma_ops = &xen_swiotlb_dma_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #ifdef CONFIG_PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 		/* Make sure ACS will be enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 		pci_request_acs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int pci_xen_swiotlb_init_late(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	if (xen_swiotlb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	rc = xen_swiotlb_init(1, false /* late */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 	dma_ops = &xen_swiotlb_dma_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #ifdef CONFIG_PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 	/* Make sure ACS will be enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 	pci_request_acs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) 		  NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) 		  pci_xen_swiotlb_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) 		  NULL);