Path: blob/master/arch/microblaze/pci/xilinx_pci.c
10817 views
/*1* PCI support for Xilinx plbv46_pci soft-core which can be used on2* Xilinx Virtex ML410 / ML510 boards.3*4* Copyright 2009 Roderick Colenbrander5* Copyright 2009 Secret Lab Technologies Ltd.6*7* The pci bridge fixup code was copied from ppc4xx_pci.c and was written8* by Benjamin Herrenschmidt.9* Copyright 2007 Ben. Herrenschmidt <[email protected]>, IBM Corp.10*11* This file is licensed under the terms of the GNU General Public License12* version 2. This program is licensed "as is" without any warranty of any13* kind, whether express or implied.14*/1516#include <linux/ioport.h>17#include <linux/of.h>18#include <linux/of_address.h>19#include <linux/pci.h>20#include <asm/io.h>2122#define XPLB_PCI_ADDR 0x10c23#define XPLB_PCI_DATA 0x11024#define XPLB_PCI_BUS 0x1142526#define PCI_HOST_ENABLE_CMD (PCI_COMMAND_SERR | PCI_COMMAND_PARITY | \27PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY)2829static struct of_device_id xilinx_pci_match[] = {30{ .compatible = "xlnx,plbv46-pci-1.03.a", },31{}32};3334/**35* xilinx_pci_fixup_bridge - Block Xilinx PHB configuration.36*/37static void xilinx_pci_fixup_bridge(struct pci_dev *dev)38{39struct pci_controller *hose;40int i;4142if (dev->devfn || dev->bus->self)43return;4445hose = pci_bus_to_host(dev->bus);46if (!hose)47return;4849if (!of_match_node(xilinx_pci_match, hose->dn))50return;5152/* Hide the PCI host BARs from the kernel as their content doesn't53* fit well in the resource management54*/55for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {56dev->resource[i].start = 0;57dev->resource[i].end = 0;58dev->resource[i].flags = 0;59}6061dev_info(&dev->dev, "Hiding Xilinx plb-pci host bridge resources %s\n",62pci_name(dev));63}64DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, xilinx_pci_fixup_bridge);6566#ifdef DEBUG67/**68* xilinx_pci_exclude_device - Don't do config access for non-root bus69*70* This is a hack. Config access to any bus other than bus 0 does not71* currently work on the ML510 so we prevent it here.72*/73static int74xilinx_pci_exclude_device(struct pci_controller *hose, u_char bus, u8 devfn)75{76return (bus != 0);77}7879/**80* xilinx_early_pci_scan - List pci config space for available devices81*82* List pci devices in very early phase.83*/84void __init xilinx_early_pci_scan(struct pci_controller *hose)85{86u32 bus = 0;87u32 val, dev, func, offset;8889/* Currently we have only 2 device connected - up-to 32 devices */90for (dev = 0; dev < 2; dev++) {91/* List only first function number - up-to 8 functions */92for (func = 0; func < 1; func++) {93printk(KERN_INFO "%02x:%02x:%02x", bus, dev, func);94/* read the first 64 standardized bytes */95/* Up-to 192 bytes can be list of capabilities */96for (offset = 0; offset < 64; offset += 4) {97early_read_config_dword(hose, bus,98PCI_DEVFN(dev, func), offset, &val);99if (offset == 0 && val == 0xFFFFFFFF) {100printk(KERN_CONT "\nABSENT");101break;102}103if (!(offset % 0x10))104printk(KERN_CONT "\n%04x: ", offset);105106printk(KERN_CONT "%08x ", val);107}108printk(KERN_INFO "\n");109}110}111}112#else113void __init xilinx_early_pci_scan(struct pci_controller *hose)114{115}116#endif117118/**119* xilinx_pci_init - Find and register a Xilinx PCI host bridge120*/121void __init xilinx_pci_init(void)122{123struct pci_controller *hose;124struct resource r;125void __iomem *pci_reg;126struct device_node *pci_node;127128pci_node = of_find_matching_node(NULL, xilinx_pci_match);129if (!pci_node)130return;131132if (of_address_to_resource(pci_node, 0, &r)) {133pr_err("xilinx-pci: cannot resolve base address\n");134return;135}136137hose = pcibios_alloc_controller(pci_node);138if (!hose) {139pr_err("xilinx-pci: pcibios_alloc_controller() failed\n");140return;141}142143/* Setup config space */144setup_indirect_pci(hose, r.start + XPLB_PCI_ADDR,145r.start + XPLB_PCI_DATA,146INDIRECT_TYPE_SET_CFG_TYPE);147148/* According to the xilinx plbv46_pci documentation the soft-core starts149* a self-init when the bus master enable bit is set. Without this bit150* set the pci bus can't be scanned.151*/152early_write_config_word(hose, 0, 0, PCI_COMMAND, PCI_HOST_ENABLE_CMD);153154/* Set the max latency timer to 255 */155early_write_config_byte(hose, 0, 0, PCI_LATENCY_TIMER, 0xff);156157/* Set the max bus number to 255, and bus/subbus no's to 0 */158pci_reg = of_iomap(pci_node, 0);159out_be32(pci_reg + XPLB_PCI_BUS, 0x000000ff);160iounmap(pci_reg);161162/* Register the host bridge with the linux kernel! */163pci_process_bridge_OF_ranges(hose, pci_node,164INDIRECT_TYPE_SET_CFG_TYPE);165166pr_info("xilinx-pci: Registered PCI host bridge\n");167xilinx_early_pci_scan(hose);168}169170171