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