All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Isaku Yamahata <yamahata@valinux.co.jp>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH V5 10/29] pci: make pci_bar() aware of header type 1.
Date: Fri, 9 Oct 2009 09:06:48 +0200	[thread overview]
Message-ID: <20091009070648.GH9942@redhat.com> (raw)
In-Reply-To: <1255069742-15724-11-git-send-email-yamahata@valinux.co.jp>

On Fri, Oct 09, 2009 at 03:28:43PM +0900, Isaku Yamahata wrote:
> make pci_bar() aware of header type 1. When PCI_ROM_SLOT
> it should return PCI_ROM_ADDRESS1 (!= PCI_ROM_ADDRESS)
> 
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>

Some minor comments below.
Acked-by: Michael S. Tsirkin <mst@redhat.com>

> ---
>  hw/pci.c |   18 ++++++++++++------
>  hw/pci.h |    3 +++
>  2 files changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/pci.c b/hw/pci.c
> index 755ebad..82c1c3c 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -84,9 +84,15 @@ static const VMStateDescription vmstate_pcibus = {
>      }
>  };
>  
> -static inline int pci_bar(int reg)
> +static int pci_bar(PCIDevice *d, int reg)
>  {
> -    return reg == PCI_ROM_SLOT ? PCI_ROM_ADDRESS : PCI_BASE_ADDRESS_0 + reg * 4;
> +    if (reg == PCI_ROM_SLOT) {
> +        return (d->config[PCI_HEADER_TYPE] & ~PCI_HEADER_TYPE_MULTI_FUNCTION)
> +            == PCI_HEADER_TYPE_BRIDGE ?
> +            PCI_ROM_ADDRESS1 : PCI_ROM_ADDRESS;
> +    }
> +
> +    return PCI_BASE_ADDRESS_0 + reg * 4;
>  }

Nit: it would be nice to write it in a way that does not lead to such
wrapping. How about:

static int pci_bar(PCIDevice *d, int reg)
{
    uint8_t type;
    if (reg != PCI_ROM_SLOT)
	    return PCI_BASE_ADDRESS_0 + reg * 4;

    type = d->config[PCI_HEADER_TYPE] & ~PCI_HEADER_TYPE_MULTI_FUNCTION;
    return type == PCI_HEADER_TYPE_BRIDGE ?  PCI_ROM_ADDRESS1 : PCI_ROM_ADDRESS;
}

Neater, isn't it?

