[IA64] - Disable tiocx driver on non-SN systems
[linux-2.6.git] / arch / ia64 / sn / kernel / tiocx.c
index 66190d7..c1cbcd1 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/proc_fs.h>
 #include <linux/device.h>
 #include <linux/delay.h>
+#include <asm/system.h>
 #include <asm/uaccess.h>
 #include <asm/sn/sn_sal.h>
 #include <asm/sn/addrs.h>
@@ -21,6 +22,8 @@
 #include <asm/sn/types.h>
 #include <asm/sn/shubio.h>
 #include <asm/sn/tiocx.h>
+#include <asm/sn/l1.h>
+#include <asm/sn/module.h>
 #include "tio.h"
 #include "xtalk/xwidgetdev.h"
 #include "xtalk/hubdev.h"
@@ -202,8 +205,8 @@ cx_device_register(nasid_t nasid, int part_num, int mfg_num,
        cx_dev->dev.parent = NULL;
        cx_dev->dev.bus = &tiocx_bus_type;
        cx_dev->dev.release = tiocx_bus_release;
-       snprintf(cx_dev->dev.bus_id, BUS_ID_SIZE, "%d.0x%x",
-                cx_dev->cx_id.nasid, cx_dev->cx_id.part_num);
+       snprintf(cx_dev->dev.bus_id, BUS_ID_SIZE, "%d",
+                cx_dev->cx_id.nasid);
        device_register(&cx_dev->dev);
        get_device(&cx_dev->dev);
 
@@ -234,7 +237,6 @@ int cx_device_unregister(struct cx_dev *cx_dev)
  */
 static int cx_device_reload(struct cx_dev *cx_dev)
 {
-       device_remove_file(&cx_dev->dev, &dev_attr_cxdev_control);
        cx_device_unregister(cx_dev);
        return cx_device_register(cx_dev->cx_id.nasid, cx_dev->cx_id.part_num,
                                  cx_dev->cx_id.mfg_num, cx_dev->hubdev);
@@ -308,14 +310,12 @@ void tiocx_irq_free(struct sn_irq_info *sn_irq_info)
        }
 }
 
-uint64_t
-tiocx_dma_addr(uint64_t addr)
+uint64_t tiocx_dma_addr(uint64_t addr)
 {
        return PHYS_TO_TIODMA(addr);
 }
 
-uint64_t
-tiocx_swin_base(int nasid)
+uint64_t tiocx_swin_base(int nasid)
 {
        return TIO_SWIN_BASE(nasid, TIOCX_CORELET);
 }
@@ -330,19 +330,6 @@ EXPORT_SYMBOL(tiocx_bus_type);
 EXPORT_SYMBOL(tiocx_dma_addr);
 EXPORT_SYMBOL(tiocx_swin_base);
 
-static uint64_t tiocx_get_hubdev_info(u64 handle, u64 address)
-{
-
-       struct ia64_sal_retval ret_stuff;
-       ret_stuff.status = 0;
-       ret_stuff.v0 = 0;
-
-       ia64_sal_oemcall_nolock(&ret_stuff,
-                               SN_SAL_IOIF_GET_HUBDEV_INFO,
-                               handle, address, 0, 0, 0, 0, 0);
-       return ret_stuff.v0;
-}
-
 static void tio_conveyor_set(nasid_t nasid, int enable_flag)
 {
        uint64_t ice_frz;
@@ -379,7 +366,30 @@ static void tio_corelet_reset(nasid_t nasid, int corelet)
        udelay(2000);
 }
 
