mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 01:33:56 -06:00
pcmcia: QOM'ify PCMCIACardState and MicroDriveState
Turn PCMCIACardState into a device. Move callbacks to new PCMCIACardClass. Derive TYPE_MICRODRIVE from TYPE_PCMCIA_CARD. Replace ide_init2_with_non_qdev_drives(). Signed-off-by: Othmar Pasteka <pasteka@kabsi.at> Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
parent
853ca11daf
commit
d1f2c96a81
7 changed files with 221 additions and 77 deletions
2
hw/pcmcia/Makefile.objs
Normal file
2
hw/pcmcia/Makefile.objs
Normal file
|
@ -0,0 +1,2 @@
|
|||
common-obj-y += pcmcia.o
|
||||
obj-$(CONFIG_PXA2XX) += pxa2xx.o
|
24
hw/pcmcia/pcmcia.c
Normal file
24
hw/pcmcia/pcmcia.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* PCMCIA emulation
|
||||
*
|
||||
* Copyright 2013 SUSE LINUX Products GmbH
|
||||
*/
|
||||
|
||||
#include "qemu-common.h"
|
||||
#include "hw/hw.h"
|
||||
#include "hw/pcmcia.h"
|
||||
|
||||
static const TypeInfo pcmcia_card_type_info = {
|
||||
.name = TYPE_PCMCIA_CARD,
|
||||
.parent = TYPE_DEVICE,
|
||||
.instance_size = sizeof(PCMCIACardState),
|
||||
.abstract = true,
|
||||
.class_size = sizeof(PCMCIACardClass),
|
||||
};
|
||||
|
||||
static void pcmcia_register_types(void)
|
||||
{
|
||||
type_register_static(&pcmcia_card_type_info);
|
||||
}
|
||||
|
||||
type_init(pcmcia_register_types)
|
229
hw/pcmcia/pxa2xx.c
Normal file
229
hw/pcmcia/pxa2xx.c
Normal file
|
@ -0,0 +1,229 @@
|
|||
/*
|
||||
* Intel XScale PXA255/270 PC Card and CompactFlash Interface.
|
||||
*
|
||||
* Copyright (c) 2006 Openedhand Ltd.
|
||||
* Written by Andrzej Zaborowski <balrog@zabor.org>
|
||||
*
|
||||
* This code is licensed under the GPLv2.
|
||||
*
|
||||
* Contributions after 2012-01-13 are licensed under the terms of the
|
||||
* GNU GPL, version 2 or (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include "hw/hw.h"
|
||||
#include "hw/pcmcia.h"
|
||||
#include "hw/arm/pxa.h"
|
||||
|
||||
|
||||
struct PXA2xxPCMCIAState {
|
||||
PCMCIASocket slot;
|
||||
PCMCIACardState *card;
|
||||
MemoryRegion common_iomem;
|
||||
MemoryRegion attr_iomem;
|
||||
MemoryRegion iomem;
|
||||
|
||||
qemu_irq irq;
|
||||
qemu_irq cd_irq;
|
||||
};
|
||||
|
||||
static uint64_t pxa2xx_pcmcia_common_read(void *opaque,
|
||||
hwaddr offset, unsigned size)
|
||||
{
|
||||
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
||||
PCMCIACardClass *pcc;
|
||||
|
||||
if (s->slot.attached) {
|
||||
pcc = PCMCIA_CARD_GET_CLASS(s->card);
|
||||
return pcc->common_read(s->card, offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void pxa2xx_pcmcia_common_write(void *opaque, hwaddr offset,
|
||||
uint64_t value, unsigned size)
|
||||
{
|
||||
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
||||
PCMCIACardClass *pcc;
|
||||
|
||||
if (s->slot.attached) {
|
||||
pcc = PCMCIA_CARD_GET_CLASS(s->card);
|
||||
pcc->common_write(s->card, offset, value);
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t pxa2xx_pcmcia_attr_read(void *opaque,
|
||||
hwaddr offset, unsigned size)
|
||||
{
|
||||
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
||||
PCMCIACardClass *pcc;
|
||||
|
||||
if (s->slot.attached) {
|
||||
pcc = PCMCIA_CARD_GET_CLASS(s->card);
|
||||
return pcc->attr_read(s->card, offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void pxa2xx_pcmcia_attr_write(void *opaque, hwaddr offset,
|
||||
uint64_t value, unsigned size)
|
||||
{
|
||||
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
||||
PCMCIACardClass *pcc;
|
||||
|
||||
if (s->slot.attached) {
|
||||
pcc = PCMCIA_CARD_GET_CLASS(s->card);
|
||||
pcc->attr_write(s->card, offset, value);
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t pxa2xx_pcmcia_io_read(void *opaque,
|
||||
hwaddr offset, unsigned size)
|
||||
{
|
||||
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
||||
PCMCIACardClass *pcc;
|
||||
|
||||
if (s->slot.attached) {
|
||||
pcc = PCMCIA_CARD_GET_CLASS(s->card);
|
||||
return pcc->io_read(s->card, offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void pxa2xx_pcmcia_io_write(void *opaque, hwaddr offset,
|
||||
uint64_t value, unsigned size)
|
||||
{
|
||||
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
||||
PCMCIACardClass *pcc;
|
||||
|
||||
if (s->slot.attached) {
|
||||
pcc = PCMCIA_CARD_GET_CLASS(s->card);
|
||||
pcc->io_write(s->card, offset, value);
|
||||
}
|
||||
}
|
||||
|
||||
static const MemoryRegionOps pxa2xx_pcmcia_common_ops = {
|
||||
.read = pxa2xx_pcmcia_common_read,
|
||||
.write = pxa2xx_pcmcia_common_write,
|
||||
.endianness = DEVICE_NATIVE_ENDIAN
|
||||
};
|
||||
|
||||
static const MemoryRegionOps pxa2xx_pcmcia_attr_ops = {
|
||||
.read = pxa2xx_pcmcia_attr_read,
|
||||
.write = pxa2xx_pcmcia_attr_write,
|
||||
.endianness = DEVICE_NATIVE_ENDIAN
|
||||
};
|
||||
|
||||
static const MemoryRegionOps pxa2xx_pcmcia_io_ops = {
|
||||
.read = pxa2xx_pcmcia_io_read,
|
||||
.write = pxa2xx_pcmcia_io_write,
|
||||
.endianness = DEVICE_NATIVE_ENDIAN
|
||||
};
|
||||
|
||||
static void pxa2xx_pcmcia_set_irq(void *opaque, int line, int level)
|
||||
{
|
||||
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
||||
if (!s->irq)
|
||||
return;
|
||||
|
||||
qemu_set_irq(s->irq, level);
|
||||
}
|
||||
|
||||
PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion *sysmem,
|
||||
hwaddr base)
|
||||
{
|
||||
PXA2xxPCMCIAState *s;
|
||||
|
||||
s = (PXA2xxPCMCIAState *)
|
||||
g_malloc0(sizeof(PXA2xxPCMCIAState));
|
||||
|
||||
/* Socket I/O Memory Space */
|
||||
memory_region_init_io(&s->iomem, NULL, &pxa2xx_pcmcia_io_ops, s,
|
||||
"pxa2xx-pcmcia-io", 0x04000000);
|
||||
memory_region_add_subregion(sysmem, base | 0x00000000,
|
||||
&s->iomem);
|
||||
|
||||
/* Then next 64 MB is reserved */
|
||||
|
||||
/* Socket Attribute Memory Space */
|
||||
memory_region_init_io(&s->attr_iomem, NULL, &pxa2xx_pcmcia_attr_ops, s,
|
||||
"pxa2xx-pcmcia-attribute", 0x04000000);
|
||||
memory_region_add_subregion(sysmem, base | 0x08000000,
|
||||
&s->attr_iomem);
|
||||
|
||||
/* Socket Common Memory Space */
|
||||
memory_region_init_io(&s->common_iomem, NULL, &pxa2xx_pcmcia_common_ops, s,
|
||||
"pxa2xx-pcmcia-common", 0x04000000);
|
||||
memory_region_add_subregion(sysmem, base | 0x0c000000,
|
||||
&s->common_iomem);
|
||||
|
||||
if (base == 0x30000000)
|
||||
s->slot.slot_string = "PXA PC Card Socket 1";
|
||||
else
|
||||
s->slot.slot_string = "PXA PC Card Socket 0";
|
||||
s->slot.irq = qemu_allocate_irqs(pxa2xx_pcmcia_set_irq, s, 1)[0];
|
||||
pcmcia_socket_register(&s->slot);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Insert a new card into a slot */
|
||||
int pxa2xx_pcmcia_attach(void *opaque, PCMCIACardState *card)
|
||||
{
|
||||
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
||||
PCMCIACardClass *pcc;
|
||||
|
||||
if (s->slot.attached) {
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
if (s->cd_irq) {
|
||||
qemu_irq_raise(s->cd_irq);
|
||||
}
|
||||
|
||||
s->card = card;
|
||||
pcc = PCMCIA_CARD_GET_CLASS(s->card);
|
||||
|
||||
s->slot.attached = true;
|
||||
s->card->slot = &s->slot;
|
||||
pcc->attach(s->card);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Eject card from the slot */
|
||||
int pxa2xx_pcmcia_detach(void *opaque)
|
||||
{
|
||||
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
||||
PCMCIACardClass *pcc;
|
||||
|
||||
if (!s->slot.attached) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
pcc = PCMCIA_CARD_GET_CLASS(s->card);
|
||||
pcc->detach(s->card);
|
||||
s->card->slot = NULL;
|
||||
s->card = NULL;
|
||||
|
||||
s->slot.attached = false;
|
||||
|
||||
if (s->irq) {
|
||||
qemu_irq_lower(s->irq);
|
||||
}
|
||||
if (s->cd_irq) {
|
||||
qemu_irq_lower(s->cd_irq);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Who to notify on card events */
|
||||
void pxa2xx_pcmcia_set_irq_cb(void *opaque, qemu_irq irq, qemu_irq cd_irq)
|
||||
{
|
||||
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
||||
s->irq = irq;
|
||||
s->cd_irq = cd_irq;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue