All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org
Cc: samuel.thibault@ens-lyon.org, wl@xen.org,
	Juergen Gross <jgross@suse.com>
Subject: [PATCH v3 06/10] mini-os: add memory map service functions
Date: Tue, 21 Dec 2021 09:46:32 +0100	[thread overview]
Message-ID: <20211221084636.6987-7-jgross@suse.com> (raw)
In-Reply-To: <20211221084636.6987-1-jgross@suse.com>

Add two functions for adding reserved areas to the memory map and
for removing them again.

Those will be needed for proper grant table/mapping support in PVH
mode.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
V2:
- fix e820_put_reserved_pfns() (Samuel Thibault)
---
 e820.c         | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/e820.h |  4 ++++
 2 files changed, 54 insertions(+)

diff --git a/e820.c b/e820.c
index 2a371c7..df29097 100644
--- a/e820.c
+++ b/e820.c
@@ -283,6 +283,56 @@ void arch_print_memmap(void)
         printk("%012lx-%012lx: %s\n", from, to, type);
     }
 }
+
+unsigned long e820_get_reserved_pfns(int pages)
+{
+    int i;
+    unsigned long last = 0, needed = (long)pages << PAGE_SHIFT;
+
+    for ( i = 0; i < e820_entries && e820_map[i].addr < last + needed; i++ )
+        last = e820_map[i].addr + e820_map[i].size;
+
+    if ( i == 0 || e820_map[i - 1].type != E820_RESERVED )
+        e820_insert_entry_at(i, last, needed, E820_RESERVED);
+    else
+        e820_map[i - 1].size += needed;
+
+    return last >> PAGE_SHIFT;
+}
+
+void e820_put_reserved_pfns(unsigned long start_pfn, int pages)
+{
+    int i;
+    unsigned long addr = start_pfn << PAGE_SHIFT;
+    unsigned long size = (long)pages << PAGE_SHIFT;
+
+    for ( i = 0;
+          i < e820_entries && addr >= e820_map[i].addr + e820_map[i].size;
+          i++ );
+
+    BUG_ON(i == e820_entries || e820_map[i].type != E820_RESERVED ||
+           addr + size > e820_map[i].addr + e820_map[i].size);
+
+    if ( addr == e820_map[i].addr )
+    {
+        e820_map[i].addr += size;
+        e820_map[i].size -= size;
+        if ( e820_map[i].size == 0 )
+            e820_remove_entry(i);
+        return;
+    }
+
+    if ( addr + size == e820_map[i].addr + e820_map[i].size )
+    {
+        e820_map[i].size -= size;
+        return;
+    }
+
+    e820_insert_entry_at(i + 1, addr + size,
+                         e820_map[i].addr + e820_map[i].size - addr - size,
+                         E820_RESERVED);
+    e820_map[i].size = addr - e820_map[i].addr;
+}
 #endif
 
 unsigned long e820_get_maxpfn(unsigned long pages)
diff --git a/include/e820.h b/include/e820.h
index 8d4d371..aaf2f2c 100644
--- a/include/e820.h
+++ b/include/e820.h
@@ -51,5 +51,9 @@ extern unsigned e820_entries;
 
 unsigned long e820_get_maxpfn(unsigned long pages);
 unsigned long e820_get_max_contig_pages(unsigned long pfn, unsigned long pages);
+#ifndef CONFIG_E820_TRIVIAL
+unsigned long e820_get_reserved_pfns(int pages);
+void e820_put_reserved_pfns(unsigned long start_pfn, int pages);
+#endif
 
 #endif /*__E820_HEADER*/
-- 
2.26.2



  parent reply	other threads:[~2021-12-21  8:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-21  8:46 [PATCH v3 00/10] mini-os: add missing PVH features Juergen Gross
2021-12-21  8:46 ` [PATCH v3 01/10] mini-os: split e820 map handling into new source file Juergen Gross
2021-12-21  8:46 ` [PATCH v3 02/10] mini-os: sort and sanitize e820 memory map Juergen Gross
2021-12-21  8:46 ` [PATCH v3 03/10] mini-os: don't assume contiguous RAM when initializing in PVH mode Juergen Gross
2021-12-21  8:46 ` [PATCH v3 04/10] mini-os: respect memory map when ballooning up Juergen Gross
2021-12-21  8:46 ` [PATCH v3 05/10] mini-os: don't repeat definition available via header file Juergen Gross
2021-12-21  8:46 ` Juergen Gross [this message]
2021-12-21  8:46 ` [PATCH v3 07/10] mini-os: move x86 specific gnttab coding into arch/x86/gnttab.c Juergen Gross
2021-12-21  8:46 ` [PATCH v3 08/10] mini-os: add proper pvh grant table handling Juergen Gross
2021-12-21  8:46 ` [PATCH v3 09/10] mini-os: prepare grantmap entry interface for use by PVH mode Juergen Gross
2021-12-21  8:46 ` [PATCH v3 10/10] mini-os: modify grant mappings to work in " Juergen Gross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211221084636.6987-7-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=minios-devel@lists.xenproject.org \
    --cc=samuel.thibault@ens-lyon.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.