aboutsummaryrefslogtreecommitdiff
path: root/machine/finisher.c
blob: ed6604e29be14a85e188a655ea63be39f28103b1 (plain)
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
// See LICENSE for license details.

#include <string.h>
#include "finisher.h"
#include "fdt.h"

volatile uint32_t* finisher;

void finisher_exit(uint16_t code)
{
  if (!finisher) return;
  if (code == 0) {
    *finisher = FINISHER_PASS;
  } else {
    *finisher = code << 16 | FINISHER_FAIL;
  }
}

struct finisher_scan
{
  int compat;
  uint64_t reg;
};

static void finisher_open(const struct fdt_scan_node *node, void *extra)
{
  struct finisher_scan *scan = (struct finisher_scan *)extra;
  memset(scan, 0, sizeof(*scan));
}

static void finisher_prop(const struct fdt_scan_prop *prop, void *extra)
{
  struct finisher_scan *scan = (struct finisher_scan *)extra;
  if (!strcmp(prop->name, "compatible") && fdt_string_list_index(prop, "sifive,test0") >= 0) {
    scan->compat = 1;
  } else if (!strcmp(prop->name, "reg")) {
    fdt_get_address(prop->node->parent, prop->value, &scan->reg);
  }
}

static void finisher_done(const struct fdt_scan_node *node, void *extra)
{
  struct finisher_scan *scan = (struct finisher_scan *)extra;
  if (!scan->compat || !scan->reg || finisher) return;
  finisher = (uint32_t*)(uintptr_t)scan->reg;
}

void query_finisher(uintptr_t fdt)
{
  struct fdt_cb cb;
  struct finisher_scan scan;

  memset(&cb, 0, sizeof(cb));
  cb.open = finisher_open;
  cb.prop = finisher_prop;
  cb.done = finisher_done;
  cb.extra = &scan;

  fdt_scan(fdt, &cb);
}