All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Baldwin <jhb@freebsd.org>
To: Roger Pau Monne <roger.pau@citrix.com>
Cc: julien.grall@citrix.com, freebsd-xen@freebsd.org,
	freebsd-current@freebsd.org, kib@freebsd.org,
	xen-devel@lists.xenproject.org, gibbs@freebsd.org
Subject: Re: [PATCH RFC 11/13] pci: introduce a new event on PCI device detection
Date: Sat, 08 Feb 2014 16:57:11 -0500	[thread overview]
Message-ID: <2534929.ApYhIx3ttm__2353.69166262007$1392323222$gmane$org@ralph.baldwin.cx> (raw)
In-Reply-To: <1387884062-41154-12-git-send-email-roger.pau@citrix.com>

On Tuesday, December 24, 2013 12:21:00 PM Roger Pau Monne wrote:
> Add a new event that will fire each time a PCI device is added to the
> system, and allows us to register the device with Xen.

It's really hackish to make this PCI specific.  OTOH, I can't think of a
good place to have a more generic new-bus callback.  You could make the
eventhandler pass the 'device_t' instead of the dinfo.  The dinfo isn't
really a public structure, and since the device_t's ivars are already set
you can use things like 'pci_get_domain()' and 'pci_get_bus()' of the
passed in device in your callback function.

