Merge tag 'mm-stable-2023-09-04-14-00' of git://git.kernel.org/pub/scm/linux/kernel...
[platform/kernel/linux-rpi.git] / arch / m68k / emu / natfeat.c
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
12 #include <linux/init.h>
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/reboot.h>
19 #include <linux/io.h>
20 #include <asm/machdep.h>
21 #include <asm/natfeat.h>
22
23 extern long nf_get_id_phys(unsigned long feature_name);
24
25 asm("\n"
26 "       .global nf_get_id_phys,nf_call\n"
27 "nf_get_id_phys:\n"
28 "       .short  0x7300\n"
29 "       rts\n"
30 "nf_call:\n"
31 "       .short  0x7301\n"
32 "       rts\n"
33 "1:     moveq.l #0,%d0\n"
34 "       rts\n"
35 "       .section __ex_table,\"a\"\n"
36 "       .long   nf_get_id_phys,1b\n"
37 "       .long   nf_call,1b\n"
38 "       .previous");
39 EXPORT_SYMBOL_GPL(nf_call);
40
41 long nf_get_id(const char *feature_name)
42 {
43         /* feature_name may be in vmalloc()ed memory, so make a copy */
44         char name_copy[32];
45         size_t n;
46
47         n = strlcpy(name_copy, feature_name, sizeof(name_copy));
48         if (n >= sizeof(name_copy))
49                 return 0;
50
51         return nf_get_id_phys(virt_to_phys(name_copy));
52 }
53 EXPORT_SYMBOL_GPL(nf_get_id);
54
55 void nfprint(const char *fmt, ...)
56 {
57         static char buf[256];
58         va_list ap;
59         int n;
60
61         va_start(ap, fmt);
62         n = vsnprintf(buf, 256, fmt, ap);
63         nf_call(nf_get_id("NF_STDERR"), virt_to_phys(buf));
64         va_end(ap);
65 }
66
67 static void nf_poweroff(void)
68 {
69         long id = nf_get_id("NF_SHUTDOWN");
70
71         if (id)
72                 nf_call(id);
73 }
74
75 void __init nf_init(void)
76 {
77         unsigned long id, version;
78         char buf[256];
79
80         id = nf_get_id("NF_VERSION");
81         if (!id)
82                 return;
83         version = nf_call(id);
84
85         id = nf_get_id("NF_NAME");
86         if (!id)
87                 return;
88         nf_call(id, virt_to_phys(buf), 256);
89         buf[255] = 0;
90
91         pr_info("NatFeats found (%s, %lu.%lu)\n", buf, version >> 16,
92                 version & 0xffff);
93
94         register_platform_power_off(nf_poweroff);
95 }