summaryrefslogtreecommitdiffstats
path: root/pc-bios/vof/ci.c
blob: fc4821b3e970600431af31e39134ff119f0e4127 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "vof.h"

struct prom_args {
    uint32_t service;
    uint32_t nargs;
    uint32_t nret;
    uint32_t args[10];
};

typedef unsigned long prom_arg_t;

#define ADDR(x) (uint32_t)(x)

static int prom_handle(struct prom_args *pargs)
{
    void *rtasbase;
    uint32_t rtassize = 0;
    phandle rtas;

    if (strcmp("call-method", (void *)(unsigned long)pargs->service)) {
        return -1;
    }

    if (strcmp("instantiate-rtas", (void *)(unsigned long)pargs->args[0])) {
        return -1;
    }

    rtas = ci_finddevice("/rtas");
    /* rtas-size is set by QEMU depending of FWNMI support */
    ci_getprop(rtas, "rtas-size", &rtassize, sizeof(rtassize));
    if (rtassize < hv_rtas_size) {
        return -1;
    }

    rtasbase = (void *)(unsigned long) pargs->args[2];

    memcpy(rtasbase, hv_rtas, hv_rtas_size);
    pargs->args[pargs->nargs] = 0;
    pargs->args[pargs->nargs + 1] = pargs->args[2];

    return 0;
}

void prom_entry(uint32_t args)
{
    if (prom_handle((void *)(unsigned long) args)) {
        ci_entry(args);
    }
}

static int call_ci(const char *service, int nargs, int nret, ...)
{
    int i;
    struct prom_args args;
    va_list list;

    args.service = ADDR(service);
    args.nargs = nargs;
    args.nret = nret;

    va_start(list, nret);
    for (i = 0; i < nargs; i++) {
        args.args[i] = va_arg(list, prom_arg_t);
    }
    va_end(list);

    for (i = 0; i < nret; i++) {
        args.args[nargs + i] = 0;
    }

    if (ci_entry((uint32_t)(&args)) < 0) {
        return -1;
    }

    return (nret > 0) ? args.args[nargs] : 0;
}

void ci_panic(const char *str)
{
    call_ci("exit", 0, 0);
}

phandle ci_finddevice(const char *path)
{
    return call_ci("finddevice", 1, 1, path);
}

uint32_t ci_getprop(phandle ph, const char *propname, void *prop, int len)
{
    return call_ci("getprop", 4, 1, ph, propname, prop, len);
}