Petr Stehlik | 65cd577 | 2008-11-18 21:02:18 +0100 | [diff] [blame] | 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 | |
Geert Uytterhoeven | a4df02a | 2013-06-25 21:15:24 +0200 | [diff] [blame^] | 12 | #include <linux/init.h> |
Petr Stehlik | 65cd577 | 2008-11-18 21:02:18 +0100 | [diff] [blame] | 13 | #include <linux/types.h> |
| 14 | #include <linux/console.h> |
| 15 | #include <linux/string.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <asm/machdep.h> |
| 20 | #include <asm/natfeat.h> |
| 21 | |
Geert Uytterhoeven | 5549005 | 2013-08-14 10:45:00 +0200 | [diff] [blame] | 22 | extern long nf_get_id_phys(unsigned long feature_name); |
Geert Uytterhoeven | e8184e1 | 2013-07-26 00:08:25 +0200 | [diff] [blame] | 23 | |
Petr Stehlik | 65cd577 | 2008-11-18 21:02:18 +0100 | [diff] [blame] | 24 | asm("\n" |
Geert Uytterhoeven | 5549005 | 2013-08-14 10:45:00 +0200 | [diff] [blame] | 25 | " .global nf_get_id_phys,nf_call\n" |
| 26 | "nf_get_id_phys:\n" |
Petr Stehlik | 65cd577 | 2008-11-18 21:02:18 +0100 | [diff] [blame] | 27 | " .short 0x7300\n" |
| 28 | " rts\n" |
| 29 | "nf_call:\n" |
| 30 | " .short 0x7301\n" |
| 31 | " rts\n" |
| 32 | "1: moveq.l #0,%d0\n" |
| 33 | " rts\n" |
| 34 | " .section __ex_table,\"a\"\n" |
Geert Uytterhoeven | 5549005 | 2013-08-14 10:45:00 +0200 | [diff] [blame] | 35 | " .long nf_get_id_phys,1b\n" |
Petr Stehlik | 65cd577 | 2008-11-18 21:02:18 +0100 | [diff] [blame] | 36 | " .long nf_call,1b\n" |
| 37 | " .previous"); |
Petr Stehlik | 65cd577 | 2008-11-18 21:02:18 +0100 | [diff] [blame] | 38 | EXPORT_SYMBOL_GPL(nf_call); |
| 39 | |
Geert Uytterhoeven | e8184e1 | 2013-07-26 00:08:25 +0200 | [diff] [blame] | 40 | long nf_get_id(const char *feature_name) |
| 41 | { |
| 42 | /* feature_name may be in vmalloc()ed memory, so make a copy */ |
| 43 | char name_copy[32]; |
| 44 | size_t n; |
| 45 | |
| 46 | n = strlcpy(name_copy, feature_name, sizeof(name_copy)); |
| 47 | if (n >= sizeof(name_copy)) |
| 48 | return 0; |
| 49 | |
Geert Uytterhoeven | 5549005 | 2013-08-14 10:45:00 +0200 | [diff] [blame] | 50 | return nf_get_id_phys(virt_to_phys(name_copy)); |
Geert Uytterhoeven | e8184e1 | 2013-07-26 00:08:25 +0200 | [diff] [blame] | 51 | } |
| 52 | EXPORT_SYMBOL_GPL(nf_get_id); |
| 53 | |
Petr Stehlik | 65cd577 | 2008-11-18 21:02:18 +0100 | [diff] [blame] | 54 | void nfprint(const char *fmt, ...) |
| 55 | { |
| 56 | static char buf[256]; |
| 57 | va_list ap; |
| 58 | int n; |
| 59 | |
| 60 | va_start(ap, fmt); |
| 61 | n = vsnprintf(buf, 256, fmt, ap); |
Geert Uytterhoeven | 5549005 | 2013-08-14 10:45:00 +0200 | [diff] [blame] | 62 | nf_call(nf_get_id("NF_STDERR"), virt_to_phys(buf)); |
Petr Stehlik | 65cd577 | 2008-11-18 21:02:18 +0100 | [diff] [blame] | 63 | va_end(ap); |
| 64 | } |
| 65 | |
Petr Stehlik | 65cd577 | 2008-11-18 21:02:18 +0100 | [diff] [blame] | 66 | static void nf_poweroff(void) |
| 67 | { |
| 68 | long id = nf_get_id("NF_SHUTDOWN"); |
| 69 | |
| 70 | if (id) |
| 71 | nf_call(id); |
| 72 | } |
| 73 | |
Geert Uytterhoeven | a4df02a | 2013-06-25 21:15:24 +0200 | [diff] [blame^] | 74 | void __init nf_init(void) |
Petr Stehlik | 65cd577 | 2008-11-18 21:02:18 +0100 | [diff] [blame] | 75 | { |
| 76 | unsigned long id, version; |
| 77 | char buf[256]; |
| 78 | |
| 79 | id = nf_get_id("NF_VERSION"); |
| 80 | if (!id) |
| 81 | return; |
| 82 | version = nf_call(id); |
| 83 | |
| 84 | id = nf_get_id("NF_NAME"); |
| 85 | if (!id) |
| 86 | return; |
Geert Uytterhoeven | 5549005 | 2013-08-14 10:45:00 +0200 | [diff] [blame] | 87 | nf_call(id, virt_to_phys(buf), 256); |
Petr Stehlik | 65cd577 | 2008-11-18 21:02:18 +0100 | [diff] [blame] | 88 | buf[255] = 0; |
| 89 | |
| 90 | pr_info("NatFeats found (%s, %lu.%lu)\n", buf, version >> 16, |
| 91 | version & 0xffff); |
| 92 | |
| 93 | mach_power_off = nf_poweroff; |
| 94 | } |