ivpu_drv.c (cd7272215c44676dba236491941c6c406701cc5e) ivpu_drv.c (852be13f3bd32c1eab808840cfac41b1fea25991)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2020-2023 Intel Corporation
4 */
5
6#include <linux/firmware.h>
7#include <linux/module.h>
8#include <linux/pci.h>

--- 10 unchanged lines hidden (view full) ---

19#include "ivpu_fw.h"
20#include "ivpu_gem.h"
21#include "ivpu_hw.h"
22#include "ivpu_ipc.h"
23#include "ivpu_job.h"
24#include "ivpu_jsm_msg.h"
25#include "ivpu_mmu.h"
26#include "ivpu_mmu_context.h"
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2020-2023 Intel Corporation
4 */
5
6#include <linux/firmware.h>
7#include <linux/module.h>
8#include <linux/pci.h>

--- 10 unchanged lines hidden (view full) ---

19#include "ivpu_fw.h"
20#include "ivpu_gem.h"
21#include "ivpu_hw.h"
22#include "ivpu_ipc.h"
23#include "ivpu_job.h"
24#include "ivpu_jsm_msg.h"
25#include "ivpu_mmu.h"
26#include "ivpu_mmu_context.h"
27#include "ivpu_pm.h"
27
28#ifndef DRIVER_VERSION_STR
29#define DRIVER_VERSION_STR __stringify(DRM_IVPU_DRIVER_MAJOR) "." \
30 __stringify(DRM_IVPU_DRIVER_MINOR) "."
31#endif
32
33static const struct drm_driver driver;
34

--- 422 unchanged lines hidden (view full) ---

457 vdev->fw = drmm_kzalloc(&vdev->drm, sizeof(*vdev->fw), GFP_KERNEL);
458 if (!vdev->fw)
459 return -ENOMEM;
460
461 vdev->ipc = drmm_kzalloc(&vdev->drm, sizeof(*vdev->ipc), GFP_KERNEL);
462 if (!vdev->ipc)
463 return -ENOMEM;
464
28
29#ifndef DRIVER_VERSION_STR
30#define DRIVER_VERSION_STR __stringify(DRM_IVPU_DRIVER_MAJOR) "." \
31 __stringify(DRM_IVPU_DRIVER_MINOR) "."
32#endif
33
34static const struct drm_driver driver;
35

--- 422 unchanged lines hidden (view full) ---

458 vdev->fw = drmm_kzalloc(&vdev->drm, sizeof(*vdev->fw), GFP_KERNEL);
459 if (!vdev->fw)
460 return -ENOMEM;
461
462 vdev->ipc = drmm_kzalloc(&vdev->drm, sizeof(*vdev->ipc), GFP_KERNEL);
463 if (!vdev->ipc)
464 return -ENOMEM;
465
466 vdev->pm = drmm_kzalloc(&vdev->drm, sizeof(*vdev->pm), GFP_KERNEL);
467 if (!vdev->pm)
468 return -ENOMEM;
469
465 vdev->hw->ops = &ivpu_hw_mtl_ops;
466 vdev->platform = IVPU_PLATFORM_INVALID;
467 vdev->context_xa_limit.min = IVPU_GLOBAL_CONTEXT_MMU_SSID + 1;
468 vdev->context_xa_limit.max = IVPU_CONTEXT_LIMIT;
469 atomic64_set(&vdev->unique_id_counter, 0);
470 xa_init_flags(&vdev->context_xa, XA_FLAGS_ALLOC);
471 xa_init_flags(&vdev->submitted_jobs_xa, XA_FLAGS_ALLOC1);
472 lockdep_set_class(&vdev->submitted_jobs_xa.xa_lock, &submitted_jobs_xa_lock_class_key);

--- 43 unchanged lines hidden (view full) ---

516 }
517
518 ret = ivpu_ipc_init(vdev);
519 if (ret) {
520 ivpu_err(vdev, "Failed to initialize IPC: %d\n", ret);
521 goto err_fw_fini;
522 }
523
470 vdev->hw->ops = &ivpu_hw_mtl_ops;
471 vdev->platform = IVPU_PLATFORM_INVALID;
472 vdev->context_xa_limit.min = IVPU_GLOBAL_CONTEXT_MMU_SSID + 1;
473 vdev->context_xa_limit.max = IVPU_CONTEXT_LIMIT;
474 atomic64_set(&vdev->unique_id_counter, 0);
475 xa_init_flags(&vdev->context_xa, XA_FLAGS_ALLOC);
476 xa_init_flags(&vdev->submitted_jobs_xa, XA_FLAGS_ALLOC1);
477 lockdep_set_class(&vdev->submitted_jobs_xa.xa_lock, &submitted_jobs_xa_lock_class_key);

--- 43 unchanged lines hidden (view full) ---

