~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to .pc/linaro-patches-1.5.0/0038-hw-omap_uart.c-Forbid-extended-MCR-bit-writes-unless.patch/hw/char/omap_uart.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-10-22 22:47:07 UTC
  • mfrom: (1.8.3) (10.1.42 sid)
  • Revision ID: package-import@ubuntu.com-20131022224707-1lya34fw3k3f24tv
Tags: 1.6.0+dfsg-2ubuntu1
* Merge 1.6.0~rc0+dfsg-2exp from debian experimental.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
      - drop openbios-ppc and openhackware Depends to Suggests (for now)
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - New linaro patches from qemu-linaro rebasing branch
  - Dropped patches:
    * xen-simplify-xen_enabled.patch
    * sparc-linux-user-fix-missing-symbols-in-.rel-.rela.plt-sections.patch
    * main_loop-do-not-set-nonblocking-if-xen_enabled.patch
    * xen_machine_pv-do-not-create-a-dummy-CPU-in-machine-.patch
    * virtio-rng-fix-crash
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * linaro arm patches from qemu-linaro rebasing branch
  - New patches:
    * fix-pci-add: change CONFIG variable in ifdef to make sure that
      pci_add is defined.
* Add linaro patches
* Add experimental mach-virt patches for arm virtualization.
* qemu-system-common.install: add debian/tmp/usr/lib to install the
  qemu-bridge-helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * TI OMAP processors UART emulation.
3
 
 *
4
 
 * Copyright (C) 2006-2008 Andrzej Zaborowski  <balrog@zabor.org>
5
 
 * Copyright (C) 2007-2009 Nokia Corporation
6
 
 *
7
 
 * This program is free software; you can redistribute it and/or
8
 
 * modify it under the terms of the GNU General Public License as
9
 
 * published by the Free Software Foundation; either version 2 or
10
 
 * (at your option) version 3 of the License.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 * GNU General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU General Public License along
18
 
 * with this program; if not, see <http://www.gnu.org/licenses/>.
19
 
 */
20
 
#include "sysemu/char.h"
21
 
#include "hw/hw.h"
22
 
#include "hw/arm/omap.h"
23
 
#include "hw/char/serial.h"
24
 
#include "exec/address-spaces.h"
25
 
#include "hw/sysbus.h"
26
 
 
27
 
/* The OMAP UART functionality is similar to the TI16C752; it is
28
 
 * an enhanced version of the 16550A and we piggy-back on the 16550
29
 
 * model.
30
 
 *
31
 
 * Currently unmodelled functionality:
32
 
 *  + We should have a 64 byte FIFO but QEMU's SerialState emulation
33
 
 *    always uses a 16 byte FIFO
34
 
 *  + DMA
35
 
 *  + interrupts based on TCR/TLR values
36
 
 *  + XON/XOFF flow control
37
 
 *  + UASR auto-baudrate-detection
38
 
 */
39
 
 
40
 
struct omap_uart_s {
41
 
    SysBusDevice busdev;
42
 
    MemoryRegion iomem;
43
 
    CharDriverState *chr;
44
 
    SerialState *serial; /* TODO */
45
 
    const MemoryRegionOps *serial_ops;
46
 
    uint32_t mmio_size;
47
 
    uint32_t baudrate;
48
 
    qemu_irq tx_drq;
49
 
    qemu_irq rx_drq;
50
 
 
51
 
    /* Register access mode, which affects what registers you see */
52
 
    enum {
53
 
        regs_operational,
54
 
        regs_config_a,
55
 
        regs_config_b
56
 
    } access_mode;
57
 
 
58
 
    uint8_t eblr;
59
 
    uint8_t syscontrol;
60
 
    uint8_t wkup;
61
 
    uint8_t cfps;
62
 
    uint8_t mdr[2];
63
 
    uint8_t scr;
64
 
    uint8_t clksel;
65
 
    uint8_t blr;
66
 
    uint8_t acreg;
67
 
 
68
 
    uint8_t mcr_cache;
69
 
    uint8_t efr;
70
 
    uint8_t tcr;
71
 
    uint8_t tlr;
72
 
    uint8_t xon[2], xoff[2];
73
 
};
74
 
 
75
 
