pvr.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Support for MicroBlaze PVR (processor version register)
  3. *
  4. * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
  5. * Copyright (C) 2007-2009 PetaLogix
  6. * Copyright (C) 2007 John Williams <john.williams@petalogix.com>
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/compiler.h>
  14. #include <asm/exceptions.h>
  15. #include <asm/pvr.h>
  16. /*
  17. * Until we get an assembler that knows about the pvr registers,
  18. * this horrible cruft will have to do.
  19. * That hardcoded opcode is mfs r3, rpvrNN
  20. */
  21. #define get_single_pvr(pvrid, val) \
  22. { \
  23. register unsigned tmp __asm__("r3"); \
  24. tmp = 0x0; /* Prevent warning about unused */ \
  25. __asm__ __volatile__ ( \
  26. "mfs %0, rpvr" #pvrid ";" \
  27. : "=r" (tmp) : : "memory"); \
  28. val = tmp; \
  29. }
  30. /*
  31. * Does the CPU support the PVR register?
  32. * return value:
  33. * 0: no PVR
  34. * 1: simple PVR
  35. * 2: full PVR
  36. *
  37. * This must work on all CPU versions, including those before the
  38. * PVR was even an option.
  39. */
  40. int cpu_has_pvr(void)
  41. {
  42. unsigned long flags;
  43. unsigned pvr0;
  44. local_save_flags(flags);
  45. /* PVR bit in MSR tells us if there is any support */
  46. if (!(flags & PVR_MSR_BIT))
  47. return 0;
  48. get_single_pvr(0, pvr0);
  49. pr_debug("%s: pvr0 is 0x%08x\n", __func__, pvr0);
  50. if (pvr0 & PVR0_PVR_FULL_MASK)
  51. return 1;
  52. /* for partial PVR use static cpuinfo */
  53. return 2;
  54. }
  55. void get_pvr(struct pvr_s *p)
  56. {
  57. get_single_pvr(0, p->pvr[0]);
  58. get_single_pvr(1, p->pvr[1]);
  59. get_single_pvr(2, p->pvr[2]);
  60. get_single_pvr(3, p->pvr[3]);
  61. get_single_pvr(4, p->pvr[4]);
  62. get_single_pvr(5, p->pvr[5]);
  63. get_single_pvr(6, p->pvr[6]);
  64. get_single_pvr(7, p->pvr[7]);
  65. get_single_pvr(8, p->pvr[8]);
  66. get_single_pvr(9, p->pvr[9]);
  67. get_single_pvr(10, p->pvr[10]);
  68. get_single_pvr(11, p->pvr[11]);
  69. }