linux-efi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lukas Wunner <lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
To: Matt Fleming <matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
Cc: linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Andreas Noever
	<andreas.noever-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Peter Jones <pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Ard Biesheuvel
	<ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Subject: Re: [PATCH v3 2/3] x86/efi: Retrieve and assign Apple device properties
Date: Mon, 7 Nov 2016 11:48:27 +0100	[thread overview]
Message-ID: <20161107104827.GA6310@wunner.de> (raw)
In-Reply-To: <20161103233100.GC8845-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>

Hi Matt,

Thanks a lot for the review and comments!

On Thu, Nov 03, 2016 at 11:31:00PM +0000, Matt Fleming wrote:
> On Thu, 03 Nov, at 11:18:48AM, Lukas Wunner wrote:
> > +	if ((efi_is_64bit() ?
> > +			((apple_properties_protocol_64 *)properties)->version :
> > +			((apple_properties_protocol_32 *)properties)->version)
> > +								   != 0x10000) {
> > +		efi_printk(sys_table, "Unsupported properties proto version\n");
> > +		return;
> > +	}
> 
> It's a minor point, but please don't write the 32/64 code like this.
> Either use two separate functions, like __file_size32() and
> __file_size64(), or if that's two much code duplication stash the
> version field and get_all pointer in stack-local variables at the
> start of the function.

My plan was to introduce an efi_call_proto() macro which hides the
ternary operator similar to efi_call_early(), then use that to
deduplicate the code in the EFI stub.  I wanted to postpone opening
that can of worms until after this series has landed, hence the
not so readable code above.  To address your (valid) objection,
I've now included a commit with the efi_call_proto() macro in v4
and I'll follow up with two separate patches to demonstrate the
attainable code reduction.

So this is probably a bit different to what you had in mind.
If you think this approach isn't well suited for some reason just
let me know.


> > +	if (!memcmp((void *)sys_table->fw_vendor, apple, sizeof(apple))) {
> > +		if (IS_ENABLED(CONFIG_APPLE_PROPERTIES))
> > +			retrieve_apple_device_properties(boot_params);
> > +	}
> > +
> 
> Could you split this off into a setup_apple_properties() function to
> mirror setup_efi_pci()?

We're going to need at least one other Apple-specific quirk to
masquerade as MacOS X to EFI using another proprietary protocol:
On 2013+ MacBook Pros with hybrid graphics the integrated Intel GPU
is invisible to the OS (powered down) unless this identification
scheme is used.  A preliminary patch for this has been floating around
for a while but wasn't mainlined so far for a number of reasons:
https://marc.info/?l=grub-deavel&m=141586614924917&w=2

Conceivably we may need to add further vendor- or device-specific
quirks to the EFI stub in the future, so I've moved this out of
efi_main() and into a new setup_quirks() function.


> > +
> > +		key = kzalloc((key_len - sizeof(key_len)) * 4 + 1, GFP_KERNEL);
> > +		if (!key) {
> > +			dev_err(dev, "cannot allocate property name\n");
> > +			break;
> > +		}
> 
> Could you add a comment to document the kzalloc() size argument above?

Ok, done.  I'm allocating 4 bytes for each character to accommodate UTF-8
code points, plus 1 null byte.  I'm aware that the string may need much
less than 4 bytes per character, but it's only allocated temporarily
and freed after the properties have been assigned to the device.


> > +	if (i != dev_header->prop_count) {
> > +		dev_err(dev, "got %d device properties, expected %u\n", i,
> > +			dev_header->prop_count);
> > +		print_hex_dump(KERN_ERR, pr_fmt(), DUMP_PREFIX_OFFSET,
> > +			16, 1, dev_header, dev_header->len, true);
> > +	} else
> > +		dev_info(dev, "assigning %d device properties\n", i);
> 
> Mismatched braces are frowned upon in the CodingStyle guide. Please
> use braces for both the 'if' and 'else'. Alternatively, return early
> for one of the conditions (and save a level of indentation too).

Good idea, thanks.


> Newline here please.
[...]
> And a newline here.
[...]
> Please sprinkle a few newlines to make this more readable.
[...]
> Newline please.
[...]
> Newline.
[...]
> Newline.
[...]
> Newline.

Yes, sorry, I guess sometimes my "compact code" fetishism becomes a bit
exaggerated.


On Mon, Nov 07, 2016 at 09:37:14AM +0000, Matt Fleming wrote:
> Ideally, I'd like to send the v4.10 material to tip by the end of the
> week.

Yes, thanks for the heads-up, it was already on my radar that you send
out the pull after rc4 so I cooked this up over the weekend.

Best regards,

Lukas

  parent reply	other threads:[~2016-11-07 10:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-03 10:18 [PATCH v3 0/3] Apple device properties Lukas Wunner
     [not found] ` <cover.1478145888.git.lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2016-11-03 10:18   ` [PATCH v3 3/3] thunderbolt: Use Device ROM retrieved from EFI Lukas Wunner
     [not found]     ` <776fcc302f58628d1a122ba929751760c554cbfc.1478145888.git.lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2016-11-06 23:02       ` Andreas Noever
     [not found]         ` <CAMxnaaVfT+gxgq4q76Jz8gY_OfaBr_ToXQ8f-bYGwjcd2eS=9A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-11-07 11:28           ` Lukas Wunner
2016-11-03 10:18   ` [PATCH v3 2/3] x86/efi: Retrieve and assign Apple device properties Lukas Wunner
     [not found]     ` <495c463bcb78131bf04ece648719fc8b3e9bd4ba.1478145888.git.lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2016-11-03 23:31       ` Matt Fleming
     [not found]         ` <20161103233100.GC8845-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-11-07 10:48           ` Lukas Wunner [this message]
2016-11-03 10:18   ` [PATCH v3 1/3] efi: Add device path parser Lukas Wunner
2016-11-03 23:34   ` [PATCH v3 0/3] Apple device properties Matt Fleming
     [not found]     ` <20161103233458.GD8845-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-11-06 23:13       ` Andreas Noever
     [not found]         ` <CAMxnaaXF2F=v=HAefZ724bJSub3=0nVYV7KkCOrhE6TMb4OrZA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-11-07  9:37           ` Matt Fleming

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=20161107104827.GA6310@wunner.de \
    --to=lukas-jfq808j9c/izqb+pc5nmwq@public.gmane.org \
    --cc=andreas.noever-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org \
    --cc=pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).