include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / arch / powerpc / platforms / iseries / mf.c
index a41d8b7..d2c1d49 100644 (file)
 #include <linux/dma-mapping.h>
 #include <linux/bcd.h>
 #include <linux/rtc.h>
+#include <linux/slab.h>
 
 #include <asm/time.h>
 #include <asm/uaccess.h>
 #include <asm/paca.h>
 #include <asm/abs_addr.h>
-#include <asm/iseries/vio.h>
+#include <asm/firmware.h>
 #include <asm/iseries/mf.h>
 #include <asm/iseries/hv_lp_config.h>
+#include <asm/iseries/hv_lp_event.h>
 #include <asm/iseries/it_lp_queue.h>
 
 #include "setup.h"
 
-extern int piranha_simulator;
+static int mf_initialized;
 
 /*
  * This is the structure layout for the Machine Facilites LPAR event
@@ -143,7 +145,8 @@ static spinlock_t pending_event_spinlock;
 static struct pending_event *pending_event_head;
 static struct pending_event *pending_event_tail;
 static struct pending_event *pending_event_avail;
-static struct pending_event pending_event_prealloc[16];
+#define PENDING_EVENT_PREALLOC_LEN 16
+static struct pending_event pending_event_prealloc[PENDING_EVENT_PREALLOC_LEN];
 
 /*
  * Put a pending event onto the available queue, so it can get reused.
@@ -265,7 +268,8 @@ static struct pending_event *new_pending_event(void)
        return ev;
 }
 
-static int signal_vsp_instruction(struct vsp_cmd_data *vsp_cmd)
+static int __maybe_unused
+signal_vsp_instruction(struct vsp_cmd_data *vsp_cmd)
 {
        struct pending_event *ev = new_pending_event();
        int rc;
@@ -356,7 +360,7 @@ static int dma_and_signal_ce_msg(char *ce_msg,
  */
 static int shutdown(void)
 {
-       int rc = kill_proc(1, SIGINT, 1);
+       int rc = kill_cad_pid(SIGINT, 1);
 
        if (rc) {
                printk(KERN_ALERT "mf.c: SIGINT to init failed (%d), "
@@ -512,7 +516,7 @@ static void handle_ack(struct io_mf_lp_event *event)
  * parse it enough to know if it is an interrupt or an
  * acknowledge.
  */
-static void hv_handler(struct HvLpEvent *event, struct pt_regs *regs)
+static void hv_handler(struct HvLpEvent *event)
 {
        if ((event != NULL) && (event->xType == HvLpEvent_Type_MachineFac)) {
                if (hvlpevent_is_ack(event))
@@ -597,7 +601,7 @@ void mf_power_off(void)
  * Global kernel interface to tell the VSP object in the primary
  * partition to reboot this partition.
  */
-void mf_reboot(void)
+void mf_reboot(char *cmd)
 {
        printk(KERN_INFO "mf.c: Preparing to bounce...\n");
        signal_ce_msg_simple(0x4e, NULL);
@@ -625,7 +629,7 @@ void mf_display_src(u32 word)
 /*
  * Display a single word SRC of the form "PROGXXXX" on the VSP control panel.
  */
-void mf_display_progress(u16 value)
+static __init void mf_display_progress_src(u16 value)
 {
        u8 ce[12];
        u8 src[72];
@@ -649,30 +653,42 @@ void mf_display_progress(u16 value)
  * Clear the VSP control panel.  Used to "erase" an SRC that was
  * previously displayed.
  */
-void mf_clear_src(void)
+static void mf_clear_src(void)
 {
        signal_ce_msg_simple(0x4b, NULL);
 }
 
+void __init mf_display_progress(u16 value)
+{
+       if (!mf_initialized)
+               return;
+
+       if (0xFFFF == value)
+               mf_clear_src();
+       else
+               mf_display_progress_src(value);
+}
+
 /*
  * Initialization code here.
  */
-void mf_init(void)
+void __init mf_init(void)
 {
        int i;
 
-       /* initialize */
        spin_lock_init(&pending_event_spinlock);
-       for (i = 0;
-            i < sizeof(pending_event_prealloc) / sizeof(*pending_event_prealloc);
-            ++i)
+
+       for (i = 0; i < PENDING_EVENT_PREALLOC_LEN; i++)
                free_pending_event(&pending_event_prealloc[i]);
+
        HvLpEvent_registerHandler(HvLpEvent_Type_MachineFac, &hv_handler);
 
        /* virtual continue ack */
        signal_ce_msg_simple(0x57, NULL);
 
-       /* initialization complete */
+       mf_initialized = 1;
+       mb();
+
        printk(KERN_NOTICE "mf.c: iSeries Linux LPAR Machine Facilities "
                        "initialized\n");
 }
@@ -692,6 +708,43 @@ static void get_rtc_time_complete(void *token, struct ce_msg_data *ce_msg)
        complete(&rtc->com);
 }
 
+static int mf_set_rtc(struct rtc_time *tm)
+{
+       char ce_time[12];
+       u8 day, mon, hour, min, sec, y1, y2;
+       unsigned year;
+
+       year = 1900 + tm->tm_year;
+       y1 = year / 100;
+       y2 = year % 100;
+
+       sec = tm->tm_sec;
+       min = tm->tm_min;
+       hour = tm->tm_hour;
+       day = tm->tm_mday;
+       mon = tm->tm_mon + 1;
+
+       sec = bin2bcd(sec);
+       min = bin2bcd(min);
+       hour = bin2bcd(hour);
+       mon = bin2bcd(mon);
+       day = bin2bcd(day);
+       y1 = bin2bcd(y1);
+       y2 = bin2bcd(y2);
+
+       memset(ce_time, 0, sizeof(ce_time));
+       ce_time[3] = 0x41;
+       ce_time[4] = y1;
+       ce_time[5] = y2;
+       ce_time[6] = sec;
+       ce_time[7] = min;
+       ce_time[8] = hour;
+       ce_time[10] = day;
+       ce_time[11] = mon;
+
+       return signal_ce_msg(ce_time, NULL);
+}
+
 static int rtc_set_tm(int rc, u8 *ce_msg, struct rtc_time *tm)
 {
        tm->tm_wday = 0;
@@ -726,12 +779,12 @@ static int rtc_set_tm(int rc, u8 *ce_msg, struct rtc_time *tm)
                u8 day = ce_msg[10];
                u8 mon = ce_msg[11];
 
-               BCD_TO_BIN(sec);
-               BCD_TO_BIN(min);
-               BCD_TO_BIN(hour);
-               BCD_TO_BIN(day);
-               BCD_TO_BIN(mon);
-               BCD_TO_BIN(year);
+               sec = bcd2bin(sec);
+               min = bcd2bin(min);
+               hour = bcd2bin(hour);
+               day = bcd2bin(day);
+               mon = bcd2bin(mon);
+               year = bcd2bin(year);
 
                if (year <= 69)
                        year += 100;
@@ -747,7 +800,7 @@ static int rtc_set_tm(int rc, u8 *ce_msg, struct rtc_time *tm)
        return 0;
 }
 
-int mf_get_rtc(struct rtc_time *tm)
+static int mf_get_rtc(struct rtc_time *tm)
 {
        struct ce_msg_comp_data ce_complete;
        struct rtc_time_data rtc_data;
@@ -780,7 +833,7 @@ static void get_boot_rtc_time_complete(void *token, struct ce_msg_data *ce_msg)
        rtc->busy = 0;
 }
 
-int mf_get_boot_rtc(struct rtc_time *tm)
+static int mf_get_boot_rtc(struct rtc_time *tm)
 {
        struct ce_msg_comp_data ce_complete;
        struct boot_rtc_time_data rtc_data;
@@ -797,104 +850,64 @@ int mf_get_boot_rtc(struct rtc_time *tm)
        /* We need to poll here as we are not yet taking interrupts */
        while (rtc_data.busy) {
                if (hvlpevent_is_pending())
-                       process_hvlpevents(NULL);
+                       process_hvlpevents();
        }
        return rtc_set_tm(rtc_data.rc, rtc_data.ce_msg.ce_msg, tm);
 }
 
-int mf_set_rtc(struct rtc_time *tm)
-{
-       char ce_time[12];
-       u8 day, mon, hour, min, sec, y1, y2;
-       unsigned year;
-
-       year = 1900 + tm->tm_year;
-       y1 = year / 100;
-       y2 = year % 100;
-
-       sec = tm->tm_sec;
-       min = tm->tm_min;
-       hour = tm->tm_hour;
-       day = tm->tm_mday;
-       mon = tm->tm_mon + 1;
-
-       BIN_TO_BCD(sec);
-       BIN_TO_BCD(min);
-       BIN_TO_BCD(hour);
-       BIN_TO_BCD(mon);
-       BIN_TO_BCD(day);
-       BIN_TO_BCD(y1);
-       BIN_TO_BCD(y2);
-
-       memset(ce_time, 0, sizeof(ce_time));
-       ce_time[3] = 0x41;
-       ce_time[4] = y1;
-       ce_time[5] = y2;
-       ce_time[6] = sec;
-       ce_time[7] = min;
-       ce_time[8] = hour;
-       ce_time[10] = day;
-       ce_time[11] = mon;
-
-       return signal_ce_msg(ce_time, NULL);
-}
-
 #ifdef CONFIG_PROC_FS
-
-static int proc_mf_dump_cmdline(char *page, char **start, off_t off,
-               int count, int *eof, void *data)
+static int mf_cmdline_proc_show(struct seq_file *m, void *v)
 {
-       int len;
-       char *p;
+       char *page, *p;
        struct vsp_cmd_data vsp_cmd;
        int rc;
        dma_addr_t dma_addr;
 
        /* The HV appears to return no more than 256 bytes of command line */
-       if (off >= 256)
-               return 0;
-       if ((off + count) > 256)
-               count = 256 - off;
+       page = kmalloc(256, GFP_KERNEL);
+       if (!page)
+               return -ENOMEM;
 
-       dma_addr = dma_map_single(iSeries_vio_dev, page, off + count,
-                       DMA_FROM_DEVICE);
-       if (dma_mapping_error(dma_addr))
+       dma_addr = iseries_hv_map(page, 256, DMA_FROM_DEVICE);
+       if (dma_addr == DMA_ERROR_CODE) {
+               kfree(page);
                return -ENOMEM;
-       memset(page, 0, off + count);
+       }
+       memset(page, 0, 256);
        memset(&vsp_cmd, 0, sizeof(vsp_cmd));
        vsp_cmd.cmd = 33;
        vsp_cmd.sub_data.kern.token = dma_addr;
        vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
-       vsp_cmd.sub_data.kern.side = (u64)data;
-       vsp_cmd.sub_data.kern.length = off + count;
+       vsp_cmd.sub_data.kern.side = (u64)m->private;
+       vsp_cmd.sub_data.kern.length = 256;
        mb();
        rc = signal_vsp_instruction(&vsp_cmd);
-       dma_unmap_single(iSeries_vio_dev, dma_addr, off + count,
-                       DMA_FROM_DEVICE);
-       if (rc)
+       iseries_hv_unmap(dma_addr, 256, DMA_FROM_DEVICE);
+       if (rc) {
+               kfree(page);
                return rc;
-       if (vsp_cmd.result_code != 0)
+       }
+       if (vsp_cmd.result_code != 0) {
+               kfree(page);
                return -ENOMEM;
+       }
        p = page;
-       len = 0;
-       while (len < (off + count)) {
-               if ((*p == '\0') || (*p == '\n')) {
-                       if (*p == '\0')
-                               *p = '\n';
-                       p++;
-                       len++;
-                       *eof = 1;
+       while (p - page < 256) {
+               if (*p == '\0' || *p == '\n') {
+                       *p = '\n';
                        break;
                }
                p++;
-               len++;
-       }
 
-       if (len < off) {
-               *eof = 1;
-               len = 0;
        }
-       return len;
+       seq_write(m, page, p - page);
+       kfree(page);
+       return 0;
+}
+
+static int mf_cmdline_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, mf_cmdline_proc_show, PDE(inode)->data);
 }
 
 #if 0
@@ -905,8 +918,7 @@ static int mf_getVmlinuxChunk(char *buffer, int *size, int offset, u64 side)
        int len = *size;
        dma_addr_t dma_addr;
 
-       dma_addr = dma_map_single(iSeries_vio_dev, buffer, len,
-                       DMA_FROM_DEVICE);
+       dma_addr = iseries_hv_map(buffer, len, DMA_FROM_DEVICE);
        memset(buffer, 0, len);
        memset(&vsp_cmd, 0, sizeof(vsp_cmd));
        vsp_cmd.cmd = 32;
@@ -924,7 +936,7 @@ static int mf_getVmlinuxChunk(char *buffer, int *size, int offset, u64 side)
                        rc = -ENOMEM;
        }
 
-       dma_unmap_single(iSeries_vio_dev, dma_addr, len, DMA_FROM_DEVICE);
+       iseries_hv_unmap(dma_addr, len, DMA_FROM_DEVICE);
 
        return rc;
 }
@@ -950,10 +962,8 @@ static int proc_mf_dump_vmlinux(char *page, char **start, off_t off,
 }
 #endif
 
-static int proc_mf_dump_side(char *page, char **start, off_t off,
-               int count, int *eof, void *data)
+static int mf_side_proc_show(struct seq_file *m, void *v)
 {
-       int len;
        char mf_current_side = ' ';
        struct vsp_cmd_data vsp_cmd;
 
@@ -977,21 +987,17 @@ static int proc_mf_dump_side(char *page, char **start, off_t off,
                }
        }
 
-       len = sprintf(page, "%c\n", mf_current_side);
+       seq_printf(m, "%c\n", mf_current_side);
+       return 0;
+}
 
-       if (len <= (off + count))
-               *eof = 1;
-       *start = page + off;
-       len -= off;
-       if (len > count)
-               len = count;
-       if (len < 0)
-               len = 0;
-       return len;
+static int mf_side_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, mf_side_proc_show, NULL);
 }
 
-static int proc_mf_change_side(struct file *file, const char __user *buffer,
-               unsigned long count, void *data)
+static ssize_t mf_side_proc_write(struct file *file, const char __user *buffer,
+                                 size_t count, loff_t *pos)
 {
        char side;
        u64 newSide;
@@ -1029,6 +1035,15 @@ static int proc_mf_change_side(struct file *file, const char __user *buffer,
        return count;
 }
 
+static const struct file_operations mf_side_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = mf_side_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+       .write          = mf_side_proc_write,
+};
+
 #if 0
 static void mf_getSrcHistory(char *buffer, int size)
 {
@@ -1075,8 +1090,7 @@ static void mf_getSrcHistory(char *buffer, int size)
 }
 #endif
 
-static int proc_mf_dump_src(char *page, char **start, off_t off,
-               int count, int *eof, void *data)
+static int mf_src_proc_show(struct seq_file *m, void *v)
 {
 #if 0
        int len;
@@ -1097,8 +1111,13 @@ static int proc_mf_dump_src(char *page, char **start, off_t off,
 #endif
 }
 
-static int proc_mf_change_src(struct file *file, const char __user *buffer,
-               unsigned long count, void *data)
+static int mf_src_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, mf_src_proc_show, NULL);
+}
+
+static ssize_t mf_src_proc_write(struct file *file, const char __user *buffer,
+                                size_t count, loff_t *pos)
 {
        char stkbuf[10];
 
@@ -1123,9 +1142,19 @@ static int proc_mf_change_src(struct file *file, const char __user *buffer,
        return count;
 }
 
-static int proc_mf_change_cmdline(struct file *file, const char __user *buffer,
-               unsigned long count, void *data)
+static const struct file_operations mf_src_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = mf_src_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+       .write          = mf_src_proc_write,
+};
+
+static ssize_t mf_cmdline_proc_write(struct file *file, const char __user *buffer,
+                                    size_t count, loff_t *pos)
 {
+       void *data = PDE(file->f_path.dentry->d_inode)->data;
        struct vsp_cmd_data vsp_cmd;
        dma_addr_t dma_addr;
        char *page;
@@ -1135,8 +1164,7 @@ static int proc_mf_change_cmdline(struct file *file, const char __user *buffer,
                goto out;
 
        dma_addr = 0;
-       page = dma_alloc_coherent(iSeries_vio_dev, count, &dma_addr,
-                       GFP_ATOMIC);
+       page = iseries_hv_alloc(count, &dma_addr, GFP_ATOMIC);
        ret = -ENOMEM;
        if (page == NULL)
                goto out;
@@ -1156,16 +1184,25 @@ static int proc_mf_change_cmdline(struct file *file, const char __user *buffer,
        ret = count;
 
 out_free:
-       dma_free_coherent(iSeries_vio_dev, count, page, dma_addr);
+       iseries_hv_free(count, page, dma_addr);
 out:
        return ret;
 }
 
+static const struct file_operations mf_cmdline_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = mf_cmdline_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+       .write          = mf_cmdline_proc_write,
+};
+
 static ssize_t proc_mf_change_vmlinux(struct file *file,
                                      const char __user *buf,
                                      size_t count, loff_t *ppos)
 {
-       struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
+       struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
        ssize_t rc;
        dma_addr_t dma_addr;
        char *page;
@@ -1176,8 +1213,7 @@ static ssize_t proc_mf_change_vmlinux(struct file *file,
                goto out;
 
        dma_addr = 0;
-       page = dma_alloc_coherent(iSeries_vio_dev, count, &dma_addr,
-                       GFP_ATOMIC);
+       page = iseries_hv_alloc(count, &dma_addr, GFP_ATOMIC);
        rc = -ENOMEM;
        if (page == NULL) {
                printk(KERN_ERR "mf.c: couldn't allocate memory to set vmlinux chunk\n");
@@ -1205,12 +1241,12 @@ static ssize_t proc_mf_change_vmlinux(struct file *file,
        *ppos += count;
        rc = count;
 out_free:
-       dma_free_coherent(iSeries_vio_dev, count, page, dma_addr);
+       iseries_hv_free(count, page, dma_addr);
 out:
        return rc;
 }
 
-static struct file_operations proc_vmlinux_operations = {
+static const struct file_operations proc_vmlinux_operations = {
        .write          = proc_mf_change_vmlinux,
 };
 
@@ -1222,6 +1258,9 @@ static int __init mf_proc_init(void)
        char name[2];
        int i;
 
+       if (!firmware_has_feature(FW_FEATURE_ISERIES))
+               return 0;
+
        mf_proc_root = proc_mkdir("iSeries/mf", NULL);
        if (!mf_proc_root)
                return 1;
@@ -1233,40 +1272,30 @@ static int __init mf_proc_init(void)
                if (!mf)
                        return 1;
 
-               ent = create_proc_entry("cmdline", S_IFREG|S_IRUSR|S_IWUSR, mf);
+               ent = proc_create_data("cmdline", S_IRUSR|S_IWUSR, mf,
+                                      &mf_cmdline_proc_fops, (void *)(long)i);
                if (!ent)
                        return 1;
-               ent->nlink = 1;
-               ent->data = (void *)(long)i;
-               ent->read_proc = proc_mf_dump_cmdline;
-               ent->write_proc = proc_mf_change_cmdline;
 
                if (i == 3)     /* no vmlinux entry for 'D' */
                        continue;
 
-               ent = create_proc_entry("vmlinux", S_IFREG|S_IWUSR, mf);
+               ent = proc_create_data("vmlinux", S_IFREG|S_IWUSR, mf,
+                                      &proc_vmlinux_operations,
+                                      (void *)(long)i);
                if (!ent)
                        return 1;
-               ent->nlink = 1;
-               ent->data = (void *)(long)i;
-               ent->proc_fops = &proc_vmlinux_operations;
        }
 
-       ent = create_proc_entry("side", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
+       ent = proc_create("side", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root,
+                         &mf_side_proc_fops);
        if (!ent)
                return 1;
-       ent->nlink = 1;
-       ent->data = (void *)0;
-       ent->read_proc = proc_mf_dump_side;
-       ent->write_proc = proc_mf_change_side;
 
-       ent = create_proc_entry("src", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
+       ent = proc_create("src", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root,
+                         &mf_src_proc_fops);
        if (!ent)
                return 1;
-       ent->nlink = 1;
-       ent->data = (void *)0;
-       ent->read_proc = proc_mf_dump_src;
-       ent->write_proc = proc_mf_change_src;
 
        return 0;
 }
@@ -1281,9 +1310,6 @@ __initcall(mf_proc_init);
  */
 void iSeries_get_rtc_time(struct rtc_time *rtc_tm)
 {
-       if (piranha_simulator)
-               return;
-
        mf_get_rtc(rtc_tm);
        rtc_tm->tm_mon--;
 }
@@ -1302,9 +1328,6 @@ unsigned long iSeries_get_boot_time(void)
 {
        struct rtc_time tm;
 
-       if (piranha_simulator)
-               return 0;
-
        mf_get_boot_rtc(&tm);
        return mktime(tm.tm_year + 1900, tm.tm_mon, tm.tm_mday,
                      tm.tm_hour, tm.tm_min, tm.tm_sec);