1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright 2018 IBM Corporation
6 * Author: Anshuman Khandual <khandual@linux.vnet.ibm.com>
10 #include <asm/machdep.h>
12 #include <asm/swiotlb.h>
13 #include <asm/ultravisor.h>
15 static int __init init_svm(void)
17 if (!is_secure_guest())
20 /* Don't release the SWIOTLB buffer. */
21 ppc_swiotlb_enable = 1;
24 * Since the guest memory is inaccessible to the host, devices always
25 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
28 swiotlb_force = SWIOTLB_FORCE;
30 /* Share the SWIOTLB buffer with the host. */
31 swiotlb_update_mem_attributes();
35 machine_early_initcall(pseries, init_svm);
37 int set_memory_encrypted(unsigned long addr, int numpages)
39 if (!PAGE_ALIGNED(addr))
42 uv_unshare_page(PHYS_PFN(__pa(addr)), numpages);
47 int set_memory_decrypted(unsigned long addr, int numpages)
49 if (!PAGE_ALIGNED(addr))
52 uv_share_page(PHYS_PFN(__pa(addr)), numpages);
57 /* There's one dispatch log per CPU. */
58 #define NR_DTL_PAGE (DISPATCH_LOG_BYTES * CONFIG_NR_CPUS / PAGE_SIZE)
60 static struct page *dtl_page_store[NR_DTL_PAGE];
61 static long dtl_nr_pages;
63 static bool is_dtl_page_shared(struct page *page)
67 for (i = 0; i < dtl_nr_pages; i++)
68 if (dtl_page_store[i] == page)
74 void dtl_cache_ctor(void *addr)
76 unsigned long pfn = PHYS_PFN(__pa(addr));
77 struct page *page = pfn_to_page(pfn);
79 if (!is_dtl_page_shared(page)) {
80 dtl_page_store[dtl_nr_pages] = page;
82 WARN_ON(dtl_nr_pages >= NR_DTL_PAGE);
83 uv_share_page(pfn, 1);