segment.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 unless it becomes
  26. * unmapped uncached at error level due to EU.
  27. */
  28. if ((am == 0) || (am > 3) || (cfg & MIPS_SEGCFG_EU))
  29. str += sprintf(str, " %03lx",
  30. ((cfg & MIPS_SEGCFG_PA) >> MIPS_SEGCFG_PA_SHIFT));
  31. else
  32. str += sprintf(str, " UND");
  33. if ((am == 0) || (am > 3))
  34. str += sprintf(str, " %01ld",
  35. ((cfg & MIPS_SEGCFG_C) >> MIPS_SEGCFG_C_SHIFT));
  36. else
  37. str += sprintf(str, " U");
  38. /* Exception configuration. */
  39. str += sprintf(str, " %01ld\n",
  40. ((cfg & MIPS_SEGCFG_EU) >> MIPS_SEGCFG_EU_SHIFT));
  41. }
  42. static int show_segments(struct seq_file *m, void *v)
  43. {
  44. unsigned int segcfg;
  45. char str[42];
  46. seq_puts(m, "Segment Virtual Size Access Mode Physical Caching EU\n");
  47. seq_puts(m, "------- ------- ---- ----------- -------- ------- --\n");
  48. segcfg = read_c0_segctl0();
  49. build_segment_config(str, segcfg);
  50. seq_printf(m, " 0 e0000000 512M %s", str);
  51. segcfg >>= 16;
  52. build_segment_config(str, segcfg);
  53. seq_printf(m, " 1 c0000000 512M %s", str);
  54. segcfg = read_c0_segctl1();
  55. build_segment_config(str, segcfg);
  56. seq_printf(m, " 2 a0000000 512M %s", str);
  57. segcfg >>= 16;
  58. build_segment_config(str, segcfg);
  59. seq_printf(m, " 3 80000000 512M %s", str);
  60. segcfg = read_c0_segctl2();
  61. build_segment_config(str, segcfg);
  62. seq_printf(m, " 4 40000000 1G %s", str);
  63. segcfg >>= 16;
  64. build_segment_config(str, segcfg);
  65. seq_printf(m, " 5 00000000 1G %s\n", str);
  66. return 0;
  67. }
  68. static int segments_open(struct inode *inode, struct file *file)
  69. {
  70. return single_open(file, show_segments, NULL);
  71. }
  72. static const struct file_operations segments_fops = {
  73. .open = segments_open,
  74. .read = seq_read,
  75. .llseek = seq_lseek,
  76. .release = single_release,
  77. };
  78. static int __init segments_info(void)
  79. {
  80. struct dentry *segments;
  81. if (cpu_has_segments) {
  82. if (!mips_debugfs_dir)
  83. return -ENODEV;
  84. segments = debugfs_create_file("segments", S_IRUGO,
  85. mips_debugfs_dir, NULL,
  86. &segments_fops);
  87. if (!segments)
  88. return -ENOMEM;
  89. }
  90. return 0;
  91. }
  92. device_initcall(segments_info);