13994215dSYongbok Kim /* 23994215dSYongbok Kim * This file is subject to the terms and conditions of the GNU General Public 33994215dSYongbok Kim * License. See the file "COPYING" in the main directory of this archive 43994215dSYongbok Kim * for more details. 53994215dSYongbok Kim * 63994215dSYongbok Kim * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 73994215dSYongbok Kim * Authors: Sanjay Lal <sanjayl@kymasys.com> 83994215dSYongbok Kim * 93994215dSYongbok Kim * Copyright (C) 2015 Imagination Technologies 103994215dSYongbok Kim */ 113994215dSYongbok Kim 123994215dSYongbok Kim #include "qemu/osdep.h" 133994215dSYongbok Kim #include "qapi/error.h" 143994215dSYongbok Kim #include "hw/hw.h" 153994215dSYongbok Kim #include "hw/sysbus.h" 163994215dSYongbok Kim #include "sysemu/sysemu.h" 173994215dSYongbok Kim #include "hw/misc/mips_cmgcr.h" 18*2edd5261SLeon Alrae #include "hw/misc/mips_cpc.h" 19*2edd5261SLeon Alrae 20*2edd5261SLeon Alrae static inline bool is_cpc_connected(MIPSGCRState *s) 21*2edd5261SLeon Alrae { 22*2edd5261SLeon Alrae return s->cpc_mr != NULL; 23*2edd5261SLeon Alrae } 24*2edd5261SLeon Alrae 25*2edd5261SLeon Alrae static inline void update_cpc_base(MIPSGCRState *gcr, uint64_t val) 26*2edd5261SLeon Alrae { 27*2edd5261SLeon Alrae if (is_cpc_connected(gcr)) { 28*2edd5261SLeon Alrae gcr->cpc_base = val & GCR_CPC_BASE_MSK; 29*2edd5261SLeon Alrae memory_region_transaction_begin(); 30*2edd5261SLeon Alrae memory_region_set_address(gcr->cpc_mr, 31*2edd5261SLeon Alrae gcr->cpc_base & GCR_CPC_BASE_CPCBASE_MSK); 32*2edd5261SLeon Alrae memory_region_set_enabled(gcr->cpc_mr, 33*2edd5261SLeon Alrae gcr->cpc_base & GCR_CPC_BASE_CPCEN_MSK); 34*2edd5261SLeon Alrae memory_region_transaction_commit(); 35*2edd5261SLeon Alrae } 36*2edd5261SLeon Alrae } 373994215dSYongbok Kim 383994215dSYongbok Kim /* Read GCR registers */ 393994215dSYongbok Kim static uint64_t gcr_read(void *opaque, hwaddr addr, unsigned size) 403994215dSYongbok Kim { 413994215dSYongbok Kim MIPSGCRState *gcr = (MIPSGCRState *) opaque; 423994215dSYongbok Kim 433994215dSYongbok Kim switch (addr) { 443994215dSYongbok Kim /* Global Control Block Register */ 453994215dSYongbok Kim case GCR_CONFIG_OFS: 463994215dSYongbok Kim /* Set PCORES to 0 */ 473994215dSYongbok Kim return 0; 483994215dSYongbok Kim case GCR_BASE_OFS: 493994215dSYongbok Kim return gcr->gcr_base; 503994215dSYongbok Kim case GCR_REV_OFS: 513994215dSYongbok Kim return gcr->gcr_rev; 52*2edd5261SLeon Alrae case GCR_CPC_BASE_OFS: 53*2edd5261SLeon Alrae return gcr->cpc_base; 54*2edd5261SLeon Alrae case GCR_CPC_STATUS_OFS: 55*2edd5261SLeon Alrae return is_cpc_connected(gcr); 563994215dSYongbok Kim case GCR_L2_CONFIG_OFS: 573994215dSYongbok Kim /* L2 BYPASS */ 583994215dSYongbok Kim return GCR_L2_CONFIG_BYPASS_MSK; 593994215dSYongbok Kim /* Core-Local and Core-Other Control Blocks */ 603994215dSYongbok Kim case MIPS_CLCB_OFS + GCR_CL_CONFIG_OFS: 613994215dSYongbok Kim case MIPS_COCB_OFS + GCR_CL_CONFIG_OFS: 623994215dSYongbok Kim /* Set PVP to # of VPs - 1 */ 633994215dSYongbok Kim return gcr->num_vps - 1; 643994215dSYongbok Kim case MIPS_CLCB_OFS + GCR_CL_OTHER_OFS: 653994215dSYongbok Kim return 0; 663994215dSYongbok Kim default: 673994215dSYongbok Kim qemu_log_mask(LOG_UNIMP, "Read %d bytes at GCR offset 0x%" HWADDR_PRIx 683994215dSYongbok Kim "\n", size, addr); 693994215dSYongbok Kim return 0; 703994215dSYongbok Kim } 713994215dSYongbok Kim return 0; 723994215dSYongbok Kim } 733994215dSYongbok Kim 743994215dSYongbok Kim /* Write GCR registers */ 753994215dSYongbok Kim static void gcr_write(void *opaque, hwaddr addr, uint64_t data, unsigned size) 763994215dSYongbok Kim { 77*2edd5261SLeon Alrae MIPSGCRState *gcr = (MIPSGCRState *)opaque; 78*2edd5261SLeon Alrae 793994215dSYongbok Kim switch (addr) { 80*2edd5261SLeon Alrae case GCR_CPC_BASE_OFS: 81*2edd5261SLeon Alrae update_cpc_base(gcr, data); 82*2edd5261SLeon Alrae break; 833994215dSYongbok Kim default: 843994215dSYongbok Kim qemu_log_mask(LOG_UNIMP, "Write %d bytes at GCR offset 0x%" HWADDR_PRIx 853994215dSYongbok Kim " 0x%" PRIx64 "\n", size, addr, data); 863994215dSYongbok Kim break; 873994215dSYongbok Kim } 883994215dSYongbok Kim } 893994215dSYongbok Kim 903994215dSYongbok Kim static const MemoryRegionOps gcr_ops = { 913994215dSYongbok Kim .read = gcr_read, 923994215dSYongbok Kim .write = gcr_write, 933994215dSYongbok Kim .endianness = DEVICE_NATIVE_ENDIAN, 943994215dSYongbok Kim .impl = { 953994215dSYongbok Kim .max_access_size = 8, 963994215dSYongbok Kim }, 973994215dSYongbok Kim }; 983994215dSYongbok Kim 993994215dSYongbok Kim static void mips_gcr_init(Object *obj) 1003994215dSYongbok Kim { 1013994215dSYongbok Kim SysBusDevice *sbd = SYS_BUS_DEVICE(obj); 1023994215dSYongbok Kim MIPSGCRState *s = MIPS_GCR(obj); 1033994215dSYongbok Kim 104*2edd5261SLeon Alrae object_property_add_link(obj, "cpc", TYPE_MEMORY_REGION, 105*2edd5261SLeon Alrae (Object **)&s->cpc_mr, 106*2edd5261SLeon Alrae qdev_prop_allow_set_link_before_realize, 107*2edd5261SLeon Alrae OBJ_PROP_LINK_UNREF_ON_RELEASE, 108*2edd5261SLeon Alrae &error_abort); 109*2edd5261SLeon Alrae 1103994215dSYongbok Kim memory_region_init_io(&s->iomem, OBJECT(s), &gcr_ops, s, 1113994215dSYongbok Kim "mips-gcr", GCR_ADDRSPACE_SZ); 1123994215dSYongbok Kim sysbus_init_mmio(sbd, &s->iomem); 1133994215dSYongbok Kim } 1143994215dSYongbok Kim 115*2edd5261SLeon Alrae static void mips_gcr_reset(DeviceState *dev) 116*2edd5261SLeon Alrae { 117*2edd5261SLeon Alrae MIPSGCRState *s = MIPS_GCR(dev); 118*2edd5261SLeon Alrae 119*2edd5261SLeon Alrae update_cpc_base(s, 0); 120*2edd5261SLeon Alrae } 121*2edd5261SLeon Alrae 122*2edd5261SLeon Alrae static const VMStateDescription vmstate_mips_gcr = { 123*2edd5261SLeon Alrae .name = "mips-gcr", 124*2edd5261SLeon Alrae .version_id = 0, 125*2edd5261SLeon Alrae .minimum_version_id = 0, 126*2edd5261SLeon Alrae .fields = (VMStateField[]) { 127*2edd5261SLeon Alrae VMSTATE_UINT64(cpc_base, MIPSGCRState), 128*2edd5261SLeon Alrae VMSTATE_END_OF_LIST() 129*2edd5261SLeon Alrae }, 130*2edd5261SLeon Alrae }; 131*2edd5261SLeon Alrae 1323994215dSYongbok Kim static Property mips_gcr_properties[] = { 1333994215dSYongbok Kim DEFINE_PROP_INT32("num-vp", MIPSGCRState, num_vps, 1), 1343994215dSYongbok Kim DEFINE_PROP_INT32("gcr-rev", MIPSGCRState, gcr_rev, 0x800), 1353994215dSYongbok Kim DEFINE_PROP_UINT64("gcr-base", MIPSGCRState, gcr_base, GCR_BASE_ADDR), 1363994215dSYongbok Kim DEFINE_PROP_END_OF_LIST(), 1373994215dSYongbok Kim }; 1383994215dSYongbok Kim 1393994215dSYongbok Kim static void mips_gcr_class_init(ObjectClass *klass, void *data) 1403994215dSYongbok Kim { 1413994215dSYongbok Kim DeviceClass *dc = DEVICE_CLASS(klass); 1423994215dSYongbok Kim dc->props = mips_gcr_properties; 143*2edd5261SLeon Alrae dc->vmsd = &vmstate_mips_gcr; 144*2edd5261SLeon Alrae dc->reset = mips_gcr_reset; 1453994215dSYongbok Kim } 1463994215dSYongbok Kim 1473994215dSYongbok Kim static const TypeInfo mips_gcr_info = { 1483994215dSYongbok Kim .name = TYPE_MIPS_GCR, 1493994215dSYongbok Kim .parent = TYPE_SYS_BUS_DEVICE, 1503994215dSYongbok Kim .instance_size = sizeof(MIPSGCRState), 1513994215dSYongbok Kim .instance_init = mips_gcr_init, 1523994215dSYongbok Kim .class_init = mips_gcr_class_init, 1533994215dSYongbok Kim }; 1543994215dSYongbok Kim 1553994215dSYongbok Kim static void mips_gcr_register_types(void) 1563994215dSYongbok Kim { 1573994215dSYongbok Kim type_register_static(&mips_gcr_info); 1583994215dSYongbok Kim } 1593994215dSYongbok Kim 1603994215dSYongbok Kim type_init(mips_gcr_register_types) 161