18c2ecf20Sopenharmony_ci/* sis.c -- sis driver -*- linux-c -*-
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
48c2ecf20Sopenharmony_ci * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
58c2ecf20Sopenharmony_ci * All Rights Reserved.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
88c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
98c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
108c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
118c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
128c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next
158c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
168c2ecf20Sopenharmony_ci * Software.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
198c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
208c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
218c2ecf20Sopenharmony_ci * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
228c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
238c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
248c2ecf20Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci */
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#include <linux/module.h>
298c2ecf20Sopenharmony_ci#include <linux/pci.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#include <drm/drm_drv.h>
328c2ecf20Sopenharmony_ci#include <drm/drm_file.h>
338c2ecf20Sopenharmony_ci#include <drm/drm_pciids.h>
348c2ecf20Sopenharmony_ci#include <drm/sis_drm.h>
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#include "sis_drv.h"
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistatic struct pci_device_id pciidlist[] = {
398c2ecf20Sopenharmony_ci	sisdrv_PCI_IDS
408c2ecf20Sopenharmony_ci};
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistatic int sis_driver_load(struct drm_device *dev, unsigned long chipset)
438c2ecf20Sopenharmony_ci{
448c2ecf20Sopenharmony_ci	drm_sis_private_t *dev_priv;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	pci_set_master(dev->pdev);
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	dev_priv = kzalloc(sizeof(drm_sis_private_t), GFP_KERNEL);
498c2ecf20Sopenharmony_ci	if (dev_priv == NULL)
508c2ecf20Sopenharmony_ci		return -ENOMEM;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	idr_init(&dev_priv->object_idr);
538c2ecf20Sopenharmony_ci	dev->dev_private = (void *)dev_priv;
548c2ecf20Sopenharmony_ci	dev_priv->chipset = chipset;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	return 0;
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistatic void sis_driver_unload(struct drm_device *dev)
608c2ecf20Sopenharmony_ci{
618c2ecf20Sopenharmony_ci	drm_sis_private_t *dev_priv = dev->dev_private;
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	idr_destroy(&dev_priv->object_idr);
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	kfree(dev_priv);
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistatic const struct file_operations sis_driver_fops = {
698c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
708c2ecf20Sopenharmony_ci	.open = drm_open,
718c2ecf20Sopenharmony_ci	.release = drm_release,
728c2ecf20Sopenharmony_ci	.unlocked_ioctl = drm_ioctl,
738c2ecf20Sopenharmony_ci	.mmap = drm_legacy_mmap,
748c2ecf20Sopenharmony_ci	.poll = drm_poll,
758c2ecf20Sopenharmony_ci	.compat_ioctl = drm_compat_ioctl,
768c2ecf20Sopenharmony_ci	.llseek = noop_llseek,
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistatic int sis_driver_open(struct drm_device *dev, struct drm_file *file)
808c2ecf20Sopenharmony_ci{
818c2ecf20Sopenharmony_ci	struct sis_file_private *file_priv;
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	DRM_DEBUG_DRIVER("\n");
848c2ecf20Sopenharmony_ci	file_priv = kmalloc(sizeof(*file_priv), GFP_KERNEL);
858c2ecf20Sopenharmony_ci	if (!file_priv)
868c2ecf20Sopenharmony_ci		return -ENOMEM;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	file->driver_priv = file_priv;
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	INIT_LIST_HEAD(&file_priv->obj_list);
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci	return 0;
938c2ecf20Sopenharmony_ci}
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cistatic void sis_driver_postclose(struct drm_device *dev, struct drm_file *file)
968c2ecf20Sopenharmony_ci{
978c2ecf20Sopenharmony_ci	struct sis_file_private *file_priv = file->driver_priv;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	kfree(file_priv);
1008c2ecf20Sopenharmony_ci}
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistatic struct drm_driver driver = {
1038c2ecf20Sopenharmony_ci	.driver_features = DRIVER_USE_AGP | DRIVER_LEGACY,
1048c2ecf20Sopenharmony_ci	.load = sis_driver_load,
1058c2ecf20Sopenharmony_ci	.unload = sis_driver_unload,
1068c2ecf20Sopenharmony_ci	.open = sis_driver_open,
1078c2ecf20Sopenharmony_ci	.preclose = sis_reclaim_buffers_locked,
1088c2ecf20Sopenharmony_ci	.postclose = sis_driver_postclose,
1098c2ecf20Sopenharmony_ci	.dma_quiescent = sis_idle,
1108c2ecf20Sopenharmony_ci	.lastclose = sis_lastclose,
1118c2ecf20Sopenharmony_ci	.ioctls = sis_ioctls,
1128c2ecf20Sopenharmony_ci	.fops = &sis_driver_fops,
1138c2ecf20Sopenharmony_ci	.name = DRIVER_NAME,
1148c2ecf20Sopenharmony_ci	.desc = DRIVER_DESC,
1158c2ecf20Sopenharmony_ci	.date = DRIVER_DATE,
1168c2ecf20Sopenharmony_ci	.major = DRIVER_MAJOR,
1178c2ecf20Sopenharmony_ci	.minor = DRIVER_MINOR,
1188c2ecf20Sopenharmony_ci	.patchlevel = DRIVER_PATCHLEVEL,
1198c2ecf20Sopenharmony_ci};
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistatic struct pci_driver sis_pci_driver = {
1228c2ecf20Sopenharmony_ci	.name = DRIVER_NAME,
1238c2ecf20Sopenharmony_ci	.id_table = pciidlist,
1248c2ecf20Sopenharmony_ci};
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cistatic int __init sis_init(void)
1278c2ecf20Sopenharmony_ci{
1288c2ecf20Sopenharmony_ci	driver.num_ioctls = sis_max_ioctl;
1298c2ecf20Sopenharmony_ci	return drm_legacy_pci_init(&driver, &sis_pci_driver);
1308c2ecf20Sopenharmony_ci}
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistatic void __exit sis_exit(void)
1338c2ecf20Sopenharmony_ci{
1348c2ecf20Sopenharmony_ci	drm_legacy_pci_exit(&driver, &sis_pci_driver);
1358c2ecf20Sopenharmony_ci}
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cimodule_init(sis_init);
1388c2ecf20Sopenharmony_cimodule_exit(sis_exit);
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ciMODULE_AUTHOR(DRIVER_AUTHOR);
1418c2ecf20Sopenharmony_ciMODULE_DESCRIPTION(DRIVER_DESC);
1428c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL and additional rights");
143