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

« back to all changes in this revision

Viewing changes to .pc/linaro-patches-1.5.0/0037-hw-omap_uart.c-Refactor-register-access-mode-tests.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
 
    uint8_t lcr_cache;
52
 
    uint8_t eblr;
53
 
    uint8_t syscontrol;
54
 
    uint8_t wkup;
55
 
    uint8_t cfps;
56
 
    uint8_t mdr[2];
57
 
    uint8_t scr;
58
 
    uint8_t clksel;
59
 
    uint8_t blr;
60
 
    uint8_t acreg;
61
 
 
62
 
    uint8_t mcr_cache;
63
 
    uint8_t efr;
64
 
    uint8_t tcr;
65
 
    uint8_t tlr;
66
 
    uint8_t xon[2], xoff[2];
67
 
};
68
 
 
69
 
static void omap_uart_reset(DeviceState *qdev)
70
 
{
71
 
    struct omap_uart_s *s = FROM_SYSBUS(struct omap_uart_s,
72
 
                                        SYS_BUS_DEVICE(qdev));
73
 
    s->eblr = 0x00;
74
 
    s->syscontrol = 0;
75
 
    s->wkup = 0x3f;
76
 
    s->cfps = 0x69;
77
 
    s->clksel = 0;
78
 
    s->blr = 0x40;
79
 
    s->acreg = 0;
80
 
    s->lcr_cache = 0;
81
 
 
82
 
    s->mcr_cache = 0;
83
 
    s->tcr = 0x0f;
84
 
    s->tlr = 0;
85
 
    s->efr = 0;
86
 
    s->xon[0] = s->xon[1] = 0;
87
 
    s->xoff[0] = s->xoff[1] = 0;
88
 
}
89
 
 
90
 
static uint64_t omap_uart_read(void *opaque, hwaddr addr,
91
 
                               unsigned size)
92
 
{
93
 
    struct omap_uart_s *s = (struct omap_uart_s *) opaque;
94
 
 
95
 
    switch (addr) {
96
 
    case 0x00:
97
 
    case 0x04:
98
 
    case 0x0c:
99
 
        return s->serial_ops->read(s->serial, addr, size);
100
 
    case 0x08:
101
 
        if (s->lcr_cache == 0xbf) {
102
 
            return s->efr;
103
 
        }
104
 
        return s->serial_ops->read(s->serial, addr, size);
105
 
    case 0x10:
106
 
    case 0x14:
107
 
        if (s->lcr_cache == 0xbf) {
108
 
            return s->xon[(addr & 7) >> 2];
109
 
        } else if (addr == 0x10) {
110
 
            return s->serial_ops->read(s->serial, addr, size)
111
 
                   | (s->mcr_cache & 0xe0);
112
 
        }
113
 
        return s->serial_ops->read(s->serial, addr, size);
114
 
    case 0x18:
115
 
    case 0x1c:
116
 
        if ((s->efr & 0x10) && (s->mcr_cache & 0x40)) {
117
 
            return (addr == 0x18) ? s->tcr : s->tlr;
118
 
        }
119
 
        if (s->lcr_cache == 0xbf) {
120
 
            return s->xoff[(addr & 7) >> 2];
121
 
        }
122
 
        return s->serial_ops->read(s->serial, addr, size);
123
 
    case 0x20:  /* MDR1 */
124
 
        return s->mdr[0];
125
 
    case 0x24:  /* MDR2 */
126
 
        return s->mdr[1];
127
 
    case 0x28: /* SFLSR */
128
 
        return 0;
129
 
    case 0x2c: /* RESUME */
130
 
        return 0;
131
 
    case 0x30: /* SFREGL */
132
 
        return 0;
133
 
    case 0x34: /* SFREGH */
134
 
        return 0;
135
 
    case 0x38: /* UASR/BLR */
136
 
        if ((s->lcr_cache & 0x80)) {
137
 
            return 0; /* FIXME: return correct autodetect value */
138
 
        }
139
 
        return s->blr;
140
 
    case 0x3c: /* ACREG */
141
 
        return (s->lcr_cache & 0x80) ? 0 : s->acreg;
142
 
    case 0x40:  /* SCR */
143
 
        return s->scr;
144
 
    case 0x44:  /* SSR */
145
 
        return 0x0;
146
 
    case 0x48:  /* EBLR (OMAP2) */
147
 
        return s->eblr;
148
 
    case 0x4C:  /* OSC_12M_SEL (OMAP1) */
149
 
        return s->clksel;
150
 
    case 0x50:  /* MVR */
151
 
        return 0x30;
152
 
    case 0x54:  /* SYSC (OMAP2) */
153
 
        return s->syscontrol;
154
 
    case 0x58:  /* SYSS (OMAP2) */
155
 
        return 1;
156
 
    case 0x5c:  /* WER (OMAP2) */
157
 
        return s->wkup;
158
 
    case 0x60:  /* CFPS (OMAP2) */
159
 
        return s->cfps;
160
 
    }
161
 
 
162
 
    OMAP_BAD_REG(addr);
163
 
    return 0;
164
 
}
165
 
 
166
 
