gator: ARM DS-5.6 Streamline gator driver
[android-sdk/arm-ds5-gator.git] / gator_events_armv6.c
index a916d836a44d0eff6da1363f4c0beaba7195393d..7b1d875084f744fb8ed72f034e4c412969556fd9 100644 (file)
@@ -1,29 +1,19 @@
 /**
- * Copyright (C) ARM Limited 2010. All rights reserved.
+ * Copyright (C) ARM Limited 2010-2011. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
 
-#include <linux/types.h>
-#include <linux/sched.h>
-#include <linux/interrupt.h>
-#include <linux/irq.h>
-#include <linux/fs.h>
-
 #include "gator.h"
 
-#if defined(__arm__)
-
 #define ARM1136                0xb36
 #define ARM1156                0xb56
 #define ARM1176                0xb76
 
 static const char *pmnc_name;
 
-extern u32 gator_cpuid(void);
-
 /*
  * Per-CPU PMCR
  */
@@ -105,29 +95,13 @@ int gator_events_armv6_create_files(struct super_block *sb, struct dentry *root)
        return 0;
 }
 
-static int gator_events_armv6_init(int *key)
-{
-       unsigned int cnt;
-
-       for (cnt = PMN0; cnt <= CCNT; cnt++) {
-               pmnc_enabled[cnt] = 0;
-               pmnc_event[cnt] = 0;
-               pmnc_key[cnt] = *key;
-               *key = *key + 1;
-       }
-
-       return 0;
-}
-
-static void __gator_events_armv6_start(void* unused)
+static void gator_events_armv6_online(void)
 {
        unsigned int cnt;
        u32 pmnc;
 
        if (armv6_pmnc_read() & PMCR_E) {
-               pr_err("gator: CPU%u PMNC still enabled when setup new event counter.\n", smp_processor_id());
-               pmnc_count = 0;
-               return;
+               armv6_pmnc_write(armv6_pmnc_read() & ~PMCR_E);
        }
 
        /* initialize PMNC, reset overflow, D bit, C bit and P bit. */
@@ -138,7 +112,7 @@ static void __gator_events_armv6_start(void* unused)
        for (pmnc = 0, cnt = PMN0; cnt <= CCNT; cnt++) {
                unsigned long event;
 
-               per_cpu(perfPrev, raw_smp_processor_id())[cnt] = 0;
+               per_cpu(perfPrev, smp_processor_id())[cnt] = 0;
 
                if (!pmnc_enabled[cnt])
                        continue;
@@ -162,40 +136,30 @@ static void __gator_events_armv6_start(void* unused)
        armv6_pmnc_write(pmnc | PMCR_E);
 }
 
-static int gator_events_armv6_start(void)
-{
-       if (!pmnc_count)
-               return 0;
-       return on_each_cpu(__gator_events_armv6_start, NULL, 1);
-}
-
-static void __gator_events_armv6_stop(void* unused)
+static void gator_events_armv6_offline(void)
 {
        unsigned int cnt;
 
        armv6_pmnc_write(armv6_pmnc_read() & ~PMCR_E);
-
        for (cnt = PMN0; cnt <= CCNT; cnt++) {
                armv6_pmnc_reset_counter(cnt);
-               pmnc_enabled[cnt] = 0;
-               pmnc_event[cnt] = 0;
        }
 }
 
 static void gator_events_armv6_stop(void)
 {
-       if (!pmnc_count)
-               return;
-       on_each_cpu(__gator_events_armv6_stop, NULL, 1);
+       unsigned int cnt;
+
+       for (cnt = PMN0; cnt <= CCNT; cnt++) {
+               pmnc_enabled[cnt] = 0;
+               pmnc_event[cnt] = 0;
+       }
 }
 
 static int gator_events_armv6_read(int **buffer)
 {
        int cnt, len = 0;
-       int cpu = raw_smp_processor_id();
-
-       if (!pmnc_count)
-               return 0;
+       int cpu = smp_processor_id();
 
        for (cnt = PMN0; cnt <= CCNT; cnt++) {
                if (pmnc_enabled[cnt]) {
@@ -226,10 +190,19 @@ static int gator_events_armv6_read(int **buffer)
 
        return len;
 }
-#endif
 
-int gator_events_armv6_install(gator_interface *gi) {
-#if defined(__arm__)
+static struct gator_interface gator_events_armv6_interface = {
+       .create_files = gator_events_armv6_create_files,
+       .stop = gator_events_armv6_stop,
+       .online = gator_events_armv6_online,
+       .offline = gator_events_armv6_offline,
+       .read = gator_events_armv6_read,
+};
+
+int gator_events_armv6_init(void)
+{
+       unsigned int cnt;
+
        switch (gator_cpuid()) {
        case ARM1136:
        case ARM1156:
@@ -240,11 +213,12 @@ int gator_events_armv6_install(gator_interface *gi) {
                return -1;
        }
 
-       gi->create_files = gator_events_armv6_create_files;
-       gi->init = gator_events_armv6_init;
-       gi->start = gator_events_armv6_start;
-       gi->stop = gator_events_armv6_stop;
-       gi->read = gator_events_armv6_read;
-#endif
-       return 0;
+       for (cnt = PMN0; cnt <= CCNT; cnt++) {
+               pmnc_enabled[cnt] = 0;
+               pmnc_event[cnt] = 0;
+               pmnc_key[cnt] = gator_events_get_key();
+       }
+
+       return gator_events_install(&gator_events_armv6_interface);
 }
+gator_events_init(gator_events_armv6_init);