From owner-freebsd-embedded@FreeBSD.ORG Fri Jan 9 17:27:22 2015 Return-Path: Delivered-To: freebsd-embedded@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 96763F25; Fri, 9 Jan 2015 17:27:22 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 392A724E; Fri, 9 Jan 2015 17:27:22 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id t09HRGOp065236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 9 Jan 2015 19:27:16 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua t09HRGOp065236 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id t09HRFLV065235; Fri, 9 Jan 2015 19:27:15 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 9 Jan 2015 19:27:15 +0200 From: Konstantin Belousov To: Micha?? Stanek Subject: Re: [PATCH] Add support for 64-bit AHCI BAR. Message-ID: <20150109172715.GU42409@kib.kiev.ua> References: <20150108203959.GR42409@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home Cc: freebsd-current@freebsd.org, freebsd-embedded@freebsd.org X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Jan 2015 17:27:22 -0000 On Fri, Jan 09, 2015 at 06:07:39PM +0100, Micha?? Stanek wrote: > 2015-01-08 21:40 GMT+01:00 Konstantin Belousov : > > > > However, if > > > AHCI uses 64-bit base addresses, then this register consists of two > > dwords > > > starting at offset 0x20 - BAR4 and BAR5. This is the case on our arm64 > > > target and possibly other platforms using 64-bit BARs for AHCI. > > Is it specified anywhere, or just a quirk of the specific implementation ? > > If it is a quirk, would it make sense to also check the vendor or device > > id before applying the logic ? > > > > > Yes, indeed it is a quirk as I just found out that our platform vendor > actually uses BAR(0) as AHCI ABAR, while BAR(4) is used for something else. > I found it implemented as a quirk in Linux AHCI code. > The BAR is still 64-bit but in a different position than AHCI spec stated. > I changed it as you suggested, the new patch is in the attachment. Please > take a look. This is probably technically correct (I am not AHCI code author), but note that we have more structured quirks mechanism than directly checking vendor and device id. Look at the ahci_ids table and the quirks member. Add a bit declaring the need of the quirk and test the bit, instead of the vendor/devid. > > > > > > The following patch adds a check for the extended BAR in > > ahci_pci_attach() > > > and sets the 'rid' in bus_alloc_resource_any accordingly. It fixes the > > > allocation error on our platform. > > > > > > Please review and test this patch on other platforms. If there are no > > > issues then it will be committed in a week. > > > > > > From b6220884d9e71d7c4fc1c2a22ade374fc023c831 Mon Sep 17 00:00:00 2001 > From: Michal Stanek > Date: Fri, 9 Jan 2015 17:20:38 +0100 > Subject: [PATCH] Add quirk for Cavium AHCI BAR location > > --- > sys/dev/ahci/ahci_pci.c | 9 +++------ > 1 file changed, 3 insertions(+), 6 deletions(-) > > diff --git a/sys/dev/ahci/ahci_pci.c b/sys/dev/ahci/ahci_pci.c > index 43723a6..dce4acb 100644 > --- a/sys/dev/ahci/ahci_pci.c > +++ b/sys/dev/ahci/ahci_pci.c > @@ -373,7 +373,6 @@ ahci_pci_attach(device_t dev) > int error, i; > uint32_t devid = pci_get_devid(dev); > uint8_t revid = pci_get_revid(dev); > - struct pci_map *map; > > i = 0; > while (ahci_ids[i].id != 0 && > @@ -392,11 +391,9 @@ ahci_pci_attach(device_t dev) > ctlr->subvendorid = pci_get_subvendor(dev); > ctlr->subdeviceid = pci_get_subdevice(dev); > > - /* AHCI Base Address is BAR(5) by default, unless BARs are 64-bit */ > - map = pci_find_bar(dev, PCIR_BAR(4)); > - if (map != NULL && > - ((map->pm_value & PCIM_BAR_MEM_TYPE) == PCIM_BAR_MEM_64)) > - ctlr->r_rid = PCIR_BAR(4); > + /* Default AHCI Base Address is BAR(5), Cavium uses BAR(0) */ > + if (ctlr->vendorid == 0x177d && ctlr->deviceid == 0xa01c) > + ctlr->r_rid = PCIR_BAR(0); > else > ctlr->r_rid = PCIR_BAR(5); > if (!(ctlr->r_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, > -- > 2.2.1 >