Re: [PATCH] pci: generic host: make it more generic

2015-01-15 Thread Alexander Graf
On 11.11.14 11:33, Ming Lei wrote:
> This patch converts the generic host controller driver
> into a more generic one, and basically don't need
> platform's pcibios support, and use DT based generic
> APIs to parse resource and remap IO port.
> 
> This patch has been tested on both ARMv7 and ARMv8
> VM, and in theroy it should support other ARCHs too.
> 
> With this patch, virtio PCI block, network and scsi devices
> can work well on ARMv7 and ARMv8 VM.
> 
> QEMU needs below patches for runing the test:
> 
> - Rob Herring's "Add generic PCI host device" patches
>   http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg03482.html
>   http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg03483.html
> - Alvise Rigo's "Add Generic PCI host device update"
>   http://marc.info/?l=qemu-devel=140506329920172=2
> 
> For ARMv8, cpu model of "host" and "cortex-a57" is missed
> in Alvise Rigo's patchset, otherwise ARM64 VM can't boot.
> 
> All these QEMU patches can be found in below tree:
> 
>   
> http://kernel.ubuntu.com/git?p=ming/qemu.git;a=shortlog;h=refs/heads/arm64-pci-test
> 
> Signed-off-by: Ming Lei 
> ---
>  drivers/pci/host/Kconfig|2 +-
>  drivers/pci/host/pci-host-generic.c |  196 
> +++
>  2 files changed, 63 insertions(+), 135 deletions(-)
> 
> diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig
> index 3dc25fa..885034d 100644
> --- a/drivers/pci/host/Kconfig
> +++ b/drivers/pci/host/Kconfig
> @@ -50,7 +50,7 @@ config PCI_RCAR_GEN2_PCIE
>  
>  config PCI_HOST_GENERIC
>   bool "Generic PCI host controller"
> - depends on ARM && OF
> + depends on OF
>   help
> Say Y here if you want to support a simple generic PCI host
> controller, such as the one emulated by kvmtool.
> diff --git a/drivers/pci/host/pci-host-generic.c 
> b/drivers/pci/host/pci-host-generic.c
> index 3d2076f..00d0ca3 100644
> --- a/drivers/pci/host/pci-host-generic.c
> +++ b/drivers/pci/host/pci-host-generic.c
> @@ -44,12 +44,14 @@ struct gen_pci {
>   struct list_headresources;
>  };
>  
> +/* fake sysdata for cheating ARCH's pcibios code */
> +static char  gen_sysdata[256];
> +
>  static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus,
>unsigned int devfn,
>int where)
>  {
> - struct pci_sys_data *sys = bus->sysdata;
> - struct gen_pci *pci = sys->private_data;
> + struct gen_pci *pci = dev_get_drvdata(bus->dev.parent->parent);

Just as a heads up, this breaks when you have PCI bridges in between. In
that case you need something like the ugly patch below on top.


Alex


diff --git a/drivers/pci/host/pci-host-generic.c
b/drivers/pci/host/pci-host-generic.c
index e580296..730a07b 100644
--- a/drivers/pci/host/pci-host-generic.c
+++ b/drivers/pci/host/pci-host-generic.c
@@ -47,11 +47,26 @@ struct gen_pci {
 /* fake sysdata for cheating ARCH's pcibios code */
 static chargen_sysdata[256];

+static struct gen_pci *gen_pci_get_drvdata(struct pci_bus *bus)
+{
+   struct device *dev = bus->dev.parent->parent;
+   struct gen_pci *pci;
+
+   while (dev) {
+   pci = dev_get_drvdata(dev);
+   if (pci)
+   return pci;
+   dev = dev->parent;
+   }
+
+   return NULL;
+}
+
 static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus,
 unsigned int devfn,
 int where)
 {
-   struct gen_pci *pci = dev_get_drvdata(bus->dev.parent->parent);
+   struct gen_pci *pci = gen_pci_get_drvdata(bus);
resource_size_t idx = bus->number - pci->cfg.bus_range.start;

return pci->cfg.win[idx] + ((devfn << 8) | where);
@@ -66,7 +81,7 @@ static void __iomem *gen_pci_map_cfg_bus_ecam(struct
pci_bus *bus,
  unsigned int devfn,
  int where)
 {
-   struct gen_pci *pci = dev_get_drvdata(bus->dev.parent->parent);
+   struct gen_pci *pci = gen_pci_get_drvdata(bus);
resource_size_t idx = bus->number - pci->cfg.bus_range.start;

return pci->cfg.win[idx] + ((devfn << 12) | where);
@@ -81,7 +96,11 @@ static int gen_pci_config_read(struct pci_bus *bus,
unsigned int devfn,
int where, int size, u32 *val)
 {
void __iomem *addr;
-   struct gen_pci *pci = dev_get_drvdata(bus->dev.parent->parent);
+   struct gen_pci *pci = gen_pci_get_drvdata(bus);
+
+   WARN_ON(!pci);
+   if (!pci)
+   return PCIBIOS_DEVICE_NOT_FOUND;

addr = pci->cfg.ops->map_bus(bus, devfn, where);

@@ -103,7 +122,11 @@ static int gen_pci_config_write(struct pci_bus
*bus, unsigned int devfn,
 int where, int size, u32 val)
 {
void __iomem *addr;
-   

Re: [PATCH] pci: generic host: make it more generic

2015-01-15 Thread Alexander Graf
On 11.11.14 11:33, Ming Lei wrote:
 This patch converts the generic host controller driver
 into a more generic one, and basically don't need
 platform's pcibios support, and use DT based generic
 APIs to parse resource and remap IO port.
 
 This patch has been tested on both ARMv7 and ARMv8
 VM, and in theroy it should support other ARCHs too.
 
 With this patch, virtio PCI block, network and scsi devices
 can work well on ARMv7 and ARMv8 VM.
 
 QEMU needs below patches for runing the test:
 
 - Rob Herring's Add generic PCI host device patches
   http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg03482.html
   http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg03483.html
 - Alvise Rigo's Add Generic PCI host device update
   http://marc.info/?l=qemu-develm=140506329920172w=2
 
 For ARMv8, cpu model of host and cortex-a57 is missed
 in Alvise Rigo's patchset, otherwise ARM64 VM can't boot.
 
 All these QEMU patches can be found in below tree:
 
   
 http://kernel.ubuntu.com/git?p=ming/qemu.git;a=shortlog;h=refs/heads/arm64-pci-test
 
 Signed-off-by: Ming Lei ming@canonical.com
 ---
  drivers/pci/host/Kconfig|2 +-
  drivers/pci/host/pci-host-generic.c |  196 
 +++
  2 files changed, 63 insertions(+), 135 deletions(-)
 
 diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig
 index 3dc25fa..885034d 100644
 --- a/drivers/pci/host/Kconfig
 +++ b/drivers/pci/host/Kconfig
 @@ -50,7 +50,7 @@ config PCI_RCAR_GEN2_PCIE
  
  config PCI_HOST_GENERIC
   bool Generic PCI host controller
 - depends on ARM  OF
 + depends on OF
   help
 Say Y here if you want to support a simple generic PCI host
 controller, such as the one emulated by kvmtool.
 diff --git a/drivers/pci/host/pci-host-generic.c 
 b/drivers/pci/host/pci-host-generic.c
 index 3d2076f..00d0ca3 100644
 --- a/drivers/pci/host/pci-host-generic.c
 +++ b/drivers/pci/host/pci-host-generic.c
 @@ -44,12 +44,14 @@ struct gen_pci {
   struct list_headresources;
  };
  
 +/* fake sysdata for cheating ARCH's pcibios code */
 +static char  gen_sysdata[256];
 +
  static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus,
unsigned int devfn,
int where)
  {
 - struct pci_sys_data *sys = bus-sysdata;
 - struct gen_pci *pci = sys-private_data;
 + struct gen_pci *pci = dev_get_drvdata(bus-dev.parent-parent);

Just as a heads up, this breaks when you have PCI bridges in between. In
that case you need something like the ugly patch below on top.


Alex


diff --git a/drivers/pci/host/pci-host-generic.c
b/drivers/pci/host/pci-host-generic.c
index e580296..730a07b 100644
--- a/drivers/pci/host/pci-host-generic.c
+++ b/drivers/pci/host/pci-host-generic.c
@@ -47,11 +47,26 @@ struct gen_pci {
 /* fake sysdata for cheating ARCH's pcibios code */
 static chargen_sysdata[256];

+static struct gen_pci *gen_pci_get_drvdata(struct pci_bus *bus)
+{
+   struct device *dev = bus-dev.parent-parent;
+   struct gen_pci *pci;
+
+   while (dev) {
+   pci = dev_get_drvdata(dev);
+   if (pci)
+   return pci;
+   dev = dev-parent;
+   }
+
+   return NULL;
+}
+
 static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus,
 unsigned int devfn,
 int where)
 {
-   struct gen_pci *pci = dev_get_drvdata(bus-dev.parent-parent);
+   struct gen_pci *pci = gen_pci_get_drvdata(bus);
resource_size_t idx = bus-number - pci-cfg.bus_range.start;

return pci-cfg.win[idx] + ((devfn  8) | where);
@@ -66,7 +81,7 @@ static void __iomem *gen_pci_map_cfg_bus_ecam(struct
pci_bus *bus,
  unsigned int devfn,
  int where)
 {
-   struct gen_pci *pci = dev_get_drvdata(bus-dev.parent-parent);
+   struct gen_pci *pci = gen_pci_get_drvdata(bus);
resource_size_t idx = bus-number - pci-cfg.bus_range.start;

return pci-cfg.win[idx] + ((devfn  12) | where);
@@ -81,7 +96,11 @@ static int gen_pci_config_read(struct pci_bus *bus,
unsigned int devfn,
int where, int size, u32 *val)
 {
void __iomem *addr;
-   struct gen_pci *pci = dev_get_drvdata(bus-dev.parent-parent);
+   struct gen_pci *pci = gen_pci_get_drvdata(bus);
+
+   WARN_ON(!pci);
+   if (!pci)
+   return PCIBIOS_DEVICE_NOT_FOUND;

addr = pci-cfg.ops-map_bus(bus, devfn, where);

@@ -103,7 +122,11 @@ static int gen_pci_config_write(struct pci_bus
*bus, unsigned int devfn,
 int where, int size, u32 val)
 {
void __iomem *addr;
-   struct gen_pci *pci = dev_get_drvdata(bus-dev.parent-parent);
+   struct 

Re: [PATCH] pci: generic host: make it more generic

2014-11-12 Thread Bjorn Helgaas
On Wed, Nov 12, 2014 at 1:58 AM, Ming Lei  wrote:
> On Wed, Nov 12, 2014 at 10:47 AM, Bjorn Helgaas  wrote:
>> On Tue, Nov 11, 2014 at 7:12 PM, Ming Lei  wrote:
>>> ...
>>> Do you think it is doable to introduce a option(from module
>>> parameter, or device tree, ...) to let the driver and PCI core
>>> ignore/bypass all pcibios handling for the generic bus?
>>
>> No, I don't think so.
>
> Could you explain a bit? In VM world, it might be reasonable to
> claim that there is no pcibios service or pcibios service needn't.
>
> IMO it isn't easy to make a cross-arch PCI generic controller
> driver if pcibios handling has to be involved.

I'm not going to add kernel or module parameters to change the way the
basic code works.  We need a way to factor the differences so the PCI
core code is the same for all arches, and the differences are hidden
in the arch-specific code.

That's basically what the pcibios interfaces do.  I suspect they were
originally named "pcibios" because there's a "PCI BIOS" spec that
tells you how to make BIOS calls to enumerate devices, access config
space, manage interrupts, etc.  But "pcibios" is now just the name of
interfaces to arch-specific functionality.  Most arches don't have a
BIOS, and most pcibios_*() functions don't make BIOS calls.

If you have a new arch that has no "pcibios service" (I don't know
exactly what you mean by that), you can still implement the
pcibios_*() interfaces used by the PCI core.  If some of these
interfaces don't actually do anything on your arch, that's fine; they
can be no-ops.

Bjorn
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-12 Thread Ming Lei
On Wed, Nov 12, 2014 at 8:32 PM, Lorenzo Pieralisi
 wrote:
> On Wed, Nov 12, 2014 at 10:51:31AM +, Ming Lei wrote:
>> On Wed, Nov 12, 2014 at 5:58 PM, Lorenzo Pieralisi
>>  wrote:
>> > On Wed, Nov 12, 2014 at 02:12:12AM +, Ming Lei wrote:
>> >> On Wed, Nov 12, 2014 at 2:24 AM, Lorenzo Pieralisi
>> >>  wrote:
>> >> > On Tue, Nov 11, 2014 at 02:02:20PM +, Ming Lei wrote:
>> >> >
>> >> > [...]
>> >> >
>> >> >> > http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/296535.html
>> >> >> >
>> >> >> > Patch above is already queued and applies most of the changes you 
>> >> >> > have posted
>> >> >> > above.
>> >> >>
>> >> >> I should have looked at list first before writing the patch, :-(
>> >> >>
>> >> >> Could you make it more generic so that other ARCHs(at least ARM64)
>> >> >> can benefit from it too?
>> >> >
>> >> > That's our current goal, we are carrying out clean-ups to remove arch
>> >> > dependency and move code to the generic layer PCI layer.
>> >>
>> >> OK, I am glad to test them after you post them out.
>> >>
>> >> At least, the 'struct gen_pci' pointer can be put in driver data
>> >> of the platform_device now, which may remove dependency on
>> >> pci_sysdata in this driver.  But ARCH's pcibios code still may
>> >> access 'pci_sysdata', do you have patches or solution to handle
>> >> this issue?
>> >
>> > I will consider adding struct gen_pci pointer as platform device
>> > driver data, we are working on removing pci_sys_data dependency in the ARM
>> > pcibios backend, and I do not think we are far from achieving that.
>>
>> Other ARCHs has sort of pcibios backend too, so that said it still
>> depends on ARM or ARM64, doesn't it?
>
> Yes, so ? If you think there is a way to make this host controller work

I mean suppose the driver/device is only for ARM and ARM64, it
should be easy to support, and it may not be necessary to remove
pci_sys_data dependency in the ARM, such as:

- make a different code path for ARM64
- or like this patch to fake sysdata for ARM
- or what ever

> on all arches you fancy using it on with no arch dependency in a proper
> way step up to the plate and post the code, we will duly review it.

The only way I thought of is to bypass pcibios handling for the
generic host controller, but it may not be agreed.

Thanks,
Ming Lei
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-12 Thread Lorenzo Pieralisi
On Wed, Nov 12, 2014 at 10:51:31AM +, Ming Lei wrote:
> On Wed, Nov 12, 2014 at 5:58 PM, Lorenzo Pieralisi
>  wrote:
> > On Wed, Nov 12, 2014 at 02:12:12AM +, Ming Lei wrote:
> >> On Wed, Nov 12, 2014 at 2:24 AM, Lorenzo Pieralisi
> >>  wrote:
> >> > On Tue, Nov 11, 2014 at 02:02:20PM +, Ming Lei wrote:
> >> >
> >> > [...]
> >> >
> >> >> > http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/296535.html
> >> >> >
> >> >> > Patch above is already queued and applies most of the changes you 
> >> >> > have posted
> >> >> > above.
> >> >>
> >> >> I should have looked at list first before writing the patch, :-(
> >> >>
> >> >> Could you make it more generic so that other ARCHs(at least ARM64)
> >> >> can benefit from it too?
> >> >
> >> > That's our current goal, we are carrying out clean-ups to remove arch
> >> > dependency and move code to the generic layer PCI layer.
> >>
> >> OK, I am glad to test them after you post them out.
> >>
> >> At least, the 'struct gen_pci' pointer can be put in driver data
> >> of the platform_device now, which may remove dependency on
> >> pci_sysdata in this driver.  But ARCH's pcibios code still may
> >> access 'pci_sysdata', do you have patches or solution to handle
> >> this issue?
> >
> > I will consider adding struct gen_pci pointer as platform device
> > driver data, we are working on removing pci_sys_data dependency in the ARM
> > pcibios backend, and I do not think we are far from achieving that.
> 
> Other ARCHs has sort of pcibios backend too, so that said it still
> depends on ARM or ARM64, doesn't it?

Yes, so ? If you think there is a way to make this host controller work
on all arches you fancy using it on with no arch dependency in a proper
way step up to the plate and post the code, we will duly review it.

Thanks,
Lorenzo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-12 Thread Ming Lei
On Wed, Nov 12, 2014 at 5:58 PM, Lorenzo Pieralisi
 wrote:
> On Wed, Nov 12, 2014 at 02:12:12AM +, Ming Lei wrote:
>> On Wed, Nov 12, 2014 at 2:24 AM, Lorenzo Pieralisi
>>  wrote:
>> > On Tue, Nov 11, 2014 at 02:02:20PM +, Ming Lei wrote:
>> >
>> > [...]
>> >
>> >> > http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/296535.html
>> >> >
>> >> > Patch above is already queued and applies most of the changes you have 
>> >> > posted
>> >> > above.
>> >>
>> >> I should have looked at list first before writing the patch, :-(
>> >>
>> >> Could you make it more generic so that other ARCHs(at least ARM64)
>> >> can benefit from it too?
>> >
>> > That's our current goal, we are carrying out clean-ups to remove arch
>> > dependency and move code to the generic layer PCI layer.
>>
>> OK, I am glad to test them after you post them out.
>>
>> At least, the 'struct gen_pci' pointer can be put in driver data
>> of the platform_device now, which may remove dependency on
>> pci_sysdata in this driver.  But ARCH's pcibios code still may
>> access 'pci_sysdata', do you have patches or solution to handle
>> this issue?
>
> I will consider adding struct gen_pci pointer as platform device
> driver data, we are working on removing pci_sys_data dependency in the ARM
> pcibios backend, and I do not think we are far from achieving that.

Other ARCHs has sort of pcibios backend too, so that said it still
depends on ARM or ARM64, doesn't it?

Thanks,
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-12 Thread Lorenzo Pieralisi
On Wed, Nov 12, 2014 at 02:12:12AM +, Ming Lei wrote:
> On Wed, Nov 12, 2014 at 2:24 AM, Lorenzo Pieralisi
>  wrote:
> > On Tue, Nov 11, 2014 at 02:02:20PM +, Ming Lei wrote:
> >
> > [...]
> >
> >> > http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/296535.html
> >> >
> >> > Patch above is already queued and applies most of the changes you have 
> >> > posted
> >> > above.
> >>
> >> I should have looked at list first before writing the patch, :-(
> >>
> >> Could you make it more generic so that other ARCHs(at least ARM64)
> >> can benefit from it too?
> >
> > That's our current goal, we are carrying out clean-ups to remove arch
> > dependency and move code to the generic layer PCI layer.
> 
> OK, I am glad to test them after you post them out.
> 
> At least, the 'struct gen_pci' pointer can be put in driver data
> of the platform_device now, which may remove dependency on
> pci_sysdata in this driver.  But ARCH's pcibios code still may
> access 'pci_sysdata', do you have patches or solution to handle
> this issue?

I will consider adding struct gen_pci pointer as platform device
driver data, we are working on removing pci_sys_data dependency in the ARM
pcibios backend, and I do not think we are far from achieving that.

Thanks,
Lorenzo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-12 Thread Ming Lei
On Wed, Nov 12, 2014 at 10:47 AM, Bjorn Helgaas  wrote:
> On Tue, Nov 11, 2014 at 7:12 PM, Ming Lei  wrote:
>> ...
>> Do you think it is doable to introduce a option(from module
>> parameter, or device tree, ...) to let the driver and PCI core
>> ignore/bypass all pcibios handling for the generic bus?
>
> No, I don't think so.

Could you explain a bit? In VM world, it might be reasonable to
claim that there is no pcibios service or pcibios service needn't.

IMO it isn't easy to make a cross-arch PCI generic controller
driver if pcibios handling has to be involved.

Thanks,
Ming Lei
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-12 Thread Ming Lei
On Wed, Nov 12, 2014 at 10:47 AM, Bjorn Helgaas bhelg...@google.com wrote:
 On Tue, Nov 11, 2014 at 7:12 PM, Ming Lei ming@canonical.com wrote:
 ...
 Do you think it is doable to introduce a option(from module
 parameter, or device tree, ...) to let the driver and PCI core
 ignore/bypass all pcibios handling for the generic bus?

 No, I don't think so.

Could you explain a bit? In VM world, it might be reasonable to
claim that there is no pcibios service or pcibios service needn't.

IMO it isn't easy to make a cross-arch PCI generic controller
driver if pcibios handling has to be involved.

Thanks,
Ming Lei
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-12 Thread Lorenzo Pieralisi
On Wed, Nov 12, 2014 at 02:12:12AM +, Ming Lei wrote:
 On Wed, Nov 12, 2014 at 2:24 AM, Lorenzo Pieralisi
 lorenzo.pieral...@arm.com wrote:
  On Tue, Nov 11, 2014 at 02:02:20PM +, Ming Lei wrote:
 
  [...]
 
   http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/296535.html
  
   Patch above is already queued and applies most of the changes you have 
   posted
   above.
 
  I should have looked at list first before writing the patch, :-(
 
  Could you make it more generic so that other ARCHs(at least ARM64)
  can benefit from it too?
 
  That's our current goal, we are carrying out clean-ups to remove arch
  dependency and move code to the generic layer PCI layer.
 
 OK, I am glad to test them after you post them out.
 
 At least, the 'struct gen_pci' pointer can be put in driver data
 of the platform_device now, which may remove dependency on
 pci_sysdata in this driver.  But ARCH's pcibios code still may
 access 'pci_sysdata', do you have patches or solution to handle
 this issue?

I will consider adding struct gen_pci pointer as platform device
driver data, we are working on removing pci_sys_data dependency in the ARM
pcibios backend, and I do not think we are far from achieving that.

Thanks,
Lorenzo
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-12 Thread Ming Lei
On Wed, Nov 12, 2014 at 5:58 PM, Lorenzo Pieralisi
lorenzo.pieral...@arm.com wrote:
 On Wed, Nov 12, 2014 at 02:12:12AM +, Ming Lei wrote:
 On Wed, Nov 12, 2014 at 2:24 AM, Lorenzo Pieralisi
 lorenzo.pieral...@arm.com wrote:
  On Tue, Nov 11, 2014 at 02:02:20PM +, Ming Lei wrote:
 
  [...]
 
   http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/296535.html
  
   Patch above is already queued and applies most of the changes you have 
   posted
   above.
 
  I should have looked at list first before writing the patch, :-(
 
  Could you make it more generic so that other ARCHs(at least ARM64)
  can benefit from it too?
 
  That's our current goal, we are carrying out clean-ups to remove arch
  dependency and move code to the generic layer PCI layer.

 OK, I am glad to test them after you post them out.

 At least, the 'struct gen_pci' pointer can be put in driver data
 of the platform_device now, which may remove dependency on
 pci_sysdata in this driver.  But ARCH's pcibios code still may
 access 'pci_sysdata', do you have patches or solution to handle
 this issue?

 I will consider adding struct gen_pci pointer as platform device
 driver data, we are working on removing pci_sys_data dependency in the ARM
 pcibios backend, and I do not think we are far from achieving that.

Other ARCHs has sort of pcibios backend too, so that said it still
depends on ARM or ARM64, doesn't it?

Thanks,
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-12 Thread Lorenzo Pieralisi
On Wed, Nov 12, 2014 at 10:51:31AM +, Ming Lei wrote:
 On Wed, Nov 12, 2014 at 5:58 PM, Lorenzo Pieralisi
 lorenzo.pieral...@arm.com wrote:
  On Wed, Nov 12, 2014 at 02:12:12AM +, Ming Lei wrote:
  On Wed, Nov 12, 2014 at 2:24 AM, Lorenzo Pieralisi
  lorenzo.pieral...@arm.com wrote:
   On Tue, Nov 11, 2014 at 02:02:20PM +, Ming Lei wrote:
  
   [...]
  
http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/296535.html
   
Patch above is already queued and applies most of the changes you 
have posted
above.
  
   I should have looked at list first before writing the patch, :-(
  
   Could you make it more generic so that other ARCHs(at least ARM64)
   can benefit from it too?
  
   That's our current goal, we are carrying out clean-ups to remove arch
   dependency and move code to the generic layer PCI layer.
 
  OK, I am glad to test them after you post them out.
 
  At least, the 'struct gen_pci' pointer can be put in driver data
  of the platform_device now, which may remove dependency on
  pci_sysdata in this driver.  But ARCH's pcibios code still may
  access 'pci_sysdata', do you have patches or solution to handle
  this issue?
 
  I will consider adding struct gen_pci pointer as platform device
  driver data, we are working on removing pci_sys_data dependency in the ARM
  pcibios backend, and I do not think we are far from achieving that.
 
 Other ARCHs has sort of pcibios backend too, so that said it still
 depends on ARM or ARM64, doesn't it?

Yes, so ? If you think there is a way to make this host controller work
on all arches you fancy using it on with no arch dependency in a proper
way step up to the plate and post the code, we will duly review it.

Thanks,
Lorenzo
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-12 Thread Ming Lei
On Wed, Nov 12, 2014 at 8:32 PM, Lorenzo Pieralisi
lorenzo.pieral...@arm.com wrote:
 On Wed, Nov 12, 2014 at 10:51:31AM +, Ming Lei wrote:
 On Wed, Nov 12, 2014 at 5:58 PM, Lorenzo Pieralisi
 lorenzo.pieral...@arm.com wrote:
  On Wed, Nov 12, 2014 at 02:12:12AM +, Ming Lei wrote:
  On Wed, Nov 12, 2014 at 2:24 AM, Lorenzo Pieralisi
  lorenzo.pieral...@arm.com wrote:
   On Tue, Nov 11, 2014 at 02:02:20PM +, Ming Lei wrote:
  
   [...]
  
http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/296535.html
   
Patch above is already queued and applies most of the changes you 
have posted
above.
  
   I should have looked at list first before writing the patch, :-(
  
   Could you make it more generic so that other ARCHs(at least ARM64)
   can benefit from it too?
  
   That's our current goal, we are carrying out clean-ups to remove arch
   dependency and move code to the generic layer PCI layer.
 
  OK, I am glad to test them after you post them out.
 
  At least, the 'struct gen_pci' pointer can be put in driver data
  of the platform_device now, which may remove dependency on
  pci_sysdata in this driver.  But ARCH's pcibios code still may
  access 'pci_sysdata', do you have patches or solution to handle
  this issue?
 
  I will consider adding struct gen_pci pointer as platform device
  driver data, we are working on removing pci_sys_data dependency in the ARM
  pcibios backend, and I do not think we are far from achieving that.

 Other ARCHs has sort of pcibios backend too, so that said it still
 depends on ARM or ARM64, doesn't it?

 Yes, so ? If you think there is a way to make this host controller work

I mean suppose the driver/device is only for ARM and ARM64, it
should be easy to support, and it may not be necessary to remove
pci_sys_data dependency in the ARM, such as:

- make a different code path for ARM64
- or like this patch to fake sysdata for ARM
- or what ever

 on all arches you fancy using it on with no arch dependency in a proper
 way step up to the plate and post the code, we will duly review it.

The only way I thought of is to bypass pcibios handling for the
generic host controller, but it may not be agreed.

Thanks,
Ming Lei
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-12 Thread Bjorn Helgaas
On Wed, Nov 12, 2014 at 1:58 AM, Ming Lei ming@canonical.com wrote:
 On Wed, Nov 12, 2014 at 10:47 AM, Bjorn Helgaas bhelg...@google.com wrote:
 On Tue, Nov 11, 2014 at 7:12 PM, Ming Lei ming@canonical.com wrote:
 ...
 Do you think it is doable to introduce a option(from module
 parameter, or device tree, ...) to let the driver and PCI core
 ignore/bypass all pcibios handling for the generic bus?

 No, I don't think so.

 Could you explain a bit? In VM world, it might be reasonable to
 claim that there is no pcibios service or pcibios service needn't.

 IMO it isn't easy to make a cross-arch PCI generic controller
 driver if pcibios handling has to be involved.

I'm not going to add kernel or module parameters to change the way the
basic code works.  We need a way to factor the differences so the PCI
core code is the same for all arches, and the differences are hidden
in the arch-specific code.

That's basically what the pcibios interfaces do.  I suspect they were
originally named pcibios because there's a PCI BIOS spec that
tells you how to make BIOS calls to enumerate devices, access config
space, manage interrupts, etc.  But pcibios is now just the name of
interfaces to arch-specific functionality.  Most arches don't have a
BIOS, and most pcibios_*() functions don't make BIOS calls.

If you have a new arch that has no pcibios service (I don't know
exactly what you mean by that), you can still implement the
pcibios_*() interfaces used by the PCI core.  If some of these
interfaces don't actually do anything on your arch, that's fine; they
can be no-ops.

Bjorn
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-11 Thread Bjorn Helgaas
On Tue, Nov 11, 2014 at 7:12 PM, Ming Lei  wrote:
> ...
> Do you think it is doable to introduce a option(from module
> parameter, or device tree, ...) to let the driver and PCI core
> ignore/bypass all pcibios handling for the generic bus?

No, I don't think so.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-11 Thread Ming Lei
On Wed, Nov 12, 2014 at 2:24 AM, Lorenzo Pieralisi
 wrote:
> On Tue, Nov 11, 2014 at 02:02:20PM +, Ming Lei wrote:
>
> [...]
>
>> > http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/296535.html
>> >
>> > Patch above is already queued and applies most of the changes you have 
>> > posted
>> > above.
>>
>> I should have looked at list first before writing the patch, :-(
>>
>> Could you make it more generic so that other ARCHs(at least ARM64)
>> can benefit from it too?
>
> That's our current goal, we are carrying out clean-ups to remove arch
> dependency and move code to the generic layer PCI layer.

OK, I am glad to test them after you post them out.

At least, the 'struct gen_pci' pointer can be put in driver data
of the platform_device now, which may remove dependency on
pci_sysdata in this driver.  But ARCH's pcibios code still may
access 'pci_sysdata', do you have patches or solution to handle
this issue?

Do you think it is doable to introduce a option(from module
parameter, or device tree, ...) to let the driver and PCI core
ignore/bypass all pcibios handling for the generic bus?  If that
is OK, it can provide an approach to reach the goal a bit easy.
In reality, generic host controller should be only used by VM,
and VM's firmware shouldn't be very complicated and I think
the option can meet most of demands.

Thanks,
Ming Lei
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-11 Thread Lorenzo Pieralisi
On Tue, Nov 11, 2014 at 02:02:20PM +, Ming Lei wrote:

[...]

> > http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/296535.html
> >
> > Patch above is already queued and applies most of the changes you have 
> > posted
> > above.
> 
> I should have looked at list first before writing the patch, :-(
> 
> Could you make it more generic so that other ARCHs(at least ARM64)
> can benefit from it too?

That's our current goal, we are carrying out clean-ups to remove arch
dependency and move code to the generic layer PCI layer.

Lorenzo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-11 Thread Ming Lei
On Tue, Nov 11, 2014 at 8:29 PM, Lorenzo Pieralisi
 wrote:
> On Tue, Nov 11, 2014 at 10:33:59AM +, Ming Lei wrote:
>> This patch converts the generic host controller driver
>> into a more generic one, and basically don't need
>> platform's pcibios support, and use DT based generic
>> APIs to parse resource and remap IO port.
>>
>> This patch has been tested on both ARMv7 and ARMv8
>> VM, and in theroy it should support other ARCHs too.
>
> In theory, yes.
>
>> With this patch, virtio PCI block, network and scsi devices
>> can work well on ARMv7 and ARMv8 VM.
>>
>> QEMU needs below patches for runing the test:
>>
>> - Rob Herring's "Add generic PCI host device" patches
>>   http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg03482.html
>>   http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg03483.html
>> - Alvise Rigo's "Add Generic PCI host device update"
>>   http://marc.info/?l=qemu-devel=140506329920172=2
>>
>> For ARMv8, cpu model of "host" and "cortex-a57" is missed
>> in Alvise Rigo's patchset, otherwise ARM64 VM can't boot.
>>
>> All these QEMU patches can be found in below tree:
>>
>>   
>> http://kernel.ubuntu.com/git?p=ming/qemu.git;a=shortlog;h=refs/heads/arm64-pci-test
>>
>> Signed-off-by: Ming Lei 
>> ---
>>  drivers/pci/host/Kconfig|2 +-
>>  drivers/pci/host/pci-host-generic.c |  196 
>> +++
>>  2 files changed, 63 insertions(+), 135 deletions(-)
>>
>> diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig
>> index 3dc25fa..885034d 100644
>> --- a/drivers/pci/host/Kconfig
>> +++ b/drivers/pci/host/Kconfig
>> @@ -50,7 +50,7 @@ config PCI_RCAR_GEN2_PCIE
>>
>>  config PCI_HOST_GENERIC
>>   bool "Generic PCI host controller"
>> - depends on ARM && OF
>> + depends on OF
>>   help
>> Say Y here if you want to support a simple generic PCI host
>> controller, such as the one emulated by kvmtool.
>> diff --git a/drivers/pci/host/pci-host-generic.c 
>> b/drivers/pci/host/pci-host-generic.c
>> index 3d2076f..00d0ca3 100644
>> --- a/drivers/pci/host/pci-host-generic.c
>> +++ b/drivers/pci/host/pci-host-generic.c
>> @@ -44,12 +44,14 @@ struct gen_pci {
>>   struct list_headresources;
>>  };
>>
>> +/* fake sysdata for cheating ARCH's pcibios code */
>> +static char  gen_sysdata[256];
>
> I take this as a joke and it does not make me laugh.

One motivation of the patch is to remove ARCH or platform dependency,
that is why the above faked sysdata is introduced, but pci_sysdata is a
generic issue.

>
>>  static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus,
>>unsigned int devfn,
>>int where)
>>  {
>> - struct pci_sys_data *sys = bus->sysdata;
>> - struct gen_pci *pci = sys->private_data;
>> + struct gen_pci *pci = dev_get_drvdata(bus->dev.parent->parent);
>>   resource_size_t idx = bus->number - pci->cfg.bus_range.start;
>>
>>   return pci->cfg.win[idx] + ((devfn << 8) | where);
>> @@ -64,8 +66,7 @@ static void __iomem *gen_pci_map_cfg_bus_ecam(struct 
>> pci_bus *bus,
>> unsigned int devfn,
>> int where)
>>  {
>> - struct pci_sys_data *sys = bus->sysdata;
>> - struct gen_pci *pci = sys->private_data;
>> + struct gen_pci *pci = dev_get_drvdata(bus->dev.parent->parent);
>>   resource_size_t idx = bus->number - pci->cfg.bus_range.start;
>>
>>   return pci->cfg.win[idx] + ((devfn << 12) | where);
>> @@ -80,8 +81,7 @@ static int gen_pci_config_read(struct pci_bus *bus, 
>> unsigned int devfn,
>>   int where, int size, u32 *val)
>>  {
>>   void __iomem *addr;
>> - struct pci_sys_data *sys = bus->sysdata;
>> - struct gen_pci *pci = sys->private_data;
>> + struct gen_pci *pci = dev_get_drvdata(bus->dev.parent->parent);
>>
>>   addr = pci->cfg.ops->map_bus(bus, devfn, where);
>>
>> @@ -103,8 +103,7 @@ static int gen_pci_config_write(struct pci_bus *bus, 
>> unsigned int devfn,
>>int where, int size, u32 val)
>>  {
>>   void __iomem *addr;
>> - struct pci_sys_data *sys = bus->sysdata;
>> - struct gen_pci *pci = sys->private_data;
>> + struct gen_pci *pci = dev_get_drvdata(bus->dev.parent->parent);
>>
>>   addr = pci->cfg.ops->map_bus(bus, devfn, where);
>>
>> @@ -138,45 +137,6 @@ static const struct of_device_id gen_pci_of_match[] = {
>>  };
>>  MODULE_DEVICE_TABLE(of, gen_pci_of_match);
>>
>> -static int gen_pci_calc_io_offset(struct device *dev,
>> -   struct of_pci_range *range,
>> -   struct resource *res,
>> -   resource_size_t *offset)
>> -{
>> - static atomic_t wins = ATOMIC_INIT(0);
>> - int err, idx, max_win;
>> - unsigned int window;
>> -
>> - 

Re: [PATCH] pci: generic host: make it more generic

2014-11-11 Thread Lorenzo Pieralisi
On Tue, Nov 11, 2014 at 10:33:59AM +, Ming Lei wrote:
> This patch converts the generic host controller driver
> into a more generic one, and basically don't need
> platform's pcibios support, and use DT based generic
> APIs to parse resource and remap IO port.
> 
> This patch has been tested on both ARMv7 and ARMv8
> VM, and in theroy it should support other ARCHs too.

In theory, yes.

> With this patch, virtio PCI block, network and scsi devices
> can work well on ARMv7 and ARMv8 VM.
> 
> QEMU needs below patches for runing the test:
> 
> - Rob Herring's "Add generic PCI host device" patches
>   http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg03482.html
>   http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg03483.html
> - Alvise Rigo's "Add Generic PCI host device update"
>   http://marc.info/?l=qemu-devel=140506329920172=2
> 
> For ARMv8, cpu model of "host" and "cortex-a57" is missed
> in Alvise Rigo's patchset, otherwise ARM64 VM can't boot.
> 
> All these QEMU patches can be found in below tree:
> 
>   
> http://kernel.ubuntu.com/git?p=ming/qemu.git;a=shortlog;h=refs/heads/arm64-pci-test
> 
> Signed-off-by: Ming Lei 
> ---
>  drivers/pci/host/Kconfig|2 +-
>  drivers/pci/host/pci-host-generic.c |  196 
> +++
>  2 files changed, 63 insertions(+), 135 deletions(-)
> 
> diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig
> index 3dc25fa..885034d 100644
> --- a/drivers/pci/host/Kconfig
> +++ b/drivers/pci/host/Kconfig
> @@ -50,7 +50,7 @@ config PCI_RCAR_GEN2_PCIE
>  
>  config PCI_HOST_GENERIC
>   bool "Generic PCI host controller"
> - depends on ARM && OF
> + depends on OF
>   help
> Say Y here if you want to support a simple generic PCI host
> controller, such as the one emulated by kvmtool.
> diff --git a/drivers/pci/host/pci-host-generic.c 
> b/drivers/pci/host/pci-host-generic.c
> index 3d2076f..00d0ca3 100644
> --- a/drivers/pci/host/pci-host-generic.c
> +++ b/drivers/pci/host/pci-host-generic.c
> @@ -44,12 +44,14 @@ struct gen_pci {
>   struct list_headresources;
>  };
>  
> +/* fake sysdata for cheating ARCH's pcibios code */
> +static char  gen_sysdata[256];

I take this as a joke and it does not make me laugh.

>  static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus,
>unsigned int devfn,
>int where)
>  {
> - struct pci_sys_data *sys = bus->sysdata;
> - struct gen_pci *pci = sys->private_data;
> + struct gen_pci *pci = dev_get_drvdata(bus->dev.parent->parent);
>   resource_size_t idx = bus->number - pci->cfg.bus_range.start;
>  
>   return pci->cfg.win[idx] + ((devfn << 8) | where);
> @@ -64,8 +66,7 @@ static void __iomem *gen_pci_map_cfg_bus_ecam(struct 
> pci_bus *bus,
> unsigned int devfn,
> int where)
>  {
> - struct pci_sys_data *sys = bus->sysdata;
> - struct gen_pci *pci = sys->private_data;
> + struct gen_pci *pci = dev_get_drvdata(bus->dev.parent->parent);
>   resource_size_t idx = bus->number - pci->cfg.bus_range.start;
>  
>   return pci->cfg.win[idx] + ((devfn << 12) | where);
> @@ -80,8 +81,7 @@ static int gen_pci_config_read(struct pci_bus *bus, 
> unsigned int devfn,
>   int where, int size, u32 *val)
>  {
>   void __iomem *addr;
> - struct pci_sys_data *sys = bus->sysdata;
> - struct gen_pci *pci = sys->private_data;
> + struct gen_pci *pci = dev_get_drvdata(bus->dev.parent->parent);
>  
>   addr = pci->cfg.ops->map_bus(bus, devfn, where);
>  
> @@ -103,8 +103,7 @@ static int gen_pci_config_write(struct pci_bus *bus, 
> unsigned int devfn,
>int where, int size, u32 val)
>  {
>   void __iomem *addr;
> - struct pci_sys_data *sys = bus->sysdata;
> - struct gen_pci *pci = sys->private_data;
> + struct gen_pci *pci = dev_get_drvdata(bus->dev.parent->parent);
>  
>   addr = pci->cfg.ops->map_bus(bus, devfn, where);
>  
> @@ -138,45 +137,6 @@ static const struct of_device_id gen_pci_of_match[] = {
>  };
>  MODULE_DEVICE_TABLE(of, gen_pci_of_match);
>  
> -static int gen_pci_calc_io_offset(struct device *dev,
> -   struct of_pci_range *range,
> -   struct resource *res,
> -   resource_size_t *offset)
> -{
> - static atomic_t wins = ATOMIC_INIT(0);
> - int err, idx, max_win;
> - unsigned int window;
> -
> - if (!PAGE_ALIGNED(range->cpu_addr))
> - return -EINVAL;
> -
> - max_win = (IO_SPACE_LIMIT + 1) / SZ_64K;
> - idx = atomic_inc_return();
> - if (idx > max_win)
> - return -ENOSPC;
> -
> - window = (idx - 1) * SZ_64K;
> - err = pci_ioremap_io(window, range->cpu_addr);
> -  

Re: [PATCH] pci: generic host: make it more generic

2014-11-11 Thread Lorenzo Pieralisi
On Tue, Nov 11, 2014 at 10:33:59AM +, Ming Lei wrote:
 This patch converts the generic host controller driver
 into a more generic one, and basically don't need
 platform's pcibios support, and use DT based generic
 APIs to parse resource and remap IO port.
 
 This patch has been tested on both ARMv7 and ARMv8
 VM, and in theroy it should support other ARCHs too.

In theory, yes.

 With this patch, virtio PCI block, network and scsi devices
 can work well on ARMv7 and ARMv8 VM.
 
 QEMU needs below patches for runing the test:
 
 - Rob Herring's Add generic PCI host device patches
   http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg03482.html
   http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg03483.html
 - Alvise Rigo's Add Generic PCI host device update
   http://marc.info/?l=qemu-develm=140506329920172w=2
 
 For ARMv8, cpu model of host and cortex-a57 is missed
 in Alvise Rigo's patchset, otherwise ARM64 VM can't boot.
 
 All these QEMU patches can be found in below tree:
 
   
 http://kernel.ubuntu.com/git?p=ming/qemu.git;a=shortlog;h=refs/heads/arm64-pci-test
 
 Signed-off-by: Ming Lei ming@canonical.com
 ---
  drivers/pci/host/Kconfig|2 +-
  drivers/pci/host/pci-host-generic.c |  196 
 +++
  2 files changed, 63 insertions(+), 135 deletions(-)
 
 diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig
 index 3dc25fa..885034d 100644
 --- a/drivers/pci/host/Kconfig
 +++ b/drivers/pci/host/Kconfig
 @@ -50,7 +50,7 @@ config PCI_RCAR_GEN2_PCIE
  
  config PCI_HOST_GENERIC
   bool Generic PCI host controller
 - depends on ARM  OF
 + depends on OF
   help
 Say Y here if you want to support a simple generic PCI host
 controller, such as the one emulated by kvmtool.
 diff --git a/drivers/pci/host/pci-host-generic.c 
 b/drivers/pci/host/pci-host-generic.c
 index 3d2076f..00d0ca3 100644
 --- a/drivers/pci/host/pci-host-generic.c
 +++ b/drivers/pci/host/pci-host-generic.c
 @@ -44,12 +44,14 @@ struct gen_pci {
   struct list_headresources;
  };
  
 +/* fake sysdata for cheating ARCH's pcibios code */
 +static char  gen_sysdata[256];

I take this as a joke and it does not make me laugh.

  static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus,
unsigned int devfn,
int where)
  {
 - struct pci_sys_data *sys = bus-sysdata;
 - struct gen_pci *pci = sys-private_data;
 + struct gen_pci *pci = dev_get_drvdata(bus-dev.parent-parent);
   resource_size_t idx = bus-number - pci-cfg.bus_range.start;
  
   return pci-cfg.win[idx] + ((devfn  8) | where);
 @@ -64,8 +66,7 @@ static void __iomem *gen_pci_map_cfg_bus_ecam(struct 
 pci_bus *bus,
 unsigned int devfn,
 int where)
  {
 - struct pci_sys_data *sys = bus-sysdata;
 - struct gen_pci *pci = sys-private_data;
 + struct gen_pci *pci = dev_get_drvdata(bus-dev.parent-parent);
   resource_size_t idx = bus-number - pci-cfg.bus_range.start;
  
   return pci-cfg.win[idx] + ((devfn  12) | where);
 @@ -80,8 +81,7 @@ static int gen_pci_config_read(struct pci_bus *bus, 
 unsigned int devfn,
   int where, int size, u32 *val)
  {
   void __iomem *addr;
 - struct pci_sys_data *sys = bus-sysdata;
 - struct gen_pci *pci = sys-private_data;
 + struct gen_pci *pci = dev_get_drvdata(bus-dev.parent-parent);
  
   addr = pci-cfg.ops-map_bus(bus, devfn, where);
  
 @@ -103,8 +103,7 @@ static int gen_pci_config_write(struct pci_bus *bus, 
 unsigned int devfn,
int where, int size, u32 val)
  {
   void __iomem *addr;
 - struct pci_sys_data *sys = bus-sysdata;
 - struct gen_pci *pci = sys-private_data;
 + struct gen_pci *pci = dev_get_drvdata(bus-dev.parent-parent);
  
   addr = pci-cfg.ops-map_bus(bus, devfn, where);
  
 @@ -138,45 +137,6 @@ static const struct of_device_id gen_pci_of_match[] = {
  };
  MODULE_DEVICE_TABLE(of, gen_pci_of_match);
  
 -static int gen_pci_calc_io_offset(struct device *dev,
 -   struct of_pci_range *range,
 -   struct resource *res,
 -   resource_size_t *offset)
 -{
 - static atomic_t wins = ATOMIC_INIT(0);
 - int err, idx, max_win;
 - unsigned int window;
 -
 - if (!PAGE_ALIGNED(range-cpu_addr))
 - return -EINVAL;
 -
 - max_win = (IO_SPACE_LIMIT + 1) / SZ_64K;
 - idx = atomic_inc_return(wins);
 - if (idx  max_win)
 - return -ENOSPC;
 -
 - window = (idx - 1) * SZ_64K;
 - err = pci_ioremap_io(window, range-cpu_addr);
 - if (err)
 - return err;
 -
 - of_pci_range_to_resource(range, dev-of_node, res);
 - res-start = window;
 - 

Re: [PATCH] pci: generic host: make it more generic

2014-11-11 Thread Ming Lei
On Tue, Nov 11, 2014 at 8:29 PM, Lorenzo Pieralisi
lorenzo.pieral...@arm.com wrote:
 On Tue, Nov 11, 2014 at 10:33:59AM +, Ming Lei wrote:
 This patch converts the generic host controller driver
 into a more generic one, and basically don't need
 platform's pcibios support, and use DT based generic
 APIs to parse resource and remap IO port.

 This patch has been tested on both ARMv7 and ARMv8
 VM, and in theroy it should support other ARCHs too.

 In theory, yes.

 With this patch, virtio PCI block, network and scsi devices
 can work well on ARMv7 and ARMv8 VM.

 QEMU needs below patches for runing the test:

 - Rob Herring's Add generic PCI host device patches
   http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg03482.html
   http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg03483.html
 - Alvise Rigo's Add Generic PCI host device update
   http://marc.info/?l=qemu-develm=140506329920172w=2

 For ARMv8, cpu model of host and cortex-a57 is missed
 in Alvise Rigo's patchset, otherwise ARM64 VM can't boot.

 All these QEMU patches can be found in below tree:

   
 http://kernel.ubuntu.com/git?p=ming/qemu.git;a=shortlog;h=refs/heads/arm64-pci-test

 Signed-off-by: Ming Lei ming@canonical.com
 ---
  drivers/pci/host/Kconfig|2 +-
  drivers/pci/host/pci-host-generic.c |  196 
 +++
  2 files changed, 63 insertions(+), 135 deletions(-)

 diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig
 index 3dc25fa..885034d 100644
 --- a/drivers/pci/host/Kconfig
 +++ b/drivers/pci/host/Kconfig
 @@ -50,7 +50,7 @@ config PCI_RCAR_GEN2_PCIE

  config PCI_HOST_GENERIC
   bool Generic PCI host controller
 - depends on ARM  OF
 + depends on OF
   help
 Say Y here if you want to support a simple generic PCI host
 controller, such as the one emulated by kvmtool.
 diff --git a/drivers/pci/host/pci-host-generic.c 
 b/drivers/pci/host/pci-host-generic.c
 index 3d2076f..00d0ca3 100644
 --- a/drivers/pci/host/pci-host-generic.c
 +++ b/drivers/pci/host/pci-host-generic.c
 @@ -44,12 +44,14 @@ struct gen_pci {
   struct list_headresources;
  };

 +/* fake sysdata for cheating ARCH's pcibios code */
 +static char  gen_sysdata[256];

 I take this as a joke and it does not make me laugh.

One motivation of the patch is to remove ARCH or platform dependency,
that is why the above faked sysdata is introduced, but pci_sysdata is a
generic issue.


  static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus,
unsigned int devfn,
int where)
  {
 - struct pci_sys_data *sys = bus-sysdata;
 - struct gen_pci *pci = sys-private_data;
 + struct gen_pci *pci = dev_get_drvdata(bus-dev.parent-parent);
   resource_size_t idx = bus-number - pci-cfg.bus_range.start;

   return pci-cfg.win[idx] + ((devfn  8) | where);
 @@ -64,8 +66,7 @@ static void __iomem *gen_pci_map_cfg_bus_ecam(struct 
 pci_bus *bus,
 unsigned int devfn,
 int where)
  {
 - struct pci_sys_data *sys = bus-sysdata;
 - struct gen_pci *pci = sys-private_data;
 + struct gen_pci *pci = dev_get_drvdata(bus-dev.parent-parent);
   resource_size_t idx = bus-number - pci-cfg.bus_range.start;

   return pci-cfg.win[idx] + ((devfn  12) | where);
 @@ -80,8 +81,7 @@ static int gen_pci_config_read(struct pci_bus *bus, 
 unsigned int devfn,
   int where, int size, u32 *val)
  {
   void __iomem *addr;
 - struct pci_sys_data *sys = bus-sysdata;
 - struct gen_pci *pci = sys-private_data;
 + struct gen_pci *pci = dev_get_drvdata(bus-dev.parent-parent);

   addr = pci-cfg.ops-map_bus(bus, devfn, where);

 @@ -103,8 +103,7 @@ static int gen_pci_config_write(struct pci_bus *bus, 
 unsigned int devfn,
int where, int size, u32 val)
  {
   void __iomem *addr;
 - struct pci_sys_data *sys = bus-sysdata;
 - struct gen_pci *pci = sys-private_data;
 + struct gen_pci *pci = dev_get_drvdata(bus-dev.parent-parent);

   addr = pci-cfg.ops-map_bus(bus, devfn, where);

 @@ -138,45 +137,6 @@ static const struct of_device_id gen_pci_of_match[] = {
  };
  MODULE_DEVICE_TABLE(of, gen_pci_of_match);

 -static int gen_pci_calc_io_offset(struct device *dev,
 -   struct of_pci_range *range,
 -   struct resource *res,
 -   resource_size_t *offset)
 -{
 - static atomic_t wins = ATOMIC_INIT(0);
 - int err, idx, max_win;
 - unsigned int window;
 -
 - if (!PAGE_ALIGNED(range-cpu_addr))
 - return -EINVAL;
 -
 - max_win = (IO_SPACE_LIMIT + 1) / SZ_64K;
 - idx = atomic_inc_return(wins);
 - if (idx  max_win)
 - return -ENOSPC;
 -
 - window 

Re: [PATCH] pci: generic host: make it more generic

2014-11-11 Thread Lorenzo Pieralisi
On Tue, Nov 11, 2014 at 02:02:20PM +, Ming Lei wrote:

[...]

  http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/296535.html
 
  Patch above is already queued and applies most of the changes you have 
  posted
  above.
 
 I should have looked at list first before writing the patch, :-(
 
 Could you make it more generic so that other ARCHs(at least ARM64)
 can benefit from it too?

That's our current goal, we are carrying out clean-ups to remove arch
dependency and move code to the generic layer PCI layer.

Lorenzo
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-11 Thread Ming Lei
On Wed, Nov 12, 2014 at 2:24 AM, Lorenzo Pieralisi
lorenzo.pieral...@arm.com wrote:
 On Tue, Nov 11, 2014 at 02:02:20PM +, Ming Lei wrote:

 [...]

  http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/296535.html
 
  Patch above is already queued and applies most of the changes you have 
  posted
  above.

 I should have looked at list first before writing the patch, :-(

 Could you make it more generic so that other ARCHs(at least ARM64)
 can benefit from it too?

 That's our current goal, we are carrying out clean-ups to remove arch
 dependency and move code to the generic layer PCI layer.

OK, I am glad to test them after you post them out.

At least, the 'struct gen_pci' pointer can be put in driver data
of the platform_device now, which may remove dependency on
pci_sysdata in this driver.  But ARCH's pcibios code still may
access 'pci_sysdata', do you have patches or solution to handle
this issue?

Do you think it is doable to introduce a option(from module
parameter, or device tree, ...) to let the driver and PCI core
ignore/bypass all pcibios handling for the generic bus?  If that
is OK, it can provide an approach to reach the goal a bit easy.
In reality, generic host controller should be only used by VM,
and VM's firmware shouldn't be very complicated and I think
the option can meet most of demands.

Thanks,
Ming Lei
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] pci: generic host: make it more generic

2014-11-11 Thread Bjorn Helgaas
On Tue, Nov 11, 2014 at 7:12 PM, Ming Lei ming@canonical.com wrote:
 ...
 Do you think it is doable to introduce a option(from module
 parameter, or device tree, ...) to let the driver and PCI core
 ignore/bypass all pcibios handling for the generic bus?

No, I don't think so.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/