Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4623405pxb; Tue, 25 Jan 2022 14:48:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJyPxO+6K3DIAEd62CTylZxRnjCQRcU4aanrEiuMXqhfxSY/faYmFzchWwStx3vOe7MCa5fo X-Received: by 2002:a63:3604:: with SMTP id d4mr17113231pga.93.1643150904481; Tue, 25 Jan 2022 14:48:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643150904; cv=none; d=google.com; s=arc-20160816; b=HJygLmk8fbCTwPGR/jK1d2jxOFoGeUMeSXUskiFehy7pxIOgj9lKKAbe74c4CjfMaD DkbwhsCEYn3bgGjMrJQXa1qLFwczObg5Vu2AAsmRjTdgMpVyua2Kyh1bKiwsn25NVrUR lDkOVavWlXGIQY7PiOnGoIM1BetD+uzyDLJHFklTyNAfZI+YXdrv3JoQeVtFp5+F21pS /3lGMZ4yYhKI/BFS+zv0+pqezzZ3Ckdf3oBNMm5C/aJS3lN/CqRyfpIlZQlm6GKXHiRy FcOZlrbrofDEM8/OCQvrlqLyBcbEB4a0UDZzTeV8n5Sx43LStpwy4jzLktW+xwaBe8rr lkmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=2swlk2R1Iyz8CGGk7h2fU+pmuJYKGgtN7VeZzZ2pbkg=; b=f8e33O14Qn7AT+jGMRbdhziU+6Wt8xnnQolUV2bdb0vjucEvkNY9gQ53QV0fwlhhBf 3MYL+83lmfbk/TrEFj8FmL3RXd+rLVRtzQQQqCASrASQIu07Gv4KuPpfr/7X3EFl9fum dAjiM7Fs4SWbayfNXZ8vkjixntJnZdk3xEOnOUQm0SfzLWcFeJtC+MOcv0cKxRywi57a uVx7EgiJJ9+ZwUP/rakhi4OWW/XkqNYGGa0mP+g/+q0CBsnuN0+kB8dQjzFbczWwZIzW 1Dwj2cbaqqeR2FhKODL7wP9E0ugSg3hWzghX2m7EYxgr1Dw/zkCOF+hg9XMBmWFfYvjS pixw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@howett-net.20210112.gappssmtp.com header.s=20210112 header.b=fxvSYu8h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u5si15317816pgm.420.2022.01.25.14.48.12; Tue, 25 Jan 2022 14:48:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@howett-net.20210112.gappssmtp.com header.s=20210112 header.b=fxvSYu8h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389807AbiAYPSg (ORCPT + 99 others); Tue, 25 Jan 2022 10:18:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359582AbiAYPQD (ORCPT ); Tue, 25 Jan 2022 10:16:03 -0500 Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E95AC06177B for ; Tue, 25 Jan 2022 07:15:58 -0800 (PST) Received: by mail-yb1-xb36.google.com with SMTP id l68so62076123ybl.0 for ; Tue, 25 Jan 2022 07:15:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=howett-net.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2swlk2R1Iyz8CGGk7h2fU+pmuJYKGgtN7VeZzZ2pbkg=; b=fxvSYu8hoO0zSxzftetHu2jcfxaoONx5V+3hyQXsdGScaJLj7KE9NaLV+M2LJtLPhJ 3tAdr8749rMhwIMfinDJEvUTvy8mEp31j5zkl3hQZghV2U2UKJcMOfhrjTbswQ6sgM9M fLeckj4cKAC05JqWaa5pun5hZ5IUUkuQcqhju0EoJxMirkmog8yf0n9RA702PlZKdwzn gQsgYGjmNp/BxLD8I72FFQh17yB8GS7sAhoQOUUIy1xB8LPwwvboraLwCu56HCDxk8A3 sI+IPxwPthE1KAPyymnxQUQ5nl3Sg+GruWM6kT9h1ti6uBcp7JUzHjFjzyma/qlDP70X 4wEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2swlk2R1Iyz8CGGk7h2fU+pmuJYKGgtN7VeZzZ2pbkg=; b=sBJNPL2QZWjyFJMhH2Jd4jgvRhuw6z+kseM+XYVPR3ZaPG+X2oqmmbisfs0O0MgHmh 9GZdjI0ZnuCZEEz9G73AUs9N8gYwk97/6G+tmvaPI9Gr5AGbhbMWaN+3RNTH7Inmac2s p1QiVPvfbL8QFZuU1cNfcT7sw3IOQsfGeR4Pzg+sjf/WKHDkZCSzdZn1NAii9/wx2nOJ wHsIwhn7hFs11FShUhbGY5syX5TL2x13cBMePs70DYbO11sNKfHar8l0WpA9TdtL2gxF EbpD6eaNjF3WmpGcYB5CwrE1OkvH6zYkaROjGkW4mYElFGkSORYJl4dirlexaErUExIq 5sGg== X-Gm-Message-State: AOAM532mkbjeFGtEMXeHItCb5g47JOkHrPGh+x/sTTdXDKFTaCb+jrIt yFdG64RMGFO4ABErpRaKbExd0au0EvdS+/AYwXBQtg== X-Received: by 2002:a25:cc47:: with SMTP id l68mr32658286ybf.105.1643123757334; Tue, 25 Jan 2022 07:15:57 -0800 (PST) MIME-Version: 1.0 References: <20220105031242.287751-1-dustin@howett.net> <20220105031242.287751-3-dustin@howett.net> In-Reply-To: From: Dustin Howett Date: Tue, 25 Jan 2022 09:15:45 -0600 Message-ID: Subject: Re: [PATCH 2/2] platform/chrome: reserve only the I/O ports required for the MEC EC To: Tzung-Bi Shih Cc: linux-kernel@vger.kernel.org, Benson Leung , Guenter Roeck Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 24, 2022 at 10:17 PM Tzung-Bi Shih wrote: > > > The original code: > - devm_request_region(dev, EC_LPC_ADDR_MEMMAP, ...) and then > - cros_ec_lpc_ops.read(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID, ...). > > After the patch: > - devm_request_region(dev, EC_HOST_CMD_REGION0, ...) and then > - cros_ec_lpc_ops.read(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID, ...). > > Does it work if it reads out of request_region range? > > > The 2 request_region are now guarded by the first "if (buf[0] != 'E' || buf[1] != 'C')". That is, only non-MEC will request the 2 regions. > > Doesn't other MECs (e.g. non-Framework Laptop) need the 2 regions? So, in both cases this should be legal. Here's why: The MEC protocol multiplexes memory-mapped reads through the same 8 I/O ports (0x800 - 0x807) as it does host commands. It works by adjusting the base address, EC_LPC_ADDR_MEMMAP (0x900), to 0x100 before it initiates a standard MEC LPC xfer. See cros_ec_lpc_mec_read_bytes line ~101 (as of 881007522c8fcc3785). Therefore, the adjusted flow in the patch is: 0. Default cros_ec_lpc_ops to the MEC version of read/xfer [unchanged in patch] 1. Request 0x800 - 0x807 (MEC region) 2. read() using the MEC read function (using only the above ports) 3. if it succeeds, great! we have a MEC EC. --- if it failed --- 4. Map the non-MEC port range 0x900 - 0x9FF for memory-mapped reads 5. read() using the NON-MEC read function (using ports 0x900 - 0x9FF) 6. if it succeeds, map the remaining host command ports 0x808 - 0x8FF In short, only non-MEC needs the 0x900 - 0x9FF mapping for "mapped memory". Therefore we can defer the port allocation until after we've failed to read mapped memory the MEC way. :) Based on my understanding of the MEC protocol, non-Framework Laptop MECs hold this invariant true as well. They should only need ports 0x800 - 0x807. Hope that helps! Want me to send a v2 with updated commit messages? d