Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1698746lqb; Sun, 26 May 2024 12:59:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWc7+xheZltlb/LfvUu+hGe+l7Ugzwkwe3xaW3m4K2GaAyKfCI5ptG96gt8MWNUgbGBl4azuJd+RR16raqvC4ANkG0XjKwmjfwL4xzmoQ== X-Google-Smtp-Source: AGHT+IGQ+1NdgTHTgJ60RVUA4VVSfQxSwSkKV4O1qWj+856kvlvwBdoQPyUkqkvr+cE1xOtD7iRA X-Received: by 2002:a05:622a:1aaa:b0:43e:22d0:d1a6 with SMTP id d75a77b69052e-43fa7455fc6mr186427201cf.13.1716753574983; Sun, 26 May 2024 12:59:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716753574; cv=pass; d=google.com; s=arc-20160816; b=K3Y5l/qryvXFdbj/2Yds4SR5MBpkXdHPrvmJwcxg7qCd4jvrTKUa70V95eyo1+Qw/y Zh/WoQ7DDG90Lv/h2UKB8BHw6OKFFPGESt0Au/whERsBzjQOMg3yCxgw8k7MfZK2ooPg bUE3ce1M7Bb8KwHQU2W/hJ33wllVZd42sSkxnH3G0Mfo5a/nmBlzoaEysfGr4G9Ktc+5 Bm+Syo82LXkNz7mmLKsMtGoSqpNAk8HRBzOa8DD7CR8wc9Ly25QgKa9f01qbn1IZp1Rs 03XRC3jZeavSlNqfA98kyWzCdW9P43OHhA+qy8FNmkXU6KIP07Z5ckDZN61uRDfEAFay uFgA== ARC-Message-Signature: i=2; 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=gt1GZxDNDVzPynPm2Fc/jjTcpRuD3aRfoyoaAWA9e3w=; fh=FINt0rIw/rPodBwcJrqXwOg2bLb0oiIvvxMT3hhBbHU=; b=j6ipOAx+NF+oGi0tAysvrxJx0KjMzZLI2K3ZpCLsC8yA5AlKW32ZgQgPlX08O1mBFS G58jUTWxCIXUxa2ZD4WKthXFU+lldsWZf62ZmtNE1L6pioHha0o2PbzZ3ISvNnGSrM4w ysp3rgjEh+BejAofzaGyHfSfYZ7ZALBYUaKqVZbynVpfBZ9nxulfSCKBMHJrCKM1coaE F3/UzSxz55zGEIfM30OcftV/S9fLJGxV9FbITK+fgn6xAYJL96agta1FvEVZ6vMt+ws2 xB6qGYDIJDk3yiyxHh76ZkXu49rvPnNYppGtH08uCtzsswpmAyHDsC4WoabyWL0kffvY flKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=K5mU3L9P; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-189851-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189851-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43fb18a6395si74018261cf.232.2024.05.26.12.59.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 12:59:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189851-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=K5mU3L9P; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-189851-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189851-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B5E7D1C20C3F for ; Sun, 26 May 2024 19:59:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4214132483; Sun, 26 May 2024 19:59:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="K5mU3L9P" Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 80D38131BC9 for ; Sun, 26 May 2024 19:59:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716753560; cv=none; b=pJrB7K3FWYTNftPjgQAHOEk6R4SGH+uqoGG8Tg0yeeTWPCh5NcEY2tqE8ATT2Ci6ZOi5mf3PdkQXByKPAiLsyrYBs9QJdRhH1ILSUxr/t3Ix4xq8HdBd6BlqF8RvR56f1SUAk4p2zaTgqjcZeDnITHSo9dgqfNRWeL8ZRncsVu4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716753560; c=relaxed/simple; bh=ydmk/YchOc4SHakXg/LL+RjHVED3LNZ1vfW9P27w0zY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qwSbH2nn7PUXqvtuZ8Ng95tHbp9lyR362M5hcB+OkV3RQt83fCYSgpqPEBuLBXC6ELBlwMqrxdTLEVY8CczHKsgYsi4jVGoIevU1LloDygqcxX48dm3m/9VabiRP/Cjpl4dTp+KaB154FHzeIUHahFke8MAIx3TY2T1WkwulMgU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=K5mU3L9P; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: maarten.lankhorst@linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1716753556; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gt1GZxDNDVzPynPm2Fc/jjTcpRuD3aRfoyoaAWA9e3w=; b=K5mU3L9PDVN6Qiciorijzn+pS4JN/fokyXR+ka1VTpYo0plVLSwMop8iUnyDiFXqZxk0kx tV5Qsp4klcwmsGJi8LmuE8JQd9u1sgt5RMKgrU/KNdXVRjpNOb5h3dRxIbVC2eBhXLxBOm PG4V3/tOCefTN52+8w7InI7hFTPCyt4= X-Envelope-To: mripard@kernel.org X-Envelope-To: tzimmermann@suse.de X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: dri-devel@lists.freedesktop.org X-Envelope-To: markus.elfring@web.de X-Envelope-To: sui.jingfeng@linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Sui Jingfeng To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Markus Elfring , Sui Jingfeng Subject: [PATCH v2 1/3] drm/loongson: Add a helper for creating child devices Date: Mon, 27 May 2024 03:58:24 +0800 Message-Id: <20240526195826.109008-2-sui.jingfeng@linux.dev> In-Reply-To: <20240526195826.109008-1-sui.jingfeng@linux.dev> References: <20240526195826.109008-1-sui.jingfeng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT In some display subsystems, the functionality of a PCIe device may too complex to be managed by a single driver. A split of the functionality into child devices can helpful to achieve better modularity. Another benefit is that we could migrate the dependency on exterinal modules to a submodule level with the helper created. For example, it's not uncommon that some exterinal module will return -EPROBE_DEFER to our driver during probe time. KMS driver has to tear down everything when it receives -EPROBE_DEFER, the problem is that it's completely not necessary and rising cyclic dependency problems if not process correctly. Add the loongson_create_platform_device() function, which allows the KMS driver to create sub-devices for it. The manually created decice acts as agents for the principal part, migrate the potential issue to submodule. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/loongson/loongson_device.c | 42 ++++++++++++++++++++++ drivers/gpu/drm/loongson/lsdc_drv.h | 6 ++++ 2 files changed, 48 insertions(+) diff --git a/drivers/gpu/drm/loongson/loongson_device.c b/drivers/gpu/drm/loongson/loongson_device.c index 9986c8a2a255..b268549d643e 100644 --- a/drivers/gpu/drm/loongson/loongson_device.c +++ b/drivers/gpu/drm/loongson/loongson_device.c @@ -4,6 +4,7 @@ */ #include +#include #include "lsdc_drv.h" @@ -100,3 +101,44 @@ lsdc_device_probe(struct pci_dev *pdev, enum loongson_chip_id chip_id) { return __chip_id_desc_table[chip_id]; } + +int loongson_create_platform_device(struct device *parent, + const char *name, int id, + struct resource *pres, + void *data, + struct platform_device **ppdev) +{ + struct platform_device *pdev; + int ret; + + pdev = platform_device_alloc(name, id); + if (!pdev) + return -ENOMEM; + + pdev->dev.parent = parent; + + if (pres) { + ret = platform_device_add_resources(pdev, pres, 1); + if (ret) { + platform_device_put(pdev); + return ret; + } + } + + if (data) { + void *pdata = kmalloc(sizeof(void *), GFP_KERNEL); + + *(void **)pdata = data; + pdev->dev.platform_data = pdata; + } + + ret = platform_device_add(pdev); + if (ret) { + platform_device_put(pdev); + return ret; + } + + *ppdev = pdev; + + return 0; +} diff --git a/drivers/gpu/drm/loongson/lsdc_drv.h b/drivers/gpu/drm/loongson/lsdc_drv.h index fbf2d760ef27..a2c6b496a69f 100644 --- a/drivers/gpu/drm/loongson/lsdc_drv.h +++ b/drivers/gpu/drm/loongson/lsdc_drv.h @@ -47,6 +47,12 @@ enum loongson_chip_id { const struct lsdc_desc * lsdc_device_probe(struct pci_dev *pdev, enum loongson_chip_id chip); +int loongson_create_platform_device(struct device *parent, + const char *name, int id, + struct resource *pres, + void *data, + struct platform_device **ppdev); + struct lsdc_kms_funcs; /* DC specific */ -- 2.34.1