static int tcr_tlr_mode(struct omap_uart_s *s)
76
 
{
77
 
    /* Return true if registers 0x18 and 0x1c are TCR/TLR
78
 
     * (as opposed to SPR/MSR/XOFF)
79
 
     */
80
 
    return (s->efr & 0x10) && (s->mcr_cache & 0x40);
81
 
}
82
 
 
83
 
static void omap_uart_reset(DeviceState *qdev)
84
 
{
85
 
    struct omap_uart_s *s = FROM_SYSBUS(struct omap_uart_s,
86
 
                                        SYS_BUS_DEVICE(qdev));
87
 
    s->eblr = 0x00;
88
 
    s->syscontrol = 0;
89
 
    s->wkup = 0x3f;
90
 
    s->cfps = 0x69;
91
 
    s->clksel = 0;
92
 
    s->blr = 0x40;
93
 
    s->acreg = 0;
94
 
    s->access_mode = regs_operational;
95
 
 
96
 
    s->mcr_cache = 0;
97
 
    s->tcr = 0x0f;
98
 
    s->tlr = 0;
99
 
    s->efr = 0;
100
 
    s->xon[0] = s->xon[1] = 0;
101
 
    s->xoff[0] = s->xoff[1] = 0;
102
 
}
103
 
 
104
 
static uint64_t omap_uart_read(void *opaque, hwaddr addr,
105
 
                               unsigned size)
106
 
{
107
 
    struct omap_uart_s *s = (struct omap_uart_s *) opaque;
108
 
 
109
 
    switch (addr) {
110
 
    case 0x00:
111
 
    case 0x04:
112
 
    case 0x0c:
113
 
        return s->serial_ops->read(s->serial, addr, size);
114
 
    case 0x08:
115
 
        if (s->access_mode == regs_config_b) {
116
 
            return s->efr;
117
 
        }
118
 
        return s->serial_ops->read(s->serial, addr, size);
119
 
    case 0x10:
120
 
    case 0x14:
121
 
        if (s->access_mode == regs_config_b) {
122
 
            return s->xon[(addr & 7) >> 2];
123
 
        } else if (addr == 0x10) {
124
 
            return s->serial_ops->read(s->serial, addr, size)
125
 
                   | (s->mcr_cache & 0xe0);
126
 
        }
127
 
        return s->serial_ops->read(s->serial, addr, size);
128
 
    case 0x18:
129
 
    case 0x1c:
130
 
        if (tcr_tlr_mode(s)) {
131
 
            return (addr == 0x18) ? s->tcr : s->tlr;
132
 
        }
133
 
        if (s->access_mode == regs_config_b) {
134
 
            return s->xoff[(addr & 7) >> 2];
135
 
        }
136
 
        return s->serial_ops->read(s->serial, addr, size);
137
 
    case 0x20:  /* MDR1 */
138
 
        return s->mdr[0];
139
 
    case 0x24:  /* MDR2 */
140
 
        return s->mdr[1];
141
 
    case 0x28: /* SFLSR */
142
 
        return 0;
143
 
    case 0x2c: /* RESUME */
144
 
        return 0;
145
 
    case 0x30: /* SFREGL */
146
 
        return 0;
147
 
    case 0x34: /* SFREGH */
148
 
        return 0;
149
 
    case 0x38: /* UASR/BLR */
150
 
        if (s->access_mode != regs_operational) {
151
 
            return 0; /* FIXME: return correct autodetect value */
152
 
        }
153
 
        return s->blr;
154
 
    case 0x3c: /* ACREG */
155
 
        return (s->access_mode != regs_operational) ? 0 : s->acreg;
156
 
    case 0x40:  /* SCR */
157
 
        return s->scr;
158
 
    case 0x44:  /* SSR */
159
 
        return 0x0;
160
 
    case 0x48:  /* EBLR (OMAP2) */
161
 
        return s->eblr;
162
 
    case 0x4C:  /* OSC_12M_SEL (OMAP1) */
163
 
        return s->clksel;
164
 
    case 0x50:  /* MVR */
165
 
        return 0x30;
166
 
    case 0x54:  /* SYSC (OMAP2) */
167
 
        return s->syscontrol;
168
 
    case 0x58:  /* SYSS (OMAP2) */
169
 
        return 1;
170
 
    case 0x5c:  /* WER (OMAP2) */
171
 
        return s->wkup;
172
 
    case 0x60:  /* CFPS (OMAP2) */
173
 
        return s->cfps;
174
 
    }
175
 
 
176
 
    OMAP_BAD_REG(addr);
177
 
    return 0;
178
 
}
179
 
 
180
 
