/*1* This file is subject to the terms and conditions of the GNU General Public2* License. See the file "COPYING" in the main directory of this archive3* for more details.4*5* Copyright (C) 2005-2009 Cavium Networks6*/7#include <linux/kernel.h>8#include <linux/init.h>9#include <linux/pci.h>10#include <linux/interrupt.h>11#include <linux/time.h>12#include <linux/delay.h>13#include <linux/platform_device.h>14#include <linux/swiotlb.h>1516#include <asm/time.h>1718#include <asm/octeon/octeon.h>19#include <asm/octeon/cvmx-npi-defs.h>20#include <asm/octeon/cvmx-pci-defs.h>21#include <asm/octeon/pci-octeon.h>2223#define USE_OCTEON_INTERNAL_ARBITER2425/*26* Octeon's PCI controller uses did=3, subdid=2 for PCI IO27* addresses. Use PCI endian swapping 1 so no address swapping is28* necessary. The Linux io routines will endian swap the data.29*/30#define OCTEON_PCI_IOSPACE_BASE 0x80011a0400000000ull31#define OCTEON_PCI_IOSPACE_SIZE (1ull<<32)3233/* Octeon't PCI controller uses did=3, subdid=3 for PCI memory. */34#define OCTEON_PCI_MEMSPACE_OFFSET (0x00011b0000000000ull)3536u64 octeon_bar1_pci_phys;3738/**39* This is the bit decoding used for the Octeon PCI controller addresses40*/41union octeon_pci_address {42uint64_t u64;43struct {44uint64_t upper:2;45uint64_t reserved:13;46uint64_t io:1;47uint64_t did:5;48uint64_t subdid:3;49uint64_t reserved2:4;50uint64_t endian_swap:2;51uint64_t reserved3:10;52uint64_t bus:8;53uint64_t dev:5;54uint64_t func:3;55uint64_t reg:8;56} s;57};5859int (*octeon_pcibios_map_irq)(const struct pci_dev *dev, u8 slot, u8 pin);60enum octeon_dma_bar_type octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_INVALID;6162/**63* Map a PCI device to the appropriate interrupt line64*65* @dev: The Linux PCI device structure for the device to map66* @slot: The slot number for this device on __BUS 0__. Linux67* enumerates through all the bridges and figures out the68* slot on Bus 0 where this device eventually hooks to.69* @pin: The PCI interrupt pin read from the device, then swizzled70* as it goes through each bridge.71* Returns Interrupt number for the device72*/73int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)74{75if (octeon_pcibios_map_irq)76return octeon_pcibios_map_irq(dev, slot, pin);77else78panic("octeon_pcibios_map_irq not set.");79}808182/*83* Called to perform platform specific PCI setup84*/85int pcibios_plat_dev_init(struct pci_dev *dev)86{87uint16_t config;88uint32_t dconfig;89int pos;90/*91* Force the Cache line setting to 64 bytes. The standard92* Linux bus scan doesn't seem to set it. Octeon really has93* 128 byte lines, but Intel bridges get really upset if you94* try and set values above 64 bytes. Value is specified in95* 32bit words.96*/97pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 64 / 4);98/* Set latency timers for all devices */99pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);100101/* Enable reporting System errors and parity errors on all devices */102/* Enable parity checking and error reporting */103pci_read_config_word(dev, PCI_COMMAND, &config);104config |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;105pci_write_config_word(dev, PCI_COMMAND, config);106107if (dev->subordinate) {108/* Set latency timers on sub bridges */109pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER, 64);110/* More bridge error detection */111pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &config);112config |= PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR;113pci_write_config_word(dev, PCI_BRIDGE_CONTROL, config);114}115116/* Enable the PCIe normal error reporting */117config = PCI_EXP_DEVCTL_CERE; /* Correctable Error Reporting */118config |= PCI_EXP_DEVCTL_NFERE; /* Non-Fatal Error Reporting */119config |= PCI_EXP_DEVCTL_FERE; /* Fatal Error Reporting */120config |= PCI_EXP_DEVCTL_URRE; /* Unsupported Request */121pcie_capability_set_word(dev, PCI_EXP_DEVCTL, config);122123/* Find the Advanced Error Reporting capability */124pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);125if (pos) {126/* Clear Uncorrectable Error Status */127pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS,128&dconfig);129pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS,130dconfig);131/* Enable reporting of all uncorrectable errors */132/* Uncorrectable Error Mask - turned on bits disable errors */133pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, 0);134/*135* Leave severity at HW default. This only controls if136* errors are reported as uncorrectable or137* correctable, not if the error is reported.138*/139/* PCI_ERR_UNCOR_SEVER - Uncorrectable Error Severity */140/* Clear Correctable Error Status */141pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &dconfig);142pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, dconfig);143/* Enable reporting of all correctable errors */144/* Correctable Error Mask - turned on bits disable errors */145pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, 0);146/* Advanced Error Capabilities */147pci_read_config_dword(dev, pos + PCI_ERR_CAP, &dconfig);148/* ECRC Generation Enable */149if (config & PCI_ERR_CAP_ECRC_GENC)150config |= PCI_ERR_CAP_ECRC_GENE;151/* ECRC Check Enable */152if (config & PCI_ERR_CAP_ECRC_CHKC)153config |= PCI_ERR_CAP_ECRC_CHKE;154pci_write_config_dword(dev, pos + PCI_ERR_CAP, dconfig);155/* PCI_ERR_HEADER_LOG - Header Log Register (16 bytes) */156/* Report all errors to the root complex */157pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND,158PCI_ERR_ROOT_CMD_COR_EN |159PCI_ERR_ROOT_CMD_NONFATAL_EN |160PCI_ERR_ROOT_CMD_FATAL_EN);161/* Clear the Root status register */162pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &dconfig);163pci_write_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, dconfig);164}165166return 0;167}168169/**170* Return the mapping of PCI device number to IRQ line. Each171* character in the return string represents the interrupt172* line for the device at that position. Device 1 maps to the173* first character, etc. The characters A-D are used for PCI174* interrupts.175*176* Returns PCI interrupt mapping177*/178const char *octeon_get_pci_interrupts(void)179{180/*181* Returning an empty string causes the interrupts to be182* routed based on the PCI specification. From the PCI spec:183*184* INTA# of Device Number 0 is connected to IRQW on the system185* board. (Device Number has no significance regarding being186* located on the system board or in a connector.) INTA# of187* Device Number 1 is connected to IRQX on the system188* board. INTA# of Device Number 2 is connected to IRQY on the189* system board. INTA# of Device Number 3 is connected to IRQZ190* on the system board. The table below describes how each191* agent's INTx# lines are connected to the system board192* interrupt lines. The following equation can be used to193* determine to which INTx# signal on the system board a given194* device's INTx# line(s) is connected.195*196* MB = (D + I) MOD 4 MB = System board Interrupt (IRQW = 0,197* IRQX = 1, IRQY = 2, and IRQZ = 3) D = Device Number I =198* Interrupt Number (INTA# = 0, INTB# = 1, INTC# = 2, and199* INTD# = 3)200*/201if (of_machine_is_compatible("dlink,dsr-500n"))202return "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC";203switch (octeon_bootinfo->board_type) {204case CVMX_BOARD_TYPE_NAO38:205/* This is really the NAC38 */206return "AAAAADABAAAAAAAAAAAAAAAAAAAAAAAA";207case CVMX_BOARD_TYPE_EBH3100:208case CVMX_BOARD_TYPE_CN3010_EVB_HS5:209case CVMX_BOARD_TYPE_CN3005_EVB_HS5:210return "AAABAAAAAAAAAAAAAAAAAAAAAAAAAAAA";211case CVMX_BOARD_TYPE_BBGW_REF:212return "AABCD";213case CVMX_BOARD_TYPE_CUST_DSR1000N:214return "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC";215case CVMX_BOARD_TYPE_THUNDER:216case CVMX_BOARD_TYPE_EBH3000:217default:218return "";219}220}221222/**223* Map a PCI device to the appropriate interrupt line224*225* @dev: The Linux PCI device structure for the device to map226* @slot: The slot number for this device on __BUS 0__. Linux227* enumerates through all the bridges and figures out the228* slot on Bus 0 where this device eventually hooks to.229* @pin: The PCI interrupt pin read from the device, then swizzled230* as it goes through each bridge.231* Returns Interrupt number for the device232*/233int __init octeon_pci_pcibios_map_irq(const struct pci_dev *dev,234u8 slot, u8 pin)235{236int irq_num;237const char *interrupts;238int dev_num;239240/* Get the board specific interrupt mapping */241interrupts = octeon_get_pci_interrupts();242243dev_num = dev->devfn >> 3;244if (dev_num < strlen(interrupts))245irq_num = ((interrupts[dev_num] - 'A' + pin - 1) & 3) +246OCTEON_IRQ_PCI_INT0;247else248irq_num = ((slot + pin - 3) & 3) + OCTEON_IRQ_PCI_INT0;249return irq_num;250}251252253/*254* Read a value from configuration space255*/256static int octeon_read_config(struct pci_bus *bus, unsigned int devfn,257int reg, int size, u32 *val)258{259union octeon_pci_address pci_addr;260261pci_addr.u64 = 0;262pci_addr.s.upper = 2;263pci_addr.s.io = 1;264pci_addr.s.did = 3;265pci_addr.s.subdid = 1;266pci_addr.s.endian_swap = 1;267pci_addr.s.bus = bus->number;268pci_addr.s.dev = devfn >> 3;269pci_addr.s.func = devfn & 0x7;270pci_addr.s.reg = reg;271272switch (size) {273case 4:274*val = le32_to_cpu(cvmx_read64_uint32(pci_addr.u64));275return PCIBIOS_SUCCESSFUL;276case 2:277*val = le16_to_cpu(cvmx_read64_uint16(pci_addr.u64));278return PCIBIOS_SUCCESSFUL;279case 1:280*val = cvmx_read64_uint8(pci_addr.u64);281return PCIBIOS_SUCCESSFUL;282}283return PCIBIOS_FUNC_NOT_SUPPORTED;284}285286287/*288* Write a value to PCI configuration space289*/290static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,291int reg, int size, u32 val)292{293union octeon_pci_address pci_addr;294295pci_addr.u64 = 0;296pci_addr.s.upper = 2;297pci_addr.s.io = 1;298pci_addr.s.did = 3;299pci_addr.s.subdid = 1;300pci_addr.s.endian_swap = 1;301pci_addr.s.bus = bus->number;302pci_addr.s.dev = devfn >> 3;303pci_addr.s.func = devfn & 0x7;304pci_addr.s.reg = reg;305306switch (size) {307case 4:308cvmx_write64_uint32(pci_addr.u64, cpu_to_le32(val));309return PCIBIOS_SUCCESSFUL;310case 2:311cvmx_write64_uint16(pci_addr.u64, cpu_to_le16(val));312return PCIBIOS_SUCCESSFUL;313case 1:314cvmx_write64_uint8(pci_addr.u64, val);315return PCIBIOS_SUCCESSFUL;316}317return PCIBIOS_FUNC_NOT_SUPPORTED;318}319320321static struct pci_ops octeon_pci_ops = {322.read = octeon_read_config,323.write = octeon_write_config,324};325326static struct resource octeon_pci_mem_resource = {327.start = 0,328.end = 0,329.name = "Octeon PCI MEM",330.flags = IORESOURCE_MEM,331};332333/*334* PCI ports must be above 16KB so the ISA bus filtering in the PCI-X to PCI335* bridge336*/337static struct resource octeon_pci_io_resource = {338.start = 0x4000,339.end = OCTEON_PCI_IOSPACE_SIZE - 1,340.name = "Octeon PCI IO",341.flags = IORESOURCE_IO,342};343344static struct pci_controller octeon_pci_controller = {345.pci_ops = &octeon_pci_ops,346.mem_resource = &octeon_pci_mem_resource,347.mem_offset = OCTEON_PCI_MEMSPACE_OFFSET,348.io_resource = &octeon_pci_io_resource,349.io_offset = 0,350.io_map_base = OCTEON_PCI_IOSPACE_BASE,351};352353354/*355* Low level initialize the Octeon PCI controller356*/357static void octeon_pci_initialize(void)358{359union cvmx_pci_cfg01 cfg01;360union cvmx_npi_ctl_status ctl_status;361union cvmx_pci_ctl_status_2 ctl_status_2;362union cvmx_pci_cfg19 cfg19;363union cvmx_pci_cfg16 cfg16;364union cvmx_pci_cfg22 cfg22;365union cvmx_pci_cfg56 cfg56;366367/* Reset the PCI Bus */368cvmx_write_csr(CVMX_CIU_SOFT_PRST, 0x1);369cvmx_read_csr(CVMX_CIU_SOFT_PRST);370371udelay(2000); /* Hold PCI reset for 2 ms */372373ctl_status.u64 = 0; /* cvmx_read_csr(CVMX_NPI_CTL_STATUS); */374ctl_status.s.max_word = 1;375ctl_status.s.timer = 1;376cvmx_write_csr(CVMX_NPI_CTL_STATUS, ctl_status.u64);377378/* Deassert PCI reset and advertise PCX Host Mode Device Capability379(64b) */380cvmx_write_csr(CVMX_CIU_SOFT_PRST, 0x4);381cvmx_read_csr(CVMX_CIU_SOFT_PRST);382383udelay(2000); /* Wait 2 ms after deasserting PCI reset */384385ctl_status_2.u32 = 0;386ctl_status_2.s.tsr_hwm = 1; /* Initializes to 0. Must be set387before any PCI reads. */388ctl_status_2.s.bar2pres = 1; /* Enable BAR2 */389ctl_status_2.s.bar2_enb = 1;390ctl_status_2.s.bar2_cax = 1; /* Don't use L2 */391ctl_status_2.s.bar2_esx = 1;392ctl_status_2.s.pmo_amod = 1; /* Round robin priority */393if (octeon_dma_bar_type == OCTEON_DMA_BAR_TYPE_BIG) {394/* BAR1 hole */395ctl_status_2.s.bb1_hole = OCTEON_PCI_BAR1_HOLE_BITS;396ctl_status_2.s.bb1_siz = 1; /* BAR1 is 2GB */397ctl_status_2.s.bb_ca = 1; /* Don't use L2 with big bars */398ctl_status_2.s.bb_es = 1; /* Big bar in byte swap mode */399ctl_status_2.s.bb1 = 1; /* BAR1 is big */400ctl_status_2.s.bb0 = 1; /* BAR0 is big */401}402403octeon_npi_write32(CVMX_NPI_PCI_CTL_STATUS_2, ctl_status_2.u32);404udelay(2000); /* Wait 2 ms before doing PCI reads */405406ctl_status_2.u32 = octeon_npi_read32(CVMX_NPI_PCI_CTL_STATUS_2);407pr_notice("PCI Status: %s %s-bit\n",408ctl_status_2.s.ap_pcix ? "PCI-X" : "PCI",409ctl_status_2.s.ap_64ad ? "64" : "32");410411if (OCTEON_IS_MODEL(OCTEON_CN58XX) || OCTEON_IS_MODEL(OCTEON_CN50XX)) {412union cvmx_pci_cnt_reg cnt_reg_start;413union cvmx_pci_cnt_reg cnt_reg_end;414unsigned long cycles, pci_clock;415416cnt_reg_start.u64 = cvmx_read_csr(CVMX_NPI_PCI_CNT_REG);417cycles = read_c0_cvmcount();418udelay(1000);419cnt_reg_end.u64 = cvmx_read_csr(CVMX_NPI_PCI_CNT_REG);420cycles = read_c0_cvmcount() - cycles;421pci_clock = (cnt_reg_end.s.pcicnt - cnt_reg_start.s.pcicnt) /422(cycles / (mips_hpt_frequency / 1000000));423pr_notice("PCI Clock: %lu MHz\n", pci_clock);424}425426/*427* TDOMC must be set to one in PCI mode. TDOMC should be set to 4428* in PCI-X mode to allow four outstanding splits. Otherwise,429* should not change from its reset value. Don't write PCI_CFG19430* in PCI mode (0x82000001 reset value), write it to 0x82000004431* after PCI-X mode is known. MRBCI,MDWE,MDRE -> must be zero.432* MRBCM -> must be one.433*/434if (ctl_status_2.s.ap_pcix) {435cfg19.u32 = 0;436/*437* Target Delayed/Split request outstanding maximum438* count. [1..31] and 0=32. NOTE: If the user439* programs these bits beyond the Designed Maximum440* outstanding count, then the designed maximum table441* depth will be used instead. No additional442* Deferred/Split transactions will be accepted if443* this outstanding maximum count is444* reached. Furthermore, no additional deferred/split445* transactions will be accepted if the I/O delay/ I/O446* Split Request outstanding maximum is reached.447*/448cfg19.s.tdomc = 4;449/*450* Master Deferred Read Request Outstanding Max Count451* (PCI only). CR4C[26:24] Max SAC cycles MAX DAC452* cycles 000 8 4 001 1 0 010 2 1 011 3 1 100 4 2 101453* 5 2 110 6 3 111 7 3 For example, if these bits are454* programmed to 100, the core can support 2 DAC455* cycles, 4 SAC cycles or a combination of 1 DAC and456* 2 SAC cycles. NOTE: For the PCI-X maximum457* outstanding split transactions, refer to458* CRE0[22:20].459*/460cfg19.s.mdrrmc = 2;461/*462* Master Request (Memory Read) Byte Count/Byte Enable463* select. 0 = Byte Enables valid. In PCI mode, a464* burst transaction cannot be performed using Memory465* Read command=4?h6. 1 = DWORD Byte Count valid466* (default). In PCI Mode, the memory read byte467* enables are automatically generated by the468* core. Note: N3 Master Request transaction sizes are469* always determined through the470* am_attr[<35:32>|<7:0>] field.471*/472cfg19.s.mrbcm = 1;473octeon_npi_write32(CVMX_NPI_PCI_CFG19, cfg19.u32);474}475476477cfg01.u32 = 0;478cfg01.s.msae = 1; /* Memory Space Access Enable */479cfg01.s.me = 1; /* Master Enable */480cfg01.s.pee = 1; /* PERR# Enable */481cfg01.s.see = 1; /* System Error Enable */482cfg01.s.fbbe = 1; /* Fast Back to Back Transaction Enable */483484octeon_npi_write32(CVMX_NPI_PCI_CFG01, cfg01.u32);485486#ifdef USE_OCTEON_INTERNAL_ARBITER487/*488* When OCTEON is a PCI host, most systems will use OCTEON's489* internal arbiter, so must enable it before any PCI/PCI-X490* traffic can occur.491*/492{493union cvmx_npi_pci_int_arb_cfg pci_int_arb_cfg;494495pci_int_arb_cfg.u64 = 0;496pci_int_arb_cfg.s.en = 1; /* Internal arbiter enable */497cvmx_write_csr(CVMX_NPI_PCI_INT_ARB_CFG, pci_int_arb_cfg.u64);498}499#endif /* USE_OCTEON_INTERNAL_ARBITER */500501/*502* Preferably written to 1 to set MLTD. [RDSATI,TRTAE,503* TWTAE,TMAE,DPPMR -> must be zero. TILT -> must not be set to504* 1..7.505*/506cfg16.u32 = 0;507cfg16.s.mltd = 1; /* Master Latency Timer Disable */508octeon_npi_write32(CVMX_NPI_PCI_CFG16, cfg16.u32);509510/*511* Should be written to 0x4ff00. MTTV -> must be zero.512* FLUSH -> must be 1. MRV -> should be 0xFF.513*/514cfg22.u32 = 0;515/* Master Retry Value [1..255] and 0=infinite */516cfg22.s.mrv = 0xff;517/*518* AM_DO_FLUSH_I control NOTE: This bit MUST BE ONE for proper519* N3K operation.520*/521cfg22.s.flush = 1;522octeon_npi_write32(CVMX_NPI_PCI_CFG22, cfg22.u32);523524/*525* MOST Indicates the maximum number of outstanding splits (in -1526* notation) when OCTEON is in PCI-X mode. PCI-X performance is527* affected by the MOST selection. Should generally be written528* with one of 0x3be807, 0x2be807, 0x1be807, or 0x0be807,529* depending on the desired MOST of 3, 2, 1, or 0, respectively.530*/531cfg56.u32 = 0;532cfg56.s.pxcid = 7; /* RO - PCI-X Capability ID */533cfg56.s.ncp = 0xe8; /* RO - Next Capability Pointer */534cfg56.s.dpere = 1; /* Data Parity Error Recovery Enable */535cfg56.s.roe = 1; /* Relaxed Ordering Enable */536cfg56.s.mmbc = 1; /* Maximum Memory Byte Count537[0=512B,1=1024B,2=2048B,3=4096B] */538cfg56.s.most = 3; /* Maximum outstanding Split transactions [0=1539.. 7=32] */540541octeon_npi_write32(CVMX_NPI_PCI_CFG56, cfg56.u32);542543/*544* Affects PCI performance when OCTEON services reads to its545* BAR1/BAR2. Refer to Section 10.6.1. The recommended values are546* 0x22, 0x33, and 0x33 for PCI_READ_CMD_6, PCI_READ_CMD_C, and547* PCI_READ_CMD_E, respectively. Unfortunately due to errata DDR-700,548* these values need to be changed so they won't possibly prefetch off549* of the end of memory if PCI is DMAing a buffer at the end of550* memory. Note that these values differ from their reset values.551*/552octeon_npi_write32(CVMX_NPI_PCI_READ_CMD_6, 0x21);553octeon_npi_write32(CVMX_NPI_PCI_READ_CMD_C, 0x31);554octeon_npi_write32(CVMX_NPI_PCI_READ_CMD_E, 0x31);555}556557558/*559* Initialize the Octeon PCI controller560*/561static int __init octeon_pci_setup(void)562{563union cvmx_npi_mem_access_subidx mem_access;564int index;565566/* Only these chips have PCI */567if (octeon_has_feature(OCTEON_FEATURE_PCIE))568return 0;569570if (!octeon_is_pci_host()) {571pr_notice("Not in host mode, PCI Controller not initialized\n");572return 0;573}574575/* Point pcibios_map_irq() to the PCI version of it */576octeon_pcibios_map_irq = octeon_pci_pcibios_map_irq;577578/* Only use the big bars on chips that support it */579if (OCTEON_IS_MODEL(OCTEON_CN31XX) ||580OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||581OCTEON_IS_MODEL(OCTEON_CN38XX_PASS1))582octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_SMALL;583else584octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_BIG;585586/* PCI I/O and PCI MEM values */587set_io_port_base(OCTEON_PCI_IOSPACE_BASE);588ioport_resource.start = 0;589ioport_resource.end = OCTEON_PCI_IOSPACE_SIZE - 1;590591pr_notice("%s Octeon big bar support\n",592(octeon_dma_bar_type ==593OCTEON_DMA_BAR_TYPE_BIG) ? "Enabling" : "Disabling");594595octeon_pci_initialize();596597mem_access.u64 = 0;598mem_access.s.esr = 1; /* Endian-Swap on read. */599mem_access.s.esw = 1; /* Endian-Swap on write. */600mem_access.s.nsr = 0; /* No-Snoop on read. */601mem_access.s.nsw = 0; /* No-Snoop on write. */602mem_access.s.ror = 0; /* Relax Read on read. */603mem_access.s.row = 0; /* Relax Order on write. */604mem_access.s.ba = 0; /* PCI Address bits [63:36]. */605cvmx_write_csr(CVMX_NPI_MEM_ACCESS_SUBID3, mem_access.u64);606607/*608* Remap the Octeon BAR 2 above all 32 bit devices609* (0x8000000000ul). This is done here so it is remapped610* before the readl()'s below. We don't want BAR2 overlapping611* with BAR0/BAR1 during these reads.612*/613octeon_npi_write32(CVMX_NPI_PCI_CFG08,614(u32)(OCTEON_BAR2_PCI_ADDRESS & 0xffffffffull));615octeon_npi_write32(CVMX_NPI_PCI_CFG09,616(u32)(OCTEON_BAR2_PCI_ADDRESS >> 32));617618if (octeon_dma_bar_type == OCTEON_DMA_BAR_TYPE_BIG) {619/* Remap the Octeon BAR 0 to 0-2GB */620octeon_npi_write32(CVMX_NPI_PCI_CFG04, 0);621octeon_npi_write32(CVMX_NPI_PCI_CFG05, 0);622623/*624* Remap the Octeon BAR 1 to map 2GB-4GB (minus the625* BAR 1 hole).626*/627octeon_npi_write32(CVMX_NPI_PCI_CFG06, 2ul << 30);628octeon_npi_write32(CVMX_NPI_PCI_CFG07, 0);629630/* BAR1 movable mappings set for identity mapping */631octeon_bar1_pci_phys = 0x80000000ull;632for (index = 0; index < 32; index++) {633union cvmx_pci_bar1_indexx bar1_index;634635bar1_index.u32 = 0;636/* Address bits[35:22] sent to L2C */637bar1_index.s.addr_idx =638(octeon_bar1_pci_phys >> 22) + index;639/* Don't put PCI accesses in L2. */640bar1_index.s.ca = 1;641/* Endian Swap Mode */642bar1_index.s.end_swp = 1;643/* Set '1' when the selected address range is valid. */644bar1_index.s.addr_v = 1;645octeon_npi_write32(CVMX_NPI_PCI_BAR1_INDEXX(index),646bar1_index.u32);647}648649/* Devices go after BAR1 */650octeon_pci_mem_resource.start =651OCTEON_PCI_MEMSPACE_OFFSET + (4ul << 30) -652(OCTEON_PCI_BAR1_HOLE_SIZE << 20);653octeon_pci_mem_resource.end =654octeon_pci_mem_resource.start + (1ul << 30);655} else {656/* Remap the Octeon BAR 0 to map 128MB-(128MB+4KB) */657octeon_npi_write32(CVMX_NPI_PCI_CFG04, 128ul << 20);658octeon_npi_write32(CVMX_NPI_PCI_CFG05, 0);659660/* Remap the Octeon BAR 1 to map 0-128MB */661octeon_npi_write32(CVMX_NPI_PCI_CFG06, 0);662octeon_npi_write32(CVMX_NPI_PCI_CFG07, 0);663664/* BAR1 movable regions contiguous to cover the swiotlb */665octeon_bar1_pci_phys =666default_swiotlb_base() & ~((1ull << 22) - 1);667668for (index = 0; index < 32; index++) {669union cvmx_pci_bar1_indexx bar1_index;670671bar1_index.u32 = 0;672/* Address bits[35:22] sent to L2C */673bar1_index.s.addr_idx =674(octeon_bar1_pci_phys >> 22) + index;675/* Don't put PCI accesses in L2. */676bar1_index.s.ca = 1;677/* Endian Swap Mode */678bar1_index.s.end_swp = 1;679/* Set '1' when the selected address range is valid. */680bar1_index.s.addr_v = 1;681octeon_npi_write32(CVMX_NPI_PCI_BAR1_INDEXX(index),682bar1_index.u32);683}684685/* Devices go after BAR0 */686octeon_pci_mem_resource.start =687OCTEON_PCI_MEMSPACE_OFFSET + (128ul << 20) +688(4ul << 10);689octeon_pci_mem_resource.end =690octeon_pci_mem_resource.start + (1ul << 30);691}692693register_pci_controller(&octeon_pci_controller);694695/*696* Clear any errors that might be pending from before the bus697* was setup properly.698*/699cvmx_write_csr(CVMX_NPI_PCI_INT_SUM2, -1);700701if (IS_ERR(platform_device_register_simple("octeon_pci_edac",702-1, NULL, 0)))703pr_err("Registration of co_pci_edac failed!\n");704705octeon_pci_dma_init();706707return 0;708}709710arch_initcall(octeon_pci_setup);711712713