Path: blob/master/arch/powerpc/oprofile/op_model_7450.c
10818 views
/*1* arch/powerpc/oprofile/op_model_7450.c2*3* Freescale 745x/744x oprofile support, based on fsl_booke support4* Copyright (C) 2004 Anton Blanchard <[email protected]>, IBM5*6* Copyright (c) 2004 Freescale Semiconductor, Inc7*8* Author: Andy Fleming9* Maintainer: Kumar Gala <[email protected]>10*11* This program is free software; you can redistribute it and/or12* modify it under the terms of the GNU General Public License13* as published by the Free Software Foundation; either version14* 2 of the License, or (at your option) any later version.15*/1617#include <linux/oprofile.h>18#include <linux/init.h>19#include <linux/smp.h>20#include <asm/ptrace.h>21#include <asm/system.h>22#include <asm/processor.h>23#include <asm/cputable.h>24#include <asm/page.h>25#include <asm/pmc.h>26#include <asm/oprofile_impl.h>2728static unsigned long reset_value[OP_MAX_COUNTER];2930static int oprofile_running;31static u32 mmcr0_val, mmcr1_val, mmcr2_val, num_pmcs;3233#define MMCR0_PMC1_SHIFT 634#define MMCR0_PMC2_SHIFT 035#define MMCR1_PMC3_SHIFT 2736#define MMCR1_PMC4_SHIFT 2237#define MMCR1_PMC5_SHIFT 1738#define MMCR1_PMC6_SHIFT 113940#define mmcr0_event1(event) \41((event << MMCR0_PMC1_SHIFT) & MMCR0_PMC1SEL)42#define mmcr0_event2(event) \43((event << MMCR0_PMC2_SHIFT) & MMCR0_PMC2SEL)4445#define mmcr1_event3(event) \46((event << MMCR1_PMC3_SHIFT) & MMCR1_PMC3SEL)47#define mmcr1_event4(event) \48((event << MMCR1_PMC4_SHIFT) & MMCR1_PMC4SEL)49#define mmcr1_event5(event) \50((event << MMCR1_PMC5_SHIFT) & MMCR1_PMC5SEL)51#define mmcr1_event6(event) \52((event << MMCR1_PMC6_SHIFT) & MMCR1_PMC6SEL)5354#define MMCR0_INIT (MMCR0_FC | MMCR0_FCS | MMCR0_FCP | MMCR0_FCM1 | MMCR0_FCM0)5556/* Unfreezes the counters on this CPU, enables the interrupt,57* enables the counters to trigger the interrupt, and sets the58* counters to only count when the mark bit is not set.59*/60static void pmc_start_ctrs(void)61{62u32 mmcr0 = mfspr(SPRN_MMCR0);6364mmcr0 &= ~(MMCR0_FC | MMCR0_FCM0);65mmcr0 |= (MMCR0_FCECE | MMCR0_PMC1CE | MMCR0_PMCnCE | MMCR0_PMXE);6667mtspr(SPRN_MMCR0, mmcr0);68}6970/* Disables the counters on this CPU, and freezes them */71static void pmc_stop_ctrs(void)72{73u32 mmcr0 = mfspr(SPRN_MMCR0);7475mmcr0 |= MMCR0_FC;76mmcr0 &= ~(MMCR0_FCECE | MMCR0_PMC1CE | MMCR0_PMCnCE | MMCR0_PMXE);7778mtspr(SPRN_MMCR0, mmcr0);79}8081/* Configures the counters on this CPU based on the global82* settings */83static int fsl7450_cpu_setup(struct op_counter_config *ctr)84{85/* freeze all counters */86pmc_stop_ctrs();8788mtspr(SPRN_MMCR0, mmcr0_val);89mtspr(SPRN_MMCR1, mmcr1_val);90if (num_pmcs > 4)91mtspr(SPRN_MMCR2, mmcr2_val);9293return 0;94}9596/* Configures the global settings for the countes on all CPUs. */97static int fsl7450_reg_setup(struct op_counter_config *ctr,98struct op_system_config *sys,99int num_ctrs)100{101int i;102103num_pmcs = num_ctrs;104/* Our counters count up, and "count" refers to105* how much before the next interrupt, and we interrupt106* on overflow. So we calculate the starting value107* which will give us "count" until overflow.108* Then we set the events on the enabled counters */109for (i = 0; i < num_ctrs; ++i)110reset_value[i] = 0x80000000UL - ctr[i].count;111112/* Set events for Counters 1 & 2 */113mmcr0_val = MMCR0_INIT | mmcr0_event1(ctr[0].event)114| mmcr0_event2(ctr[1].event);115116/* Setup user/kernel bits */117if (sys->enable_kernel)118mmcr0_val &= ~(MMCR0_FCS);119120if (sys->enable_user)121mmcr0_val &= ~(MMCR0_FCP);122123/* Set events for Counters 3-6 */124mmcr1_val = mmcr1_event3(ctr[2].event)125| mmcr1_event4(ctr[3].event);126if (num_ctrs > 4)127mmcr1_val |= mmcr1_event5(ctr[4].event)128| mmcr1_event6(ctr[5].event);129130mmcr2_val = 0;131132return 0;133}134135/* Sets the counters on this CPU to the chosen values, and starts them */136static int fsl7450_start(struct op_counter_config *ctr)137{138int i;139140mtmsr(mfmsr() | MSR_PMM);141142for (i = 0; i < num_pmcs; ++i) {143if (ctr[i].enabled)144classic_ctr_write(i, reset_value[i]);145else146classic_ctr_write(i, 0);147}148149/* Clear the freeze bit, and enable the interrupt.150* The counters won't actually start until the rfi clears151* the PMM bit */152pmc_start_ctrs();153154oprofile_running = 1;155156return 0;157}158159/* Stop the counters on this CPU */160static void fsl7450_stop(void)161{162/* freeze counters */163pmc_stop_ctrs();164165oprofile_running = 0;166167mb();168}169170171/* Handle the interrupt on this CPU, and log a sample for each172* event that triggered the interrupt */173static void fsl7450_handle_interrupt(struct pt_regs *regs,174struct op_counter_config *ctr)175{176unsigned long pc;177int is_kernel;178int val;179int i;180181/* set the PMM bit (see comment below) */182mtmsr(mfmsr() | MSR_PMM);183184pc = mfspr(SPRN_SIAR);185is_kernel = is_kernel_addr(pc);186187for (i = 0; i < num_pmcs; ++i) {188val = classic_ctr_read(i);189if (val < 0) {190if (oprofile_running && ctr[i].enabled) {191oprofile_add_ext_sample(pc, regs, i, is_kernel);192classic_ctr_write(i, reset_value[i]);193} else {194classic_ctr_write(i, 0);195}196}197}198199/* The freeze bit was set by the interrupt. */200/* Clear the freeze bit, and reenable the interrupt.201* The counters won't actually start until the rfi clears202* the PM/M bit */203pmc_start_ctrs();204}205206struct op_powerpc_model op_model_7450= {207.reg_setup = fsl7450_reg_setup,208.cpu_setup = fsl7450_cpu_setup,209.start = fsl7450_start,210.stop = fsl7450_stop,211.handle_interrupt = fsl7450_handle_interrupt,212};213214215