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: cam@cs.ualberta.ca, seabios@seabios.org, adnan@khaleel.us,
	qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH 1/2] pci: introduce pci_region to manage pci io/memory/prefmemory regions.
Date: Mon, 18 Oct 2010 11:55:08 +0200	[thread overview]
Message-ID: <20101018095508.GB21892@redhat.com> (raw)
In-Reply-To: <712ef3fe0235a61f870b46fff1cdbd282551e3b7.1287394119.git.yamahata@valinux.co.jp>

On Mon, Oct 18, 2010 at 06:34:22PM +0900, Isaku Yamahata wrote:
> This patch adds helper functions to manage pci area.
> 
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
> ---
>  Makefile         |    3 +-
>  src/pci_region.c |   70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  src/util.h       |   15 +++++++++++
>  3 files changed, 87 insertions(+), 1 deletions(-)
>  create mode 100644 src/pci_region.c
> 
> diff --git a/Makefile b/Makefile
> index 9d412f1..1663a5d 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -19,7 +19,8 @@ SRCBOTH=misc.c pmm.c stacks.c output.c util.c block.c floppy.c ata.c mouse.c \
>  SRC16=$(SRCBOTH) system.c disk.c font.c
>  SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \
>        acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \
> -      lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c dev-i440fx.c
> +      lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c dev-i440fx.c \
> +      pci_region.c
>  SRC32SEG=util.c output.c pci.c pcibios.c apm.c stacks.c
>  
>  cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
> diff --git a/src/pci_region.c b/src/pci_region.c
> new file mode 100644
> index 0000000..a4e71d9
> --- /dev/null
> +++ b/src/pci_region.c
> @@ -0,0 +1,70 @@
> +// helper functions to manage pci io/memory/prefetch memory region
> +//
> +// Copyright (C) 2009 Isaku Yamahata <yamahata at valinux co jp>
> +//
> +// This file may be distributed under the terms of the GNU LGPLv3 license.
> +//
> +//
> +
> +#include "util.h"
> +
> +#define PCI_REGION_DISABLED     (-1)
> +
> +void pci_region_init(struct pci_region *r, u32 start, u32 end)
> +{
> +    r->start = start;
> +    r->end = end;
> +
> +    r->cur_end = start;
> +}
> +
> +static u32 pci_region_alloc_align(struct pci_region *r, u32 size, u32 align)
> +{
> +    if (r->cur_end == PCI_REGION_DISABLED) {
> +        return 0;
> +    }

So is special value PCI_REGION_DISABLED or cur_end?

> +
> +    u32 s = ALIGN(r->cur_end, align);
> +    if (s > r->end || s < r->cur_end) {
> +        return 0;
> +    }
> +    u32 e = s + size;
> +    if (e > r->end || e < s) {
> +        return 0;
> +    }
> +    r->cur_end = e;
> +    return s;
> +}
> +
> +u32 pci_region_alloc(struct pci_region *r, u32 size)
> +{
> +    return pci_region_alloc_align(r, size, size);
> +}
> +
> +u32 pci_region_align(struct pci_region *r, u32 align)
> +{
> +    return pci_region_alloc_align(r, 0, align);
> +}
> +
> +void pci_region_revert(struct pci_region *r, u32 addr)
> +{
> +    r->cur_end = addr;
> +}
> +
> +u32 pci_region_disable(struct pci_region *r)
> +{
> +    return r->cur_end = PCI_REGION_DISABLED;
> +}
> +
> +u32 pci_region_addr(const struct pci_region *r)
> +{
> +    if (r->cur_end == PCI_REGION_DISABLED){
> +        return r->end;
> +    }
> +    return r->cur_end;
> +}
> +
> +u32 pci_region_size(const struct pci_region *r)
> +{
> +    return r->end - r->start;
> +}
> diff --git a/src/util.h b/src/util.h
> index 5cc9f17..ecd1c16 100644
> --- a/src/util.h
> +++ b/src/util.h
> @@ -344,6 +344,21 @@ void qemu_prep_reset(void);
>  void smm_save_and_copy(void);
>  void smm_relocate_and_restore(void);
>  
> +// pci_region.c
> +struct pci_region {
> +    u32 start;
> +    u32 end;
> +
> +    u32 cur_end;
> +};
> +void pci_region_init(struct pci_region *r, u32 start, u32 end);
> +u32 pci_region_alloc(struct pci_region *r, u32 size);
> +u32 pci_region_align(struct pci_region *r, u32 align);
> +void pci_region_revert(struct pci_region *r, u32 addr);
> +u32 pci_region_disable(struct pci_region *r);
> +u32 pci_region_addr(const struct pci_region *r);
> +u32 pci_region_size(const struct pci_region *r);
> +

Please document structure fields here and functions in the .c file.

>  // pciinit.c
>  extern const u8 pci_irqs[4];
>  void pci_bios_allocate_regions(u16 bdf, void *arg);
> -- 
> 1.7.1.1

  reply	other threads:[~2010-10-18 10:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-18  9:34 [Qemu-devel] [PATCH 0/2] pciinit: fix overflow when bar allocation Isaku Yamahata
2010-10-18  9:34 ` [Qemu-devel] [PATCH 1/2] pci: introduce pci_region to manage pci io/memory/prefmemory regions Isaku Yamahata
2010-10-18  9:55   ` Michael S. Tsirkin [this message]
2010-10-19  1:43     ` [Qemu-devel] Re: [SeaBIOS] " Isaku Yamahata
2010-10-18  9:34 ` [Qemu-devel] [PATCH 2/2] pciinit: use pci_region functions Isaku Yamahata
2010-10-18  9:47 ` [Qemu-devel] Re: [PATCH 0/2] pciinit: fix overflow when bar allocation Michael S. Tsirkin
2010-10-19  1:56   ` [Qemu-devel] Re: [SeaBIOS] " Isaku Yamahata

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=20101018095508.GB21892@redhat.com \
    --to=mst@redhat.com \
    --cc=adnan@khaleel.us \
    --cc=cam@cs.ualberta.ca \
    --cc=qemu-devel@nongnu.org \
    --cc=seabios@seabios.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.