From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1UO1ye-00032J-6w for mharc-grub-devel@gnu.org; Fri, 05 Apr 2013 04:26:28 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39102) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UO1ya-00031q-Ed for grub-devel@gnu.org; Fri, 05 Apr 2013 04:26:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UO1yY-0006wI-E3 for grub-devel@gnu.org; Fri, 05 Apr 2013 04:26:24 -0400 Received: from mail-ea0-x22a.google.com ([2a00:1450:4013:c01::22a]:65430) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UO1yY-0006w4-4F for grub-devel@gnu.org; Fri, 05 Apr 2013 04:26:22 -0400 Received: by mail-ea0-f170.google.com with SMTP id a15so1301937eae.29 for ; Fri, 05 Apr 2013 01:26:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:x-enigmail-version:content-type; bh=hzBn8HXaxV6Bo9it9y0va6UgGfc9/QcxKJ3wcTKh4XQ=; b=jSLlPPoKJygOi3RLFK9mWYrJATmj5LbLHLnu6UlnNoD2oi3pngLmUjHWZQQzjL5QGD zXS1207u8oCIFdsYWiyh1nkn+miwWianj5GulvEsHWqGf2TInj6ynpkLfb/wwJwlFr3Y YUZORx0VJe7Vlsz8W/5d3o+CXAZMPmpyRsoP5J3hT4P3v8HrvwFvhDCMdIhDrIuve/gz Ub3PSQI1kCZFxfU7QVrT7ScIGDKyMbQZWF9kRBkpx3cSvu0jZFKjvNJTOFKJ1xf0SzNX H90AZgZCVF/YYMWzo70EaR/nV/0rteN/aZLmrwvekoRD5iQ8BQvJQopu9O0ydPbs5wZe f8QA== X-Received: by 10.15.101.200 with SMTP id bp48mr17396717eeb.38.1365150381138; Fri, 05 Apr 2013 01:26:21 -0700 (PDT) Received: from debian.x201.phnet (45-233.197-178.cust.bluewin.ch. [178.197.233.45]) by mx.google.com with ESMTPS id n2sm14084425eeo.10.2013.04.05.01.26.17 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Apr 2013 01:26:20 -0700 (PDT) Message-ID: <515E8AA6.6020106@gmail.com> Date: Fri, 05 Apr 2013 10:26:14 +0200 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: The development of GNU GRUB Subject: Re: [PATCH] Add testpci command (v4) References: <20120927214211.GS2289@earth.li> <20121011002145.GV2289@earth.li> <20121012221805.GB2289@earth.li> <50FC6F50.9040507@gmail.com> <20130125051241.GP27908@earth.li> In-Reply-To: <20130125051241.GP27908@earth.li> X-Enigmail-Version: 1.4.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enigB8E7938AE1CFBCD60CD42313" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::22a X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Apr 2013 08:26:26 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigB8E7938AE1CFBCD60CD42313 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 25.01.2013 06:12, Jonathan McDowell wrote: > On Sun, Jan 20, 2013 at 11:27:28PM +0100, Vladimir '=CF=86-coder/phcode= r' > Serbinenko wrote: >> > On 13.10.2012 00:18, Jonathan McDowell wrote: > (some code) >> > ARG_TYPE_INT means that the argument is decimal integer but it's not= the >> > case here. >> > Please follow indent style. >> > You need to check grub_errno to catch any error in number parsing. >> > Also you need to update a little bit because of recent callback chan= ges. >> > Other than this the patch is fine. > Ok, I've updated against latest bzr and made the changes as above. > Here's v4. >=20 > Signed-off-by: Jonathan McDowell >=20 > ----- > =3D=3D=3D modified file 'docs/grub.texi' > --- docs/grub.texi 2013-01-21 16:53:41 +0000 > +++ docs/grub.texi 2013-01-23 01:35:32 +0000 > @@ -3366,6 +3366,7 @@ > * sendkey:: Emulate keystrokes > * set:: Set an environment variable > * source:: Read a configuration file in same cont= ext > +* testpci:: Test for the existence of a PCI device= > * true:: Do nothing, successfully > * unset:: Unset an environment variable > * uppermem:: Set the upper memory size > @@ -4147,6 +4148,18 @@ > @end deffn > =20 > =20 > +@node testpci > +@subsection testpci > + > +@deffn Command testpci [@option{--vendor=3DVENDORID}] @ > + [@option{--product=3DPRODUCTID}] [@option{--subvendor VENDORID}] @ > + [@option{--subproduct PRODUCTID}] > +Test for the existence of a given PCI device. Returns true if a device= > +matching the specified vendor/product and/or subvendor/subproduct info= rmation > +is found. > +@end deffn > + > + > @node true > @subsection true > =20 >=20 > =3D=3D=3D modified file 'grub-core/Makefile.core.def' > --- grub-core/Makefile.core.def 2013-01-16 19:44:11 +0000 > +++ grub-core/Makefile.core.def 2013-01-23 01:34:44 +0000 > @@ -862,6 +862,12 @@ > }; > =20 > module =3D { > + name =3D testpci; > + common =3D commands/testpci.c; > + enable =3D pci; > +}; > + > +module =3D { > name =3D true; > common =3D commands/true.c; > }; >=20 > =3D=3D=3D added file 'grub-core/commands/testpci.c' > --- grub-core/commands/testpci.c 1970-01-01 00:00:00 +0000 > +++ grub-core/commands/testpci.c 2013-01-23 22:21:11 +0000 > @@ -0,0 +1,128 @@ > +/* testpci.c - Test for PCI device existence. */ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2013 Free Software Foundation, Inc. > + * > + * GRUB is free software: you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published = by > + * the Free Software Foundation, either version 3 of the License, or > + * (at your option) any later version. > + * > + * GRUB is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with GRUB. If not, see . > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +GRUB_MOD_LICENSE ("GPLv3+"); > + > +static const struct grub_arg_option options[] =3D > + { > + {"vendor", 'v' , 0, N_("PCI vendor ID to look for"), 0, ARG_TYPE_S= TRING}, > + {"product", 'p' , 0, N_("PCI product ID to look for"), 0, ARG_TYPE= _STRING}, > + {"subvendor", 's' , 0, N_("PCI subsystem vendor ID to look for"), = 0, ARG_TYPE_STRING}, > + {"subproduct", 't' , 0, N_("PCI subsystem product ID to look for")= , 0, ARG_TYPE_STRING}, > + {0, 0, 0, 0, 0, 0} > + }; > + > +static grub_uint32_t pcimask, pcisubmask; > +static grub_pci_id_t pcisearch; > +static grub_pci_id_t pcisubsearch; > + This should be inside a structure passed through the iterator, not a static variable. > +static int > +grub_testpci_iter (grub_pci_device_t dev __attribute__ ((unused)), > + grub_pci_id_t pciid, > + void *data) > +{ > + grub_pci_address_t addr; > + grub_uint32_t subsystem; > + int *found =3D data; > + > + if ((pciid & pcimask) !=3D pcisearch) { > + return 0; > + } > + > + if (pcisubmask !=3D 0) { > + addr =3D grub_pci_make_address (dev, GRUB_PCI_REG_SUBVENDOR); > + subsystem =3D grub_pci_read (addr); > + if ((subsystem & pcisubmask) !=3D pcisubsearch) { > + return 0; > + } > + } > + > + *found =3D 1; > + return 1; > +} > + > +static grub_err_t > +grub_cmd_testpci (grub_extcmd_context_t ctxt, > + int argc __attribute__ ((unused)), > + char **args __attribute__ ((unused))) > +{ > + struct grub_arg_list *state =3D ctxt->state; > + int found =3D 0; > + > + pcimask =3D pcisubmask =3D pcisearch =3D pcisubsearch =3D 0; > + > + if (state[0].set) { > + pcisearch |=3D grub_strtoull (state[0].arg, 0, 16); > + if (grub_errno !=3D GRUB_ERR_NONE) { > + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Couldn't parse PCI= vendor ID")); Lowercase c > + } > + pcimask |=3D 0xFFFF; > + } > + > + if (state[1].set) { > + pcisearch |=3D (grub_strtoull (state[1].arg, 0, 16) << 16); > + if (grub_errno !=3D GRUB_ERR_NONE) { > + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Couldn't parse PCI= product ID")); ditto > + } > + pcimask |=3D 0xFFFF0000; > + } > + > + if (state[2].set) { > + pcisubsearch |=3D grub_strtoull (state[2].arg, 0, 16); > + if (grub_errno !=3D GRUB_ERR_NONE) { > + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Couldn't parse PCI= subsystem vendor ID")); ditto > + } > + pcisubmask |=3D 0xFFFF; > + } > + > + if (state[3].set) { > + pcisubsearch |=3D (grub_strtoull (state[3].arg, 0, 16) << 16); > + if (grub_errno !=3D GRUB_ERR_NONE) { > + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Couldn't parse PCI= subsystem product ID")); ditto. > + } > + pcisubmask |=3D 0xFFFF0000; > + } > + > + grub_pci_iterate (grub_testpci_iter, &found); > + > + return found ? GRUB_ERR_NONE : grub_error (GRUB_ERR_TEST_FAILURE, "f= alse"); > +} > + > +static grub_extcmd_t cmd; > + > +GRUB_MOD_INIT(testpci) > +{ > + cmd =3D grub_register_extcmd ("testpci", grub_cmd_testpci, 0, > + N_("[--vendor=3DVENDORID] [--product=3DPRODUCTID] " > + "[--subvendor=3DVENDORID] " > + "[--subproduct=3DPRODUCTID]"), > + N_("Test for PCI device existence."), > + options); > +} > + > +GRUB_MOD_FINI(testpci) > +{ > + grub_unregister_extcmd (cmd); > +} >=20 > ----- >=20 > J. >=20 > -- "Basically, if you're allowed to own it, you're probably allowed to > burn it." -- Stephen Gower, ox.general >=20 >=20 >=20 > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel >=20 --------------enigB8E7938AE1CFBCD60CD42313 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iF4EAREKAAYFAlFeiqcACgkQNak7dOguQgmywQD/cPs7T24a7rHtUvSzf/R6RhUk KqI+LqZNzc0HmCCanLkA/3flsWx35xU4gSx+gMljjpNG31CUzWgCc02UsRKXfxyW =FzUU -----END PGP SIGNATURE----- --------------enigB8E7938AE1CFBCD60CD42313--