natfeat.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. asm("\n"
  20. " .global nf_get_id,nf_call\n"
  21. "nf_get_id:\n"
  22. " .short 0x7300\n"
  23. " rts\n"
  24. "nf_call:\n"
  25. " .short 0x7301\n"
  26. " rts\n"
  27. "1: moveq.l #0,%d0\n"
  28. " rts\n"
  29. " .section __ex_table,\"a\"\n"
  30. " .long nf_get_id,1b\n"
  31. " .long nf_call,1b\n"
  32. " .previous");
  33. EXPORT_SYMBOL_GPL(nf_get_id);
  34. EXPORT_SYMBOL_GPL(nf_call);
  35. static int stderr_id;
  36. static void nf_write(struct console *co, const char *str, unsigned int count)
  37. {
  38. char buf[68];
  39. buf[64] = 0;
  40. while (count > 64) {
  41. memcpy(buf, str, 64);
  42. nf_call(stderr_id, buf);
  43. str += 64;
  44. count -= 64;
  45. }
  46. memcpy(buf, str, count);
  47. buf[count] = 0;
  48. nf_call(stderr_id, buf);
  49. }
  50. void nfprint(const char *fmt, ...)
  51. {
  52. static char buf[256];
  53. va_list ap;
  54. int n;
  55. va_start(ap, fmt);
  56. n = vsnprintf(buf, 256, fmt, ap);
  57. nf_call(nf_get_id("NF_STDERR"), buf);
  58. va_end(ap);
  59. }
  60. static struct console nf_console_driver = {
  61. .name = "debug",
  62. .write = nf_write,
  63. .flags = CON_PRINTBUFFER,
  64. .index = -1,
  65. };
  66. static int __init nf_debug_setup(char *arg)
  67. {
  68. if (strcmp(arg, "emu"))
  69. return 0;
  70. stderr_id = nf_get_id("NF_STDERR");
  71. if (stderr_id)
  72. register_console(&nf_console_driver);
  73. return 0;
  74. }
  75. early_param("debug", nf_debug_setup);
  76. static void nf_poweroff(void)
  77. {
  78. long id = nf_get_id("NF_SHUTDOWN");
  79. if (id)
  80. nf_call(id);
  81. }
  82. void nf_init(void)
  83. {
  84. unsigned long id, version;
  85. char buf[256];
  86. id = nf_get_id("NF_VERSION");
  87. if (!id)
  88. return;
  89. version = nf_call(id);
  90. id = nf_get_id("NF_NAME");
  91. if (!id)
  92. return;
  93. nf_call(id, buf, 256);
  94. buf[255] = 0;
  95. pr_info("NatFeats found (%s, %lu.%lu)\n", buf, version >> 16,
  96. version & 0xffff);
  97. mach_power_off = nf_poweroff;
  98. }