segment.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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/mipsregs.h>
  13. static void build_segment_config(char *str, unsigned int cfg)
  14. {
  15. unsigned int am;
  16. static const char * const am_str[] = {
  17. "UK", "MK", "MSK", "MUSK", "MUSUK", "USK",
  18. "RSRVD", "UUSK"};
  19. /* Segment access mode. */
  20. am = (cfg & MIPS_SEGCFG_AM) >> MIPS_SEGCFG_AM_SHIFT;
  21. str += sprintf(str, "%-5s", am_str[am]);
  22. /*
  23. * Access modes MK, MSK and MUSK are mapped segments. Therefore
  24. * there is no direct physical address mapping.
  25. */
  26. if ((am == 0) || (am > 3)) {
  27. str += sprintf(str, " %03lx",
  28. ((cfg & MIPS_SEGCFG_PA) >> MIPS_SEGCFG_PA_SHIFT));
  29. str += sprintf(str, " %01ld",
  30. ((cfg & MIPS_SEGCFG_C) >> MIPS_SEGCFG_C_SHIFT));
  31. } else {
  32. str += sprintf(str, " UND");
  33. str += sprintf(str, " U");
  34. }
  35. /* Exception configuration. */
  36. str += sprintf(str, " %01ld\n",
  37. ((cfg & MIPS_SEGCFG_EU) >> MIPS_SEGCFG_EU_SHIFT));
  38. }
  39. static int show_segments(struct seq_file *m, void *v)
  40. {
  41. unsigned int segcfg;
  42. char str[42];
  43. seq_puts(m, "Segment Virtual Size Access Mode Physical Caching EU\n");
  44. seq_puts(m, "------- ------- ---- ----------- -------- ------- --\n");
  45. segcfg = read_c0_segctl0();
  46. build_segment_config(str, segcfg);
  47. seq_printf(m, " 0 e0000000 512M %s", str);
  48. segcfg >>= 16;
  49. build_segment_config(str, segcfg);
  50. seq_printf(m, " 1 c0000000 512M %s", str);
  51. segcfg = read_c0_segctl1();
  52. build_segment_config(str, segcfg);
  53. seq_printf(m, " 2 a0000000 512M %s", str);
  54. segcfg >>= 16;
  55. build_segment_config(str, segcfg);
  56. seq_printf(m, " 3 80000000 512M %s", str);
  57. segcfg = read_c0_segctl2();
  58. build_segment_config(str, segcfg);
  59. seq_printf(m, " 4 40000000 1G %s", str);
  60. segcfg >>= 16;
  61. build_segment_config(str, segcfg);
  62. seq_printf(m, " 5 00000000 1G %s\n", str);
  63. return 0;
  64. }
  65. static int segments_open(struct inode *inode, struct file *file)
  66. {
  67. return single_open(file, show_segments, NULL);
  68. }
  69. static const struct file_operations segments_fops = {
  70. .open = segments_open,
  71. .read = seq_read,
  72. .llseek = seq_lseek,
  73. .release = single_release,
  74. };
  75. static int __init segments_info(void)
  76. {
  77. extern struct dentry *mips_debugfs_dir;
  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);