3939 * the PDC INTRIGUE calls. This is done to eliminate bugs introduced
4040 * in various PDC revisions. The code is much more maintainable
4141 * and reliable this way vs having to debug on every version of PDC
42- * on every box.
42+ * on every box.
4343 */
4444
4545#include <linux/capability.h>
@@ -195,8 +195,8 @@ static int perf_config(uint32_t *image_ptr);
195195static int perf_release (struct inode * inode , struct file * file );
196196static int perf_open (struct inode * inode , struct file * file );
197197static ssize_t perf_read (struct file * file , char __user * buf , size_t cnt , loff_t * ppos );
198- static ssize_t perf_write (struct file * file , const char __user * buf , size_t count ,
199- loff_t * ppos );
198+ static ssize_t perf_write (struct file * file , const char __user * buf ,
199+ size_t count , loff_t * ppos );
200200static long perf_ioctl (struct file * file , unsigned int cmd , unsigned long arg );
201201static void perf_start_counters (void );
202202static int perf_stop_counters (uint32_t * raddr );
@@ -222,7 +222,7 @@ extern void perf_intrigue_disable_perf_counters (void);
222222/*
223223 * configure:
224224 *
225- * Configure the cpu with a given data image. First turn off the counters,
225+ * Configure the cpu with a given data image. First turn off the counters,
226226 * then download the image, then turn the counters back on.
227227 */
228228static int perf_config (uint32_t * image_ptr )
@@ -234,15 +234,15 @@ static int perf_config(uint32_t *image_ptr)
234234 error = perf_stop_counters (raddr );
235235 if (error != 0 ) {
236236 printk ("perf_config: perf_stop_counters = %ld\n" , error );
237- return - EINVAL ;
237+ return - EINVAL ;
238238 }
239239
240240printk ("Preparing to write image\n" );
241241 /* Write the image to the chip */
242242 error = perf_write_image ((uint64_t * )image_ptr );
243243 if (error != 0 ) {
244244 printk ("perf_config: DOWNLOAD = %ld\n" , error );
245- return - EINVAL ;
245+ return - EINVAL ;
246246 }
247247
248248printk ("Preparing to start counters\n" );
@@ -254,7 +254,7 @@ printk("Preparing to start counters\n");
254254}
255255
256256/*
257- * Open the device and initialize all of its memory. The device is only
257+ * Open the device and initialize all of its memory. The device is only
258258 * opened once, but can be "queried" by multiple processes that know its
259259 * file descriptor.
260260 */
@@ -298,19 +298,19 @@ static ssize_t perf_read(struct file *file, char __user *buf, size_t cnt, loff_t
298298 * called on the processor that the download should happen
299299 * on.
300300 */
301- static ssize_t perf_write (struct file * file , const char __user * buf , size_t count ,
302- loff_t * ppos )
301+ static ssize_t perf_write (struct file * file , const char __user * buf ,
302+ size_t count , loff_t * ppos )
303303{
304304 size_t image_size ;
305305 uint32_t image_type ;
306306 uint32_t interface_type ;
307307 uint32_t test ;
308308
309- if (perf_processor_interface == ONYX_INTF )
309+ if (perf_processor_interface == ONYX_INTF )
310310 image_size = PCXU_IMAGE_SIZE ;
311- else if (perf_processor_interface == CUDA_INTF )
311+ else if (perf_processor_interface == CUDA_INTF )
312312 image_size = PCXW_IMAGE_SIZE ;
313- else
313+ else
314314 return - EFAULT ;
315315
316316 if (!capable (CAP_SYS_ADMIN ))
@@ -330,22 +330,22 @@ static ssize_t perf_write(struct file *file, const char __user *buf, size_t coun
330330
331331 /* First check the machine type is correct for
332332 the requested image */
333- if (((perf_processor_interface == CUDA_INTF ) &&
334- (interface_type != CUDA_INTF )) ||
335- ((perf_processor_interface == ONYX_INTF ) &&
336- (interface_type != ONYX_INTF )))
333+ if (((perf_processor_interface == CUDA_INTF ) &&
334+ (interface_type != CUDA_INTF )) ||
335+ ((perf_processor_interface == ONYX_INTF ) &&
336+ (interface_type != ONYX_INTF )))
337337 return - EINVAL ;
338338
339339 /* Next check to make sure the requested image
340340 is valid */
341- if (((interface_type == CUDA_INTF ) &&
341+ if (((interface_type == CUDA_INTF ) &&
342342 (test >= MAX_CUDA_IMAGES )) ||
343- ((interface_type == ONYX_INTF ) &&
344- (test >= MAX_ONYX_IMAGES )))
343+ ((interface_type == ONYX_INTF ) &&
344+ (test >= MAX_ONYX_IMAGES )))
345345 return - EINVAL ;
346346
347347 /* Copy the image into the processor */
348- if (interface_type == CUDA_INTF )
348+ if (interface_type == CUDA_INTF )
349349 return perf_config (cuda_images [test ]);
350350 else
351351 return perf_config (onyx_images [test ]);
@@ -359,39 +359,39 @@ static ssize_t perf_write(struct file *file, const char __user *buf, size_t coun
359359static void perf_patch_images (void )
360360{
361361#if 0 /* FIXME!! */
362- /*
362+ /*
363363 * NOTE: this routine is VERY specific to the current TLB image.
364364 * If the image is changed, this routine might also need to be changed.
365365 */
366366 extern void $i_itlb_miss_2_0 ();
367367 extern void $i_dtlb_miss_2_0 ();
368368 extern void PA2_0_iva ();
369369
370- /*
370+ /*
371371 * We can only use the lower 32-bits, the upper 32-bits should be 0
372- * anyway given this is in the kernel
372+ * anyway given this is in the kernel
373373 */
374374 uint32_t itlb_addr = (uint32_t )& ($i_itlb_miss_2_0 );
375375 uint32_t dtlb_addr = (uint32_t )& ($i_dtlb_miss_2_0 );
376376 uint32_t IVAaddress = (uint32_t )& PA2_0_iva ;
377377
378378 if (perf_processor_interface == ONYX_INTF ) {
379379 /* clear last 2 bytes */
380- onyx_images [TLBMISS ][15 ] &= 0xffffff00 ;
380+ onyx_images [TLBMISS ][15 ] &= 0xffffff00 ;
381381 /* set 2 bytes */
382382 onyx_images [TLBMISS ][15 ] |= (0x000000ff & ((dtlb_addr ) >> 24 ));
383383 onyx_images [TLBMISS ][16 ] = (dtlb_addr << 8 )& 0xffffff00 ;
384384 onyx_images [TLBMISS ][17 ] = itlb_addr ;
385385
386386 /* clear last 2 bytes */
387- onyx_images [TLBHANDMISS ][15 ] &= 0xffffff00 ;
387+ onyx_images [TLBHANDMISS ][15 ] &= 0xffffff00 ;
388388 /* set 2 bytes */
389389 onyx_images [TLBHANDMISS ][15 ] |= (0x000000ff & ((dtlb_addr ) >> 24 ));
390390 onyx_images [TLBHANDMISS ][16 ] = (dtlb_addr << 8 )& 0xffffff00 ;
391391 onyx_images [TLBHANDMISS ][17 ] = itlb_addr ;
392392
393393 /* clear last 2 bytes */
394- onyx_images [BIG_CPI ][15 ] &= 0xffffff00 ;
394+ onyx_images [BIG_CPI ][15 ] &= 0xffffff00 ;
395395 /* set 2 bytes */
396396 onyx_images [BIG_CPI ][15 ] |= (0x000000ff & ((dtlb_addr ) >> 24 ));
397397 onyx_images [BIG_CPI ][16 ] = (dtlb_addr << 8 )& 0xffffff00 ;
@@ -404,24 +404,24 @@ static void perf_patch_images(void)
404404
405405 } else if (perf_processor_interface == CUDA_INTF ) {
406406 /* Cuda interface */
407- cuda_images [TLBMISS ][16 ] =
407+ cuda_images [TLBMISS ][16 ] =
408408 (cuda_images [TLBMISS ][16 ]& 0xffff0000 ) |
409409 ((dtlb_addr >> 8 )& 0x0000ffff );
410- cuda_images [TLBMISS ][17 ] =
410+ cuda_images [TLBMISS ][17 ] =
411411 ((dtlb_addr << 24 )& 0xff000000 ) | ((itlb_addr >> 16 )& 0x000000ff );
412412 cuda_images [TLBMISS ][18 ] = (itlb_addr << 16 )& 0xffff0000 ;
413413
414- cuda_images [TLBHANDMISS ][16 ] =
414+ cuda_images [TLBHANDMISS ][16 ] =
415415 (cuda_images [TLBHANDMISS ][16 ]& 0xffff0000 ) |
416416 ((dtlb_addr >> 8 )& 0x0000ffff );
417- cuda_images [TLBHANDMISS ][17 ] =
417+ cuda_images [TLBHANDMISS ][17 ] =
418418 ((dtlb_addr << 24 )& 0xff000000 ) | ((itlb_addr >> 16 )& 0x000000ff );
419419 cuda_images [TLBHANDMISS ][18 ] = (itlb_addr << 16 )& 0xffff0000 ;
420420
421- cuda_images [BIG_CPI ][16 ] =
421+ cuda_images [BIG_CPI ][16 ] =
422422 (cuda_images [BIG_CPI ][16 ]& 0xffff0000 ) |
423423 ((dtlb_addr >> 8 )& 0x0000ffff );
424- cuda_images [BIG_CPI ][17 ] =
424+ cuda_images [BIG_CPI ][17 ] =
425425 ((dtlb_addr << 24 )& 0xff000000 ) | ((itlb_addr >> 16 )& 0x000000ff );
426426 cuda_images [BIG_CPI ][18 ] = (itlb_addr << 16 )& 0xffff0000 ;
427427 } else {
@@ -433,7 +433,7 @@ static void perf_patch_images(void)
433433
434434/*
435435 * ioctl routine
436- * All routines effect the processor that they are executed on. Thus you
436+ * All routines effect the processor that they are executed on. Thus you
437437 * must be running on the processor that you wish to change.
438438 */
439439
@@ -459,7 +459,7 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
459459 }
460460
461461 /* copy out the Counters */
462- if (copy_to_user ((void __user * )arg , raddr ,
462+ if (copy_to_user ((void __user * )arg , raddr ,
463463 sizeof (raddr )) != 0 ) {
464464 error = - EFAULT ;
465465 break ;
@@ -487,7 +487,7 @@ static const struct file_operations perf_fops = {
487487 .open = perf_open ,
488488 .release = perf_release
489489};
490-
490+
491491static struct miscdevice perf_dev = {
492492 MISC_DYNAMIC_MINOR ,
493493 PA_PERF_DEV ,
@@ -595,7 +595,7 @@ static int perf_stop_counters(uint32_t *raddr)
595595 /* OR sticky2 (bit 1496) to counter2 bit 32 */
596596 tmp64 |= (userbuf [23 ] >> 8 ) & 0x0000000080000000 ;
597597 raddr [2 ] = (uint32_t )tmp64 ;
598-
598+
599599 /* Counter3 is bits 1497 to 1528 */
600600 tmp64 = (userbuf [23 ] >> 7 ) & 0x00000000ffffffff ;
601601 /* OR sticky3 (bit 1529) to counter3 bit 32 */
@@ -617,21 +617,21 @@ static int perf_stop_counters(uint32_t *raddr)
617617 userbuf [22 ] = 0 ;
618618 userbuf [23 ] = 0 ;
619619
620- /*
620+ /*
621621 * Write back the zeroed bytes + the image given
622622 * the read was destructive.
623623 */
624624 perf_rdr_write (16 , userbuf );
625625 } else {
626626
627627 /*
628- * Read RDR-15 which contains the counters and sticky bits
628+ * Read RDR-15 which contains the counters and sticky bits
629629 */
630630 if (!perf_rdr_read_ubuf (15 , userbuf )) {
631631 return -13 ;
632632 }
633633
634- /*
634+ /*
635635 * Clear out the counters
636636 */
637637 perf_rdr_clear (15 );
@@ -644,7 +644,7 @@ static int perf_stop_counters(uint32_t *raddr)
644644 raddr [2 ] = (uint32_t )((userbuf [1 ] >> 32 ) & 0x00000000ffffffffUL );
645645 raddr [3 ] = (uint32_t )(userbuf [1 ] & 0x00000000ffffffffUL );
646646 }
647-
647+
648648 return 0 ;
649649}
650650
@@ -682,7 +682,7 @@ static int perf_rdr_read_ubuf(uint32_t rdr_num, uint64_t *buffer)
682682 i = tentry -> num_words ;
683683 while (i -- ) {
684684 buffer [i ] = 0 ;
685- }
685+ }
686686
687687 /* Check for bits an even number of 64 */
688688 if ((xbits = width & 0x03f ) != 0 ) {
@@ -808,18 +808,22 @@ static int perf_write_image(uint64_t *memaddr)
808808 }
809809
810810 runway = ioremap_nocache (cpu_device -> hpa .start , 4096 );
811+ if (!runway ) {
812+ pr_err ("perf_write_image: ioremap failed!\n" );
813+ return - ENOMEM ;
814+ }
811815
812816 /* Merge intrigue bits into Runway STATUS 0 */
813817 tmp64 = __raw_readq (runway + RUNWAY_STATUS ) & 0xffecfffffffffffful ;
814- __raw_writeq (tmp64 | (* memaddr ++ & 0x0013000000000000ul ),
818+ __raw_writeq (tmp64 | (* memaddr ++ & 0x0013000000000000ul ),
815819 runway + RUNWAY_STATUS );
816-
820+
817821 /* Write RUNWAY DEBUG registers */
818822 for (i = 0 ; i < 8 ; i ++ ) {
819823 __raw_writeq (* memaddr ++ , runway + RUNWAY_DEBUG );
820824 }
821825
822- return 0 ;
826+ return 0 ;
823827}
824828
825829/*
@@ -843,7 +847,7 @@ printk("perf_rdr_write\n");
843847 perf_rdr_shift_out_U (rdr_num , buffer [i ]);
844848 } else {
845849 perf_rdr_shift_out_W (rdr_num , buffer [i ]);
846- }
850+ }
847851 }
848852printk ("perf_rdr_write done\n" );
849853}
0 commit comments