From patchwork Wed Sep 25 14:56:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1167369 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="hyCcibtg"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46dhRc13kVz9sP3 for ; Thu, 26 Sep 2019 01:14:20 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id C2A03C22038; Wed, 25 Sep 2019 15:13:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 2069CC22047; Wed, 25 Sep 2019 15:01:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3B8E3C22125; Wed, 25 Sep 2019 15:01:37 +0000 (UTC) Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by lists.denx.de (Postfix) with ESMTPS id D8EEBC22049 for ; Wed, 25 Sep 2019 14:58:24 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id j4so14561893iog.11 for ; Wed, 25 Sep 2019 07:58:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n7PREhvndOxuF1IilGvKr8efL5wZviaFjplQzn0cFEE=; b=hyCcibtgEy4ONhW61Tz74mgM6azm7GQCH5fansrbKkJO+BIis4b13NkRVdOpU5LZ9q Mvom+tR/fC7NsFlYrbx7TB/uaesiqDxd1zpFtv0ejKrGFIYBQqByRw2onThXrpC4AnXl BPhvCn+DmSw/oOZEdM1htnpdZqcJtoAneJh9A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n7PREhvndOxuF1IilGvKr8efL5wZviaFjplQzn0cFEE=; b=tY/u5MYpK1RV2sutkc5Fc+sd1OcvThgCnpKVAVd05ayheUlYIhMq4OUbFDwIwIiqNM nKVoISFpGc5mcj46hAh9LLOhxzhYylsaJ3r4EhUBfU6lWCUEqtCpbo5NBKS4K6516mfh jwv6rJTy17fxHjZ6CbIMgx/tfMMK7j5iDkshmQverHme/qGqPcCM8dB5TT0mhMWJnaZt PR568xB4wCn2oVM1wBJgluGBScVrgou8IbcWuo20Hli00D0jkMFwxoIrfWPsHOlDkxX4 xEKbzg4tUoz14SFfkdLbKtXydaADosFF2TpIRH8wyNTmH3HLbpLfjEzaeG7tuBNF5fIo cCYA== X-Gm-Message-State: APjAAAWEkdizJFTQA0xg6xiB3CWUMFYzdqydRIWLd7SFihtM8NYdLdt4 Rx5EG+Plg3X9DZJKa7XSVSQeaEFHDkQ= X-Google-Smtp-Source: APXvYqwaxOgOZUXVQgbHxnskJlRaIDpuQbaQT+5NCNXp/pYMUuyZxJJNJl23KO1g4hT6fhgXh5Pogw== X-Received: by 2002:a6b:e302:: with SMTP id u2mr10338340ioc.135.1569423503679; Wed, 25 Sep 2019 07:58:23 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id d9sm4254964ioq.9.2019.09.25.07.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2019 07:58:23 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Wed, 25 Sep 2019 08:56:06 -0600 Message-Id: <20190925145750.200592-23-sjg@chromium.org> X-Mailer: git-send-email 2.23.0.444.g18eeb5a265-goog In-Reply-To: <20190925145750.200592-1-sjg@chromium.org> References: <20190925145750.200592-1-sjg@chromium.org> MIME-Version: 1.0 Subject: [U-Boot] [PATCH 022/126] sandbox: pci: Move pci_offset_to_barnum() to pci.h X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This function is useful in PCI emulators. More it into the header file to avoid duplicating it in other drivers. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- drivers/misc/swap_case.c | 7 ++----- include/pci.h | 4 ++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/misc/swap_case.c b/drivers/misc/swap_case.c index 18d756e9cd5..75fe6416707 100644 --- a/drivers/misc/swap_case.c +++ b/drivers/misc/swap_case.c @@ -24,9 +24,6 @@ struct swap_case_platdata { u32 bar[6]; }; -#define offset_to_barnum(offset) \ - (((offset) - PCI_BASE_ADDRESS_0) / sizeof(u32)) - enum { MEM_TEXT_SIZE = 0x100, }; @@ -144,7 +141,7 @@ static int sandbox_swap_case_read_config(struct udevice *emul, uint offset, int barnum; u32 *bar, result; - barnum = offset_to_barnum(offset); + barnum = pci_offset_to_barnum(offset); bar = &plat->bar[barnum]; result = *bar; @@ -224,7 +221,7 @@ static int sandbox_swap_case_write_config(struct udevice *emul, uint offset, int barnum; u32 *bar; - barnum = offset_to_barnum(offset); + barnum = pci_offset_to_barnum(offset); bar = &plat->bar[barnum]; debug("w bar %d=%lx\n", barnum, value); diff --git a/include/pci.h b/include/pci.h index 999a594cddf..2b82b2c5a3e 100644 --- a/include/pci.h +++ b/include/pci.h @@ -215,6 +215,10 @@ #define PCI_BASE_ADDRESS_IO_MASK (~0x03ULL) /* bit 1 is reserved if address_space = 1 */ +/* Convert a regsister address (e.g. PCI_BASE_ADDRESS_1) to a bar # (e.g. 1) */ +#define pci_offset_to_barnum(offset) \ + (((offset) - PCI_BASE_ADDRESS_0) / sizeof(u32)) + /* Header type 0 (normal devices) */ #define PCI_CARDBUS_CIS 0x28 #define PCI_SUBSYSTEM_VENDOR_ID 0x2c