Re: [RFC PATCH 1/4] gpu: dxgkrnl: core code

From
Greg KH <gregkh@linuxfoundation.org>
Date
2020-05-19 17:27:14
Also in
dri-devel, linux-fbdev, lkml
On Tue, May 19, 2020 at 12:32:31PM -0400, Sasha Levin wrote:
quoted hunk
+static int dxgglobal_init_global_channel(struct hv_device *hdev)
+{
+	int ret = 0;
+
+	TRACE_DEBUG(1, "%s %x  %x", __func__, hdev->vendor_id, hdev->device_id);
+	{
+		TRACE_DEBUG(1, "device type   : %pUb\n", &hdev->dev_type);
+		TRACE_DEBUG(1, "device channel: %pUb %p primary: %p\n",
+			    &hdev->channel->offermsg.offer.if_type,
+			    hdev->channel, hdev->channel->primary_channel);
+	}
+
+	if (dxgglobal->hdev) {
+		/* This device should appear only once */
+		pr_err("dxgglobal already initialized\n");
+		ret = -EBADE;
+		goto error;
+	}
+
+	dxgglobal->hdev = hdev;
+
+	ret = dxgvmbuschannel_init(&dxgglobal->channel, hdev);
+	if (ret) {
+		pr_err("dxgvmbuschannel_init failed: %d\n", ret);
+		goto error;
+	}
+
+	ret = dxgglobal_getiospace(dxgglobal);
+	if (ret) {
+		pr_err("getiospace failed: %d\n", ret);
+		goto error;
+	}
+
+	ret = dxgvmb_send_set_iospace_region(dxgglobal->mmiospace_base,
+					     dxgglobal->mmiospace_size, 0);
+	if (ret) {
+		pr_err("send_set_iospace_region failed\n");
+		goto error;
+	}
+
+	hv_set_drvdata(hdev, dxgglobal);
+
+	if (alloc_chrdev_region(&dxgglobal->device_devt, 0, 1, "dxgkrnl") < 0) {
+		pr_err("alloc_chrdev_region failed\n");
+		ret = -ENODEV;
+		goto error;
+	}
+	dxgglobal->devt_initialized = true;
+	dxgglobal->device_class = class_create(THIS_MODULE, "dxgkdrv");
+	if (dxgglobal->device_class == NULL) {
+		pr_err("class_create failed\n");
+		ret = -ENODEV;
+		goto error;
+	}
+	dxgglobal->device_class->devnode = dxg_devnode;
+	dxgglobal->device = device_create(dxgglobal->device_class, NULL,
+					  dxgglobal->device_devt, NULL, "dxg");
+	if (dxgglobal->device == NULL) {
+		pr_err("device_create failed\n");
+		ret = -ENODEV;
+		goto error;
+	}
+	dxgglobaldev = dxgglobal->device;
+	cdev_init(&dxgglobal->device_cdev, &dxgk_fops);
+	ret = cdev_add(&dxgglobal->device_cdev, dxgglobal->device_devt, 1);
+	if (ret < 0) {
+		pr_err("cdev_add failed: %d\n", ret);
+		goto error;
+	}
+	dxgglobal->cdev_initialized = true;
+
+error:
+	return ret;
+}
As you only are asking for a single char dev node, please just use the
misc device api instead of creating your own class and major number on
the fly.  It's much simpler and easier overall to make sure you got all
of the above logic correct.

thanks,

greg k-h
Thread (1 message) 1 message, 1 author, last reply 2020-05-19
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help