2008-04-24 21:21:53 +02:00
|
|
|
/*
|
|
|
|
* Marvell MV88W8618 / Freecom MusicPal emulation.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Jan Kiszka
|
|
|
|
*
|
2011-06-26 04:21:35 +02:00
|
|
|
* This code is licensed under the GNU GPL v2.
|
2012-01-13 17:44:23 +01:00
|
|
|
*
|
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
2008-04-24 21:21:53 +02:00
|
|
|
*/
|
|
|
|
|
2015-12-07 17:23:45 +01:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2016-01-19 21:51:44 +01:00
|
|
|
#include "cpu.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/sysbus.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2019-05-23 15:47:43 +02:00
|
|
|
#include "hw/arm/boot.h"
|
2012-10-24 08:43:34 +02:00
|
|
|
#include "net/net.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/sysemu.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/boards.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/char/serial.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/timer.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/ptimer.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/block/flash.h"
|
2012-11-28 12:06:30 +01:00
|
|
|
#include "ui/console.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/i2c/i2c.h"
|
2019-08-12 07:23:42 +02:00
|
|
|
#include "hw/irq.h"
|
2020-11-07 20:34:02 +01:00
|
|
|
#include "hw/or-irq.h"
|
2017-09-19 14:30:53 +02:00
|
|
|
#include "hw/audio/wm8750.h"
|
2014-10-07 13:59:13 +02:00
|
|
|
#include "sysemu/block-backend.h"
|
2019-08-12 07:23:59 +02:00
|
|
|
#include "sysemu/runstate.h"
|
2020-08-28 11:02:44 +02:00
|
|
|
#include "sysemu/dma.h"
|
2012-11-28 12:06:30 +01:00
|
|
|
#include "ui/pixel_ops.h"
|
2020-02-19 17:08:58 +01:00
|
|
|
#include "qemu/cutils.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2009-03-10 20:25:13 +01:00
|
|
|
#define MP_MISC_BASE 0x80002000
|
|
|
|
#define MP_MISC_SIZE 0x00001000
|
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
#define MP_ETH_BASE 0x80008000
|
|
|
|
#define MP_ETH_SIZE 0x00001000
|
|
|
|
|
2009-03-10 20:25:13 +01:00
|
|
|
#define MP_WLAN_BASE 0x8000C000
|
|
|
|
#define MP_WLAN_SIZE 0x00000800
|
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
#define MP_UART1_BASE 0x8000C840
|
|
|
|
#define MP_UART2_BASE 0x8000C940
|
|
|
|
|
2009-03-10 20:25:13 +01:00
|
|
|
#define MP_GPIO_BASE 0x8000D000
|
|
|
|
#define MP_GPIO_SIZE 0x00001000
|
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
#define MP_FLASHCFG_BASE 0x90006000
|
|
|
|
#define MP_FLASHCFG_SIZE 0x00001000
|
|
|
|
|
|
|
|
#define MP_AUDIO_BASE 0x90007000
|
|
|
|
|
|
|
|
#define MP_PIC_BASE 0x90008000
|
|
|
|
#define MP_PIC_SIZE 0x00001000
|
|
|
|
|
|
|
|
#define MP_PIT_BASE 0x90009000
|
|
|
|
#define MP_PIT_SIZE 0x00001000
|
|
|
|
|
|
|
|
#define MP_LCD_BASE 0x9000c000
|
|
|
|
#define MP_LCD_SIZE 0x00001000
|
|
|
|
|
|
|
|
#define MP_SRAM_BASE 0xC0000000
|
|
|
|
#define MP_SRAM_SIZE 0x00020000
|
|
|
|
|
|
|
|
#define MP_RAM_DEFAULT_SIZE 32*1024*1024
|
|
|
|
#define MP_FLASH_SIZE_MAX 32*1024*1024
|
|
|
|
|
|
|
|
#define MP_TIMER1_IRQ 4
|
2009-05-14 23:35:08 +02:00
|
|
|
#define MP_TIMER2_IRQ 5
|
|
|
|
#define MP_TIMER3_IRQ 6
|
2008-04-24 21:21:53 +02:00
|
|
|
#define MP_TIMER4_IRQ 7
|
|
|
|
#define MP_EHCI_IRQ 8
|
|
|
|
#define MP_ETH_IRQ 9
|
2020-11-07 20:34:02 +01:00
|
|
|
#define MP_UART_SHARED_IRQ 11
|
2008-04-24 21:21:53 +02:00
|
|
|
#define MP_GPIO_IRQ 12
|
|
|
|
#define MP_RTC_IRQ 28
|
|
|
|
#define MP_AUDIO_IRQ 30
|
|
|
|
|
|
|
|
/* Wolfson 8750 I2C address */
|
2010-01-23 18:51:22 +01:00
|
|
|
#define MP_WM_ADDR 0x1A
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
/* Ethernet register offsets */
|
|
|
|
#define MP_ETH_SMIR 0x010
|
|
|
|
#define MP_ETH_PCXR 0x408
|
|
|
|
#define MP_ETH_SDCMR 0x448
|
|
|
|
#define MP_ETH_ICR 0x450
|
|
|
|
#define MP_ETH_IMR 0x458
|
|
|
|
#define MP_ETH_FRDP0 0x480
|
|
|
|
#define MP_ETH_FRDP1 0x484
|
|
|
|
#define MP_ETH_FRDP2 0x488
|
|
|
|
#define MP_ETH_FRDP3 0x48C
|
|
|
|
#define MP_ETH_CRDP0 0x4A0
|
|
|
|
#define MP_ETH_CRDP1 0x4A4
|
|
|
|
#define MP_ETH_CRDP2 0x4A8
|
|
|
|
#define MP_ETH_CRDP3 0x4AC
|
|
|
|
#define MP_ETH_CTDP0 0x4E0
|
|
|
|
#define MP_ETH_CTDP1 0x4E4
|
|
|
|
|
|
|
|
/* MII PHY access */
|
|
|
|
#define MP_ETH_SMIR_DATA 0x0000FFFF
|
|
|
|
#define MP_ETH_SMIR_ADDR 0x03FF0000
|
|
|
|
#define MP_ETH_SMIR_OPCODE (1 << 26) /* Read value */
|
|
|
|
#define MP_ETH_SMIR_RDVALID (1 << 27)
|
|
|
|
|
|
|
|
/* PHY registers */
|
|
|
|
#define MP_ETH_PHY1_BMSR 0x00210000
|
|
|
|
#define MP_ETH_PHY1_PHYSID1 0x00410000
|
|
|
|
#define MP_ETH_PHY1_PHYSID2 0x00610000
|
|
|
|
|
|
|
|
#define MP_PHY_BMSR_LINK 0x0004
|
|
|
|
#define MP_PHY_BMSR_AUTONEG 0x0008
|
|
|
|
|
|
|
|
#define MP_PHY_88E3015 0x01410E20
|
|
|
|
|
|
|
|
/* TX descriptor status */
|
2014-03-10 15:56:30 +01:00
|
|
|
#define MP_ETH_TX_OWN (1U << 31)
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
/* RX descriptor status */
|
2014-03-10 15:56:30 +01:00
|
|
|
#define MP_ETH_RX_OWN (1U << 31)
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
/* Interrupt cause/mask bits */
|
|
|
|
#define MP_ETH_IRQ_RX_BIT 0
|
|
|
|
#define MP_ETH_IRQ_RX (1 << MP_ETH_IRQ_RX_BIT)
|
|
|
|
#define MP_ETH_IRQ_TXHI_BIT 2
|
|
|
|
#define MP_ETH_IRQ_TXLO_BIT 3
|
|
|
|
|
|
|
|
/* Port config bits */
|
|
|
|
#define MP_ETH_PCXR_2BSM_BIT 28 /* 2-byte incoming suffix */
|
|
|
|
|
|
|
|
/* SDMA command bits */
|
|
|
|
#define MP_ETH_CMD_TXHI (1 << 23)
|
|
|
|
#define MP_ETH_CMD_TXLO (1 << 22)
|
|
|
|
|
|
|
|
typedef struct mv88w8618_tx_desc {
|
|
|
|
uint32_t cmdstat;
|
|
|
|
uint16_t res;
|
|
|
|
uint16_t bytes;
|
|
|
|
uint32_t buffer;
|
|
|
|
uint32_t next;
|
|
|
|
} mv88w8618_tx_desc;
|
|
|
|
|
|
|
|
typedef struct mv88w8618_rx_desc {
|
|
|
|
uint32_t cmdstat;
|
|
|
|
uint16_t bytes;
|
|
|
|
uint16_t buffer_size;
|
|
|
|
uint32_t buffer;
|
|
|
|
uint32_t next;
|
|
|
|
} mv88w8618_rx_desc;
|
|
|
|
|
2013-07-24 01:12:52 +02:00
|
|
|
#define TYPE_MV88W8618_ETH "mv88w8618_eth"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(mv88w8618_eth_state, MV88W8618_ETH)
|
2013-07-24 01:12:52 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct mv88w8618_eth_state {
|
2013-07-24 01:12:52 +02:00
|
|
|
/*< private >*/
|
|
|
|
SysBusDevice parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
MemoryRegion iomem;
|
2008-04-24 21:21:53 +02:00
|
|
|
qemu_irq irq;
|
2020-08-28 11:02:44 +02:00
|
|
|
MemoryRegion *dma_mr;
|
|
|
|
AddressSpace dma_as;
|
2008-04-24 21:21:53 +02:00
|
|
|
uint32_t smir;
|
|
|
|
uint32_t icr;
|
|
|
|
uint32_t imr;
|
2009-04-17 19:11:08 +02:00
|
|
|
int mmio_index;
|
2009-09-18 20:51:23 +02:00
|
|
|
uint32_t vlan_header;
|
2009-04-10 03:24:26 +02:00
|
|
|
uint32_t tx_queue[2];
|
|
|
|
uint32_t rx_queue[4];
|
|
|
|
uint32_t frx_queue[4];
|
|
|
|
uint32_t cur_rx[4];
|
2009-11-25 19:49:22 +01:00
|
|
|
NICState *nic;
|
2009-10-21 15:25:40 +02:00
|
|
|
NICConf conf;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2020-08-28 11:02:44 +02:00
|
|
|
static void eth_rx_desc_put(AddressSpace *dma_as, uint32_t addr,
|
|
|
|
mv88w8618_rx_desc *desc)
|
2009-04-10 03:24:26 +02:00
|
|
|
{
|
|
|
|
cpu_to_le32s(&desc->cmdstat);
|
|
|
|
cpu_to_le16s(&desc->bytes);
|
|
|
|
cpu_to_le16s(&desc->buffer_size);
|
|
|
|
cpu_to_le32s(&desc->buffer);
|
|
|
|
cpu_to_le32s(&desc->next);
|
2020-08-28 11:02:44 +02:00
|
|
|
dma_memory_write(dma_as, addr, desc, sizeof(*desc));
|
2009-04-10 03:24:26 +02:00
|
|
|
}
|
|
|
|
|
2020-08-28 11:02:44 +02:00
|
|
|
static void eth_rx_desc_get(AddressSpace *dma_as, uint32_t addr,
|
|
|
|
mv88w8618_rx_desc *desc)
|
2009-04-10 03:24:26 +02:00
|
|
|
{
|
2020-08-28 11:02:44 +02:00
|
|
|
dma_memory_read(dma_as, addr, desc, sizeof(*desc));
|
2009-04-10 03:24:26 +02:00
|
|
|
le32_to_cpus(&desc->cmdstat);
|
|
|
|
le16_to_cpus(&desc->bytes);
|
|
|
|
le16_to_cpus(&desc->buffer_size);
|
|
|
|
le32_to_cpus(&desc->buffer);
|
|
|
|
le32_to_cpus(&desc->next);
|
|
|
|
}
|
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
static ssize_t eth_receive(NetClientState *nc, const uint8_t *buf, size_t size)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
2013-01-30 12:12:23 +01:00
|
|
|
mv88w8618_eth_state *s = qemu_get_nic_opaque(nc);
|
2009-04-10 03:24:26 +02:00
|
|
|
uint32_t desc_addr;
|
|
|
|
mv88w8618_rx_desc desc;
|
2008-04-24 21:21:53 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
2009-04-10 03:24:26 +02:00
|
|
|
desc_addr = s->cur_rx[i];
|
2009-09-18 20:51:23 +02:00
|
|
|
if (!desc_addr) {
|
2008-04-24 21:21:53 +02:00
|
|
|
continue;
|
2009-09-18 20:51:23 +02:00
|
|
|
}
|
2008-04-24 21:21:53 +02:00
|
|
|
do {
|
2020-08-28 11:02:44 +02:00
|
|
|
eth_rx_desc_get(&s->dma_as, desc_addr, &desc);
|
2009-04-10 03:24:26 +02:00
|
|
|
if ((desc.cmdstat & MP_ETH_RX_OWN) && desc.buffer_size >= size) {
|
2020-08-28 11:02:44 +02:00
|
|
|
dma_memory_write(&s->dma_as, desc.buffer + s->vlan_header,
|
2009-04-10 03:24:26 +02:00
|
|
|
buf, size);
|
|
|
|
desc.bytes = size + s->vlan_header;
|
|
|
|
desc.cmdstat &= ~MP_ETH_RX_OWN;
|
|
|
|
s->cur_rx[i] = desc.next;
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
s->icr |= MP_ETH_IRQ_RX;
|
2009-09-18 20:51:23 +02:00
|
|
|
if (s->icr & s->imr) {
|
2008-04-24 21:21:53 +02:00
|
|
|
qemu_irq_raise(s->irq);
|
2009-09-18 20:51:23 +02:00
|
|
|
}
|
2020-08-28 11:02:44 +02:00
|
|
|
eth_rx_desc_put(&s->dma_as, desc_addr, &desc);
|
2009-05-18 14:40:55 +02:00
|
|
|
return size;
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
2009-04-10 03:24:26 +02:00
|
|
|
desc_addr = desc.next;
|
|
|
|
} while (desc_addr != s->rx_queue[i]);
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
2009-05-18 14:40:55 +02:00
|
|
|
return size;
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
2020-08-28 11:02:44 +02:00
|
|
|
static void eth_tx_desc_put(AddressSpace *dma_as, uint32_t addr,
|
|
|
|
mv88w8618_tx_desc *desc)
|
2009-04-10 03:24:26 +02:00
|
|
|
{
|
|
|
|
cpu_to_le32s(&desc->cmdstat);
|
|
|
|
cpu_to_le16s(&desc->res);
|
|
|
|
cpu_to_le16s(&desc->bytes);
|
|
|
|
cpu_to_le32s(&desc->buffer);
|
|
|
|
cpu_to_le32s(&desc->next);
|
2020-08-28 11:02:44 +02:00
|
|
|
dma_memory_write(dma_as, addr, desc, sizeof(*desc));
|
2009-04-10 03:24:26 +02:00
|
|
|
}
|
|
|
|
|
2020-08-28 11:02:44 +02:00
|
|
|
static void eth_tx_desc_get(AddressSpace *dma_as, uint32_t addr,
|
|
|
|
mv88w8618_tx_desc *desc)
|
2009-04-10 03:24:26 +02:00
|
|
|
{
|
2020-08-28 11:02:44 +02:00
|
|
|
dma_memory_read(dma_as, addr, desc, sizeof(*desc));
|
2009-04-10 03:24:26 +02:00
|
|
|
le32_to_cpus(&desc->cmdstat);
|
|
|
|
le16_to_cpus(&desc->res);
|
|
|
|
le16_to_cpus(&desc->bytes);
|
|
|
|
le32_to_cpus(&desc->buffer);
|
|
|
|
le32_to_cpus(&desc->next);
|
|
|
|
}
|
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
static void eth_send(mv88w8618_eth_state *s, int queue_index)
|
|
|
|
{
|
2009-04-10 03:24:26 +02:00
|
|
|
uint32_t desc_addr = s->tx_queue[queue_index];
|
|
|
|
mv88w8618_tx_desc desc;
|
2010-01-24 09:51:49 +01:00
|
|
|
uint32_t next_desc;
|
2009-04-10 03:24:26 +02:00
|
|
|
uint8_t buf[2048];
|
|
|
|
int len;
|
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
do {
|
2020-08-28 11:02:44 +02:00
|
|
|
eth_tx_desc_get(&s->dma_as, desc_addr, &desc);
|
2010-01-24 09:51:49 +01:00
|
|
|
next_desc = desc.next;
|
2009-04-10 03:24:26 +02:00
|
|
|
if (desc.cmdstat & MP_ETH_TX_OWN) {
|
|
|
|
len = desc.bytes;
|
|
|
|
if (len < 2048) {
|
2020-08-28 11:02:44 +02:00
|
|
|
dma_memory_read(&s->dma_as, desc.buffer, buf, len);
|
2013-01-30 12:12:22 +01:00
|
|
|
qemu_send_packet(qemu_get_queue(s->nic), buf, len);
|
2009-04-10 03:24:26 +02:00
|
|
|
}
|
|
|
|
desc.cmdstat &= ~MP_ETH_TX_OWN;
|
2008-04-24 21:21:53 +02:00
|
|
|
s->icr |= 1 << (MP_ETH_IRQ_TXLO_BIT - queue_index);
|
2020-08-28 11:02:44 +02:00
|
|
|
eth_tx_desc_put(&s->dma_as, desc_addr, &desc);
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
2010-01-24 09:51:49 +01:00
|
|
|
desc_addr = next_desc;
|
2009-04-10 03:24:26 +02:00
|
|
|
} while (desc_addr != s->tx_queue[queue_index]);
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t mv88w8618_eth_read(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
unsigned size)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
|
|
|
mv88w8618_eth_state *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case MP_ETH_SMIR:
|
|
|
|
if (s->smir & MP_ETH_SMIR_OPCODE) {
|
|
|
|
switch (s->smir & MP_ETH_SMIR_ADDR) {
|
|
|
|
case MP_ETH_PHY1_BMSR:
|
|
|
|
return MP_PHY_BMSR_LINK | MP_PHY_BMSR_AUTONEG |
|
|
|
|
MP_ETH_SMIR_RDVALID;
|
|
|
|
case MP_ETH_PHY1_PHYSID1:
|
|
|
|
return (MP_PHY_88E3015 >> 16) | MP_ETH_SMIR_RDVALID;
|
|
|
|
case MP_ETH_PHY1_PHYSID2:
|
|
|
|
return (MP_PHY_88E3015 & 0xFFFF) | MP_ETH_SMIR_RDVALID;
|
|
|
|
default:
|
|
|
|
return MP_ETH_SMIR_RDVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case MP_ETH_ICR:
|
|
|
|
return s->icr;
|
|
|
|
|
|
|
|
case MP_ETH_IMR:
|
|
|
|
return s->imr;
|
|
|
|
|
|
|
|
case MP_ETH_FRDP0 ... MP_ETH_FRDP3:
|
2009-04-10 03:24:26 +02:00
|
|
|
return s->frx_queue[(offset - MP_ETH_FRDP0)/4];
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
case MP_ETH_CRDP0 ... MP_ETH_CRDP3:
|
2009-04-10 03:24:26 +02:00
|
|
|
return s->rx_queue[(offset - MP_ETH_CRDP0)/4];
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2014-02-26 18:19:59 +01:00
|
|
|
case MP_ETH_CTDP0 ... MP_ETH_CTDP1:
|
2009-04-10 03:24:26 +02:00
|
|
|
return s->tx_queue[(offset - MP_ETH_CTDP0)/4];
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void mv88w8618_eth_write(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
uint64_t value, unsigned size)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
|
|
|
mv88w8618_eth_state *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case MP_ETH_SMIR:
|
|
|
|
s->smir = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_ETH_PCXR:
|
|
|
|
s->vlan_header = ((value >> MP_ETH_PCXR_2BSM_BIT) & 1) * 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_ETH_SDCMR:
|
2009-09-18 20:51:23 +02:00
|
|
|
if (value & MP_ETH_CMD_TXHI) {
|
2008-04-24 21:21:53 +02:00
|
|
|
eth_send(s, 1);
|
2009-09-18 20:51:23 +02:00
|
|
|
}
|
|
|
|
if (value & MP_ETH_CMD_TXLO) {
|
2008-04-24 21:21:53 +02:00
|
|
|
eth_send(s, 0);
|
2009-09-18 20:51:23 +02:00
|
|
|
}
|
|
|
|
if (value & (MP_ETH_CMD_TXHI | MP_ETH_CMD_TXLO) && s->icr & s->imr) {
|
2008-04-24 21:21:53 +02:00
|
|
|
qemu_irq_raise(s->irq);
|
2009-09-18 20:51:23 +02:00
|
|
|
}
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_ETH_ICR:
|
|
|
|
s->icr &= value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_ETH_IMR:
|
|
|
|
s->imr = value;
|
2009-09-18 20:51:23 +02:00
|
|
|
if (s->icr & s->imr) {
|
2008-04-24 21:21:53 +02:00
|
|
|
qemu_irq_raise(s->irq);
|
2009-09-18 20:51:23 +02:00
|
|
|
}
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_ETH_FRDP0 ... MP_ETH_FRDP3:
|
2009-04-10 03:24:26 +02:00
|
|
|
s->frx_queue[(offset - MP_ETH_FRDP0)/4] = value;
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_ETH_CRDP0 ... MP_ETH_CRDP3:
|
|
|
|
s->rx_queue[(offset - MP_ETH_CRDP0)/4] =
|
2009-04-10 03:24:26 +02:00
|
|
|
s->cur_rx[(offset - MP_ETH_CRDP0)/4] = value;
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
|
2014-02-26 18:19:59 +01:00
|
|
|
case MP_ETH_CTDP0 ... MP_ETH_CTDP1:
|
2009-04-10 03:24:26 +02:00
|
|
|
s->tx_queue[(offset - MP_ETH_CTDP0)/4] = value;
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
static const MemoryRegionOps mv88w8618_eth_ops = {
|
|
|
|
.read = mv88w8618_eth_read,
|
|
|
|
.write = mv88w8618_eth_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2008-04-24 21:21:53 +02:00
|
|
|
};
|
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
static void eth_cleanup(NetClientState *nc)
|
2009-04-17 19:11:08 +02:00
|
|
|
{
|
2013-01-30 12:12:23 +01:00
|
|
|
mv88w8618_eth_state *s = qemu_get_nic_opaque(nc);
|
2009-04-17 19:11:08 +02:00
|
|
|
|
2009-11-25 19:49:22 +01:00
|
|
|
s->nic = NULL;
|
2009-04-17 19:11:08 +02:00
|
|
|
}
|
|
|
|
|
2009-11-25 19:49:22 +01:00
|
|
|
static NetClientInfo net_mv88w8618_info = {
|
qapi: Change Netdev into a flat union
This is a mostly-mechanical conversion that creates a new flat
union 'Netdev' QAPI type that covers all the branches of the
former 'NetClientOptions' simple union, where the branches are
now listed in a new 'NetClientDriver' enum rather than generated
from the simple union. The existence of a flat union has no
change to the command line syntax accepted for new code, and
will make it possible for a future patch to switch the QMP
command to parse a boxed union for no change to valid QMP; but
it does have some ripple effect on the C code when dealing with
the new types.
While making the conversion, note that the 'NetLegacy' type
remains unchanged: it applies only to legacy command line options,
and will not be ported to QMP, so it should remain a wrapper
around a simple union; to avoid confusion, the type named
'NetClientOptions' is now gone, and we introduce 'NetLegacyOptions'
in its place. Then, in the C code, we convert from NetLegacy to
Netdev as soon as possible, so that the bulk of the net stack
only has to deal with one QAPI type, not two. Note that since
the old legacy code always rejected 'hubport', we can just omit
that branch from the new 'NetLegacyOptions' simple union.
Based on an idea originally by Zoltán Kővágó <DirtY.iCE.hu@gmail.com>:
Message-Id: <01a527fbf1a5de880091f98cf011616a78adeeee.1441627176.git.DirtY.iCE.hu@gmail.com>
although the sed script in that patch no longer applies due to
other changes in the tree since then, and I also did some manual
cleanups (such as fixing whitespace to keep checkpatch happy).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1468468228-27827-13-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Fixup from Eric squashed in]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-07-14 05:50:23 +02:00
|
|
|
.type = NET_CLIENT_DRIVER_NIC,
|
2009-11-25 19:49:22 +01:00
|
|
|
.size = sizeof(NICState),
|
|
|
|
.receive = eth_receive,
|
|
|
|
.cleanup = eth_cleanup,
|
|
|
|
};
|
|
|
|
|
2016-10-24 17:26:55 +02:00
|
|
|
static void mv88w8618_eth_init(Object *obj)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
2016-10-24 17:26:55 +02:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2013-07-24 01:12:52 +02:00
|
|
|
DeviceState *dev = DEVICE(sbd);
|
|
|
|
mv88w8618_eth_state *s = MV88W8618_ETH(dev);
|
2009-01-13 20:39:36 +01:00
|
|
|
|
2013-07-24 01:12:52 +02:00
|
|
|
sysbus_init_irq(sbd, &s->irq);
|
2016-10-24 17:26:55 +02:00
|
|
|
memory_region_init_io(&s->iomem, obj, &mv88w8618_eth_ops, s,
|
2013-06-07 03:25:08 +02:00
|
|
|
"mv88w8618-eth", MP_ETH_SIZE);
|
2013-07-24 01:12:52 +02:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2016-10-24 17:26:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mv88w8618_eth_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
mv88w8618_eth_state *s = MV88W8618_ETH(dev);
|
|
|
|
|
2020-08-28 11:02:44 +02:00
|
|
|
if (!s->dma_mr) {
|
|
|
|
error_setg(errp, TYPE_MV88W8618_ETH " 'dma-memory' link not set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
address_space_init(&s->dma_as, s->dma_mr, "emac-dma");
|
2016-10-24 17:26:55 +02:00
|
|
|
s->nic = qemu_new_nic(&net_mv88w8618_info, &s->conf,
|
|
|
|
object_get_typename(OBJECT(dev)), dev->id, s);
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
static const VMStateDescription mv88w8618_eth_vmsd = {
|
|
|
|
.name = "mv88w8618_eth",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(smir, mv88w8618_eth_state),
|
|
|
|
VMSTATE_UINT32(icr, mv88w8618_eth_state),
|
|
|
|
VMSTATE_UINT32(imr, mv88w8618_eth_state),
|
|
|
|
VMSTATE_UINT32(vlan_header, mv88w8618_eth_state),
|
|
|
|
VMSTATE_UINT32_ARRAY(tx_queue, mv88w8618_eth_state, 2),
|
|
|
|
VMSTATE_UINT32_ARRAY(rx_queue, mv88w8618_eth_state, 4),
|
|
|
|
VMSTATE_UINT32_ARRAY(frx_queue, mv88w8618_eth_state, 4),
|
|
|
|
VMSTATE_UINT32_ARRAY(cur_rx, mv88w8618_eth_state, 4),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static Property mv88w8618_eth_properties[] = {
|
|
|
|
DEFINE_NIC_PROPERTIES(mv88w8618_eth_state, conf),
|
2020-08-28 11:02:44 +02:00
|
|
|
DEFINE_PROP_LINK("dma-memory", mv88w8618_eth_state, dma_mr,
|
|
|
|
TYPE_MEMORY_REGION, MemoryRegion *),
|
2012-01-24 20:12:29 +01:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void mv88w8618_eth_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->vmsd = &mv88w8618_eth_vmsd;
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, mv88w8618_eth_properties);
|
2016-10-24 17:26:55 +02:00
|
|
|
dc->realize = mv88w8618_eth_realize;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo mv88w8618_eth_info = {
|
2013-07-24 01:12:52 +02:00
|
|
|
.name = TYPE_MV88W8618_ETH,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(mv88w8618_eth_state),
|
2016-10-24 17:26:55 +02:00
|
|
|
.instance_init = mv88w8618_eth_init,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = mv88w8618_eth_class_init,
|
2009-09-18 20:51:23 +02:00
|
|
|
};
|
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
/* LCD register offsets */
|
|
|
|
#define MP_LCD_IRQCTRL 0x180
|
|
|
|
#define MP_LCD_IRQSTAT 0x184
|
|
|
|
#define MP_LCD_SPICTRL 0x1ac
|
|
|
|
#define MP_LCD_INST 0x1bc
|
|
|
|
#define MP_LCD_DATA 0x1c0
|
|
|
|
|
|
|
|
/* Mode magics */
|
|
|
|
#define MP_LCD_SPI_DATA 0x00100011
|
|
|
|
#define MP_LCD_SPI_CMD 0x00104011
|
|
|
|
#define MP_LCD_SPI_INVALID 0x00000000
|
|
|
|
|
|
|
|
/* Commmands */
|
|
|
|
#define MP_LCD_INST_SETPAGE0 0xB0
|
|
|
|
/* ... */
|
|
|
|
#define MP_LCD_INST_SETPAGE7 0xB7
|
|
|
|
|
|
|
|
#define MP_LCD_TEXTCOLOR 0xe0e0ff /* RRGGBB */
|
|
|
|
|
2013-07-24 01:16:13 +02:00
|
|
|
#define TYPE_MUSICPAL_LCD "musicpal_lcd"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(musicpal_lcd_state, MUSICPAL_LCD)
|
2013-07-24 01:16:13 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct musicpal_lcd_state {
|
2013-07-24 01:16:13 +02:00
|
|
|
/*< private >*/
|
|
|
|
SysBusDevice parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
MemoryRegion iomem;
|
2009-08-23 14:38:07 +02:00
|
|
|
uint32_t brightness;
|
2008-04-24 21:21:53 +02:00
|
|
|
uint32_t mode;
|
|
|
|
uint32_t irqctrl;
|
2009-09-18 20:51:23 +02:00
|
|
|
uint32_t page;
|
|
|
|
uint32_t page_off;
|
2013-03-05 15:24:14 +01:00
|
|
|
QemuConsole *con;
|
2008-04-24 21:21:53 +02:00
|
|
|
uint8_t video_ram[128*64/8];
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2009-08-23 14:38:07 +02:00
|
|
|
static uint8_t scale_lcd_color(musicpal_lcd_state *s, uint8_t col)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
2009-08-23 14:38:07 +02:00
|
|
|
switch (s->brightness) {
|
|
|
|
case 7:
|
|
|
|
return col;
|
|
|
|
case 0:
|
2008-04-24 21:21:53 +02:00
|
|
|
return 0;
|
|
|
|
default:
|
2009-08-23 14:38:07 +02:00
|
|
|
return (col * s->brightness) / 7;
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-15 11:32:07 +01:00
|
|
|
static inline void set_lcd_pixel32(musicpal_lcd_state *s,
|
|
|
|
int x, int y, uint32_t col)
|
|
|
|
{
|
|
|
|
int dx, dy;
|
|
|
|
DisplaySurface *surface = qemu_console_surface(s->con);
|
|
|
|
uint32_t *pixel =
|
|
|
|
&((uint32_t *) surface_data(surface))[(y * 128 * 3 + x) * 3];
|
|
|
|
|
|
|
|
for (dy = 0; dy < 3; dy++, pixel += 127 * 3) {
|
|
|
|
for (dx = 0; dx < 3; dx++, pixel++) {
|
|
|
|
*pixel = col;
|
|
|
|
}
|
|
|
|
}
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
2008-04-25 02:59:43 +02:00
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
static void lcd_refresh(void *opaque)
|
|
|
|
{
|
|
|
|
musicpal_lcd_state *s = opaque;
|
2008-04-25 02:59:43 +02:00
|
|
|
int x, y, col;
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2021-02-15 11:32:07 +01:00
|
|
|
col = rgb_to_pixel32(scale_lcd_color(s, (MP_LCD_TEXTCOLOR >> 16) & 0xff),
|
|
|
|
scale_lcd_color(s, (MP_LCD_TEXTCOLOR >> 8) & 0xff),
|
|
|
|
scale_lcd_color(s, MP_LCD_TEXTCOLOR & 0xff));
|
|
|
|
for (x = 0; x < 128; x++) {
|
|
|
|
for (y = 0; y < 64; y++) {
|
|
|
|
if (s->video_ram[x + (y / 8) * 128] & (1 << (y % 8))) {
|
|
|
|
set_lcd_pixel32(s, x, y, col);
|
|
|
|
} else {
|
|
|
|
set_lcd_pixel32(s, x, y, 0);
|
|
|
|
}
|
|
|
|
}
|
2008-04-25 02:59:43 +02:00
|
|
|
}
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2013-03-05 15:24:14 +01:00
|
|
|
dpy_gfx_update(s->con, 0, 0, 128*3, 64*3);
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
2008-06-02 04:04:56 +02:00
|
|
|
static void lcd_invalidate(void *opaque)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-28 07:54:55 +02:00
|
|
|
static void musicpal_lcd_gpio_brightness_in(void *opaque, int irq, int level)
|
2009-08-23 14:38:07 +02:00
|
|
|
{
|
2009-09-18 20:51:23 +02:00
|
|
|
musicpal_lcd_state *s = opaque;
|
2009-08-23 14:38:07 +02:00
|
|
|
s->brightness &= ~(1 << irq);
|
|
|
|
s->brightness |= level << irq;
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t musicpal_lcd_read(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
unsigned size)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
|
|
|
musicpal_lcd_state *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case MP_LCD_IRQCTRL:
|
|
|
|
return s->irqctrl;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void musicpal_lcd_write(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
uint64_t value, unsigned size)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
|
|
|
musicpal_lcd_state *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case MP_LCD_IRQCTRL:
|
|
|
|
s->irqctrl = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_LCD_SPICTRL:
|
2009-09-18 20:51:23 +02:00
|
|
|
if (value == MP_LCD_SPI_DATA || value == MP_LCD_SPI_CMD) {
|
2008-04-24 21:21:53 +02:00
|
|
|
s->mode = value;
|
2009-09-18 20:51:23 +02:00
|
|
|
} else {
|
2008-04-24 21:21:53 +02:00
|
|
|
s->mode = MP_LCD_SPI_INVALID;
|
2009-09-18 20:51:23 +02:00
|
|
|
}
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_LCD_INST:
|
|
|
|
if (value >= MP_LCD_INST_SETPAGE0 && value <= MP_LCD_INST_SETPAGE7) {
|
|
|
|
s->page = value - MP_LCD_INST_SETPAGE0;
|
|
|
|
s->page_off = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_LCD_DATA:
|
|
|
|
if (s->mode == MP_LCD_SPI_CMD) {
|
|
|
|
if (value >= MP_LCD_INST_SETPAGE0 &&
|
|
|
|
value <= MP_LCD_INST_SETPAGE7) {
|
|
|
|
s->page = value - MP_LCD_INST_SETPAGE0;
|
|
|
|
s->page_off = 0;
|
|
|
|
}
|
|
|
|
} else if (s->mode == MP_LCD_SPI_DATA) {
|
|
|
|
s->video_ram[s->page*128 + s->page_off] = value;
|
|
|
|
s->page_off = (s->page_off + 1) & 127;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
static const MemoryRegionOps musicpal_lcd_ops = {
|
|
|
|
.read = musicpal_lcd_read,
|
|
|
|
.write = musicpal_lcd_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2008-04-24 21:21:53 +02:00
|
|
|
};
|
|
|
|
|
2013-03-13 14:04:18 +01:00
|
|
|
static const GraphicHwOps musicpal_gfx_ops = {
|
|
|
|
.invalidate = lcd_invalidate,
|
|
|
|
.gfx_update = lcd_refresh,
|
|
|
|
};
|
|
|
|
|
2016-10-24 17:26:55 +02:00
|
|
|
static void musicpal_lcd_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
musicpal_lcd_state *s = MUSICPAL_LCD(dev);
|
|
|
|
s->con = graphic_console_init(dev, 0, &musicpal_gfx_ops, s);
|
|
|
|
qemu_console_resize(s->con, 128 * 3, 64 * 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void musicpal_lcd_init(Object *obj)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
2016-10-24 17:26:55 +02:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2013-07-24 01:16:13 +02:00
|
|
|
DeviceState *dev = DEVICE(sbd);
|
|
|
|
musicpal_lcd_state *s = MUSICPAL_LCD(dev);
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2009-08-23 14:38:07 +02:00
|
|
|
s->brightness = 7;
|
|
|
|
|
2016-10-24 17:26:55 +02:00
|
|
|
memory_region_init_io(&s->iomem, obj, &musicpal_lcd_ops, s,
|
2011-08-08 21:50:06 +02:00
|
|
|
"musicpal-lcd", MP_LCD_SIZE);
|
2013-07-24 01:16:13 +02:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2013-07-24 01:16:13 +02:00
|
|
|
qdev_init_gpio_in(dev, musicpal_lcd_gpio_brightness_in, 3);
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
static const VMStateDescription musicpal_lcd_vmsd = {
|
|
|
|
.name = "musicpal_lcd",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(brightness, musicpal_lcd_state),
|
|
|
|
VMSTATE_UINT32(mode, musicpal_lcd_state),
|
|
|
|
VMSTATE_UINT32(irqctrl, musicpal_lcd_state),
|
|
|
|
VMSTATE_UINT32(page, musicpal_lcd_state),
|
|
|
|
VMSTATE_UINT32(page_off, musicpal_lcd_state),
|
|
|
|
VMSTATE_BUFFER(video_ram, musicpal_lcd_state),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void musicpal_lcd_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->vmsd = &musicpal_lcd_vmsd;
|
2016-10-24 17:26:55 +02:00
|
|
|
dc->realize = musicpal_lcd_realize;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo musicpal_lcd_info = {
|
2013-07-24 01:16:13 +02:00
|
|
|
.name = TYPE_MUSICPAL_LCD,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(musicpal_lcd_state),
|
2016-10-24 17:26:55 +02:00
|
|
|
.instance_init = musicpal_lcd_init,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = musicpal_lcd_class_init,
|
2009-09-18 20:51:23 +02:00
|
|
|
};
|
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
/* PIC register offsets */
|
|
|
|
#define MP_PIC_STATUS 0x00
|
|
|
|
#define MP_PIC_ENABLE_SET 0x08
|
|
|
|
#define MP_PIC_ENABLE_CLR 0x0C
|
|
|
|
|
2013-07-24 01:22:07 +02:00
|
|
|
#define TYPE_MV88W8618_PIC "mv88w8618_pic"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(mv88w8618_pic_state, MV88W8618_PIC)
|
2013-07-24 01:22:07 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct mv88w8618_pic_state {
|
2013-07-24 01:22:07 +02:00
|
|
|
/*< private >*/
|
|
|
|
SysBusDevice parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
MemoryRegion iomem;
|
2008-04-24 21:21:53 +02:00
|
|
|
uint32_t level;
|
|
|
|
uint32_t enabled;
|
|
|
|
qemu_irq parent_irq;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
static void mv88w8618_pic_update(mv88w8618_pic_state *s)
|
|
|
|
{
|
|
|
|
qemu_set_irq(s->parent_irq, (s->level & s->enabled));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mv88w8618_pic_set_irq(void *opaque, int irq, int level)
|
|
|
|
{
|
|
|
|
mv88w8618_pic_state *s = opaque;
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
if (level) {
|
2008-04-24 21:21:53 +02:00
|
|
|
s->level |= 1 << irq;
|
2009-09-18 20:51:23 +02:00
|
|
|
} else {
|
2008-04-24 21:21:53 +02:00
|
|
|
s->level &= ~(1 << irq);
|
2009-09-18 20:51:23 +02:00
|
|
|
}
|
2008-04-24 21:21:53 +02:00
|
|
|
mv88w8618_pic_update(s);
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t mv88w8618_pic_read(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
unsigned size)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
|
|
|
mv88w8618_pic_state *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case MP_PIC_STATUS:
|
|
|
|
return s->level & s->enabled;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void mv88w8618_pic_write(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
uint64_t value, unsigned size)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
|
|
|
mv88w8618_pic_state *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case MP_PIC_ENABLE_SET:
|
|
|
|
s->enabled |= value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_PIC_ENABLE_CLR:
|
|
|
|
s->enabled &= ~value;
|
|
|
|
s->level &= ~value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mv88w8618_pic_update(s);
|
|
|
|
}
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
static void mv88w8618_pic_reset(DeviceState *d)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
2013-07-24 01:22:07 +02:00
|
|
|
mv88w8618_pic_state *s = MV88W8618_PIC(d);
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
s->level = 0;
|
|
|
|
s->enabled = 0;
|
|
|
|
}
|
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
static const MemoryRegionOps mv88w8618_pic_ops = {
|
|
|
|
.read = mv88w8618_pic_read,
|
|
|
|
.write = mv88w8618_pic_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2008-04-24 21:21:53 +02:00
|
|
|
};
|
|
|
|
|
2016-10-24 17:26:55 +02:00
|
|
|
static void mv88w8618_pic_init(Object *obj)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
2016-10-24 17:26:55 +02:00
|
|
|
SysBusDevice *dev = SYS_BUS_DEVICE(obj);
|
2013-07-24 01:22:07 +02:00
|
|
|
mv88w8618_pic_state *s = MV88W8618_PIC(dev);
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2013-07-24 01:22:07 +02:00
|
|
|
qdev_init_gpio_in(DEVICE(dev), mv88w8618_pic_set_irq, 32);
|
2009-05-14 23:35:08 +02:00
|
|
|
sysbus_init_irq(dev, &s->parent_irq);
|
2016-10-24 17:26:55 +02:00
|
|
|
memory_region_init_io(&s->iomem, obj, &mv88w8618_pic_ops, s,
|
2011-08-08 21:50:06 +02:00
|
|
|
"musicpal-pic", MP_PIC_SIZE);
|
2011-11-27 10:38:10 +01:00
|
|
|
sysbus_init_mmio(dev, &s->iomem);
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
static const VMStateDescription mv88w8618_pic_vmsd = {
|
|
|
|
.name = "mv88w8618_pic",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(level, mv88w8618_pic_state),
|
|
|
|
VMSTATE_UINT32(enabled, mv88w8618_pic_state),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void mv88w8618_pic_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->reset = mv88w8618_pic_reset;
|
|
|
|
dc->vmsd = &mv88w8618_pic_vmsd;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo mv88w8618_pic_info = {
|
2013-07-24 01:22:07 +02:00
|
|
|
.name = TYPE_MV88W8618_PIC,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(mv88w8618_pic_state),
|
2016-10-24 17:26:55 +02:00
|
|
|
.instance_init = mv88w8618_pic_init,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = mv88w8618_pic_class_init,
|
2009-09-18 20:51:23 +02:00
|
|
|
};
|
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
/* PIT register offsets */
|
|
|
|
#define MP_PIT_TIMER1_LENGTH 0x00
|
|
|
|
/* ... */
|
|
|
|
#define MP_PIT_TIMER4_LENGTH 0x0C
|
|
|
|
#define MP_PIT_CONTROL 0x10
|
|
|
|
#define MP_PIT_TIMER1_VALUE 0x14
|
|
|
|
/* ... */
|
|
|
|
#define MP_PIT_TIMER4_VALUE 0x20
|
|
|
|
#define MP_BOARD_RESET 0x34
|
|
|
|
|
|
|
|
/* Magic board reset value (probably some watchdog behind it) */
|
|
|
|
#define MP_BOARD_RESET_MAGIC 0x10000
|
|
|
|
|
|
|
|
typedef struct mv88w8618_timer_state {
|
2009-05-14 23:35:08 +02:00
|
|
|
ptimer_state *ptimer;
|
2008-04-24 21:21:53 +02:00
|
|
|
uint32_t limit;
|
|
|
|
int freq;
|
|
|
|
qemu_irq irq;
|
|
|
|
} mv88w8618_timer_state;
|
|
|
|
|
2013-07-24 01:27:32 +02:00
|
|
|
#define TYPE_MV88W8618_PIT "mv88w8618_pit"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(mv88w8618_pit_state, MV88W8618_PIT)
|
2013-07-24 01:27:32 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct mv88w8618_pit_state {
|
2013-07-24 01:27:32 +02:00
|
|
|
/*< private >*/
|
|
|
|
SysBusDevice parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
MemoryRegion iomem;
|
2009-05-14 23:35:08 +02:00
|
|
|
mv88w8618_timer_state timer[4];
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
static void mv88w8618_timer_tick(void *opaque)
|
|
|
|
{
|
|
|
|
mv88w8618_timer_state *s = opaque;
|
|
|
|
|
|
|
|
qemu_irq_raise(s->irq);
|
|
|
|
}
|
|
|
|
|
2009-05-14 23:35:08 +02:00
|
|
|
static void mv88w8618_timer_init(SysBusDevice *dev, mv88w8618_timer_state *s,
|
|
|
|
uint32_t freq)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
2009-05-14 23:35:08 +02:00
|
|
|
sysbus_init_irq(dev, &s->irq);
|
2008-04-24 21:21:53 +02:00
|
|
|
s->freq = freq;
|
|
|
|
|
2019-10-08 19:17:24 +02:00
|
|
|
s->ptimer = ptimer_init(mv88w8618_timer_tick, s, PTIMER_POLICY_DEFAULT);
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t mv88w8618_pit_read(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
unsigned size)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
|
|
|
mv88w8618_pit_state *s = opaque;
|
|
|
|
mv88w8618_timer_state *t;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case MP_PIT_TIMER1_VALUE ... MP_PIT_TIMER4_VALUE:
|
2009-05-14 23:35:08 +02:00
|
|
|
t = &s->timer[(offset-MP_PIT_TIMER1_VALUE) >> 2];
|
|
|
|
return ptimer_get_count(t->ptimer);
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void mv88w8618_pit_write(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
uint64_t value, unsigned size)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
|
|
|
mv88w8618_pit_state *s = opaque;
|
|
|
|
mv88w8618_timer_state *t;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case MP_PIT_TIMER1_LENGTH ... MP_PIT_TIMER4_LENGTH:
|
2009-05-14 23:35:08 +02:00
|
|
|
t = &s->timer[offset >> 2];
|
2008-04-24 21:21:53 +02:00
|
|
|
t->limit = value;
|
2019-10-08 19:17:24 +02:00
|
|
|
ptimer_transaction_begin(t->ptimer);
|
2009-09-18 20:51:23 +02:00
|
|
|
if (t->limit > 0) {
|
|
|
|
ptimer_set_limit(t->ptimer, t->limit, 1);
|
|
|
|
} else {
|
|
|
|
ptimer_stop(t->ptimer);
|
|
|
|
}
|
2019-10-08 19:17:24 +02:00
|
|
|
ptimer_transaction_commit(t->ptimer);
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_PIT_CONTROL:
|
|
|
|
for (i = 0; i < 4; i++) {
|
2009-09-18 20:51:23 +02:00
|
|
|
t = &s->timer[i];
|
2019-10-08 19:17:24 +02:00
|
|
|
ptimer_transaction_begin(t->ptimer);
|
2009-09-18 20:51:23 +02:00
|
|
|
if (value & 0xf && t->limit > 0) {
|
2009-05-14 23:35:08 +02:00
|
|
|
ptimer_set_limit(t->ptimer, t->limit, 0);
|
|
|
|
ptimer_set_freq(t->ptimer, t->freq);
|
|
|
|
ptimer_run(t->ptimer, 0);
|
2009-09-18 20:51:23 +02:00
|
|
|
} else {
|
|
|
|
ptimer_stop(t->ptimer);
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
2019-10-08 19:17:24 +02:00
|
|
|
ptimer_transaction_commit(t->ptimer);
|
2008-04-24 21:21:53 +02:00
|
|
|
value >>= 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_BOARD_RESET:
|
2009-09-18 20:51:23 +02:00
|
|
|
if (value == MP_BOARD_RESET_MAGIC) {
|
2017-05-15 23:41:13 +02:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2009-09-18 20:51:23 +02:00
|
|
|
}
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
static void mv88w8618_pit_reset(DeviceState *d)
|
2009-09-18 20:51:23 +02:00
|
|
|
{
|
2013-07-24 01:27:32 +02:00
|
|
|
mv88w8618_pit_state *s = MV88W8618_PIT(d);
|
2009-09-18 20:51:23 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
2019-10-08 19:17:24 +02:00
|
|
|
mv88w8618_timer_state *t = &s->timer[i];
|
|
|
|
ptimer_transaction_begin(t->ptimer);
|
|
|
|
ptimer_stop(t->ptimer);
|
|
|
|
ptimer_transaction_commit(t->ptimer);
|
|
|
|
t->limit = 0;
|
2009-09-18 20:51:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
static const MemoryRegionOps mv88w8618_pit_ops = {
|
|
|
|
.read = mv88w8618_pit_read,
|
|
|
|
.write = mv88w8618_pit_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2008-04-24 21:21:53 +02:00
|
|
|
};
|
|
|
|
|
2016-10-24 17:26:55 +02:00
|
|
|
static void mv88w8618_pit_init(Object *obj)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
2016-10-24 17:26:55 +02:00
|
|
|
SysBusDevice *dev = SYS_BUS_DEVICE(obj);
|
2013-07-24 01:27:32 +02:00
|
|
|
mv88w8618_pit_state *s = MV88W8618_PIT(dev);
|
2009-05-14 23:35:08 +02:00
|
|
|
int i;
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
/* Letting them all run at 1 MHz is likely just a pragmatic
|
|
|
|
* simplification. */
|
2009-05-14 23:35:08 +02:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
mv88w8618_timer_init(dev, &s->timer[i], 1000000);
|
|
|
|
}
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2016-10-24 17:26:55 +02:00
|
|
|
memory_region_init_io(&s->iomem, obj, &mv88w8618_pit_ops, s,
|
2011-08-08 21:50:06 +02:00
|
|
|
"musicpal-pit", MP_PIT_SIZE);
|
2011-11-27 10:38:10 +01:00
|
|
|
sysbus_init_mmio(dev, &s->iomem);
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
2020-12-17 12:31:54 +01:00
|
|
|
static void mv88w8618_pit_finalize(Object *obj)
|
|
|
|
{
|
|
|
|
SysBusDevice *dev = SYS_BUS_DEVICE(obj);
|
|
|
|
mv88w8618_pit_state *s = MV88W8618_PIT(dev);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
ptimer_free(s->timer[i].ptimer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
static const VMStateDescription mv88w8618_timer_vmsd = {
|
|
|
|
.name = "timer",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_PTIMER(ptimer, mv88w8618_timer_state),
|
|
|
|
VMSTATE_UINT32(limit, mv88w8618_timer_state),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const VMStateDescription mv88w8618_pit_vmsd = {
|
|
|
|
.name = "mv88w8618_pit",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_STRUCT_ARRAY(timer, mv88w8618_pit_state, 4, 1,
|
|
|
|
mv88w8618_timer_vmsd, mv88w8618_timer_state),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void mv88w8618_pit_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->reset = mv88w8618_pit_reset;
|
|
|
|
dc->vmsd = &mv88w8618_pit_vmsd;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo mv88w8618_pit_info = {
|
2013-07-24 01:27:32 +02:00
|
|
|
.name = TYPE_MV88W8618_PIT,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(mv88w8618_pit_state),
|
2016-10-24 17:26:55 +02:00
|
|
|
.instance_init = mv88w8618_pit_init,
|
2020-12-17 12:31:54 +01:00
|
|
|
.instance_finalize = mv88w8618_pit_finalize,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = mv88w8618_pit_class_init,
|
2009-09-18 20:51:23 +02:00
|
|
|
};
|
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
/* Flash config register offsets */
|
|
|
|
#define MP_FLASHCFG_CFGR0 0x04
|
|
|
|
|
2013-07-24 01:32:00 +02:00
|
|
|
#define TYPE_MV88W8618_FLASHCFG "mv88w8618_flashcfg"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(mv88w8618_flashcfg_state, MV88W8618_FLASHCFG)
|
2013-07-24 01:32:00 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct mv88w8618_flashcfg_state {
|
2013-07-24 01:32:00 +02:00
|
|
|
/*< private >*/
|
|
|
|
SysBusDevice parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
MemoryRegion iomem;
|
2008-04-24 21:21:53 +02:00
|
|
|
uint32_t cfgr0;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
static uint64_t mv88w8618_flashcfg_read(void *opaque,
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
unsigned size)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
|
|
|
mv88w8618_flashcfg_state *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case MP_FLASHCFG_CFGR0:
|
|
|
|
return s->cfgr0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void mv88w8618_flashcfg_write(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
uint64_t value, unsigned size)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
|
|
|
mv88w8618_flashcfg_state *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case MP_FLASHCFG_CFGR0:
|
|
|
|
s->cfgr0 = value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
static const MemoryRegionOps mv88w8618_flashcfg_ops = {
|
|
|
|
.read = mv88w8618_flashcfg_read,
|
|
|
|
.write = mv88w8618_flashcfg_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2008-04-24 21:21:53 +02:00
|
|
|
};
|
|
|
|
|
2016-10-24 17:26:55 +02:00
|
|
|
static void mv88w8618_flashcfg_init(Object *obj)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
2016-10-24 17:26:55 +02:00
|
|
|
SysBusDevice *dev = SYS_BUS_DEVICE(obj);
|
2013-07-24 01:32:00 +02:00
|
|
|
mv88w8618_flashcfg_state *s = MV88W8618_FLASHCFG(dev);
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
s->cfgr0 = 0xfffe4285; /* Default as set by U-Boot for 8 MB flash */
|
2016-10-24 17:26:55 +02:00
|
|
|
memory_region_init_io(&s->iomem, obj, &mv88w8618_flashcfg_ops, s,
|
2011-08-08 21:50:06 +02:00
|
|
|
"musicpal-flashcfg", MP_FLASHCFG_SIZE);
|
2011-11-27 10:38:10 +01:00
|
|
|
sysbus_init_mmio(dev, &s->iomem);
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
static const VMStateDescription mv88w8618_flashcfg_vmsd = {
|
|
|
|
.name = "mv88w8618_flashcfg",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(cfgr0, mv88w8618_flashcfg_state),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void mv88w8618_flashcfg_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->vmsd = &mv88w8618_flashcfg_vmsd;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo mv88w8618_flashcfg_info = {
|
2013-07-24 01:32:00 +02:00
|
|
|
.name = TYPE_MV88W8618_FLASHCFG,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(mv88w8618_flashcfg_state),
|
2016-10-24 17:26:55 +02:00
|
|
|
.instance_init = mv88w8618_flashcfg_init,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = mv88w8618_flashcfg_class_init,
|
2009-09-18 20:51:23 +02:00
|
|
|
};
|
|
|
|
|
2009-03-10 20:25:13 +01:00
|
|
|
/* Misc register offsets */
|
|
|
|
#define MP_MISC_BOARD_REVISION 0x18
|
|
|
|
|
|
|
|
#define MP_BOARD_REVISION 0x31
|
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct MusicPalMiscState {
|
2013-03-15 15:34:20 +01:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
MemoryRegion iomem;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2013-03-15 15:34:20 +01:00
|
|
|
|
|
|
|
#define TYPE_MUSICPAL_MISC "musicpal-misc"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(MusicPalMiscState, MUSICPAL_MISC)
|
2013-03-15 15:34:20 +01:00
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t musicpal_misc_read(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
unsigned size)
|
2009-03-10 20:25:13 +01:00
|
|
|
{
|
|
|
|
switch (offset) {
|
|
|
|
case MP_MISC_BOARD_REVISION:
|
|
|
|
return MP_BOARD_REVISION;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void musicpal_misc_write(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
uint64_t value, unsigned size)
|
2009-03-10 20:25:13 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
static const MemoryRegionOps musicpal_misc_ops = {
|
|
|
|
.read = musicpal_misc_read,
|
|
|
|
.write = musicpal_misc_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2009-03-10 20:25:13 +01:00
|
|
|
};
|
|
|
|
|
2013-03-15 15:34:20 +01:00
|
|
|
static void musicpal_misc_init(Object *obj)
|
2009-03-10 20:25:13 +01:00
|
|
|
{
|
2013-03-15 15:34:20 +01:00
|
|
|
SysBusDevice *sd = SYS_BUS_DEVICE(obj);
|
|
|
|
MusicPalMiscState *s = MUSICPAL_MISC(obj);
|
2009-03-10 20:25:13 +01:00
|
|
|
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&s->iomem, OBJECT(s), &musicpal_misc_ops, NULL,
|
2011-08-08 21:50:06 +02:00
|
|
|
"musicpal-misc", MP_MISC_SIZE);
|
2013-03-15 15:34:20 +01:00
|
|
|
sysbus_init_mmio(sd, &s->iomem);
|
2009-03-10 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2013-03-15 15:34:20 +01:00
|
|
|
static const TypeInfo musicpal_misc_info = {
|
|
|
|
.name = TYPE_MUSICPAL_MISC,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_init = musicpal_misc_init,
|
|
|
|
.instance_size = sizeof(MusicPalMiscState),
|
|
|
|
};
|
|
|
|
|
2009-03-10 20:25:13 +01:00
|
|
|
/* WLAN register offsets */
|
|
|
|
#define MP_WLAN_MAGIC1 0x11c
|
|
|
|
#define MP_WLAN_MAGIC2 0x124
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t mv88w8618_wlan_read(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
unsigned size)
|
2009-03-10 20:25:13 +01:00
|
|
|
{
|
|
|
|
switch (offset) {
|
|
|
|
/* Workaround to allow loading the binary-only wlandrv.ko crap
|
|
|
|
* from the original Freecom firmware. */
|
|
|
|
case MP_WLAN_MAGIC1:
|
|
|
|
return ~3;
|
|
|
|
case MP_WLAN_MAGIC2:
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void mv88w8618_wlan_write(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
uint64_t value, unsigned size)
|
2009-03-10 20:25:13 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
static const MemoryRegionOps mv88w8618_wlan_ops = {
|
|
|
|
.read = mv88w8618_wlan_read,
|
|
|
|
.write =mv88w8618_wlan_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2009-03-10 20:25:13 +01:00
|
|
|
};
|
|
|
|
|
2018-12-13 14:47:56 +01:00
|
|
|
static void mv88w8618_wlan_realize(DeviceState *dev, Error **errp)
|
2009-03-10 20:25:13 +01:00
|
|
|
{
|
2011-08-08 21:50:06 +02:00
|
|
|
MemoryRegion *iomem = g_new(MemoryRegion, 1);
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(iomem, OBJECT(dev), &mv88w8618_wlan_ops, NULL,
|
2011-08-08 21:50:06 +02:00
|
|
|
"musicpal-wlan", MP_WLAN_SIZE);
|
2018-12-13 14:47:56 +01:00
|
|
|
sysbus_init_mmio(SYS_BUS_DEVICE(dev), iomem);
|
2009-03-10 20:25:13 +01:00
|
|
|
}
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2009-03-10 20:25:13 +01:00
|
|
|
/* GPIO register offsets */
|
|
|
|
#define MP_GPIO_OE_LO 0x008
|
|
|
|
#define MP_GPIO_OUT_LO 0x00c
|
|
|
|
#define MP_GPIO_IN_LO 0x010
|
2009-09-18 20:51:23 +02:00
|
|
|
#define MP_GPIO_IER_LO 0x014
|
|
|
|
#define MP_GPIO_IMR_LO 0x018
|
2009-03-10 20:25:13 +01:00
|
|
|
#define MP_GPIO_ISR_LO 0x020
|
|
|
|
#define MP_GPIO_OE_HI 0x508
|
|
|
|
#define MP_GPIO_OUT_HI 0x50c
|
|
|
|
#define MP_GPIO_IN_HI 0x510
|
2009-09-18 20:51:23 +02:00
|
|
|
#define MP_GPIO_IER_HI 0x514
|
|
|
|
#define MP_GPIO_IMR_HI 0x518
|
2009-03-10 20:25:13 +01:00
|
|
|
#define MP_GPIO_ISR_HI 0x520
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
/* GPIO bits & masks */
|
|
|
|
#define MP_GPIO_LCD_BRIGHTNESS 0x00070000
|
|
|
|
#define MP_GPIO_I2C_DATA_BIT 29
|
|
|
|
#define MP_GPIO_I2C_CLOCK_BIT 30
|
|
|
|
|
|
|
|
/* LCD brightness bits in GPIO_OE_HI */
|
|
|
|
#define MP_OE_LCD_BRIGHTNESS 0x0007
|
|
|
|
|
2013-07-24 01:36:24 +02:00
|
|
|
#define TYPE_MUSICPAL_GPIO "musicpal_gpio"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(musicpal_gpio_state, MUSICPAL_GPIO)
|
2013-07-24 01:36:24 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct musicpal_gpio_state {
|
2013-07-24 01:36:24 +02:00
|
|
|
/*< private >*/
|
|
|
|
SysBusDevice parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
MemoryRegion iomem;
|
2009-08-23 14:38:07 +02:00
|
|
|
uint32_t lcd_brightness;
|
|
|
|
uint32_t out_state;
|
|
|
|
uint32_t in_state;
|
2009-09-18 20:51:23 +02:00
|
|
|
uint32_t ier;
|
|
|
|
uint32_t imr;
|
2009-08-23 14:38:07 +02:00
|
|
|
uint32_t isr;
|
|
|
|
qemu_irq irq;
|
2009-09-18 20:51:23 +02:00
|
|
|
qemu_irq out[5]; /* 3 brightness out + 2 lcd (data and clock ) */
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2009-08-23 14:38:07 +02:00
|
|
|
|
|
|
|
static void musicpal_gpio_brightness_update(musicpal_gpio_state *s) {
|
|
|
|
int i;
|
|
|
|
uint32_t brightness;
|
|
|
|
|
|
|
|
/* compute brightness ratio */
|
|
|
|
switch (s->lcd_brightness) {
|
|
|
|
case 0x00000007:
|
|
|
|
brightness = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x00020000:
|
|
|
|
brightness = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x00020001:
|
|
|
|
brightness = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x00040000:
|
|
|
|
brightness = 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x00010006:
|
|
|
|
brightness = 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x00020005:
|
|
|
|
brightness = 5;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x00040003:
|
|
|
|
brightness = 6;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x00030004:
|
|
|
|
default:
|
|
|
|
brightness = 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set lcd brightness GPIOs */
|
2009-09-18 20:51:23 +02:00
|
|
|
for (i = 0; i <= 2; i++) {
|
2009-08-23 14:38:07 +02:00
|
|
|
qemu_set_irq(s->out[i], (brightness >> i) & 1);
|
2009-09-18 20:51:23 +02:00
|
|
|
}
|
2009-08-23 14:38:07 +02:00
|
|
|
}
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
static void musicpal_gpio_pin_event(void *opaque, int pin, int level)
|
2009-08-23 14:38:07 +02:00
|
|
|
{
|
2009-09-18 20:51:23 +02:00
|
|
|
musicpal_gpio_state *s = opaque;
|
2009-09-18 20:51:23 +02:00
|
|
|
uint32_t mask = 1 << pin;
|
|
|
|
uint32_t delta = level << pin;
|
|
|
|
uint32_t old = s->in_state & mask;
|
2009-08-23 14:38:07 +02:00
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
s->in_state &= ~mask;
|
|
|
|
s->in_state |= delta;
|
2009-08-23 14:38:07 +02:00
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
if ((old ^ delta) &&
|
|
|
|
((level && (s->imr & mask)) || (!level && (s->ier & mask)))) {
|
|
|
|
s->isr = mask;
|
|
|
|
qemu_irq_raise(s->irq);
|
2009-08-23 14:38:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t musicpal_gpio_read(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
unsigned size)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
2009-09-18 20:51:23 +02:00
|
|
|
musicpal_gpio_state *s = opaque;
|
2009-08-23 14:38:07 +02:00
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
switch (offset) {
|
|
|
|
case MP_GPIO_OE_HI: /* used for LCD brightness control */
|
2009-08-23 14:38:07 +02:00
|
|
|
return s->lcd_brightness & MP_OE_LCD_BRIGHTNESS;
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
case MP_GPIO_OUT_LO:
|
2009-08-23 14:38:07 +02:00
|
|
|
return s->out_state & 0xFFFF;
|
2008-04-24 21:21:53 +02:00
|
|
|
case MP_GPIO_OUT_HI:
|
2009-08-23 14:38:07 +02:00
|
|
|
return s->out_state >> 16;
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
case MP_GPIO_IN_LO:
|
2009-08-23 14:38:07 +02:00
|
|
|
return s->in_state & 0xFFFF;
|
2008-04-24 21:21:53 +02:00
|
|
|
case MP_GPIO_IN_HI:
|
2009-08-23 14:38:07 +02:00
|
|
|
return s->in_state >> 16;
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
case MP_GPIO_IER_LO:
|
|
|
|
return s->ier & 0xFFFF;
|
|
|
|
case MP_GPIO_IER_HI:
|
|
|
|
return s->ier >> 16;
|
|
|
|
|
|
|
|
case MP_GPIO_IMR_LO:
|
|
|
|
return s->imr & 0xFFFF;
|
|
|
|
case MP_GPIO_IMR_HI:
|
|
|
|
return s->imr >> 16;
|
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
case MP_GPIO_ISR_LO:
|
2009-08-23 14:38:07 +02:00
|
|
|
return s->isr & 0xFFFF;
|
2008-04-24 21:21:53 +02:00
|
|
|
case MP_GPIO_ISR_HI:
|
2009-08-23 14:38:07 +02:00
|
|
|
return s->isr >> 16;
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void musicpal_gpio_write(void *opaque, hwaddr offset,
|
2011-08-08 21:50:06 +02:00
|
|
|
uint64_t value, unsigned size)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
2009-09-18 20:51:23 +02:00
|
|
|
musicpal_gpio_state *s = opaque;
|
2008-04-24 21:21:53 +02:00
|
|
|
switch (offset) {
|
|
|
|
case MP_GPIO_OE_HI: /* used for LCD brightness control */
|
2009-08-23 14:38:07 +02:00
|
|
|
s->lcd_brightness = (s->lcd_brightness & MP_GPIO_LCD_BRIGHTNESS) |
|
2008-04-24 21:21:53 +02:00
|
|
|
(value & MP_OE_LCD_BRIGHTNESS);
|
2009-08-23 14:38:07 +02:00
|
|
|
musicpal_gpio_brightness_update(s);
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_GPIO_OUT_LO:
|
2009-08-23 14:38:07 +02:00
|
|
|
s->out_state = (s->out_state & 0xFFFF0000) | (value & 0xFFFF);
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
case MP_GPIO_OUT_HI:
|
2009-08-23 14:38:07 +02:00
|
|
|
s->out_state = (s->out_state & 0xFFFF) | (value << 16);
|
|
|
|
s->lcd_brightness = (s->lcd_brightness & 0xFFFF) |
|
|
|
|
(s->out_state & MP_GPIO_LCD_BRIGHTNESS);
|
|
|
|
musicpal_gpio_brightness_update(s);
|
2009-08-23 15:51:14 +02:00
|
|
|
qemu_set_irq(s->out[3], (s->out_state >> MP_GPIO_I2C_DATA_BIT) & 1);
|
|
|
|
qemu_set_irq(s->out[4], (s->out_state >> MP_GPIO_I2C_CLOCK_BIT) & 1);
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
case MP_GPIO_IER_LO:
|
|
|
|
s->ier = (s->ier & 0xFFFF0000) | (value & 0xFFFF);
|
|
|
|
break;
|
|
|
|
case MP_GPIO_IER_HI:
|
|
|
|
s->ier = (s->ier & 0xFFFF) | (value << 16);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_GPIO_IMR_LO:
|
|
|
|
s->imr = (s->imr & 0xFFFF0000) | (value & 0xFFFF);
|
|
|
|
break;
|
|
|
|
case MP_GPIO_IMR_HI:
|
|
|
|
s->imr = (s->imr & 0xFFFF) | (value << 16);
|
|
|
|
break;
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-08 21:50:06 +02:00
|
|
|
static const MemoryRegionOps musicpal_gpio_ops = {
|
|
|
|
.read = musicpal_gpio_read,
|
|
|
|
.write = musicpal_gpio_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2009-03-10 20:25:13 +01:00
|
|
|
};
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
static void musicpal_gpio_reset(DeviceState *d)
|
2009-03-10 20:25:13 +01:00
|
|
|
{
|
2013-07-24 01:36:24 +02:00
|
|
|
musicpal_gpio_state *s = MUSICPAL_GPIO(d);
|
2009-09-18 20:51:23 +02:00
|
|
|
|
|
|
|
s->lcd_brightness = 0;
|
|
|
|
s->out_state = 0;
|
2009-08-23 14:38:07 +02:00
|
|
|
s->in_state = 0xffffffff;
|
2009-09-18 20:51:23 +02:00
|
|
|
s->ier = 0;
|
|
|
|
s->imr = 0;
|
2009-08-23 14:38:07 +02:00
|
|
|
s->isr = 0;
|
|
|
|
}
|
|
|
|
|
2016-10-24 17:26:55 +02:00
|
|
|
static void musicpal_gpio_init(Object *obj)
|
2009-08-23 14:38:07 +02:00
|
|
|
{
|
2016-10-24 17:26:55 +02:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2013-07-24 01:36:24 +02:00
|
|
|
DeviceState *dev = DEVICE(sbd);
|
|
|
|
musicpal_gpio_state *s = MUSICPAL_GPIO(dev);
|
2009-03-10 20:25:13 +01:00
|
|
|
|
2013-07-24 01:36:24 +02:00
|
|
|
sysbus_init_irq(sbd, &s->irq);
|
2009-08-23 14:38:07 +02:00
|
|
|
|
2016-10-24 17:26:55 +02:00
|
|
|
memory_region_init_io(&s->iomem, obj, &musicpal_gpio_ops, s,
|
2011-08-08 21:50:06 +02:00
|
|
|
"musicpal-gpio", MP_GPIO_SIZE);
|
2013-07-24 01:36:24 +02:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2009-08-23 14:38:07 +02:00
|
|
|
|
2013-07-24 01:36:24 +02:00
|
|
|
qdev_init_gpio_out(dev, s->out, ARRAY_SIZE(s->out));
|
2009-09-18 20:51:23 +02:00
|
|
|
|
2013-07-24 01:36:24 +02:00
|
|
|
qdev_init_gpio_in(dev, musicpal_gpio_pin_event, 32);
|
2009-03-10 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
static const VMStateDescription musicpal_gpio_vmsd = {
|
|
|
|
.name = "musicpal_gpio",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(lcd_brightness, musicpal_gpio_state),
|
|
|
|
VMSTATE_UINT32(out_state, musicpal_gpio_state),
|
|
|
|
VMSTATE_UINT32(in_state, musicpal_gpio_state),
|
|
|
|
VMSTATE_UINT32(ier, musicpal_gpio_state),
|
|
|
|
VMSTATE_UINT32(imr, musicpal_gpio_state),
|
|
|
|
VMSTATE_UINT32(isr, musicpal_gpio_state),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void musicpal_gpio_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->reset = musicpal_gpio_reset;
|
|
|
|
dc->vmsd = &musicpal_gpio_vmsd;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo musicpal_gpio_info = {
|
2013-07-24 01:36:24 +02:00
|
|
|
.name = TYPE_MUSICPAL_GPIO,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(musicpal_gpio_state),
|
2016-10-24 17:26:55 +02:00
|
|
|
.instance_init = musicpal_gpio_init,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = musicpal_gpio_class_init,
|
2009-09-18 20:51:23 +02:00
|
|
|
};
|
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
/* Keyboard codes & masks */
|
2008-05-17 20:18:04 +02:00
|
|
|
#define KEY_RELEASED 0x80
|
2008-04-24 21:21:53 +02:00
|
|
|
#define KEY_CODE 0x7f
|
|
|
|
|
|
|
|
#define KEYCODE_TAB 0x0f
|
|
|
|
#define KEYCODE_ENTER 0x1c
|
|
|
|
#define KEYCODE_F 0x21
|
|
|
|
#define KEYCODE_M 0x32
|
|
|
|
|
|
|
|
#define KEYCODE_EXTENDED 0xe0
|
|
|
|
#define KEYCODE_UP 0x48
|
|
|
|
#define KEYCODE_DOWN 0x50
|
|
|
|
#define KEYCODE_LEFT 0x4b
|
|
|
|
#define KEYCODE_RIGHT 0x4d
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
#define MP_KEY_WHEEL_VOL (1 << 0)
|
2009-08-23 14:38:07 +02:00
|
|
|
#define MP_KEY_WHEEL_VOL_INV (1 << 1)
|
|
|
|
#define MP_KEY_WHEEL_NAV (1 << 2)
|
|
|
|
#define MP_KEY_WHEEL_NAV_INV (1 << 3)
|
|
|
|
#define MP_KEY_BTN_FAVORITS (1 << 4)
|
|
|
|
#define MP_KEY_BTN_MENU (1 << 5)
|
|
|
|
#define MP_KEY_BTN_VOLUME (1 << 6)
|
|
|
|
#define MP_KEY_BTN_NAVIGATION (1 << 7)
|
|
|
|
|
2013-07-24 01:38:59 +02:00
|
|
|
#define TYPE_MUSICPAL_KEY "musicpal_key"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(musicpal_key_state, MUSICPAL_KEY)
|
2013-07-24 01:38:59 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct musicpal_key_state {
|
2013-07-24 01:38:59 +02:00
|
|
|
/*< private >*/
|
|
|
|
SysBusDevice parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
2011-11-14 11:59:29 +01:00
|
|
|
MemoryRegion iomem;
|
2009-08-23 14:38:07 +02:00
|
|
|
uint32_t kbd_extended;
|
2009-09-18 20:51:23 +02:00
|
|
|
uint32_t pressed_keys;
|
|
|
|
qemu_irq out[8];
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2009-08-23 14:38:07 +02:00
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
static void musicpal_key_event(void *opaque, int keycode)
|
|
|
|
{
|
2009-09-18 20:51:23 +02:00
|
|
|
musicpal_key_state *s = opaque;
|
2008-04-24 21:21:53 +02:00
|
|
|
uint32_t event = 0;
|
2009-08-23 14:38:07 +02:00
|
|
|
int i;
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
if (keycode == KEYCODE_EXTENDED) {
|
2009-08-23 14:38:07 +02:00
|
|
|
s->kbd_extended = 1;
|
2008-04-24 21:21:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
if (s->kbd_extended) {
|
2008-04-24 21:21:53 +02:00
|
|
|
switch (keycode & KEY_CODE) {
|
|
|
|
case KEYCODE_UP:
|
2009-08-23 14:38:07 +02:00
|
|
|
event = MP_KEY_WHEEL_NAV | MP_KEY_WHEEL_NAV_INV;
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYCODE_DOWN:
|
2009-08-23 14:38:07 +02:00
|
|
|
event = MP_KEY_WHEEL_NAV;
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYCODE_LEFT:
|
2009-08-23 14:38:07 +02:00
|
|
|
event = MP_KEY_WHEEL_VOL | MP_KEY_WHEEL_VOL_INV;
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYCODE_RIGHT:
|
2009-08-23 14:38:07 +02:00
|
|
|
event = MP_KEY_WHEEL_VOL;
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
}
|
2009-09-18 20:51:23 +02:00
|
|
|
} else {
|
2008-04-24 21:21:53 +02:00
|
|
|
switch (keycode & KEY_CODE) {
|
|
|
|
case KEYCODE_F:
|
2009-08-23 14:38:07 +02:00
|
|
|
event = MP_KEY_BTN_FAVORITS;
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYCODE_TAB:
|
2009-08-23 14:38:07 +02:00
|
|
|
event = MP_KEY_BTN_VOLUME;
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYCODE_ENTER:
|
2009-08-23 14:38:07 +02:00
|
|
|
event = MP_KEY_BTN_NAVIGATION;
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYCODE_M:
|
2009-08-23 14:38:07 +02:00
|
|
|
event = MP_KEY_BTN_MENU;
|
2008-04-24 21:21:53 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-05-17 20:18:04 +02:00
|
|
|
/* Do not repeat already pressed buttons */
|
2009-09-18 20:51:23 +02:00
|
|
|
if (!(keycode & KEY_RELEASED) && (s->pressed_keys & event)) {
|
2008-05-17 20:18:04 +02:00
|
|
|
event = 0;
|
2009-09-18 20:51:23 +02:00
|
|
|
}
|
2008-05-17 20:18:04 +02:00
|
|
|
}
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2008-05-17 20:18:04 +02:00
|
|
|
if (event) {
|
2009-09-18 20:51:23 +02:00
|
|
|
/* Raise GPIO pin first if repeating a key */
|
|
|
|
if (!(keycode & KEY_RELEASED) && (s->pressed_keys & event)) {
|
|
|
|
for (i = 0; i <= 7; i++) {
|
|
|
|
if (event & (1 << i)) {
|
|
|
|
qemu_set_irq(s->out[i], 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i <= 7; i++) {
|
|
|
|
if (event & (1 << i)) {
|
|
|
|
qemu_set_irq(s->out[i], !!(keycode & KEY_RELEASED));
|
|
|
|
}
|
|
|
|
}
|
2008-05-17 20:18:04 +02:00
|
|
|
if (keycode & KEY_RELEASED) {
|
2009-09-18 20:51:23 +02:00
|
|
|
s->pressed_keys &= ~event;
|
2008-05-17 20:18:04 +02:00
|
|
|
} else {
|
2009-09-18 20:51:23 +02:00
|
|
|
s->pressed_keys |= event;
|
2008-05-17 20:18:04 +02:00
|
|
|
}
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
2009-08-23 14:38:07 +02:00
|
|
|
s->kbd_extended = 0;
|
|
|
|
}
|
|
|
|
|
2016-10-24 17:26:55 +02:00
|
|
|
static void musicpal_key_init(Object *obj)
|
2009-08-23 14:38:07 +02:00
|
|
|
{
|
2016-10-24 17:26:55 +02:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2013-07-24 01:38:59 +02:00
|
|
|
DeviceState *dev = DEVICE(sbd);
|
|
|
|
musicpal_key_state *s = MUSICPAL_KEY(dev);
|
2009-08-23 14:38:07 +02:00
|
|
|
|
2016-10-24 17:26:55 +02:00
|
|
|
memory_region_init(&s->iomem, obj, "dummy", 0);
|
2013-07-24 01:38:59 +02:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2009-08-23 14:38:07 +02:00
|
|
|
|
|
|
|
s->kbd_extended = 0;
|
2009-09-18 20:51:23 +02:00
|
|
|
s->pressed_keys = 0;
|
2009-08-23 14:38:07 +02:00
|
|
|
|
2013-07-24 01:38:59 +02:00
|
|
|
qdev_init_gpio_out(dev, s->out, ARRAY_SIZE(s->out));
|
2009-08-23 14:38:07 +02:00
|
|
|
|
|
|
|
qemu_add_kbd_event_handler(musicpal_key_event, s);
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
static const VMStateDescription musicpal_key_vmsd = {
|
|
|
|
.name = "musicpal_key",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(kbd_extended, musicpal_key_state),
|
|
|
|
VMSTATE_UINT32(pressed_keys, musicpal_key_state),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void musicpal_key_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->vmsd = &musicpal_key_vmsd;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo musicpal_key_info = {
|
2013-07-24 01:38:59 +02:00
|
|
|
.name = TYPE_MUSICPAL_KEY,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(musicpal_key_state),
|
2016-10-24 17:26:55 +02:00
|
|
|
.instance_init = musicpal_key_init,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = musicpal_key_class_init,
|
2009-09-18 20:51:23 +02:00
|
|
|
};
|
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
static struct arm_boot_info musicpal_binfo = {
|
|
|
|
.loader_start = 0x0,
|
|
|
|
.board_id = 0x20e,
|
|
|
|
};
|
|
|
|
|
2014-05-07 16:42:57 +02:00
|
|
|
static void musicpal_init(MachineState *machine)
|
2008-04-24 21:21:53 +02:00
|
|
|
{
|
2012-05-14 01:54:18 +02:00
|
|
|
ARMCPU *cpu;
|
2009-05-14 23:35:08 +02:00
|
|
|
DeviceState *dev;
|
2020-11-07 20:34:03 +01:00
|
|
|
DeviceState *pic;
|
2020-11-07 20:34:02 +01:00
|
|
|
DeviceState *uart_orgate;
|
2009-08-23 15:51:14 +02:00
|
|
|
DeviceState *i2c_dev;
|
2009-08-23 14:38:07 +02:00
|
|
|
DeviceState *lcd_dev;
|
|
|
|
DeviceState *key_dev;
|
2020-07-06 00:41:53 +02:00
|
|
|
I2CSlave *wm8750_dev;
|
2009-08-23 15:51:14 +02:00
|
|
|
SysBusDevice *s;
|
2013-08-03 00:18:51 +02:00
|
|
|
I2CBus *i2c;
|
2009-05-14 23:35:08 +02:00
|
|
|
int i;
|
2008-04-24 21:21:53 +02:00
|
|
|
unsigned long flash_size;
|
2009-07-22 16:42:57 +02:00
|
|
|
DriveInfo *dinfo;
|
2020-02-19 17:08:58 +01:00
|
|
|
MachineClass *mc = MACHINE_GET_CLASS(machine);
|
2011-08-08 21:50:06 +02:00
|
|
|
MemoryRegion *address_space_mem = get_system_memory();
|
|
|
|
MemoryRegion *sram = g_new(MemoryRegion, 1);
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2020-02-19 17:08:58 +01:00
|
|
|
/* For now we use a fixed - the original - RAM size */
|
|
|
|
if (machine->ram_size != mc->default_ram_size) {
|
|
|
|
char *sz = size_to_str(mc->default_ram_size);
|
|
|
|
error_report("Invalid RAM size, should be %s", sz);
|
|
|
|
g_free(sz);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2017-09-13 18:04:57 +02:00
|
|
|
cpu = ARM_CPU(cpu_create(machine->cpu_type));
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2020-02-19 17:08:58 +01:00
|
|
|
memory_region_add_subregion(address_space_mem, 0, machine->ram);
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2017-07-07 16:42:53 +02:00
|
|
|
memory_region_init_ram(sram, NULL, "musicpal.sram", MP_SRAM_SIZE,
|
Fix bad error handling after memory_region_init_ram()
Symptom:
$ qemu-system-x86_64 -m 10000000
Unexpected error in ram_block_add() at /work/armbru/qemu/exec.c:1456:
upstream-qemu: cannot set up guest memory 'pc.ram': Cannot allocate memory
Aborted (core dumped)
Root cause: commit ef701d7 screwed up handling of out-of-memory
conditions. Before the commit, we report the error and exit(1), in
one place, ram_block_add(). The commit lifts the error handling up
the call chain some, to three places. Fine. Except it uses
&error_abort in these places, changing the behavior from exit(1) to
abort(), and thus undoing the work of commit 3922825 "exec: Don't
abort when we can't allocate guest memory".
The three places are:
* memory_region_init_ram()
Commit 4994653 (right after commit ef701d7) lifted the error
handling further, through memory_region_init_ram(), multiplying the
incorrect use of &error_abort. Later on, imitation of existing
(bad) code may have created more.
* memory_region_init_ram_ptr()
The &error_abort is still there.
* memory_region_init_rom_device()
Doesn't need fixing, because commit 33e0eb5 (soon after commit
ef701d7) lifted the error handling further, and in the process
changed it from &error_abort to passing it up the call chain.
Correct, because the callers are realize() methods.
Fix the error handling after memory_region_init_ram() with a
Coccinelle semantic patch:
@r@
expression mr, owner, name, size, err;
position p;
@@
memory_region_init_ram(mr, owner, name, size,
(
- &error_abort
+ &error_fatal
|
err@p
)
);
@script:python@
p << r.p;
@@
print "%s:%s:%s" % (p[0].file, p[0].line, p[0].column)
When the last argument is &error_abort, it gets replaced by
&error_fatal. This is the fix.
If the last argument is anything else, its position is reported. This
lets us check the fix is complete. Four positions get reported:
* ram_backend_memory_alloc()
Error is passed up the call chain, ultimately through
user_creatable_complete(). As far as I can tell, it's callers all
handle the error sanely.
* fsl_imx25_realize(), fsl_imx31_realize(), dp8393x_realize()
DeviceClass.realize() methods, errors handled sanely further up the
call chain.
We're good. Test case again behaves:
$ qemu-system-x86_64 -m 10000000
qemu-system-x86_64: cannot set up guest memory 'pc.ram': Cannot allocate memory
[Exit 1 ]
The next commits will repair the rest of commit ef701d7's damage.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1441983105-26376-3-git-send-email-armbru@redhat.com>
Reviewed-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
2015-09-11 16:51:43 +02:00
|
|
|
&error_fatal);
|
2011-08-08 21:50:06 +02:00
|
|
|
memory_region_add_subregion(address_space_mem, MP_SRAM_BASE, sram);
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2020-11-07 20:34:03 +01:00
|
|
|
pic = sysbus_create_simple(TYPE_MV88W8618_PIC, MP_PIC_BASE,
|
2013-08-20 15:54:29 +02:00
|
|
|
qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_IRQ));
|
2020-11-07 20:34:03 +01:00
|
|
|
sysbus_create_varargs(TYPE_MV88W8618_PIT, MP_PIT_BASE,
|
|
|
|
qdev_get_gpio_in(pic, MP_TIMER1_IRQ),
|
|
|
|
qdev_get_gpio_in(pic, MP_TIMER2_IRQ),
|
|
|
|
qdev_get_gpio_in(pic, MP_TIMER3_IRQ),
|
|
|
|
qdev_get_gpio_in(pic, MP_TIMER4_IRQ), NULL);
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2020-11-07 20:34:02 +01:00
|
|
|
/* Logically OR both UART IRQs together */
|
|
|
|
uart_orgate = DEVICE(object_new(TYPE_OR_IRQ));
|
|
|
|
object_property_set_int(OBJECT(uart_orgate), "num-lines", 2, &error_fatal);
|
|
|
|
qdev_realize_and_unref(uart_orgate, NULL, &error_fatal);
|
2020-11-07 20:34:03 +01:00
|
|
|
qdev_connect_gpio_out(DEVICE(uart_orgate), 0,
|
|
|
|
qdev_get_gpio_in(pic, MP_UART_SHARED_IRQ));
|
2020-11-07 20:34:02 +01:00
|
|
|
|
|
|
|
serial_mm_init(address_space_mem, MP_UART1_BASE, 2,
|
|
|
|
qdev_get_gpio_in(uart_orgate, 0),
|
2020-05-05 11:59:45 +02:00
|
|
|
1825000, serial_hd(0), DEVICE_NATIVE_ENDIAN);
|
2020-11-07 20:34:02 +01:00
|
|
|
serial_mm_init(address_space_mem, MP_UART2_BASE, 2,
|
|
|
|
qdev_get_gpio_in(uart_orgate, 1),
|
2020-05-05 11:59:45 +02:00
|
|
|
1825000, serial_hd(1), DEVICE_NATIVE_ENDIAN);
|
2008-04-24 21:21:53 +02:00
|
|
|
|
|
|
|
/* Register flash */
|
2009-07-22 16:42:57 +02:00
|
|
|
dinfo = drive_get(IF_PFLASH, 0, 0);
|
|
|
|
if (dinfo) {
|
2014-10-07 13:59:18 +02:00
|
|
|
BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
|
2014-10-07 13:59:13 +02:00
|
|
|
|
2014-10-07 13:59:18 +02:00
|
|
|
flash_size = blk_getlength(blk);
|
2008-04-24 21:21:53 +02:00
|
|
|
if (flash_size != 8*1024*1024 && flash_size != 16*1024*1024 &&
|
|
|
|
flash_size != 32*1024*1024) {
|
hw/arm: Replace fprintf(stderr, "*\n" with error_report()
Replace a large number of the fprintf(stderr, "*\n" calls with
error_report(). The functions were renamed with these commands and then
compiler issues where manually fixed.
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
Some lines where then manually tweaked to pass checkpatch.
The 'qemu: ' prefix was manually removed from the hw/arm/boot.c file.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Cc: qemu-arm@nongnu.org
Conversions that aren't followed by exit() dropped, because they might
be inappropriate.
Also trim trailing punctuation from error messages.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20180203084315.20497-3-armbru@redhat.com>
2018-02-03 09:43:03 +01:00
|
|
|
error_report("Invalid flash image size");
|
2008-04-24 21:21:53 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The original U-Boot accesses the flash at 0xFE000000 instead of
|
|
|
|
* 0xFF800000 (if there is 8 MB flash). So remap flash access if the
|
|
|
|
* image is smaller than 32 MB.
|
|
|
|
*/
|
2019-03-08 10:46:09 +01:00
|
|
|
pflash_cfi02_register(0x100000000ULL - MP_FLASH_SIZE_MAX,
|
2011-08-04 14:55:30 +02:00
|
|
|
"musicpal.flash", flash_size,
|
2019-03-08 10:46:10 +01:00
|
|
|
blk, 0x10000,
|
2010-03-29 21:23:55 +02:00
|
|
|
MP_FLASH_SIZE_MAX / flash_size,
|
|
|
|
2, 0x00BF, 0x236D, 0x0000, 0x0000,
|
2011-08-25 21:39:18 +02:00
|
|
|
0x5555, 0x2AAA, 0);
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
2013-07-24 01:32:00 +02:00
|
|
|
sysbus_create_simple(TYPE_MV88W8618_FLASHCFG, MP_FLASHCFG_BASE, NULL);
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2009-05-14 23:35:08 +02:00
|
|
|
qemu_check_nic_model(&nd_table[0], "mv88w8618");
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:31:58 +02:00
|
|
|
dev = qdev_new(TYPE_MV88W8618_ETH);
|
2009-10-21 15:25:40 +02:00
|
|
|
qdev_set_nic_properties(dev, &nd_table[0]);
|
2020-08-28 11:02:44 +02:00
|
|
|
object_property_set_link(OBJECT(dev), "dma-memory",
|
|
|
|
OBJECT(get_system_memory()), &error_fatal);
|
sysbus: Convert to sysbus_realize() etc. with Coccinelle
Convert from qdev_realize(), qdev_realize_and_unref() with null @bus
argument to sysbus_realize(), sysbus_realize_and_unref().
Coccinelle script:
@@
expression dev, errp;
@@
- qdev_realize(DEVICE(dev), NULL, errp);
+ sysbus_realize(SYS_BUS_DEVICE(dev), errp);
@@
expression sysbus_dev, dev, errp;
@@
+ sysbus_dev = SYS_BUS_DEVICE(dev);
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
- sysbus_dev = SYS_BUS_DEVICE(dev);
@@
expression sysbus_dev, dev, errp;
expression expr;
@@
sysbus_dev = SYS_BUS_DEVICE(dev);
... when != dev = expr;
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(DEVICE(dev), NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
Whitespace changes minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-46-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:32:34 +02:00
|
|
|
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
|
2013-01-20 02:47:33 +01:00
|
|
|
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, MP_ETH_BASE);
|
2020-11-07 20:34:03 +01:00
|
|
|
sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0,
|
|
|
|
qdev_get_gpio_in(pic, MP_ETH_IRQ));
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2009-05-14 23:35:08 +02:00
|
|
|
sysbus_create_simple("mv88w8618_wlan", MP_WLAN_BASE, NULL);
|
2009-03-10 20:25:13 +01:00
|
|
|
|
2013-03-15 15:34:20 +01:00
|
|
|
sysbus_create_simple(TYPE_MUSICPAL_MISC, MP_MISC_BASE, NULL);
|
2009-08-23 14:38:07 +02:00
|
|
|
|
2013-07-24 01:36:24 +02:00
|
|
|
dev = sysbus_create_simple(TYPE_MUSICPAL_GPIO, MP_GPIO_BASE,
|
2020-11-07 20:34:03 +01:00
|
|
|
qdev_get_gpio_in(pic, MP_GPIO_IRQ));
|
2011-04-10 09:35:42 +02:00
|
|
|
i2c_dev = sysbus_create_simple("gpio_i2c", -1, NULL);
|
2013-08-03 00:18:51 +02:00
|
|
|
i2c = (I2CBus *)qdev_get_child_bus(i2c_dev, "i2c");
|
2009-08-23 15:51:14 +02:00
|
|
|
|
2013-07-24 01:16:13 +02:00
|
|
|
lcd_dev = sysbus_create_simple(TYPE_MUSICPAL_LCD, MP_LCD_BASE, NULL);
|
2013-07-24 01:38:59 +02:00
|
|
|
key_dev = sysbus_create_simple(TYPE_MUSICPAL_KEY, -1, NULL);
|
2009-08-23 14:38:07 +02:00
|
|
|
|
2009-08-23 15:51:14 +02:00
|
|
|
/* I2C read data */
|
2009-09-18 20:51:23 +02:00
|
|
|
qdev_connect_gpio_out(i2c_dev, 0,
|
|
|
|
qdev_get_gpio_in(dev, MP_GPIO_I2C_DATA_BIT));
|
2009-08-23 15:51:14 +02:00
|
|
|
/* I2C data */
|
|
|
|
qdev_connect_gpio_out(dev, 3, qdev_get_gpio_in(i2c_dev, 0));
|
|
|
|
/* I2C clock */
|
|
|
|
qdev_connect_gpio_out(dev, 4, qdev_get_gpio_in(i2c_dev, 1));
|
|
|
|
|
2009-09-18 20:51:23 +02:00
|
|
|
for (i = 0; i < 3; i++) {
|
2009-08-23 14:38:07 +02:00
|
|
|
qdev_connect_gpio_out(dev, i, qdev_get_gpio_in(lcd_dev, i));
|
2009-09-18 20:51:23 +02:00
|
|
|
}
|
2009-09-18 20:51:23 +02:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
qdev_connect_gpio_out(key_dev, i, qdev_get_gpio_in(dev, i + 8));
|
|
|
|
}
|
|
|
|
for (i = 4; i < 8; i++) {
|
|
|
|
qdev_connect_gpio_out(key_dev, i, qdev_get_gpio_in(dev, i + 15));
|
|
|
|
}
|
2008-04-24 21:21:53 +02:00
|
|
|
|
2020-07-06 00:41:53 +02:00
|
|
|
wm8750_dev = i2c_slave_create_simple(i2c, TYPE_WM8750, MP_WM_ADDR);
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:31:58 +02:00
|
|
|
dev = qdev_new(TYPE_MV88W8618_AUDIO);
|
2013-01-20 02:47:33 +01:00
|
|
|
s = SYS_BUS_DEVICE(dev);
|
qom: Put name parameter before value / visitor parameter
The object_property_set_FOO() setters take property name and value in
an unusual order:
void object_property_set_FOO(Object *obj, FOO_TYPE value,
const char *name, Error **errp)
Having to pass value before name feels grating. Swap them.
Same for object_property_set(), object_property_get(), and
object_property_parse().
Convert callers with this Coccinelle script:
@@
identifier fun = {
object_property_get, object_property_parse, object_property_set_str,
object_property_set_link, object_property_set_bool,
object_property_set_int, object_property_set_uint, object_property_set,
object_property_set_qobject
};
expression obj, v, name, errp;
@@
- fun(obj, v, name, errp)
+ fun(obj, name, v, errp)
Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information". Convert that one manually.
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
by RXCPU being used both as typedef and function-like macro there.
Convert manually. The other files using RXCPU that way don't need
conversion.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-27-armbru@redhat.com>
[Straightforwad conflict with commit 2336172d9b "audio: set default
value for pcspk.iobase property" resolved]
2020-07-07 18:05:54 +02:00
|
|
|
object_property_set_link(OBJECT(dev), "wm8750", OBJECT(wm8750_dev),
|
|
|
|
NULL);
|
sysbus: Convert to sysbus_realize() etc. with Coccinelle
Convert from qdev_realize(), qdev_realize_and_unref() with null @bus
argument to sysbus_realize(), sysbus_realize_and_unref().
Coccinelle script:
@@
expression dev, errp;
@@
- qdev_realize(DEVICE(dev), NULL, errp);
+ sysbus_realize(SYS_BUS_DEVICE(dev), errp);
@@
expression sysbus_dev, dev, errp;
@@
+ sysbus_dev = SYS_BUS_DEVICE(dev);
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
- sysbus_dev = SYS_BUS_DEVICE(dev);
@@
expression sysbus_dev, dev, errp;
expression expr;
@@
sysbus_dev = SYS_BUS_DEVICE(dev);
... when != dev = expr;
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(DEVICE(dev), NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
Whitespace changes minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-46-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:32:34 +02:00
|
|
|
sysbus_realize_and_unref(s, &error_fatal);
|
2009-08-23 15:51:14 +02:00
|
|
|
sysbus_mmio_map(s, 0, MP_AUDIO_BASE);
|
2020-11-07 20:34:03 +01:00
|
|
|
sysbus_connect_irq(s, 0, qdev_get_gpio_in(pic, MP_AUDIO_IRQ));
|
2009-08-23 15:51:14 +02:00
|
|
|
|
2008-04-24 21:21:53 +02:00
|
|
|
musicpal_binfo.ram_size = MP_RAM_DEFAULT_SIZE;
|
2019-08-09 08:57:21 +02:00
|
|
|
arm_load_kernel(cpu, machine, &musicpal_binfo);
|
2008-04-24 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
2015-09-04 20:37:08 +02:00
|
|
|
static void musicpal_machine_init(MachineClass *mc)
|
2009-05-21 01:38:09 +02:00
|
|
|
{
|
2015-09-04 20:37:08 +02:00
|
|
|
mc->desc = "Marvell 88w8618 / MusicPal (ARM926EJ-S)";
|
|
|
|
mc->init = musicpal_init;
|
2017-09-07 14:54:54 +02:00
|
|
|
mc->ignore_memory_transaction_failures = true;
|
2017-09-13 18:04:57 +02:00
|
|
|
mc->default_cpu_type = ARM_CPU_TYPE_NAME("arm926");
|
2020-02-19 17:08:58 +01:00
|
|
|
mc->default_ram_size = MP_RAM_DEFAULT_SIZE;
|
|
|
|
mc->default_ram_id = "musicpal.ram";
|
2009-05-21 01:38:09 +02:00
|
|
|
}
|
|
|
|
|
2015-09-04 20:37:08 +02:00
|
|
|
DEFINE_MACHINE("musicpal", musicpal_machine_init)
|
2009-05-21 01:38:09 +02:00
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void mv88w8618_wlan_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2018-12-13 14:47:56 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2018-12-13 14:47:56 +01:00
|
|
|
dc->realize = mv88w8618_wlan_realize;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo mv88w8618_wlan_info = {
|
2011-12-08 04:34:16 +01:00
|
|
|
.name = "mv88w8618_wlan",
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(SysBusDevice),
|
|
|
|
.class_init = mv88w8618_wlan_class_init,
|
2012-01-24 20:12:29 +01:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void musicpal_register_types(void)
|
2009-05-14 23:35:08 +02:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&mv88w8618_pic_info);
|
|
|
|
type_register_static(&mv88w8618_pit_info);
|
|
|
|
type_register_static(&mv88w8618_flashcfg_info);
|
|
|
|
type_register_static(&mv88w8618_eth_info);
|
|
|
|
type_register_static(&mv88w8618_wlan_info);
|
|
|
|
type_register_static(&musicpal_lcd_info);
|
|
|
|
type_register_static(&musicpal_gpio_info);
|
|
|
|
type_register_static(&musicpal_key_info);
|
2013-03-15 15:34:20 +01:00
|
|
|
type_register_static(&musicpal_misc_info);
|
2009-05-14 23:35:08 +02:00
|
|
|
}
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
type_init(musicpal_register_types)
|