>  
>  static void pci_device_reset(PCIDevice *dev)
> @@ -102,7 +108,7 @@ static void pci_device_reset(PCIDevice *dev)
>          if (!dev->io_regions[r].size) {
>              continue;
>          }
> -        pci_set_long(dev->config + pci_bar(r), dev->io_regions[r].type);
> +        pci_set_long(dev->config + pci_bar(dev, r), dev->io_regions[r].type);
>      }
>      pci_update_mappings(dev);
>  }
> @@ -472,7 +478,7 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
>      r->map_func = map_func;
>  
>      wmask = ~(size - 1);
> -    addr = pci_bar(region_num);
> +    addr = pci_bar(pci_dev, region_num);
>      if (region_num == PCI_ROM_SLOT) {
>          /* ROM enable bit is writeable */
>          wmask |= PCI_ROM_ADDRESS_ENABLE;
> @@ -494,7 +500,7 @@ static void pci_update_mappings(PCIDevice *d)
>          if (r->size != 0) {
>              if (r->type & PCI_BASE_ADDRESS_SPACE_IO) {
>                  if (cmd & PCI_COMMAND_IO) {
> -                    new_addr = pci_get_long(d->config + pci_bar(i));
> +                    new_addr = pci_get_long(d->config + pci_bar(d, i));
>                      new_addr = new_addr & ~(r->size - 1);
>                      last_addr = new_addr + r->size - 1;
>                      /* NOTE: we have only 64K ioports on PC */
> @@ -507,7 +513,7 @@ static void pci_update_mappings(PCIDevice *d)
>                  }
>              } else {
>                  if (cmd & PCI_COMMAND_MEMORY) {
> -                    new_addr = pci_get_long(d->config + pci_bar(i));
> +                    new_addr = pci_get_long(d->config + pci_bar(d, i));
>                      /* the ROM slot has a specific enable bit */
>                      if (i == PCI_ROM_SLOT && !(new_addr & PCI_ROM_ADDRESS_ENABLE))
>                          goto no_mem_map;
> diff --git a/hw/pci.h b/hw/pci.h
> index bbce56b..bd63534 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -153,6 +153,9 @@ typedef struct PCIIORegion {
>  
>  #define PCI_COMMAND_RESERVED_MASK_HI (PCI_COMMAND_RESERVED >> 8)
>  
> +/* Header type 1 (PCI-to-PCI bridges) */
> +#define PCI_ROM_ADDRESS1        0x38    /* Same as PCI_ROM_ADDRESS, but for htype 1 */
> +

PCI_COMMAND_RESERVED_MASK_HI is our own macro, PCI_ROM_ADDRESS1 comes
from pci_regs.h, it should come in the same block with macros copied
from there. Also please try to keep macros there in the same order, so
one can diff to easily fine errors.

>  /* Size of the standard PCI config header */
>  #define PCI_CONFIG_HEADER_SIZE 0x40
>  /* Size of the standard PCI config space */
> -- 
> 1.6.0.2

  reply	other threads:[~2009-10-09  7:09 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-09  6:28 [Qemu-devel] [PATCH V5 00/29] pci: various pci clean up and pci express support Isaku Yamahata
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 01/29] pci: fix PCI_DPRINTF() wrt variadic macro Isaku Yamahata
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 02/29] pci: introduce constant PCI_NUM_PINS for the number of interrupt pins, 4 Isaku Yamahata
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 03/29] pci: use PCI_SLOT() and PCI_FUNC() Isaku Yamahata
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 04/29] pci: define a constant to represent a unmapped bar and use it Isaku Yamahata
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 05/29] pci: helper functions to access PCIDevice::config Isaku Yamahata
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 06/29] pci: use helper functions to access pci config space Isaku Yamahata
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 07/29] pci/bridge: clean up of pci_bridge_initfn() Isaku Yamahata
2009-10-09  6:53   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-13 13:20     ` Isaku Yamahata
2009-10-13 14:17       ` Michael S. Tsirkin
2009-10-13 15:12       ` Blue Swirl
2009-10-13 15:26         ` Michael S. Tsirkin
2009-10-13 16:32           ` Blue Swirl
2009-10-09  6:54   ` Michael S. Tsirkin
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 08/29] pci: s/PCI_ADDRESS_SPACE_/PCI_BASE_ADDRESS_SPACE_/ to match pci_regs.h Isaku Yamahata
2009-10-09  6:57   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-13 13:21     ` Isaku Yamahata
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 09/29] pci: clean up of pci_default_read_config Isaku Yamahata
2009-10-09  6:50   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-09  6:58   ` Michael S. Tsirkin
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 10/29] pci: make pci_bar() aware of header type 1 Isaku Yamahata
2009-10-09  7:06   ` Michael S. Tsirkin [this message]
2009-10-10 19:29   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 11/29] pci_host.h: move functions in pci_host.h into .c file Isaku Yamahata
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 12/29] pci_host: consolidate pci config address access Isaku Yamahata
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 13/29] pci: introduce pcibus_t to represent pci bus address/size instead of uint32_t Isaku Yamahata
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 14/29] pci: introduce FMT_PCIBUS for printf format for pcibus_t Isaku Yamahata
2009-10-10 19:32   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 15/29] pci: typedef pcibus_t as uint64_t instead of uint32_t Isaku Yamahata
2009-10-11 10:43   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-13 13:31     ` Isaku Yamahata
2009-10-13 14:39       ` Michael S. Tsirkin
2009-10-14  4:35         ` Isaku Yamahata
2009-10-14  8:55           ` Michael S. Tsirkin
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 16/29] pci: 64bit bar support Isaku Yamahata
2009-10-10 19:39   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-13 13:52     ` Isaku Yamahata
2009-10-13 15:00       ` Michael S. Tsirkin
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 17/29] pci: make pci configuration transaction more accurate Isaku Yamahata
2009-10-09 12:52   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 18/29] pci: factor out the conversion logic from io port address into pci device Isaku Yamahata
2009-10-10 19:41   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 19/29] pci: split out ioport address parsing from pci configuration access logic Isaku Yamahata
2009-10-10 19:45   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-13 14:14     ` Isaku Yamahata
2009-10-13 14:49       ` Michael S. Tsirkin
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 20/29] pci: move pci host stuff from pci.c to pci_host.c Isaku Yamahata
2009-10-10 19:46   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 21/29] pci_host: change the signature of pci_data_{read, write} Isaku Yamahata
2009-10-09 12:02   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 22/29] vmstate: add VMSTATE_ARRAY_POINTER for pointer to array Isaku Yamahata
2009-10-11 10:37   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 23/29] pci: pcie host and mmcfg support Isaku Yamahata
2009-10-11 10:26   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 24/29] pci: fix pci_default_write_config() Isaku Yamahata
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 25/29] pci: add helper functions for pci config write function Isaku Yamahata
2009-10-10 19:58   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-09  6:28 ` [Qemu-devel] [PATCH V5 26/29] pci: use helper function in pci_default_write_config() Isaku Yamahata
2009-10-09  6:29 ` [Qemu-devel] [PATCH V5 27/29] pci/bridge: don't update bar mapping when bar2-5 is changed Isaku Yamahata
2009-10-09 10:35   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-09  6:29 ` [Qemu-devel] [PATCH V5 28/29] pci: initialize pci config headers depending it pci header type Isaku Yamahata
2009-10-09 10:42   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-13 14:31     ` Isaku Yamahata
2009-10-13 14:52       ` Michael S. Tsirkin
2009-10-13 15:06       ` Michael S. Tsirkin
2009-10-09  6:29 ` [Qemu-devel] [PATCH V5 29/29] pci/monitor: print out bridge's filtering values and so on Isaku Yamahata
2009-10-10 20:05   ` [Qemu-devel] " Michael S. Tsirkin

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=20091009070648.GH9942@redhat.com \
    --to=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yamahata@valinux.co.jp \
    /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.