11.2Sriastrad/*	$NetBSD: sis_drv.c,v 1.4 2021/12/18 23:45:44 riastradh Exp $	*/
21.2Sriastrad
31.1Sriastrad/* sis.c -- sis driver -*- linux-c -*-
41.1Sriastrad *
51.1Sriastrad * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
61.1Sriastrad * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
71.1Sriastrad * All Rights Reserved.
81.1Sriastrad *
91.1Sriastrad * Permission is hereby granted, free of charge, to any person obtaining a
101.1Sriastrad * copy of this software and associated documentation files (the "Software"),
111.1Sriastrad * to deal in the Software without restriction, including without limitation
121.1Sriastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense,
131.1Sriastrad * and/or sell copies of the Software, and to permit persons to whom the
141.1Sriastrad * Software is furnished to do so, subject to the following conditions:
151.1Sriastrad *
161.1Sriastrad * The above copyright notice and this permission notice (including the next
171.1Sriastrad * paragraph) shall be included in all copies or substantial portions of the
181.1Sriastrad * Software.
191.1Sriastrad *
201.1Sriastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
211.1Sriastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
221.1Sriastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
231.1Sriastrad * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
241.1Sriastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
251.1Sriastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
261.1Sriastrad * DEALINGS IN THE SOFTWARE.
271.1Sriastrad *
281.1Sriastrad */
291.1Sriastrad
301.2Sriastrad#include <sys/cdefs.h>
311.2Sriastrad__KERNEL_RCSID(0, "$NetBSD: sis_drv.c,v 1.4 2021/12/18 23:45:44 riastradh Exp $");
321.2Sriastrad
331.1Sriastrad#include <linux/module.h>
341.4Sriastrad#include <linux/pci.h>
351.1Sriastrad
361.4Sriastrad#include <drm/drm_drv.h>
371.4Sriastrad#include <drm/drm_file.h>
381.4Sriastrad#include <drm/drm_pciids.h>
391.1Sriastrad#include <drm/sis_drm.h>
401.4Sriastrad
411.1Sriastrad#include "sis_drv.h"
421.1Sriastrad
431.1Sriastradstatic struct pci_device_id pciidlist[] = {
441.1Sriastrad	sisdrv_PCI_IDS
451.1Sriastrad};
461.1Sriastrad
471.1Sriastradstatic int sis_driver_load(struct drm_device *dev, unsigned long chipset)
481.1Sriastrad{
491.1Sriastrad	drm_sis_private_t *dev_priv;
501.1Sriastrad
511.1Sriastrad	pci_set_master(dev->pdev);
521.1Sriastrad
531.1Sriastrad	dev_priv = kzalloc(sizeof(drm_sis_private_t), GFP_KERNEL);
541.1Sriastrad	if (dev_priv == NULL)
551.1Sriastrad		return -ENOMEM;
561.1Sriastrad
571.1Sriastrad	idr_init(&dev_priv->object_idr);
581.1Sriastrad	dev->dev_private = (void *)dev_priv;
591.1Sriastrad	dev_priv->chipset = chipset;
601.1Sriastrad
611.1Sriastrad	return 0;
621.1Sriastrad}
631.1Sriastrad
641.4Sriastradstatic void sis_driver_unload(struct drm_device *dev)
651.1Sriastrad{
661.1Sriastrad	drm_sis_private_t *dev_priv = dev->dev_private;
671.1Sriastrad
681.1Sriastrad	idr_destroy(&dev_priv->object_idr);
691.1Sriastrad
701.1Sriastrad	kfree(dev_priv);
711.1Sriastrad}
721.1Sriastrad
731.1Sriastradstatic const struct file_operations sis_driver_fops = {
741.1Sriastrad	.owner = THIS_MODULE,
751.1Sriastrad	.open = drm_open,
761.1Sriastrad	.release = drm_release,
771.1Sriastrad	.unlocked_ioctl = drm_ioctl,
781.2Sriastrad	.mmap = drm_legacy_mmap,
791.1Sriastrad	.poll = drm_poll,
801.1Sriastrad	.compat_ioctl = drm_compat_ioctl,
811.1Sriastrad	.llseek = noop_llseek,
821.1Sriastrad};
831.1Sriastrad
841.1Sriastradstatic int sis_driver_open(struct drm_device *dev, struct drm_file *file)
851.1Sriastrad{
861.1Sriastrad	struct sis_file_private *file_priv;
871.1Sriastrad
881.1Sriastrad	DRM_DEBUG_DRIVER("\n");
891.1Sriastrad	file_priv = kmalloc(sizeof(*file_priv), GFP_KERNEL);
901.1Sriastrad	if (!file_priv)
911.1Sriastrad		return -ENOMEM;
921.1Sriastrad
931.1Sriastrad	file->driver_priv = file_priv;
941.1Sriastrad
951.1Sriastrad	INIT_LIST_HEAD(&file_priv->obj_list);
961.1Sriastrad
971.1Sriastrad	return 0;
981.1Sriastrad}
991.1Sriastrad
1001.2Sriastradstatic void sis_driver_postclose(struct drm_device *dev, struct drm_file *file)
1011.1Sriastrad{
1021.1Sriastrad	struct sis_file_private *file_priv = file->driver_priv;
1031.1Sriastrad
1041.1Sriastrad	kfree(file_priv);
1051.1Sriastrad}
1061.1Sriastrad
1071.1Sriastradstatic struct drm_driver driver = {
1081.4Sriastrad	.driver_features = DRIVER_USE_AGP | DRIVER_LEGACY,
1091.1Sriastrad	.load = sis_driver_load,
1101.1Sriastrad	.unload = sis_driver_unload,
1111.1Sriastrad	.open = sis_driver_open,
1121.1Sriastrad	.preclose = sis_reclaim_buffers_locked,
1131.1Sriastrad	.postclose = sis_driver_postclose,
1141.1Sriastrad	.dma_quiescent = sis_idle,
1151.1Sriastrad	.lastclose = sis_lastclose,
1161.1Sriastrad	.ioctls = sis_ioctls,
1171.1Sriastrad	.fops = &sis_driver_fops,
1181.1Sriastrad	.name = DRIVER_NAME,
1191.1Sriastrad	.desc = DRIVER_DESC,
1201.1Sriastrad	.date = DRIVER_DATE,
1211.1Sriastrad	.major = DRIVER_MAJOR,
1221.1Sriastrad	.minor = DRIVER_MINOR,
1231.1Sriastrad	.patchlevel = DRIVER_PATCHLEVEL,
1241.1Sriastrad};
1251.1Sriastrad
1261.1Sriastradstatic struct pci_driver sis_pci_driver = {
1271.1Sriastrad	.name = DRIVER_NAME,
1281.1Sriastrad	.id_table = pciidlist,
1291.1Sriastrad};
1301.1Sriastrad
1311.1Sriastradstatic int __init sis_init(void)
1321.1Sriastrad{
1331.1Sriastrad	driver.num_ioctls = sis_max_ioctl;
1341.4Sriastrad	return drm_legacy_pci_init(&driver, &sis_pci_driver);
1351.1Sriastrad}
1361.1Sriastrad
1371.1Sriastradstatic void __exit sis_exit(void)
1381.1Sriastrad{
1391.4Sriastrad	drm_legacy_pci_exit(&driver, &sis_pci_driver);
1401.1Sriastrad}
1411.1Sriastrad
1421.1Sriastradmodule_init(sis_init);
1431.1Sriastradmodule_exit(sis_exit);
1441.1Sriastrad
1451.1SriastradMODULE_AUTHOR(DRIVER_AUTHOR);
1461.1SriastradMODULE_DESCRIPTION(DRIVER_DESC);
1471.1SriastradMODULE_LICENSE("GPL and additional rights");
148