From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1c7iLk-0007IJ-4R for mharc-grub-devel@gnu.org; Fri, 18 Nov 2016 07:33:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45908) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7iLe-0007Gt-Ta for grub-devel@gnu.org; Fri, 18 Nov 2016 07:32:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c7iLZ-0000zh-Vz for grub-devel@gnu.org; Fri, 18 Nov 2016 07:32:54 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:31084) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c7iLZ-0000zP-OW for grub-devel@gnu.org; Fri, 18 Nov 2016 07:32:49 -0500 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id uAICWka4022279 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 18 Nov 2016 12:32:47 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id uAICWkiO002453 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 18 Nov 2016 12:32:46 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id uAICWkXR020937 for ; Fri, 18 Nov 2016 12:32:46 GMT Received: from [10.162.81.122] (/10.162.81.122) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 18 Nov 2016 04:32:46 -0800 Subject: Re: [PATCH 1/2] ieee1275: alloc-mem and free-mem To: The development of GNU GRUB References: <1460464796-24738-1-git-send-email-stanislav.kholmanskikh@oracle.com> <20161115212243.GH16470@router-fw-old.local.net-space.pl> Cc: vasily.isaenko@oracle.com From: Stanislav Kholmanskikh Message-ID: <582EF4EB.1040305@oracle.com> Date: Fri, 18 Nov 2016 15:32:43 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <20161115212243.GH16470@router-fw-old.local.net-space.pl> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Source-IP: userv0021.oracle.com [156.151.31.71] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 141.146.126.69 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: Fri, 18 Nov 2016 12:32:56 -0000 Hi, Daniel. Thank you for review. My comments are below. On 11/16/2016 12:22 AM, Daniel Kiper wrote: > 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? In the current git code in grub-core/net/drivers/ieee1275/ofnet.c the search_net_devices() function uses the "alloc-mem" command for allocation of the transmit buffer for the case when GRUB_IEEE1275_FLAG_VIRT_TO_REAL_BROKEN is set. Yes, besides "alloc-mem", "free-mem", there are other options for allocating memory. But, to be honest, I don't know why grub_malloc() cannot be used for the receive buffer on those systems. From the flag's name it seems those systems don't have a MMU. Ok, but grub_malloc() is called from many places in grub, and, presumably, grub works on those systems. I don't have such a MacRISC system to try grub_malloc() for the buffers (grub-core/kern/ieee1275/cmain.c). In patch 2 I'm implementing a receive buffer, so I decided to keep this case as is, but move "alloc-mem", "free-mem" into functions. Does it answer your questions? If yes, I'll update the commit message for V2 with a more detailed explanation why these functions are needed. > >> 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. Ok. > >> + { >> + 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. Ok. > > Daniel > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel >