All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Cc: vasily.isaenko@oracle.com
Subject: Re: [PATCH 1/2] ieee1275: alloc-mem and free-mem
Date: Fri, 18 Nov 2016 15:32:43 +0300	[thread overview]
Message-ID: <582EF4EB.1040305@oracle.com> (raw)
In-Reply-To: <20161115212243.GH16470@router-fw-old.local.net-space.pl>

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 <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)
> 
> 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
> 


  reply	other threads:[~2016-11-18 12:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2017-05-11  1:51     ` Vladimir 'phcoder' Serbinenko

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=582EF4EB.1040305@oracle.com \
    --to=stanislav.kholmanskikh@oracle.com \
    --cc=grub-devel@gnu.org \
    --cc=vasily.isaenko@oracle.com \
    /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.