Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp4065168rdb; Thu, 28 Dec 2023 08:59:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4riL1Z/eYsk0hRx2/ILCzNPRWHBUW3EPQ6j7ryv1+dy3amWzsOxFJhS01JFpQWxQ5zKHq X-Received: by 2002:a05:6e02:1aaa:b0:35f:fe74:2cc0 with SMTP id l10-20020a056e021aaa00b0035ffe742cc0mr10672306ilv.18.1703782793119; Thu, 28 Dec 2023 08:59:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703782793; cv=none; d=google.com; s=arc-20160816; b=sgPc3ULZ6Lm9K8yI4kPqHBGy7OelvhxgAneKuIKNXi7bh2glcJMVaIELF6sJVpJd5y ahRJXBys9DrFGNmEGHwoCbanqZJp+rvqsLRvYges6Cakt4DEKSWZhbnXuL5EI/vp87Uq V+wT6K+twtOD0rPDBqAclhAn0gpm9Z68FEvtVDdiEWiz7EWucaVu83ifvLq0gzv+WnYp 6ZQ3UO1AhBJbzwx2hMT+r8+G27zlIH6p5y+ns5PJ9dmRxl8X1KCTlGAXHWZKOeyKYwij d46Jkey//bJnxIZw2FTnMWZIfFYJ/93kug8XrenmDh6aaBFrwA4HMs5mzZCosI8oUxlu PUkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=odb37Esu2g4iS0dlXxzHVxlfUjgrEuRtoiiuh3ZavpM=; fh=PcD3BSy+jXPLqmuWAB6/T4RIeSGGA+Y8ZhhYuWNsC8A=; b=IF0ASabkN0+amWiNxFImp2HwLtFGQiVcYoKcnUppVgEvuCAz7E8LAWM5rHUHlvXLoJ /9a6cRD4+HOB/jMFHcSj6o2HkrnPoBguvI6DTw2KgjSgOMYzXC2UB+KdqkspP6ND7D9w 48+AHxMSr/oScPCAFEMxzRqEDloKkQyCe6SCAsZAHSpRm3c5BajCD3kWOCKRWu8WQZvQ m0NLt4RTsHvULOWbkO74ZtjXenqp4L//3Csmh2Wp1mSGCu738GKzCEmdykQnr43F4oZo NzqyjuQjrERhxA7GJsbDbUmqBKctA6S1U9aonEQyx9Zbvu93T4PGdotEov9fycRd6oX5 6WnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="RzDCblR/"; spf=pass (google.com: domain of linux-kernel+bounces-12793-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 11-20020a63104b000000b005c61d17e6aasi13091856pgq.122.2023.12.28.08.59.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 08:59:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12793-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="RzDCblR/"; spf=pass (google.com: domain of linux-kernel+bounces-12793-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A5EDFB240ED for ; Thu, 28 Dec 2023 16:59:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7CA9D101C1; Thu, 28 Dec 2023 16:58:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RzDCblR/" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 497D11094A; Thu, 28 Dec 2023 16:58:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703782706; x=1735318706; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WYw+ej8p75zSV2PmRVDEXfp4ji6lrtgJzEwDsDP49x0=; b=RzDCblR/5VtUnlVh9tyGo2ztgfg7fST3j6IOU18rCVQU3gZzyKdQNqh+ O69b9TtU02E7F1ojIHVyyUFh4Xpl0NBV5dDLpP4ep7yCDWrDkGYLCMVaS Jsq2bQnQpcHg6axtu45IwzLNNFCPG+7jVR1C+6EjsGowZbmlPh9/t8lOD sODrxH/Qc4ByrYBgPoQiW7YcjjG81OqaNs72HEO9RRgv0bnBB2vJj+VTh 2GA9Pwfowef8wobV4Zkzu/gcBDN3ar2rITlvD3lJSlevcN5BS5Cvr18eF ZMCIeNXqY4eoZ+HeEOjCq2E9nv7+QwFsO7kk94iSQqvIu0JCBdLPaNEsS A==; X-IronPort-AV: E=McAfee;i="6600,9927,10937"; a="9958072" X-IronPort-AV: E=Sophos;i="6.04,312,1695711600"; d="scan'208";a="9958072" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Dec 2023 08:58:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10937"; a="951847269" X-IronPort-AV: E=Sophos;i="6.04,312,1695711600"; d="scan'208";a="951847269" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.94.250.171]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Dec 2023 08:58:19 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Igor Mammedov , Lukas Wunner , Mika Westerberg , Andy Shevchenko , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Andy Shevchenko Subject: [PATCH v2 6/7] resource: Export find_empty_resource_slot() Date: Thu, 28 Dec 2023 18:57:06 +0200 Message-Id: <20231228165707.3447-7-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231228165707.3447-1-ilpo.jarvinen@linux.intel.com> References: <20231228165707.3447-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PCI bridge window logic needs to find out in advance to the actual allocation if there is an empty slot big enough to fit the window. Export find_empty_resource_slot() for the purpose. Also move the struct resource_constraint into generic header to be able to use the new interface. Signed-off-by: Ilpo Järvinen Reviewed-by: Andy Shevchenko --- include/linux/ioport.h | 22 ++++++++++++++++++++++ kernel/resource.c | 25 ++++--------------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 26bfd9515653..b6ed244bc4b9 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -205,6 +205,24 @@ typedef resource_size_t (*resource_alignf)(void *data, resource_size_t size, resource_size_t align); +/** + * resource_constraint - constraints to be met while searching empty resource slots + * @min: The minimum address for the memory range + * @max: The maximum address for the memory range + * @align: Alignment for the start address of the empty slot + * @alignf: Additional alignment constraints callback + * @alignf_data: Data provided for @alignf callback + * + * Contains the range and alignment constraints that have to be met during + * find_empty_resource_slot(). @alignf can be NULL indicating no alignment + * beyond @align is necessary. + */ +struct resource_constraint { + resource_size_t min, max, align; + resource_alignf alignf; + void *alignf_data; +}; + /* PC/ISA/whatever - the normal PC address spaces: IO and memory */ extern struct resource ioport_resource; extern struct resource iomem_resource; @@ -278,6 +296,10 @@ static inline bool resource_union(const struct resource *r1, const struct resour return true; } +int find_empty_resource_slot(struct resource *root, struct resource *new, + resource_size_t size, + struct resource_constraint *constraint); + /* Convenience shorthand with allocation */ #define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), 0) #define request_muxed_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), IORESOURCE_MUXED) diff --git a/kernel/resource.c b/kernel/resource.c index f0e4d57d0c35..c1bbb0943d9c 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -46,24 +46,6 @@ struct resource iomem_resource = { }; EXPORT_SYMBOL(iomem_resource); -/** - * resource_constraint - constraints to be met while searching empty resource slots - * @min: The minimum address for the memory range - * @max: The maximum address for the memory range - * @align: Alignment for the start address of the empty slot - * @alignf: Additional alignment constraints callback - * @alignf_data: Data provided for @alignf callback - * - * Contains the range and alignment constraints that have to be met during - * find_empty_resource_slot(). @alignf can be NULL indicating no alignment - * beyond @align is necessary. - */ -struct resource_constraint { - resource_size_t min, max, align; - resource_alignf alignf; - void *alignf_data; -}; - static DEFINE_RWLOCK(resource_lock); static struct resource *next_resource(struct resource *p, bool skip_children) @@ -650,12 +632,13 @@ next: if (!this || this->end == root->end) * * %0 - if successful, @new members start, end, and flags are altered. * * %-EBUSY - if no empty slot was found. */ -static int find_empty_resource_slot(struct resource *root, struct resource *new, - resource_size_t size, - struct resource_constraint *constraint) +int find_empty_resource_slot(struct resource *root, struct resource *new, + resource_size_t size, + struct resource_constraint *constraint) { return __find_empty_resource_slot(root, NULL, new, size, constraint); } +EXPORT_SYMBOL_GPL(find_empty_resource_slot); /** * reallocate_resource - allocate a slot in the resource tree given range & alignment. -- 2.30.2