Path: blob/master/arch/alpha/kernel/core_irongate.c
10817 views
/*1* linux/arch/alpha/kernel/core_irongate.c2*3* Based on code written by David A. Rusling ([email protected]).4*5* Copyright (C) 1999 Alpha Processor, Inc.,6* (David Daniel, Stig Telfer, Soohoon Lee)7*8* Code common to all IRONGATE core logic chips.9*/1011#define __EXTERN_INLINE inline12#include <asm/io.h>13#include <asm/core_irongate.h>14#undef __EXTERN_INLINE1516#include <linux/types.h>17#include <linux/pci.h>18#include <linux/sched.h>19#include <linux/init.h>20#include <linux/initrd.h>21#include <linux/bootmem.h>2223#include <asm/ptrace.h>24#include <asm/pci.h>25#include <asm/cacheflush.h>26#include <asm/tlbflush.h>2728#include "proto.h"29#include "pci_impl.h"3031/*32* BIOS32-style PCI interface:33*/3435#define DEBUG_CONFIG 03637#if DEBUG_CONFIG38# define DBG_CFG(args) printk args39#else40# define DBG_CFG(args)41#endif4243igcsr32 *IronECC;4445/*46* Given a bus, device, and function number, compute resulting47* configuration space address accordingly. It is therefore not safe48* to have concurrent invocations to configuration space access49* routines, but there really shouldn't be any need for this.50*51* addr[31:24] reserved52* addr[23:16] bus number (8 bits = 128 possible buses)53* addr[15:11] Device number (5 bits)54* addr[10: 8] function number55* addr[ 7: 2] register number56*57* For IRONGATE:58* if (bus = addr[23:16]) == 059* then60* type 0 config cycle:61* addr_on_pci[31:11] = id selection for device = addr[15:11]62* addr_on_pci[10: 2] = addr[10: 2] ???63* addr_on_pci[ 1: 0] = 0064* else65* type 1 config cycle (pass on with no decoding):66* addr_on_pci[31:24] = 067* addr_on_pci[23: 2] = addr[23: 2]68* addr_on_pci[ 1: 0] = 0169* fi70*71* Notes:72* The function number selects which function of a multi-function device73* (e.g., SCSI and Ethernet).74*75* The register selects a DWORD (32 bit) register offset. Hence it76* doesn't get shifted by 2 bits as we want to "drop" the bottom two77* bits.78*/7980static int81mk_conf_addr(struct pci_bus *pbus, unsigned int device_fn, int where,82unsigned long *pci_addr, unsigned char *type1)83{84unsigned long addr;85u8 bus = pbus->number;8687DBG_CFG(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x, "88"pci_addr=0x%p, type1=0x%p)\n",89bus, device_fn, where, pci_addr, type1));9091*type1 = (bus != 0);9293addr = (bus << 16) | (device_fn << 8) | where;94addr |= IRONGATE_CONF;9596*pci_addr = addr;97DBG_CFG(("mk_conf_addr: returning pci_addr 0x%lx\n", addr));98return 0;99}100101static int102irongate_read_config(struct pci_bus *bus, unsigned int devfn, int where,103int size, u32 *value)104{105unsigned long addr;106unsigned char type1;107108if (mk_conf_addr(bus, devfn, where, &addr, &type1))109return PCIBIOS_DEVICE_NOT_FOUND;110111switch (size) {112case 1:113*value = __kernel_ldbu(*(vucp)addr);114break;115case 2:116*value = __kernel_ldwu(*(vusp)addr);117break;118case 4:119*value = *(vuip)addr;120break;121}122123return PCIBIOS_SUCCESSFUL;124}125126static int127irongate_write_config(struct pci_bus *bus, unsigned int devfn, int where,128int size, u32 value)129{130unsigned long addr;131unsigned char type1;132133if (mk_conf_addr(bus, devfn, where, &addr, &type1))134return PCIBIOS_DEVICE_NOT_FOUND;135136switch (size) {137case 1:138__kernel_stb(value, *(vucp)addr);139mb();140__kernel_ldbu(*(vucp)addr);141break;142case 2:143__kernel_stw(value, *(vusp)addr);144mb();145__kernel_ldwu(*(vusp)addr);146break;147case 4:148*(vuip)addr = value;149mb();150*(vuip)addr;151break;152}153154return PCIBIOS_SUCCESSFUL;155}156157struct pci_ops irongate_pci_ops =158{159.read = irongate_read_config,160.write = irongate_write_config,161};162163int164irongate_pci_clr_err(void)165{166unsigned int nmi_ctl=0;167unsigned int IRONGATE_jd;168169again:170IRONGATE_jd = IRONGATE0->stat_cmd;171printk("Iron stat_cmd %x\n", IRONGATE_jd);172IRONGATE0->stat_cmd = IRONGATE_jd; /* write again clears error bits */173mb();174IRONGATE_jd = IRONGATE0->stat_cmd; /* re-read to force write */175176IRONGATE_jd = *IronECC;177printk("Iron ECC %x\n", IRONGATE_jd);178*IronECC = IRONGATE_jd; /* write again clears error bits */179mb();180IRONGATE_jd = *IronECC; /* re-read to force write */181182/* Clear ALI NMI */183nmi_ctl = inb(0x61);184nmi_ctl |= 0x0c;185outb(nmi_ctl, 0x61);186nmi_ctl &= ~0x0c;187outb(nmi_ctl, 0x61);188189IRONGATE_jd = *IronECC;190if (IRONGATE_jd & 0x300) goto again;191192return 0;193}194195#define IRONGATE_3GB 0xc0000000UL196197/* On Albacore (aka UP1500) with 4Gb of RAM we have to reserve some198memory for PCI. At this point we just reserve memory above 3Gb. Most199of this memory will be freed after PCI setup is done. */200static void __init201albacore_init_arch(void)202{203unsigned long memtop = max_low_pfn << PAGE_SHIFT;204unsigned long pci_mem = (memtop + 0x1000000UL) & ~0xffffffUL;205struct percpu_struct *cpu;206int pal_rev, pal_var;207208cpu = (struct percpu_struct*)((char*)hwrpb + hwrpb->processor_offset);209pal_rev = cpu->pal_revision & 0xffff;210pal_var = (cpu->pal_revision >> 16) & 0xff;211212/* Consoles earlier than A5.6-18 (OSF PALcode v1.62-2) set up213the CPU incorrectly (leave speculative stores enabled),214which causes memory corruption under certain conditions.215Issue a warning for such consoles. */216if (alpha_using_srm &&217(pal_rev < 0x13e || (pal_rev == 0x13e && pal_var < 2)))218printk(KERN_WARNING "WARNING! Upgrade to SRM A5.6-19 "219"or later\n");220221if (pci_mem > IRONGATE_3GB)222pci_mem = IRONGATE_3GB;223IRONGATE0->pci_mem = pci_mem;224alpha_mv.min_mem_address = pci_mem;225if (memtop > pci_mem) {226#ifdef CONFIG_BLK_DEV_INITRD227extern unsigned long initrd_start, initrd_end;228extern void *move_initrd(unsigned long);229230/* Move the initrd out of the way. */231if (initrd_end && __pa(initrd_end) > pci_mem) {232unsigned long size;233234size = initrd_end - initrd_start;235free_bootmem_node(NODE_DATA(0), __pa(initrd_start),236PAGE_ALIGN(size));237if (!move_initrd(pci_mem))238printk("irongate_init_arch: initrd too big "239"(%ldK)\ndisabling initrd\n",240size / 1024);241}242#endif243reserve_bootmem_node(NODE_DATA(0), pci_mem, memtop -244pci_mem, BOOTMEM_DEFAULT);245printk("irongate_init_arch: temporarily reserving "246"region %08lx-%08lx for PCI\n", pci_mem, memtop - 1);247}248}249250static void __init251irongate_setup_agp(void)252{253/* Disable the GART window. AGPGART doesn't work due to yet254unresolved memory coherency issues... */255IRONGATE0->agpva = IRONGATE0->agpva & ~0xf;256alpha_agpgart_size = 0;257}258259void __init260irongate_init_arch(void)261{262struct pci_controller *hose;263int amd761 = (IRONGATE0->dev_vendor >> 16) > 0x7006; /* Albacore? */264265IronECC = amd761 ? &IRONGATE0->bacsr54_eccms761 : &IRONGATE0->dramms;266267irongate_pci_clr_err();268269if (amd761)270albacore_init_arch();271272irongate_setup_agp();273274/*275* Create our single hose.276*/277278pci_isa_hose = hose = alloc_pci_controller();279hose->io_space = &ioport_resource;280hose->mem_space = &iomem_resource;281hose->index = 0;282283/* This is for userland consumption. For some reason, the 40-bit284PIO bias that we use in the kernel through KSEG didn't work for285the page table based user mappings. So make sure we get the28643-bit PIO bias. */287hose->sparse_mem_base = 0;288hose->sparse_io_base = 0;289hose->dense_mem_base290= (IRONGATE_MEM & 0xffffffffffUL) | 0x80000000000UL;291hose->dense_io_base292= (IRONGATE_IO & 0xffffffffffUL) | 0x80000000000UL;293294hose->sg_isa = hose->sg_pci = NULL;295__direct_map_base = 0;296__direct_map_size = 0xffffffff;297}298299/*300* IO map and AGP support301*/302#include <linux/vmalloc.h>303#include <linux/agp_backend.h>304#include <linux/agpgart.h>305#include <asm/pgalloc.h>306307#define GET_PAGE_DIR_OFF(addr) (addr >> 22)308#define GET_PAGE_DIR_IDX(addr) (GET_PAGE_DIR_OFF(addr))309310#define GET_GATT_OFF(addr) ((addr & 0x003ff000) >> 12)311#define GET_GATT(addr) (gatt_pages[GET_PAGE_DIR_IDX(addr)])312313void __iomem *314irongate_ioremap(unsigned long addr, unsigned long size)315{316struct vm_struct *area;317unsigned long vaddr;318unsigned long baddr, last;319u32 *mmio_regs, *gatt_pages, *cur_gatt, pte;320unsigned long gart_bus_addr;321322if (!alpha_agpgart_size)323return (void __iomem *)(addr + IRONGATE_MEM);324325gart_bus_addr = (unsigned long)IRONGATE0->bar0 &326PCI_BASE_ADDRESS_MEM_MASK;327328/*329* Check for within the AGP aperture...330*/331do {332/*333* Check the AGP area334*/335if (addr >= gart_bus_addr && addr + size - 1 <336gart_bus_addr + alpha_agpgart_size)337break;338339/*340* Not found - assume legacy ioremap341*/342return (void __iomem *)(addr + IRONGATE_MEM);343} while(0);344345mmio_regs = (u32 *)(((unsigned long)IRONGATE0->bar1 &346PCI_BASE_ADDRESS_MEM_MASK) + IRONGATE_MEM);347348gatt_pages = (u32 *)(phys_to_virt(mmio_regs[1])); /* FIXME */349350/*351* Adjust the limits (mappings must be page aligned)352*/353if (addr & ~PAGE_MASK) {354printk("AGP ioremap failed... addr not page aligned (0x%lx)\n",355addr);356return (void __iomem *)(addr + IRONGATE_MEM);357}358last = addr + size - 1;359size = PAGE_ALIGN(last) - addr;360361#if 0362printk("irongate_ioremap(0x%lx, 0x%lx)\n", addr, size);363printk("irongate_ioremap: gart_bus_addr 0x%lx\n", gart_bus_addr);364printk("irongate_ioremap: gart_aper_size 0x%lx\n", gart_aper_size);365printk("irongate_ioremap: mmio_regs %p\n", mmio_regs);366printk("irongate_ioremap: gatt_pages %p\n", gatt_pages);367368for(baddr = addr; baddr <= last; baddr += PAGE_SIZE)369{370cur_gatt = phys_to_virt(GET_GATT(baddr) & ~1);371pte = cur_gatt[GET_GATT_OFF(baddr)] & ~1;372printk("irongate_ioremap: cur_gatt %p pte 0x%x\n",373cur_gatt, pte);374}375#endif376377/*378* Map it379*/380area = get_vm_area(size, VM_IOREMAP);381if (!area) return NULL;382383for(baddr = addr, vaddr = (unsigned long)area->addr;384baddr <= last;385baddr += PAGE_SIZE, vaddr += PAGE_SIZE)386{387cur_gatt = phys_to_virt(GET_GATT(baddr) & ~1);388pte = cur_gatt[GET_GATT_OFF(baddr)] & ~1;389390if (__alpha_remap_area_pages(vaddr,391pte, PAGE_SIZE, 0)) {392printk("AGP ioremap: FAILED to map...\n");393vfree(area->addr);394return NULL;395}396}397398flush_tlb_all();399400vaddr = (unsigned long)area->addr + (addr & ~PAGE_MASK);401#if 0402printk("irongate_ioremap(0x%lx, 0x%lx) returning 0x%lx\n",403addr, size, vaddr);404#endif405return (void __iomem *)vaddr;406}407EXPORT_SYMBOL(irongate_ioremap);408409void410irongate_iounmap(volatile void __iomem *xaddr)411{412unsigned long addr = (unsigned long) xaddr;413if (((long)addr >> 41) == -2)414return; /* kseg map, nothing to do */415if (addr)416return vfree((void *)(PAGE_MASK & addr));417}418EXPORT_SYMBOL(irongate_iounmap);419420421