From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49206) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePf9w-0006Sp-FK for qemu-devel@nongnu.org; Thu, 14 Dec 2017 20:51:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePf9v-0001zj-K7 for qemu-devel@nongnu.org; Thu, 14 Dec 2017 20:51:32 -0500 MIME-Version: 1.0 Sender: philippe.mathieu.daude@gmail.com In-Reply-To: References: <20171213195852.30439-1-f4bug@amsat.org> <20171213195852.30439-5-f4bug@amsat.org> From: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= Date: Thu, 14 Dec 2017 22:51:29 -0300 Message-ID: Content-Type: text/plain; charset="UTF-8" Subject: Re: [Qemu-devel] [PATCH 04/14] sdhci: use deposit64() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alistair Francis Cc: "Edgar E . Iglesias" , Peter Maydell , Prasad J Pandit , Peter Crosthwaite , Andrey Smirnov , "qemu-devel@nongnu.org Developers" , Andrew Baumann , Sai Pavan Boddu , QEMU Trivial , Andrey Yurovsky >>>> good catch :) I'll respin with: >>>> >>>> case SDHC_ADMASYSADDR: >>>> s->admasysaddr = deposit64(s->admasysaddr, 0, 32, value) >>>> break; >>>> case SDHC_ADMASYSADDR + 4: >>>> s->admasysaddr = deposit64(s->admasysaddr, 32, 32, value); >>>> break; >>> >>> This still doesn't take the mask value into account though. >>> >>> Also, doesn't deposit() shift value up in this case? We want to mask >>> the low bits out. I don't have the code in front of me though, so I >>> could be wrong here. >> >> We have sdhci_mmio_ops.max_access_size = 4, so value will be at most 32bits. > > Ah! Good point. > >> Now ADMASYSADDR is a 64-bit register, accessible in 2x32-bit. >> >> /** >> * Deposit @fieldval into the 64 bit @value at the bit field specified >> * by the @start and @length parameters, and return the modified >> * @value. Bits of @value outside the bit field are not modified. >> >> uint64_t deposit64(uint64_t value, int start, int length, uint64_t fieldval); >> >> in both access we use length=32 >> >> at SDHC_ADMASYSADDR we use start=0, >> while at SDHC_ADMASYSADDR + 4 we use start=32. >> >> both deposit the 32b value (32b masked) into a 64b s->admasysaddr. >> >> This is good to clarify this now, because the Spec v3 series (and >> v4.20 if we want it) add a lot of them. > > Ok, this sounds fine to me then. > > The mask variable is still being ignored though. value should be anded > with mask. This is what deposit64() does: uint64_t deposit64(uint64_t value, int start, int length, uint64_t fieldval) { uint64_t mask; assert(start >= 0 && length > 0 && length <= 64 - start); mask = (~0ULL >> (64 - length)) << start; return (value & ~mask) | ((fieldval << start) & mask); }