static void omap_uart_write(void *opaque, hwaddr addr,
181
 
                            uint64_t value, unsigned size)
182
 
{
183
 
    struct omap_uart_s *s = (struct omap_uart_s *) opaque;
184
 
 
185
 
    switch (addr) {
186
 
    case 0x00:
187
 
    case 0x04:
188
 
        s->serial_ops->write(s->serial, addr, value, size);
189
 
        break;
190
 
    case 0x08:
191
 
        if (s->access_mode == regs_config_b) {
192
 
            s->efr = value;
193
 
        } else {
194
 
            s->serial_ops->write(s->serial, addr, value, size);
195
 
        }
196
 
        break;
197
 
    case 0x0c:
198
 
        if ((value & 0xff) == 0xbf) {
199
 
            s->access_mode = regs_config_b;
200
 
        } else if (value & 0x80) {
201
 
            s->access_mode = regs_config_a;
202
 
        } else {
203
 
            s->access_mode = regs_operational;
204
 
        }
205
 
        s->serial_ops->write(s->serial, addr, value, size);
206
 
        break;
207
 
    case 0x10:
208
 
    case 0x14:
209
 
        if (s->access_mode == regs_config_b) {
210
 
            s->xon[(addr & 7) >> 2] = value;
211
 
        } else {
212
 
            if (addr == 0x10) {
213
 
                s->mcr_cache = value & 0x7f;
214
 
            }
215
 
            s->serial_ops->write(s->serial, addr, value, size);
216
 
        }
217
 
        break;
218
 
    case 0x18:
219
 
    case 0x1c:
220
 
        if (tcr_tlr_mode(s)) {
221
 
            if (addr == 0x18) {
222
 
                s->tcr = value & 0xff;
223
 
            } else {
224
 
                s->tlr = value & 0xff;
225
 
            }
226
 
        } else if (s->access_mode == regs_config_b) {
227
 
            s->xoff[(addr & 7) >> 2] = value;
228
 
        } else {
229
 
            s->serial_ops->write(s->serial, addr, value, size);
230
 
        }
231
 
        break;
232
 
    case 0x20:  /* MDR1 */
233
 
        s->mdr[0] = value & 0x7f;
234
 
        break;
235
 
    case 0x24:  /* MDR2 */
236
 
        s->mdr[1] = value & 0xff;
237
 
        break;
238
 
    case 0x28: /* TXFLL */
239
 
    case 0x2c: /* TXFLH */
240
 
    case 0x30: /* RXFLL */
241
 
    case 0x34: /* RXFLH */
242
 
        /* ignored */
243
 
        break;
244
 
    case 0x38: /* BLR */
245
 
        if (s->access_mode == regs_operational) {
246
 
            s->blr = value & 0xc0;
247
 
        }
248
 
        break;
249
 
    case 0x3c: /* ACREG */
250
 
        if (s->access_mode == regs_operational) {
251
 
            s->acreg = value & 0xff;
252
 
        }
253
 
        break;
254
 
    case 0x40:  /* SCR */
255
 
        s->scr = value & 0xff;
256
 
        break;
257
 
    case 0x44:  /* SSR */
258
 
        OMAP_RO_REG(addr);
259
 
        break;
260
 
    case 0x48:  /* EBLR (OMAP2) */
261
 
        s->eblr = value & 0xff;
262
 
        break;
263
 
    case 0x4C:  /* OSC_12M_SEL (OMAP1) */
264
 
        s->clksel = value & 1;
265
 
        break;
266
 
    case 0x50:  /* MVR */
267
 
        OMAP_RO_REG(addr);
268
 
        break;
269
 
    case 0x54:  /* SYSC (OMAP2) */
270
 
        s->syscontrol = value & 0x1d;
271
 
        if (value & 2) {
272
 
            /* TODO: reset s->serial also. */
273
 
            omap_uart_reset(&s->busdev.qdev);
274
 
        }
275
 
        break;
276
 
    case 0x58:  /* SYSS (OMAP2) */
277
 
        OMAP_RO_REG(addr);
278
 
        break;
279
 
    case 0x5c:  /* WER (OMAP2) */
280
 
        s->wkup = value & 0x7f;
281
 
        break;
282
 
    case 0x60:  /* CFPS (OMAP2) */
283
 
        s->cfps = value & 0xff;
284
 
        break;
285
 
    default:
286
 
        OMAP_BAD_REG(addr);
287
 
    }
288
 
}
289
 
 
290
 
