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