~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/skiboot/platforms/qemu/qemu.c

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2013-2014 IBM Corp.
 
2
 *
 
3
 * Licensed under the Apache License, Version 2.0 (the "License");
 
4
 * you may not use this file except in compliance with the License.
 
5
 * You may obtain a copy of the License at
 
6
 *
 
7
 *      http://www.apache.org/licenses/LICENSE-2.0
 
8
 *
 
9
 * Unless required by applicable law or agreed to in writing, software
 
10
 * distributed under the License is distributed on an "AS IS" BASIS,
 
11
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 
12
 * implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
 
 
18
#include <skiboot.h>
 
19
#include <device.h>
 
20
#include <lpc.h>
 
21
#include <console.h>
 
22
#include <opal.h>
 
23
#include <psi.h>
 
24
 
 
25
static void qemu_init(void)
 
26
{
 
27
        /* Setup UART console for use by Linux via OPAL API */
 
28
        if (!dummy_console_enabled())
 
29
                uart_setup_opal_console();
 
30
 
 
31
        /* Setup LPC RTC and use it as time source. Call after
 
32
         * chiptod_init()
 
33
         */
 
34
        lpc_rtc_init();
 
35
}
 
36
 
 
37
static void qemu_dt_fixup_uart(struct dt_node *lpc)
 
38
{
 
39
        /*
 
40
         * The official OF ISA/LPC binding is a bit odd, it prefixes
 
41
         * the unit address for IO with "i". It uses 2 cells, the first
 
42
         * one indicating IO vs. Memory space (along with bits to
 
43
         * represent aliasing).
 
44
         *
 
45
         * We pickup that binding and add to it "2" as a indication
 
46
         * of FW space.
 
47
         *
 
48
         * TODO: Probe the UART instead if the LPC bus allows for it
 
49
         */
 
50
        struct dt_node *uart;
 
51
        char namebuf[32];
 
52
#define UART_IO_BASE    0x3f8
 
53
#define UART_IO_COUNT   8
 
54
#define UART_LPC_IRQ    4
 
55
 
 
56
        snprintf(namebuf, sizeof(namebuf), "serial@i%x", UART_IO_BASE);
 
57
        uart = dt_new(lpc, namebuf);
 
58
 
 
59
        dt_add_property_cells(uart, "reg",
 
60
                              1, /* IO space */
 
61
                              UART_IO_BASE, UART_IO_COUNT);
 
62
        dt_add_property_strings(uart, "compatible",
 
63
                                "ns16550",
 
64
                                "pnpPNP,501");
 
65
        dt_add_property_cells(uart, "clock-frequency", 1843200);
 
66
        dt_add_property_cells(uart, "current-speed", 115200);
 
67
        dt_add_property_cells(uart, "interrupts", UART_LPC_IRQ);
 
68
        dt_add_property_cells(uart, "interrupt-parent", lpc->phandle);
 
69
 
 
70
        /*
 
71
         * This is needed by Linux for some obscure reasons,
 
72
         * we'll eventually need to sanitize it but in the meantime
 
73
         * let's make sure it's there
 
74
         */
 
75
        dt_add_property_strings(uart, "device_type", "serial");
 
76
}
 
77
 
 
78
/*
 
79
 * This adds the legacy RTC device to the device-tree
 
80
 * for Linux to use
 
81
 */
 
82
static void qemu_dt_fixup_rtc(struct dt_node *lpc)
 
83
{
 
84
        struct dt_node *rtc;
 
85
        char namebuf[32];
 
86
 
 
87
        /*
 
88
         * Follows the structure expected by the kernel file
 
89
         * arch/powerpc/sysdev/rtc_cmos_setup.c
 
90
         */
 
91
        snprintf(namebuf, sizeof(namebuf), "rtc@i%x", 0x70);
 
92
        rtc = dt_new(lpc, namebuf);
 
93
        dt_add_property_string(rtc, "compatible", "pnpPNP,b00");
 
94
        dt_add_property_cells(rtc, "reg",
 
95
                              1, /* IO space */
 
96
                              0x70, 2);
 
97
}
 
98
 
 
99
static void qemu_dt_fixup(void)
 
100
{
 
101
        struct dt_node *n, *primary_lpc = NULL;
 
102
 
 
103
        /* Find the primary LPC bus */
 
104
        dt_for_each_compatible(dt_root, n, "ibm,power8-lpc") {
 
105
                if (!primary_lpc || dt_has_node_property(n, "primary", NULL))
 
106
                        primary_lpc = n;
 
107
                if (dt_has_node_property(n, "#address-cells", NULL))
 
108
                        break;
 
109
        }
 
110
 
 
111
        if (!primary_lpc)
 
112
                return;
 
113
 
 
114
        qemu_dt_fixup_rtc(primary_lpc);
 
115
        qemu_dt_fixup_uart(primary_lpc);
 
116
}
 
117
 
 
118
static void qemu_ext_irq_serirq_cpld(unsigned int chip_id)
 
119
{
 
120
        lpc_all_interrupts(chip_id);
 
121
}
 
122
 
 
123
static bool qemu_probe(void)
 
124
{
 
125
        if (!dt_node_is_compatible(dt_root, "qemu,powernv"))
 
126
                return false;
 
127
 
 
128
        /* Add missing bits of device-tree such as the UART */
 
129
        qemu_dt_fixup();
 
130
 
 
131
        psi_set_external_irq_policy(EXTERNAL_IRQ_POLICY_SKIBOOT);
 
132
 
 
133
        /* Setup UART and use it as console */
 
134
        uart_init();
 
135
 
 
136
        return true;
 
137
}
 
138
 
 
139
DECLARE_PLATFORM(qemu) = {
 
140
        .name           = "Qemu",
 
141
        .probe          = qemu_probe,
 
142
        .init           = qemu_init,
 
143
        .external_irq   = qemu_ext_irq_serirq_cpld,
 
144
};