Path: blob/master/arch/powerpc/platforms/chrp/setup.c
10820 views
/*1* Copyright (C) 1995 Linus Torvalds2* Adapted from 'alpha' version by Gary Thomas3* Modified by Cort Dougan ([email protected])4*/56/*7* bootup setup stuff..8*/910#include <linux/errno.h>11#include <linux/sched.h>12#include <linux/kernel.h>13#include <linux/mm.h>14#include <linux/stddef.h>15#include <linux/unistd.h>16#include <linux/ptrace.h>17#include <linux/user.h>18#include <linux/tty.h>19#include <linux/major.h>20#include <linux/interrupt.h>21#include <linux/reboot.h>22#include <linux/init.h>23#include <linux/pci.h>24#include <generated/utsrelease.h>25#include <linux/adb.h>26#include <linux/module.h>27#include <linux/delay.h>28#include <linux/console.h>29#include <linux/seq_file.h>30#include <linux/root_dev.h>31#include <linux/initrd.h>32#include <linux/timer.h>3334#include <asm/io.h>35#include <asm/pgtable.h>36#include <asm/prom.h>37#include <asm/pci-bridge.h>38#include <asm/dma.h>39#include <asm/machdep.h>40#include <asm/irq.h>41#include <asm/hydra.h>42#include <asm/sections.h>43#include <asm/time.h>44#include <asm/i8259.h>45#include <asm/mpic.h>46#include <asm/rtas.h>47#include <asm/xmon.h>4849#include "chrp.h"50#include "gg2.h"5152void rtas_indicator_progress(char *, unsigned short);5354int _chrp_type;55EXPORT_SYMBOL(_chrp_type);5657static struct mpic *chrp_mpic;5859/* Used for doing CHRP event-scans */60DEFINE_PER_CPU(struct timer_list, heartbeat_timer);61unsigned long event_scan_interval;6263extern unsigned long loops_per_jiffy;6465/* To be replaced by RTAS when available */66static unsigned int __iomem *briq_SPOR;6768#ifdef CONFIG_SMP69extern struct smp_ops_t chrp_smp_ops;70#endif7172static const char *gg2_memtypes[4] = {73"FPM", "SDRAM", "EDO", "BEDO"74};75static const char *gg2_cachesizes[4] = {76"256 KB", "512 KB", "1 MB", "Reserved"77};78static const char *gg2_cachetypes[4] = {79"Asynchronous", "Reserved", "Flow-Through Synchronous",80"Pipelined Synchronous"81};82static const char *gg2_cachemodes[4] = {83"Disabled", "Write-Through", "Copy-Back", "Transparent Mode"84};8586static const char *chrp_names[] = {87"Unknown",88"","","",89"Motorola",90"IBM or Longtrail",91"Genesi Pegasos",92"Total Impact Briq"93};9495void chrp_show_cpuinfo(struct seq_file *m)96{97int i, sdramen;98unsigned int t;99struct device_node *root;100const char *model = "";101102root = of_find_node_by_path("/");103if (root)104model = of_get_property(root, "model", NULL);105seq_printf(m, "machine\t\t: CHRP %s\n", model);106107/* longtrail (goldengate) stuff */108if (model && !strncmp(model, "IBM,LongTrail", 13)) {109/* VLSI VAS96011/12 `Golden Gate 2' */110/* Memory banks */111sdramen = (in_le32(gg2_pci_config_base + GG2_PCI_DRAM_CTRL)112>>31) & 1;113for (i = 0; i < (sdramen ? 4 : 6); i++) {114t = in_le32(gg2_pci_config_base+115GG2_PCI_DRAM_BANK0+116i*4);117if (!(t & 1))118continue;119switch ((t>>8) & 0x1f) {120case 0x1f:121model = "4 MB";122break;123case 0x1e:124model = "8 MB";125break;126case 0x1c:127model = "16 MB";128break;129case 0x18:130model = "32 MB";131break;132case 0x10:133model = "64 MB";134break;135case 0x00:136model = "128 MB";137break;138default:139model = "Reserved";140break;141}142seq_printf(m, "memory bank %d\t: %s %s\n", i, model,143gg2_memtypes[sdramen ? 1 : ((t>>1) & 3)]);144}145/* L2 cache */146t = in_le32(gg2_pci_config_base+GG2_PCI_CC_CTRL);147seq_printf(m, "board l2\t: %s %s (%s)\n",148gg2_cachesizes[(t>>7) & 3],149gg2_cachetypes[(t>>2) & 3],150gg2_cachemodes[t & 3]);151}152of_node_put(root);153}154155/*156* Fixes for the National Semiconductor PC78308VUL SuperI/O157*158* Some versions of Open Firmware incorrectly initialize the IRQ settings159* for keyboard and mouse160*/161static inline void __init sio_write(u8 val, u8 index)162{163outb(index, 0x15c);164outb(val, 0x15d);165}166167static inline u8 __init sio_read(u8 index)168{169outb(index, 0x15c);170return inb(0x15d);171}172173static void __init sio_fixup_irq(const char *name, u8 device, u8 level,174u8 type)175{176u8 level0, type0, active;177178/* select logical device */179sio_write(device, 0x07);180active = sio_read(0x30);181level0 = sio_read(0x70);182type0 = sio_read(0x71);183if (level0 != level || type0 != type || !active) {184printk(KERN_WARNING "sio: %s irq level %d, type %d, %sactive: "185"remapping to level %d, type %d, active\n",186name, level0, type0, !active ? "in" : "", level, type);187sio_write(0x01, 0x30);188sio_write(level, 0x70);189sio_write(type, 0x71);190}191}192193static void __init sio_init(void)194{195struct device_node *root;196const char *model;197198root = of_find_node_by_path("/");199if (!root)200return;201202model = of_get_property(root, "model", NULL);203if (model && !strncmp(model, "IBM,LongTrail", 13)) {204/* logical device 0 (KBC/Keyboard) */205sio_fixup_irq("keyboard", 0, 1, 2);206/* select logical device 1 (KBC/Mouse) */207sio_fixup_irq("mouse", 1, 12, 2);208}209210of_node_put(root);211}212213214static void __init pegasos_set_l2cr(void)215{216struct device_node *np;217218/* On Pegasos, enable the l2 cache if needed, as the OF forgets it */219if (_chrp_type != _CHRP_Pegasos)220return;221222/* Enable L2 cache if needed */223np = of_find_node_by_type(NULL, "cpu");224if (np != NULL) {225const unsigned int *l2cr = of_get_property(np, "l2cr", NULL);226if (l2cr == NULL) {227printk ("Pegasos l2cr : no cpu l2cr property found\n");228goto out;229}230if (!((*l2cr) & 0x80000000)) {231printk ("Pegasos l2cr : L2 cache was not active, "232"activating\n");233_set_L2CR(0);234_set_L2CR((*l2cr) | 0x80000000);235}236}237out:238of_node_put(np);239}240241static void briq_restart(char *cmd)242{243local_irq_disable();244if (briq_SPOR)245out_be32(briq_SPOR, 0);246for(;;);247}248249/*250* Per default, input/output-device points to the keyboard/screen251* If no card is installed, the built-in serial port is used as a fallback.252* But unfortunately, the firmware does not connect /chosen/{stdin,stdout}253* the the built-in serial node. Instead, a /failsafe node is created.254*/255static void chrp_init_early(void)256{257struct device_node *node;258const char *property;259260if (strstr(cmd_line, "console="))261return;262/* find the boot console from /chosen/stdout */263if (!of_chosen)264return;265node = of_find_node_by_path("/");266if (!node)267return;268property = of_get_property(node, "model", NULL);269if (!property)270goto out_put;271if (strcmp(property, "Pegasos2"))272goto out_put;273/* this is a Pegasos2 */274property = of_get_property(of_chosen, "linux,stdout-path", NULL);275if (!property)276goto out_put;277of_node_put(node);278node = of_find_node_by_path(property);279if (!node)280return;281property = of_get_property(node, "device_type", NULL);282if (!property)283goto out_put;284if (strcmp(property, "serial"))285goto out_put;286/*287* The 9pin connector is either /failsafe288* or /pci@80000000/isa@C/serial@i2F8289* The optional graphics card has also type 'serial' in VGA mode.290*/291property = of_get_property(node, "name", NULL);292if (!property)293goto out_put;294if (!strcmp(property, "failsafe") || !strcmp(property, "serial"))295add_preferred_console("ttyS", 0, NULL);296out_put:297of_node_put(node);298}299300void __init chrp_setup_arch(void)301{302struct device_node *root = of_find_node_by_path("/");303const char *machine = NULL;304305/* init to some ~sane value until calibrate_delay() runs */306loops_per_jiffy = 50000000/HZ;307308if (root)309machine = of_get_property(root, "model", NULL);310if (machine && strncmp(machine, "Pegasos", 7) == 0) {311_chrp_type = _CHRP_Pegasos;312} else if (machine && strncmp(machine, "IBM", 3) == 0) {313_chrp_type = _CHRP_IBM;314} else if (machine && strncmp(machine, "MOT", 3) == 0) {315_chrp_type = _CHRP_Motorola;316} else if (machine && strncmp(machine, "TotalImpact,BRIQ-1", 18) == 0) {317_chrp_type = _CHRP_briq;318/* Map the SPOR register on briq and change the restart hook */319briq_SPOR = ioremap(0xff0000e8, 4);320ppc_md.restart = briq_restart;321} else {322/* Let's assume it is an IBM chrp if all else fails */323_chrp_type = _CHRP_IBM;324}325of_node_put(root);326printk("chrp type = %x [%s]\n", _chrp_type, chrp_names[_chrp_type]);327328rtas_initialize();329if (rtas_token("display-character") >= 0)330ppc_md.progress = rtas_progress;331332/* use RTAS time-of-day routines if available */333if (rtas_token("get-time-of-day") != RTAS_UNKNOWN_SERVICE) {334ppc_md.get_boot_time = rtas_get_boot_time;335ppc_md.get_rtc_time = rtas_get_rtc_time;336ppc_md.set_rtc_time = rtas_set_rtc_time;337}338339/* On pegasos, enable the L2 cache if not already done by OF */340pegasos_set_l2cr();341342/* Lookup PCI host bridges */343chrp_find_bridges();344345/*346* Temporary fixes for PCI devices.347* -- Geert348*/349hydra_init(); /* Mac I/O */350351/*352* Fix the Super I/O configuration353*/354sio_init();355356pci_create_OF_bus_map();357358/*359* Print the banner, then scroll down so boot progress360* can be printed. -- Cort361*/362if (ppc_md.progress) ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0x0);363}364365static void chrp_8259_cascade(unsigned int irq, struct irq_desc *desc)366{367struct irq_chip *chip = irq_desc_get_chip(desc);368unsigned int cascade_irq = i8259_irq();369370if (cascade_irq != NO_IRQ)371generic_handle_irq(cascade_irq);372373chip->irq_eoi(&desc->irq_data);374}375376/*377* Finds the open-pic node and sets up the mpic driver.378*/379static void __init chrp_find_openpic(void)380{381struct device_node *np, *root;382int len, i, j;383int isu_size, idu_size;384const unsigned int *iranges, *opprop = NULL;385int oplen = 0;386unsigned long opaddr;387int na = 1;388389np = of_find_node_by_type(NULL, "open-pic");390if (np == NULL)391return;392root = of_find_node_by_path("/");393if (root) {394opprop = of_get_property(root, "platform-open-pic", &oplen);395na = of_n_addr_cells(root);396}397if (opprop && oplen >= na * sizeof(unsigned int)) {398opaddr = opprop[na-1]; /* assume 32-bit */399oplen /= na * sizeof(unsigned int);400} else {401struct resource r;402if (of_address_to_resource(np, 0, &r)) {403goto bail;404}405opaddr = r.start;406oplen = 0;407}408409printk(KERN_INFO "OpenPIC at %lx\n", opaddr);410411iranges = of_get_property(np, "interrupt-ranges", &len);412if (iranges == NULL)413len = 0; /* non-distributed mpic */414else415len /= 2 * sizeof(unsigned int);416417/*418* The first pair of cells in interrupt-ranges refers to the419* IDU; subsequent pairs refer to the ISUs.420*/421if (oplen < len) {422printk(KERN_ERR "Insufficient addresses for distributed"423" OpenPIC (%d < %d)\n", oplen, len);424len = oplen;425}426427isu_size = 0;428idu_size = 0;429if (len > 0 && iranges[1] != 0) {430printk(KERN_INFO "OpenPIC irqs %d..%d in IDU\n",431iranges[0], iranges[0] + iranges[1] - 1);432idu_size = iranges[1];433}434if (len > 1)435isu_size = iranges[3];436437chrp_mpic = mpic_alloc(np, opaddr, MPIC_PRIMARY,438isu_size, 0, " MPIC ");439if (chrp_mpic == NULL) {440printk(KERN_ERR "Failed to allocate MPIC structure\n");441goto bail;442}443j = na - 1;444for (i = 1; i < len; ++i) {445iranges += 2;446j += na;447printk(KERN_INFO "OpenPIC irqs %d..%d in ISU at %x\n",448iranges[0], iranges[0] + iranges[1] - 1,449opprop[j]);450mpic_assign_isu(chrp_mpic, i - 1, opprop[j]);451}452453mpic_init(chrp_mpic);454ppc_md.get_irq = mpic_get_irq;455bail:456of_node_put(root);457of_node_put(np);458}459460#if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_XMON)461static struct irqaction xmon_irqaction = {462.handler = xmon_irq,463.name = "XMON break",464};465#endif466467static void __init chrp_find_8259(void)468{469struct device_node *np, *pic = NULL;470unsigned long chrp_int_ack = 0;471unsigned int cascade_irq;472473/* Look for cascade */474for_each_node_by_type(np, "interrupt-controller")475if (of_device_is_compatible(np, "chrp,iic")) {476pic = np;477break;478}479/* Ok, 8259 wasn't found. We need to handle the case where480* we have a pegasos that claims to be chrp but doesn't have481* a proper interrupt tree482*/483if (pic == NULL && chrp_mpic != NULL) {484printk(KERN_ERR "i8259: Not found in device-tree"485" assuming no legacy interrupts\n");486return;487}488489/* Look for intack. In a perfect world, we would look for it on490* the ISA bus that holds the 8259 but heh... Works that way. If491* we ever see a problem, we can try to re-use the pSeries code here.492* Also, Pegasos-type platforms don't have a proper node to start493* from anyway494*/495for_each_node_by_name(np, "pci") {496const unsigned int *addrp = of_get_property(np,497"8259-interrupt-acknowledge", NULL);498499if (addrp == NULL)500continue;501chrp_int_ack = addrp[of_n_addr_cells(np)-1];502break;503}504of_node_put(np);505if (np == NULL)506printk(KERN_WARNING "Cannot find PCI interrupt acknowledge"507" address, polling\n");508509i8259_init(pic, chrp_int_ack);510if (ppc_md.get_irq == NULL) {511ppc_md.get_irq = i8259_irq;512irq_set_default_host(i8259_get_host());513}514if (chrp_mpic != NULL) {515cascade_irq = irq_of_parse_and_map(pic, 0);516if (cascade_irq == NO_IRQ)517printk(KERN_ERR "i8259: failed to map cascade irq\n");518else519irq_set_chained_handler(cascade_irq,520chrp_8259_cascade);521}522}523524void __init chrp_init_IRQ(void)525{526#if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_XMON)527struct device_node *kbd;528#endif529chrp_find_openpic();530chrp_find_8259();531532#ifdef CONFIG_SMP533/* Pegasos has no MPIC, those ops would make it crash. It might be an534* option to move setting them to after we probe the PIC though535*/536if (chrp_mpic != NULL)537smp_ops = &chrp_smp_ops;538#endif /* CONFIG_SMP */539540if (_chrp_type == _CHRP_Pegasos)541ppc_md.get_irq = i8259_irq;542543#if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_XMON)544/* see if there is a keyboard in the device tree545with a parent of type "adb" */546for_each_node_by_name(kbd, "keyboard")547if (kbd->parent && kbd->parent->type548&& strcmp(kbd->parent->type, "adb") == 0)549break;550of_node_put(kbd);551if (kbd)552setup_irq(HYDRA_INT_ADB_NMI, &xmon_irqaction);553#endif554}555556void __init557chrp_init2(void)558{559#ifdef CONFIG_NVRAM560chrp_nvram_init();561#endif562563request_region(0x20,0x20,"pic1");564request_region(0xa0,0x20,"pic2");565request_region(0x00,0x20,"dma1");566request_region(0x40,0x20,"timer");567request_region(0x80,0x10,"dma page reg");568request_region(0xc0,0x20,"dma2");569570if (ppc_md.progress)571ppc_md.progress(" Have fun! ", 0x7777);572}573574static int __init chrp_probe(void)575{576char *dtype = of_get_flat_dt_prop(of_get_flat_dt_root(),577"device_type", NULL);578if (dtype == NULL)579return 0;580if (strcmp(dtype, "chrp"))581return 0;582583ISA_DMA_THRESHOLD = ~0L;584DMA_MODE_READ = 0x44;585DMA_MODE_WRITE = 0x48;586587return 1;588}589590define_machine(chrp) {591.name = "CHRP",592.probe = chrp_probe,593.setup_arch = chrp_setup_arch,594.init = chrp_init2,595.init_early = chrp_init_early,596.show_cpuinfo = chrp_show_cpuinfo,597.init_IRQ = chrp_init_IRQ,598.restart = rtas_restart,599.power_off = rtas_power_off,600.halt = rtas_halt,601.time_init = chrp_time_init,602.set_rtc_time = chrp_set_rtc_time,603.get_rtc_time = chrp_get_rtc_time,604.calibrate_decr = generic_calibrate_decr,605.phys_mem_access_prot = pci_phys_mem_access_prot,606};607608609