natfeat.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * natfeat.c - ARAnyM hardware support via Native Features (natfeats)
  3. *
  4. * Copyright (c) 2005 Petr Stehlik of ARAnyM dev team
  5. *
  6. * Reworked for Linux by Roman Zippel <zippel@linux-m68k.org>
  7. *
  8. * This software may be used and distributed according to the terms of
  9. * the GNU General Public License (GPL), incorporated herein by reference.
  10. */
  11. #include <linux/types.h>
  12. #include <linux/console.h>
  13. #include <linux/string.h>
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/io.h>
  17. #include <asm/machdep.h>
  18. #include <asm/natfeat.h>
  19. extern long nf_get_id2(const char *feature_name);
  20. asm("\n"
  21. " .global nf_get_id2,nf_call\n"
  22. "nf_get_id2:\n"
  23. " .short 0x7300\n"
  24. " rts\n"
  25. "nf_call:\n"
  26. " .short 0x7301\n"
  27. " rts\n"
  28. "1: moveq.l #0,%d0\n"
  29. " rts\n"
  30. " .section __ex_table,\"a\"\n"
  31. " .long nf_get_id2,1b\n"
  32. " .long nf_call,1b\n"
  33. " .previous");
  34. EXPORT_SYMBOL_GPL(nf_call);
  35. long nf_get_id(const char *feature_name)
  36. {
  37. /* feature_name may be in vmalloc()ed memory, so make a copy */
  38. char name_copy[32];
  39. size_t n;
  40. n = strlcpy(name_copy, feature_name, sizeof(name_copy));
  41. if (n >= sizeof(name_copy))
  42. return 0;
  43. return nf_get_id2(name_copy);
  44. }
  45. EXPORT_SYMBOL_GPL(nf_get_id);
  46. void nfprint(const char *fmt, ...)
  47. {
  48. static char buf[256];
  49. va_list ap;
  50. int n;
  51. va_start(ap, fmt);
  52. n = vsnprintf(buf, 256, fmt, ap);
  53. nf_call(nf_get_id("NF_STDERR"), buf);
  54. va_end(ap);
  55. }
  56. static void nf_poweroff(void)
  57. {
  58. long id = nf_get_id("NF_SHUTDOWN");
  59. if (id)
  60. nf_call(id);
  61. }
  62. void nf_init(void)
  63. {
  64. unsigned long id, version;
  65. char buf[256];
  66. id = nf_get_id("NF_VERSION");
  67. if (!id)
  68. return;
  69. version = nf_call(id);
  70. id = nf_get_id("NF_NAME");
  71. if (!id)
  72. return;
  73. nf_call(id, buf, 256);
  74. buf[255] = 0;
  75. pr_info("NatFeats found (%s, %lu.%lu)\n", buf, version >> 16,
  76. version & 0xffff);
  77. mach_power_off = nf_poweroff;
  78. }