From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17B52C433F5 for ; Fri, 31 Dec 2021 22:27:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231852AbhLaW1z (ORCPT ); Fri, 31 Dec 2021 17:27:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231847AbhLaW1z (ORCPT ); Fri, 31 Dec 2021 17:27:55 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D83DDC061574 for ; Fri, 31 Dec 2021 14:27:54 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D4D3E61807 for ; Fri, 31 Dec 2021 22:27:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18F6EC36AE9; Fri, 31 Dec 2021 22:27:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1640989672; bh=8YQvQ5JxlqHtrb82dPb5QMNGh2qi2eQKAFEp7BsFovg=; h=Date:From:To:Subject:References:In-Reply-To:From; b=YXO/UhkhXmtSRbV/CnUfh4x/mGwVB8tX4fes4U2V/Ja5SYUDiiLZpaHUfPySCrCCd lq0sxmEygDF3qshrsO8WL8dKUX1la2QFkjYTYtk59g3jLRmiL4vSaIVy5+Jj5IpdYl rWMP1kApiP+DPtYNhy2xX1Dc3hmW1WclbEGefv9IP4jLiz/ygssx93mwFB9lHI7Sbo MAFALGlp5HA/QF4vFPFLkfAUQ7QGYSAYF3hFXnfZ3vogi9Es1/LjP6sX3t+hxdZqQx zOikBHUz3fGhpHcoR/BRvGjB9Wo8NV1BGAr+wNjCUh0u3EHjRQP4weTaSLETKe+5BY sqF2i1Nowu1Dw== Received: by pali.im (Postfix) id F14A692F; Fri, 31 Dec 2021 23:27:48 +0100 (CET) Date: Fri, 31 Dec 2021 23:27:48 +0100 From: Pali =?utf-8?B?Um9ow6Fy?= To: Martin =?utf-8?B?TWFyZcWh?= , Bjorn Helgaas , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Matthew Wilcox , linux-pci@vger.kernel.org Subject: Re: [PATCH pciutils 3/4] libpci: Add support for filling bridge resources Message-ID: <20211231222748.xriixk5etfya2xbn@pali> References: <20211220155448.1233-1-pali@kernel.org> <20211220155448.1233-3-pali@kernel.org> <20211226222027.byugwn7c23ckwach@pali> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211226222027.byugwn7c23ckwach@pali> User-Agent: NeoMutt/20180716 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Sunday 26 December 2021 23:20:27 Pali Rohár wrote: > On Sunday 26 December 2021 23:13:11 Martin Mareš wrote: > > Hi! > > > > > + else if (i < 7+6+4) > > > + { > > > + /* > > > + * If kernel was compiled without CONFIG_PCI_IOV option then after > > > + * the ROM line for configured bridge device (that which had set > > > + * subordinary bus number to non-zero value) are four additional lines > > > + * which describe resources behind bridge. For PCI-to-PCI bridges they > > > + * are: IO, MEM, PREFMEM and empty. For CardBus bridges they are: IO0, > > > + * IO1, MEM0 and MEM1. For unconfigured bridges and other devices > > > + * there is no additional line after the ROM line. If kernel was > > > + * compiled with CONFIG_PCI_IOV option then after the ROM line and > > > + * before the first bridge resource line are six additional lines > > > + * which describe IOV resources. Read all remaining lines in resource > > > + * file and based on the number of remaining lines (0, 4, 6, 10) parse > > > + * resources behind bridge. > > > + */ > > > + lines[i-7].flags = flags; > > > + lines[i-7].base_addr = start; > > > + lines[i-7].size = size; > > > + } > > > + } > > > + if (i == 7+4 || i == 7+6+4) > > > > This looks crazy: is there any other way how to tell what the bridge entries mean? > > Checking the number of entries looks very brittle. > > I do not know any other way. Just for reference, here is a link to the > function resource_show() and DEVICE_COUNT_RESOURCE enum: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/pci/pci-sysfs.c?h=v5.15#n136 > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/pci.h?h=v5.15#n94 I have also checked flags and there is no indication if resource is assigned on bridge as BAR or is forwarded behind the bridge. Bjorn, Krzysztof: any idea if something better than checking number of entries in "resource" node can be used to determinate type of entry at specified line in "resource" node?