[MIPS] Sibyte: Fix ZBbus profiler

o Fix build error.
o Handle error returns.
o Deal with signals received while sleeping.
o Don't allow to be selected when we're not building the directory with
the driver anyway.
o Coding style cleanups.

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

+283 -218
+10 -2
arch/mips/sibyte/Kconfig
··· 8 8 config SIBYTE_BCM1120 9 9 bool 10 10 select SIBYTE_BCM112X 11 + select SIBYTE_HAS_ZBUS_PROFILING 11 12 select SIBYTE_SB1xxx_SOC 12 13 13 14 config SIBYTE_BCM1125 14 15 bool 15 16 select HW_HAS_PCI 16 17 select SIBYTE_BCM112X 18 + select SIBYTE_HAS_ZBUS_PROFILING 17 19 select SIBYTE_SB1xxx_SOC 18 20 19 21 config SIBYTE_BCM1125H ··· 23 21 select HW_HAS_PCI 24 22 select SIBYTE_BCM112X 25 23 select SIBYTE_ENABLE_LDT_IF_PCI 24 + select SIBYTE_HAS_ZBUS_PROFILING 26 25 select SIBYTE_SB1xxx_SOC 27 26 28 27 config SIBYTE_BCM112X 29 28 bool 30 29 select SIBYTE_SB1xxx_SOC 30 + select SIBYTE_HAS_ZBUS_PROFILING 31 31 32 32 config SIBYTE_BCM1x80 33 33 bool ··· 41 37 bool 42 38 select HW_HAS_PCI 43 39 select SIBYTE_SB1xxx_SOC 40 + select SIBYTE_HAS_ZBUS_PROFILING 44 41 select SYS_SUPPORTS_SMP 45 42 46 43 config SIBYTE_SB1xxx_SOC ··· 169 164 depends on SIBYTE_SB1xxx_SOC 170 165 171 166 config SIBYTE_TBPROF 172 - bool "Support for ZBbus profiling" 173 - depends on SIBYTE_SB1xxx_SOC 167 + tristate "Support for ZBbus profiling" 168 + depends on SIBYTE_HAS_ZBUS_PROFILING 169 + 170 + config SIBYTE_HAS_ZBUS_PROFILING 171 + bool
+271 -106
arch/mips/sibyte/sb1250/bcm1250_tbprof.c
··· 1 1 /* 2 - * Copyright (C) 2001, 2002, 2003 Broadcom Corporation 3 - * 4 2 * This program is free software; you can redistribute it and/or 5 3 * modify it under the terms of the GNU General Public License 6 4 * as published by the Free Software Foundation; either version 2 ··· 12 14 * You should have received a copy of the GNU General Public License 13 15 * along with this program; if not, write to the Free Software 14 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 + * 18 + * Copyright (C) 2001, 2002, 2003 Broadcom Corporation 19 + * Copyright (C) 2007 Ralf Baechle <ralf@linux-mips.org> 20 + * Copyright (C) 2007 MIPS Technologies, Inc. 21 + * written by Ralf Baechle <ralf@linux-mips.org> 15 22 */ 16 23 17 - #define SBPROF_TB_DEBUG 0 24 + #undef DEBUG 18 25 26 + #include <linux/device.h> 19 27 #include <linux/module.h> 20 28 #include <linux/kernel.h> 21 29 #include <linux/types.h> ··· 31 27 #include <linux/vmalloc.h> 32 28 #include <linux/fs.h> 33 29 #include <linux/errno.h> 34 - #include <linux/reboot.h> 35 - #include <linux/smp_lock.h> 30 + #include <linux/types.h> 36 31 #include <linux/wait.h> 37 - #include <asm/uaccess.h> 32 + 38 33 #include <asm/io.h> 39 34 #include <asm/sibyte/sb1250.h> 40 35 #include <asm/sibyte/sb1250_regs.h> 41 36 #include <asm/sibyte/sb1250_scd.h> 42 37 #include <asm/sibyte/sb1250_int.h> 43 - #include <asm/sibyte/trace_prof.h> 38 + #include <asm/system.h> 39 + #include <asm/uaccess.h> 44 40 45 - #define DEVNAME "bcm1250_tbprof" 41 + #define SBPROF_TB_MAJOR 240 42 + 43 + typedef u64 tb_sample_t[6*256]; 44 + 45 + enum open_status { 46 + SB_CLOSED, 47 + SB_OPENING, 48 + SB_OPEN 49 + }; 50 + 51 + struct sbprof_tb { 52 + wait_queue_head_t tb_sync; 53 + wait_queue_head_t tb_read; 54 + struct mutex lock; 55 + enum open_status open; 56 + tb_sample_t *sbprof_tbbuf; 57 + int next_tb_sample; 58 + 59 + volatile int tb_enable; 60 + volatile int tb_armed; 61 + 62 + }; 46 63 47 64 static struct sbprof_tb sbp; 48 65 66 + #define MAX_SAMPLE_BYTES (24*1024*1024) 67 + #define MAX_TBSAMPLE_BYTES (12*1024*1024) 68 + 69 + #define MAX_SAMPLES (MAX_SAMPLE_BYTES/sizeof(u_int32_t)) 70 + #define TB_SAMPLE_SIZE (sizeof(tb_sample_t)) 71 + #define MAX_TB_SAMPLES (MAX_TBSAMPLE_BYTES/TB_SAMPLE_SIZE) 72 + 73 + /* ioctls */ 74 + #define SBPROF_ZBSTART _IOW('s', 0, int) 75 + #define SBPROF_ZBSTOP _IOW('s', 1, int) 76 + #define SBPROF_ZBWAITFULL _IOW('s', 2, int) 77 + 78 + /* 79 + * Routines for using 40-bit SCD cycle counter 80 + * 81 + * Client responsible for either handling interrupts or making sure 82 + * the cycles counter never saturates, e.g., by doing 83 + * zclk_timer_init(0) at least every 2^40 - 1 ZCLKs. 84 + */ 85 + 86 + /* 87 + * Configures SCD counter 0 to count ZCLKs starting from val; 88 + * Configures SCD counters1,2,3 to count nothing. 89 + * Must not be called while gathering ZBbus profiles. 90 + */ 91 + 92 + #define zclk_timer_init(val) \ 93 + __asm__ __volatile__ (".set push;" \ 94 + ".set mips64;" \ 95 + "la $8, 0xb00204c0;" /* SCD perf_cnt_cfg */ \ 96 + "sd %0, 0x10($8);" /* write val to counter0 */ \ 97 + "sd %1, 0($8);" /* config counter0 for zclks*/ \ 98 + ".set pop" \ 99 + : /* no outputs */ \ 100 + /* enable, counter0 */ \ 101 + : /* inputs */ "r"(val), "r" ((1ULL << 33) | 1ULL) \ 102 + : /* modifies */ "$8" ) 103 + 104 + 105 + /* Reads SCD counter 0 and puts result in value 106 + unsigned long long val; */ 107 + #define zclk_get(val) \ 108 + __asm__ __volatile__ (".set push;" \ 109 + ".set mips64;" \ 110 + "la $8, 0xb00204c0;" /* SCD perf_cnt_cfg */ \ 111 + "ld %0, 0x10($8);" /* write val to counter0 */ \ 112 + ".set pop" \ 113 + : /* outputs */ "=r"(val) \ 114 + : /* inputs */ \ 115 + : /* modifies */ "$8" ) 116 + 117 + #define DEVNAME "bcm1250_tbprof" 118 + 49 119 #define TB_FULL (sbp.next_tb_sample == MAX_TB_SAMPLES) 50 120 51 - /************************************************************************ 121 + /* 52 122 * Support for ZBbus sampling using the trace buffer 53 123 * 54 124 * We use the SCD performance counter interrupt, caused by a Zclk counter ··· 132 54 * overflow. 133 55 * 134 56 * We map the interrupt for trace_buffer_freeze to handle it on CPU 0. 135 - * 136 - ************************************************************************/ 57 + */ 137 58 138 - static u_int64_t tb_period; 59 + static u64 tb_period; 139 60 140 61 static void arm_tb(void) 141 62 { 142 - u_int64_t scdperfcnt; 143 - u_int64_t next = (1ULL << 40) - tb_period; 144 - u_int64_t tb_options = M_SCD_TRACE_CFG_FREEZE_FULL; 145 - /* Generate an SCD_PERFCNT interrupt in TB_PERIOD Zclks to 146 - trigger start of trace. XXX vary sampling period */ 63 + u64 scdperfcnt; 64 + u64 next = (1ULL << 40) - tb_period; 65 + u64 tb_options = M_SCD_TRACE_CFG_FREEZE_FULL; 66 + 67 + /* 68 + * Generate an SCD_PERFCNT interrupt in TB_PERIOD Zclks to trigger 69 + *start of trace. XXX vary sampling period 70 + */ 147 71 __raw_writeq(0, IOADDR(A_SCD_PERF_CNT_1)); 148 72 scdperfcnt = __raw_readq(IOADDR(A_SCD_PERF_CNT_CFG)); 149 - /* Unfortunately, in Pass 2 we must clear all counters to knock down 150 - a previous interrupt request. This means that bus profiling 151 - requires ALL of the SCD perf counters. */ 73 + 74 + /* 75 + * Unfortunately, in Pass 2 we must clear all counters to knock down a 76 + * previous interrupt request. This means that bus profiling requires 77 + * ALL of the SCD perf counters. 78 + */ 152 79 __raw_writeq((scdperfcnt & ~M_SPC_CFG_SRC1) | 153 - // keep counters 0,2,3 as is 154 - M_SPC_CFG_ENABLE | // enable counting 155 - M_SPC_CFG_CLEAR | // clear all counters 156 - V_SPC_CFG_SRC1(1), // counter 1 counts cycles 80 + /* keep counters 0,2,3 as is */ 81 + M_SPC_CFG_ENABLE | /* enable counting */ 82 + M_SPC_CFG_CLEAR | /* clear all counters */ 83 + V_SPC_CFG_SRC1(1), /* counter 1 counts cycles */ 157 84 IOADDR(A_SCD_PERF_CNT_CFG)); 158 85 __raw_writeq(next, IOADDR(A_SCD_PERF_CNT_1)); 86 + 159 87 /* Reset the trace buffer */ 160 88 __raw_writeq(M_SCD_TRACE_CFG_RESET, IOADDR(A_SCD_TRACE_CFG)); 161 89 #if 0 && defined(M_SCD_TRACE_CFG_FORCECNT) ··· 175 91 static irqreturn_t sbprof_tb_intr(int irq, void *dev_id) 176 92 { 177 93 int i; 178 - DBG(printk(DEVNAME ": tb_intr\n")); 94 + 95 + pr_debug(DEVNAME ": tb_intr\n"); 96 + 179 97 if (sbp.next_tb_sample < MAX_TB_SAMPLES) { 180 98 /* XXX should use XKPHYS to make writes bypass L2 */ 181 - u_int64_t *p = sbp.sbprof_tbbuf[sbp.next_tb_sample++]; 99 + u64 *p = sbp.sbprof_tbbuf[sbp.next_tb_sample++]; 182 100 /* Read out trace */ 183 101 __raw_writeq(M_SCD_TRACE_CFG_START_READ, 184 102 IOADDR(A_SCD_TRACE_CFG)); 185 103 __asm__ __volatile__ ("sync" : : : "memory"); 186 104 /* Loop runs backwards because bundles are read out in reverse order */ 187 105 for (i = 256 * 6; i > 0; i -= 6) { 188 - // Subscripts decrease to put bundle in the order 189 - // t0 lo, t0 hi, t1 lo, t1 hi, t2 lo, t2 hi 106 + /* Subscripts decrease to put bundle in the order */ 107 + /* t0 lo, t0 hi, t1 lo, t1 hi, t2 lo, t2 hi */ 190 108 p[i - 1] = __raw_readq(IOADDR(A_SCD_TRACE_READ)); 191 - // read t2 hi 109 + /* read t2 hi */ 192 110 p[i - 2] = __raw_readq(IOADDR(A_SCD_TRACE_READ)); 193 - // read t2 lo 111 + /* read t2 lo */ 194 112 p[i - 3] = __raw_readq(IOADDR(A_SCD_TRACE_READ)); 195 - // read t1 hi 113 + /* read t1 hi */ 196 114 p[i - 4] = __raw_readq(IOADDR(A_SCD_TRACE_READ)); 197 - // read t1 lo 115 + /* read t1 lo */ 198 116 p[i - 5] = __raw_readq(IOADDR(A_SCD_TRACE_READ)); 199 - // read t0 hi 117 + /* read t0 hi */ 200 118 p[i - 6] = __raw_readq(IOADDR(A_SCD_TRACE_READ)); 201 - // read t0 lo 119 + /* read t0 lo */ 202 120 } 203 121 if (!sbp.tb_enable) { 204 - DBG(printk(DEVNAME ": tb_intr shutdown\n")); 122 + pr_debug(DEVNAME ": tb_intr shutdown\n"); 205 123 __raw_writeq(M_SCD_TRACE_CFG_RESET, 206 124 IOADDR(A_SCD_TRACE_CFG)); 207 125 sbp.tb_armed = 0; 208 126 wake_up(&sbp.tb_sync); 209 127 } else { 210 - arm_tb(); // knock down current interrupt and get another one later 128 + arm_tb(); /* knock down current interrupt and get another one later */ 211 129 } 212 130 } else { 213 131 /* No more trace buffer samples */ 214 - DBG(printk(DEVNAME ": tb_intr full\n")); 132 + pr_debug(DEVNAME ": tb_intr full\n"); 215 133 __raw_writeq(M_SCD_TRACE_CFG_RESET, IOADDR(A_SCD_TRACE_CFG)); 216 134 sbp.tb_armed = 0; 217 135 if (!sbp.tb_enable) { ··· 221 135 } 222 136 wake_up(&sbp.tb_read); 223 137 } 138 + 224 139 return IRQ_HANDLED; 225 140 } 226 141 ··· 231 144 return IRQ_NONE; 232 145 } 233 146 234 - int sbprof_zbprof_start(struct file *filp) 235 - { 236 - u_int64_t scdperfcnt; 147 + /* 148 + * Requires: Already called zclk_timer_init with a value that won't 149 + * saturate 40 bits. No subsequent use of SCD performance counters 150 + * or trace buffer. 151 + */ 237 152 238 - if (sbp.tb_enable) 153 + static int sbprof_zbprof_start(struct file *filp) 154 + { 155 + u64 scdperfcnt; 156 + int err; 157 + 158 + if (xchg(&sbp.tb_enable, 1)) 239 159 return -EBUSY; 240 160 241 - DBG(printk(DEVNAME ": starting\n")); 161 + pr_debug(DEVNAME ": starting\n"); 242 162 243 - sbp.tb_enable = 1; 244 163 sbp.next_tb_sample = 0; 245 164 filp->f_pos = 0; 246 165 247 - if (request_irq 248 - (K_INT_TRACE_FREEZE, sbprof_tb_intr, 0, DEVNAME " trace freeze", &sbp)) { 166 + err = request_irq(K_INT_TRACE_FREEZE, sbprof_tb_intr, 0, 167 + DEVNAME " trace freeze", &sbp); 168 + if (err) 249 169 return -EBUSY; 250 - } 170 + 251 171 /* Make sure there isn't a perf-cnt interrupt waiting */ 252 172 scdperfcnt = __raw_readq(IOADDR(A_SCD_PERF_CNT_CFG)); 253 173 /* Disable and clear counters, override SRC_1 */ ··· 262 168 M_SPC_CFG_ENABLE | M_SPC_CFG_CLEAR | V_SPC_CFG_SRC1(1), 263 169 IOADDR(A_SCD_PERF_CNT_CFG)); 264 170 265 - /* We grab this interrupt to prevent others from trying to use 266 - it, even though we don't want to service the interrupts 267 - (they only feed into the trace-on-interrupt mechanism) */ 268 - if (request_irq 269 - (K_INT_PERF_CNT, sbprof_pc_intr, 0, DEVNAME " scd perfcnt", &sbp)) { 270 - free_irq(K_INT_TRACE_FREEZE, &sbp); 271 - return -EBUSY; 272 - } 171 + /* 172 + * We grab this interrupt to prevent others from trying to use it, even 173 + * though we don't want to service the interrupts (they only feed into 174 + * the trace-on-interrupt mechanism) 175 + */ 176 + err = request_irq(K_INT_PERF_CNT, sbprof_pc_intr, 0, 177 + DEVNAME " scd perfcnt", &sbp); 178 + if (err) 179 + goto out_free_irq; 273 180 274 - /* I need the core to mask these, but the interrupt mapper to 275 - pass them through. I am exploiting my knowledge that 276 - cp0_status masks out IP[5]. krw */ 181 + /* 182 + * I need the core to mask these, but the interrupt mapper to pass them 183 + * through. I am exploiting my knowledge that cp0_status masks out 184 + * IP[5]. krw 185 + */ 277 186 __raw_writeq(K_INT_MAP_I3, 278 187 IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MAP_BASE) + 279 188 (K_INT_PERF_CNT << 3))); ··· 298 201 __raw_writeq(0, IOADDR(A_ADDR_TRAP_CFG_3)); 299 202 300 203 /* Initialize Trace Event 0-7 */ 301 - // when interrupt 204 + /* when interrupt */ 302 205 __raw_writeq(M_SCD_TREVT_INTERRUPT, IOADDR(A_SCD_TRACE_EVENT_0)); 303 206 __raw_writeq(0, IOADDR(A_SCD_TRACE_EVENT_1)); 304 207 __raw_writeq(0, IOADDR(A_SCD_TRACE_EVENT_2)); ··· 309 212 __raw_writeq(0, IOADDR(A_SCD_TRACE_EVENT_7)); 310 213 311 214 /* Initialize Trace Sequence 0-7 */ 312 - // Start on event 0 (interrupt) 215 + /* Start on event 0 (interrupt) */ 313 216 __raw_writeq(V_SCD_TRSEQ_FUNC_START | 0x0fff, 314 217 IOADDR(A_SCD_TRACE_SEQUENCE_0)); 315 - // dsamp when d used | asamp when a used 218 + /* dsamp when d used | asamp when a used */ 316 219 __raw_writeq(M_SCD_TRSEQ_ASAMPLE | M_SCD_TRSEQ_DSAMPLE | 317 220 K_SCD_TRSEQ_TRIGGER_ALL, 318 221 IOADDR(A_SCD_TRACE_SEQUENCE_1)); ··· 329 232 330 233 arm_tb(); 331 234 332 - DBG(printk(DEVNAME ": done starting\n")); 235 + pr_debug(DEVNAME ": done starting\n"); 333 236 334 237 return 0; 238 + 239 + out_free_irq: 240 + free_irq(K_INT_TRACE_FREEZE, &sbp); 241 + 242 + return err; 335 243 } 336 244 337 - int sbprof_zbprof_stop(void) 245 + static int sbprof_zbprof_stop(void) 338 246 { 339 - DEFINE_WAIT(wait); 340 - DBG(printk(DEVNAME ": stopping\n")); 247 + int err; 248 + 249 + pr_debug(DEVNAME ": stopping\n"); 341 250 342 251 if (sbp.tb_enable) { 252 + /* 253 + * XXXKW there is a window here where the intr handler may run, 254 + * see the disable, and do the wake_up before this sleep 255 + * happens. 256 + */ 257 + pr_debug(DEVNAME ": wait for disarm\n"); 258 + err = wait_event_interruptible(sbp.tb_sync, !sbp.tb_armed); 259 + pr_debug(DEVNAME ": disarm complete, stat %d\n", err); 260 + 261 + if (err) 262 + return err; 263 + 343 264 sbp.tb_enable = 0; 344 - /* XXXKW there is a window here where the intr handler 345 - may run, see the disable, and do the wake_up before 346 - this sleep happens. */ 347 - if (sbp.tb_armed) { 348 - DBG(printk(DEVNAME ": wait for disarm\n")); 349 - prepare_to_wait(&sbp.tb_sync, &wait, TASK_INTERRUPTIBLE); 350 - schedule(); 351 - finish_wait(&sbp.tb_sync, &wait); 352 - DBG(printk(DEVNAME ": disarm complete\n")); 353 - } 354 265 free_irq(K_INT_TRACE_FREEZE, &sbp); 355 266 free_irq(K_INT_PERF_CNT, &sbp); 356 267 } 357 268 358 - DBG(printk(DEVNAME ": done stopping\n")); 269 + pr_debug(DEVNAME ": done stopping\n"); 359 270 360 271 return 0; 361 272 } ··· 373 268 int minor; 374 269 375 270 minor = iminor(inode); 376 - if (minor != 0) { 271 + if (minor != 0) 377 272 return -ENODEV; 378 - } 379 - if (sbp.open) { 273 + 274 + if (xchg(&sbp.open, SB_OPENING) != SB_CLOSED) 380 275 return -EBUSY; 381 - } 382 276 383 277 memset(&sbp, 0, sizeof(struct sbprof_tb)); 278 + 384 279 sbp.sbprof_tbbuf = vmalloc(MAX_TBSAMPLE_BYTES); 385 - if (!sbp.sbprof_tbbuf) { 280 + if (!sbp.sbprof_tbbuf) 386 281 return -ENOMEM; 387 - } 282 + 388 283 memset(sbp.sbprof_tbbuf, 0, MAX_TBSAMPLE_BYTES); 389 284 init_waitqueue_head(&sbp.tb_sync); 390 285 init_waitqueue_head(&sbp.tb_read); 391 - sbp.open = 1; 286 + mutex_init(&sbp.lock); 287 + 288 + sbp.open = SB_OPEN; 392 289 393 290 return 0; 394 291 } 395 292 396 293 static int sbprof_tb_release(struct inode *inode, struct file *filp) 397 294 { 398 - int minor; 295 + int minor = iminor(inode); 399 296 400 - minor = iminor(inode); 401 - if (minor != 0 || !sbp.open) { 297 + if (minor != 0 || !sbp.open) 402 298 return -ENODEV; 403 - } 404 299 405 - if (sbp.tb_armed || sbp.tb_enable) { 300 + mutex_lock(&sbp.lock); 301 + 302 + if (sbp.tb_armed || sbp.tb_enable) 406 303 sbprof_zbprof_stop(); 407 - } 408 304 409 305 vfree(sbp.sbprof_tbbuf); 410 306 sbp.open = 0; 307 + 308 + mutex_unlock(&sbp.lock); 411 309 412 310 return 0; 413 311 } ··· 419 311 size_t size, loff_t *offp) 420 312 { 421 313 int cur_sample, sample_off, cur_count, sample_left; 422 - char *src; 423 - int count = 0; 424 - char *dest = buf; 425 314 long cur_off = *offp; 315 + char *dest = buf; 316 + int count = 0; 317 + char *src; 318 + 319 + if (!access_ok(VERIFY_WRITE, buf, size)) 320 + return -EFAULT; 321 + 322 + mutex_lock(&sbp.lock); 426 323 427 324 count = 0; 428 325 cur_sample = cur_off / TB_SAMPLE_SIZE; 429 326 sample_off = cur_off % TB_SAMPLE_SIZE; 430 327 sample_left = TB_SAMPLE_SIZE - sample_off; 328 + 431 329 while (size && (cur_sample < sbp.next_tb_sample)) { 330 + int err; 331 + 432 332 cur_count = size < sample_left ? size : sample_left; 433 333 src = (char *)(((long)sbp.sbprof_tbbuf[cur_sample])+sample_off); 434 - copy_to_user(dest, src, cur_count); 435 - DBG(printk(DEVNAME ": read from sample %d, %d bytes\n", 436 - cur_sample, cur_count)); 334 + err = __copy_to_user(dest, src, cur_count); 335 + if (err) { 336 + *offp = cur_off + cur_count - err; 337 + mutex_unlock(&sbp.lock); 338 + return err; 339 + } 340 + 341 + pr_debug(DEVNAME ": read from sample %d, %d bytes\n", 342 + cur_sample, cur_count); 437 343 size -= cur_count; 438 344 sample_left -= cur_count; 439 345 if (!sample_left) { ··· 461 339 dest += cur_count; 462 340 count += cur_count; 463 341 } 342 + 464 343 *offp = cur_off; 344 + mutex_unlock(&sbp.lock); 465 345 466 346 return count; 467 347 } 468 348 469 - static long sbprof_tb_ioctl(struct file *filp, 470 - unsigned int command, 471 - unsigned long arg) 349 + static long sbprof_tb_ioctl(struct file *filp, unsigned int command, 350 + unsigned long arg) 472 351 { 473 352 int error = 0; 474 353 475 - lock_kernel(); 476 354 switch (command) { 477 355 case SBPROF_ZBSTART: 356 + mutex_lock(&sbp.lock); 478 357 error = sbprof_zbprof_start(filp); 358 + mutex_unlock(&sbp.lock); 479 359 break; 360 + 480 361 case SBPROF_ZBSTOP: 362 + mutex_lock(&sbp.lock); 481 363 error = sbprof_zbprof_stop(); 364 + mutex_unlock(&sbp.lock); 482 365 break; 366 + 483 367 case SBPROF_ZBWAITFULL: 484 - DEFINE_WAIT(wait); 485 - prepare_to_wait(&sbp.tb_read, &wait, TASK_INTERRUPTIBLE); 486 - schedule(); 487 - finish_wait(&sbp.tb_read, &wait); 488 - /* XXXKW check if interrupted? */ 489 - return put_user(TB_FULL, (int *) arg); 368 + error = wait_event_interruptible(sbp.tb_read, TB_FULL); 369 + if (error) 370 + break; 371 + 372 + error = put_user(TB_FULL, (int *) arg); 373 + break; 374 + 490 375 default: 491 376 error = -EINVAL; 492 377 break; 493 378 } 494 - unlock_kernel(); 495 379 496 380 return error; 497 381 } ··· 512 384 .mmap = NULL, 513 385 }; 514 386 387 + static struct class *tb_class; 388 + static struct device *tb_dev; 389 + 515 390 static int __init sbprof_tb_init(void) 516 391 { 392 + struct device *dev; 393 + struct class *tbc; 394 + int err; 395 + 517 396 if (register_chrdev(SBPROF_TB_MAJOR, DEVNAME, &sbprof_tb_fops)) { 518 397 printk(KERN_WARNING DEVNAME ": initialization failed (dev %d)\n", 519 398 SBPROF_TB_MAJOR); 520 399 return -EIO; 521 400 } 401 + 402 + tbc = class_create(THIS_MODULE, "sb_tracebuffer"); 403 + if (IS_ERR(tbc)) { 404 + err = PTR_ERR(tbc); 405 + goto out_chrdev; 406 + } 407 + 408 + tb_class = tbc; 409 + 410 + dev = device_create(tbc, NULL, MKDEV(SBPROF_TB_MAJOR, 0), "tb"); 411 + if (IS_ERR(dev)) { 412 + err = PTR_ERR(dev); 413 + goto out_class; 414 + } 415 + tb_dev = dev; 416 + 522 417 sbp.open = 0; 523 418 tb_period = zbbus_mhz * 10000LL; 524 - printk(KERN_INFO DEVNAME ": initialized - tb_period = %lld\n", tb_period); 419 + pr_info(DEVNAME ": initialized - tb_period = %lld\n", tb_period); 420 + 525 421 return 0; 422 + 423 + out_class: 424 + class_destroy(tb_class); 425 + out_chrdev: 426 + unregister_chrdev(SBPROF_TB_MAJOR, DEVNAME); 427 + 428 + return err; 526 429 } 527 430 528 431 static void __exit sbprof_tb_cleanup(void) 529 432 { 433 + device_destroy(tb_class, MKDEV(SBPROF_TB_MAJOR, 0)); 530 434 unregister_chrdev(SBPROF_TB_MAJOR, DEVNAME); 435 + class_destroy(tb_class); 531 436 } 532 437 533 438 module_init(sbprof_tb_init); 534 439 module_exit(sbprof_tb_cleanup); 440 + 441 + MODULE_ALIAS_CHARDEV_MAJOR(SBPROF_TB_MAJOR); 442 + MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>"); 443 + MODULE_LICENSE("GPL");
+2
arch/mips/sibyte/sb1250/setup.c
··· 16 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 17 */ 18 18 #include <linux/init.h> 19 + #include <linux/module.h> 19 20 #include <linux/kernel.h> 20 21 #include <linux/reboot.h> 21 22 #include <linux/string.h> ··· 33 32 unsigned int soc_type; 34 33 unsigned int periph_rev; 35 34 unsigned int zbbus_mhz; 35 + EXPORT_SYMBOL(zbbus_mhz); 36 36 37 37 static char *soc_str; 38 38 static char *pass_str;
-110
include/asm-mips/sibyte/trace_prof.h
··· 1 - /* 2 - * Copyright (C) 2001 Broadcom Corporation 3 - * 4 - * This program is free software; you can redistribute it and/or 5 - * modify it under the terms of the GNU General Public License 6 - * as published by the Free Software Foundation; either version 2 7 - * of the License, or (at your option) any later version. 8 - * 9 - * This program is distributed in the hope that it will be useful, 10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 - * GNU General Public License for more details. 13 - * 14 - * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 - */ 18 - 19 - #ifndef __ASM_SIBYTE_TRACE_PROF_H 20 - #define __ASM_SIBYTE_TRACE_PROF_H 21 - 22 - #undef DBG 23 - #if SBPROF_TB_DEBUG 24 - #define DBG(a) a 25 - #else 26 - #define DBG(a) 27 - #endif 28 - 29 - #define SBPROF_TB_MAJOR 240 30 - #define DEVNAME "bcm1250_tbprof" 31 - 32 - typedef u_int64_t tb_sample_t[6*256]; 33 - 34 - struct sbprof_tb { 35 - int open; 36 - tb_sample_t *sbprof_tbbuf; 37 - int next_tb_sample; 38 - 39 - volatile int tb_enable; 40 - volatile int tb_armed; 41 - 42 - wait_queue_head_t tb_sync; 43 - wait_queue_head_t tb_read; 44 - }; 45 - 46 - #define MAX_SAMPLE_BYTES (24*1024*1024) 47 - #define MAX_TBSAMPLE_BYTES (12*1024*1024) 48 - 49 - #define MAX_SAMPLES (MAX_SAMPLE_BYTES/sizeof(u_int32_t)) 50 - #define TB_SAMPLE_SIZE (sizeof(tb_sample_t)) 51 - #define MAX_TB_SAMPLES (MAX_TBSAMPLE_BYTES/TB_SAMPLE_SIZE) 52 - 53 - /* IOCTLs */ 54 - #define SBPROF_ZBSTART _IOW('s', 0, int) 55 - #define SBPROF_ZBSTOP _IOW('s', 1, int) 56 - #define SBPROF_ZBWAITFULL _IOW('s', 2, int) 57 - 58 - /*************************************************************************** 59 - * Routines for gathering ZBbus profiles using trace buffer 60 - ***************************************************************************/ 61 - 62 - /* Requires: Already called zclk_timer_init with a value that won't 63 - saturate 40 bits. No subsequent use of SCD performance counters 64 - or trace buffer. 65 - Effect: Starts gathering random ZBbus profiles using trace buffer. */ 66 - extern int sbprof_zbprof_start(struct file *filp); 67 - 68 - /* Effect: Stops collection of ZBbus profiles */ 69 - extern int sbprof_zbprof_stop(void); 70 - 71 - 72 - /*************************************************************************** 73 - * Routines for using 40-bit SCD cycle counter 74 - * 75 - * Client responsible for either handling interrupts or making sure 76 - * the cycles counter never saturates, e.g., by doing 77 - * zclk_timer_init(0) at least every 2^40 - 1 ZCLKs. 78 - ***************************************************************************/ 79 - 80 - /* Configures SCD counter 0 to count ZCLKs starting from val; 81 - Configures SCD counters1,2,3 to count nothing. 82 - Must not be called while gathering ZBbus profiles. 83 - 84 - unsigned long long val; */ 85 - #define zclk_timer_init(val) \ 86 - __asm__ __volatile__ (".set push;" \ 87 - ".set mips64;" \ 88 - "la $8, 0xb00204c0;" /* SCD perf_cnt_cfg */ \ 89 - "sd %0, 0x10($8);" /* write val to counter0 */ \ 90 - "sd %1, 0($8);" /* config counter0 for zclks*/ \ 91 - ".set pop" \ 92 - : /* no outputs */ \ 93 - /* enable, counter0 */ \ 94 - : /* inputs */ "r"(val), "r" ((1ULL << 33) | 1ULL) \ 95 - : /* modifies */ "$8" ) 96 - 97 - 98 - /* Reads SCD counter 0 and puts result in value 99 - unsigned long long val; */ 100 - #define zclk_get(val) \ 101 - __asm__ __volatile__ (".set push;" \ 102 - ".set mips64;" \ 103 - "la $8, 0xb00204c0;" /* SCD perf_cnt_cfg */ \ 104 - "ld %0, 0x10($8);" /* write val to counter0 */ \ 105 - ".set pop" \ 106 - : /* outputs */ "=r"(val) \ 107 - : /* inputs */ \ 108 - : /* modifies */ "$8" ) 109 - 110 - #endif /* __ASM_SIBYTE_TRACE_PROF_H */