source: trunk/packages/xen-3.1/xen-3.1/xen/arch/powerpc/rtas.c @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 2.3 KB
Line 
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
15 *
16 * Copyright (C) IBM Corp. 2006
17 *
18 * Authors: Jimi Xenidis <jimix@watson.ibm.com>
19 */
20
21#include <xen/config.h>
22#include <xen/init.h>
23#include <xen/lib.h>
24#include <xen/errno.h>
25#include "of-devtree.h"
26#include "rtas.h"
27
28static int rtas_halt_token = -1;
29static int rtas_reboot_token = -1;
30int rtas_entry;
31unsigned long rtas_msr;
32unsigned long rtas_base;
33unsigned long rtas_end;
34
35struct rtas_args {
36    int ra_token;
37    int ra_nargs;
38    int ra_nrets;
39    int ra_args[10];
40} __attribute__ ((aligned(8)));
41
42static int rtas_call(struct rtas_args *r)
43{
44    if (rtas_entry == 0)
45        return -ENOSYS;
46
47    return prom_call(r, rtas_base, rtas_entry, rtas_msr);
48}
49
50int __init rtas_init(void *m)
51{
52    static const char halt[] = "power-off";
53    static const char reboot[] = "system-reboot";
54    ofdn_t n;
55
56    if (rtas_entry == 0)
57        return -ENOSYS;
58
59    n = ofd_node_find(m, "/rtas");
60    if (n <= 0)
61        return -ENOSYS;
62
63    ofd_getprop(m, n, halt,
64                &rtas_halt_token, sizeof (rtas_halt_token));
65    ofd_getprop(m, n, reboot,
66                &rtas_reboot_token, sizeof (rtas_reboot_token));
67    return 1;
68}
69
70int
71rtas_halt(void)
72{
73    struct rtas_args r;
74
75    if (rtas_halt_token == -1)
76        return -1;
77
78    r.ra_token = rtas_halt_token;
79    r.ra_nargs = 2;
80    r.ra_nrets = 1;
81    r.ra_args[0] = 0;
82    r.ra_args[1] = 0;
83
84    return rtas_call(&r);
85}
86
87int
88rtas_reboot(void)
89{
90    struct rtas_args r;
91
92    if (rtas_reboot_token == -1)
93        return -ENOSYS;
94
95    r.ra_token = rtas_reboot_token;
96    r.ra_nargs = 2;
97    r.ra_nrets = 1;
98    r.ra_args[0] = 0;
99    r.ra_args[1] = 0;
100
101    return rtas_call(&r);
102}
Note: See TracBrowser for help on using the repository browser.