From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Tx3MW-0006U3-G0 for mharc-grub-devel@gnu.org; Sun, 20 Jan 2013 17:27:36 -0500 Received: from eggs.gnu.org ([208.118.235.92]:32884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tx3MU-0006Tx-7G for grub-devel@gnu.org; Sun, 20 Jan 2013 17:27:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tx3MS-0001Nl-Ly for grub-devel@gnu.org; Sun, 20 Jan 2013 17:27:34 -0500 Received: from mail-ea0-f169.google.com ([209.85.215.169]:64829) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tx3MS-0001Nh-CA for grub-devel@gnu.org; Sun, 20 Jan 2013 17:27:32 -0500 Received: by mail-ea0-f169.google.com with SMTP id d13so2279096eaa.0 for ; Sun, 20 Jan 2013 14:27:31 -0800 (PST) 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=GQfpmyK34YAO5xvwbg76hb7UP3K0gBtPH5NfcGqhzsI=; b=WKEwTB+IKv3Y4nSVHcFiv+JuTv6ZEymzuVny5YQ4F8LanNPs2t0ypi23vvL4SUJWpi 6nvrJScBGbg+TMWW3lVugZho5EJxnxwrMK90hlhzs+sQ8bpapt/gPTEE7sR2Jxa6lRmJ 2xeSG+azN4jLgz82q/D5o3GbYSxFyxBF5866w9Xqui20pUKVHhpE9EkKLN5WrWjHS9dH UpWtfIJDMbTDPggcQ8N1MIjwwjCwqnjsbmE2G/IW6dwnSk+d1jkVLwg2yfkcAuWicOFy No1sV5oKzLeLkZwbP91I5tDBhWKtxISxi4bpfyS1+8/2KwbOsvHDUFqaU3nE7oVQYCpg /TnQ== X-Received: by 10.14.194.4 with SMTP id l4mr53170768een.42.1358720851333; Sun, 20 Jan 2013 14:27:31 -0800 (PST) Received: from debian.x201.phnet (90-165.78-83.cust.bluewin.ch. [83.78.165.90]) by mx.google.com with ESMTPS id 43sm19502993eed.10.2013.01.20.14.27.29 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 20 Jan 2013 14:27:30 -0800 (PST) Message-ID: <50FC6F50.9040507@gmail.com> Date: Sun, 20 Jan 2013 23:27:28 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.11) Gecko/20121122 Icedove/10.0.11 MIME-Version: 1.0 To: The development of GNU GRUB , noodles@earth.li Subject: Re: [PATCH] Add testpci command (v3) References: <20120927214211.GS2289@earth.li> <20121011002145.GV2289@earth.li> <20121012221805.GB2289@earth.li> In-Reply-To: <20121012221805.GB2289@earth.li> X-Enigmail-Version: 1.4.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig582469D69F6FBE90FCF1188B" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.215.169 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: Sun, 20 Jan 2013 22:27:35 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig582469D69F6FBE90FCF1188B Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 13.10.2012 00:18, Jonathan McDowell wrote: > ----- > =3D=3D=3D modified file 'docs/grub.texi' > --- docs/grub.texi 2012-07-31 22:18:57 +0000 > +++ docs/grub.texi 2012-10-12 22:13:23 +0000 > @@ -3302,6 +3302,7 @@ > * search:: Search devices by file, label, or UUID= > * sendkey:: Emulate keystrokes > * set:: Set an environment variable > +* testpci:: Test for the existence of a PCI device= > * true:: Do nothing, successfully > * unset:: Unset an environment variable > * uppermem:: Set the upper memory size > @@ -4068,6 +4069,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 2012-09-08 07:40:24 +0000 > +++ grub-core/Makefile.core.def 2012-09-27 21:00:31 +0000 > @@ -837,6 +837,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 2012-10-12 22:08:21 +0000 > @@ -0,0 +1,114 @@ > +/* testpci.c - Test for PCI device existence. */ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2012 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_I= NT}, > + {"product", 'p' , 0, N_("PCI product ID to look for"), 0, ARG_TYPE= _INT}, > + {"subvendor", 's' , 0, N_("PCI subsystem vendor ID to look for"), = 0, ARG_TYPE_INT}, > + {"subproduct", 't' , 0, N_("PCI subsystem product ID to look for")= , 0, ARG_TYPE_INT}, > + {0, 0, 0, 0, 0, 0} > + }; ARG_TYPE_INT means that the argument is decimal integer but it's not the case here. > + > +static int pcifound; > +static grub_uint32_t pcimask, pcisubmask; > +static grub_pci_id_t pcisearch; > +static grub_pci_id_t pcisubsearch; > + > +static int NESTED_FUNC_ATTR > +grub_testpci_iter (grub_pci_device_t dev __attribute__ ((unused)), > + grub_pci_id_t pciid) > +{ > + grub_pci_address_t addr; > + grub_uint32_t subsystem; > + > + 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; > + } > + } > + Please follow indent style. > + pcifound =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; > + > + pcifound =3D pcimask =3D pcisubmask =3D pcisearch =3D pcisubsearch =3D= 0; > + > + if (state[0].set) { > + pcisearch |=3D grub_strtoull (state[0].arg, 0, 16); > + pcimask |=3D 0xFFFF; > + } > + > + if (state[1].set) { > + pcisearch |=3D (grub_strtoull (state[1].arg, 0, 16) << 16); > + pcimask |=3D 0xFFFF0000; > + } > + > + if (state[2].set) { > + pcisubsearch |=3D grub_strtoull (state[2].arg, 0, 16); > + pcisubmask |=3D 0xFFFF; > + } > + > + if (state[3].set) { > + pcisubsearch |=3D (grub_strtoull (state[3].arg, 0, 16) << 16); > + pcisubmask |=3D 0xFFFF0000; > + } > + 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 changes. Other than this the patch is fine. --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------enig582469D69F6FBE90FCF1188B 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/ iF4EAREKAAYFAlD8b1AACgkQNak7dOguQgkd6QD+NT3Ukd1IhKDx7KgAxLGFtMwZ NyGiJJzymJ0jaGUapk4A/RyATgZH2Id498Rqw586vFJ/D7X1Bzw7qfoPeX3/666/ =S1+H -----END PGP SIGNATURE----- --------------enig582469D69F6FBE90FCF1188B--