-static int fpga_attached(nasid_t nasid)
+static int tiocx_btchar_get(int nasid)
+{
+       moduleid_t module_id;
+       geoid_t geoid;
+       int cnodeid;
+
+       cnodeid = nasid_to_cnodeid(nasid);
+       geoid = cnodeid_get_geoid(cnodeid);
+       module_id = geo_module(geoid);
+       return MODULE_GET_BTCHAR(module_id);
+}
+
+static int is_fpga_brick(int nasid)
+{
+       switch (tiocx_btchar_get(nasid)) {
+       case L1_BRICKTYPE_SA:
+       case L1_BRICKTYPE_ATHENA:
+       case L1_BRICKTYPE_DAYTONA:
+               return 1;
+       }
+       return 0;
+}
+
+static int bitstream_loaded(nasid_t nasid)
 {
        uint64_t cx_credits;
 
@@ -396,11 +406,11 @@ static int tiocx_reload(struct cx_dev *cx_dev)
        int mfg_num = CX_DEV_NONE;
        nasid_t nasid = cx_dev->cx_id.nasid;
 
-       if (fpga_attached(nasid)) {
+       if (bitstream_loaded(nasid)) {
                uint64_t cx_id;
 
                cx_id =
-                   *(volatile int32_t *)(TIO_SWIN_BASE(nasid, TIOCX_CORELET) +
+                   *(volatile uint64_t *)(TIO_SWIN_BASE(nasid, TIOCX_CORELET) +
                                          WIDGET_ID);
                part_num = XWIDGET_PART_NUM(cx_id);
                mfg_num = XWIDGET_MFG_NUM(cx_id);
@@ -423,16 +433,17 @@ static int tiocx_reload(struct cx_dev *cx_dev)
        return cx_device_reload(cx_dev);
 }
 
-static ssize_t show_cxdev_control(struct device *dev, char *buf)
+static ssize_t show_cxdev_control(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct cx_dev *cx_dev = to_cx_dev(dev);
 
-       return sprintf(buf, "0x%x 0x%x 0x%x\n",
+       return sprintf(buf, "0x%x 0x%x 0x%x %d\n",
                       cx_dev->cx_id.nasid,
-                      cx_dev->cx_id.part_num, cx_dev->cx_id.mfg_num);
+                      cx_dev->cx_id.part_num, cx_dev->cx_id.mfg_num,
+                      tiocx_btchar_get(cx_dev->cx_id.nasid));
 }
 
-static ssize_t store_cxdev_control(struct device *dev, const char *buf,
+static ssize_t store_cxdev_control(struct device *dev, struct device_attribute *attr, const char *buf,
                                   size_t count)
 {
        int n;
@@ -448,6 +459,10 @@ static ssize_t store_cxdev_control(struct device *dev, const char *buf,
 
        switch (n) {
        case 1:
+               tio_corelet_reset(cx_dev->cx_id.nasid, TIOCX_CORELET);
+               tiocx_reload(cx_dev);
+               break;
+       case 2:
                tiocx_reload(cx_dev);
                break;
        case 3:
@@ -467,6 +482,9 @@ static int __init tiocx_init(void)
        cnodeid_t cnodeid;
        int found_tiocx_device = 0;
 
+       if (!ia64_platform_is("sn2"))
+               return -ENODEV;
+
        bus_register(&tiocx_bus_type);
 
        for (cnodeid = 0; cnodeid < MAX_COMPACT_NODES; cnodeid++) {
@@ -475,20 +493,14 @@ static int __init tiocx_init(void)
                if ((nasid = cnodeid_to_nasid(cnodeid)) < 0)
                        break;  /* No more nasids .. bail out of loop */
 
-               if (nasid & 0x1) {      /* TIO's are always odd */
+               if ((nasid & 0x1) && is_fpga_brick(nasid)) {
                        struct hubdev_info *hubdev;
-                       uint64_t status;
                        struct xwidget_info *widgetp;
 
                        DBG("Found TIO at nasid 0x%x\n", nasid);
 
                        hubdev =
                            (struct hubdev_info *)(NODEPDA(cnodeid)->pdinfo);
-                       status =
-                           tiocx_get_hubdev_info(nasid,
-                                                 (uint64_t) __pa(hubdev));
-                       if (status)
-                               continue;
 
                        widgetp = &hubdev->hdi_xwidget_info[TIOCX_CORELET];
 
@@ -514,29 +526,26 @@ static int __init tiocx_init(void)
        return 0;
 }
 
-static void __exit tiocx_exit(void)
+static int cx_remove_device(struct device * dev, void * data)
 {
-       struct device *dev;
-       struct device *tdev;
+       struct cx_dev *cx_dev = to_cx_dev(dev);
+       device_remove_file(dev, &dev_attr_cxdev_control);
+       cx_device_unregister(cx_dev);
+       return 0;
+}
 
+static void __exit tiocx_exit(void)
+{
        DBG("tiocx_exit\n");
 
        /*
         * Unregister devices.
         */
-       list_for_each_entry_safe(dev, tdev, &tiocx_bus_type.devices.list,
-                                bus_list) {
-               if (dev) {
-                       struct cx_dev *cx_dev = to_cx_dev(dev);
-                       device_remove_file(dev, &dev_attr_cxdev_control);
-                       cx_device_unregister(cx_dev);
-               }
-       }
-
+       bus_for_each_dev(&tiocx_bus_type, NULL, NULL, cx_remove_device);
        bus_unregister(&tiocx_bus_type);
 }
 
-module_init(tiocx_init);
+subsys_initcall(tiocx_init);
 module_exit(tiocx_exit);
 
 /************************************************************************