#ifndef _ASM_X86_VGA_H
 #define _ASM_X86_VGA_H
 
+#include <asm/set_memory.h>
+
 /*
  *     On the PC, we can just recalculate addresses and then
  *     access the videoram directly without any black magic.
+ *     To support memory encryption however, we need to access
+ *     the videoram as decrypted memory.
  */
 
-#define VGA_MAP_MEM(x, s) (unsigned long)phys_to_virt(x)
+#define VGA_MAP_MEM(x, s)                                      \
+({                                                             \
+       unsigned long start = (unsigned long)phys_to_virt(x);   \
+                                                               \
+       if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT))                 \
+               set_memory_decrypted(start, (s) >> PAGE_SHIFT); \
+                                                               \
+       start;                                                  \
+})
 
 #define vga_readb(x) (*(x))
 #define vga_writeb(x, y) (*(y) = (x))
 
 {
        return __set_memory_enc_dec(addr, numpages, true);
 }
+EXPORT_SYMBOL_GPL(set_memory_encrypted);
 
 int set_memory_decrypted(unsigned long addr, int numpages)
 {
        return __set_memory_enc_dec(addr, numpages, false);
 }
+EXPORT_SYMBOL_GPL(set_memory_decrypted);
 
 int set_pages_uc(struct page *page, int numpages)
 {
 
 #include <linux/pagemap.h>
 #include <linux/shmem_fs.h>
 #include <linux/dma-buf.h>
+#include <linux/mem_encrypt.h>
 #include <drm/drmP.h>
 #include <drm/drm_vma_manager.h>
 #include <drm/drm_gem.h>
        vma->vm_ops = dev->driver->gem_vm_ops;
        vma->vm_private_data = obj;
        vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags));
+       vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
 
        /* Take a ref for this mapping of the object, so that the fault
         * handler can dereference the mmap offset's pointer to the object.
 
 #include <linux/efi.h>
 #include <linux/slab.h>
 #endif
+#include <linux/mem_encrypt.h>
 #include <asm/pgtable.h>
 #include "drm_internal.h"
 #include "drm_legacy.h"
 {
        pgprot_t tmp = vm_get_page_prot(vma->vm_flags);
 
+       /* We don't want graphics memory to be mapped encrypted */
+       tmp = pgprot_decrypted(tmp);
+
 #if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__)
        if (map->type == _DRM_REGISTERS && !(map->flags & _DRM_WRITE_COMBINING))
                tmp = pgprot_noncached(tmp);
 
 #include <linux/rbtree.h>
 #include <linux/module.h>
 #include <linux/uaccess.h>
+#include <linux/mem_encrypt.h>
 
 #define TTM_BO_VM_NUM_PREFAULT 16
 
         * first page.
         */
        for (i = 0; i < TTM_BO_VM_NUM_PREFAULT; ++i) {
-               if (bo->mem.bus.is_iomem)
+               if (bo->mem.bus.is_iomem) {
+                       /* Iomem should not be marked encrypted */
+                       cvma.vm_page_prot = pgprot_decrypted(cvma.vm_page_prot);
                        pfn = bdev->driver->io_mem_pfn(bo, page_offset);
-               else {
+               } else {
                        page = ttm->pages[page_offset];
                        if (unlikely(!page && i == 0)) {
                                retval = VM_FAULT_OOM;
 
 #include <linux/slab.h>
 #include <linux/fb.h>
 #include <linux/dma-buf.h>
+#include <linux/mem_encrypt.h>
 
 #include <drm/drmP.h>
 #include <drm/drm_crtc.h>
        pr_notice("mmap() framebuffer addr:%lu size:%lu\n",
                  pos, size);
 
+       /* We don't want the framebuffer to be mapped encrypted */
+       vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
+
        while (size > 0) {
                page = vmalloc_to_pfn((void *)pos);
                if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED))
 
 #include <linux/device.h>
 #include <linux/efi.h>
 #include <linux/fb.h>
+#include <linux/mem_encrypt.h>
 
 #include <asm/fb.h>
 
        mutex_lock(&info->mm_lock);
        if (fb->fb_mmap) {
                int res;
+
+               /*
+                * The framebuffer needs to be accessed decrypted, be sure
+                * SME protection is removed ahead of the call
+                */
+               vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
                res = fb->fb_mmap(info, vma);
                mutex_unlock(&info->mm_lock);
                return res;
        mutex_unlock(&info->mm_lock);
 
        vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
+       /*
+        * The framebuffer needs to be accessed decrypted, be sure
+        * SME protection is removed
+        */
+       vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
        fb_pgprotect(file, vma, start);
 
        return vm_iomap_memory(vma, start, len);