static const MemoryRegionOps omap_uart_ops = {
291
 
    .read = omap_uart_read,
292
 
    .write = omap_uart_write,
293
 
    .endianness = DEVICE_NATIVE_ENDIAN,
294
 
};
295
 
 
296
 
static int omap_uart_init(SysBusDevice *busdev)
297
 
{
298
 
    struct omap_uart_s *s = FROM_SYSBUS(struct omap_uart_s, busdev);
299
 
    if (!s->chr) {
300
 
        s->chr = qemu_chr_new(busdev->qdev.id, "null", NULL);
301
 
    }
302
 
    /* TODO: DMA support. Current 16550A emulation does not emulate DMA mode
303
 
     * transfers via TXRDY/RXRDY pins. We create DMA irq lines here for
304
 
     * future use nevertheless. */
305
 
    /* Nasty hackery because trying to extend an existing device is
306
 
     * not really supported, and the serial driver isn't even qdev.
307
 
     */
308
 
    s->serial = serial_mm_init(NULL, 0, 2, NULL, s->baudrate, s->chr,
309
 
                               DEVICE_NATIVE_ENDIAN);
310
 
    s->serial_ops = serial_get_memops(DEVICE_NATIVE_ENDIAN);
311
 
    sysbus_init_irq(busdev, serial_get_irq(s->serial));
312
 
    sysbus_init_irq(busdev, &s->tx_drq);
313
 
    sysbus_init_irq(busdev, &s->rx_drq);
314
 
    memory_region_init_io(&s->iomem, &omap_uart_ops, s, "omap_uart",
315
 
                          s->mmio_size);
316
 
    sysbus_init_mmio(busdev, &s->iomem);
317
 
    return 0;
318
 
}
319
 
 
320
 
static Property omap_uart_properties[] = {
321
 
    DEFINE_PROP_UINT32("mmio_size", struct omap_uart_s, mmio_size, 0x400),
322
 
    DEFINE_PROP_UINT32("baudrate", struct omap_uart_s, baudrate, 0),
323
 
    DEFINE_PROP_CHR("chardev", struct omap_uart_s, chr),
324
 
    DEFINE_PROP_END_OF_LIST()
325
 
};
326
 
 
327
 
static void omap_uart_class_init(ObjectClass *klass, void *data)
328
 
{
329
 
    DeviceClass *dc = DEVICE_CLASS(klass);
330
 
    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
331
 
    k->init = omap_uart_init;
332
 
    dc->props = omap_uart_properties;
333
 
    dc->reset = omap_uart_reset;
334
 
}
335
 
 
336
 
static TypeInfo omap_uart_info = {
337
 
    .name = "omap_uart",
338
 
    .parent = TYPE_SYS_BUS_DEVICE,
339
 
    .instance_size = sizeof(struct omap_uart_s),
340
 
    .class_init = omap_uart_class_init,
341
 
};
342
 
 
343
 
static void omap_uart_register_types(void)
344
 
{
345
 
    type_register_static(&omap_uart_info);
346
 
}
347
 
 
348
 
void omap_uart_attach(DeviceState *qdev, CharDriverState *chr,
349
 
                      const char *label)
350
 
{
351
 
    struct omap_uart_s *s = FROM_SYSBUS(struct omap_uart_s,
352
 
                                        SYS_BUS_DEVICE(qdev));
353
 
    s->chr = chr ?: qemu_chr_new(label, "null", NULL);
354
 
    serial_change_char_driver(s->serial, s->chr);
355
 
}
356
 
 
357
 
type_init(omap_uart_register_types)