已合并
vnpu: resolve a series of timing issues #139
任文杰创建于 8月25日
vnpu: resolve a series of timing issues #139
已合并
共 34 个文件变更+2170-2544
| @@ -15,21 +15,21 @@ KERNEL_DIR=/lib/modules/$(UNAME)/build | |||
| 15 | KERNEL_SOURCE_DIR=/lib/modules/$(UNAME)/source | 15 | KERNEL_SOURCE_DIR=/lib/modules/$(UNAME)/source |
| 16 | 16 | ||
| 17 | ifneq ($(TOP_DIR),) | 17 | ifneq ($(TOP_DIR),) |
| 18 | - EXTRA_CFLAGS += -I$(TOP_DIR)/driver/driver/src/sdk_driver/kernel_adapt/include | 18 | + ccflags-y += -I$(TOP_DIR)/driver/driver/src/sdk_driver/kernel_adapt/include |
| 19 | endif | 19 | endif |
| 20 | 20 | ||
| 21 | ifeq ($(DAVINCI_HIAI_DKMS), y) | 21 | ifeq ($(DAVINCI_HIAI_DKMS), y) |
| 22 | - EXTRA_CFLAGS += -I$(HIAI_DKMS_DIR)/kernel_adapt/include | 22 | + ccflags-y += -I$(HIAI_DKMS_DIR)/kernel_adapt/include |
| 23 | else | 23 | else |
| 24 | - EXTRA_CFLAGS += -I$(PWD)/../kernel_adapt/include | 24 | + ccflags-y += -I$(PWD)/../kernel_adapt/include |
| 25 | endif | 25 | endif |
| 26 | 26 | ||
| 27 | ifeq ($(ENABLE_OPEN_SRC), y) | 27 | ifeq ($(ENABLE_OPEN_SRC), y) |
| 28 | - EXTRA_CFLAGS += -I$(DRIVER_KERNEL_DIR)/kernel_adapt/include | 28 | + ccflags-y += -I$(DRIVER_KERNEL_DIR)/kernel_adapt/include |
| 29 | endif | 29 | endif |
| 30 | 30 | ||
| 31 | ifneq ($(NOT_SUPPORT_SP), y) | 31 | ifneq ($(NOT_SUPPORT_SP), y) |
| 32 | - EXTRA_CFLAGS += -fstack-protector-all | 32 | + ccflags-y += -fstack-protector-all |
| 33 | endif | 33 | endif |
| 34 | 34 | ||
| 35 | ifeq ($(DAVINCI_TEST),y) | 35 | ifeq ($(DAVINCI_TEST),y) |
| @@ -17,15 +17,11 @@ | |||
| 17 | #include "dma_pool.h" | 17 | #include "dma_pool.h" |
| 18 | #include "dma_pool_map.h" | 18 | #include "dma_pool_map.h" |
| 19 | 19 | ||
| 20 | -STATIC void dev_map_scheduled(struct hw_vdavinci *vdavinci, | 20 | +STATIC void dev_map_scheduled(struct hw_vdavinci *vdavinci, unsigned long *count) |
| 21 | - unsigned long *count) | ||
| 22 | { | 21 | { |
| 23 | (*count)++; | 22 | (*count)++; |
| 24 | - if (hw_vdavinci_scheduled(vdavinci, | 23 | + if (hw_vdavinci_scheduled(vdavinci, (*count) * KA_VFIO_PIN_PAGES_MAX_ENTRIES, VDAVINCI_MAP_PAGES_OF_SCHEDULE, |
| 25 | - (*count) * KA_VFIO_PIN_PAGES_MAX_ENTRIES, | 24 | + VDAVINCI_MAP_TIME_OF_SCHEDULE, NULL)) { |
| 26 | - VDAVINCI_MAP_PAGES_OF_SCHEDULE, | ||
| 27 | - VDAVINCI_MAP_TIME_OF_SCHEDULE, | ||
| 28 | - NULL)) { | ||
| 29 | (*count) = 0; | 25 | (*count) = 0; |
| 30 | } | 26 | } |
| 31 | } | 27 | } |
| @@ -46,8 +42,7 @@ STATIC void dev_unmap_2m(ka_device_t *dev, ka_sg_table_t *dma_sgt) | |||
| 46 | ka_mm_kfree(dma_sgt); | 42 | ka_mm_kfree(dma_sgt); |
| 47 | } | 43 | } |
| 48 | 44 | ||
| 49 | -STATIC int dev_map_2m(ka_device_t *dev, unsigned long gfn, | 45 | +STATIC int dev_map_2m(ka_device_t *dev, unsigned long gfn, ka_sg_table_t **dma_sgt, |
| 50 | - ka_sg_table_t **dma_sgt, | ||
| 51 | struct page_info_list *dma_page_list, unsigned long size) | 46 | struct page_info_list *dma_page_list, unsigned long size) |
| 52 | { | 47 | { |
| 53 | int ret; | 48 | int ret; |
| @@ -65,14 +60,15 @@ STATIC int dev_map_2m(ka_device_t *dev, unsigned long gfn, | |||
| 65 | 60 | ||
| 66 | ret = ka_base_sg_alloc_table(*dma_sgt, dma_page_list->elem_num, KA_GFP_KERNEL); | 61 | ret = ka_base_sg_alloc_table(*dma_sgt, dma_page_list->elem_num, KA_GFP_KERNEL); |
| 67 | if (ret) { | 62 | if (ret) { |
| 68 | - vascend_err(dev, "ka_base_sg_alloc_table return error result, ret: %d, sg_len: %u", | 63 | + vascend_err(dev, "ka_base_sg_alloc_table return error result, ret: %d, sg_len: %u", ret, |
| 69 | - ret, dma_page_list->elem_num); | 64 | + dma_page_list->elem_num); |
| 70 | ret = -ENOMEM; | 65 | ret = -ENOMEM; |
| 71 | goto err_free_sgt; | 66 | goto err_free_sgt; |
| 72 | } | 67 | } |
| 73 | 68 | ||
| 74 | sgl = (*dma_sgt)->sgl; | 69 | sgl = (*dma_sgt)->sgl; |
| 75 | - ka_list_for_each_entry(dma_page_info, &dma_page_list->head, list) { | 70 | + ka_list_for_each_entry(dma_page_info, &dma_page_list->head, list) |
| 71 | + { | ||
| 76 | ka_base_sg_set_page(sgl, dma_page_info->page, dma_page_info->length, 0); | 72 | ka_base_sg_set_page(sgl, dma_page_info->page, dma_page_info->length, 0); |
| 77 | sgl = ka_base_sg_next(sgl); | 73 | sgl = ka_base_sg_next(sgl); |
| 78 | } | 74 | } |
| @@ -93,8 +89,7 @@ err_free_sgt: | |||
| 93 | return ret; | 89 | return ret; |
| 94 | } | 90 | } |
| 95 | 91 | ||
| 96 | -void dev_dma_unmap_ram_range(struct hw_vdavinci *vdavinci, | 92 | +void dev_dma_unmap_ram_range(struct hw_vdavinci *vdavinci, struct ram_range_info *ram_info) |
| 97 | - struct ram_range_info *ram_info) | ||
| 98 | { | 93 | { |
| 99 | int i; | 94 | int i; |
| 100 | bool found = false; | 95 | bool found = false; |
| @@ -107,7 +102,8 @@ void dev_dma_unmap_ram_range(struct hw_vdavinci *vdavinci, | |||
| 107 | if (ka_list_empty(&(vdavinci->vdev.dev_dma_info_list_head))) { | 102 | if (ka_list_empty(&(vdavinci->vdev.dev_dma_info_list_head))) { |
| 108 | return; | 103 | return; |
| 109 | } | 104 | } |
| 110 | - ka_list_for_each_safe(pos, next, &(vdavinci->vdev.dev_dma_info_list_head)) { | 105 | + ka_list_for_each_safe(pos, next, &(vdavinci->vdev.dev_dma_info_list_head)) |
| 106 | + { | ||
| 111 | dma_info = ka_list_entry(pos, struct dev_dma_info, list); | 107 | dma_info = ka_list_entry(pos, struct dev_dma_info, list); |
| 112 | if (ram_info != dma_info->ram_info) { | 108 | if (ram_info != dma_info->ram_info) { |
| 113 | continue; | 109 | continue; |
| @@ -119,8 +115,10 @@ void dev_dma_unmap_ram_range(struct hw_vdavinci *vdavinci, | |||
| 119 | dev_unmap_2m(dev, dev_dma_sgt->dma_sgt); | 115 | dev_unmap_2m(dev, dev_dma_sgt->dma_sgt); |
| 120 | ka_mm_kfree(dev_dma_sgt); | 116 | ka_mm_kfree(dev_dma_sgt); |
| 121 | } | 117 | } |
| 118 | + ka_mm_kfree(dma_info->sgt_array); | ||
| 122 | ka_mm_kfree(dma_info); | 119 | ka_mm_kfree(dma_info); |
| 123 | found = true; | 120 | found = true; |
| 121 | + break; | ||
| 124 | } | 122 | } |
| 125 | if (!found) { | 123 | if (!found) { |
| 126 | return; | 124 | return; |
| @@ -128,17 +126,14 @@ void dev_dma_unmap_ram_range(struct hw_vdavinci *vdavinci, | |||
| 128 | ka_base_atomic_dec(&ram_info->map_count); | 126 | ka_base_atomic_dec(&ram_info->map_count); |
| 129 | } | 127 | } |
| 130 | 128 | ||
| 131 | -STATIC struct dev_dma_sgt *dev_map_sgt_2m(struct hw_vdavinci *vdavinci, | 129 | +STATIC struct dev_dma_sgt *dev_map_sgt_2m(struct hw_vdavinci *vdavinci, struct dma_info_2m *dma_array_node) |
| 132 | - struct dma_info_2m *dma_array_node) | ||
| 133 | { | 130 | { |
| 134 | int ret = 0; | 131 | int ret = 0; |
| 135 | ka_sg_table_t *dma_sgt = NULL; | 132 | ka_sg_table_t *dma_sgt = NULL; |
| 136 | struct dev_dma_sgt *dev_dma_sgt = NULL; | 133 | struct dev_dma_sgt *dev_dma_sgt = NULL; |
| 137 | ka_device_t *dev = vdavinci_get_device(vdavinci); | 134 | ka_device_t *dev = vdavinci_get_device(vdavinci); |
| 138 | 135 | ||
| 139 | - ret = dev_map_2m(dev, dma_array_node->gfn, &dma_sgt, | 136 | + ret = dev_map_2m(dev, dma_array_node->gfn, &dma_sgt, &dma_array_node->dma_page_list, dma_array_node->size); |
| 140 | - &dma_array_node->dma_page_list, | ||
| 141 | - dma_array_node->size); | ||
| 142 | if (ret != 0) { | 137 | if (ret != 0) { |
| 143 | goto out; | 138 | goto out; |
| 144 | } | 139 | } |
| @@ -159,13 +154,11 @@ STATIC struct dev_dma_sgt *dev_map_sgt_2m(struct hw_vdavinci *vdavinci, | |||
| 159 | free: | 154 | free: |
| 160 | dev_unmap_2m(dev, dma_sgt); | 155 | dev_unmap_2m(dev, dma_sgt); |
| 161 | out: | 156 | out: |
| 162 | - vascend_err(dev, "dma map page failed, ret: %d, size: 0x%lx\n", | 157 | + vascend_err(dev, "dma map page failed, ret: %d, size: 0x%lx\n", ret, dma_array_node->size); |
| 163 | - ret, dma_array_node->size); | ||
| 164 | return NULL; | 158 | return NULL; |
| 165 | } | 159 | } |
| 166 | 160 | ||
| 167 | -int dev_dma_map_ram_range(struct hw_vdavinci *vdavinci, | 161 | +int dev_dma_map_ram_range(struct hw_vdavinci *vdavinci, struct ram_range_info *ram_info) |
| 168 | - struct ram_range_info *ram_info) | ||
| 169 | { | 162 | { |
| 170 | int ret = 0, i = 0, j = 0; | 163 | int ret = 0, i = 0, j = 0; |
| 171 | unsigned long count = 0; | 164 | unsigned long count = 0; |
| @@ -175,8 +168,8 @@ int dev_dma_map_ram_range(struct hw_vdavinci *vdavinci, | |||
| 175 | ka_device_t *dev = vdavinci_get_device(vdavinci); | 168 | ka_device_t *dev = vdavinci_get_device(vdavinci); |
| 176 | struct dev_dma_info *dma_info = NULL; | 169 | struct dev_dma_info *dma_info = NULL; |
| 177 | 170 | ||
| 178 | - sgt_array = (struct dev_dma_sgt **) | 171 | + sgt_array = (struct dev_dma_sgt **)ka_mm_kzalloc(sizeof(struct dev_dma_sgt *) * ram_info->dma_array_len, |
| 179 | - ka_mm_kzalloc(sizeof(struct dev_dma_sgt *) * ram_info->dma_array_len, KA_GFP_KERNEL); | 172 | + KA_GFP_KERNEL); |
| 180 | if (sgt_array == NULL) { | 173 | if (sgt_array == NULL) { |
| 181 | return -ENOMEM; | 174 | return -ENOMEM; |
| 182 | } | 175 | } |
| @@ -215,14 +208,14 @@ free_sgt: | |||
| 215 | return ret; | 208 | return ret; |
| 216 | } | 209 | } |
| 217 | 210 | ||
| 218 | -STATIC void vf_unmap_2m(ka_device_t *dev, ka_dma_addr_t base_2m_iova, | 211 | +STATIC void vf_unmap_2m(ka_device_t *dev, ka_dma_addr_t base_2m_iova, struct page_info_list *dma_page_list) |
| 219 | - struct page_info_list *dma_page_list) | ||
| 220 | { | 212 | { |
| 221 | struct page_info_entry *dma_page_info = NULL; | 213 | struct page_info_entry *dma_page_info = NULL; |
| 222 | ka_list_head_t *pos = NULL, *next = NULL; | 214 | ka_list_head_t *pos = NULL, *next = NULL; |
| 223 | ka_dma_addr_t iova = base_2m_iova; | 215 | ka_dma_addr_t iova = base_2m_iova; |
| 224 | 216 | ||
| 225 | - ka_list_for_each_safe(pos, next, &(dma_page_list->head)) { | 217 | + ka_list_for_each_safe(pos, next, &(dma_page_list->head)) |
| 218 | + { | ||
| 226 | dma_page_info = ka_list_entry(pos, struct page_info_entry, list); | 219 | dma_page_info = ka_list_entry(pos, struct page_info_entry, list); |
| 227 | vdavinci_iommu_unmap(dev, iova, dma_page_info->length); | 220 | vdavinci_iommu_unmap(dev, iova, dma_page_info->length); |
| 228 | iova += dma_page_info->length; | 221 | iova += dma_page_info->length; |
| @@ -234,9 +227,7 @@ STATIC void vf_unmap_2m(ka_device_t *dev, ka_dma_addr_t base_2m_iova, | |||
| 234 | * addresses. Then you can use this function to convert the pfn address to the iova | 227 | * addresses. Then you can use this function to convert the pfn address to the iova |
| 235 | * address of the corresponding pcie device. | 228 | * address of the corresponding pcie device. |
| 236 | */ | 229 | */ |
| 237 | -STATIC int vf_map_2m(ka_device_t *dev, | 230 | +STATIC int vf_map_2m(ka_device_t *dev, ka_dma_addr_t base_2m_iova, struct page_info_list *dma_page_list, int prot) |
| 238 | - ka_dma_addr_t base_2m_iova, struct page_info_list *dma_page_list, | ||
| 239 | - int prot) | ||
| 240 | { | 231 | { |
| 241 | struct page_info_entry *dma_page_info = NULL; | 232 | struct page_info_entry *dma_page_info = NULL; |
| 242 | struct page_info_entry *dma_page_info_err = NULL; | 233 | struct page_info_entry *dma_page_info_err = NULL; |
| @@ -248,7 +239,8 @@ STATIC int vf_map_2m(ka_device_t *dev, | |||
| 248 | return -EINVAL; | 239 | return -EINVAL; |
| 249 | } | 240 | } |
| 250 | 241 | ||
| 251 | - ka_list_for_each_safe(pos, next, &(dma_page_list->head)) { | 242 | + ka_list_for_each_safe(pos, next, &(dma_page_list->head)) |
| 243 | + { | ||
| 252 | dma_page_info = ka_list_entry(pos, struct page_info_entry, list); | 244 | dma_page_info = ka_list_entry(pos, struct page_info_entry, list); |
| 253 | 245 | ||
| 254 | phys = ka_mm_page_to_phys(dma_page_info->page); | 246 | phys = ka_mm_page_to_phys(dma_page_info->page); |
| @@ -265,7 +257,8 @@ STATIC int vf_map_2m(ka_device_t *dev, | |||
| 265 | 257 | ||
| 266 | unmap: | 258 | unmap: |
| 267 | iova = base_2m_iova; | 259 | iova = base_2m_iova; |
| 268 | - ka_list_for_each_safe(pos, next, &(dma_page_list->head)) { | 260 | + ka_list_for_each_safe(pos, next, &(dma_page_list->head)) |
| 261 | + { | ||
| 269 | dma_page_info = ka_list_entry(pos, struct page_info_entry, list); | 262 | dma_page_info = ka_list_entry(pos, struct page_info_entry, list); |
| 270 | 263 | ||
| 271 | if (dma_page_info != dma_page_info_err) { | 264 | if (dma_page_info != dma_page_info_err) { |
| @@ -279,8 +272,7 @@ unmap: | |||
| 279 | return -EFAULT; | 272 | return -EFAULT; |
| 280 | } | 273 | } |
| 281 | 274 | ||
| 282 | -void vf_unmap_ram_range(struct hw_vdavinci *vdavinci, | 275 | +void vf_unmap_ram_range(struct hw_vdavinci *vdavinci, struct ram_range_info *ram_info) |
| 283 | - struct ram_range_info *ram_info) | ||
| 284 | { | 276 | { |
| 285 | int j; | 277 | int j; |
| 286 | bool found = false; | 278 | bool found = false; |
| @@ -293,7 +285,8 @@ void vf_unmap_ram_range(struct hw_vdavinci *vdavinci, | |||
| 293 | if (ka_list_empty(&(vdavinci->vdev.dev_dma_info_list_head))) { | 285 | if (ka_list_empty(&(vdavinci->vdev.dev_dma_info_list_head))) { |
| 294 | return; | 286 | return; |
| 295 | } | 287 | } |
| 296 | - ka_list_for_each_safe(pos, next, &(vdavinci->vdev.dev_dma_info_list_head)) { | 288 | + ka_list_for_each_safe(pos, next, &(vdavinci->vdev.dev_dma_info_list_head)) |
| 289 | + { | ||
| 297 | dma_info = ka_list_entry(pos, struct dev_dma_info, list); | 290 | dma_info = ka_list_entry(pos, struct dev_dma_info, list); |
| 298 | if (ram_info != dma_info->ram_info) { | 291 | if (ram_info != dma_info->ram_info) { |
| 299 | continue; | 292 | continue; |
| @@ -302,9 +295,8 @@ void vf_unmap_ram_range(struct hw_vdavinci *vdavinci, | |||
| 302 | for (j = 0; j < ram_info->dma_array_len; j++) { | 295 | for (j = 0; j < ram_info->dma_array_len; j++) { |
| 303 | dev_map_scheduled(vdavinci, &count); | 296 | dev_map_scheduled(vdavinci, &count); |
| 304 | dma_array_node = ram_info->dma_array[j]; | 297 | dma_array_node = ram_info->dma_array[j]; |
| 305 | - vf_unmap_2m(dev, dma_info->base_iova + | 298 | + vf_unmap_2m(dev, dma_info->base_iova + j * KA_VFIO_PIN_PAGES_MAX_ENTRIES * KA_MM_PAGE_SIZE, |
| 306 | - j * KA_VFIO_PIN_PAGES_MAX_ENTRIES * KA_MM_PAGE_SIZE, | 299 | + &(dma_array_node->dma_page_list)); |
| 307 | - &(dma_array_node->dma_page_list)); | ||
| 308 | } | 300 | } |
| 309 | ka_mm_kfree(dma_info); | 301 | ka_mm_kfree(dma_info); |
| 310 | found = true; | 302 | found = true; |
| @@ -315,8 +307,7 @@ void vf_unmap_ram_range(struct hw_vdavinci *vdavinci, | |||
| 315 | ka_base_atomic_dec(&ram_info->map_count); | 307 | ka_base_atomic_dec(&ram_info->map_count); |
| 316 | } | 308 | } |
| 317 | 309 | ||
| 318 | -int vf_map_ram_range(struct hw_vdavinci *vdavinci, | 310 | +int vf_map_ram_range(struct hw_vdavinci *vdavinci, struct ram_range_info *ram_info) |
| 319 | - struct ram_range_info *ram_info) | ||
| 320 | { | 311 | { |
| 321 | unsigned long count = 0; | 312 | unsigned long count = 0; |
| 322 | int i = 0, j = 0, ret = 0; | 313 | int i = 0, j = 0, ret = 0; |
| @@ -336,8 +327,7 @@ int vf_map_ram_range(struct hw_vdavinci *vdavinci, | |||
| 336 | dev_map_scheduled(vdavinci, &count); | 327 | dev_map_scheduled(vdavinci, &count); |
| 337 | dma_array_node = ram_info->dma_array[i]; | 328 | dma_array_node = ram_info->dma_array[i]; |
| 338 | ret = vf_map_2m(dev, base_iova + i * KA_VFIO_PIN_PAGES_MAX_ENTRIES * KA_MM_PAGE_SIZE, | 329 | ret = vf_map_2m(dev, base_iova + i * KA_VFIO_PIN_PAGES_MAX_ENTRIES * KA_MM_PAGE_SIZE, |
| 339 | - &(dma_array_node->dma_page_list), | 330 | + &(dma_array_node->dma_page_list), prot); |
| 340 | - prot); | ||
| 341 | if (ret != 0) { | 331 | if (ret != 0) { |
| 342 | goto out; | 332 | goto out; |
| 343 | } | 333 | } |
| @@ -31,9 +31,9 @@ struct dev_dma_sgt { | |||
| 31 | 31 | ||
| 32 | struct dev_dma_info { | 32 | struct dev_dma_info { |
| 33 | ka_device_t *dev; | 33 | ka_device_t *dev; |
| 34 | - ka_dma_addr_t base_iova; /* for arm */ | 34 | + ka_dma_addr_t base_iova; /* for arm */ |
| 35 | struct ram_range_info *ram_info; | 35 | struct ram_range_info *ram_info; |
| 36 | - struct dev_dma_sgt **sgt_array; /* for x86 */ | 36 | + struct dev_dma_sgt **sgt_array; /* for x86 */ |
| 37 | ka_list_head_t list; | 37 | ka_list_head_t list; |
| 38 | }; | 38 | }; |
| 39 | 39 | ||
| @@ -54,20 +54,16 @@ struct ram_range_info { | |||
| 54 | unsigned long npages; | 54 | unsigned long npages; |
| 55 | unsigned long userspace_addr; | 55 | unsigned long userspace_addr; |
| 56 | int dma_array_len; | 56 | int dma_array_len; |
| 57 | - struct dma_info_2m** dma_array; | 57 | + struct dma_info_2m **dma_array; |
| 58 | ka_list_head_t list; | 58 | ka_list_head_t list; |
| 59 | ka_atomic_t map_count; | 59 | ka_atomic_t map_count; |
| 60 | }; | 60 | }; |
| 61 | 61 | ||
| 62 | -int dev_dma_map_ram_range(struct hw_vdavinci *vdavinci, | 62 | +int dev_dma_map_ram_range(struct hw_vdavinci *vdavinci, struct ram_range_info *ram_info); |
| 63 | - struct ram_range_info *ram_info); | ||
| 64 | 63 | ||
| 65 | -void dev_dma_unmap_ram_range(struct hw_vdavinci *vdavinci, | 64 | +void dev_dma_unmap_ram_range(struct hw_vdavinci *vdavinci, struct ram_range_info *ram_info); |
| 66 | - struct ram_range_info *ram_info); | ||
| 67 | 65 | ||
| 68 | -int vf_map_ram_range(struct hw_vdavinci *vdavinci, | 66 | +int vf_map_ram_range(struct hw_vdavinci *vdavinci, struct ram_range_info *ram_info); |
| 69 | - struct ram_range_info *ram_info); | ||
| 70 | 67 | ||
| 71 | -void vf_unmap_ram_range(struct hw_vdavinci *vdavinci, | 68 | +void vf_unmap_ram_range(struct hw_vdavinci *vdavinci, struct ram_range_info *ram_info); |
| 72 | - struct ram_range_info *ram_info); | ||
| 73 | #endif | 69 | #endif |
| @@ -16,8 +16,7 @@ | |||
| 16 | #include "dvt.h" | 16 | #include "dvt.h" |
| 17 | #include "dvt_sysfs.h" | 17 | #include "dvt_sysfs.h" |
| 18 | 18 | ||
| 19 | -STATIC struct hw_vdavinci_type *get_vdavinci_type(ka_device_t *dev, | 19 | +STATIC struct hw_vdavinci_type *get_vdavinci_type(ka_device_t *dev, const char *name) |
| 20 | - const char *name) | ||
| 21 | { | 20 | { |
| 22 | struct hw_vdavinci_type *type = NULL; | 21 | struct hw_vdavinci_type *type = NULL; |
| 23 | struct vdavinci_priv *priv = NULL; | 22 | struct vdavinci_priv *priv = NULL; |
| @@ -66,11 +65,11 @@ ssize_t description_ops(ka_device_t *dev, const char *name, char *buf) | |||
| 66 | } | 65 | } |
| 67 | 66 | ||
| 68 | return snprintf_s(buf, KA_MM_PAGE_SIZE, KA_MM_PAGE_SIZE - 1, | 67 | return snprintf_s(buf, KA_MM_PAGE_SIZE, KA_MM_PAGE_SIZE - 1, |
| 69 | - "type name: %s\naicore num: %u\nmemory size: %luGB\naicpu num: %u\nvpc num: %u\n"\ | 68 | + "type name: %s\naicore num: %u\nmemory size: %luGB\naicpu num: %u\nvpc num: %u\n" |
| 70 | - "jpegd num: %u\njpege num: %u\nvenc num: %u\nvdec num: %u\nbar2 size: %uKB\nbar4 size: %luKB\n", | 69 | + "jpegd num: %u\njpege num: %u\nvenc num: %u\nvdec num: %u\nbar2 size: %uKB\nbar4 size: %luKB\n", |
| 71 | - type->template_name, type->aicore_num, type->mem_size, type->aicpu_num, type->vpc_num, | 70 | + type->template_name, type->aicore_num, type->mem_size, type->aicpu_num, type->vpc_num, |
| 72 | - type->jpegd_num, type->jpege_num, type->venc_num, type->vdec_num, | 71 | + type->jpegd_num, type->jpege_num, type->venc_num, type->vdec_num, BYTES_TO_KB(type->bar2_size), |
| 73 | - BYTES_TO_KB(type->bar2_size), BYTES_TO_KB(type->bar4_size)); | 72 | + BYTES_TO_KB(type->bar4_size)); |
| 74 | } | 73 | } |
| 75 | 74 | ||
| 76 | ssize_t device_api_ops(ka_device_t *dev, char *buf) | 75 | ssize_t device_api_ops(ka_device_t *dev, char *buf) |
| @@ -80,13 +79,11 @@ ssize_t device_api_ops(ka_device_t *dev, char *buf) | |||
| 80 | if (buf == NULL) { | 79 | if (buf == NULL) { |
| 81 | return 0; | 80 | return 0; |
| 82 | } | 81 | } |
| 83 | - ret = snprintf_s(buf, KA_MM_PAGE_SIZE, KA_MM_PAGE_SIZE - 1, "%s\n", | 82 | + ret = snprintf_s(buf, KA_MM_PAGE_SIZE, KA_MM_PAGE_SIZE - 1, "%s\n", KA_VFIO_DEVICE_API_PCI_STRING); |
| 84 | - KA_VFIO_DEVICE_API_PCI_STRING); | ||
| 85 | return ret == -1 ? 0 : ret; | 83 | return ret == -1 ? 0 : ret; |
| 86 | } | 84 | } |
| 87 | 85 | ||
| 88 | -ssize_t vfg_id_store_ops(ka_device_t *dev, const char *name, | 86 | +ssize_t vfg_id_store_ops(ka_device_t *dev, const char *name, const char *buf, size_t count) |
| 89 | - const char *buf, size_t count) | ||
| 90 | { | 87 | { |
| 91 | unsigned int vfg_id; | 88 | unsigned int vfg_id; |
| 92 | struct hw_vdavinci_type *type = NULL; | 89 | struct hw_vdavinci_type *type = NULL; |
| @@ -109,8 +106,7 @@ ssize_t vfg_id_store_ops(ka_device_t *dev, const char *name, | |||
| 109 | return count; | 106 | return count; |
| 110 | } | 107 | } |
| 111 | 108 | ||
| 112 | -STATIC ssize_t | 109 | +STATIC ssize_t vdavinci_id_show(ka_device_t *dev, ka_device_attribute_t *attr, char *buf) |
| 113 | -vdavinci_id_show(ka_device_t *dev, ka_device_attribute_t *attr, char *buf) | ||
| 114 | { | 110 | { |
| 115 | struct hw_vdavinci *vdavinci = get_vdavinci_from_dev(dev); | 111 | struct hw_vdavinci *vdavinci = get_vdavinci_from_dev(dev); |
| 116 | int ret; | 112 | int ret; |
| @@ -123,8 +119,7 @@ vdavinci_id_show(ka_device_t *dev, ka_device_attribute_t *attr, char *buf) | |||
| 123 | return ret == -1 ? 0 : ret; | 119 | return ret == -1 ? 0 : ret; |
| 124 | } | 120 | } |
| 125 | 121 | ||
| 126 | -STATIC ssize_t | 122 | +STATIC ssize_t hw_id_show(ka_device_t *dev, ka_device_attribute_t *attr, char *buf) |
| 127 | -hw_id_show(ka_device_t *dev, ka_device_attribute_t *attr, char *buf) | ||
| 128 | { | 123 | { |
| 129 | struct hw_vdavinci *vdavinci = get_vdavinci_from_dev(dev); | 124 | struct hw_vdavinci *vdavinci = get_vdavinci_from_dev(dev); |
| 130 | int ret; | 125 | int ret; |
| @@ -132,15 +127,13 @@ hw_id_show(ka_device_t *dev, ka_device_attribute_t *attr, char *buf) | |||
| 132 | if (vdavinci == NULL) { | 127 | if (vdavinci == NULL) { |
| 133 | return 0; | 128 | return 0; |
| 134 | } | 129 | } |
| 135 | - ret = snprintf_s(buf, KA_MM_PAGE_SIZE, KA_MM_PAGE_SIZE - 1, | 130 | + ret = snprintf_s(buf, KA_MM_PAGE_SIZE, KA_MM_PAGE_SIZE - 1, "Device [%x:%x]\n", vdavinci->dvt->vendor, |
| 136 | - "Device [%x:%x]\n", vdavinci->dvt->vendor, | ||
| 137 | vdavinci->dvt->device); | 131 | vdavinci->dvt->device); |
| 138 | 132 | ||
| 139 | return ret == -1 ? 0 : ret; | 133 | return ret == -1 ? 0 : ret; |
| 140 | } | 134 | } |
| 141 | 135 | ||
| 142 | -STATIC ssize_t | 136 | +STATIC ssize_t vfg_id_show(ka_device_t *dev, ka_device_attribute_t *attr, char *buf) |
| 143 | -vfg_id_show(ka_device_t *dev, ka_device_attribute_t *attr, char *buf) | ||
| 144 | { | 137 | { |
| 145 | struct hw_vdavinci *vdavinci = get_vdavinci_from_dev(dev); | 138 | struct hw_vdavinci *vdavinci = get_vdavinci_from_dev(dev); |
| 146 | int ret; | 139 | int ret; |
| @@ -153,8 +146,7 @@ vfg_id_show(ka_device_t *dev, ka_device_attribute_t *attr, char *buf) | |||
| 153 | return ret == -1 ? 0 : ret; | 146 | return ret == -1 ? 0 : ret; |
| 154 | } | 147 | } |
| 155 | 148 | ||
| 156 | -STATIC ssize_t | 149 | +STATIC ssize_t vf_show(ka_device_t *dev, ka_device_attribute_t *attr, char *buf) |
| 157 | -vf_show(ka_device_t *dev, ka_device_attribute_t *attr, char *buf) | ||
| 158 | { | 150 | { |
| 159 | struct hw_vdavinci *vdavinci = get_vdavinci_from_dev(dev); | 151 | struct hw_vdavinci *vdavinci = get_vdavinci_from_dev(dev); |
| 160 | ka_pci_dev_t *pdev = NULL; | 152 | ka_pci_dev_t *pdev = NULL; |
| @@ -167,11 +159,14 @@ vf_show(ka_device_t *dev, ka_device_attribute_t *attr, char *buf) | |||
| 167 | dvt = vdavinci->dvt; | 159 | dvt = vdavinci->dvt; |
| 168 | if (dvt->is_sriov_enabled && dvt->sriov.vf_num > 0) { | 160 | if (dvt->is_sriov_enabled && dvt->sriov.vf_num > 0) { |
| 169 | pdev = vdavinci->vf.pdev; | 161 | pdev = vdavinci->vf.pdev; |
| 170 | - ret = snprintf_s(buf, KA_MM_PAGE_SIZE, KA_MM_PAGE_SIZE - 1, | 162 | + if (pdev == NULL) { |
| 171 | - "%02x:%02x.%u\n", pdev->bus->number, KA_PCI_SLOT(pdev->devfn), | 163 | + goto out; |
| 172 | - KA_PCI_FUNC(pdev->devfn)); | 164 | + } |
| 165 | + ret = snprintf_s(buf, KA_MM_PAGE_SIZE, KA_MM_PAGE_SIZE - 1, "%02x:%02x.%u\n", pdev->bus->number, | ||
| 166 | + KA_PCI_SLOT(pdev->devfn), KA_PCI_FUNC(pdev->devfn)); | ||
| 173 | return ret == -1 ? 0 : ret; | 167 | return ret == -1 ? 0 : ret; |
| 174 | } | 168 | } |
| 169 | +out: | ||
| 175 | ret = snprintf_s(buf, KA_MM_PAGE_SIZE, KA_MM_PAGE_SIZE - 1, "\n"); | 170 | ret = snprintf_s(buf, KA_MM_PAGE_SIZE, KA_MM_PAGE_SIZE - 1, "\n"); |
| 176 | return ret == -1 ? 0 : ret; | 171 | return ret == -1 ? 0 : ret; |
| 177 | } | 172 | } |
| @@ -180,13 +175,8 @@ static KA_DEVICE_ATTR_RO(vdavinci_id); | |||
| 180 | static KA_DEVICE_ATTR_RO(hw_id); | 175 | static KA_DEVICE_ATTR_RO(hw_id); |
| 181 | static KA_DEVICE_ATTR_RO(vf); | 176 | static KA_DEVICE_ATTR_RO(vf); |
| 182 | 177 | ||
| 183 | -static ka_attribute_t *hw_vdavinci_attrs[] = { | 178 | +static ka_attribute_t *hw_vdavinci_attrs[] = {&dev_attr_vdavinci_id.attr, &dev_attr_hw_id.attr, &dev_attr_vfg_id.attr, |
| 184 | - &dev_attr_vdavinci_id.attr, | 179 | + &dev_attr_vf.attr, NULL}; |
| 185 | - &dev_attr_hw_id.attr, | ||
| 186 | - &dev_attr_vfg_id.attr, | ||
| 187 | - &dev_attr_vf.attr, | ||
| 188 | - NULL | ||
| 189 | -}; | ||
| 190 | 180 | ||
| 191 | static ka_attribute_group_t hw_vdavinci_group = { | 181 | static ka_attribute_group_t hw_vdavinci_group = { |
| 192 | .name = "hw_vdavinci", | 182 | .name = "hw_vdavinci", |
| @@ -18,6 +18,5 @@ const ka_attribute_group_t **get_hw_vdavinci_groups(void); | |||
| 18 | ssize_t available_instances_ops(ka_device_t *dev, const char *name, char *buf); | 18 | ssize_t available_instances_ops(ka_device_t *dev, const char *name, char *buf); |
| 19 | ssize_t description_ops(ka_device_t *dev, const char *name, char *buf); | 19 | ssize_t description_ops(ka_device_t *dev, const char *name, char *buf); |
| 20 | ssize_t device_api_ops(ka_device_t *dev, char *buf); | 20 | ssize_t device_api_ops(ka_device_t *dev, char *buf); |
| 21 | -ssize_t vfg_id_store_ops(ka_device_t *dev, const char *name, | 21 | +ssize_t vfg_id_store_ops(ka_device_t *dev, const char *name, const char *buf, size_t count); |
| 22 | - const char *buf, size_t count); | ||
| 23 | #endif | 22 | #endif |
| @@ -18,34 +18,34 @@ | |||
| 18 | #include "ka_kvm_pub.h" | 18 | #include "ka_kvm_pub.h" |
| 19 | #include "ka_memory_pub.h" | 19 | #include "ka_memory_pub.h" |
| 20 | 20 | ||
| 21 | -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0)) | 21 | +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0)) |
| 22 | -#define IS_VDAVINCI_KERNEL_VERSION_SUPPORT 1 | 22 | +#define IS_VDAVINCI_KERNEL_VERSION_SUPPORT 1 |
| 23 | #else | 23 | #else |
| 24 | -#define IS_VDAVINCI_KERNEL_VERSION_SUPPORT 0 | 24 | +#define IS_VDAVINCI_KERNEL_VERSION_SUPPORT 0 |
| 25 | #endif | 25 | #endif |
| 26 | 26 | ||
| 27 | -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,0)) | 27 | +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0)) |
| 28 | -#define IS_VDAVINCI_IODEV_SUPPORT 1 | 28 | +#define IS_VDAVINCI_IODEV_SUPPORT 1 |
| 29 | #else | 29 | #else |
| 30 | -#define IS_VDAVINCI_IODEV_SUPPORT 0 | 30 | +#define IS_VDAVINCI_IODEV_SUPPORT 0 |
| 31 | #endif | 31 | #endif |
| 32 | 32 | ||
| 33 | #ifdef VM_ALLOW_ANY_UNCACHED | 33 | #ifdef VM_ALLOW_ANY_UNCACHED |
| 34 | -#define IS_VDAVINCI_NORMAL_NC_SUPPORT 1 | 34 | +#define IS_VDAVINCI_NORMAL_NC_SUPPORT 1 |
| 35 | #else | 35 | #else |
| 36 | -#define IS_VDAVINCI_NORMAL_NC_SUPPORT 0 | 36 | +#define IS_VDAVINCI_NORMAL_NC_SUPPORT 0 |
| 37 | #endif | 37 | #endif |
| 38 | 38 | ||
| 39 | -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,10,0)) && defined(CONFIG_KEXEC_KERNEL_HOTUPGRADE) | 39 | +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) && defined(CONFIG_KEXEC_KERNEL_HOTUPGRADE) |
| 40 | -#define IS_VDAVINCI_VPMEM_SUPPORT 1 | 40 | +#define IS_VDAVINCI_VPMEM_SUPPORT 1 |
| 41 | #else | 41 | #else |
| 42 | -#define IS_VDAVINCI_VPMEM_SUPPORT 0 | 42 | +#define IS_VDAVINCI_VPMEM_SUPPORT 0 |
| 43 | #endif | 43 | #endif |
| 44 | 44 | ||
| 45 | -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,10,0)) | 45 | +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) |
| 46 | -#define IS_VDAVINCI_PIN_HVA_SUPPORT 1 | 46 | +#define IS_VDAVINCI_PIN_HVA_SUPPORT 1 |
| 47 | #else | 47 | #else |
| 48 | -#define IS_VDAVINCI_PIN_HVA_SUPPORT 0 | 48 | +#define IS_VDAVINCI_PIN_HVA_SUPPORT 0 |
| 49 | #endif | 49 | #endif |
| 50 | 50 | ||
| 51 | #define RESERVE_SIZE 40 | 51 | #define RESERVE_SIZE 40 |
| @@ -158,7 +158,7 @@ enum HW_VDAVINCI_TYPE_950_BIN0 { | |||
| 158 | TYPE_VIR04_1C_15G_BIN0, | 158 | TYPE_VIR04_1C_15G_BIN0, |
| 159 | TYPE_MAX_950_BIN0 | 159 | TYPE_MAX_950_BIN0 |
| 160 | }; | 160 | }; |
| 161 | - | 161 | + |
| 162 | /* 32core, 128G */ | 162 | /* 32core, 128G */ |
| 163 | enum HW_VDAVINCI_TYPE_950_BIN1 { | 163 | enum HW_VDAVINCI_TYPE_950_BIN1 { |
| 164 | TYPE_VIR16_7C_60G_BIN1, | 164 | TYPE_VIR16_7C_60G_BIN1, |
| @@ -166,14 +166,14 @@ enum HW_VDAVINCI_TYPE_950_BIN1 { | |||
| 166 | TYPE_VIR04_1C_15G_BIN1, | 166 | TYPE_VIR04_1C_15G_BIN1, |
| 167 | TYPE_MAX_950_BIN1 | 167 | TYPE_MAX_950_BIN1 |
| 168 | }; | 168 | }; |
| 169 | - | 169 | + |
| 170 | /* 28core, 128G */ | 170 | /* 28core, 128G */ |
| 171 | enum HW_VDAVINCI_TYPE_950_BIN2 { | 171 | enum HW_VDAVINCI_TYPE_950_BIN2 { |
| 172 | TYPE_VIR14_5C_60G_BIN2, | 172 | TYPE_VIR14_5C_60G_BIN2, |
| 173 | TYPE_VIR07_2C_30G_BIN2, | 173 | TYPE_VIR07_2C_30G_BIN2, |
| 174 | TYPE_MAX_950_BIN2 | 174 | TYPE_MAX_950_BIN2 |
| 175 | }; | 175 | }; |
| 176 | - | 176 | + |
| 177 | /* 28core, 112G */ | 177 | /* 28core, 112G */ |
| 178 | enum HW_VDAVINCI_TYPE_950_BIN3 { | 178 | enum HW_VDAVINCI_TYPE_950_BIN3 { |
| 179 | TYPE_VIR14_5C_52G_BIN3, | 179 | TYPE_VIR14_5C_52G_BIN3, |
| @@ -199,7 +199,7 @@ struct vdavinci_type { | |||
| 199 | int type; | 199 | int type; |
| 200 | unsigned int bar0_size; | 200 | unsigned int bar0_size; |
| 201 | unsigned int bar2_size; | 201 | unsigned int bar2_size; |
| 202 | - unsigned long bar4_size; /* if non-zero, use this value first */ | 202 | + unsigned long bar4_size; /* if non-zero, use this value first */ |
| 203 | unsigned int aicore_num; | 203 | unsigned int aicore_num; |
| 204 | unsigned long mem_size; | 204 | unsigned long mem_size; |
| 205 | unsigned int aicpu_num; | 205 | unsigned int aicpu_num; |
| @@ -208,7 +208,7 @@ struct vdavinci_type { | |||
| 208 | unsigned int jpege_num; | 208 | unsigned int jpege_num; |
| 209 | unsigned int venc_num; | 209 | unsigned int venc_num; |
| 210 | unsigned int vdec_num; | 210 | unsigned int vdec_num; |
| 211 | - unsigned int share; /* the minimum value is 1 */ | 211 | + unsigned int share; /* the minimum value is 1 */ |
| 212 | unsigned long ddrmem_size; | 212 | unsigned long ddrmem_size; |
| 213 | unsigned long hbmmem_size; | 213 | unsigned long hbmmem_size; |
| 214 | }; | 214 | }; |
| @@ -236,8 +236,8 @@ struct vdavinci_bar_map { | |||
| 236 | size_t offset; | 236 | size_t offset; |
| 237 | enum HW_MAP_TYPE map_type; | 237 | enum HW_MAP_TYPE map_type; |
| 238 | union { | 238 | union { |
| 239 | - u64 paddr; /* vaild when map_type is MAP_TYPE_PASSTHROUGH */ | 239 | + u64 paddr; /* vaild when map_type is MAP_TYPE_PASSTHROUGH */ |
| 240 | - void *vaddr; /* vaild when map_type is MAP_TYPE_BACKEND */ | 240 | + void *vaddr; /* vaild when map_type is MAP_TYPE_BACKEND */ |
| 241 | }; | 241 | }; |
| 242 | size_t size; | 242 | size_t size; |
| 243 | }; | 243 | }; |
| @@ -259,20 +259,17 @@ struct vdavinci_dev { | |||
| 259 | * dev_index value [0, 1 ...] | 259 | * dev_index value [0, 1 ...] |
| 260 | */ | 260 | */ |
| 261 | struct vdavinci_priv_ops { | 261 | struct vdavinci_priv_ops { |
| 262 | - int (*vdavinci_create)(struct vdavinci_dev *dev, void *vdavinci, | 262 | + int (*vdavinci_create)(struct vdavinci_dev *dev, void *vdavinci, struct vdavinci_type *type, ka_uuid_le_t uuid); |
| 263 | - struct vdavinci_type *type, ka_uuid_le_t uuid); | ||
| 264 | void (*vdavinci_destroy)(struct vdavinci_dev *dev); | 263 | void (*vdavinci_destroy)(struct vdavinci_dev *dev); |
| 265 | void (*vdavinci_release)(struct vdavinci_dev *dev); | 264 | void (*vdavinci_release)(struct vdavinci_dev *dev); |
| 266 | int (*vdavinci_reset)(struct vdavinci_dev *dev); | 265 | int (*vdavinci_reset)(struct vdavinci_dev *dev); |
| 267 | int (*vdavinci_flr)(struct vdavinci_dev *dev); | 266 | int (*vdavinci_flr)(struct vdavinci_dev *dev); |
| 268 | void (*vdavinci_notify)(struct vdavinci_dev *dev, int db_index); | 267 | void (*vdavinci_notify)(struct vdavinci_dev *dev, int db_index); |
| 269 | - int (*vdavinci_getmapinfo)(struct vdavinci_dev *dev, | 268 | + int (*vdavinci_getmapinfo)(struct vdavinci_dev *dev, struct vdavinci_type *type, u32 bar_id, |
| 270 | - struct vdavinci_type *type, u32 bar_id, | ||
| 271 | struct vdavinci_mapinfo *mapinfo); | 269 | struct vdavinci_mapinfo *mapinfo); |
| 272 | int (*vdavinci_putmapinfo)(struct vdavinci_dev *dev); | 270 | int (*vdavinci_putmapinfo)(struct vdavinci_dev *dev); |
| 273 | int (*davinci_getdevnum)(ka_device_t *dev); | 271 | int (*davinci_getdevnum)(ka_device_t *dev); |
| 274 | - int (*davinci_getdevinfo)(ka_device_t *dev, u32 dev_index, | 272 | + int (*davinci_getdevinfo)(ka_device_t *dev, u32 dev_index, struct dvt_devinfo *dev_info); |
| 275 | - struct dvt_devinfo* dev_info); | ||
| 276 | int (*vascend_enable_sriov)(ka_pci_dev_t *pdev, int numvfs); | 273 | int (*vascend_enable_sriov)(ka_pci_dev_t *pdev, int numvfs); |
| 277 | }; | 274 | }; |
| 278 | 275 | ||
| @@ -304,8 +301,7 @@ int hw_dvt_hypervisor_inject_msix(void *__vdavinci, u32 vector, int irq); | |||
| 304 | * Returns: | 301 | * Returns: |
| 305 | * Zero on success, negative error code if failed. | 302 | * Zero on success, negative error code if failed. |
| 306 | */ | 303 | */ |
| 307 | -int hw_dvt_hypervisor_read_gpa(void *__vdavinci, unsigned long gpa, | 304 | +int hw_dvt_hypervisor_read_gpa(void *__vdavinci, unsigned long gpa, void *buf, unsigned long len); |
| 308 | - void *buf, unsigned long len); | ||
| 309 | 305 | ||
| 310 | /** | 306 | /** |
| 311 | * hw_dvt_hypervisor_write_gpa - copy data from host data buffer to GPA | 307 | * hw_dvt_hypervisor_write_gpa - copy data from host data buffer to GPA |
| @@ -317,8 +313,7 @@ int hw_dvt_hypervisor_read_gpa(void *__vdavinci, unsigned long gpa, | |||
| 317 | * Returns: | 313 | * Returns: |
| 318 | * Zero on success, negative error code if failed. | 314 | * Zero on success, negative error code if failed. |
| 319 | */ | 315 | */ |
| 320 | -int hw_dvt_hypervisor_write_gpa(void *__vdavinci, unsigned long gpa, | 316 | +int hw_dvt_hypervisor_write_gpa(void *__vdavinci, unsigned long gpa, void *buf, unsigned long len); |
| 321 | - void *buf, unsigned long len); | ||
| 322 | 317 | ||
| 323 | /** | 318 | /** |
| 324 | * hw_dvt_hypervisor_gfn_to_mfn - translate a GFN to MFN | 319 | * hw_dvt_hypervisor_gfn_to_mfn - translate a GFN to MFN |
| @@ -328,8 +323,7 @@ int hw_dvt_hypervisor_write_gpa(void *__vdavinci, unsigned long gpa, | |||
| 328 | * Returns: | 323 | * Returns: |
| 329 | * MFN on success, hw_dvt_INVALID_ADDR if failed. | 324 | * MFN on success, hw_dvt_INVALID_ADDR if failed. |
| 330 | */ | 325 | */ |
| 331 | -unsigned long hw_dvt_hypervisor_gfn_to_mfn(void *__vdavinci, | 326 | +unsigned long hw_dvt_hypervisor_gfn_to_mfn(void *__vdavinci, unsigned long gfn); |
| 332 | - unsigned long gfn); | ||
| 333 | 327 | ||
| 334 | /** | 328 | /** |
| 335 | * hw_dvt_hypervisor_dma_pool_init - dma pool init | 329 | * hw_dvt_hypervisor_dma_pool_init - dma pool init |
| @@ -356,8 +350,7 @@ void hw_dvt_hypervisor_dma_pool_uninit(void *__vdavinci); | |||
| 356 | * Returns: | 350 | * Returns: |
| 357 | * 0 on success, negative error code if failed. | 351 | * 0 on success, negative error code if failed. |
| 358 | */ | 352 | */ |
| 359 | -int hw_dvt_hypervisor_dma_map_guest_page(void *__vdavinci, unsigned long gfn, | 353 | +int hw_dvt_hypervisor_dma_map_guest_page(void *__vdavinci, unsigned long gfn, unsigned long size, |
| 360 | - unsigned long size, | ||
| 361 | ka_sg_table_t **dma_sgt); | 354 | ka_sg_table_t **dma_sgt); |
| 362 | 355 | ||
| 363 | /** | 356 | /** |
| @@ -365,8 +358,7 @@ int hw_dvt_hypervisor_dma_map_guest_page(void *__vdavinci, unsigned long gfn, | |||
| 365 | * @vdavinci: a vdavinci | 358 | * @vdavinci: a vdavinci |
| 366 | * @dma_sgt: the dma addr list(sg_table) | 359 | * @dma_sgt: the dma addr list(sg_table) |
| 367 | */ | 360 | */ |
| 368 | -void hw_dvt_hypervisor_dma_unmap_guest_page(void *__vdavinci, | 361 | +void hw_dvt_hypervisor_dma_unmap_guest_page(void *__vdavinci, ka_sg_table_t *dma_sgt); |
| 369 | - ka_sg_table_t *dma_sgt); | ||
| 370 | 362 | ||
| 371 | /** | 363 | /** |
| 372 | * hw_dvt_hypervisor_dma_pool_active - dma pool active or not | 364 | * hw_dvt_hypervisor_dma_pool_active - dma pool active or not |
| @@ -388,9 +380,7 @@ bool hw_dvt_hypervisor_dma_pool_active(void *__vdavinci); | |||
| 388 | * Returns: | 380 | * Returns: |
| 389 | * 0 on success, negative error code if failed. | 381 | * 0 on success, negative error code if failed. |
| 390 | */ | 382 | */ |
| 391 | -int hw_dvt_hypervisor_dma_map_guest_page_batch(void *__vdavinci, | 383 | +int hw_dvt_hypervisor_dma_map_guest_page_batch(void *__vdavinci, unsigned long *gfn, unsigned long *dma_addr, |
| 392 | - unsigned long *gfn, | ||
| 393 | - unsigned long *dma_addr, | ||
| 394 | unsigned long count); | 384 | unsigned long count); |
| 395 | 385 | ||
| 396 | /** | 386 | /** |
| @@ -401,9 +391,7 @@ int hw_dvt_hypervisor_dma_map_guest_page_batch(void *__vdavinci, | |||
| 401 | * @dma_addr: retrieve dma addr array | 391 | * @dma_addr: retrieve dma addr array |
| 402 | * @count: array size | 392 | * @count: array size |
| 403 | */ | 393 | */ |
| 404 | -void hw_dvt_hypervisor_dma_unmap_guest_page_batch(void *__vdavinci, | 394 | +void hw_dvt_hypervisor_dma_unmap_guest_page_batch(void *__vdavinci, unsigned long *gfn, unsigned long *dma_addr, |
| 405 | - unsigned long *gfn, | ||
| 406 | - unsigned long *dma_addr, | ||
| 407 | unsigned long count); | 395 | unsigned long count); |
| 408 | /** | 396 | /** |
| 409 | * hw_dvt_hypervisor_is_valid_gfn - check if a visible gfn | 397 | * hw_dvt_hypervisor_is_valid_gfn - check if a visible gfn |
| @@ -428,21 +416,14 @@ bool hw_dvt_hypervisor_is_valid_gfn(void *__vdavinci, unsigned long gfn); | |||
| 428 | 416 | ||
| 429 | int hw_dvt_hypervisor_mmio_get(void **dst, int *size, void *__vdavinci, int bar); | 417 | int hw_dvt_hypervisor_mmio_get(void **dst, int *size, void *__vdavinci, int bar); |
| 430 | 418 | ||
| 431 | -bool hw_dvt_hypervisor_is_vm_pfn_valid(ka_device_t *dev, | 419 | +bool hw_dvt_hypervisor_is_vm_pfn_valid(ka_device_t *dev, unsigned long pfn, unsigned long size); |
| 432 | - unsigned long pfn, unsigned long size); | ||
| 433 | 420 | ||
| 434 | - | 421 | +void *vdavinci_dma_alloc_coherent(ka_device_t *dev, size_t size, ka_dma_addr_t *dma_handle, ka_gfp_t flags); |
| 435 | -void *vdavinci_dma_alloc_coherent(ka_device_t *dev, size_t size, | 422 | +void vdavinci_dma_free_coherent(ka_device_t *dev, size_t size, void *vaddr, ka_dma_addr_t dma_handle); |
| 436 | - ka_dma_addr_t *dma_handle, ka_gfp_t flags); | 423 | +ka_dma_addr_t vdavinci_dma_map_single(ka_device_t *dev, void *ptr, size_t size, ka_dma_data_direction_t dir); |
| 437 | -void vdavinci_dma_free_coherent(ka_device_t *dev, size_t size, | 424 | +ka_dma_addr_t vdavinci_dma_map_page(ka_device_t *dev, ka_page_t *page, size_t offset, size_t size, |
| 438 | - void *vaddr, ka_dma_addr_t dma_handle); | 425 | + ka_dma_data_direction_t dir); |
| 439 | -ka_dma_addr_t vdavinci_dma_map_single(ka_device_t *dev, void *ptr, size_t size, | 426 | +void vdavinci_dma_unmap_single(ka_device_t *dev, ka_dma_addr_t addr, size_t size, ka_dma_data_direction_t dir); |
| 440 | - ka_dma_data_direction_t dir); | 427 | +void vdavinci_dma_unmap_page(ka_device_t *dev, ka_dma_addr_t addr, size_t size, ka_dma_data_direction_t dir); |
| 441 | -ka_dma_addr_t vdavinci_dma_map_page(ka_device_t *dev, ka_page_t *page, size_t offset, | ||
| 442 | - size_t size, ka_dma_data_direction_t dir); | ||
| 443 | -void vdavinci_dma_unmap_single(ka_device_t *dev, ka_dma_addr_t addr, size_t size, | ||
| 444 | - ka_dma_data_direction_t dir); | ||
| 445 | -void vdavinci_dma_unmap_page(ka_device_t *dev, ka_dma_addr_t addr, size_t size, | ||
| 446 | - ka_dma_data_direction_t dir); | ||
| 447 | 428 | ||
| 448 | #endif /* HW_VDAVINCI_H_ */ | 429 | #endif /* HW_VDAVINCI_H_ */ |
| @@ -18,23 +18,26 @@ | |||
| 18 | 18 | ||
| 19 | #define module_devdrv "vascend" | 19 | #define module_devdrv "vascend" |
| 20 | #ifdef DAVINCI_DEBUG | 20 | #ifdef DAVINCI_DEBUG |
| 21 | -#define vascend_err(dev, fmt, ...) ka_dev_err(dev, "[%s] [CPU %d] [%s/%d/%d] [%s %d] " \ | 21 | +#define vascend_err(dev, fmt, ...) \ |
| 22 | - fmt, module_devdrv, ka_system_smp_processor_id(), ka_task_get_current()->comm, ka_task_get_current()->tgid, ka_task_get_current()->pid, \ | 22 | + ka_dev_err(dev, "[%s] [CPU %d] [%s/%d/%d] [%s %d] " fmt, module_devdrv, ka_system_smp_processor_id(), \ |
| 23 | - __func__, __LINE__, ##__VA_ARGS__) | 23 | + ka_task_get_current()->comm, ka_task_get_current()->tgid, ka_task_get_current()->pid, __func__, \ |
| 24 | -#define vascend_warn(dev, fmt, ...) ka_dev_warn(dev, "[%s] [CPU %d] [%s/%d/%d] [%s %d] " \ | 24 | + __LINE__, ##__VA_ARGS__) |
| 25 | - fmt, module_devdrv, ka_system_smp_processor_id(), ka_task_get_current()->comm, ka_task_get_current()->tgid, ka_task_get_current()->pid, \ | 25 | +#define vascend_warn(dev, fmt, ...) \ |
| 26 | - __func__, __LINE__, ##__VA_ARGS__) | 26 | + ka_dev_warn(dev, "[%s] [CPU %d] [%s/%d/%d] [%s %d] " fmt, module_devdrv, ka_system_smp_processor_id(), \ |
| 27 | -#define vascend_info(dev, fmt, ...) ka_dev_info(dev, "[%s] [CPU %d] [%s/%d/%d] [%s %d] " \ | 27 | + ka_task_get_current()->comm, ka_task_get_current()->tgid, ka_task_get_current()->pid, __func__, \ |
| 28 | - fmt, module_devdrv, ka_system_smp_processor_id(), ka_task_get_current()->comm, ka_task_get_current()->tgid, ka_task_get_current()->pid, \ | 28 | + __LINE__, ##__VA_ARGS__) |
| 29 | - __func__, __LINE__, ##__VA_ARGS__) | 29 | +#define vascend_info(dev, fmt, ...) \ |
| 30 | + ka_dev_info(dev, "[%s] [CPU %d] [%s/%d/%d] [%s %d] " fmt, module_devdrv, ka_system_smp_processor_id(), \ | ||
| 31 | + ka_task_get_current()->comm, ka_task_get_current()->tgid, ka_task_get_current()->pid, __func__, \ | ||
| 32 | + __LINE__, ##__VA_ARGS__) | ||
| 30 | #define vascend_debug(fmt, ...) pr_info("[%s]" fmt, __func__, ##__VA_ARGS__) | 33 | #define vascend_debug(fmt, ...) pr_info("[%s]" fmt, __func__, ##__VA_ARGS__) |
| 31 | #else | 34 | #else |
| 32 | -#define vascend_err(dev, fmt, ...) ka_dev_err(dev, "[%s] [%s %d] " \ | 35 | +#define vascend_err(dev, fmt, ...) \ |
| 33 | - fmt, module_devdrv, __func__, __LINE__, ##__VA_ARGS__) | 36 | + ka_dev_err(dev, "[%s] [%s %d] " fmt, module_devdrv, __func__, __LINE__, ##__VA_ARGS__) |
| 34 | -#define vascend_warn(dev, fmt, ...) ka_dev_warn(dev, "[%s] [%s %d] " \ | 37 | +#define vascend_warn(dev, fmt, ...) \ |
| 35 | - fmt, module_devdrv, __func__, __LINE__, ##__VA_ARGS__) | 38 | + ka_dev_warn(dev, "[%s] [%s %d] " fmt, module_devdrv, __func__, __LINE__, ##__VA_ARGS__) |
| 36 | -#define vascend_info(dev, fmt, ...) ka_dev_info(dev, "[%s] [%s %d] " \ | 39 | +#define vascend_info(dev, fmt, ...) \ |
| 37 | - fmt, module_devdrv, __func__, __LINE__, ##__VA_ARGS__) | 40 | + ka_dev_info(dev, "[%s] [%s %d] " fmt, module_devdrv, __func__, __LINE__, ##__VA_ARGS__) |
| 38 | #define vascend_debug(fmt, ...) | 41 | #define vascend_debug(fmt, ...) |
| 39 | #endif /* DAVINCI_DEBUG */ | 42 | #endif /* DAVINCI_DEBUG */ |
| 40 | 43 | ||
| @@ -18,11 +18,10 @@ | |||
| 18 | struct hw_dvt; | 18 | struct hw_dvt; |
| 19 | struct hw_vdavinci; | 19 | struct hw_vdavinci; |
| 20 | 20 | ||
| 21 | -#define DOORBELL_MAX 1024 | 21 | +#define DOORBELL_MAX 1024 |
| 22 | -#define DOORBELL_SIZE 4 | 22 | +#define DOORBELL_SIZE 4 |
| 23 | 23 | ||
| 24 | -typedef int (*dvt_mmio_func)(struct hw_vdavinci *, unsigned int, | 24 | +typedef int (*dvt_mmio_func)(struct hw_vdavinci *, unsigned int, void *, unsigned int); |
| 25 | - void *, unsigned int); | ||
| 26 | 25 | ||
| 27 | enum MMIO_INFO_TYPE { | 26 | enum MMIO_INFO_TYPE { |
| 28 | DOORBELL = 0, | 27 | DOORBELL = 0, |
| @@ -64,13 +63,9 @@ void hw_vdavinci_950_vf_mmio_uninit(struct hw_vdavinci *vdavinci); | |||
| 64 | 63 | ||
| 65 | int hw_dvt_set_mmio_device_info(struct hw_dvt *dvt); | 64 | int hw_dvt_set_mmio_device_info(struct hw_dvt *dvt); |
| 66 | 65 | ||
| 67 | -int hw_vdavinci_emulate_mmio_read(struct hw_vdavinci *vdavinci, | 66 | +int hw_vdavinci_emulate_mmio_read(struct hw_vdavinci *vdavinci, uint64_t pa, void *buf, unsigned int bytes); |
| 68 | - uint64_t pa, void *buf, unsigned int bytes); | 67 | +int hw_vdavinci_emulate_mmio_write(struct hw_vdavinci *vdavinci, uint64_t pa, void *buf, unsigned int bytes); |
| 69 | -int hw_vdavinci_emulate_mmio_write(struct hw_vdavinci *vdavinci, | 68 | +int hw_vdavinci_emulate_mmio_quirk_read(struct hw_vdavinci *vdavinci, uint64_t pa, void *buf, unsigned int bytes); |
| 70 | - uint64_t pa, void *buf, unsigned int bytes); | 69 | +int hw_vdavinci_emulate_mmio_quirk_write(struct hw_vdavinci *vdavinci, uint64_t pa, void *buf, unsigned int bytes); |
| 71 | -int hw_vdavinci_emulate_mmio_quirk_read(struct hw_vdavinci *vdavinci, uint64_t pa, | ||
| 72 | - void *buf, unsigned int bytes); | ||
| 73 | -int hw_vdavinci_emulate_mmio_quirk_write(struct hw_vdavinci *vdavinci, uint64_t pa, | ||
| 74 | - void *buf, unsigned int bytes); | ||
| 75 | void hw_vdavinci_map_quirk_split(struct hw_vdavinci *vdavinci, phys_addr_t base); | 70 | void hw_vdavinci_map_quirk_split(struct hw_vdavinci *vdavinci, phys_addr_t base); |
| 76 | #endif | 71 | #endif |
| @@ -1,176 +1,170 @@ | |||
| 1 | -/* | 1 | +/* |
| 2 | - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. | 2 | + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. |
| 3 | - * | 3 | + * |
| 4 | - * This program is free software; you can redistribute it and/or modify | 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | - * it under the terms of the GNU General Public License version 2 and | 5 | + * it under the terms of the GNU General Public License version 2 and |
| 6 | - * only version 2 as published by the Free Software Foundation. | 6 | + * only version 2 as published by the Free Software Foundation. |
| 7 | - * | 7 | + * |
| 8 | - * This program is distributed in the hope that it will be useful, | 8 | + * This program is distributed in the hope that it will be useful, |
| 9 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | - * GNU General Public License for more details. | 11 | + * GNU General Public License for more details. |
| 12 | - */ | 12 | + */ |
| 13 | - | 13 | + |
| 14 | -#include "ka_compiler_pub.h" | 14 | +#include "ka_compiler_pub.h" |
| 15 | -#include "hw_vdavinci.h" | 15 | +#include "hw_vdavinci.h" |
| 16 | -#include "priv_ops.h" | 16 | +#include "priv_ops.h" |
| 17 | - | 17 | + |
| 18 | -static inline bool vdavinci_priv_check(struct vdavinci_priv *priv) | 18 | +static inline bool vdavinci_priv_check(struct vdavinci_priv *priv) |
| 19 | -{ | 19 | +{ |
| 20 | - if (ka_unlikely(priv == NULL || priv->ops == NULL)) { | 20 | + if (ka_unlikely(priv == NULL || priv->ops == NULL)) { |
| 21 | - return false; | 21 | + return false; |
| 22 | - } | 22 | + } |
| 23 | - | 23 | + |
| 24 | - return true; | 24 | + return true; |
| 25 | -} | 25 | +} |
| 26 | - | 26 | + |
| 27 | -int vdavinci_priv_vdev_create(struct hw_vdavinci *vdavinci, | 27 | +int vdavinci_priv_vdev_create(struct hw_vdavinci *vdavinci, struct vdavinci_type *tp, ka_uuid_le_t uuid) |
| 28 | - struct vdavinci_type *tp, ka_uuid_le_t uuid) | 28 | +{ |
| 29 | -{ | 29 | + if (!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv)) { |
| 30 | - if (!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv)) { | 30 | + return -EINVAL; |
| 31 | - return -EINVAL; | 31 | + } |
| 32 | - } | 32 | + if (vdavinci->dvt->vdavinci_priv->ops->vdavinci_create == NULL) { |
| 33 | - if (vdavinci->dvt->vdavinci_priv->ops->vdavinci_create == NULL) { | 33 | + vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's create ops is null\n"); |
| 34 | - vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's create ops is null\n"); | 34 | + return -EINVAL; |
| 35 | - return -EINVAL; | 35 | + } |
| 36 | - } | 36 | + |
| 37 | - | 37 | + return vdavinci->dvt->vdavinci_priv->ops->vdavinci_create(&vdavinci->dev, vdavinci, tp, uuid); |
| 38 | - return vdavinci->dvt->vdavinci_priv->ops->vdavinci_create(&vdavinci->dev, vdavinci, | 38 | +} |
| 39 | - tp, uuid); | 39 | + |
| 40 | -} | 40 | +void vdavinci_priv_vdev_destroy(struct hw_vdavinci *vdavinci) |
| 41 | - | 41 | +{ |
| 42 | -void vdavinci_priv_vdev_destroy(struct hw_vdavinci *vdavinci) | 42 | + if (!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv)) { |
| 43 | -{ | 43 | + return; |
| 44 | - if (!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv)) { | 44 | + } |
| 45 | - return; | 45 | + if (vdavinci->dvt->vdavinci_priv->ops->vdavinci_destroy == NULL) { |
| 46 | - } | 46 | + vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's destroy ops is null\n"); |
| 47 | - if (vdavinci->dvt->vdavinci_priv->ops->vdavinci_destroy == NULL) { | 47 | + return; |
| 48 | - vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's destroy ops is null\n"); | 48 | + } |
| 49 | - return; | 49 | + |
| 50 | - } | 50 | + vdavinci->dvt->vdavinci_priv->ops->vdavinci_destroy(&vdavinci->dev); |
| 51 | - | 51 | +} |
| 52 | - vdavinci->dvt->vdavinci_priv->ops->vdavinci_destroy(&vdavinci->dev); | 52 | + |
| 53 | -} | 53 | +void vdavinci_priv_vdev_release(struct hw_vdavinci *vdavinci) |
| 54 | - | 54 | +{ |
| 55 | -void vdavinci_priv_vdev_release(struct hw_vdavinci *vdavinci) | 55 | + if (!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv)) { |
| 56 | -{ | 56 | + return; |
| 57 | - if (!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv)) { | 57 | + } |
| 58 | - return; | 58 | + if (vdavinci->dvt->vdavinci_priv->ops->vdavinci_release == NULL) { |
| 59 | - } | 59 | + vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's release ops is null\n"); |
| 60 | - if (vdavinci->dvt->vdavinci_priv->ops->vdavinci_release == NULL) { | 60 | + return; |
| 61 | - vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's release ops is null\n"); | 61 | + } |
| 62 | - return; | 62 | + |
| 63 | - } | 63 | + vdavinci->dvt->vdavinci_priv->ops->vdavinci_release(&vdavinci->dev); |
| 64 | - | 64 | +} |
| 65 | - vdavinci->dvt->vdavinci_priv->ops->vdavinci_release(&vdavinci->dev); | 65 | + |
| 66 | -} | 66 | +int vdavinci_priv_vdev_reset(struct hw_vdavinci *vdavinci) |
| 67 | - | 67 | +{ |
| 68 | -int vdavinci_priv_vdev_reset(struct hw_vdavinci *vdavinci) | 68 | + if (!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv)) { |
| 69 | -{ | 69 | + return -EINVAL; |
| 70 | - if (!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv)) { | 70 | + } |
| 71 | - return -EINVAL; | 71 | + if (vdavinci->dvt->vdavinci_priv->ops->vdavinci_reset == NULL) { |
| 72 | - } | 72 | + vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's reset ops is null\n"); |
| 73 | - if (vdavinci->dvt->vdavinci_priv->ops->vdavinci_reset == NULL) { | 73 | + return -EINVAL; |
| 74 | - vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's reset ops is null\n"); | 74 | + } |
| 75 | - return -EINVAL; | 75 | + |
| 76 | - } | 76 | + return vdavinci->dvt->vdavinci_priv->ops->vdavinci_reset(&vdavinci->dev); |
| 77 | - | 77 | +} |
| 78 | - return vdavinci->dvt->vdavinci_priv->ops->vdavinci_reset(&vdavinci->dev); | 78 | + |
| 79 | -} | 79 | +int vdavinci_priv_vdev_flr(struct hw_vdavinci *vdavinci) |
| 80 | - | 80 | +{ |
| 81 | -int vdavinci_priv_vdev_flr(struct hw_vdavinci *vdavinci) | 81 | + if (!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv)) { |
| 82 | -{ | 82 | + return -EINVAL; |
| 83 | - if (!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv)) { | 83 | + } |
| 84 | - return -EINVAL; | 84 | + if (vdavinci->dvt->vdavinci_priv->ops->vdavinci_flr == NULL) { |
| 85 | - } | 85 | + vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's flr ops is null\n"); |
| 86 | - if (vdavinci->dvt->vdavinci_priv->ops->vdavinci_flr == NULL) { | 86 | + return -EINVAL; |
| 87 | - vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's flr ops is null\n"); | 87 | + } |
| 88 | - return -EINVAL; | 88 | + |
| 89 | - } | 89 | + return vdavinci->dvt->vdavinci_priv->ops->vdavinci_flr(&vdavinci->dev); |
| 90 | - | 90 | +} |
| 91 | - return vdavinci->dvt->vdavinci_priv->ops->vdavinci_flr(&vdavinci->dev); | 91 | + |
| 92 | -} | 92 | +void vdavinci_priv_vdev_notify(struct hw_vdavinci *vdavinci, int db_index) |
| 93 | - | 93 | +{ |
| 94 | -void vdavinci_priv_vdev_notify(struct hw_vdavinci *vdavinci, int db_index) | 94 | + if (ka_unlikely(!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv))) { |
| 95 | -{ | 95 | + return; |
| 96 | - if (ka_unlikely(!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv))) { | 96 | + } |
| 97 | - return; | 97 | + if (ka_unlikely(vdavinci->dvt->vdavinci_priv->ops->vdavinci_notify == NULL)) { |
| 98 | - } | 98 | + vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's notify ops is null\n"); |
| 99 | - if (ka_unlikely(vdavinci->dvt->vdavinci_priv->ops->vdavinci_notify == NULL)) { | 99 | + return; |
| 100 | - vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's notify ops is null\n"); | 100 | + } |
| 101 | - return; | 101 | + |
| 102 | - } | 102 | + vdavinci->dvt->vdavinci_priv->ops->vdavinci_notify(&vdavinci->dev, db_index); |
| 103 | - | 103 | +} |
| 104 | - vdavinci->dvt->vdavinci_priv->ops->vdavinci_notify(&vdavinci->dev, db_index); | 104 | + |
| 105 | -} | 105 | +int vdavinci_priv_vdev_getmapinfo(struct hw_vdavinci *vdavinci, struct vdavinci_type *tp, u32 bar_id, |
| 106 | - | 106 | + struct vdavinci_mapinfo *map_info) |
| 107 | -int vdavinci_priv_vdev_getmapinfo(struct hw_vdavinci *vdavinci, | 107 | +{ |
| 108 | - struct vdavinci_type *tp, u32 bar_id, | 108 | + if (!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv)) { |
| 109 | - struct vdavinci_mapinfo *map_info) | 109 | + return -EINVAL; |
| 110 | -{ | 110 | + } |
| 111 | - if (!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv)) { | 111 | + if (vdavinci->dvt->vdavinci_priv->ops->vdavinci_getmapinfo == NULL) { |
| 112 | - return -EINVAL; | 112 | + vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's getmapinfo ops is null\n"); |
| 113 | - } | 113 | + return -EINVAL; |
| 114 | - if (vdavinci->dvt->vdavinci_priv->ops->vdavinci_getmapinfo == NULL) { | 114 | + } |
| 115 | - vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's getmapinfo ops is null\n"); | 115 | + |
| 116 | - return -EINVAL; | 116 | + return vdavinci->dvt->vdavinci_priv->ops->vdavinci_getmapinfo(&vdavinci->dev, tp, bar_id, map_info); |
| 117 | - } | 117 | +} |
| 118 | - | 118 | + |
| 119 | - return vdavinci->dvt->vdavinci_priv->ops->vdavinci_getmapinfo(&vdavinci->dev, tp, | 119 | +int vdavinci_priv_vdev_putmapinfo(struct hw_vdavinci *vdavinci) |
| 120 | - bar_id, map_info); | 120 | +{ |
| 121 | -} | 121 | + if (!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv)) { |
| 122 | - | 122 | + return -EINVAL; |
| 123 | -int vdavinci_priv_vdev_putmapinfo(struct hw_vdavinci *vdavinci) | 123 | + } |
| 124 | -{ | 124 | + if (vdavinci->dvt->vdavinci_priv->ops->vdavinci_putmapinfo == NULL) { |
| 125 | - if (!vdavinci_priv_check(vdavinci->dvt->vdavinci_priv)) { | 125 | + vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's putmapinfo ops is null\n"); |
| 126 | - return -EINVAL; | 126 | + return -EINVAL; |
| 127 | - } | 127 | + } |
| 128 | - if (vdavinci->dvt->vdavinci_priv->ops->vdavinci_putmapinfo == NULL) { | 128 | + |
| 129 | - vascend_err(vdavinci_to_dev(vdavinci), "vdavinci_priv's putmapinfo ops is null\n"); | 129 | + return vdavinci->dvt->vdavinci_priv->ops->vdavinci_putmapinfo(&vdavinci->dev); |
| 130 | - return -EINVAL; | 130 | +} |
| 131 | - } | 131 | + |
| 132 | - | 132 | +unsigned int vdavinci_priv_vdev_getdevnum(struct vdavinci_priv *priv, ka_device_t *dev) |
| 133 | - return vdavinci->dvt->vdavinci_priv->ops->vdavinci_putmapinfo(&vdavinci->dev); | 133 | +{ |
| 134 | -} | 134 | + if (!vdavinci_priv_check(priv)) { |
| 135 | - | 135 | + return 0; |
| 136 | -unsigned int vdavinci_priv_vdev_getdevnum(struct vdavinci_priv *priv, ka_device_t *dev) | 136 | + } |
| 137 | -{ | 137 | + if (priv->ops->davinci_getdevnum == NULL) { |
| 138 | - if (!vdavinci_priv_check(priv)) { | 138 | + vascend_err(dev, "priv's getdevnum ops is null\n"); |
| 139 | - return 0; | 139 | + return 0; |
| 140 | - } | 140 | + } |
| 141 | - if (priv->ops->davinci_getdevnum == NULL) { | 141 | + |
| 142 | - vascend_err(dev, "priv's getdevnum ops is null\n"); | 142 | + return (unsigned int)priv->ops->davinci_getdevnum(dev); |
| 143 | - return 0; | 143 | +} |
| 144 | - } | 144 | + |
| 145 | - | 145 | +int vdavinci_priv_vdev_getdevinfo(struct vdavinci_priv *priv, ka_device_t *dev, u32 dev_index, |
| 146 | - return (unsigned int)priv->ops->davinci_getdevnum(dev); | 146 | + struct dvt_devinfo *dev_info) |
| 147 | -} | 147 | +{ |
| 148 | - | 148 | + if (!vdavinci_priv_check(priv)) { |
| 149 | -int vdavinci_priv_vdev_getdevinfo(struct vdavinci_priv *priv, | 149 | + return -EINVAL; |
| 150 | - ka_device_t *dev, u32 dev_index, | 150 | + } |
| 151 | - struct dvt_devinfo *dev_info) | 151 | + if (priv->ops->davinci_getdevinfo == NULL) { |
| 152 | -{ | 152 | + vascend_err(dev, "vdavinci_priv's getdevinfo ops is null\n"); |
| 153 | - if (!vdavinci_priv_check(priv)) { | 153 | + return -EINVAL; |
| 154 | - return -EINVAL; | 154 | + } |
| 155 | - } | 155 | + |
| 156 | - if (priv->ops->davinci_getdevinfo == NULL) { | 156 | + return priv->ops->davinci_getdevinfo(dev, dev_index, dev_info); |
| 157 | - vascend_err(dev, "vdavinci_priv's getdevinfo ops is null\n"); | 157 | +} |
| 158 | - return -EINVAL; | 158 | + |
| 159 | - } | 159 | +int vdavinci_priv_vdev_enable_sriov(struct vdavinci_priv *priv, ka_pci_dev_t *pdev, int numvfs) |
| 160 | - | 160 | +{ |
| 161 | - return priv->ops->davinci_getdevinfo(dev, dev_index, dev_info); | 161 | + if (!vdavinci_priv_check(priv)) { |
| 162 | -} | 162 | + return -EINVAL; |
| 163 | - | 163 | + } |
| 164 | -int vdavinci_priv_vdev_enable_sriov(struct vdavinci_priv *priv, | 164 | + if (priv->ops->vascend_enable_sriov == NULL) { |
| 165 | - ka_pci_dev_t *pdev, int numvfs) | 165 | + vascend_err(&pdev->dev, "vdavinci_priv's vascend_enable_sriov ops is null\n"); |
| 166 | -{ | 166 | + return -EINVAL; |
| 167 | - if (!vdavinci_priv_check(priv)) { | 167 | + } |
| 168 | - return -EINVAL; | 168 | + |
| 169 | - } | 169 | + return priv->ops->vascend_enable_sriov(pdev, numvfs); |
| 170 | - if (priv->ops->vascend_enable_sriov == NULL) { | ||
| 171 | - vascend_err(&pdev->dev, "vdavinci_priv's vascend_enable_sriov ops is null\n"); | ||
| 172 | - return -EINVAL; | ||
| 173 | - } | ||
| 174 | - | ||
| 175 | - return priv->ops->vascend_enable_sriov(pdev, numvfs); | ||
| 176 | } | 170 | } |
| @@ -1,37 +1,33 @@ | |||
| 1 | -/* | 1 | +/* |
| 2 | - * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. | 2 | + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. |
| 3 | - * | 3 | + * |
| 4 | - * This program is free software; you can redistribute it and/or modify | 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | - * it under the terms of the GNU General Public License version 2 and | 5 | + * it under the terms of the GNU General Public License version 2 and |
| 6 | - * only version 2 as published by the Free Software Foundation. | 6 | + * only version 2 as published by the Free Software Foundation. |
| 7 | - * | 7 | + * |
| 8 | - * This program is distributed in the hope that it will be useful, | 8 | + * This program is distributed in the hope that it will be useful, |
| 9 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | - * GNU General Public License for more details. | 11 | + * GNU General Public License for more details. |
| 12 | - */ | 12 | + */ |
| 13 | - | 13 | + |
| 14 | -#ifndef _PRIV_OPS_H_ | 14 | +#ifndef _PRIV_OPS_H_ |
| 15 | -#define _PRIV_OPS_H_ | 15 | +#define _PRIV_OPS_H_ |
| 16 | - | 16 | + |
| 17 | -#include "dvt.h" | 17 | +#include "dvt.h" |
| 18 | - | 18 | + |
| 19 | -int vdavinci_priv_vdev_create(struct hw_vdavinci *vdavinci, | 19 | +int vdavinci_priv_vdev_create(struct hw_vdavinci *vdavinci, struct vdavinci_type *tp, ka_uuid_le_t uuid); |
| 20 | - struct vdavinci_type *tp, ka_uuid_le_t uuid); | 20 | +void vdavinci_priv_vdev_destroy(struct hw_vdavinci *vdavinci); |
| 21 | -void vdavinci_priv_vdev_destroy(struct hw_vdavinci *vdavinci); | 21 | +void vdavinci_priv_vdev_release(struct hw_vdavinci *vdavinci); |
| 22 | -void vdavinci_priv_vdev_release(struct hw_vdavinci *vdavinci); | 22 | +int vdavinci_priv_vdev_reset(struct hw_vdavinci *vdavinci); |
| 23 | -int vdavinci_priv_vdev_reset(struct hw_vdavinci *vdavinci); | 23 | +int vdavinci_priv_vdev_flr(struct hw_vdavinci *vdavinci); |
| 24 | -int vdavinci_priv_vdev_flr(struct hw_vdavinci *vdavinci); | 24 | +void vdavinci_priv_vdev_notify(struct hw_vdavinci *vdavinci, int db_index); |
| 25 | -void vdavinci_priv_vdev_notify(struct hw_vdavinci *vdavinci, int db_index); | 25 | +int vdavinci_priv_vdev_getmapinfo(struct hw_vdavinci *vdavinci, struct vdavinci_type *tp, u32 bar_id, |
| 26 | -int vdavinci_priv_vdev_getmapinfo(struct hw_vdavinci *vdavinci, | 26 | + struct vdavinci_mapinfo *map_info); |
| 27 | - struct vdavinci_type *tp, u32 bar_id, | 27 | +int vdavinci_priv_vdev_putmapinfo(struct hw_vdavinci *vdavinci); |
| 28 | - struct vdavinci_mapinfo *map_info); | 28 | +unsigned int vdavinci_priv_vdev_getdevnum(struct vdavinci_priv *priv, ka_device_t *dev); |
| 29 | -int vdavinci_priv_vdev_putmapinfo(struct hw_vdavinci *vdavinci); | 29 | +int vdavinci_priv_vdev_getdevinfo(struct vdavinci_priv *priv, ka_device_t *dev, u32 dev_index, |
| 30 | -unsigned int vdavinci_priv_vdev_getdevnum(struct vdavinci_priv *priv, ka_device_t *dev); | 30 | + struct dvt_devinfo *dev_info); |
| 31 | -int vdavinci_priv_vdev_getdevinfo(struct vdavinci_priv *priv, | 31 | +int vdavinci_priv_vdev_enable_sriov(struct vdavinci_priv *priv, ka_pci_dev_t *pdev, int numvfs); |
| 32 | - ka_device_t *dev, u32 dev_index, | 32 | + |
| 33 | - struct dvt_devinfo *dev_info); | ||
| 34 | -int vdavinci_priv_vdev_enable_sriov(struct vdavinci_priv *priv, | ||
| 35 | - ka_pci_dev_t *pdev, int numvfs); | ||
| 36 | - | ||
| 37 | #endif /* _PRIV_OPS_H_ */ | 33 | #endif /* _PRIV_OPS_H_ */ |
| @@ -1,134 +1,131 @@ | |||
| 1 | -/* | 1 | +/* |
| 2 | - * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. | 2 | + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. |
| 3 | - * | 3 | + * |
| 4 | - * This program is free software; you can redistribute it and/or modify | 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | - * it under the terms of the GNU General Public License version 2 and | 5 | + * it under the terms of the GNU General Public License version 2 and |
| 6 | - * only version 2 as published by the Free Software Foundation. | 6 | + * only version 2 as published by the Free Software Foundation. |
| 7 | - * | 7 | + * |
| 8 | - * This program is distributed in the hope that it will be useful, | 8 | + * This program is distributed in the hope that it will be useful, |
| 9 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | - * GNU General Public License for more details. | 11 | + * GNU General Public License for more details. |
| 12 | - */ | 12 | + */ |
| 13 | - | 13 | + |
| 14 | -#include "ka_system_pub.h" | 14 | +#include "ka_system_pub.h" |
| 15 | -#include "hw_vdavinci.h" | 15 | +#include "hw_vdavinci.h" |
| 16 | -#include "dvt.h" | 16 | +#include "dvt.h" |
| 17 | -#include "vfio_ops.h" | 17 | +#include "vfio_ops.h" |
| 18 | -#include "schedule.h" | 18 | +#include "schedule.h" |
| 19 | - | 19 | + |
| 20 | -bool hw_vdavinci_changed_cpu(ka_task_struct_t *p, | 20 | +bool hw_vdavinci_changed_cpu(ka_task_struct_t *p, const ka_cpumask_t *next_mask) |
| 21 | - const ka_cpumask_t *next_mask) | 21 | +{ |
| 22 | -{ | 22 | +#if (IS_VDAVINCI_KERNEL_VERSION_SUPPORT || (defined(DRV_UT))) |
| 23 | -#if (IS_VDAVINCI_KERNEL_VERSION_SUPPORT || (defined(DRV_UT))) | 23 | + if (ka_base_cpumask_empty(next_mask)) { |
| 24 | - if (ka_base_cpumask_empty(next_mask)) { | 24 | + return false; |
| 25 | - return false; | 25 | + } |
| 26 | - } | 26 | + |
| 27 | - | 27 | + if (cpumask_test_cpu(ka_system_smp_processor_id(), next_mask)) { |
| 28 | - if (cpumask_test_cpu(ka_system_smp_processor_id(), next_mask)) { | 28 | + return false; |
| 29 | - return false; | 29 | + } |
| 30 | - } | 30 | + |
| 31 | - | 31 | + if (ka_base_set_cpus_allowed_ptr(p, next_mask) != 0) { |
| 32 | - if (ka_base_set_cpus_allowed_ptr(p, next_mask) != 0) { | 32 | + return false; |
| 33 | - return false; | 33 | + } |
| 34 | - } | 34 | +#endif |
| 35 | -#endif | 35 | + return true; |
| 36 | - return true; | 36 | +} |
| 37 | -} | 37 | + |
| 38 | - | 38 | +bool hw_vdavinci_scheduled(struct hw_vdavinci *vdavinci, unsigned long current_pages, unsigned long max_pages, |
| 39 | -bool hw_vdavinci_scheduled(struct hw_vdavinci *vdavinci, | 39 | + unsigned int timeout, ka_page_t *page) |
| 40 | - unsigned long current_pages, | 40 | +{ |
| 41 | - unsigned long max_pages, | 41 | +#if (IS_VDAVINCI_KERNEL_VERSION_SUPPORT || (defined(DRV_UT))) |
| 42 | - unsigned int timeout, | 42 | + ka_cpumask_var_t next_mask; |
| 43 | - ka_page_t *page) | 43 | + bool ret; |
| 44 | -{ | 44 | + |
| 45 | -#if (IS_VDAVINCI_KERNEL_VERSION_SUPPORT || (defined(DRV_UT))) | 45 | + if (page != NULL) { |
| 46 | - ka_cpumask_var_t next_mask; | 46 | + if (!ka_base_zalloc_cpumask_var(&next_mask, KA_GFP_KERNEL)) { |
| 47 | - bool ret; | 47 | + return false; |
| 48 | - | 48 | + } |
| 49 | - if (page != NULL) { | 49 | + ret = get_node_cpu_by_page(vdavinci, ka_system_smp_processor_id(), page, next_mask); |
| 50 | - if (!ka_base_zalloc_cpumask_var(&next_mask, KA_GFP_KERNEL)) { | 50 | + if (ret && hw_vdavinci_changed_cpu(ka_task_get_current(), next_mask)) { |
| 51 | - return false; | 51 | + ka_base_free_cpumask_var(next_mask); |
| 52 | - } | 52 | + return true; |
| 53 | - ret = get_node_cpu_by_page(vdavinci, ka_system_smp_processor_id(), page, next_mask); | 53 | + } |
| 54 | - if (ret && hw_vdavinci_changed_cpu(ka_task_get_current(), next_mask)) { | 54 | + ka_base_free_cpumask_var(next_mask); |
| 55 | - ka_base_free_cpumask_var(next_mask); | 55 | + } |
| 56 | - return true; | 56 | + if (current_pages >= max_pages) { |
| 57 | - } | 57 | + ka_task_set_current_state(KA_TASK_INTERRUPTIBLE); |
| 58 | - ka_base_free_cpumask_var(next_mask); | 58 | + ka_task_schedule_timeout((long)ka_system_msecs_to_jiffies(timeout)); |
| 59 | - } | 59 | + return true; |
| 60 | - if (current_pages >= max_pages) { | 60 | + } |
| 61 | - ka_task_set_current_state(KA_TASK_INTERRUPTIBLE); | 61 | +#endif |
| 62 | - ka_task_schedule_timeout((long)ka_system_msecs_to_jiffies(timeout)); | 62 | + return false; |
| 63 | - return true; | 63 | +} |
| 64 | - } | 64 | + |
| 65 | -#endif | 65 | +#ifdef CONFIG_NUMA |
| 66 | - return false; | 66 | +#if (IS_VDAVINCI_KERNEL_VERSION_SUPPORT || (defined(DRV_UT))) |
| 67 | -} | 67 | +STATIC bool is_vcpu_thread(ka_task_struct_t *task) |
| 68 | - | 68 | +{ |
| 69 | -#ifdef CONFIG_NUMA | 69 | + return ka_strstarts(task->comm, "CPU "); |
| 70 | -#if (IS_VDAVINCI_KERNEL_VERSION_SUPPORT || (defined(DRV_UT))) | 70 | +} |
| 71 | -STATIC bool is_vcpu_thread(ka_task_struct_t *task) | 71 | + |
| 72 | -{ | 72 | +STATIC int get_page_node(ka_page_t *page) |
| 73 | - return ka_strstarts(task->comm, "CPU "); | 73 | +{ |
| 74 | -} | 74 | + if (!ka_mm_pfn_valid(ka_mm_page_to_pfn(page))) { |
| 75 | - | 75 | + return -1; |
| 76 | -STATIC int get_page_node(ka_page_t *page) | 76 | + } |
| 77 | -{ | 77 | + |
| 78 | - if (!ka_mm_pfn_valid(ka_mm_page_to_pfn(page))) { | 78 | + return ka_mm_page_to_nid(page); |
| 79 | - return -1; | 79 | +} |
| 80 | - } | 80 | +#endif /* VERSION_SUPPORT */ |
| 81 | - | 81 | +#endif /* CONFIG_NUMA */ |
| 82 | - return ka_mm_page_to_nid(page); | 82 | + |
| 83 | -} | 83 | +bool get_node_cpu_by_page(struct hw_vdavinci *vdavinci, unsigned int current_cpu, ka_page_t *page, |
| 84 | -#endif /* VERSION_SUPPORT */ | 84 | + ka_cpumask_t *cpumask) |
| 85 | -#endif /* CONFIG_NUMA */ | 85 | +{ |
| 86 | - | 86 | +#ifdef CONFIG_NUMA |
| 87 | -bool get_node_cpu_by_page(struct hw_vdavinci *vdavinci, | 87 | +#if (IS_VDAVINCI_KERNEL_VERSION_SUPPORT || (defined(DRV_UT))) |
| 88 | - unsigned int current_cpu, | 88 | + unsigned int cpu = 0; |
| 89 | - ka_page_t *page, | 89 | + ka_task_struct_t *me = NULL; |
| 90 | - ka_cpumask_t *cpumask) | 90 | + ka_task_struct_t *thread = NULL; |
| 91 | -{ | 91 | + int page_node = get_page_node(page); |
| 92 | -#ifdef CONFIG_NUMA | 92 | + ka_task_struct_t *qemu_task = vdavinci->qemu_task; |
| 93 | -#if (IS_VDAVINCI_KERNEL_VERSION_SUPPORT || (defined(DRV_UT))) | 93 | + const ka_cpumask_t *thread_mask; |
| 94 | - unsigned int cpu = 0; | 94 | + |
| 95 | - ka_task_struct_t *me = NULL; | 95 | + if (page_node < 0) { |
| 96 | - ka_task_struct_t *thread = NULL; | 96 | + return false; |
| 97 | - int page_node = get_page_node(page); | 97 | + } |
| 98 | - ka_task_struct_t *qemu_task = vdavinci->qemu_task; | 98 | + if (page_node == ka_system_cpu_to_node(current_cpu)) { |
| 99 | - const ka_cpumask_t *thread_mask; | 99 | + return false; |
| 100 | - | 100 | + } |
| 101 | - if (page_node < 0) { | 101 | + me = qemu_task; |
| 102 | - return false; | 102 | + thread = me; |
| 103 | - } | 103 | + do { |
| 104 | - if (page_node == ka_system_cpu_to_node(current_cpu)) { | 104 | + if (!is_vcpu_thread(thread)) { |
| 105 | - return false; | 105 | + continue; |
| 106 | - } | 106 | + } |
| 107 | - me = qemu_task; | 107 | + cpu = ka_task_task_cpu(thread); |
| 108 | - thread = me; | 108 | + if (ka_system_cpu_to_node(cpu) == page_node) { |
| 109 | - do { | 109 | + ka_base_cpumask_set_cpu(cpu, cpumask); |
| 110 | - if (!is_vcpu_thread(thread)) { | 110 | + } |
| 111 | - continue; | 111 | + thread_mask = ka_get_cpumask(thread); |
| 112 | - } | 112 | + ka_base_cpumask_or(&(vdavinci->vm_cpus_mask), &(vdavinci->vm_cpus_mask), thread_mask); |
| 113 | - cpu = ka_task_task_cpu(thread); | 113 | + } |
| 114 | - if (ka_system_cpu_to_node(cpu) == page_node) { | 114 | + ka_while_each_thread(me, thread); |
| 115 | - ka_base_cpumask_set_cpu(cpu, cpumask); | 115 | + ka_base_for_each_cpu(cpu, &(vdavinci->vm_cpus_mask)) |
| 116 | - } | 116 | + { |
| 117 | - thread_mask = ka_get_cpumask(thread); | 117 | + if (ka_system_cpu_to_node(cpu) == page_node) { |
| 118 | - ka_base_cpumask_or(&(vdavinci->vm_cpus_mask), &(vdavinci->vm_cpus_mask), thread_mask); | 118 | + ka_base_cpumask_set_cpu(cpu, cpumask); |
| 119 | - } ka_while_each_thread(me, thread); | 119 | + } |
| 120 | - ka_base_for_each_cpu(cpu, &(vdavinci->vm_cpus_mask)) { | 120 | + } |
| 121 | - if (ka_system_cpu_to_node(cpu) == page_node) { | 121 | + thread_mask = ka_get_cpumask(qemu_task); |
| 122 | - ka_base_cpumask_set_cpu(cpu, cpumask); | 122 | + ka_base_for_each_cpu(cpu, thread_mask) |
| 123 | - } | 123 | + { |
| 124 | - } | 124 | + if (ka_system_cpu_to_node(cpu) == page_node) { |
| 125 | - thread_mask = ka_get_cpumask(qemu_task); | 125 | + ka_base_cpumask_set_cpu(cpu, cpumask); |
| 126 | - ka_base_for_each_cpu(cpu, thread_mask) { | 126 | + } |
| 127 | - if (ka_system_cpu_to_node(cpu) == page_node) { | 127 | + } |
| 128 | - ka_base_cpumask_set_cpu(cpu, cpumask); | 128 | +#endif /* VERSION_SUPPORT */ |
| 129 | - } | 129 | +#endif /* CONFIG_NUMA */ |
| 130 | - } | 130 | + return true; |
| 131 | -#endif /* VERSION_SUPPORT */ | ||
| 132 | -#endif /* CONFIG_NUMA */ | ||
| 133 | - return true; | ||
| 134 | } | 131 | } |
| @@ -1,22 +1,21 @@ | |||
| 1 | -/* | 1 | +/* |
| 2 | - * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. | 2 | + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. |
| 3 | - * | 3 | + * |
| 4 | - * This program is free software; you can redistribute it and/or modify | 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | - * it under the terms of the GNU General Public License version 2 and | 5 | + * it under the terms of the GNU General Public License version 2 and |
| 6 | - * only version 2 as published by the Free Software Foundation. | 6 | + * only version 2 as published by the Free Software Foundation. |
| 7 | - * | 7 | + * |
| 8 | - * This program is distributed in the hope that it will be useful, | 8 | + * This program is distributed in the hope that it will be useful, |
| 9 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | - * GNU General Public License for more details. | 11 | + * GNU General Public License for more details. |
| 12 | - */ | 12 | + */ |
| 13 | - | 13 | + |
| 14 | -#ifndef _VDAVINCI_H_ | 14 | +#ifndef _VDAVINCI_H_ |
| 15 | -#define _VDAVINCI_H_ | 15 | +#define _VDAVINCI_H_ |
| 16 | - | 16 | + |
| 17 | -void hw_vdavinci_unregister_iodev(struct hw_vdavinci *vdavinci); | 17 | +void hw_vdavinci_unregister_iodev(struct hw_vdavinci *vdavinci); |
| 18 | -int hw_vdavinci_register_iodev(struct hw_vdavinci *vdavinci, | 18 | +int hw_vdavinci_register_iodev(struct hw_vdavinci *vdavinci, gpa_t addr, int len, int index); |
| 19 | - gpa_t addr, int len, int index); | 19 | +void vdavinci_module_exit(void); |
| 20 | -void vdavinci_module_exit(void); | 20 | + |
| 21 | - | 21 | +#endif |
| 22 | -#endif | ||