static void omap_uart_write(void *opaque, hwaddr addr,
167
 
                            uint64_t value, unsigned size)
168
 
{
169
 
    struct omap_uart_s *s = (struct omap_uart_s *) opaque;
170
 
 
171
 
    switch (addr) {
172
 
    case 0x00:
173
 
    case 0x04:
174
 
        s->serial_ops->write(s->serial, addr, value, size);
175
 
        break;
176
 
    case 0x08:
177
 
        if (s->lcr_cache == 0xbf) {
178
 
            s->efr = value;
179
 
        } else {
180
 
            s->serial_ops->write(s->serial, addr, value, size);
181
 
        }
182
 
        break;
183
 
    case 0x0c:
184
 
        s->lcr_cache = value;
185
 
        s->serial_ops->write(s->serial, addr, value, size);
186
 
        break;
187
 
    case 0x10:
188
 
    case 0x14:
189
 
        if (s->lcr_cache == 0xbf) {
190
 
            s->xon[(addr & 7) >> 2] = value;
191
 
        } else {
192
 
            if (addr == 0x10) {
193
 
                s->mcr_cache = value & 0x7f;
194
 
            }
195
 
            s->serial_ops->write(s->serial, addr, value, size);
196
 
        }
197
 
        break;
198
 
    case 0x18:
199
 
    case 0x1c:
200
 
        if ((s->efr & 0x10) && (s->mcr_cache & 0x40)) {
201
 
            if (addr == 0x18) {
202
 
                s->tcr = value & 0xff;
203
 
            } else {
204
 
                s->tlr = value & 0xff;
205
 
            }
206
 
        } else if (s->lcr_cache == 0xbf) {
207
 
            s->xoff[(addr & 7) >> 2] = value;
208
 
        } else {
209
 
            s->serial_ops->write(s->serial, addr, value, size);
210
 
        }
211
 
        break;
212
 
    case 0x20:  /* MDR1 */
213
 
        s->mdr[0] = value & 0x7f;
214
 
        break;
215
 
    case 0x24:  /* MDR2 */
216
 
        s->mdr[1] = value & 0xff;
217
 
        break;
218
 
    case 0x28: /* TXFLL */
219
 
    case 0x2c: /* TXFLH */
220
 
    case 0x30: /* RXFLL */
221
 
    case 0x34: /* RXFLH */
222
 
        /* ignored */
223
 
        break;
224
 
    case 0x38: /* BLR */
225
 
        if (!(s->lcr_cache & 0x80)) {
226
 
            s->blr = value & 0xc0;
227
 
        }
228
 
        break;
229
 
    case 0x3c: /* ACREG */
230
 
        if (!(s->lcr_cache & 0x80)) {
231
 
            s->acreg = value & 0xff;
232
 
        }
233
 
        break;
234
 
    case 0x40:  /* SCR */
235
 
        s->scr = value & 0xff;
236
 
        break;
237
 
    case 0x44:  /* SSR */
238
 
        OMAP_RO_REG(addr);
239
 
        break;
240
 
    case 0x48:  /* EBLR (OMAP2) */
241
 
        s->eblr = value & 0xff;
242
 
        break;
243
 
    case 0x4C:  /* OSC_12M_SEL (OMAP1) */
244
 
        s->clksel = value & 1;
245
 
        break;
246
 
    case 0x50:  /* MVR */
247
 
        OMAP_RO_REG(addr);
248
 
        break;
249
 
    case 0x54:  /* SYSC (OMAP2) */
250
 
        s->syscontrol = value & 0x1d;
251
 
        if (value & 2) {
252
 
            /* TODO: reset s->serial also. */
253
 
            omap_uart_reset(&s->busdev.qdev);
254
 
        }
255
 
        break;
256
 
    case 0x58:  /* SYSS (OMAP2) */
257
 
        OMAP_RO_REG(addr);
258
 
        break;
259
 
    case 0x5c:  /* WER (OMAP2) */
260
 
        s->wkup = value & 0x7f;
261
 
        break;
262
 
    case 0x60:  /* CFPS (OMAP2) */
263
 
        s->cfps = value & 0xff;
264
 
        break;
265
 
    default:
266
 
        OMAP_BAD_REG(addr);
267
 
    }
268
 
}
269
 
 
270
 
