Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp93728rdh; Wed, 22 Nov 2023 20:05:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDM0i1j9HZ7nxFZ7WjPiS4Cmk0PnmUYcTAGuQa7/zFVflFozoZ+hpCra5nlO0jOAVFZwBL X-Received: by 2002:a17:90a:191a:b0:280:cc47:b60d with SMTP id 26-20020a17090a191a00b00280cc47b60dmr4612990pjg.14.1700712302065; Wed, 22 Nov 2023 20:05:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700712302; cv=none; d=google.com; s=arc-20160816; b=MxL0Wcy10OfXjDfdr6qW97dxMpNr8XJJbZXg72cW1eBSYTkxC0G8TPA7Azm1AK7Rm+ yKhJUju0589gFRZQdLWnvtP8cPXmUOu1BXV2NFGhWJlIjaXSKfVYzbrZFvqayADD6ZY0 ++kJAfy0e3L8vXI/RpcAEbel2f9dwUVMOZ6NKmrnTDZvr+Xp0rqPND/14StiI/bGMHDq 74YKaD/QNi5SA7rFUuWCuBMn0DtSlaWZAkoRBYdDpAdSSGG0IN6FrkloCUfeZQnPrhn8 fb0jcGeFQ8yTIFB7BOcHizpoCo/wdwddqjtDkx9qCYMmSkHqVy+deIqw/QqItIiC+HTX Zk+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=RDxfQsJf20VfOfdnJOmxuA4xs9AKQvMUxfGnGoQCOkQ=; fh=d9G4dsZtlI8UONIvGKwhW94hCYEPGxy6CqYeKEG646A=; b=phRiAna+CnSXkijv9/0i/wLBGeq91H8Ha9UVw4RmvxvnLMP8bIcpBCzlHYLjp9wQlH 9xHYSEtt4A6+Xcge50yckfhr0RAfPpBeuhy9cTTYTRtwSBMuFc+Yai/QVmiZDtTLmgOh 8JXu/CYvRsoss5eE4JqvmDY394ZfAAQiyh6AZRxLOqSdTQaBIcyJAY8DRyAkBk8BY3BL w4m/ckO2W0nx0afM0zLqMg5kEnJjCiwcuYL6KXBJq/NYEN4beMCVibR+cuLSVaOezL4z PCGJTz747lfobt2dL5aGrdk95AHGhGfnASACdi3AtQUNosajh8w714Ss8YcpmeWCbleP ddXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NRB4pSTu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id j13-20020a17090ae60d00b002791d79bbf9si956921pjy.187.2023.11.22.20.05.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 20:05:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NRB4pSTu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id E5A058261022; Wed, 22 Nov 2023 20:04:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344662AbjKWEE0 (ORCPT + 99 others); Wed, 22 Nov 2023 23:04:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232939AbjKWEDw (ORCPT ); Wed, 22 Nov 2023 23:03:52 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37E80D43; Wed, 22 Nov 2023 20:03:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700712239; x=1732248239; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=TtKsydOx3gWnba4fJ4T6LAEwpRvLx4xg4R8u/y5POrM=; b=NRB4pSTu3uO0qF4e2EDpveGX6gs9PTXYC23HHEhZq25jyIgMPxrvrnYU icemf77cvFvbOMeotL0AoGJ+NU9CwM1Js8EPLNuIhANuxn8LjCm3BUNIQ dcgfANhsdTOiPhz+0kvuatEiKNcp5SrCOWCB3WYuea8aq4ZJSvJGrp3V6 PbYJh3EAwtnZ0UXaiXfOspbIbZzQJ/PyOFTwDPpaZvYDWxUyB001gzGUP tpOmRsS4vKsF1GH7/fwpp4ASs3Iqi55LMyw8jrlpdG4wAJKLxqud+RWCT HPkGPGRAAcvrFkuM5nRyakxXjFFTk7ifwQwsg42YGvf1yNJOCW5lEJ5RG w==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="389347946" X-IronPort-AV: E=Sophos;i="6.04,220,1695711600"; d="scan'208";a="389347946" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2023 20:03:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="801925650" X-IronPort-AV: E=Sophos;i="6.04,220,1695711600"; d="scan'208";a="801925650" Received: from linux.intel.com ([10.54.29.200]) by orsmga001.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2023 20:03:56 -0800 Received: from debox1-desk4.lan (snpatel1-mobl.amr.corp.intel.com [10.209.89.91]) by linux.intel.com (Postfix) with ESMTP id 19DB1580D7B; Wed, 22 Nov 2023 20:03:56 -0800 (PST) From: "David E. Box" To: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH V5 06/20] platform/x86/intel/vsec: Add intel_vsec_register Date: Wed, 22 Nov 2023 20:03:41 -0800 Message-Id: <20231123040355.82139-7-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231123040355.82139-1-david.e.box@linux.intel.com> References: <20231123040355.82139-1-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 22 Nov 2023 20:04:56 -0800 (PST) From: Gayatri Kammela Add and export intel_vsec_register() to allow the registration of Intel extended capabilities from other drivers. Add check to look for memory conflicts before registering a new capability. Add a parent field to intel_vsec_platform_info to allow specifying the parent device for device managed cleanup. Signed-off-by: Gayatri Kammela Signed-off-by: David E. Box --- V5 - Add parent variable in intel_vsec_add_dev() and set parent to the pci device if info->parent is not set. V4 - Move res cleanup to previous patch V3 - Replace kfree on request_mem_region fail with use of cleanup.h helper. V2 - New patch splitting previous PATCH 1 drivers/platform/x86/intel/vsec.c | 24 +++++++++++++++++++++++- drivers/platform/x86/intel/vsec.h | 4 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel/vsec.c index 7a717183c58b..03eabb7d3d3d 100644 --- a/drivers/platform/x86/intel/vsec.c +++ b/drivers/platform/x86/intel/vsec.c @@ -159,9 +159,15 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he struct intel_vsec_device __free(kfree) *intel_vsec_dev = NULL; struct resource __free(kfree) *res = NULL; struct resource *tmp; + struct device *parent; unsigned long quirks = info->quirks; int i; + if (info->parent) + parent = info->parent; + else + parent = &pdev->dev; + if (!intel_vsec_supported(header->id, info->caps)) return -EINVAL; @@ -196,6 +202,12 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he header->offset + i * (header->entry_size * sizeof(u32)); tmp->end = tmp->start + (header->entry_size * sizeof(u32)) - 1; tmp->flags = IORESOURCE_MEM; + + /* Check resource is not in use */ + if (!request_mem_region(tmp->start, resource_size(tmp), "")) + return -EBUSY; + + release_mem_region(tmp->start, resource_size(tmp)); } intel_vsec_dev->pcidev = pdev; @@ -212,7 +224,7 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he * Pass the ownership of intel_vsec_dev and resource within it to * intel_vsec_add_aux() */ - return intel_vsec_add_aux(pdev, &pdev->dev, no_free_ptr(intel_vsec_dev), + return intel_vsec_add_aux(pdev, parent, no_free_ptr(intel_vsec_dev), intel_vsec_name(header->id)); } @@ -330,6 +342,16 @@ static bool intel_vsec_walk_vsec(struct pci_dev *pdev, return have_devices; } +void intel_vsec_register(struct pci_dev *pdev, + struct intel_vsec_platform_info *info) +{ + if (!pdev || !info) + return; + + intel_vsec_walk_header(pdev, info); +} +EXPORT_SYMBOL_NS_GPL(intel_vsec_register, INTEL_VSEC); + static int intel_vsec_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { struct intel_vsec_platform_info *info; diff --git a/drivers/platform/x86/intel/vsec.h b/drivers/platform/x86/intel/vsec.h index 8b9fad170503..bb8b6452df70 100644 --- a/drivers/platform/x86/intel/vsec.h +++ b/drivers/platform/x86/intel/vsec.h @@ -69,6 +69,7 @@ enum intel_vsec_quirks { /* Platform specific data */ struct intel_vsec_platform_info { + struct device *parent; struct intel_vsec_header **headers; unsigned long caps; unsigned long quirks; @@ -99,4 +100,7 @@ static inline struct intel_vsec_device *auxdev_to_ivdev(struct auxiliary_device { return container_of(auxdev, struct intel_vsec_device, auxdev); } + +void intel_vsec_register(struct pci_dev *pdev, + struct intel_vsec_platform_info *info); #endif -- 2.34.1