]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/powerpc/platforms/pseries/lpar.c
Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
[linux-2.6-omap-h63xx.git] / arch / powerpc / platforms / pseries / lpar.c
index e384a5a9179607b2af53873fb596122bfe89789b..1820a0b0a8c6e55cd3f7351e34ea68a2f0110ab5 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  */
 
-#define DEBUG
+#undef DEBUG_LOW
 
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/dma-mapping.h>
+#include <linux/console.h>
 #include <asm/processor.h>
 #include <asm/mmu.h>
 #include <asm/page.h>
 #include <asm/machdep.h>
 #include <asm/abs_addr.h>
 #include <asm/mmu_context.h>
-#include <asm/ppcdebug.h>
 #include <asm/iommu.h>
 #include <asm/tlbflush.h>
 #include <asm/tlb.h>
 #include <asm/prom.h>
 #include <asm/abs_addr.h>
 #include <asm/cputable.h>
+#include <asm/udbg.h>
+#include <asm/smp.h>
 
 #include "plpar_wrappers.h"
 
-#ifdef DEBUG
-#define DBG(fmt...) udbg_printf(fmt)
+#ifdef DEBUG_LOW
+#define DBG_LOW(fmt...) do { udbg_printf(fmt); } while(0)
 #else
-#define DBG(fmt...)
+#define DBG_LOW(fmt...) do { } while(0)
 #endif
 
-/* in pSeries_hvCall.S */
+/* in hvCall.S */
 EXPORT_SYMBOL(plpar_hcall);
-EXPORT_SYMBOL(plpar_hcall_4out);
+EXPORT_SYMBOL(plpar_hcall9);
 EXPORT_SYMBOL(plpar_hcall_norets);
-EXPORT_SYMBOL(plpar_hcall_8arg_2ret);
 
 extern void pSeries_find_serial_port(void);
 
@@ -59,7 +59,7 @@ extern void pSeries_find_serial_port(void);
 int vtermno;   /* virtual terminal# for udbg  */
 
 #define __ALIGNED__ __attribute__((__aligned__(sizeof(long))))
-static void udbg_hvsi_putc(unsigned char c)
+static void udbg_hvsi_putc(char c)
 {
        /* packet's seqno isn't used anyways */
        uint8_t packet[] __ALIGNED__ = { 0xff, 5, 0, 0, c };
@@ -70,7 +70,7 @@ static void udbg_hvsi_putc(unsigned char c)
 
        do {
                rc = plpar_put_term_char(vtermno, sizeof(packet), packet);
-       } while (rc == H_Busy);
+       } while (rc == H_BUSY);
 }
 
 static long hvsi_udbg_buf_len;
@@ -83,7 +83,7 @@ static int udbg_hvsi_getc_poll(void)
 
        if (hvsi_udbg_buf_len == 0) {
                rc = plpar_get_term_char(vtermno, &hvsi_udbg_buf_len, hvsi_udbg_buf);
-               if (rc != H_Success || hvsi_udbg_buf[0] != 0xff) {
+               if (rc != H_SUCCESS || hvsi_udbg_buf[0] != 0xff) {
                        /* bad read or non-data packet */
                        hvsi_udbg_buf_len = 0;
                } else {
@@ -110,7 +110,7 @@ static int udbg_hvsi_getc_poll(void)
        return ch;
 }
 
-static unsigned char udbg_hvsi_getc(void)
+static int udbg_hvsi_getc(void)
 {
        int ch;
        for (;;) {
@@ -126,7 +126,7 @@ static unsigned char udbg_hvsi_getc(void)
        }
 }
 
-static void udbg_putcLP(unsigned char c)
+static void udbg_putcLP(char c)
 {
        char buf[16];
        unsigned long rc;
@@ -137,7 +137,7 @@ static void udbg_putcLP(unsigned char c)
        buf[0] = c;
        do {
                rc = plpar_put_term_char(vtermno, 1, buf);
-       } while(rc == H_Busy);
+       } while(rc == H_BUSY);
 }
 
 /* Buffered chars getc */
@@ -156,7 +156,7 @@ static int udbg_getc_pollLP(void)
                /* get some more chars. */
                inbuflen = 0;
                rc = plpar_get_term_char(vtermno, &inbuflen, buf);
-               if (rc != H_Success)
+               if (rc != H_SUCCESS)
                        inbuflen = 0;   /* otherwise inbuflen is garbage */
        }
        if (inbuflen <= 0 || inbuflen > 16) {
@@ -171,7 +171,7 @@ static int udbg_getc_pollLP(void)
        return ch;
 }
 
