From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>, noodles@earth.li
Subject: Re: [PATCH] Add testpci command (v3)
Date: Sun, 20 Jan 2013 23:27:28 +0100 [thread overview]
Message-ID: <50FC6F50.9040507@gmail.com> (raw)
In-Reply-To: <20121012221805.GB2289@earth.li>
[-- Attachment #1: Type: text/plain, Size: 5174 bytes --]
On 13.10.2012 00:18, Jonathan McDowell wrote:
> -----
> === 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
>
>
> +@node testpci
> +@subsection testpci
> +
> +@deffn Command testpci [@option{--vendor=VENDORID}] @
> + [@option{--product=PRODUCTID}] [@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 information
> +is found.
> +@end deffn
> +
> +
> @node true
> @subsection true
>
>
> === 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 @@
> };
>
> module = {
> + name = testpci;
> + common = commands/testpci.c;
> + enable = pci;
> +};
> +
> +module = {
> name = true;
> common = commands/true.c;
> };
>
> === 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 <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <grub/pci.h>
> +#include <grub/dl.h>
> +#include <grub/extcmd.h>
> +#include <grub/misc.h>
> +#include <grub/i18n.h>
> +
> +GRUB_MOD_LICENSE ("GPLv3+");
> +
> +static const struct grub_arg_option options[] =
> + {
> + {"vendor", 'v' , 0, N_("PCI vendor ID to look for"), 0, ARG_TYPE_INT},
> + {"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) != pcisearch) {
> + return 0;
> + }
> +
> + if (pcisubmask != 0) {
> + addr = grub_pci_make_address (dev, GRUB_PCI_REG_SUBVENDOR);
> + subsystem = grub_pci_read (addr);
> + if ((subsystem & pcisubmask) != pcisubsearch) {
> + return 0;
> + }
> + }
> +
Please follow indent style.
> + pcifound = 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 = ctxt->state;
> +
> + pcifound = pcimask = pcisubmask = pcisearch = pcisubsearch = 0;
> +
> + if (state[0].set) {
> + pcisearch |= grub_strtoull (state[0].arg, 0, 16);
> + pcimask |= 0xFFFF;
> + }
> +
> + if (state[1].set) {
> + pcisearch |= (grub_strtoull (state[1].arg, 0, 16) << 16);
> + pcimask |= 0xFFFF0000;
> + }
> +
> + if (state[2].set) {
> + pcisubsearch |= grub_strtoull (state[2].arg, 0, 16);
> + pcisubmask |= 0xFFFF;
> + }
> +
> + if (state[3].set) {
> + pcisubsearch |= (grub_strtoull (state[3].arg, 0, 16) << 16);
> + pcisubmask |= 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.
--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]
next prev parent reply other threads:[~2013-01-20 22:27 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-27 21:42 [PATCH] Add testpci command Jonathan McDowell
2012-09-28 1:14 ` Seth Goldberg
2012-09-28 1:16 ` Seth Goldberg
2012-09-28 12:10 ` Andrey Borzenkov
2012-09-28 16:05 ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-09-28 16:34 ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-10-11 0:21 ` [PATCH] Add testpci command (v2) Jonathan McDowell
2012-10-11 2:54 ` Andrey Borzenkov
2012-10-12 22:18 ` [PATCH] Add testpci command (v3) Jonathan McDowell
2013-01-20 22:27 ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]
2013-01-25 5:12 ` [PATCH] Add testpci command (v4) Jonathan McDowell
2013-01-25 5:22 ` Andrey Borzenkov
2013-01-25 8:42 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-01-25 10:06 ` Andrey Borzenkov
2013-01-28 6:47 ` [PATCH] Add testpci command (v5) Jonathan McDowell
2013-04-05 8:26 ` [PATCH] Add testpci command (v4) Vladimir 'φ-coder/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=50FC6F50.9040507@gmail.com \
--to=phcoder@gmail.com \
--cc=grub-devel@gnu.org \
--cc=noodles@earth.li \
/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.