Yair Shachar | fbeb661 | 2015-05-20 13:48:26 +0300 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2014 Advanced Micro Devices, Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/log2.h> |
| 27 | #include <linux/sched.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/mutex.h> |
| 30 | #include <linux/device.h> |
| 31 | |
| 32 | #include "kfd_pm4_headers.h" |
| 33 | #include "kfd_pm4_headers_diq.h" |
| 34 | #include "kfd_kernel_queue.h" |
| 35 | #include "kfd_priv.h" |
| 36 | #include "kfd_pm4_opcodes.h" |
| 37 | #include "cik_regs.h" |
| 38 | #include "kfd_dbgmgr.h" |
| 39 | #include "kfd_dbgdev.h" |
| 40 | #include "kfd_device_queue_manager.h" |
| 41 | #include "../../radeon/cik_reg.h" |
| 42 | |
| 43 | static void dbgdev_address_watch_disable_nodiq(struct kfd_dev *dev) |
| 44 | { |
| 45 | BUG_ON(!dev || !dev->kfd2kgd); |
| 46 | |
| 47 | dev->kfd2kgd->address_watch_disable(dev->kgd); |
| 48 | } |
| 49 | |
| 50 | static int dbgdev_register_nodiq(struct kfd_dbgdev *dbgdev) |
| 51 | { |
| 52 | BUG_ON(!dbgdev); |
| 53 | |
| 54 | /* |
| 55 | * no action is needed in this case, |
| 56 | * just make sure diq will not be used |
| 57 | */ |
| 58 | |
| 59 | dbgdev->kq = NULL; |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int dbgdev_register_diq(struct kfd_dbgdev *dbgdev) |
| 65 | { |
| 66 | struct queue_properties properties; |
| 67 | unsigned int qid; |
| 68 | struct kernel_queue *kq = NULL; |
| 69 | int status; |
| 70 | |
| 71 | BUG_ON(!dbgdev || !dbgdev->pqm || !dbgdev->dev); |
| 72 | |
| 73 | status = pqm_create_queue(dbgdev->pqm, dbgdev->dev, NULL, |
| 74 | &properties, 0, KFD_QUEUE_TYPE_DIQ, |
| 75 | &qid); |
| 76 | |
| 77 | if (status) { |
| 78 | pr_err("amdkfd: Failed to create DIQ\n"); |
| 79 | return status; |
| 80 | } |
| 81 | |
| 82 | pr_debug("DIQ Created with queue id: %d\n", qid); |
| 83 | |
| 84 | kq = pqm_get_kernel_queue(dbgdev->pqm, qid); |
| 85 | |
| 86 | if (kq == NULL) { |
| 87 | pr_err("amdkfd: Error getting DIQ\n"); |
| 88 | pqm_destroy_queue(dbgdev->pqm, qid); |
| 89 | return -EFAULT; |
| 90 | } |
| 91 | |
| 92 | dbgdev->kq = kq; |
| 93 | |
| 94 | return status; |
| 95 | } |
| 96 | |
| 97 | static int dbgdev_unregister_nodiq(struct kfd_dbgdev *dbgdev) |
| 98 | { |
| 99 | BUG_ON(!dbgdev || !dbgdev->dev); |
| 100 | |
| 101 | /* disable watch address */ |
| 102 | dbgdev_address_watch_disable_nodiq(dbgdev->dev); |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | static int dbgdev_unregister_diq(struct kfd_dbgdev *dbgdev) |
| 107 | { |
| 108 | /* todo - disable address watch */ |
| 109 | int status; |
| 110 | |
| 111 | BUG_ON(!dbgdev || !dbgdev->pqm || !dbgdev->kq); |
| 112 | |
| 113 | status = pqm_destroy_queue(dbgdev->pqm, |
| 114 | dbgdev->kq->queue->properties.queue_id); |
| 115 | dbgdev->kq = NULL; |
| 116 | |
| 117 | return status; |
| 118 | } |
| 119 | |
| 120 | void kfd_dbgdev_init(struct kfd_dbgdev *pdbgdev, struct kfd_dev *pdev, |
| 121 | enum DBGDEV_TYPE type) |
| 122 | { |
| 123 | BUG_ON(!pdbgdev || !pdev); |
| 124 | |
| 125 | pdbgdev->dev = pdev; |
| 126 | pdbgdev->kq = NULL; |
| 127 | pdbgdev->type = type; |
| 128 | pdbgdev->pqm = NULL; |
| 129 | |
| 130 | switch (type) { |
| 131 | case DBGDEV_TYPE_NODIQ: |
| 132 | pdbgdev->dbgdev_register = dbgdev_register_nodiq; |
| 133 | pdbgdev->dbgdev_unregister = dbgdev_unregister_nodiq; |
| 134 | break; |
| 135 | case DBGDEV_TYPE_DIQ: |
| 136 | default: |
| 137 | pdbgdev->dbgdev_register = dbgdev_register_diq; |
| 138 | pdbgdev->dbgdev_unregister = dbgdev_unregister_diq; |
| 139 | break; |
| 140 | } |
| 141 | |
| 142 | } |