13f6ea84aSIra W. Snyder /* 23f6ea84aSIra W. Snyder * Read address ranges from a Broadcom CNB20LE Host Bridge 33f6ea84aSIra W. Snyder * 43f6ea84aSIra W. Snyder * Copyright (c) 2010 Ira W. Snyder <iws@ovro.caltech.edu> 53f6ea84aSIra W. Snyder * 63f6ea84aSIra W. Snyder * This program is free software; you can redistribute it and/or modify it 73f6ea84aSIra W. Snyder * under the terms of the GNU General Public License as published by the 83f6ea84aSIra W. Snyder * Free Software Foundation; either version 2 of the License, or (at your 93f6ea84aSIra W. Snyder * option) any later version. 103f6ea84aSIra W. Snyder */ 113f6ea84aSIra W. Snyder 1230e664afSBjorn Helgaas #include <linux/acpi.h> 133f6ea84aSIra W. Snyder #include <linux/delay.h> 143f6ea84aSIra W. Snyder #include <linux/dmi.h> 153f6ea84aSIra W. Snyder #include <linux/pci.h> 163f6ea84aSIra W. Snyder #include <linux/init.h> 173f6ea84aSIra W. Snyder #include <asm/pci_x86.h> 186361d72bSBjorn Helgaas #include <asm/pci-direct.h> 193f6ea84aSIra W. Snyder 203f6ea84aSIra W. Snyder #include "bus_numa.h" 213f6ea84aSIra W. Snyder 226361d72bSBjorn Helgaas static void __init cnb20le_res(u8 bus, u8 slot, u8 func) 233f6ea84aSIra W. Snyder { 243f6ea84aSIra W. Snyder struct pci_root_info *info; 25d28e5ac2SYinghai Lu struct pci_root_res *root_res; 263f6ea84aSIra W. Snyder struct resource res; 273f6ea84aSIra W. Snyder u16 word1, word2; 283f6ea84aSIra W. Snyder u8 fbus, lbus; 293f6ea84aSIra W. Snyder 303f6ea84aSIra W. Snyder /* read the PCI bus numbers */ 316361d72bSBjorn Helgaas fbus = read_pci_config_byte(bus, slot, func, 0x44); 326361d72bSBjorn Helgaas lbus = read_pci_config_byte(bus, slot, func, 0x45); 33d28e5ac2SYinghai Lu info = alloc_pci_root_info(fbus, lbus, 0, 0); 343f6ea84aSIra W. Snyder 353f6ea84aSIra W. Snyder /* 363f6ea84aSIra W. Snyder * Add the legacy IDE ports on bus 0 373f6ea84aSIra W. Snyder * 383f6ea84aSIra W. Snyder * These do not exist anywhere in the bridge registers, AFAICT. I do 393f6ea84aSIra W. Snyder * not have the datasheet, so this is the best I can do. 403f6ea84aSIra W. Snyder */ 413f6ea84aSIra W. Snyder if (fbus == 0) { 423f6ea84aSIra W. Snyder update_res(info, 0x01f0, 0x01f7, IORESOURCE_IO, 0); 433f6ea84aSIra W. Snyder update_res(info, 0x03f6, 0x03f6, IORESOURCE_IO, 0); 443f6ea84aSIra W. Snyder update_res(info, 0x0170, 0x0177, IORESOURCE_IO, 0); 453f6ea84aSIra W. Snyder update_res(info, 0x0376, 0x0376, IORESOURCE_IO, 0); 463f6ea84aSIra W. Snyder update_res(info, 0xffa0, 0xffaf, IORESOURCE_IO, 0); 473f6ea84aSIra W. Snyder } 483f6ea84aSIra W. Snyder 493f6ea84aSIra W. Snyder /* read the non-prefetchable memory window */ 506361d72bSBjorn Helgaas word1 = read_pci_config_16(bus, slot, func, 0xc0); 516361d72bSBjorn Helgaas word2 = read_pci_config_16(bus, slot, func, 0xc2); 523f6ea84aSIra W. Snyder if (word1 != word2) { 533f6ea84aSIra W. Snyder res.start = (word1 << 16) | 0x0000; 543f6ea84aSIra W. Snyder res.end = (word2 << 16) | 0xffff; 553f6ea84aSIra W. Snyder res.flags = IORESOURCE_MEM; 563f6ea84aSIra W. Snyder update_res(info, res.start, res.end, res.flags, 0); 573f6ea84aSIra W. Snyder } 583f6ea84aSIra W. Snyder 593f6ea84aSIra W. Snyder /* read the prefetchable memory window */ 606361d72bSBjorn Helgaas word1 = read_pci_config_16(bus, slot, func, 0xc4); 616361d72bSBjorn Helgaas word2 = read_pci_config_16(bus, slot, func, 0xc6); 623f6ea84aSIra W. Snyder if (word1 != word2) { 63*0b2d7076SBjorn Helgaas res.start = ((resource_size_t) word1 << 16) | 0x0000; 64*0b2d7076SBjorn Helgaas res.end = ((resource_size_t) word2 << 16) | 0xffff; 653f6ea84aSIra W. Snyder res.flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; 663f6ea84aSIra W. Snyder update_res(info, res.start, res.end, res.flags, 0); 673f6ea84aSIra W. Snyder } 683f6ea84aSIra W. Snyder 693f6ea84aSIra W. Snyder /* read the IO port window */ 706361d72bSBjorn Helgaas word1 = read_pci_config_16(bus, slot, func, 0xd0); 716361d72bSBjorn Helgaas word2 = read_pci_config_16(bus, slot, func, 0xd2); 723f6ea84aSIra W. Snyder if (word1 != word2) { 733f6ea84aSIra W. Snyder res.start = word1; 743f6ea84aSIra W. Snyder res.end = word2; 753f6ea84aSIra W. Snyder res.flags = IORESOURCE_IO; 763f6ea84aSIra W. Snyder update_res(info, res.start, res.end, res.flags, 0); 773f6ea84aSIra W. Snyder } 783f6ea84aSIra W. Snyder 793f6ea84aSIra W. Snyder /* print information about this host bridge */ 803f6ea84aSIra W. Snyder res.start = fbus; 813f6ea84aSIra W. Snyder res.end = lbus; 823f6ea84aSIra W. Snyder res.flags = IORESOURCE_BUS; 836361d72bSBjorn Helgaas printk(KERN_INFO "CNB20LE PCI Host Bridge (domain 0000 %pR)\n", &res); 843f6ea84aSIra W. Snyder 85d28e5ac2SYinghai Lu list_for_each_entry(root_res, &info->resources, list) 86d28e5ac2SYinghai Lu printk(KERN_INFO "host bridge window %pR\n", &root_res->res); 873f6ea84aSIra W. Snyder } 883f6ea84aSIra W. Snyder 896361d72bSBjorn Helgaas static int __init broadcom_postcore_init(void) 906361d72bSBjorn Helgaas { 916361d72bSBjorn Helgaas u8 bus = 0, slot = 0; 926361d72bSBjorn Helgaas u32 id; 936361d72bSBjorn Helgaas u16 vendor, device; 943f6ea84aSIra W. Snyder 956361d72bSBjorn Helgaas #ifdef CONFIG_ACPI 966361d72bSBjorn Helgaas /* 976361d72bSBjorn Helgaas * We should get host bridge information from ACPI unless the BIOS 986361d72bSBjorn Helgaas * doesn't support it. 996361d72bSBjorn Helgaas */ 1006361d72bSBjorn Helgaas if (acpi_os_get_root_pointer()) 1016361d72bSBjorn Helgaas return 0; 1026361d72bSBjorn Helgaas #endif 1036361d72bSBjorn Helgaas 1046361d72bSBjorn Helgaas id = read_pci_config(bus, slot, 0, PCI_VENDOR_ID); 1056361d72bSBjorn Helgaas vendor = id & 0xffff; 1066361d72bSBjorn Helgaas device = (id >> 16) & 0xffff; 1076361d72bSBjorn Helgaas 1086361d72bSBjorn Helgaas if (vendor == PCI_VENDOR_ID_SERVERWORKS && 1096361d72bSBjorn Helgaas device == PCI_DEVICE_ID_SERVERWORKS_LE) { 1106361d72bSBjorn Helgaas cnb20le_res(bus, slot, 0); 1116361d72bSBjorn Helgaas cnb20le_res(bus, slot, 1); 1126361d72bSBjorn Helgaas } 1136361d72bSBjorn Helgaas return 0; 1146361d72bSBjorn Helgaas } 1156361d72bSBjorn Helgaas 1166361d72bSBjorn Helgaas postcore_initcall(broadcom_postcore_init); 117