(added second paragraph to the last mail)

The perfmon_cell_signals.c is added. This file contains
pfm_cell_reset_signals(), pfm_cell_activate_signals() and
the pfm_cell_pmc_check(). 
(Only PPE signal group are included this time).

The bug fix of the pfm_cell_pmc_check() and the modification
for linux-2.6.22 are included in this patch. 

Signed-off-by: Takaki Azuma <[EMAIL PROTECTED]>
Signed-off-by: Takayuki Uchikawa <[EMAIL PROTECTED]>

Index: linux-2.6.22/arch/powerpc/perfmon/perfmon_cell_signals.c
===================================================================
--- linux-2.6.22-base/arch/powerpc/perfmon/perfmon_cell_signals.c
+++ linux-2.6.22/arch/powerpc/perfmon/perfmon_cell_signals.c
@@ -0,0 +1,279 @@
+/*
+ * This file contains the Cell Performance Monitor Signal setting
+ * used by perfmon_cell.c without RTAS.
+ *
+ * (C) Copyright 2007 TOSHIBA CORPORATION
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ * 02111-1307 USA
+ */
+#ifndef __PERFMON_CELL_SIGNALS_C__
+#define __PERFMON_CELL_SIGNALS_C__
+
+#include <linux/module.h>
+#include <linux/perfmon.h>
+#include <asm/cell-pmu.h>
+#include <asm/io.h>
+#include <asm/spu.h>
+#include <asm/machdep.h>
+#include "../platforms/cell/cbe_regs.h"
+
+struct cell_rtas_arg {
+       u16 cpu;
+       u16 sub_unit;
+       s16 signal_group;
+       u8 bus_word;
+       u8 bit;
+};
+
+#define GET_BUS_WORD(x)                (((x) >> 48) & 0x0ff)
+#define GET_SIGNAL_NUMBER(x)   (((x) & 0x0ffff) / 100)
+
+
+enum {
+       BUS_WORD_0 = 1,
+       BUS_WORD_1 = 2,
+       BUS_WORD_2 = 4,
+       BUS_WORD_3 = 8,
+};
+
+enum {
+       SIG_GROUP_NONE = 0,
+
+       /* 2. PowerPC Processor Unit (PPU) Signal Selection */
+       SIG_GROUP_PPU_IU1 = 21,
+       SIG_GROUP_PPU_XU = 23,
+};
+
+
+#define rmw_spr(spr_id, a_mask, o_mask) \
+       do { \
+               u64 tmp; \
+               read_spr(spr_id, tmp); \
+               tmp &= (u64)(a_mask); \
+               tmp |= (u64)(o_mask); \
+               __asm__ __volatile__("mtspr %1,%0;sync"::"r"(tmp),"i"(spr_id)); 
\
+       } while (0)
+
+#define read_spr(spr_id, tmp) \
+       do { \
+               __asm__ __volatile__("mfspr %0,%1": "=r"(tmp):"i"(spr_id)); \
+       } while (0)
+
+#define rmwb_mmio_reg64(mem, bitN, bit) \
+       rmw_mmio_reg64(mem, ~((bit) << (63 - (bitN))), ((bit) << (63 - (bitN))))
+
+#define        rmw_mmio_reg64(mem, a_mask, o_mask) \
+       do { \
+               u64 tmp; \
+               tmp = in_be64(&mem); \
+               tmp &= ((u64)(a_mask)); \
+               tmp |= ((u64)(o_mask)); \
+               out_be64(&mem, tmp); \
+       } while (0)
+
+
+#define passthrough_enable(cpu)                passthrough(cpu, 1ul)
+#define passthrough_disable(cpu)       passthrough(cpu, 0ul)
+
+
+static inline int passthrough(u32 cpu, u64 bit)
+{
+       int err = 0;
+       struct cbe_ppe_priv_regs __iomem * ppe_priv_regs;
+       struct cbe_pmd_regs __iomem * pmd_regs;
+       struct cbe_mic_tm_regs __iomem * mic_tm_regs;
+
+       ppe_priv_regs = cbe_get_cpu_ppe_priv_regs(cpu);
+       pmd_regs = cbe_get_cpu_pmd_regs(cpu);
+       mic_tm_regs = cbe_get_cpu_mic_tm_regs(cpu);
+
+       if ((!ppe_priv_regs) || (!pmd_regs) || (!mic_tm_regs)) {
+               PFM_WARN("%p,%p,%p", ppe_priv_regs, pmd_regs, mic_tm_regs);
+               return ++err;
+       }
+
+       rmwb_mmio_reg64(ppe_priv_regs->L2_debug1, 61, bit);
+       rmwb_mmio_reg64(ppe_priv_regs->ciu_dr1, 5, bit);
+       rmwb_mmio_reg64(pmd_regs->on_ramp_trace, 39, bit);
+       rmwb_mmio_reg64(mic_tm_regs->MBL_debug, 20, bit);
+
+       return err;
+}
+
+static inline int reset_signal_registers(u32 cpu)
+{
+       int err = 0;
+
+       rmw_spr(SPRN_HID1, ~0x00000000ffffffeful, 0ul);
+
+       return err;
+}
+
+/*
+ *
+ * pfm_cell_reset_signals
+ *
+ */
+int pfm_cell_reset_signals(u32 cpu)
+{
+       int err = 0;
+
+       err += passthrough_disable(cpu);
+       err += reset_signal_registers(cpu);
+       return err;
+}
+
+static int ppu_selection(struct cell_rtas_arg * signal)
+{
+       int err = 0;
+       u8 bus_word;
+       u64 enable_word = 0ul;
+       u64 enable_mask = 0ul;
+
+       BUG_ON(!signal);
+
+       bus_word = signal->bus_word;
+
+       switch (signal->signal_group) {
+       default:
+               PFM_DBG("Not implemented signal_group(%d), now",
+                       signal->signal_group);
+               return ++err;
+
+       case SIG_GROUP_PPU_IU1: /* 2.1 PPU Instruction Unit - Group 1 */
+               if (bus_word == BUS_WORD_0) {
+                       enable_mask = 0x00000001f0c0802cul;
+                       enable_word = 0x00000001f0400000ul;
+               } else if (bus_word == BUS_WORD_1) {
+                       enable_mask = 0x000000010fc08023ul;
+                       enable_word = 0x000000010f400001ul;
+               } else {
+                       PFM_DBG("Invalid bus_word(%x)", bus_word);
+                       return ++err;
+               }
+               break;
+
+       case SIG_GROUP_PPU_XU:  /* 2.3 PPU Execution Unit */
+               if (bus_word == BUS_WORD_0) {
+                       enable_mask = 0x00000001f038402cul;
+                       enable_word = 0x00000001f0080008ul; 
+               } else if (bus_word == BUS_WORD_1) {
+                       enable_mask = 0x000000010f074023ul;
+                       enable_word = 0x000000010f030008ul; 
+               } else {
+                       PFM_DBG("Invalid bus_word(%x)", bus_word);
+                       return ++err;
+               }
+               break;
+       }
+
+       rmw_spr(SPRN_HID1, ~enable_mask, enable_word);
+
+       return err;
+}
+
+
+/*
+ *
+ * pfm_cell_activate_signals
+ *
+ */
+int pfm_cell_activate_signals(struct cell_rtas_arg * signals, int num_signals)
+{
+       int err = 0;
+       int i;
+
+       for (i = 0; i < num_signals; i++) {
+
+               switch (signals[i].signal_group) {
+               default:
+                       PFM_DBG("Not implemented signal_group(%d), now",
+                               signals[i].signal_group);
+                       return ++err;
+
+               /* 2. PowerPC Processor Unit (PPU) Signal Selection */
+               case SIG_GROUP_PPU_IU1:
+               case SIG_GROUP_PPU_XU:
+                       err += ppu_selection(&signals[i]);
+                       if (err)
+                               goto error;
+                       break;
+               }
+               err += passthrough_enable(signals[i].cpu);
+               if (err)
+                       break;
+       }
+
+error:
+       return err;
+}
+
+/*
+ *
+ *  pfm_cell_pmc_check
+ *
+ */
+int pfm_cell_pmc_check(struct pfm_context * ctx,
+                      struct pfm_event_set * set,
+                      struct pfarg_pmc * req)
+{
+       int err = 0;
+       int cnum;
+       u64 reg_num;
+       s16 signal_group;
+       u8 bus_word;
+
+       BUG_ON(!ctx || !set || !req);
+
+       reg_num = req->reg_num;
+       bus_word = GET_BUS_WORD(req->reg_value);
+       signal_group = GET_SIGNAL_NUMBER(req->reg_value);
+
+       BUG_ON((reg_num < NR_CTRS) || ((NR_CTRS * 2) <= reg_num));
+
+       switch (signal_group) {
+       default:
+               PFM_DBG("Not implemented signal_group(%d), now", signal_group);
+               return ++err;
+
+       case SIG_GROUP_PPU_IU1:
+       case SIG_GROUP_PPU_XU:
+               if ((bus_word != 0) && (bus_word != 1)) {
+                       PFM_DBG("invalid bus word. (%x,%d)",
+                               bus_word, signal_group);
+                       return ++err;
+               }
+               break;
+       }
+
+       for (cnum = NR_CTRS; cnum < (NR_CTRS * 2); cnum++) {
+               if (!test_bit(cnum, cast_ulp(set->used_pmcs)))
+                       continue;
+               if (bus_word != GET_BUS_WORD(set->pmcs[cnum]))
+                       continue;
+               if (signal_group == GET_SIGNAL_NUMBER(set->pmcs[cnum]))
+                       continue;
+
+               PFM_DBG("impossible combination. (%d,%d,%d) (%d,%d,%d)",
+                        (int)reg_num, bus_word, signal_group, cnum,
+                        (u8)GET_BUS_WORD(set->pmcs[cnum]),
+                        (s16)GET_SIGNAL_NUMBER(set->pmcs[cnum]));
+               return  ++err;
+       }
+
+       return err;
+}
+
+#endif /* __PERFMON_CELL_SIGNALS_C__ */
Index: linux-2.6.22/arch/powerpc/perfmon/perfmon_cell_signals.h
===================================================================
--- linux-2.6.22-base/arch/powerpc/perfmon/perfmon_cell_signals.h
+++ linux-2.6.22/arch/powerpc/perfmon/perfmon_cell_signals.h
@@ -0,0 +1,31 @@
+/*
+ * This file contains the Cell Performance Monitor Signal setting
+ * used by perfmon_cell.h without RTAS.
+ *
+ * (C) Copyright 2007 TOSHIBA CORPORATION
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ * 02111-1307 USA
+ */
+#ifndef __PERFMON_CELL_SIGNALS_H__
+#define __PERFMON_CELL_SIGNALS_H__
+
+extern int pfm_cell_reset_signals(u32 cpu);
+extern int pfm_cell_activate_signals(struct cell_rtas_arg * signals,
+                                    int num_signals);
+extern int pfm_cell_pmc_check(struct pfm_context * ctx,
+                             struct pfm_event_set * set,
+                             struct pfarg_pmc * req);
+
+#endif  /* __PERFMON_CELL_SIGNALS_H__ */

_______________________________________________
perfmon mailing list
[email protected]
http://www.hpl.hp.com/hosted/linux/mail-archives/perfmon/

Reply via email to