segment.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2013 Imagination Technologies Ltd.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/debugfs.h>
  10. #include <linux/seq_file.h>
  11. #include <asm/cpu.h>
  12. #include <asm/debug.h>
  13. #include <asm/mipsregs.h>
  14. static void build_segment_config(char *str, unsigned int cfg)
  15. {
  16. unsigned int am;
  17. static const char * const am_str[] = {
  18. "UK", "MK", "MSK", "MUSK", "MUSUK", "USK",
  19. "RSRVD", "UUSK"};
  20. /* Segment access mode. */
  21. am = (cfg & MIPS_SEGCFG_AM) >> MIPS_SEGCFG_AM_SHIFT;
  22. str += sprintf(str, "%-5s", am_str[am]);
  23. /*
  24. * Access modes MK, MSK and MUSK are mapped segments. Therefore
  25. * there is no direct physical address mapping.
  26. */
  27. if ((am == 0) || (am > 3)) {
  28. str += sprintf(str, " %03lx",
  29. ((cfg & MIPS_SEGCFG_PA) >> MIPS_SEGCFG_PA_SHIFT));
  30. str += sprintf(str, " %01ld",
  31. ((cfg & MIPS_SEGCFG_C) >> MIPS_SEGCFG_C_SHIFT));
  32. } else {
  33. str += sprintf(str, " UND");
  34. str += sprintf(str, " U");
  35. }
  36. /* Exception configuration. */
  37. str += sprintf(str, " %01ld\n",
  38. ((cfg & MIPS_SEGCFG_EU) >> MIPS_SEGCFG_EU_SHIFT));
  39. }
  40. static int show_segments(struct seq_file *m, void *v)
  41. {
  42. unsigned int segcfg;
  43. char str[42];
  44. seq_puts(m, "Segment Virtual Size Access Mode Physical Caching EU\n");
  45. seq_puts(m, "------- ------- ---- ----------- -------- ------- --\n");
  46. segcfg = read_c0_segctl0();
  47. build_segment_config(str, segcfg);
  48. seq_printf(m, " 0 e0000000 512M %s", str);
  49. segcfg >>= 16;
  50. build_segment_config(str, segcfg);
  51. seq_printf(m, " 1 c0000000 512M %s", str);
  52. segcfg = read_c0_segctl1();
  53. build_segment_config(str, segcfg);
  54. seq_printf(m, " 2 a0000000 512M %s", str);
  55. segcfg >>= 16;
  56. build_segment_config(str, segcfg);
  57. seq_printf(m, " 3 80000000 512M %s", str);
  58. segcfg = read_c0_segctl2();
  59. build_segment_config(str, segcfg);
  60. seq_printf(m, " 4 40000000 1G %s", str);
  61. segcfg >>= 16;
  62. build_segment_config(str, segcfg);
  63. seq_printf(m, " 5 00000000 1G %s\n", str);
  64. return 0;
  65. }
  66. static int segments_open(struct inode *inode, struct file *file)
  67. {
  68. return single_open(file, show_segments, NULL);
  69. }
  70. static const struct file_operations segments_fops = {
  71. .open = segments_open,
  72. .read = seq_read,
  73. .llseek = seq_lseek,
  74. .release = single_release,
  75. };
  76. static int __init segments_info(void)
  77. {
  78. struct dentry *segments;
  79. if (cpu_has_segments) {
  80. if (!mips_debugfs_dir)
  81. return -ENODEV;
  82. segments = debugfs_create_file("segments", S_IRUGO,
  83. mips_debugfs_dir, NULL,
  84. &segments_fops);
  85. if (!segments)
  86. return -ENOMEM;
  87. }
  88. return 0;
  89. }
  90. device_initcall(segments_info);