-static unsigned char udbg_getcLP(void)
+static int udbg_getcLP(void)
 {
        int ch;
        for (;;) {
@@ -190,7 +190,7 @@ static unsigned char udbg_getcLP(void)
 /* call this from early_init() for a working debug console on
  * vterm capable LPAR machines
  */
-void udbg_init_debug_lpar(void)
+void __init udbg_init_debug_lpar(void)
 {
        vtermno = 0;
        udbg_putc = udbg_putcLP;
@@ -199,97 +199,109 @@ void udbg_init_debug_lpar(void)
 }
 
 /* returns 0 if couldn't find or use /chosen/stdout as console */
-int find_udbg_vterm(void)
+void __init find_udbg_vterm(void)
 {
        struct device_node *stdout_node;
-       u32 *termno;
-       char *name;
-       int found = 0;
+       const u32 *termno;
+       const char *name;
+       int add_console;
 
        /* find the boot console from /chosen/stdout */
        if (!of_chosen)
-               return 0;
-       name = (char *)get_property(of_chosen, "linux,stdout-path", NULL);
+               return;
+       name = get_property(of_chosen, "linux,stdout-path", NULL);
        if (name == NULL)
-               return 0;
+               return;
        stdout_node = of_find_node_by_path(name);
        if (!stdout_node)
-               return 0;
-
-       /* now we have the stdout node; figure out what type of device it is. */
-       name = (char *)get_property(stdout_node, "name", NULL);
+               return;
+       name = get_property(stdout_node, "name", NULL);
        if (!name) {
                printk(KERN_WARNING "stdout node missing 'name' property!\n");
                goto out;
        }
+       /* The user has requested a console so this is already set up. */
+       add_console = !strstr(cmd_line, "console=");
 
-       if (strncmp(name, "vty", 3) == 0) {
-               if (device_is_compatible(stdout_node, "hvterm1")) {
-                       termno = (u32 *)get_property(stdout_node, "reg", NULL);
-                       if (termno) {
-                               vtermno = termno[0];
-                               udbg_putc = udbg_putcLP;
-                               udbg_getc = udbg_getcLP;
-                               udbg_getc_poll = udbg_getc_pollLP;
-                               found = 1;
-                       }
-               } else if (device_is_compatible(stdout_node, "hvterm-protocol")) {
-                       termno = (u32 *)get_property(stdout_node, "reg", NULL);
-                       if (termno) {
-                               vtermno = termno[0];
-                               udbg_putc = udbg_hvsi_putc;
-                               udbg_getc = udbg_hvsi_getc;
-                               udbg_getc_poll = udbg_hvsi_getc_poll;
-                               found = 1;
-                       }
-               }
-       } else if (strncmp(name, "serial", 6)) {
-               /* XXX fix ISA serial console */
-               printk(KERN_WARNING "serial stdout on LPAR ('%s')! "
-                               "can't print udbg messages\n",
-                      stdout_node->full_name);
-       } else {
-               printk(KERN_WARNING "don't know how to print to stdout '%s'\n",
-                      stdout_node->full_name);
+       /* Check if it's a virtual terminal */
+       if (strncmp(name, "vty", 3) != 0)
+               goto out;
+       termno = get_property(stdout_node, "reg", NULL);
+       if (termno == NULL)
+               goto out;
+       vtermno = termno[0];
+
+       if (device_is_compatible(stdout_node, "hvterm1")) {
+               udbg_putc = udbg_putcLP;
+               udbg_getc = udbg_getcLP;
+               udbg_getc_poll = udbg_getc_pollLP;
+               if (add_console)
+                       add_preferred_console("hvc", termno[0] & 0xff, NULL);
+       } else if (device_is_compatible(stdout_node, "hvterm-protocol")) {
+               vtermno = termno[0];
+               udbg_putc = udbg_hvsi_putc;
+               udbg_getc = udbg_hvsi_getc;
+               udbg_getc_poll = udbg_hvsi_getc_poll;
+               if (add_console)
+                       add_preferred_console("hvsi", termno[0] & 0xff, NULL);
        }
-
 out:
        of_node_put(stdout_node);
-       return found;
 }
 
 void vpa_init(int cpu)
 {
        int hwcpu = get_hard_smp_processor_id(cpu);
-       unsigned long vpa = __pa(&paca[cpu].lppaca);
+       unsigned long addr;
        long ret;
 
        if (cpu_has_feature(CPU_FTR_ALTIVEC))
-               paca[cpu].lppaca.vmxregs_in_use = 1;
+               lppaca[cpu].vmxregs_in_use = 1;
 
-       ret = register_vpa(hwcpu, vpa);
+       addr = __pa(&lppaca[cpu]);
+       ret = register_vpa(hwcpu, addr);
 
-       if (ret)
+       if (ret) {
                printk(KERN_ERR "WARNING: vpa_init: VPA registration for "
                                "cpu %d (hw %d) of area %lx returns %ld\n",
-                               cpu, hwcpu, vpa, ret);
+                               cpu, hwcpu, addr, ret);
+               return;
+       }
+       /*
+        * PAPR says this feature is SLB-Buffer but firmware never
+        * reports that.  All SPLPAR support SLB shadow buffer.
+        */
+       addr = __pa(&slb_shadow[cpu]);
+       if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
+               ret = register_slb_shadow(hwcpu, addr);
+               if (ret)
+                       printk(KERN_ERR
+                              "WARNING: vpa_init: SLB shadow buffer "
+                              "registration for cpu %d (hw %d) of area %lx "
+                              "returns %ld\n", cpu, hwcpu, addr, ret);
+       }
 }
 
 long pSeries_lpar_hpte_insert(unsigned long hpte_group,
-                             unsigned long va, unsigned long prpn,
-                             unsigned long vflags, unsigned long rflags)
+                             unsigned long va, unsigned long pa,
+                             unsigned long rflags, unsigned long vflags,
+                             int psize)
 {
        unsigned long lpar_rc;
        unsigned long flags;
        unsigned long slot;
        unsigned long hpte_v, hpte_r;
-       unsigned long dummy0, dummy1;
 
-       hpte_v = ((va >> 23) << HPTE_V_AVPN_SHIFT) | vflags | HPTE_V_VALID;
-       if (vflags & HPTE_V_LARGE)
-               hpte_v &= ~(1UL << HPTE_V_AVPN_SHIFT);
+       if (!(vflags & HPTE_V_BOLTED))
+               DBG_LOW("hpte_insert(group=%lx, va=%016lx, pa=%016lx, "
+                       "rflags=%lx, vflags=%lx, psize=%d)\n",
+               hpte_group, va, pa, rflags, vflags, psize);
+
+       hpte_v = hpte_encode_v(va, psize) | vflags | HPTE_V_VALID;
+       hpte_r = hpte_encode_r(pa, psize) | rflags;
 
-       hpte_r = (prpn << HPTE_R_RPN_SHIFT) | rflags;
+       if (!(vflags & HPTE_V_BOLTED))
+               DBG_LOW(" hpte_v=%016lx, hpte_r=%016lx\n", hpte_v, hpte_r);
 
        /* Now fill in the actual HPTE */
        /* Set CEC cookie to 0         */
@@ -299,23 +311,29 @@ long pSeries_lpar_hpte_insert(unsigned long hpte_group,
        /* Exact = 0                   */
        flags = 0;
 
-       /* XXX why is this here? - Anton */
+       /* Make pHyp happy */
        if (rflags & (_PAGE_GUARDED|_PAGE_NO_CACHE))
                hpte_r &= ~_PAGE_COHERENT;
 
-       lpar_rc = plpar_hcall(H_ENTER, flags, hpte_group, hpte_v,
-                             hpte_r, &slot, &dummy0, &dummy1);
-
-       if (unlikely(lpar_rc == H_PTEG_Full))
+       lpar_rc = plpar_pte_enter(flags, hpte_group, hpte_v, hpte_r, &slot);
+       if (unlikely(lpar_rc == H_PTEG_FULL)) {
+               if (!(vflags & HPTE_V_BOLTED))
+                       DBG_LOW(" full\n");
                return -1;
+       }
 
        /*
         * Since we try and ioremap PHBs we don't own, the pte insert
         * will fail. However we must catch the failure in hash_page
         * or we will loop forever, so return -2 in this case.
         */
-       if (unlikely(lpar_rc != H_Success))
+       if (unlikely(lpar_rc != H_SUCCESS)) {
+               if (!(vflags & HPTE_V_BOLTED))
+                       DBG_LOW(" lpar err %d\n", lpar_rc);
                return -2;
+       }
+       if (!(vflags & HPTE_V_BOLTED))
+               DBG_LOW(" -> slot: %d\n", slot & 7);
 
        /* Because of iSeries, we have to pass down the secondary
         * bucket bit here as well
@@ -340,11 +358,9 @@ static long pSeries_lpar_hpte_remove(unsigned long hpte_group)
                /* don't remove a bolted entry */
                lpar_rc = plpar_pte_remove(H_ANDCOND, hpte_group + slot_offset,
                                           (0x1UL << 4), &dummy1, &dummy2);
-
-               if (lpar_rc == H_Success)
+               if (lpar_rc == H_SUCCESS)
                        return i;
-
-               BUG_ON(lpar_rc != H_Not_Found);
+               BUG_ON(lpar_rc != H_NOT_FOUND);
 
                slot_offset++;
                slot_offset &= 0x7;
@@ -371,22 +387,30 @@ static void pSeries_lpar_hptab_clear(void)
  * We can probably optimize here and assume the high bits of newpp are
  * already zero.  For now I am paranoid.
  */
-static long pSeries_lpar_hpte_updatepp(unsigned long slot, unsigned long newpp,
-                                      unsigned long va, int large, int local)
+static long pSeries_lpar_hpte_updatepp(unsigned long slot,
+                                      unsigned long newpp,
+                                      unsigned long va,
+                                      int psize, int local)
 {
        unsigned long lpar_rc;
        unsigned long flags = (newpp & 7) | H_AVPN;
-       unsigned long avpn = va >> 23;
+       unsigned long want_v;
 
-       if (large)
-               avpn &= ~0x1UL;
+       want_v = hpte_encode_v(va, psize);
 
-       lpar_rc = plpar_pte_protect(flags, slot, (avpn << 7));
+       DBG_LOW("    update: avpnv=%016lx, hash=%016lx, f=%x, psize: %d ... ",
+               want_v & HPTE_V_AVPN, slot, flags, psize);
 
-       if (lpar_rc == H_Not_Found)
+       lpar_rc = plpar_pte_protect(flags, slot, want_v & HPTE_V_AVPN);
+
+       if (lpar_rc == H_NOT_FOUND) {
+               DBG_LOW("not found !\n");
                return -1;
+       }
 
-       BUG_ON(lpar_rc != H_Success);
+       DBG_LOW("ok\n");
+
+       BUG_ON(lpar_rc != H_SUCCESS);
 
        return 0;
 }
@@ -405,26 +429,27 @@ static unsigned long pSeries_lpar_hpte_getword0(unsigned long slot)
 
        lpar_rc = plpar_pte_read(flags, slot, &dword0, &dummy_word1);
 
-       BUG_ON(lpar_rc != H_Success);
+       BUG_ON(lpar_rc != H_SUCCESS);
 
        return dword0;
 }
 
-static long pSeries_lpar_hpte_find(unsigned long vpn)
+static long pSeries_lpar_hpte_find(unsigned long va, int psize)
 {
        unsigned long hash;
        unsigned long i, j;
        long slot;
-       unsigned long hpte_v;
+       unsigned long want_v, hpte_v;
 
-       hash = hpt_hash(vpn, 0);
+       hash = hpt_hash(va, mmu_psize_defs[psize].shift);
+       want_v = hpte_encode_v(va, psize);
 
        for (j = 0; j < 2; j++) {
                slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
                for (i = 0; i < HPTES_PER_GROUP; i++) {
                        hpte_v = pSeries_lpar_hpte_getword0(slot);
 
-                       if ((HPTE_V_AVPN_VAL(hpte_v) == (vpn >> 11))
+                       if (HPTE_V_COMPARE(hpte_v, want_v)
                            && (hpte_v & HPTE_V_VALID)
                            && (!!(hpte_v & HPTE_V_SECONDARY) == j)) {
                                /* HPTE matches */
@@ -441,42 +466,40 @@ static long pSeries_lpar_hpte_find(unsigned long vpn)
 } 
 
 static void pSeries_lpar_hpte_updateboltedpp(unsigned long newpp,
-                                            unsigned long ea)
+                                            unsigned long ea,
+                                            int psize)
 {
-       unsigned long lpar_rc;
-       unsigned long vsid, va, vpn, flags;
-       long slot;
+       unsigned long lpar_rc, slot, vsid, va, flags;
 
        vsid = get_kernel_vsid(ea);
        va = (vsid << 28) | (ea & 0x0fffffff);
-       vpn = va >> PAGE_SHIFT;
 
-       slot = pSeries_lpar_hpte_find(vpn);
+       slot = pSeries_lpar_hpte_find(va, psize);
        BUG_ON(slot == -1);
 
        flags = newpp & 7;
        lpar_rc = plpar_pte_protect(flags, slot, 0);
 
-       BUG_ON(lpar_rc != H_Success);
+       BUG_ON(lpar_rc != H_SUCCESS);
 }
 
 static void pSeries_lpar_hpte_invalidate(unsigned long slot, unsigned long va,
-                                        int large, int local)
+                                        int psize, int local)
 {
-       unsigned long avpn = va >> 23;
+       unsigned long want_v;
        unsigned long lpar_rc;
        unsigned long dummy1, dummy2;
 
-       if (large)
-               avpn &= ~0x1UL;
-
-       lpar_rc = plpar_pte_remove(H_AVPN, slot, (avpn << 7), &dummy1,
-                                  &dummy2);
+       DBG_LOW("    inval : slot=%lx, va=%016lx, psize: %d, local: %d",
+               slot, va, psize, local);
 
-       if (lpar_rc == H_Not_Found)
+       want_v = hpte_encode_v(va, psize);
+       lpar_rc = plpar_pte_remove(H_AVPN, slot, want_v & HPTE_V_AVPN,
+                                  &dummy1, &dummy2);
+       if (lpar_rc == H_NOT_FOUND)
                return;
 
-       BUG_ON(lpar_rc != H_Success);
+       BUG_ON(lpar_rc != H_SUCCESS);
 }
 
 /*
@@ -494,13 +517,14 @@ void pSeries_lpar_flush_hash_range(unsigned long number, int local)
                spin_lock_irqsave(&pSeries_lpar_tlbie_lock, flags);
 
        for (i = 0; i < number; i++)
-               flush_hash_page(batch->vaddr[i], batch->pte[i], local);
+               flush_hash_page(batch->vaddr[i], batch->pte[i],
+                               batch->psize, local);
 
        if (lock_tlbie)
                spin_unlock_irqrestore(&pSeries_lpar_tlbie_lock, flags);
 }
 
-void hpte_init_lpar(void)
+void __init hpte_init_lpar(void)
 {
        ppc_md.hpte_invalidate  = pSeries_lpar_hpte_invalidate;
        ppc_md.hpte_updatepp    = pSeries_lpar_hpte_updatepp;
@@ -509,6 +533,4 @@ void hpte_init_lpar(void)
        ppc_md.hpte_remove      = pSeries_lpar_hpte_remove;
        ppc_md.flush_hash_range = pSeries_lpar_flush_hash_range;
        ppc_md.hpte_clear_all   = pSeries_lpar_hptab_clear;
-
-       htab_finish_init();
 }