1c0907c9eSPaolo Bonzini /* 2c0907c9eSPaolo Bonzini * bonito north bridge support 3c0907c9eSPaolo Bonzini * 4c0907c9eSPaolo Bonzini * Copyright (c) 2008 yajin (yajin@vm-kernel.org) 5c0907c9eSPaolo Bonzini * Copyright (c) 2010 Huacai Chen (zltjiangshi@gmail.com) 6c0907c9eSPaolo Bonzini * 7c0907c9eSPaolo Bonzini * This code is licensed under the GNU GPL v2. 8c0907c9eSPaolo Bonzini * 9c0907c9eSPaolo Bonzini * Contributions after 2012-01-13 are licensed under the terms of the 10c0907c9eSPaolo Bonzini * GNU GPL, version 2 or (at your option) any later version. 11c0907c9eSPaolo Bonzini */ 12c0907c9eSPaolo Bonzini 13c0907c9eSPaolo Bonzini /* 14c0907c9eSPaolo Bonzini * fulong 2e mini pc has a bonito north bridge. 15c0907c9eSPaolo Bonzini */ 16c0907c9eSPaolo Bonzini 17c0907c9eSPaolo Bonzini /* what is the meaning of devfn in qemu and IDSEL in bonito northbridge? 18c0907c9eSPaolo Bonzini * 19c0907c9eSPaolo Bonzini * devfn pci_slot<<3 + funno 20c0907c9eSPaolo Bonzini * one pci bus can have 32 devices and each device can have 8 functions. 21c0907c9eSPaolo Bonzini * 22c0907c9eSPaolo Bonzini * In bonito north bridge, pci slot = IDSEL bit - 12. 23c0907c9eSPaolo Bonzini * For example, PCI_IDSEL_VIA686B = 17, 24c0907c9eSPaolo Bonzini * pci slot = 17-12=5 25c0907c9eSPaolo Bonzini * 26c0907c9eSPaolo Bonzini * so 27c0907c9eSPaolo Bonzini * VT686B_FUN0's devfn = (5<<3)+0 28c0907c9eSPaolo Bonzini * VT686B_FUN1's devfn = (5<<3)+1 29c0907c9eSPaolo Bonzini * 30c0907c9eSPaolo Bonzini * qemu also uses pci address for north bridge to access pci config register. 31c0907c9eSPaolo Bonzini * bus_no [23:16] 32c0907c9eSPaolo Bonzini * dev_no [15:11] 33c0907c9eSPaolo Bonzini * fun_no [10:8] 34c0907c9eSPaolo Bonzini * reg_no [7:2] 35c0907c9eSPaolo Bonzini * 36c0907c9eSPaolo Bonzini * so function bonito_sbridge_pciaddr for the translation from 37c0907c9eSPaolo Bonzini * north bridge address to pci address. 38c0907c9eSPaolo Bonzini */ 39c0907c9eSPaolo Bonzini 4097d5408fSPeter Maydell #include "qemu/osdep.h" 41c0907c9eSPaolo Bonzini 42c0907c9eSPaolo Bonzini #include "hw/hw.h" 43c0907c9eSPaolo Bonzini #include "hw/pci/pci.h" 44c0907c9eSPaolo Bonzini #include "hw/i386/pc.h" 45c0907c9eSPaolo Bonzini #include "hw/mips/mips.h" 46c0907c9eSPaolo Bonzini #include "hw/pci/pci_host.h" 47c0907c9eSPaolo Bonzini #include "sysemu/sysemu.h" 48c0907c9eSPaolo Bonzini #include "exec/address-spaces.h" 49c0907c9eSPaolo Bonzini 50c0907c9eSPaolo Bonzini //#define DEBUG_BONITO 51c0907c9eSPaolo Bonzini 52c0907c9eSPaolo Bonzini #ifdef DEBUG_BONITO 53c0907c9eSPaolo Bonzini #define DPRINTF(fmt, ...) fprintf(stderr, "%s: " fmt, __FUNCTION__, ##__VA_ARGS__) 54c0907c9eSPaolo Bonzini #else 55c0907c9eSPaolo Bonzini #define DPRINTF(fmt, ...) 56c0907c9eSPaolo Bonzini #endif 57c0907c9eSPaolo Bonzini 58c0907c9eSPaolo Bonzini /* from linux soure code. include/asm-mips/mips-boards/bonito64.h*/ 59c0907c9eSPaolo Bonzini #define BONITO_BOOT_BASE 0x1fc00000 60c0907c9eSPaolo Bonzini #define BONITO_BOOT_SIZE 0x00100000 61c0907c9eSPaolo Bonzini #define BONITO_BOOT_TOP (BONITO_BOOT_BASE+BONITO_BOOT_SIZE-1) 62c0907c9eSPaolo Bonzini #define BONITO_FLASH_BASE 0x1c000000 63c0907c9eSPaolo Bonzini #define BONITO_FLASH_SIZE 0x03000000 64c0907c9eSPaolo Bonzini #define BONITO_FLASH_TOP (BONITO_FLASH_BASE+BONITO_FLASH_SIZE-1) 65c0907c9eSPaolo Bonzini #define BONITO_SOCKET_BASE 0x1f800000 66c0907c9eSPaolo Bonzini #define BONITO_SOCKET_SIZE 0x00400000 67c0907c9eSPaolo Bonzini #define BONITO_SOCKET_TOP (BONITO_SOCKET_BASE+BONITO_SOCKET_SIZE-1) 68c0907c9eSPaolo Bonzini #define BONITO_REG_BASE 0x1fe00000 69c0907c9eSPaolo Bonzini #define BONITO_REG_SIZE 0x00040000 70c0907c9eSPaolo Bonzini #define BONITO_REG_TOP (BONITO_REG_BASE+BONITO_REG_SIZE-1) 71c0907c9eSPaolo Bonzini #define BONITO_DEV_BASE 0x1ff00000 72c0907c9eSPaolo Bonzini #define BONITO_DEV_SIZE 0x00100000 73c0907c9eSPaolo Bonzini #define BONITO_DEV_TOP (BONITO_DEV_BASE+BONITO_DEV_SIZE-1) 74c0907c9eSPaolo Bonzini #define BONITO_PCILO_BASE 0x10000000 75c0907c9eSPaolo Bonzini #define BONITO_PCILO_BASE_VA 0xb0000000 76c0907c9eSPaolo Bonzini #define BONITO_PCILO_SIZE 0x0c000000 77c0907c9eSPaolo Bonzini #define BONITO_PCILO_TOP (BONITO_PCILO_BASE+BONITO_PCILO_SIZE-1) 78c0907c9eSPaolo Bonzini #define BONITO_PCILO0_BASE 0x10000000 79c0907c9eSPaolo Bonzini #define BONITO_PCILO1_BASE 0x14000000 80c0907c9eSPaolo Bonzini #define BONITO_PCILO2_BASE 0x18000000 81c0907c9eSPaolo Bonzini #define BONITO_PCIHI_BASE 0x20000000 82c0907c9eSPaolo Bonzini #define BONITO_PCIHI_SIZE 0x20000000 83c0907c9eSPaolo Bonzini #define BONITO_PCIHI_TOP (BONITO_PCIHI_BASE+BONITO_PCIHI_SIZE-1) 84c0907c9eSPaolo Bonzini #define BONITO_PCIIO_BASE 0x1fd00000 85c0907c9eSPaolo Bonzini #define BONITO_PCIIO_BASE_VA 0xbfd00000 86c0907c9eSPaolo Bonzini #define BONITO_PCIIO_SIZE 0x00010000 87c0907c9eSPaolo Bonzini #define BONITO_PCIIO_TOP (BONITO_PCIIO_BASE+BONITO_PCIIO_SIZE-1) 88c0907c9eSPaolo Bonzini #define BONITO_PCICFG_BASE 0x1fe80000 89c0907c9eSPaolo Bonzini #define BONITO_PCICFG_SIZE 0x00080000 90c0907c9eSPaolo Bonzini #define BONITO_PCICFG_TOP (BONITO_PCICFG_BASE+BONITO_PCICFG_SIZE-1) 91c0907c9eSPaolo Bonzini 92c0907c9eSPaolo Bonzini 93c0907c9eSPaolo Bonzini #define BONITO_PCICONFIGBASE 0x00 94c0907c9eSPaolo Bonzini #define BONITO_REGBASE 0x100 95c0907c9eSPaolo Bonzini 96c0907c9eSPaolo Bonzini #define BONITO_PCICONFIG_BASE (BONITO_PCICONFIGBASE+BONITO_REG_BASE) 97c0907c9eSPaolo Bonzini #define BONITO_PCICONFIG_SIZE (0x100) 98c0907c9eSPaolo Bonzini 99c0907c9eSPaolo Bonzini #define BONITO_INTERNAL_REG_BASE (BONITO_REGBASE+BONITO_REG_BASE) 100c0907c9eSPaolo Bonzini #define BONITO_INTERNAL_REG_SIZE (0x70) 101c0907c9eSPaolo Bonzini 102c0907c9eSPaolo Bonzini #define BONITO_SPCICONFIG_BASE (BONITO_PCICFG_BASE) 103c0907c9eSPaolo Bonzini #define BONITO_SPCICONFIG_SIZE (BONITO_PCICFG_SIZE) 104c0907c9eSPaolo Bonzini 105c0907c9eSPaolo Bonzini 106c0907c9eSPaolo Bonzini 107c0907c9eSPaolo Bonzini /* 1. Bonito h/w Configuration */ 108c0907c9eSPaolo Bonzini /* Power on register */ 109c0907c9eSPaolo Bonzini 110c0907c9eSPaolo Bonzini #define BONITO_BONPONCFG (0x00 >> 2) /* 0x100 */ 111c0907c9eSPaolo Bonzini #define BONITO_BONGENCFG_OFFSET 0x4 112c0907c9eSPaolo Bonzini #define BONITO_BONGENCFG (BONITO_BONGENCFG_OFFSET>>2) /*0x104 */ 113c0907c9eSPaolo Bonzini 114c0907c9eSPaolo Bonzini /* 2. IO & IDE configuration */ 115c0907c9eSPaolo Bonzini #define BONITO_IODEVCFG (0x08 >> 2) /* 0x108 */ 116c0907c9eSPaolo Bonzini 117c0907c9eSPaolo Bonzini /* 3. IO & IDE configuration */ 118c0907c9eSPaolo Bonzini #define BONITO_SDCFG (0x0c >> 2) /* 0x10c */ 119c0907c9eSPaolo Bonzini 120c0907c9eSPaolo Bonzini /* 4. PCI address map control */ 121c0907c9eSPaolo Bonzini #define BONITO_PCIMAP (0x10 >> 2) /* 0x110 */ 122c0907c9eSPaolo Bonzini #define BONITO_PCIMEMBASECFG (0x14 >> 2) /* 0x114 */ 123c0907c9eSPaolo Bonzini #define BONITO_PCIMAP_CFG (0x18 >> 2) /* 0x118 */ 124c0907c9eSPaolo Bonzini 125c0907c9eSPaolo Bonzini /* 5. ICU & GPIO regs */ 126c0907c9eSPaolo Bonzini /* GPIO Regs - r/w */ 127c0907c9eSPaolo Bonzini #define BONITO_GPIODATA_OFFSET 0x1c 128c0907c9eSPaolo Bonzini #define BONITO_GPIODATA (BONITO_GPIODATA_OFFSET >> 2) /* 0x11c */ 129c0907c9eSPaolo Bonzini #define BONITO_GPIOIE (0x20 >> 2) /* 0x120 */ 130c0907c9eSPaolo Bonzini 131c0907c9eSPaolo Bonzini /* ICU Configuration Regs - r/w */ 132c0907c9eSPaolo Bonzini #define BONITO_INTEDGE (0x24 >> 2) /* 0x124 */ 133c0907c9eSPaolo Bonzini #define BONITO_INTSTEER (0x28 >> 2) /* 0x128 */ 134c0907c9eSPaolo Bonzini #define BONITO_INTPOL (0x2c >> 2) /* 0x12c */ 135c0907c9eSPaolo Bonzini 136c0907c9eSPaolo Bonzini /* ICU Enable Regs - IntEn & IntISR are r/o. */ 137c0907c9eSPaolo Bonzini #define BONITO_INTENSET (0x30 >> 2) /* 0x130 */ 138c0907c9eSPaolo Bonzini #define BONITO_INTENCLR (0x34 >> 2) /* 0x134 */ 139c0907c9eSPaolo Bonzini #define BONITO_INTEN (0x38 >> 2) /* 0x138 */ 140c0907c9eSPaolo Bonzini #define BONITO_INTISR (0x3c >> 2) /* 0x13c */ 141c0907c9eSPaolo Bonzini 142c0907c9eSPaolo Bonzini /* PCI mail boxes */ 143c0907c9eSPaolo Bonzini #define BONITO_PCIMAIL0_OFFSET 0x40 144c0907c9eSPaolo Bonzini #define BONITO_PCIMAIL1_OFFSET 0x44 145c0907c9eSPaolo Bonzini #define BONITO_PCIMAIL2_OFFSET 0x48 146c0907c9eSPaolo Bonzini #define BONITO_PCIMAIL3_OFFSET 0x4c 147c0907c9eSPaolo Bonzini #define BONITO_PCIMAIL0 (0x40 >> 2) /* 0x140 */ 148c0907c9eSPaolo Bonzini #define BONITO_PCIMAIL1 (0x44 >> 2) /* 0x144 */ 149c0907c9eSPaolo Bonzini #define BONITO_PCIMAIL2 (0x48 >> 2) /* 0x148 */ 150c0907c9eSPaolo Bonzini #define BONITO_PCIMAIL3 (0x4c >> 2) /* 0x14c */ 151c0907c9eSPaolo Bonzini 152c0907c9eSPaolo Bonzini /* 6. PCI cache */ 153c0907c9eSPaolo Bonzini #define BONITO_PCICACHECTRL (0x50 >> 2) /* 0x150 */ 154c0907c9eSPaolo Bonzini #define BONITO_PCICACHETAG (0x54 >> 2) /* 0x154 */ 155c0907c9eSPaolo Bonzini #define BONITO_PCIBADADDR (0x58 >> 2) /* 0x158 */ 156c0907c9eSPaolo Bonzini #define BONITO_PCIMSTAT (0x5c >> 2) /* 0x15c */ 157c0907c9eSPaolo Bonzini 158c0907c9eSPaolo Bonzini /* 7. other*/ 159c0907c9eSPaolo Bonzini #define BONITO_TIMECFG (0x60 >> 2) /* 0x160 */ 160c0907c9eSPaolo Bonzini #define BONITO_CPUCFG (0x64 >> 2) /* 0x164 */ 161c0907c9eSPaolo Bonzini #define BONITO_DQCFG (0x68 >> 2) /* 0x168 */ 162c0907c9eSPaolo Bonzini #define BONITO_MEMSIZE (0x6C >> 2) /* 0x16c */ 163c0907c9eSPaolo Bonzini 164c0907c9eSPaolo Bonzini #define BONITO_REGS (0x70 >> 2) 165c0907c9eSPaolo Bonzini 166c0907c9eSPaolo Bonzini /* PCI config for south bridge. type 0 */ 167c0907c9eSPaolo Bonzini #define BONITO_PCICONF_IDSEL_MASK 0xfffff800 /* [31:11] */ 168c0907c9eSPaolo Bonzini #define BONITO_PCICONF_IDSEL_OFFSET 11 169c0907c9eSPaolo Bonzini #define BONITO_PCICONF_FUN_MASK 0x700 /* [10:8] */ 170c0907c9eSPaolo Bonzini #define BONITO_PCICONF_FUN_OFFSET 8 171c0907c9eSPaolo Bonzini #define BONITO_PCICONF_REG_MASK 0xFC 172c0907c9eSPaolo Bonzini #define BONITO_PCICONF_REG_OFFSET 0 173c0907c9eSPaolo Bonzini 174c0907c9eSPaolo Bonzini 175c0907c9eSPaolo Bonzini /* idsel BIT = pci slot number +12 */ 176c0907c9eSPaolo Bonzini #define PCI_SLOT_BASE 12 177c0907c9eSPaolo Bonzini #define PCI_IDSEL_VIA686B_BIT (17) 178c0907c9eSPaolo Bonzini #define PCI_IDSEL_VIA686B (1<<PCI_IDSEL_VIA686B_BIT) 179c0907c9eSPaolo Bonzini 180c0907c9eSPaolo Bonzini #define PCI_ADDR(busno,devno,funno,regno) \ 181c0907c9eSPaolo Bonzini ((((busno)<<16)&0xff0000) + (((devno)<<11)&0xf800) + (((funno)<<8)&0x700) + (regno)) 182c0907c9eSPaolo Bonzini 183c0907c9eSPaolo Bonzini typedef struct BonitoState BonitoState; 184c0907c9eSPaolo Bonzini 185c0907c9eSPaolo Bonzini typedef struct PCIBonitoState 186c0907c9eSPaolo Bonzini { 187c0907c9eSPaolo Bonzini PCIDevice dev; 188c0907c9eSPaolo Bonzini 189c0907c9eSPaolo Bonzini BonitoState *pcihost; 190c0907c9eSPaolo Bonzini uint32_t regs[BONITO_REGS]; 191c0907c9eSPaolo Bonzini 192c0907c9eSPaolo Bonzini struct bonldma { 193c0907c9eSPaolo Bonzini uint32_t ldmactrl; 194c0907c9eSPaolo Bonzini uint32_t ldmastat; 195c0907c9eSPaolo Bonzini uint32_t ldmaaddr; 196c0907c9eSPaolo Bonzini uint32_t ldmago; 197c0907c9eSPaolo Bonzini } bonldma; 198c0907c9eSPaolo Bonzini 199c0907c9eSPaolo Bonzini /* Based at 1fe00300, bonito Copier */ 200c0907c9eSPaolo Bonzini struct boncop { 201c0907c9eSPaolo Bonzini uint32_t copctrl; 202c0907c9eSPaolo Bonzini uint32_t copstat; 203c0907c9eSPaolo Bonzini uint32_t coppaddr; 204c0907c9eSPaolo Bonzini uint32_t copgo; 205c0907c9eSPaolo Bonzini } boncop; 206c0907c9eSPaolo Bonzini 207c0907c9eSPaolo Bonzini /* Bonito registers */ 208c0907c9eSPaolo Bonzini MemoryRegion iomem; 209c0907c9eSPaolo Bonzini MemoryRegion iomem_ldma; 210c0907c9eSPaolo Bonzini MemoryRegion iomem_cop; 211e37b80faSPaolo Bonzini MemoryRegion bonito_pciio; 212e37b80faSPaolo Bonzini MemoryRegion bonito_localio; 213c0907c9eSPaolo Bonzini 214c0907c9eSPaolo Bonzini } PCIBonitoState; 215c0907c9eSPaolo Bonzini 216a2a645d9SCao jin struct BonitoState { 217a2a645d9SCao jin PCIHostState parent_obj; 218a2a645d9SCao jin qemu_irq *pic; 219a2a645d9SCao jin PCIBonitoState *pci_dev; 220a2a645d9SCao jin }; 221a2a645d9SCao jin 222a2a645d9SCao jin #define TYPE_BONITO_PCI_HOST_BRIDGE "Bonito-pcihost" 223c0907c9eSPaolo Bonzini #define BONITO_PCI_HOST_BRIDGE(obj) \ 224c0907c9eSPaolo Bonzini OBJECT_CHECK(BonitoState, (obj), TYPE_BONITO_PCI_HOST_BRIDGE) 225c0907c9eSPaolo Bonzini 226a2a645d9SCao jin #define TYPE_PCI_BONITO "Bonito" 227a2a645d9SCao jin #define PCI_BONITO(obj) \ 228a2a645d9SCao jin OBJECT_CHECK(PCIBonitoState, (obj), TYPE_PCI_BONITO) 229c0907c9eSPaolo Bonzini 230c0907c9eSPaolo Bonzini static void bonito_writel(void *opaque, hwaddr addr, 231c0907c9eSPaolo Bonzini uint64_t val, unsigned size) 232c0907c9eSPaolo Bonzini { 233c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 234c0907c9eSPaolo Bonzini uint32_t saddr; 235c0907c9eSPaolo Bonzini int reset = 0; 236c0907c9eSPaolo Bonzini 2370ca4f941SPaolo Bonzini saddr = addr >> 2; 238c0907c9eSPaolo Bonzini 239c0907c9eSPaolo Bonzini DPRINTF("bonito_writel "TARGET_FMT_plx" val %x saddr %x\n", addr, val, saddr); 240c0907c9eSPaolo Bonzini switch (saddr) { 241c0907c9eSPaolo Bonzini case BONITO_BONPONCFG: 242c0907c9eSPaolo Bonzini case BONITO_IODEVCFG: 243c0907c9eSPaolo Bonzini case BONITO_SDCFG: 244c0907c9eSPaolo Bonzini case BONITO_PCIMAP: 245c0907c9eSPaolo Bonzini case BONITO_PCIMEMBASECFG: 246c0907c9eSPaolo Bonzini case BONITO_PCIMAP_CFG: 247c0907c9eSPaolo Bonzini case BONITO_GPIODATA: 248c0907c9eSPaolo Bonzini case BONITO_GPIOIE: 249c0907c9eSPaolo Bonzini case BONITO_INTEDGE: 250c0907c9eSPaolo Bonzini case BONITO_INTSTEER: 251c0907c9eSPaolo Bonzini case BONITO_INTPOL: 252c0907c9eSPaolo Bonzini case BONITO_PCIMAIL0: 253c0907c9eSPaolo Bonzini case BONITO_PCIMAIL1: 254c0907c9eSPaolo Bonzini case BONITO_PCIMAIL2: 255c0907c9eSPaolo Bonzini case BONITO_PCIMAIL3: 256c0907c9eSPaolo Bonzini case BONITO_PCICACHECTRL: 257c0907c9eSPaolo Bonzini case BONITO_PCICACHETAG: 258c0907c9eSPaolo Bonzini case BONITO_PCIBADADDR: 259c0907c9eSPaolo Bonzini case BONITO_PCIMSTAT: 260c0907c9eSPaolo Bonzini case BONITO_TIMECFG: 261c0907c9eSPaolo Bonzini case BONITO_CPUCFG: 262c0907c9eSPaolo Bonzini case BONITO_DQCFG: 263c0907c9eSPaolo Bonzini case BONITO_MEMSIZE: 264c0907c9eSPaolo Bonzini s->regs[saddr] = val; 265c0907c9eSPaolo Bonzini break; 266c0907c9eSPaolo Bonzini case BONITO_BONGENCFG: 267c0907c9eSPaolo Bonzini if (!(s->regs[saddr] & 0x04) && (val & 0x04)) { 268c0907c9eSPaolo Bonzini reset = 1; /* bit 2 jump from 0 to 1 cause reset */ 269c0907c9eSPaolo Bonzini } 270c0907c9eSPaolo Bonzini s->regs[saddr] = val; 271c0907c9eSPaolo Bonzini if (reset) { 272*cf83f140SEric Blake qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); 273c0907c9eSPaolo Bonzini } 274c0907c9eSPaolo Bonzini break; 275c0907c9eSPaolo Bonzini case BONITO_INTENSET: 276c0907c9eSPaolo Bonzini s->regs[BONITO_INTENSET] = val; 277c0907c9eSPaolo Bonzini s->regs[BONITO_INTEN] |= val; 278c0907c9eSPaolo Bonzini break; 279c0907c9eSPaolo Bonzini case BONITO_INTENCLR: 280c0907c9eSPaolo Bonzini s->regs[BONITO_INTENCLR] = val; 281c0907c9eSPaolo Bonzini s->regs[BONITO_INTEN] &= ~val; 282c0907c9eSPaolo Bonzini break; 283c0907c9eSPaolo Bonzini case BONITO_INTEN: 284c0907c9eSPaolo Bonzini case BONITO_INTISR: 285c0907c9eSPaolo Bonzini DPRINTF("write to readonly bonito register %x\n", saddr); 286c0907c9eSPaolo Bonzini break; 287c0907c9eSPaolo Bonzini default: 288c0907c9eSPaolo Bonzini DPRINTF("write to unknown bonito register %x\n", saddr); 289c0907c9eSPaolo Bonzini break; 290c0907c9eSPaolo Bonzini } 291c0907c9eSPaolo Bonzini } 292c0907c9eSPaolo Bonzini 293c0907c9eSPaolo Bonzini static uint64_t bonito_readl(void *opaque, hwaddr addr, 294c0907c9eSPaolo Bonzini unsigned size) 295c0907c9eSPaolo Bonzini { 296c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 297c0907c9eSPaolo Bonzini uint32_t saddr; 298c0907c9eSPaolo Bonzini 2990ca4f941SPaolo Bonzini saddr = addr >> 2; 300c0907c9eSPaolo Bonzini 301c0907c9eSPaolo Bonzini DPRINTF("bonito_readl "TARGET_FMT_plx"\n", addr); 302c0907c9eSPaolo Bonzini switch (saddr) { 303c0907c9eSPaolo Bonzini case BONITO_INTISR: 304c0907c9eSPaolo Bonzini return s->regs[saddr]; 305c0907c9eSPaolo Bonzini default: 306c0907c9eSPaolo Bonzini return s->regs[saddr]; 307c0907c9eSPaolo Bonzini } 308c0907c9eSPaolo Bonzini } 309c0907c9eSPaolo Bonzini 310c0907c9eSPaolo Bonzini static const MemoryRegionOps bonito_ops = { 311c0907c9eSPaolo Bonzini .read = bonito_readl, 312c0907c9eSPaolo Bonzini .write = bonito_writel, 313c0907c9eSPaolo Bonzini .endianness = DEVICE_NATIVE_ENDIAN, 314c0907c9eSPaolo Bonzini .valid = { 315c0907c9eSPaolo Bonzini .min_access_size = 4, 316c0907c9eSPaolo Bonzini .max_access_size = 4, 317c0907c9eSPaolo Bonzini }, 318c0907c9eSPaolo Bonzini }; 319c0907c9eSPaolo Bonzini 320c0907c9eSPaolo Bonzini static void bonito_pciconf_writel(void *opaque, hwaddr addr, 321c0907c9eSPaolo Bonzini uint64_t val, unsigned size) 322c0907c9eSPaolo Bonzini { 323c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 324c0907c9eSPaolo Bonzini PCIDevice *d = PCI_DEVICE(s); 325c0907c9eSPaolo Bonzini 326c0907c9eSPaolo Bonzini DPRINTF("bonito_pciconf_writel "TARGET_FMT_plx" val %x\n", addr, val); 327c0907c9eSPaolo Bonzini d->config_write(d, addr, val, 4); 328c0907c9eSPaolo Bonzini } 329c0907c9eSPaolo Bonzini 330c0907c9eSPaolo Bonzini static uint64_t bonito_pciconf_readl(void *opaque, hwaddr addr, 331c0907c9eSPaolo Bonzini unsigned size) 332c0907c9eSPaolo Bonzini { 333c0907c9eSPaolo Bonzini 334c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 335c0907c9eSPaolo Bonzini PCIDevice *d = PCI_DEVICE(s); 336c0907c9eSPaolo Bonzini 337c0907c9eSPaolo Bonzini DPRINTF("bonito_pciconf_readl "TARGET_FMT_plx"\n", addr); 338c0907c9eSPaolo Bonzini return d->config_read(d, addr, 4); 339c0907c9eSPaolo Bonzini } 340c0907c9eSPaolo Bonzini 341c0907c9eSPaolo Bonzini /* north bridge PCI configure space. 0x1fe0 0000 - 0x1fe0 00ff */ 342c0907c9eSPaolo Bonzini 343c0907c9eSPaolo Bonzini static const MemoryRegionOps bonito_pciconf_ops = { 344c0907c9eSPaolo Bonzini .read = bonito_pciconf_readl, 345c0907c9eSPaolo Bonzini .write = bonito_pciconf_writel, 346c0907c9eSPaolo Bonzini .endianness = DEVICE_NATIVE_ENDIAN, 347c0907c9eSPaolo Bonzini .valid = { 348c0907c9eSPaolo Bonzini .min_access_size = 4, 349c0907c9eSPaolo Bonzini .max_access_size = 4, 350c0907c9eSPaolo Bonzini }, 351c0907c9eSPaolo Bonzini }; 352c0907c9eSPaolo Bonzini 353c0907c9eSPaolo Bonzini static uint64_t bonito_ldma_readl(void *opaque, hwaddr addr, 354c0907c9eSPaolo Bonzini unsigned size) 355c0907c9eSPaolo Bonzini { 356c0907c9eSPaolo Bonzini uint32_t val; 357c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 358c0907c9eSPaolo Bonzini 35958d47978SPeter Maydell if (addr >= sizeof(s->bonldma)) { 36058d47978SPeter Maydell return 0; 36158d47978SPeter Maydell } 36258d47978SPeter Maydell 363c0907c9eSPaolo Bonzini val = ((uint32_t *)(&s->bonldma))[addr/sizeof(uint32_t)]; 364c0907c9eSPaolo Bonzini 365c0907c9eSPaolo Bonzini return val; 366c0907c9eSPaolo Bonzini } 367c0907c9eSPaolo Bonzini 368c0907c9eSPaolo Bonzini static void bonito_ldma_writel(void *opaque, hwaddr addr, 369c0907c9eSPaolo Bonzini uint64_t val, unsigned size) 370c0907c9eSPaolo Bonzini { 371c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 372c0907c9eSPaolo Bonzini 37358d47978SPeter Maydell if (addr >= sizeof(s->bonldma)) { 37458d47978SPeter Maydell return; 37558d47978SPeter Maydell } 37658d47978SPeter Maydell 377c0907c9eSPaolo Bonzini ((uint32_t *)(&s->bonldma))[addr/sizeof(uint32_t)] = val & 0xffffffff; 378c0907c9eSPaolo Bonzini } 379c0907c9eSPaolo Bonzini 380c0907c9eSPaolo Bonzini static const MemoryRegionOps bonito_ldma_ops = { 381c0907c9eSPaolo Bonzini .read = bonito_ldma_readl, 382c0907c9eSPaolo Bonzini .write = bonito_ldma_writel, 383c0907c9eSPaolo Bonzini .endianness = DEVICE_NATIVE_ENDIAN, 384c0907c9eSPaolo Bonzini .valid = { 385c0907c9eSPaolo Bonzini .min_access_size = 4, 386c0907c9eSPaolo Bonzini .max_access_size = 4, 387c0907c9eSPaolo Bonzini }, 388c0907c9eSPaolo Bonzini }; 389c0907c9eSPaolo Bonzini 390c0907c9eSPaolo Bonzini static uint64_t bonito_cop_readl(void *opaque, hwaddr addr, 391c0907c9eSPaolo Bonzini unsigned size) 392c0907c9eSPaolo Bonzini { 393c0907c9eSPaolo Bonzini uint32_t val; 394c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 395c0907c9eSPaolo Bonzini 39658d47978SPeter Maydell if (addr >= sizeof(s->boncop)) { 39758d47978SPeter Maydell return 0; 39858d47978SPeter Maydell } 39958d47978SPeter Maydell 400c0907c9eSPaolo Bonzini val = ((uint32_t *)(&s->boncop))[addr/sizeof(uint32_t)]; 401c0907c9eSPaolo Bonzini 402c0907c9eSPaolo Bonzini return val; 403c0907c9eSPaolo Bonzini } 404c0907c9eSPaolo Bonzini 405c0907c9eSPaolo Bonzini static void bonito_cop_writel(void *opaque, hwaddr addr, 406c0907c9eSPaolo Bonzini uint64_t val, unsigned size) 407c0907c9eSPaolo Bonzini { 408c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 409c0907c9eSPaolo Bonzini 41058d47978SPeter Maydell if (addr >= sizeof(s->boncop)) { 41158d47978SPeter Maydell return; 41258d47978SPeter Maydell } 41358d47978SPeter Maydell 414c0907c9eSPaolo Bonzini ((uint32_t *)(&s->boncop))[addr/sizeof(uint32_t)] = val & 0xffffffff; 415c0907c9eSPaolo Bonzini } 416c0907c9eSPaolo Bonzini 417c0907c9eSPaolo Bonzini static const MemoryRegionOps bonito_cop_ops = { 418c0907c9eSPaolo Bonzini .read = bonito_cop_readl, 419c0907c9eSPaolo Bonzini .write = bonito_cop_writel, 420c0907c9eSPaolo Bonzini .endianness = DEVICE_NATIVE_ENDIAN, 421c0907c9eSPaolo Bonzini .valid = { 422c0907c9eSPaolo Bonzini .min_access_size = 4, 423c0907c9eSPaolo Bonzini .max_access_size = 4, 424c0907c9eSPaolo Bonzini }, 425c0907c9eSPaolo Bonzini }; 426c0907c9eSPaolo Bonzini 427c0907c9eSPaolo Bonzini static uint32_t bonito_sbridge_pciaddr(void *opaque, hwaddr addr) 428c0907c9eSPaolo Bonzini { 429c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 430c0907c9eSPaolo Bonzini PCIHostState *phb = PCI_HOST_BRIDGE(s->pcihost); 431c0907c9eSPaolo Bonzini uint32_t cfgaddr; 432c0907c9eSPaolo Bonzini uint32_t idsel; 433c0907c9eSPaolo Bonzini uint32_t devno; 434c0907c9eSPaolo Bonzini uint32_t funno; 435c0907c9eSPaolo Bonzini uint32_t regno; 436c0907c9eSPaolo Bonzini uint32_t pciaddr; 437c0907c9eSPaolo Bonzini 438c0907c9eSPaolo Bonzini /* support type0 pci config */ 439c0907c9eSPaolo Bonzini if ((s->regs[BONITO_PCIMAP_CFG] & 0x10000) != 0x0) { 440c0907c9eSPaolo Bonzini return 0xffffffff; 441c0907c9eSPaolo Bonzini } 442c0907c9eSPaolo Bonzini 443c0907c9eSPaolo Bonzini cfgaddr = addr & 0xffff; 444c0907c9eSPaolo Bonzini cfgaddr |= (s->regs[BONITO_PCIMAP_CFG] & 0xffff) << 16; 445c0907c9eSPaolo Bonzini 446c0907c9eSPaolo Bonzini idsel = (cfgaddr & BONITO_PCICONF_IDSEL_MASK) >> BONITO_PCICONF_IDSEL_OFFSET; 447786a4ea8SStefan Hajnoczi devno = ctz32(idsel); 448c0907c9eSPaolo Bonzini funno = (cfgaddr & BONITO_PCICONF_FUN_MASK) >> BONITO_PCICONF_FUN_OFFSET; 449c0907c9eSPaolo Bonzini regno = (cfgaddr & BONITO_PCICONF_REG_MASK) >> BONITO_PCICONF_REG_OFFSET; 450c0907c9eSPaolo Bonzini 451c0907c9eSPaolo Bonzini if (idsel == 0) { 452c0907c9eSPaolo Bonzini fprintf(stderr, "error in bonito pci config address " TARGET_FMT_plx 453c0907c9eSPaolo Bonzini ",pcimap_cfg=%x\n", addr, s->regs[BONITO_PCIMAP_CFG]); 454c0907c9eSPaolo Bonzini exit(1); 455c0907c9eSPaolo Bonzini } 456c0907c9eSPaolo Bonzini pciaddr = PCI_ADDR(pci_bus_num(phb->bus), devno, funno, regno); 457c0907c9eSPaolo Bonzini DPRINTF("cfgaddr %x pciaddr %x busno %x devno %d funno %d regno %d\n", 458c0907c9eSPaolo Bonzini cfgaddr, pciaddr, pci_bus_num(phb->bus), devno, funno, regno); 459c0907c9eSPaolo Bonzini 460c0907c9eSPaolo Bonzini return pciaddr; 461c0907c9eSPaolo Bonzini } 462c0907c9eSPaolo Bonzini 463c0907c9eSPaolo Bonzini static void bonito_spciconf_writeb(void *opaque, hwaddr addr, 464c0907c9eSPaolo Bonzini uint32_t val) 465c0907c9eSPaolo Bonzini { 466c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 467c0907c9eSPaolo Bonzini PCIDevice *d = PCI_DEVICE(s); 468c0907c9eSPaolo Bonzini PCIHostState *phb = PCI_HOST_BRIDGE(s->pcihost); 469c0907c9eSPaolo Bonzini uint32_t pciaddr; 470c0907c9eSPaolo Bonzini uint16_t status; 471c0907c9eSPaolo Bonzini 472c0907c9eSPaolo Bonzini DPRINTF("bonito_spciconf_writeb "TARGET_FMT_plx" val %x\n", addr, val); 473c0907c9eSPaolo Bonzini pciaddr = bonito_sbridge_pciaddr(s, addr); 474c0907c9eSPaolo Bonzini 475c0907c9eSPaolo Bonzini if (pciaddr == 0xffffffff) { 476c0907c9eSPaolo Bonzini return; 477c0907c9eSPaolo Bonzini } 478c0907c9eSPaolo Bonzini 479c0907c9eSPaolo Bonzini /* set the pci address in s->config_reg */ 480c0907c9eSPaolo Bonzini phb->config_reg = (pciaddr) | (1u << 31); 481c0907c9eSPaolo Bonzini pci_data_write(phb->bus, phb->config_reg, val & 0xff, 1); 482c0907c9eSPaolo Bonzini 483c0907c9eSPaolo Bonzini /* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ 484c0907c9eSPaolo Bonzini status = pci_get_word(d->config + PCI_STATUS); 485c0907c9eSPaolo Bonzini status &= ~(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT); 486c0907c9eSPaolo Bonzini pci_set_word(d->config + PCI_STATUS, status); 487c0907c9eSPaolo Bonzini } 488c0907c9eSPaolo Bonzini 489c0907c9eSPaolo Bonzini static void bonito_spciconf_writew(void *opaque, hwaddr addr, 490c0907c9eSPaolo Bonzini uint32_t val) 491c0907c9eSPaolo Bonzini { 492c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 493c0907c9eSPaolo Bonzini PCIDevice *d = PCI_DEVICE(s); 494c0907c9eSPaolo Bonzini PCIHostState *phb = PCI_HOST_BRIDGE(s->pcihost); 495c0907c9eSPaolo Bonzini uint32_t pciaddr; 496c0907c9eSPaolo Bonzini uint16_t status; 497c0907c9eSPaolo Bonzini 498c0907c9eSPaolo Bonzini DPRINTF("bonito_spciconf_writew "TARGET_FMT_plx" val %x\n", addr, val); 499c0907c9eSPaolo Bonzini assert((addr & 0x1) == 0); 500c0907c9eSPaolo Bonzini 501c0907c9eSPaolo Bonzini pciaddr = bonito_sbridge_pciaddr(s, addr); 502c0907c9eSPaolo Bonzini 503c0907c9eSPaolo Bonzini if (pciaddr == 0xffffffff) { 504c0907c9eSPaolo Bonzini return; 505c0907c9eSPaolo Bonzini } 506c0907c9eSPaolo Bonzini 507c0907c9eSPaolo Bonzini /* set the pci address in s->config_reg */ 508c0907c9eSPaolo Bonzini phb->config_reg = (pciaddr) | (1u << 31); 509c0907c9eSPaolo Bonzini pci_data_write(phb->bus, phb->config_reg, val, 2); 510c0907c9eSPaolo Bonzini 511c0907c9eSPaolo Bonzini /* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ 512c0907c9eSPaolo Bonzini status = pci_get_word(d->config + PCI_STATUS); 513c0907c9eSPaolo Bonzini status &= ~(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT); 514c0907c9eSPaolo Bonzini pci_set_word(d->config + PCI_STATUS, status); 515c0907c9eSPaolo Bonzini } 516c0907c9eSPaolo Bonzini 517c0907c9eSPaolo Bonzini static void bonito_spciconf_writel(void *opaque, hwaddr addr, 518c0907c9eSPaolo Bonzini uint32_t val) 519c0907c9eSPaolo Bonzini { 520c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 521c0907c9eSPaolo Bonzini PCIDevice *d = PCI_DEVICE(s); 522c0907c9eSPaolo Bonzini PCIHostState *phb = PCI_HOST_BRIDGE(s->pcihost); 523c0907c9eSPaolo Bonzini uint32_t pciaddr; 524c0907c9eSPaolo Bonzini uint16_t status; 525c0907c9eSPaolo Bonzini 526c0907c9eSPaolo Bonzini DPRINTF("bonito_spciconf_writel "TARGET_FMT_plx" val %x\n", addr, val); 527c0907c9eSPaolo Bonzini assert((addr & 0x3) == 0); 528c0907c9eSPaolo Bonzini 529c0907c9eSPaolo Bonzini pciaddr = bonito_sbridge_pciaddr(s, addr); 530c0907c9eSPaolo Bonzini 531c0907c9eSPaolo Bonzini if (pciaddr == 0xffffffff) { 532c0907c9eSPaolo Bonzini return; 533c0907c9eSPaolo Bonzini } 534c0907c9eSPaolo Bonzini 535c0907c9eSPaolo Bonzini /* set the pci address in s->config_reg */ 536c0907c9eSPaolo Bonzini phb->config_reg = (pciaddr) | (1u << 31); 537c0907c9eSPaolo Bonzini pci_data_write(phb->bus, phb->config_reg, val, 4); 538c0907c9eSPaolo Bonzini 539c0907c9eSPaolo Bonzini /* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ 540c0907c9eSPaolo Bonzini status = pci_get_word(d->config + PCI_STATUS); 541c0907c9eSPaolo Bonzini status &= ~(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT); 542c0907c9eSPaolo Bonzini pci_set_word(d->config + PCI_STATUS, status); 543c0907c9eSPaolo Bonzini } 544c0907c9eSPaolo Bonzini 545c0907c9eSPaolo Bonzini static uint32_t bonito_spciconf_readb(void *opaque, hwaddr addr) 546c0907c9eSPaolo Bonzini { 547c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 548c0907c9eSPaolo Bonzini PCIDevice *d = PCI_DEVICE(s); 549c0907c9eSPaolo Bonzini PCIHostState *phb = PCI_HOST_BRIDGE(s->pcihost); 550c0907c9eSPaolo Bonzini uint32_t pciaddr; 551c0907c9eSPaolo Bonzini uint16_t status; 552c0907c9eSPaolo Bonzini 553c0907c9eSPaolo Bonzini DPRINTF("bonito_spciconf_readb "TARGET_FMT_plx"\n", addr); 554c0907c9eSPaolo Bonzini pciaddr = bonito_sbridge_pciaddr(s, addr); 555c0907c9eSPaolo Bonzini 556c0907c9eSPaolo Bonzini if (pciaddr == 0xffffffff) { 557c0907c9eSPaolo Bonzini return 0xff; 558c0907c9eSPaolo Bonzini } 559c0907c9eSPaolo Bonzini 560c0907c9eSPaolo Bonzini /* set the pci address in s->config_reg */ 561c0907c9eSPaolo Bonzini phb->config_reg = (pciaddr) | (1u << 31); 562c0907c9eSPaolo Bonzini 563c0907c9eSPaolo Bonzini /* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ 564c0907c9eSPaolo Bonzini status = pci_get_word(d->config + PCI_STATUS); 565c0907c9eSPaolo Bonzini status &= ~(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT); 566c0907c9eSPaolo Bonzini pci_set_word(d->config + PCI_STATUS, status); 567c0907c9eSPaolo Bonzini 568c0907c9eSPaolo Bonzini return pci_data_read(phb->bus, phb->config_reg, 1); 569c0907c9eSPaolo Bonzini } 570c0907c9eSPaolo Bonzini 571c0907c9eSPaolo Bonzini static uint32_t bonito_spciconf_readw(void *opaque, hwaddr addr) 572c0907c9eSPaolo Bonzini { 573c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 574c0907c9eSPaolo Bonzini PCIDevice *d = PCI_DEVICE(s); 575c0907c9eSPaolo Bonzini PCIHostState *phb = PCI_HOST_BRIDGE(s->pcihost); 576c0907c9eSPaolo Bonzini uint32_t pciaddr; 577c0907c9eSPaolo Bonzini uint16_t status; 578c0907c9eSPaolo Bonzini 579c0907c9eSPaolo Bonzini DPRINTF("bonito_spciconf_readw "TARGET_FMT_plx"\n", addr); 580c0907c9eSPaolo Bonzini assert((addr & 0x1) == 0); 581c0907c9eSPaolo Bonzini 582c0907c9eSPaolo Bonzini pciaddr = bonito_sbridge_pciaddr(s, addr); 583c0907c9eSPaolo Bonzini 584c0907c9eSPaolo Bonzini if (pciaddr == 0xffffffff) { 585c0907c9eSPaolo Bonzini return 0xffff; 586c0907c9eSPaolo Bonzini } 587c0907c9eSPaolo Bonzini 588c0907c9eSPaolo Bonzini /* set the pci address in s->config_reg */ 589c0907c9eSPaolo Bonzini phb->config_reg = (pciaddr) | (1u << 31); 590c0907c9eSPaolo Bonzini 591c0907c9eSPaolo Bonzini /* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ 592c0907c9eSPaolo Bonzini status = pci_get_word(d->config + PCI_STATUS); 593c0907c9eSPaolo Bonzini status &= ~(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT); 594c0907c9eSPaolo Bonzini pci_set_word(d->config + PCI_STATUS, status); 595c0907c9eSPaolo Bonzini 596c0907c9eSPaolo Bonzini return pci_data_read(phb->bus, phb->config_reg, 2); 597c0907c9eSPaolo Bonzini } 598c0907c9eSPaolo Bonzini 599c0907c9eSPaolo Bonzini static uint32_t bonito_spciconf_readl(void *opaque, hwaddr addr) 600c0907c9eSPaolo Bonzini { 601c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 602c0907c9eSPaolo Bonzini PCIDevice *d = PCI_DEVICE(s); 603c0907c9eSPaolo Bonzini PCIHostState *phb = PCI_HOST_BRIDGE(s->pcihost); 604c0907c9eSPaolo Bonzini uint32_t pciaddr; 605c0907c9eSPaolo Bonzini uint16_t status; 606c0907c9eSPaolo Bonzini 607c0907c9eSPaolo Bonzini DPRINTF("bonito_spciconf_readl "TARGET_FMT_plx"\n", addr); 608c0907c9eSPaolo Bonzini assert((addr & 0x3) == 0); 609c0907c9eSPaolo Bonzini 610c0907c9eSPaolo Bonzini pciaddr = bonito_sbridge_pciaddr(s, addr); 611c0907c9eSPaolo Bonzini 612c0907c9eSPaolo Bonzini if (pciaddr == 0xffffffff) { 613c0907c9eSPaolo Bonzini return 0xffffffff; 614c0907c9eSPaolo Bonzini } 615c0907c9eSPaolo Bonzini 616c0907c9eSPaolo Bonzini /* set the pci address in s->config_reg */ 617c0907c9eSPaolo Bonzini phb->config_reg = (pciaddr) | (1u << 31); 618c0907c9eSPaolo Bonzini 619c0907c9eSPaolo Bonzini /* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ 620c0907c9eSPaolo Bonzini status = pci_get_word(d->config + PCI_STATUS); 621c0907c9eSPaolo Bonzini status &= ~(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT); 622c0907c9eSPaolo Bonzini pci_set_word(d->config + PCI_STATUS, status); 623c0907c9eSPaolo Bonzini 624c0907c9eSPaolo Bonzini return pci_data_read(phb->bus, phb->config_reg, 4); 625c0907c9eSPaolo Bonzini } 626c0907c9eSPaolo Bonzini 627c0907c9eSPaolo Bonzini /* south bridge PCI configure space. 0x1fe8 0000 - 0x1fef ffff */ 628c0907c9eSPaolo Bonzini static const MemoryRegionOps bonito_spciconf_ops = { 629c0907c9eSPaolo Bonzini .old_mmio = { 630c0907c9eSPaolo Bonzini .read = { 631c0907c9eSPaolo Bonzini bonito_spciconf_readb, 632c0907c9eSPaolo Bonzini bonito_spciconf_readw, 633c0907c9eSPaolo Bonzini bonito_spciconf_readl, 634c0907c9eSPaolo Bonzini }, 635c0907c9eSPaolo Bonzini .write = { 636c0907c9eSPaolo Bonzini bonito_spciconf_writeb, 637c0907c9eSPaolo Bonzini bonito_spciconf_writew, 638c0907c9eSPaolo Bonzini bonito_spciconf_writel, 639c0907c9eSPaolo Bonzini }, 640c0907c9eSPaolo Bonzini }, 641c0907c9eSPaolo Bonzini .endianness = DEVICE_NATIVE_ENDIAN, 642c0907c9eSPaolo Bonzini }; 643c0907c9eSPaolo Bonzini 644c0907c9eSPaolo Bonzini #define BONITO_IRQ_BASE 32 645c0907c9eSPaolo Bonzini 646c0907c9eSPaolo Bonzini static void pci_bonito_set_irq(void *opaque, int irq_num, int level) 647c0907c9eSPaolo Bonzini { 648c0907c9eSPaolo Bonzini BonitoState *s = opaque; 649c0907c9eSPaolo Bonzini qemu_irq *pic = s->pic; 650c0907c9eSPaolo Bonzini PCIBonitoState *bonito_state = s->pci_dev; 651c0907c9eSPaolo Bonzini int internal_irq = irq_num - BONITO_IRQ_BASE; 652c0907c9eSPaolo Bonzini 653c0907c9eSPaolo Bonzini if (bonito_state->regs[BONITO_INTEDGE] & (1 << internal_irq)) { 654c0907c9eSPaolo Bonzini qemu_irq_pulse(*pic); 655c0907c9eSPaolo Bonzini } else { /* level triggered */ 656c0907c9eSPaolo Bonzini if (bonito_state->regs[BONITO_INTPOL] & (1 << internal_irq)) { 657c0907c9eSPaolo Bonzini qemu_irq_raise(*pic); 658c0907c9eSPaolo Bonzini } else { 659c0907c9eSPaolo Bonzini qemu_irq_lower(*pic); 660c0907c9eSPaolo Bonzini } 661c0907c9eSPaolo Bonzini } 662c0907c9eSPaolo Bonzini } 663c0907c9eSPaolo Bonzini 664c0907c9eSPaolo Bonzini /* map the original irq (0~3) to bonito irq (16~47, but 16~31 are unused) */ 665c0907c9eSPaolo Bonzini static int pci_bonito_map_irq(PCIDevice * pci_dev, int irq_num) 666c0907c9eSPaolo Bonzini { 667c0907c9eSPaolo Bonzini int slot; 668c0907c9eSPaolo Bonzini 669c0907c9eSPaolo Bonzini slot = (pci_dev->devfn >> 3); 670c0907c9eSPaolo Bonzini 671c0907c9eSPaolo Bonzini switch (slot) { 672c0907c9eSPaolo Bonzini case 5: /* FULONG2E_VIA_SLOT, SouthBridge, IDE, USB, ACPI, AC97, MC97 */ 673c0907c9eSPaolo Bonzini return irq_num % 4 + BONITO_IRQ_BASE; 674c0907c9eSPaolo Bonzini case 6: /* FULONG2E_ATI_SLOT, VGA */ 675c0907c9eSPaolo Bonzini return 4 + BONITO_IRQ_BASE; 676c0907c9eSPaolo Bonzini case 7: /* FULONG2E_RTL_SLOT, RTL8139 */ 677c0907c9eSPaolo Bonzini return 5 + BONITO_IRQ_BASE; 678c0907c9eSPaolo Bonzini case 8 ... 12: /* PCI slot 1 to 4 */ 679c0907c9eSPaolo Bonzini return (slot - 8 + irq_num) + 6 + BONITO_IRQ_BASE; 680c0907c9eSPaolo Bonzini default: /* Unknown device, don't do any translation */ 681c0907c9eSPaolo Bonzini return irq_num; 682c0907c9eSPaolo Bonzini } 683c0907c9eSPaolo Bonzini } 684c0907c9eSPaolo Bonzini 685c0907c9eSPaolo Bonzini static void bonito_reset(void *opaque) 686c0907c9eSPaolo Bonzini { 687c0907c9eSPaolo Bonzini PCIBonitoState *s = opaque; 688c0907c9eSPaolo Bonzini 689c0907c9eSPaolo Bonzini /* set the default value of north bridge registers */ 690c0907c9eSPaolo Bonzini 691c0907c9eSPaolo Bonzini s->regs[BONITO_BONPONCFG] = 0xc40; 692c0907c9eSPaolo Bonzini s->regs[BONITO_BONGENCFG] = 0x1384; 693c0907c9eSPaolo Bonzini s->regs[BONITO_IODEVCFG] = 0x2bff8010; 694c0907c9eSPaolo Bonzini s->regs[BONITO_SDCFG] = 0x255e0091; 695c0907c9eSPaolo Bonzini 696c0907c9eSPaolo Bonzini s->regs[BONITO_GPIODATA] = 0x1ff; 697c0907c9eSPaolo Bonzini s->regs[BONITO_GPIOIE] = 0x1ff; 698c0907c9eSPaolo Bonzini s->regs[BONITO_DQCFG] = 0x8; 699c0907c9eSPaolo Bonzini s->regs[BONITO_MEMSIZE] = 0x10000000; 700c0907c9eSPaolo Bonzini s->regs[BONITO_PCIMAP] = 0x6140; 701c0907c9eSPaolo Bonzini } 702c0907c9eSPaolo Bonzini 703c0907c9eSPaolo Bonzini static const VMStateDescription vmstate_bonito = { 704c0907c9eSPaolo Bonzini .name = "Bonito", 705c0907c9eSPaolo Bonzini .version_id = 1, 706c0907c9eSPaolo Bonzini .minimum_version_id = 1, 707c0907c9eSPaolo Bonzini .fields = (VMStateField[]) { 708c0907c9eSPaolo Bonzini VMSTATE_PCI_DEVICE(dev, PCIBonitoState), 709c0907c9eSPaolo Bonzini VMSTATE_END_OF_LIST() 710c0907c9eSPaolo Bonzini } 711c0907c9eSPaolo Bonzini }; 712c0907c9eSPaolo Bonzini 713c0907c9eSPaolo Bonzini static int bonito_pcihost_initfn(SysBusDevice *dev) 714c0907c9eSPaolo Bonzini { 715c0907c9eSPaolo Bonzini PCIHostState *phb = PCI_HOST_BRIDGE(dev); 716c0907c9eSPaolo Bonzini 717c0907c9eSPaolo Bonzini phb->bus = pci_register_bus(DEVICE(dev), "pci", 718c0907c9eSPaolo Bonzini pci_bonito_set_irq, pci_bonito_map_irq, dev, 719c0907c9eSPaolo Bonzini get_system_memory(), get_system_io(), 720c0907c9eSPaolo Bonzini 0x28, 32, TYPE_PCI_BUS); 721c0907c9eSPaolo Bonzini 722c0907c9eSPaolo Bonzini return 0; 723c0907c9eSPaolo Bonzini } 724c0907c9eSPaolo Bonzini 7259af21dbeSMarkus Armbruster static void bonito_realize(PCIDevice *dev, Error **errp) 726c0907c9eSPaolo Bonzini { 727a2a645d9SCao jin PCIBonitoState *s = PCI_BONITO(dev); 728c0907c9eSPaolo Bonzini SysBusDevice *sysbus = SYS_BUS_DEVICE(s->pcihost); 729c0907c9eSPaolo Bonzini PCIHostState *phb = PCI_HOST_BRIDGE(s->pcihost); 730c0907c9eSPaolo Bonzini 731c0907c9eSPaolo Bonzini /* Bonito North Bridge, built on FPGA, VENDOR_ID/DEVICE_ID are "undefined" */ 732c0907c9eSPaolo Bonzini pci_config_set_prog_interface(dev->config, 0x00); 733c0907c9eSPaolo Bonzini 734c0907c9eSPaolo Bonzini /* set the north bridge register mapping */ 73540c5dce9SPaolo Bonzini memory_region_init_io(&s->iomem, OBJECT(s), &bonito_ops, s, 736c0907c9eSPaolo Bonzini "north-bridge-register", BONITO_INTERNAL_REG_SIZE); 737c0907c9eSPaolo Bonzini sysbus_init_mmio(sysbus, &s->iomem); 738c0907c9eSPaolo Bonzini sysbus_mmio_map(sysbus, 0, BONITO_INTERNAL_REG_BASE); 739c0907c9eSPaolo Bonzini 740c0907c9eSPaolo Bonzini /* set the north bridge pci configure mapping */ 74140c5dce9SPaolo Bonzini memory_region_init_io(&phb->conf_mem, OBJECT(s), &bonito_pciconf_ops, s, 742c0907c9eSPaolo Bonzini "north-bridge-pci-config", BONITO_PCICONFIG_SIZE); 743c0907c9eSPaolo Bonzini sysbus_init_mmio(sysbus, &phb->conf_mem); 744c0907c9eSPaolo Bonzini sysbus_mmio_map(sysbus, 1, BONITO_PCICONFIG_BASE); 745c0907c9eSPaolo Bonzini 746c0907c9eSPaolo Bonzini /* set the south bridge pci configure mapping */ 74740c5dce9SPaolo Bonzini memory_region_init_io(&phb->data_mem, OBJECT(s), &bonito_spciconf_ops, s, 748c0907c9eSPaolo Bonzini "south-bridge-pci-config", BONITO_SPCICONFIG_SIZE); 749c0907c9eSPaolo Bonzini sysbus_init_mmio(sysbus, &phb->data_mem); 750c0907c9eSPaolo Bonzini sysbus_mmio_map(sysbus, 2, BONITO_SPCICONFIG_BASE); 751c0907c9eSPaolo Bonzini 75240c5dce9SPaolo Bonzini memory_region_init_io(&s->iomem_ldma, OBJECT(s), &bonito_ldma_ops, s, 753c0907c9eSPaolo Bonzini "ldma", 0x100); 754c0907c9eSPaolo Bonzini sysbus_init_mmio(sysbus, &s->iomem_ldma); 755c0907c9eSPaolo Bonzini sysbus_mmio_map(sysbus, 3, 0xbfe00200); 756c0907c9eSPaolo Bonzini 75740c5dce9SPaolo Bonzini memory_region_init_io(&s->iomem_cop, OBJECT(s), &bonito_cop_ops, s, 758c0907c9eSPaolo Bonzini "cop", 0x100); 759c0907c9eSPaolo Bonzini sysbus_init_mmio(sysbus, &s->iomem_cop); 760c0907c9eSPaolo Bonzini sysbus_mmio_map(sysbus, 4, 0xbfe00300); 761c0907c9eSPaolo Bonzini 762c0907c9eSPaolo Bonzini /* Map PCI IO Space 0x1fd0 0000 - 0x1fd1 0000 */ 763e37b80faSPaolo Bonzini memory_region_init_alias(&s->bonito_pciio, OBJECT(s), "isa_mmio", 764e37b80faSPaolo Bonzini get_system_io(), 0, BONITO_PCIIO_SIZE); 765e37b80faSPaolo Bonzini sysbus_init_mmio(sysbus, &s->bonito_pciio); 766e37b80faSPaolo Bonzini sysbus_mmio_map(sysbus, 5, BONITO_PCIIO_BASE); 767c0907c9eSPaolo Bonzini 768c0907c9eSPaolo Bonzini /* add pci local io mapping */ 769e37b80faSPaolo Bonzini memory_region_init_alias(&s->bonito_localio, OBJECT(s), "isa_mmio", 770e37b80faSPaolo Bonzini get_system_io(), 0, BONITO_DEV_SIZE); 771e37b80faSPaolo Bonzini sysbus_init_mmio(sysbus, &s->bonito_localio); 772e37b80faSPaolo Bonzini sysbus_mmio_map(sysbus, 6, BONITO_DEV_BASE); 773c0907c9eSPaolo Bonzini 774c0907c9eSPaolo Bonzini /* set the default value of north bridge pci config */ 775c0907c9eSPaolo Bonzini pci_set_word(dev->config + PCI_COMMAND, 0x0000); 776c0907c9eSPaolo Bonzini pci_set_word(dev->config + PCI_STATUS, 0x0000); 777c0907c9eSPaolo Bonzini pci_set_word(dev->config + PCI_SUBSYSTEM_VENDOR_ID, 0x0000); 778c0907c9eSPaolo Bonzini pci_set_word(dev->config + PCI_SUBSYSTEM_ID, 0x0000); 779c0907c9eSPaolo Bonzini 780c0907c9eSPaolo Bonzini pci_set_byte(dev->config + PCI_INTERRUPT_LINE, 0x00); 781c0907c9eSPaolo Bonzini pci_set_byte(dev->config + PCI_INTERRUPT_PIN, 0x01); 782c0907c9eSPaolo Bonzini pci_set_byte(dev->config + PCI_MIN_GNT, 0x3c); 783c0907c9eSPaolo Bonzini pci_set_byte(dev->config + PCI_MAX_LAT, 0x00); 784c0907c9eSPaolo Bonzini 785c0907c9eSPaolo Bonzini qemu_register_reset(bonito_reset, s); 786c0907c9eSPaolo Bonzini } 787c0907c9eSPaolo Bonzini 788c0907c9eSPaolo Bonzini PCIBus *bonito_init(qemu_irq *pic) 789c0907c9eSPaolo Bonzini { 790c0907c9eSPaolo Bonzini DeviceState *dev; 791c0907c9eSPaolo Bonzini BonitoState *pcihost; 792c0907c9eSPaolo Bonzini PCIHostState *phb; 793c0907c9eSPaolo Bonzini PCIBonitoState *s; 794c0907c9eSPaolo Bonzini PCIDevice *d; 795c0907c9eSPaolo Bonzini 796c0907c9eSPaolo Bonzini dev = qdev_create(NULL, TYPE_BONITO_PCI_HOST_BRIDGE); 797c0907c9eSPaolo Bonzini phb = PCI_HOST_BRIDGE(dev); 798c0907c9eSPaolo Bonzini pcihost = BONITO_PCI_HOST_BRIDGE(dev); 799c0907c9eSPaolo Bonzini pcihost->pic = pic; 800c0907c9eSPaolo Bonzini qdev_init_nofail(dev); 801c0907c9eSPaolo Bonzini 802c0907c9eSPaolo Bonzini /* set the pcihost pointer before bonito_initfn is called */ 803a2a645d9SCao jin d = pci_create(phb->bus, PCI_DEVFN(0, 0), TYPE_PCI_BONITO); 804a2a645d9SCao jin s = PCI_BONITO(d); 805c0907c9eSPaolo Bonzini s->pcihost = pcihost; 806c0907c9eSPaolo Bonzini pcihost->pci_dev = s; 807c0907c9eSPaolo Bonzini qdev_init_nofail(DEVICE(d)); 808c0907c9eSPaolo Bonzini 809c0907c9eSPaolo Bonzini return phb->bus; 810c0907c9eSPaolo Bonzini } 811c0907c9eSPaolo Bonzini 812c0907c9eSPaolo Bonzini static void bonito_class_init(ObjectClass *klass, void *data) 813c0907c9eSPaolo Bonzini { 814c0907c9eSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 815c0907c9eSPaolo Bonzini PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); 816c0907c9eSPaolo Bonzini 8179af21dbeSMarkus Armbruster k->realize = bonito_realize; 818c0907c9eSPaolo Bonzini k->vendor_id = 0xdf53; 819c0907c9eSPaolo Bonzini k->device_id = 0x00d5; 820c0907c9eSPaolo Bonzini k->revision = 0x01; 821c0907c9eSPaolo Bonzini k->class_id = PCI_CLASS_BRIDGE_HOST; 822c0907c9eSPaolo Bonzini dc->desc = "Host bridge"; 823c0907c9eSPaolo Bonzini dc->vmsd = &vmstate_bonito; 82408c58f92SMarkus Armbruster /* 82508c58f92SMarkus Armbruster * PCI-facing part of the host bridge, not usable without the 82608c58f92SMarkus Armbruster * host-facing part, which can't be device_add'ed, yet. 82708c58f92SMarkus Armbruster */ 828e90f2a8cSEduardo Habkost dc->user_creatable = false; 829c0907c9eSPaolo Bonzini } 830c0907c9eSPaolo Bonzini 831c0907c9eSPaolo Bonzini static const TypeInfo bonito_info = { 832a2a645d9SCao jin .name = TYPE_PCI_BONITO, 833c0907c9eSPaolo Bonzini .parent = TYPE_PCI_DEVICE, 834c0907c9eSPaolo Bonzini .instance_size = sizeof(PCIBonitoState), 835c0907c9eSPaolo Bonzini .class_init = bonito_class_init, 836c0907c9eSPaolo Bonzini }; 837c0907c9eSPaolo Bonzini 838c0907c9eSPaolo Bonzini static void bonito_pcihost_class_init(ObjectClass *klass, void *data) 839c0907c9eSPaolo Bonzini { 840c0907c9eSPaolo Bonzini SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); 841c0907c9eSPaolo Bonzini 842c0907c9eSPaolo Bonzini k->init = bonito_pcihost_initfn; 843c0907c9eSPaolo Bonzini } 844c0907c9eSPaolo Bonzini 845c0907c9eSPaolo Bonzini static const TypeInfo bonito_pcihost_info = { 846c0907c9eSPaolo Bonzini .name = TYPE_BONITO_PCI_HOST_BRIDGE, 847c0907c9eSPaolo Bonzini .parent = TYPE_PCI_HOST_BRIDGE, 848c0907c9eSPaolo Bonzini .instance_size = sizeof(BonitoState), 849c0907c9eSPaolo Bonzini .class_init = bonito_pcihost_class_init, 850c0907c9eSPaolo Bonzini }; 851c0907c9eSPaolo Bonzini 852c0907c9eSPaolo Bonzini static void bonito_register_types(void) 853c0907c9eSPaolo Bonzini { 854c0907c9eSPaolo Bonzini type_register_static(&bonito_pcihost_info); 855c0907c9eSPaolo Bonzini type_register_static(&bonito_info); 856c0907c9eSPaolo Bonzini } 857c0907c9eSPaolo Bonzini 858c0907c9eSPaolo Bonzini type_init(bonito_register_types) 859