From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1c6lBs-00032G-Bo for mharc-grub-devel@gnu.org; Tue, 15 Nov 2016 16:22:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6lBp-00030u-Sx for grub-devel@gnu.org; Tue, 15 Nov 2016 16:22:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c6lBl-0001oy-Qj for grub-devel@gnu.org; Tue, 15 Nov 2016 16:22:49 -0500 Received: from boksu.net-space.pl ([185.15.1.105]:53047) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.71) (envelope-from ) id 1c6lBl-0001oT-GA for grub-devel@gnu.org; Tue, 15 Nov 2016 16:22:45 -0500 Received: (from localhost user: 'dkiper' uid#4000 fake: STDIN (dkiper@boksu.net-space.pl)) by router-fw-old.local.net-space.pl id S1667322AbcKOVWn (ORCPT ); Tue, 15 Nov 2016 22:22:43 +0100 Date: Tue, 15 Nov 2016 22:22:43 +0100 From: Daniel Kiper To: stanislav.kholmanskikh@oracle.com, grub-devel@gnu.org Cc: vasily.isaenko@oracle.com Subject: Re: [PATCH 1/2] ieee1275: alloc-mem and free-mem Message-ID: <20161115212243.GH16470@router-fw-old.local.net-space.pl> References: <1460464796-24738-1-git-send-email-stanislav.kholmanskikh@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1460464796-24738-1-git-send-email-stanislav.kholmanskikh@oracle.com> User-Agent: Mutt/1.3.28i X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.15.1.105 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Nov 2016 21:22:51 -0000 On Tue, Apr 12, 2016 at 03:39:55PM +0300, Stanislav Kholmanskikh wrote: > Add wrappers for memory allocation using > alloc-mem and free-mem commands from the User Interface. Please tell why it is needed. Additionally, please forgive me if it is stupid question, why are you using command line to allocate/free memory? There is a lack of better API in IEEE 1275? > Signed-off-by: Stanislav Kholmanskikh > --- > 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) I think that this can be in one line. > + { > + 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) Ditto. Daniel