grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

grub: Add ieee1275 interfaces for phys and virt memory allocation on spa


From: David Miller
Subject: grub: Add ieee1275 interfaces for phys and virt memory allocation on sparc64.
Date: Mon, 13 Apr 2009 00:06:10 -0700 (PDT)

This adds the ieee1275 interfaces sparc64's openboot has for
allocating physical memory, creating mappings, etc.

We can't reuse any of the existing similar calls used by powerpc since
these use two cells for passing physical addresses (even though only
one of those cell slots is used, this is legacy carry over from 32-bit
sparc times).

Committed.

2009-04-13  David S. Miller  <address@hidden>

        * kern/sparc64/ieee1275/ieee1275.c: New file.
        * include/grub/sparc64/ieee1275/ieee1275.h (IEEE1275_MAP_WRITE,
        IEEE1275_MAP_READ, IEEE1275_MAP_EXEC, IEEE1275_MAP_LOCKED,
        IEEE1275_MAP_CACHED, IEEE1275_MAP_SE, IEEE1275_MAP_GLOBAL,
        IEEE1275_MAP_IE, IEEE1275_MAP_DEFAULT): Define.
        (grub_ieee1275_map_physical, grub_ieee1275_claim_vaddr,
        grub_ieee1275_alloc_physmem): Declare new exported functions.
---
 include/grub/sparc64/ieee1275/ieee1275.h |   22 +++++
 kern/sparc64/ieee1275/ieee1275.c         |  124 ++++++++++++++++++++++++++++++
 2 files changed, 146 insertions(+), 0 deletions(-)
 create mode 100644 kern/sparc64/ieee1275/ieee1275.c

diff --git a/include/grub/sparc64/ieee1275/ieee1275.h 
b/include/grub/sparc64/ieee1275/ieee1275.h
index 1ef95f9..7626e93 100644
--- a/include/grub/sparc64/ieee1275/ieee1275.h
+++ b/include/grub/sparc64/ieee1275/ieee1275.h
@@ -24,4 +24,26 @@
 
 typedef grub_uint64_t grub_ieee1275_cell_t;
 
+/* Encoding of 'mode' argument to grub_ieee1275_map_physical() */
+#define IEEE1275_MAP_WRITE     0x0001 /* Writable */
+#define IEEE1275_MAP_READ      0x0002 /* Readable */
+#define IEEE1275_MAP_EXEC      0x0004 /* Executable */
+#define IEEE1275_MAP_LOCKED    0x0010 /* Locked in TLB */
+#define IEEE1275_MAP_CACHED    0x0020 /* Cacheable */
+#define IEEE1275_MAP_SE                0x0040 /* Side-effects */
+#define IEEE1275_MAP_GLOBAL    0x0080 /* Global */
+#define IEEE1275_MAP_IE                0x0100 /* Invert Endianness */
+#define IEEE1275_MAP_DEFAULT   (IEEE1275_MAP_WRITE | IEEE1275_MAP_READ | \
+                                IEEE1275_MAP_EXEC | IEEE1275_MAP_CACHED)
+
+extern int EXPORT_FUNC(grub_ieee1275_map_physical) (grub_addr_t paddr,
+                                                   grub_addr_t vaddr,
+                                                   grub_size_t size,
+                                                   grub_uint32_t mode);
+extern int EXPORT_FUNC(grub_ieee1275_claim_vaddr) (grub_addr_t vaddr,
+                                                  grub_size_t size);
+extern int EXPORT_FUNC(grub_ieee1275_alloc_physmem) (grub_addr_t *paddr,
+                                                    grub_size_t size,
+                                                    grub_uint32_t align);
+
 #endif /* ! GRUB_IEEE1275_MACHINE_HEADER */
diff --git a/kern/sparc64/ieee1275/ieee1275.c b/kern/sparc64/ieee1275/ieee1275.c
new file mode 100644
index 0000000..438a171
--- /dev/null
+++ b/kern/sparc64/ieee1275/ieee1275.c
@@ -0,0 +1,124 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/ieee1275/ieee1275.h>
+#include <grub/types.h>
+
+/* Sun specific ieee1275 interfaces used by GRUB.  */
+
+int
+grub_ieee1275_map_physical (grub_addr_t paddr, grub_addr_t vaddr,
+                           grub_size_t size, grub_uint32_t mode)
+{
+  struct map_physical_args
+  {
+    struct grub_ieee1275_common_hdr common;
+    grub_ieee1275_cell_t method;
+    grub_ieee1275_cell_t ihandle;
+    grub_ieee1275_cell_t mode;
+    grub_ieee1275_cell_t size;
+    grub_ieee1275_cell_t virt;
+    grub_ieee1275_cell_t phys_high;
+    grub_ieee1275_cell_t phys_low;
+    grub_ieee1275_cell_t catch_result;
+  }
+  args;
+
+  INIT_IEEE1275_COMMON (&args.common, "call-method", 7, 1);
+  args.method = (grub_ieee1275_cell_t) "map";
+  args.ihandle = grub_ieee1275_mmu;
+  args.mode = mode;
+  args.size = size;
+  args.virt = vaddr;
+  args.phys_high = 0;
+  args.phys_low = paddr;
+  args.catch_result = (grub_ieee1275_cell_t) -1;
+
+  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+    return -1;
+  return args.catch_result;
+}
+
+int
+grub_ieee1275_claim_vaddr (grub_addr_t vaddr, grub_size_t size)
+{
+  struct claim_vaddr_args
+  {
+    struct grub_ieee1275_common_hdr common;
+    grub_ieee1275_cell_t method;
+    grub_ieee1275_cell_t ihandle;
+    grub_ieee1275_cell_t align;
+    grub_ieee1275_cell_t size;
+    grub_ieee1275_cell_t virt;
+    grub_ieee1275_cell_t catch_result;
+  }
+  args;
+
+  INIT_IEEE1275_COMMON (&args.common, "call-method", 5, 2);
+  args.method = (grub_ieee1275_cell_t) "claim";
+  args.ihandle = grub_ieee1275_mmu;
+  args.align = 0;
+  args.size = size;
+  args.virt = vaddr;
+  args.catch_result = (grub_ieee1275_cell_t) -1;
+
+  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+    return -1;
+  return args.catch_result;
+}
+
+int
+grub_ieee1275_alloc_physmem (grub_addr_t *paddr, grub_size_t size,
+                            grub_uint32_t align)
+{
+  grub_uint32_t memory_ihandle;
+  struct alloc_physmem_args
+  {
+    struct grub_ieee1275_common_hdr common;
+    grub_ieee1275_cell_t method;
+    grub_ieee1275_cell_t ihandle;
+    grub_ieee1275_cell_t align;
+    grub_ieee1275_cell_t size;
+    grub_ieee1275_cell_t catch_result;
+    grub_ieee1275_cell_t phys_high;
+    grub_ieee1275_cell_t phys_low;
+  }
+  args;
+  grub_ssize_t actual = 0;
+
+  grub_ieee1275_get_property (grub_ieee1275_chosen, "memory",
+                             &memory_ihandle, sizeof (memory_ihandle),
+                             &actual);
+  if (actual != sizeof (memory_ihandle))
+    return -1;
+
+  if (!align)
+    align = 1;
+
+  INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 3);
+  args.method = (grub_ieee1275_cell_t) "claim";
+  args.ihandle = memory_ihandle;
+  args.align = (align ? align : 1);
+  args.size = size;
+  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+    return -1;
+
+  *paddr = args.phys_low;
+
+  return args.catch_result;
+}
-- 
1.6.2.3





reply via email to

[Prev in Thread] Current Thread [Next in Thread]