Received: from eggs.gnu.org ([2001:4830:134:3::10]:33269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSIQD-0000LA-KJ for qemu-devel@nongnu.org; Wed, 27 Jul 2016 02:34:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSIQA-0007cZ-AG for qemu-devel@nongnu.org; Wed, 27 Jul 2016 02:34:25 -0400 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]:35172) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSIQ8-0007cT-Oo for qemu-devel@nongnu.org; Wed, 27 Jul 2016 02:34:22 -0400 Received: by mail-pa0-x22c.google.com with SMTP id iw10so7283217pac.2 for ; Tue, 26 Jul 2016 23:34:19 -0700 (PDT) From: Prem Mallappa References: <20160623062221.18322-1-prem.mallappa@broadcom.com> <20160623062221.18322-2-prem.mallappa@broadcom.com> <20160726060759.GH16305@toto> Message-ID: Date: Wed, 27 Jul 2016 12:03:34 +0530 MIME-Version: 1.0 In-Reply-To: <20160726060759.GH16305@toto> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v1 1/8] hw: arm: SMMUv3 emulation model List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Edgar E. Iglesias" , Prem Mallappa Cc: Peter Maydell , qemu-devel@nongnu.org Hi Edger, > > A few first pass comments inline > Thanks for review. >> +typedef struct SMMUTransCfg { >> + union { >> + hwaddr va; /* Input to S1 */ >> + hwaddr ipa; /* Input to S2 */ >> + }; > > I think we could just use va here. > Agreed >> + union { >> + hwaddr opa; /* Output from S2 */ >> + hwaddr pa; /* Output from S1, Final PA */ >> + }; > > ... and pa here. Agreed > >> + >> + bool s2_needed; >> + struct SMMUTransCfg *s2cfg; > > Can't we instead of having these fields tell the translate function > what stage we are requesting translation for (and call translate > twice for S1+S2)? > > That's more in line with what we do in the CPU models. Ultimately, > it would be nice if we can gradually make the translation code > more and more similar with the CPU one to the point where we > can start sharing it. I'll look into this, and change accordingly. > >> +} SMMUTransCfg; >> + >> +typedef struct { >> + /* */ >> + SysBusDeviceClass parent_class; >> + >> + /* public */ >> + SMMUTransErr (*translate)(SMMUTransCfg *cfg, uint32_t *pagesize, >> + uint32_t *perm, bool is_write); >> + SMMUTransErr (*translate_lpae)(SMMUTransCfg *cfg, uint32_t *pagesize, >> + uint32_t *perm, bool is_write); > > I'm not sure about the naming here. In terms of SMMU, I've mostly heard > the distinction between 32 and 64 bit page-tables and not really the term > LPAE being used... > Will change it to translate_32, and translate_64, ARMv7 refers to it as LPAE in spec, hence the name. > >> +} SMMUBaseClass; >> + >> +#define SMMU_DEVICE_GET_CLASS(obj) \ >> + OBJECT_GET_CLASS(SMMUBaseClass, (obj), TYPE_SMMU_DEV_BASE) >> + >> +/* #define ARM_SMMU_DEBUG */ >> +#ifdef ARM_SMMU_DEBUG >> + >> +extern uint32_t dbg_bits; > > > Can you please have a look at reusing qemu_log for this? > There's a CPU_LOG_MMU classifier already, not sure if may > want to introduce a CPU_LOG_IOMMU one. I'd be OK either > way. > Sure, will make necessary changes. >> + RegInfo regs[SMMU_NREGS]; > > This should be uint32_t I think. You can have a different > RegisterInfo regs_info array if using the reg API. > My intensions were to use RegisterInfo, but it looked overkill for this particular case. >> + >> +static void smmu_write_reg(SMMUV3State *s, uint32_t addr, uint64_t val) >> +{ >> + RegInfo *reg = &s->regs[addr >> 2]; > > I think you should use the register API fully or not use it at all. > You are kind of reimplementing some of it's features it seems. > Have a look at hw/dma/xlnx-zynq-devcfg.c for an example on how it's done. > > IMO, this device doesn't benefit much from the register API though > so I'd just probably have an array of uint32_t regs[SMMU_REGS] and > deal with it. Either way is OK with me. > uint32_t was initial design, but it looked clumsy below is the code from earlier version (RFC) Please see smmu_write_mmio() in http://lists.nongnu.org/archive/html/qemu-devel/2016-01/msg01547.html > >> + >> + reg->data = val; >> + >> + if (reg->post) { >> + reg->post(reg, addr, val, s); >> + } >> +} >> + >> +#define smmu_write32_reg smmu_write_reg >> + >> +static inline uint32_t smmu_read32_reg(SMMUV3State *s, uint32_t addr) >> +{ >> + RegInfo *reg = &s->regs[addr >> 2]; >> + >> + return (uint32_t)reg->data; >> +} >> + >> +static inline uint64_t smmu_read64_reg(SMMUV3State *s, uint32_t addr) >> +{ >> + RegInfo *reg = &s->regs[addr >> 2]; >> + >> + return reg->data; >> +} > > You don't need this stuff with or without the register API. You can > internally always access the regs directly by looking at s->regs[R_SOME_REG]. Probably not needed for the read path, but write() path is definitely made much cleaner. I'll see what I can do for direct access to registers. Thanks /Prem <>