521 }
522
523 ret = ivpu_ipc_init(vdev);
524 if (ret) {
525 ivpu_err(vdev, "Failed to initialize IPC: %d\n", ret);
526 goto err_fw_fini;
527 }
528
529 ret = ivpu_pm_init(vdev);
530 if (ret) {
531 ivpu_err(vdev, "Failed to initialize PM: %d\n", ret);
532 goto err_ipc_fini;
533 }
534
524 ret = ivpu_job_done_thread_init(vdev);
525 if (ret) {
526 ivpu_err(vdev, "Failed to initialize job done thread: %d\n", ret);
527 goto err_ipc_fini;
528 }
529
530 ret = ivpu_fw_load(vdev);
531 if (ret) {
532 ivpu_err(vdev, "Failed to load firmware: %d\n", ret);
533 goto err_job_done_thread_fini;
534 }
535
536 ret = ivpu_boot(vdev);
537 if (ret) {
538 ivpu_err(vdev, "Failed to boot: %d\n", ret);
539 goto err_job_done_thread_fini;
540 }
541
535 ret = ivpu_job_done_thread_init(vdev);
536 if (ret) {
537 ivpu_err(vdev, "Failed to initialize job done thread: %d\n", ret);
538 goto err_ipc_fini;
539 }
540
541 ret = ivpu_fw_load(vdev);
542 if (ret) {
543 ivpu_err(vdev, "Failed to load firmware: %d\n", ret);
544 goto err_job_done_thread_fini;
545 }
546
547 ret = ivpu_boot(vdev);
548 if (ret) {
549 ivpu_err(vdev, "Failed to boot: %d\n", ret);
550 goto err_job_done_thread_fini;
551 }
552
553 ivpu_pm_enable(vdev);
554
542 return 0;
543
544err_job_done_thread_fini:
545 ivpu_job_done_thread_fini(vdev);
546err_ipc_fini:
547 ivpu_ipc_fini(vdev);
548err_fw_fini:
549 ivpu_fw_fini(vdev);

--- 4 unchanged lines hidden (view full) ---

554err_xa_destroy:
555 xa_destroy(&vdev->submitted_jobs_xa);
556 xa_destroy(&vdev->context_xa);
557 return ret;
558}
559
560static void ivpu_dev_fini(struct ivpu_device *vdev)
561{
555 return 0;
556
557err_job_done_thread_fini:
558 ivpu_job_done_thread_fini(vdev);
559err_ipc_fini:
560 ivpu_ipc_fini(vdev);
561err_fw_fini:
562 ivpu_fw_fini(vdev);

--- 4 unchanged lines hidden (view full) ---

567err_xa_destroy:
568 xa_destroy(&vdev->submitted_jobs_xa);
569 xa_destroy(&vdev->context_xa);
570 return ret;
571}
572
573static void ivpu_dev_fini(struct ivpu_device *vdev)
574{
575 ivpu_pm_disable(vdev);
562 ivpu_shutdown(vdev);
563 ivpu_job_done_thread_fini(vdev);
564 ivpu_ipc_fini(vdev);
565 ivpu_fw_fini(vdev);
566 ivpu_mmu_global_context_fini(vdev);
567
568 drm_WARN_ON(&vdev->drm, !xa_empty(&vdev->submitted_jobs_xa));
569 xa_destroy(&vdev->submitted_jobs_xa);

--- 36 unchanged lines hidden (view full) ---

606static void ivpu_remove(struct pci_dev *pdev)
607{
608 struct ivpu_device *vdev = pci_get_drvdata(pdev);
609
610 drm_dev_unregister(&vdev->drm);
611 ivpu_dev_fini(vdev);
612}
613
576 ivpu_shutdown(vdev);
577 ivpu_job_done_thread_fini(vdev);
578 ivpu_ipc_fini(vdev);
579 ivpu_fw_fini(vdev);
580 ivpu_mmu_global_context_fini(vdev);
581
582 drm_WARN_ON(&vdev->drm, !xa_empty(&vdev->submitted_jobs_xa));
583 xa_destroy(&vdev->submitted_jobs_xa);

--- 36 unchanged lines hidden (view full) ---

620static void ivpu_remove(struct pci_dev *pdev)
621{
622 struct ivpu_device *vdev = pci_get_drvdata(pdev);
623
624 drm_dev_unregister(&vdev->drm);
625 ivpu_dev_fini(vdev);
626}
627
628static const struct dev_pm_ops ivpu_drv_pci_pm = {
629 SET_SYSTEM_SLEEP_PM_OPS(ivpu_pm_suspend_cb, ivpu_pm_resume_cb)
630 SET_RUNTIME_PM_OPS(ivpu_pm_runtime_suspend_cb, ivpu_pm_runtime_resume_cb, NULL)
631};
632
633static const struct pci_error_handlers ivpu_drv_pci_err = {
634 .reset_prepare = ivpu_pm_reset_prepare_cb,
635 .reset_done = ivpu_pm_reset_done_cb,
636};
637
614static struct pci_driver ivpu_pci_driver = {
615 .name = KBUILD_MODNAME,
616 .id_table = ivpu_pci_ids,
617 .probe = ivpu_probe,
618 .remove = ivpu_remove,
638static struct pci_driver ivpu_pci_driver = {
639 .name = KBUILD_MODNAME,
640 .id_table = ivpu_pci_ids,
641 .probe = ivpu_probe,
642 .remove = ivpu_remove,
643 .driver = {
644 .pm = &ivpu_drv_pci_pm,
645 },
646 .err_handler = &ivpu_drv_pci_err,
619};
620
621module_pci_driver(ivpu_pci_driver);
622
623MODULE_AUTHOR("Intel Corporation");
624MODULE_DESCRIPTION(DRIVER_DESC);
625MODULE_LICENSE("GPL and additional rights");
626MODULE_VERSION(DRIVER_VERSION_STR);
647};
648
649module_pci_driver(ivpu_pci_driver);
650
651MODULE_AUTHOR("Intel Corporation");
652MODULE_DESCRIPTION(DRIVER_DESC);
653MODULE_LICENSE("GPL and additional rights");
654MODULE_VERSION(DRIVER_VERSION_STR);