1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright 2018 IBM Corporation
6 * Author: Anshuman Khandual <khandual@linux.vnet.ibm.com>
10 #include <linux/memblock.h>
11 #include <linux/cc_platform.h>
12 #include <asm/machdep.h>
14 #include <asm/swiotlb.h>
15 #include <asm/ultravisor.h>
18 static int __init init_svm(void)
20 if (!is_secure_guest())
23 /* Don't release the SWIOTLB buffer. */
24 ppc_swiotlb_enable = 1;
27 * Since the guest memory is inaccessible to the host, devices always
28 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
31 ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
33 /* Share the SWIOTLB buffer with the host. */
34 swiotlb_update_mem_attributes();
38 machine_early_initcall(pseries, init_svm);
40 int set_memory_encrypted(unsigned long addr, int numpages)
42 if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
45 if (!PAGE_ALIGNED(addr))
48 uv_unshare_page(PHYS_PFN(__pa(addr)), numpages);
53 int set_memory_decrypted(unsigned long addr, int numpages)
55 if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
58 if (!PAGE_ALIGNED(addr))
61 uv_share_page(PHYS_PFN(__pa(addr)), numpages);
66 /* There's one dispatch log per CPU. */
67 #define NR_DTL_PAGE (DISPATCH_LOG_BYTES * CONFIG_NR_CPUS / PAGE_SIZE)
69 static struct page *dtl_page_store[NR_DTL_PAGE];
70 static long dtl_nr_pages;
72 static bool is_dtl_page_shared(struct page *page)
76 for (i = 0; i < dtl_nr_pages; i++)
77 if (dtl_page_store[i] == page)
83 void dtl_cache_ctor(void *addr)
85 unsigned long pfn = PHYS_PFN(__pa(addr));
86 struct page *page = pfn_to_page(pfn);
88 if (!is_dtl_page_shared(page)) {
89 dtl_page_store[dtl_nr_pages] = page;
91 WARN_ON(dtl_nr_pages >= NR_DTL_PAGE);
92 uv_share_page(pfn, 1);