cpu-probe.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
  3. #include <linux/of.h>
  4. #include <linux/init.h>
  5. #include <linux/seq_file.h>
  6. #include <linux/memblock.h>
  7. #include <abi/reg_ops.h>
  8. static void percpu_print(void *arg)
  9. {
  10. struct seq_file *m = (struct seq_file *)arg;
  11. unsigned int cur, next, i;
  12. seq_printf(m, "processor : %d\n", smp_processor_id());
  13. seq_printf(m, "C-SKY CPU model : %s\n", CSKYCPU_DEF_NAME);
  14. /* read processor id, max is 100 */
  15. cur = mfcr("cr13");
  16. for (i = 0; i < 100; i++) {
  17. seq_printf(m, "product info[%d] : 0x%08x\n", i, cur);
  18. next = mfcr("cr13");
  19. /* some CPU only has one id reg */
  20. if (cur == next)
  21. break;
  22. cur = next;
  23. /* cpid index is 31-28, reset */
  24. if (!(next >> 28)) {
  25. while ((mfcr("cr13") >> 28) != i);
  26. break;
  27. }
  28. }
  29. /* CPU feature regs, setup by bootloader or gdbinit */
  30. seq_printf(m, "hint (CPU funcs): 0x%08x\n", mfcr_hint());
  31. seq_printf(m, "ccr (L1C & MMU): 0x%08x\n", mfcr("cr18"));
  32. seq_printf(m, "ccr2 (L2C) : 0x%08x\n", mfcr_ccr2());
  33. seq_printf(m, "\n");
  34. }
  35. static int c_show(struct seq_file *m, void *v)
  36. {
  37. int cpu;
  38. for_each_online_cpu(cpu)
  39. smp_call_function_single(cpu, percpu_print, m, true);
  40. #ifdef CSKY_ARCH_VERSION
  41. seq_printf(m, "arch-version : %s\n", CSKY_ARCH_VERSION);
  42. seq_printf(m, "\n");
  43. #endif
  44. return 0;
  45. }
  46. static void *c_start(struct seq_file *m, loff_t *pos)
  47. {
  48. return *pos < 1 ? (void *)1 : NULL;
  49. }
  50. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  51. {
  52. ++*pos;
  53. return NULL;
  54. }
  55. static void c_stop(struct seq_file *m, void *v) {}
  56. const struct seq_operations cpuinfo_op = {
  57. .start = c_start,
  58. .next = c_next,
  59. .stop = c_stop,
  60. .show = c_show,
  61. };