static const MemoryRegionOps omap_uart_ops = {
271
 
    .read = omap_uart_read,
272
 
    .write = omap_uart_write,
273
 
    .endianness = DEVICE_NATIVE_ENDIAN,
274
 
};
275
 
 
276
 
static int omap_uart_init(SysBusDevice *busdev)
277
 
{
278
 
    struct omap_uart_s *s = FROM_SYSBUS(struct omap_uart_s, busdev);
279
 
    if (!s->chr) {
280
 
        s->chr = qemu_chr_new(busdev->qdev.id, "null", NULL);
281
 
    }
282
 
    /* TODO: DMA support. Current 16550A emulation does not emulate DMA mode
283
 
     * transfers via TXRDY/RXRDY pins. We create DMA irq lines here for
284
 
     * future use nevertheless. */
285
 
    /* Nasty hackery because trying to extend an existing device is
286
 
     * not really supported, and the serial driver isn't even qdev.
287
 
     */
288
 
    s->serial = serial_mm_init(NULL, 0, 2, NULL, s->baudrate, s->chr,
289
 
                               DEVICE_NATIVE_ENDIAN);
290
 
    s->serial_ops = serial_get_memops(DEVICE_NATIVE_ENDIAN);
291
 
    sysbus_init_irq(busdev, serial_get_irq(s->serial));
292
 
    sysbus_init_irq(busdev, &s->tx_drq);
293
 
    sysbus_init_irq(busdev, &s->rx_drq);
294
 
    memory_region_init_io(&s->iomem, &omap_uart_ops, s, "omap_uart",
295
 
                          s->mmio_size);
296
 
    sysbus_init_mmio(busdev, &s->iomem);
297
 
    return 0;
298
 
}
299
 
 
300
 
static Property omap_uart_properties[] = {
301
 
    DEFINE_PROP_UINT32("mmio_size", struct omap_uart_s, mmio_size, 0x400),
302
 
    DEFINE_PROP_UINT32("baudrate", struct omap_uart_s, baudrate, 0),
303
 
    DEFINE_PROP_CHR("chardev", struct omap_uart_s, chr),
304
 
    DEFINE_PROP_END_OF_LIST()
305
 
};
306
 
 
307
 
static void omap_uart_class_init(ObjectClass *klass, void *data)
308
 
{
309
 
    DeviceClass *dc = DEVICE_CLASS(klass);
310
 
    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
311
 
    k->init = omap_uart_init;
312
 
    dc->props = omap_uart_properties;
313
 
    dc->reset = omap_uart_reset;
314
 
}
315
 
 
316
 
static TypeInfo omap_uart_info = {
317
 
    .name = "omap_uart",
318
 
    .parent = TYPE_SYS_BUS_DEVICE,
319
 
    .instance_size = sizeof(struct omap_uart_s),
320
 
    .class_init = omap_uart_class_init,
321
 
};
322
 
 
323
 
static void omap_uart_register_types(void)
324
 
{
325
 
    type_register_static(&omap_uart_info);
326
 
}
327
 
 
328
 
void omap_uart_attach(DeviceState *qdev, CharDriverState *chr,
329
 
                      const char *label)
330
 
{
331
 
    struct omap_uart_s *s = FROM_SYSBUS(struct omap_uart_s,
332
 
                                        SYS_BUS_DEVICE(qdev));
333
 
    s->chr = chr ?: qemu_chr_new(label, "null", NULL);
334
 
    serial_change_char_driver(s->serial, s->chr);
335
 
}
336
 
 
337
 
type_init(omap_uart_register_types)