[U-Boot] [PATCH 07/14] dm: pci: Move common auto-config functions to a common file
Bin Meng
bmeng.cn at gmail.com
Fri Nov 13 06:29:25 CET 2015
Hi Simon,
On Fri, Nov 13, 2015 at 5:45 AM, Simon Glass <sjg at chromium.org> wrote:
> Some functions will be used by driver model and legacy PCI code. To avoid
> duplication, put these in a separate, shared file.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> drivers/pci/Makefile | 2 +-
> drivers/pci/pci_auto_common.c | 128 ++++++++++++++++++++++++++++++++++++++++++
> drivers/pci/pci_auto_old.c | 122 ----------------------------------------
> 3 files changed, 129 insertions(+), 123 deletions(-)
> create mode 100644 drivers/pci/pci_auto_common.c
>
> diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
> index dee844f..1f8f86f 100644
> --- a/drivers/pci/Makefile
> +++ b/drivers/pci/Makefile
> @@ -13,7 +13,7 @@ obj-$(CONFIG_X86) += pci_x86.o
> else
> obj-$(CONFIG_PCI) += pci.o
> endif
> -obj-$(CONFIG_PCI) += pci_common.o pci_auto_old.o pci_rom.o
> +obj-$(CONFIG_PCI) += pci_auto_common.o pci_auto_old.o pci_common.o pci_rom.o
>
> obj-$(CONFIG_FSL_PCI_INIT) += fsl_pci_init.o
> obj-$(CONFIG_PCI_INDIRECT_BRIDGE) += pci_indirect.o
> diff --git a/drivers/pci/pci_auto_common.c b/drivers/pci/pci_auto_common.c
> new file mode 100644
> index 0000000..faf904e
> --- /dev/null
> +++ b/drivers/pci/pci_auto_common.c
> @@ -0,0 +1,128 @@
> +/*
> + * PCI autoconfiguration library
nits: auto configuration
> + *
> + * Author: Matt Porter <mporter at mvista.com>
> + *
> + * Copyright 2000 MontaVista Software Inc.
> + *
> + * Modifications for driver model:
> + * Copyright 2015 Google, Inc
> + * Written by Simon Glass <sjg at chromium.org>
> + *
> + * SPDX-License-Identifier: GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <errno.h>
> +#include <pci.h>
> +
> +void pciauto_region_init(struct pci_region *res)
> +{
> + /*
> + * Avoid allocating PCI resources from address 0 -- this is illegal
> + * according to PCI 2.1 and moreover, this is known to cause Linux IDE
> + * drivers to fail. Use a reasonable starting value of 0x1000 instead.
> + */
> + res->bus_lower = res->bus_start ? res->bus_start : 0x1000;
> +}
> +
> +void pciauto_region_align(struct pci_region *res, pci_size_t size)
> +{
> + res->bus_lower = ((res->bus_lower - 1) | (size - 1)) + 1;
> +}
> +
> +int pciauto_region_allocate(struct pci_region *res, pci_size_t size,
> + pci_addr_t *bar)
> +{
> + pci_addr_t addr;
> +
> + if (!res) {
> + debug("No resource");
> + goto error;
> + }
> +
> + addr = ((res->bus_lower - 1) | (size - 1)) + 1;
> +
> + if (addr - res->bus_start + size > res->size) {
> + debug("No room in resource");
> + goto error;
> + }
> +
> + res->bus_lower = addr + size;
> +
> + debug("address=0x%llx bus_lower=0x%llx", (unsigned long long)addr,
> + (unsigned long long)res->bus_lower);
> +
> + *bar = addr;
> + return 0;
> +
> + error:
> + *bar = (pci_addr_t)-1;
> + return -1;
> +}
> +
> +void pciauto_config_init(struct pci_controller *hose)
> +{
> + int i;
> +
> + hose->pci_io = NULL;
> + hose->pci_mem = NULL;
> + hose->pci_prefetch = NULL;
> +
> + for (i = 0; i < hose->region_count; i++) {
> + switch (hose->regions[i].flags) {
> + case PCI_REGION_IO:
> + if (!hose->pci_io ||
> + hose->pci_io->size < hose->regions[i].size)
> + hose->pci_io = hose->regions + i;
> + break;
> + case PCI_REGION_MEM:
> + if (!hose->pci_mem ||
> + hose->pci_mem->size < hose->regions[i].size)
> + hose->pci_mem = hose->regions + i;
> + break;
> + case (PCI_REGION_MEM | PCI_REGION_PREFETCH):
> + if (!hose->pci_prefetch ||
> + hose->pci_prefetch->size < hose->regions[i].size)
> + hose->pci_prefetch = hose->regions + i;
> + break;
> + }
> + }
> +
> +
> + if (hose->pci_mem) {
> + pciauto_region_init(hose->pci_mem);
> +
> + debug("PCI Autoconfig: Bus Memory region: [0x%llx-0x%llx],\n"
> + "\t\tPhysical Memory [%llx-%llxx]\n",
> + (u64)hose->pci_mem->bus_start,
> + (u64)(hose->pci_mem->bus_start + hose->pci_mem->size - 1),
> + (u64)hose->pci_mem->phys_start,
> + (u64)(hose->pci_mem->phys_start + hose->pci_mem->size - 1));
> + }
> +
> + if (hose->pci_prefetch) {
> + pciauto_region_init(hose->pci_prefetch);
> +
> + debug("PCI Autoconfig: Bus Prefetchable Mem: [0x%llx-0x%llx],\n"
> + "\t\tPhysical Memory [%llx-%llx]\n",
> + (u64)hose->pci_prefetch->bus_start,
> + (u64)(hose->pci_prefetch->bus_start +
> + hose->pci_prefetch->size - 1),
> + (u64)hose->pci_prefetch->phys_start,
> + (u64)(hose->pci_prefetch->phys_start +
> + hose->pci_prefetch->size - 1));
> + }
> +
> + if (hose->pci_io) {
> + pciauto_region_init(hose->pci_io);
> +
> + debug("PCI Autoconfig: Bus I/O region: [0x%llx-0x%llx],\n"
> + "\t\tPhysical Memory: [%llx-%llx]\n",
> + (u64)hose->pci_io->bus_start,
> + (u64)(hose->pci_io->bus_start + hose->pci_io->size - 1),
> + (u64)hose->pci_io->phys_start,
> + (u64)(hose->pci_io->phys_start + hose->pci_io->size - 1));
> + }
> +}
> diff --git a/drivers/pci/pci_auto_old.c b/drivers/pci/pci_auto_old.c
> index 0412bf3..54c5e1d 100644
> --- a/drivers/pci/pci_auto_old.c
> +++ b/drivers/pci/pci_auto_old.c
> @@ -23,55 +23,6 @@
> *
> */
>
> -void pciauto_region_init(struct pci_region *res)
> -{
> - /*
> - * Avoid allocating PCI resources from address 0 -- this is illegal
> - * according to PCI 2.1 and moreover, this is known to cause Linux IDE
> - * drivers to fail. Use a reasonable starting value of 0x1000 instead.
> - */
> - res->bus_lower = res->bus_start ? res->bus_start : 0x1000;
> -}
> -
> -void pciauto_region_align(struct pci_region *res, pci_size_t size)
> -{
> - res->bus_lower = ((res->bus_lower - 1) | (size - 1)) + 1;
> -}
> -
> -int pciauto_region_allocate(struct pci_region *res, pci_size_t size,
> - pci_addr_t *bar)
> -{
> - pci_addr_t addr;
> -
> - if (!res) {
> - debug("No resource");
> - goto error;
> - }
> -
> - addr = ((res->bus_lower - 1) | (size - 1)) + 1;
> -
> - if (addr - res->bus_start + size > res->size) {
> - debug("No room in resource");
> - goto error;
> - }
> -
> - res->bus_lower = addr + size;
> -
> - debug("address=0x%llx bus_lower=0x%llx", (unsigned long long)addr,
> - (unsigned long long)res->bus_lower);
> -
> - *bar = addr;
> - return 0;
> -
> - error:
> - *bar = (pci_addr_t)-1;
> - return -1;
> -}
> -
> -/*
> - *
> - */
> -
> void pciauto_setup_device(struct pci_controller *hose,
> pci_dev_t dev, int bars_num,
> struct pci_region *mem,
> @@ -89,7 +40,6 @@ void pciauto_setup_device(struct pci_controller *hose,
> struct pci_region *bar_res;
> int found_mem64 = 0;
> #endif
> - u16 class;
>
> pci_hose_read_config_word(hose, dev, PCI_COMMAND, &cmdstat);
> cmdstat = (cmdstat & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) | PCI_COMMAND_MASTER;
> @@ -207,11 +157,6 @@ void pciauto_setup_device(struct pci_controller *hose,
> }
> #endif
>
> - /* PCI_COMMAND_IO must be set for VGA device */
> - pci_hose_read_config_word(hose, dev, PCI_CLASS_DEVICE, &class);
> - if (class == PCI_CLASS_DISPLAY_VGA)
> - cmdstat |= PCI_COMMAND_IO;
> -
I guess this is a merge/rebase mistake? This should not be removed.
> pci_hose_write_config_word(hose, dev, PCI_COMMAND, cmdstat);
> pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE,
> CONFIG_SYS_PCI_CACHE_LINE_SIZE);
> @@ -385,73 +330,6 @@ void pciauto_postscan_setup_bridge(struct pci_controller *hose,
> }
> }
>
> -/*
> - *
> - */
> -
> -void pciauto_config_init(struct pci_controller *hose)
> -{
> - int i;
> -
> - hose->pci_io = hose->pci_mem = hose->pci_prefetch = NULL;
> -
> - for (i = 0; i < hose->region_count; i++) {
> - switch(hose->regions[i].flags) {
> - case PCI_REGION_IO:
> - if (!hose->pci_io ||
> - hose->pci_io->size < hose->regions[i].size)
> - hose->pci_io = hose->regions + i;
> - break;
> - case PCI_REGION_MEM:
> - if (!hose->pci_mem ||
> - hose->pci_mem->size < hose->regions[i].size)
> - hose->pci_mem = hose->regions + i;
> - break;
> - case (PCI_REGION_MEM | PCI_REGION_PREFETCH):
> - if (!hose->pci_prefetch ||
> - hose->pci_prefetch->size < hose->regions[i].size)
> - hose->pci_prefetch = hose->regions + i;
> - break;
> - }
> - }
> -
> -
> - if (hose->pci_mem) {
> - pciauto_region_init(hose->pci_mem);
> -
> - debug("PCI Autoconfig: Bus Memory region: [0x%llx-0x%llx],\n"
> - "\t\tPhysical Memory [%llx-%llxx]\n",
> - (u64)hose->pci_mem->bus_start,
> - (u64)(hose->pci_mem->bus_start + hose->pci_mem->size - 1),
> - (u64)hose->pci_mem->phys_start,
> - (u64)(hose->pci_mem->phys_start + hose->pci_mem->size - 1));
> - }
> -
> - if (hose->pci_prefetch) {
> - pciauto_region_init(hose->pci_prefetch);
> -
> - debug("PCI Autoconfig: Bus Prefetchable Mem: [0x%llx-0x%llx],\n"
> - "\t\tPhysical Memory [%llx-%llx]\n",
> - (u64)hose->pci_prefetch->bus_start,
> - (u64)(hose->pci_prefetch->bus_start +
> - hose->pci_prefetch->size - 1),
> - (u64)hose->pci_prefetch->phys_start,
> - (u64)(hose->pci_prefetch->phys_start +
> - hose->pci_prefetch->size - 1));
> - }
> -
> - if (hose->pci_io) {
> - pciauto_region_init(hose->pci_io);
> -
> - debug("PCI Autoconfig: Bus I/O region: [0x%llx-0x%llx],\n"
> - "\t\tPhysical Memory: [%llx-%llx]\n",
> - (u64)hose->pci_io->bus_start,
> - (u64)(hose->pci_io->bus_start + hose->pci_io->size - 1),
> - (u64)hose->pci_io->phys_start,
> - (u64)(hose->pci_io->phys_start + hose->pci_io->size - 1));
> -
> - }
> -}
>
> /*
> * HJF: Changed this to return int. I think this is required
> --
Regards,
Bin
More information about the U-Boot
mailing list