All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] ieee1275: alloc-mem and free-mem
@ 2016-04-12 12:39 Stanislav Kholmanskikh
  2016-04-12 12:39 ` [PATCH 2/2] ofnet: implement a receive buffer Stanislav Kholmanskikh
  2016-11-15 21:22 ` [PATCH 1/2] ieee1275: alloc-mem and free-mem Daniel Kiper
  0 siblings, 2 replies; 16+ messages in thread
From: Stanislav Kholmanskikh @ 2016-04-12 12:39 UTC (permalink / raw)
  To: grub-devel; +Cc: vasily.isaenko

Add wrappers for memory allocation using
alloc-mem and free-mem commands from the User Interface.

Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
---
 grub-core/kern/ieee1275/openfw.c |   68 ++++++++++++++++++++++++++++++++++++++
 include/grub/ieee1275/ieee1275.h |    2 +
 2 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c
index ddb7783..35225ec 100644
--- a/grub-core/kern/ieee1275/openfw.c
+++ b/grub-core/kern/ieee1275/openfw.c
@@ -561,3 +561,71 @@ grub_ieee1275_canonicalise_devname (const char *path)
   return NULL;
 }
 
+/* Allocate memory with alloc-mem */
+void *
+grub_ieee1275_alloc_mem (grub_size_t len)
+{
+  struct alloc_args
+  {
+    struct grub_ieee1275_common_hdr common;
+    grub_ieee1275_cell_t method;
+    grub_ieee1275_cell_t len;
+    grub_ieee1275_cell_t catch;
+    grub_ieee1275_cell_t result;
+  }
+  args;
+
+  if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET))
+    {
+      grub_error (GRUB_ERR_UNKNOWN_COMMAND, N_("interpret is not supported"));
+      return NULL;
+    }
+
+  INIT_IEEE1275_COMMON (&args.common, "interpret", 2, 2);
+  args.len = len;
+  args.method = (grub_ieee1275_cell_t) "alloc-mem";
+
+  if (IEEE1275_CALL_ENTRY_FN (&args) == -1
+      || args.catch)
+    {
+      grub_error (GRUB_ERR_INVALID_COMMAND, N_("alloc-mem failed"));
+      return NULL;
+    }
+  else
+    return (void *)args.result;
+}
+
+/* Free memory allocated by alloc-mem */
+grub_err_t
+grub_ieee1275_free_mem (void *addr, grub_size_t len)
+{
+  struct free_args
+  {
+    struct grub_ieee1275_common_hdr common;
+    grub_ieee1275_cell_t method;
+    grub_ieee1275_cell_t len;
+    grub_ieee1275_cell_t addr;
+    grub_ieee1275_cell_t catch;
+  }
+  args;
+
+  if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET))
+    {
+      grub_error (GRUB_ERR_UNKNOWN_COMMAND, N_("interpret is not supported"));
+      return grub_errno;
+    }
+
+  INIT_IEEE1275_COMMON (&args.common, "interpret", 3, 1);
+  args.addr = (grub_ieee1275_cell_t)addr;
+  args.len = len;
+  args.method = (grub_ieee1275_cell_t) "free-mem";
+
+  if (IEEE1275_CALL_ENTRY_FN(&args) == -1
+      || args.catch)
+    {
+      grub_error (GRUB_ERR_INVALID_COMMAND, N_("free-mem failed"));
+      return grub_errno;
+    }
+
+  return GRUB_ERR_NONE;
+}
diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h
index 8e42513..91510b3 100644
--- a/include/grub/ieee1275/ieee1275.h
+++ b/include/grub/ieee1275/ieee1275.h
@@ -234,6 +234,8 @@ int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *ali
 void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias);
 void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,
 						struct grub_ieee1275_devalias *alias);
+void *EXPORT_FUNC(grub_ieee1275_alloc_mem) (grub_size_t len);
+grub_err_t EXPORT_FUNC(grub_ieee1275_free_mem) (void * addr, grub_size_t len);
 
 #define FOR_IEEE1275_DEVALIASES(alias) for (grub_ieee1275_devalias_init_iterator (&(alias)); grub_ieee1275_devalias_next (&(alias));)
 
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2017-05-11  1:51 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-12 12:39 [PATCH 1/2] ieee1275: alloc-mem and free-mem Stanislav Kholmanskikh
2016-04-12 12:39 ` [PATCH 2/2] ofnet: implement a receive buffer Stanislav Kholmanskikh
2016-05-10 10:45   ` Stanislav Kholmanskikh
2016-07-13 14:35     ` Stanislav Kholmanskikh
2016-10-13  8:13       ` Stanislav Kholmanskikh
2016-11-15 22:34   ` Daniel Kiper
2016-11-18 13:29     ` Stanislav Kholmanskikh
2016-11-21 21:48       ` Daniel Kiper
2016-11-22 14:08         ` Stanislav Kholmanskikh
2016-11-23 11:16           ` Daniel Kiper
2016-11-23 15:09             ` Stanislav Kholmanskikh
2016-11-24  9:25               ` Daniel Kiper
2016-11-30 15:27               ` Stanislav Kholmanskikh
2016-11-15 21:22 ` [PATCH 1/2] ieee1275: alloc-mem and free-mem Daniel Kiper
2016-11-18 12:32   ` Stanislav Kholmanskikh
2017-05-11  1:51     ` Vladimir 'phcoder' Serbinenko

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.