Skip to content
Snippets Groups Projects
Select Git revision
  • 64b7faa7f9583d31e954c10de52275cdf2bf0ee1
  • master default protected
  • early-display
  • variant-emmc-nvme-boot
  • 2023-01-25
  • v3
  • variant-emmc-nvme-boot
  • 2020-06-01
8 results

snapshot.commit

Blame
  • Forked from Reform / reform-boundary-uboot
    Source project has a limited visibility.
    pci_auto_common.c 3.19 KiB
    /*
     * PCI auto-configuration library
     *
     * Author: Matt Porter <mporter@mvista.com>
     *
     * Copyright 2000 MontaVista Software Inc.
     *
     * Modifications for driver model:
     * Copyright 2015 Google, Inc
     * Written by Simon Glass <sjg@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;