> ---
>  sys/dev/pci/pci.c       |    1 +
>  sys/sys/eventhandler.h  |    5 +++++
>  sys/x86/xen/pv.c        |   21 +++++++++++++++++++++
>  sys/x86/xen/xen_nexus.c |    6 ++++++
>  sys/xen/pv.h            |    1 +
>  5 files changed, 34 insertions(+), 0 deletions(-)
> 
> diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c
> index 4d8837f..2ee5093 100644
> --- a/sys/dev/pci/pci.c
> +++ b/sys/dev/pci/pci.c
> @@ -3293,6 +3293,7 @@ pci_add_child(device_t bus, struct pci_devinfo *dinfo)
> resource_list_init(&dinfo->resources);
>  	pci_cfg_save(dinfo->cfg.dev, dinfo, 0);
>  	pci_cfg_restore(dinfo->cfg.dev, dinfo);
> +	EVENTHANDLER_INVOKE(pci_add, dinfo);
>  	pci_print_verbose(dinfo);
>  	pci_add_resources(bus, dinfo->cfg.dev, 0, 0);
>  }
> diff --git a/sys/sys/eventhandler.h b/sys/sys/eventhandler.h
> index 111c21b..3201848 100644
> --- a/sys/sys/eventhandler.h
> +++ b/sys/sys/eventhandler.h
> @@ -269,5 +269,10 @@ typedef void (*unregister_framebuffer_fn)(void *,
> struct fb_info *); EVENTHANDLER_DECLARE(register_framebuffer,
> register_framebuffer_fn); EVENTHANDLER_DECLARE(unregister_framebuffer,
> unregister_framebuffer_fn);
> 
> +/* PCI events */
> +struct pci_devinfo;
> +typedef void (*pci_add_fn)(void *, struct pci_devinfo *);
> +EVENTHANDLER_DECLARE(pci_add, pci_add_fn);
> +
>  #endif /* _SYS_EVENTHANDLER_H_ */
> 
> diff --git a/sys/x86/xen/pv.c b/sys/x86/xen/pv.c
> index e5ad200..a44f8ca 100644
> --- a/sys/x86/xen/pv.c
> +++ b/sys/x86/xen/pv.c
> @@ -39,6 +39,9 @@ __FBSDID("$FreeBSD$");
>  #include <sys/rwlock.h>
>  #include <sys/mutex.h>
>  #include <sys/smp.h>
> +#include <sys/reboot.h>
> +#include <sys/pciio.h>
> +#include <sys/eventhandler.h>
> 
>  #include <vm/vm.h>
>  #include <vm/vm_extern.h>
> @@ -63,6 +66,8 @@ __FBSDID("$FreeBSD$");
> 
>  #include <xen/interface/vcpu.h>
> 
> +#include <dev/pci/pcivar.h>
> +
>  /* Native initial function */
>  extern u_int64_t hammer_time(u_int64_t, u_int64_t);
>  /* Xen initial function */
> @@ -384,6 +389,22 @@ xen_pv_ioapic_register_intr(struct ioapic_intsrc *pin)
>  	xen_register_pirq(pin->io_irq, pin->io_activehi, pin->io_edgetrigger);
>  }
> 
> +void
> +xen_pv_pci_device_add(void *arg, struct pci_devinfo *dinfo)
> +{
> +	struct physdev_pci_device_add add_pci;
> +	int error;
> +
> +	bzero(&add_pci, sizeof(add_pci));
> +	add_pci.seg = dinfo->cfg.domain;
> +	add_pci.bus = dinfo->cfg.bus;
> +	add_pci.devfn = (dinfo->cfg.slot << 3) | dinfo->cfg.func;
> +	error = HYPERVISOR_physdev_op(PHYSDEVOP_pci_device_add, &add_pci);
> +	if (error)
> +		printf("unable to add device bus %u devfn %u error: %d\n",
> +		       add_pci.bus, add_pci.devfn, error);
> +}
> +
>  static void
>  xen_pv_set_init_ops(void)
>  {
> diff --git a/sys/x86/xen/xen_nexus.c b/sys/x86/xen/xen_nexus.c
> index 823b3bc..60c6c5d 100644
> --- a/sys/x86/xen/xen_nexus.c
> +++ b/sys/x86/xen/xen_nexus.c
> @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$");
>  #include <sys/sysctl.h>
>  #include <sys/systm.h>
>  #include <sys/smp.h>
> +#include <sys/eventhandler.h>
> 
>  #include <contrib/dev/acpica/include/acpi.h>
> 
> @@ -42,6 +43,7 @@ __FBSDID("$FreeBSD$");
>  #include <machine/nexusvar.h>
> 
>  #include <xen/xen-os.h>
> +#include <xen/pv.h>
> 
>  static const char *xen_devices[] =
>  {
> @@ -87,6 +89,10 @@ nexus_xen_attach(device_t dev)
>  		/* Disable some ACPI devices that are not usable by Dom0 */
>  		setenv("debug.acpi.disabled", "cpu hpet timer");
> 
> +		/* Register PCI add hook */
> +		EVENTHANDLER_REGISTER(pci_add, xen_pv_pci_device_add, NULL,
> +		                      EVENTHANDLER_PRI_FIRST);
> +
>  		acpi_dev = BUS_ADD_CHILD(dev, 10, "acpi", 0);
>  		if (acpi_dev == NULL)
>  			panic("Unable to add ACPI bus to Xen Dom0");
> diff --git a/sys/xen/pv.h b/sys/xen/pv.h
> index a9d6eb0..ac737a7 100644
> --- a/sys/xen/pv.h
> +++ b/sys/xen/pv.h
> @@ -24,5 +24,6 @@
>  #define	__XEN_PV_H__
> 
>  int	xen_pv_start_all_aps(void);
> +void	xen_pv_pci_device_add(void *, struct pci_devinfo *);
> 
>  #endif	/* __XEN_PV_H__ */

-- 
John Baldwin

  parent reply	other threads:[~2014-02-13 20:24 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1387884062-41154-1-git-send-email-roger.pau@citrix.com>
2013-12-24 11:20 ` [PATCH RFC 01/13] xen: use the hardware e820 map on Dom0 Roger Pau Monne
2013-12-24 11:20 ` [PATCH RFC 02/13] ioapic: introduce hooks for some ioapic ops Roger Pau Monne
2013-12-24 11:20 ` [PATCH RFC 03/13] xen: mask event channels while changing affinity Roger Pau Monne
2013-12-24 11:20 ` [PATCH RFC 04/13] xen: implement basic PIRQ support for Dom0 Roger Pau Monne
2014-01-21 18:52   ` John Baldwin
2013-12-24 11:20 ` [PATCH RFC 05/13] xen: implement Xen IO APIC ops Roger Pau Monne
2013-12-24 11:20 ` [PATCH RFC 06/13] xen: Dom0 console fixes Roger Pau Monne
2013-12-24 11:20 ` [PATCH RFC 07/13] xen: implement IO APIC support in Xen mptable parser Roger Pau Monne
2013-12-24 11:20 ` [PATCH RFC 08/13] xen: change order of Xen intr init and IO APIC registration Roger Pau Monne
2013-12-24 11:20 ` [PATCH RFC 09/13] xen: change quality of the MADT ACPI enumerator Roger Pau Monne
2014-02-08 21:42   ` John Baldwin
     [not found]   ` <1980951.95r2q2cca3@ralph.baldwin.cx>
2014-02-14  1:49     ` Andrew Cooper
     [not found]     ` <52FD7624.90202@citrix.com>
2014-02-14 17:51       ` John Baldwin
     [not found]       ` <201402141251.10278.jhb@freebsd.org>
2014-02-17 16:01         ` Roger Pau Monné
2013-12-24 11:20 ` [PATCH RFC 10/13] xen: add ACPI bus to xen_nexus when running as Dom0 Roger Pau Monne
2013-12-24 11:21 ` [PATCH RFC 11/13] pci: introduce a new event on PCI device detection Roger Pau Monne
2013-12-24 11:21 ` [PATCH RFC 12/13] mca: disable cmc enable on Xen PV Roger Pau Monne
2013-12-24 11:21 ` [PATCH RFC 13/13] xenstore: changes needed to boot in Dom0 mode Roger Pau Monne
     [not found] ` <1387884062-41154-4-git-send-email-roger.pau@citrix.com>
2014-01-03 20:45   ` [PATCH RFC 03/13] xen: mask event channels while changing affinity Konrad Rzeszutek Wilk
     [not found] ` <1387884062-41154-2-git-send-email-roger.pau@citrix.com>
2014-01-21 18:25   ` [PATCH RFC 01/13] xen: use the hardware e820 map on Dom0 John Baldwin
     [not found] ` <1387884062-41154-3-git-send-email-roger.pau@citrix.com>
2014-01-21 18:27   ` [PATCH RFC 02/13] ioapic: introduce hooks for some ioapic ops John Baldwin
     [not found] ` <1387884062-41154-6-git-send-email-roger.pau@citrix.com>
2014-01-21 18:55   ` [PATCH RFC 05/13] xen: implement Xen IO APIC ops John Baldwin
     [not found] ` <1387884062-41154-7-git-send-email-roger.pau@citrix.com>
2014-01-21 19:02   ` [PATCH RFC 06/13] xen: Dom0 console fixes John Baldwin
     [not found] ` <1387884062-41154-8-git-send-email-roger.pau@citrix.com>
2014-02-08 21:36   ` [PATCH RFC 07/13] xen: implement IO APIC support in Xen mptable parser John Baldwin
     [not found] ` <1387884062-41154-9-git-send-email-roger.pau@citrix.com>
2014-02-08 21:37   ` [PATCH RFC 08/13] xen: change order of Xen intr init and IO APIC registration John Baldwin
     [not found] ` <1387884062-41154-11-git-send-email-roger.pau@citrix.com>
2014-02-08 21:50   ` [PATCH RFC 10/13] xen: add ACPI bus to xen_nexus when running as Dom0 John Baldwin
     [not found]   ` <2410827.IqfpSAhe3T@ralph.baldwin.cx>
2014-02-14 10:38     ` Roger Pau Monné
     [not found]     ` <52FDF217.3040005@citrix.com>
2014-02-14 17:50       ` John Baldwin
     [not found] ` <1387884062-41154-12-git-send-email-roger.pau@citrix.com>
2014-02-08 21:57   ` John Baldwin [this message]
     [not found] ` <1387884062-41154-13-git-send-email-roger.pau@citrix.com>
2014-02-08 22:02   ` [PATCH RFC 12/13] mca: disable cmc enable on Xen PV John Baldwin

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='2534929.ApYhIx3ttm__2353.69166262007$1392323222$gmane$org@ralph.baldwin.cx' \
    --to=jhb@freebsd.org \
    --cc=freebsd-current@freebsd.org \
    --cc=freebsd-xen@freebsd.org \
    --cc=gibbs@freebsd.org \
    --cc=julien.grall@citrix.com \
    --cc=kib@freebsd.org \
    --cc=roger.pau@citrix.com \
    --cc=xen-devel@lists.xenproject.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 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.