/* * QEMU Uninorth PCI host (for all Mac99 and newer machines) * * Copyright (c) 2006 Fabrice Bellard * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "hw/hw.h" #include "hw/ppc/mac.h" #include "hw/pci/pci.h" #include "hw/pci/pci_host.h" /* debug UniNorth */ //#define DEBUG_UNIN #ifdef DEBUG_UNIN #define UNIN_DPRINTF(fmt, ...) \ do { printf("UNIN: " fmt , ## __VA_ARGS__); } while (0) #else #define UNIN_DPRINTF(fmt, ...) #endif static const int unin_irq_line[] = { 0x1b, 0x1c, 0x1d, 0x1e }; #define TYPE_UNI_NORTH_PCI_HOST_BRIDGE "uni-north-pci-pcihost" #define TYPE_UNI_NORTH_AGP_HOST_BRIDGE "uni-north-agp-pcihost" #define TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE "uni-north-internal-pci-pcihost" #define TYPE_U3_AGP_HOST_BRIDGE "u3-agp-pcihost" #define UNI_NORTH_PCI_HOST_BRIDGE(obj) \ OBJECT_CHECK(UNINState, (obj), TYPE_UNI_NORTH_PCI_HOST_BRIDGE) #define UNI_NORTH_AGP_HOST_BRIDGE(obj) \ OBJECT_CHECK(UNINState, (obj), TYPE_UNI_NORTH_AGP_HOST_BRIDGE) #define UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE(obj) \ OBJECT_CHECK(UNINState, (obj), TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE) #define U3_AGP_HOST_BRIDGE(obj) \ OBJECT_CHECK(UNINState, (obj), TYPE_U3_AGP_HOST_BRIDGE) typedef struct UNINState { PCIHostState parent_obj; MemoryRegion pci_mmio; MemoryRegion pci_hole; } UNINState; static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num) { int retval; int devfn = pci_dev->devfn & 0x00FFFFFF; retval = (((devfn >> 11) & 0x1F) + irq_num) & 3; return retval; } static void pci_unin_set_irq(void *opaque, int irq_num, int level) { qemu_irq *pic = opaque; UNIN_DPRINTF("%s: setting INT %d = %d\n", __func__, unin_irq_line[irq_num], level); qemu_set_irq(pic[unin_irq_line[irq_num]], level); } static uint32_t unin_get_config_reg(uint32_t reg, uint32_t addr) { uint32_t retval; if (reg & (1u << 31)) { /* XXX OpenBIOS compatibility hack */ retval = reg | (addr & 3); } else if (reg & 1) { /* CFA1 style */ retval = (reg & ~7u) | (addr & 7); } else { uint32_t slot, func; /* Grab CFA0 style values */ slot = ctz32(reg & 0xfffff800); if (slot == 32) { slot = -1; /* XXX: should this be 0? */ } func = (reg >> 8) & 7; /* ... and then convert them to x86 format */ /* config pointer */ retval = (reg & (0xff - 7)) | (addr & 7); /* slot */ retval |= slot << 11; /* fn */ retval |= func << 8; } UNIN_DPRINTF("Converted config space accessor %08x/%08x -> %08x\n", reg, addr, retval); return retval; } static void un