ide: cmd646 we can get the pci device with container_of

Patchworks-ID: 35305
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Juan Quintela 2009-10-07 16:56:27 +02:00 committed by Anthony Liguori
parent 7e078316fd
commit 61f58e5934
1 changed files with 11 additions and 6 deletions

View File

@ -68,10 +68,19 @@ static void ide_map(PCIDevice *pci_dev, int region_num,
} }
} }
static PCIIDEState *pci_from_bm(BMDMAState *bm)
{
if (bm->unit == 0) {
return container_of(bm, PCIIDEState, bmdma[0]);
} else {
return container_of(bm, PCIIDEState, bmdma[1]);
}
}
static uint32_t bmdma_readb(void *opaque, uint32_t addr) static uint32_t bmdma_readb(void *opaque, uint32_t addr)
{ {
BMDMAState *bm = opaque; BMDMAState *bm = opaque;
PCIIDEState *pci_dev; PCIIDEState *pci_dev = pci_from_bm(bm);
uint32_t val; uint32_t val;
switch(addr & 3) { switch(addr & 3) {
@ -79,14 +88,12 @@ static uint32_t bmdma_readb(void *opaque, uint32_t addr)
val = bm->cmd; val = bm->cmd;
break; break;
case 1: case 1:
pci_dev = bm->pci_dev;
val = pci_dev->dev.config[MRDMODE]; val = pci_dev->dev.config[MRDMODE];
break; break;
case 2: case 2:
val = bm->status; val = bm->status;
break; break;
case 3: case 3:
pci_dev = bm->pci_dev;
if (bm == &pci_dev->bmdma[0]) { if (bm == &pci_dev->bmdma[0]) {
val = pci_dev->dev.config[UDIDETCR0]; val = pci_dev->dev.config[UDIDETCR0];
} else { } else {
@ -106,13 +113,12 @@ static uint32_t bmdma_readb(void *opaque, uint32_t addr)
static void bmdma_writeb(void *opaque, uint32_t addr, uint32_t val) static void bmdma_writeb(void *opaque, uint32_t addr, uint32_t val)
{ {
BMDMAState *bm = opaque; BMDMAState *bm = opaque;
PCIIDEState *pci_dev; PCIIDEState *pci_dev = pci_from_bm(bm);
#ifdef DEBUG_IDE #ifdef DEBUG_IDE
printf("bmdma: writeb 0x%02x : 0x%02x\n", addr, val); printf("bmdma: writeb 0x%02x : 0x%02x\n", addr, val);
#endif #endif
switch(addr & 3) { switch(addr & 3) {
case 1: case 1:
pci_dev = bm->pci_dev;
pci_dev->dev.config[MRDMODE] = pci_dev->dev.config[MRDMODE] =
(pci_dev->dev.config[MRDMODE] & ~0x30) | (val & 0x30); (pci_dev->dev.config[MRDMODE] & ~0x30) | (val & 0x30);
cmd646_update_irq(pci_dev); cmd646_update_irq(pci_dev);
@ -121,7 +127,6 @@ static void bmdma_writeb(void *opaque, uint32_t addr, uint32_t val)
bm->status = (val & 0x60) | (bm->status & 1) | (bm->status & ~val & 0x06); bm->status = (val & 0x60) | (bm->status & 1) | (bm->status & ~val & 0x06);
break; break;
case 3: case 3:
pci_dev = bm->pci_dev;
if (bm == &pci_dev->bmdma[0]) if (bm == &pci_dev->bmdma[0])
pci_dev->dev.config[UDIDETCR0] = val; pci_dev->dev.config[UDIDETCR0] = val;
else else