radeon_object.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /*
  2. * Copyright 2009 Jerome Glisse.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sub license, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  16. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  17. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  18. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  19. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. *
  21. * The above copyright notice and this permission notice (including the
  22. * next paragraph) shall be included in all copies or substantial portions
  23. * of the Software.
  24. *
  25. */
  26. /*
  27. * Authors:
  28. * Jerome Glisse <glisse@freedesktop.org>
  29. * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
  30. * Dave Airlie
  31. */
  32. #include <linux/list.h>
  33. #include <linux/slab.h>
  34. #include <drm/drmP.h>
  35. #include "radeon_drm.h"
  36. #include "radeon.h"
  37. #include "radeon_trace.h"
  38. int radeon_ttm_init(struct radeon_device *rdev);
  39. void radeon_ttm_fini(struct radeon_device *rdev);
  40. static void radeon_bo_clear_surface_reg(struct radeon_bo *bo);
  41. /*
  42. * To exclude mutual BO access we rely on bo_reserve exclusion, as all
  43. * function are calling it.
  44. */
  45. void radeon_bo_clear_va(struct radeon_bo *bo)
  46. {
  47. struct radeon_bo_va *bo_va, *tmp;
  48. list_for_each_entry_safe(bo_va, tmp, &bo->va, bo_list) {
  49. /* remove from all vm address space */
  50. mutex_lock(&bo_va->vm->mutex);
  51. list_del(&bo_va->vm_list);
  52. mutex_unlock(&bo_va->vm->mutex);
  53. list_del(&bo_va->bo_list);
  54. kfree(bo_va);
  55. }
  56. }
  57. static void radeon_ttm_bo_destroy(struct ttm_buffer_object *tbo)
  58. {
  59. struct radeon_bo *bo;
  60. bo = container_of(tbo, struct radeon_bo, tbo);
  61. mutex_lock(&bo->rdev->gem.mutex);
  62. list_del_init(&bo->list);
  63. mutex_unlock(&bo->rdev->gem.mutex);
  64. radeon_bo_clear_surface_reg(bo);
  65. radeon_bo_clear_va(bo);
  66. drm_gem_object_release(&bo->gem_base);
  67. kfree(bo);
  68. }
  69. bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo)
  70. {
  71. if (bo->destroy == &radeon_ttm_bo_destroy)
  72. return true;
  73. return false;
  74. }
  75. void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
  76. {
  77. u32 c = 0;
  78. rbo->placement.fpfn = 0;
  79. rbo->placement.lpfn = 0;
  80. rbo->placement.placement = rbo->placements;
  81. rbo->placement.busy_placement = rbo->placements;
  82. if (domain & RADEON_GEM_DOMAIN_VRAM)
  83. rbo->placements[c++] = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED |
  84. TTM_PL_FLAG_VRAM;
  85. if (domain & RADEON_GEM_DOMAIN_GTT)
  86. rbo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_TT;
  87. if (domain & RADEON_GEM_DOMAIN_CPU)
  88. rbo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
  89. if (!c)
  90. rbo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
  91. rbo->placement.num_placement = c;
  92. rbo->placement.num_busy_placement = c;
  93. }
  94. int radeon_bo_create(struct radeon_device *rdev,
  95. unsigned long size, int byte_align, bool kernel, u32 domain,
  96. struct radeon_bo **bo_ptr)
  97. {
  98. struct radeon_bo *bo;
  99. enum ttm_bo_type type;
  100. unsigned long page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
  101. unsigned long max_size = 0;
  102. size_t acc_size;
  103. int r;
  104. size = ALIGN(size, PAGE_SIZE);
  105. if (unlikely(rdev->mman.bdev.dev_mapping == NULL)) {
  106. rdev->mman.bdev.dev_mapping = rdev->ddev->dev_mapping;
  107. }
  108. if (kernel) {
  109. type = ttm_bo_type_kernel;
  110. } else {
  111. type = ttm_bo_type_device;
  112. }
  113. *bo_ptr = NULL;
  114. /* maximun bo size is the minimun btw visible vram and gtt size */
  115. max_size = min(rdev->mc.visible_vram_size, rdev->mc.gtt_size);
  116. if ((page_align << PAGE_SHIFT) >= max_size) {
  117. printk(KERN_WARNING "%s:%d alloc size %ldM bigger than %ldMb limit\n",
  118. __func__, __LINE__, page_align >> (20 - PAGE_SHIFT), max_size >> 20);
  119. return -ENOMEM;
  120. }
  121. acc_size = ttm_bo_dma_acc_size(&rdev->mman.bdev, size,
  122. sizeof(struct radeon_bo));
  123. retry:
  124. bo = kzalloc(sizeof(struct radeon_bo), GFP_KERNEL);
  125. if (bo == NULL)
  126. return -ENOMEM;
  127. r = drm_gem_object_init(rdev->ddev, &bo->gem_base, size);
  128. if (unlikely(r)) {
  129. kfree(bo);
  130. return r;
  131. }
  132. bo->rdev = rdev;
  133. bo->gem_base.driver_private = NULL;
  134. bo->surface_reg = -1;
  135. INIT_LIST_HEAD(&bo->list);
  136. INIT_LIST_HEAD(&bo->va);
  137. radeon_ttm_placement_from_domain(bo, domain);
  138. /* Kernel allocation are uninterruptible */
  139. mutex_lock(&rdev->vram_mutex);
  140. r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type,
  141. &bo->placement, page_align, 0, !kernel, NULL,
  142. acc_size, &radeon_ttm_bo_destroy);
  143. mutex_unlock(&rdev->vram_mutex);
  144. if (unlikely(r != 0)) {
  145. if (r != -ERESTARTSYS) {
  146. if (domain == RADEON_GEM_DOMAIN_VRAM) {
  147. domain |= RADEON_GEM_DOMAIN_GTT;
  148. goto retry;
  149. }
  150. dev_err(rdev->dev,
  151. "object_init failed for (%lu, 0x%08X)\n",
  152. size, domain);
  153. }
  154. return r;
  155. }
  156. *bo_ptr = bo;
  157. trace_radeon_bo_create(bo);
  158. return 0;
  159. }
  160. int radeon_bo_kmap(struct radeon_bo *bo, void **ptr)
  161. {
  162. bool is_iomem;
  163. int r;
  164. if (bo->kptr) {
  165. if (ptr) {
  166. *ptr = bo->kptr;
  167. }
  168. return 0;
  169. }
  170. r = ttm_bo_kmap(&bo->tbo, 0, bo->tbo.num_pages, &bo->kmap);
  171. if (r) {
  172. return r;
  173. }
  174. bo->kptr = ttm_kmap_obj_virtual(&bo->kmap, &is_iomem);
  175. if (ptr) {
  176. *ptr = bo->kptr;
  177. }
  178. radeon_bo_check_tiling(bo, 0, 0);
  179. return 0;
  180. }
  181. void radeon_bo_kunmap(struct radeon_bo *bo)
  182. {
  183. if (bo->kptr == NULL)
  184. return;
  185. bo->kptr = NULL;
  186. radeon_bo_check_tiling(bo, 0, 0);
  187. ttm_bo_kunmap(&bo->kmap);
  188. }
  189. void radeon_bo_unref(struct radeon_bo **bo)
  190. {
  191. struct ttm_buffer_object *tbo;
  192. struct radeon_device *rdev;
  193. if ((*bo) == NULL)
  194. return;
  195. rdev = (*bo)->rdev;
  196. tbo = &((*bo)->tbo);
  197. mutex_lock(&rdev->vram_mutex);
  198. ttm_bo_unref(&tbo);
  199. mutex_unlock(&rdev->vram_mutex);
  200. if (tbo == NULL)
  201. *bo = NULL;
  202. }
  203. int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr)
  204. {
  205. int r, i;
  206. if (bo->pin_count) {
  207. bo->pin_count++;
  208. if (gpu_addr)
  209. *gpu_addr = radeon_bo_gpu_offset(bo);
  210. return 0;
  211. }
  212. radeon_ttm_placement_from_domain(bo, domain);
  213. if (domain == RADEON_GEM_DOMAIN_VRAM) {
  214. /* force to pin into visible video ram */
  215. bo->placement.lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
  216. }
  217. for (i = 0; i < bo->placement.num_placement; i++)
  218. bo->placements[i] |= TTM_PL_FLAG_NO_EVICT;
  219. r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false, false);
  220. if (likely(r == 0)) {
  221. bo->pin_count = 1;
  222. if (gpu_addr != NULL)
  223. *gpu_addr = radeon_bo_gpu_offset(bo);
  224. }
  225. if (unlikely(r != 0))
  226. dev_err(bo->rdev->dev, "%p pin failed\n", bo);
  227. return r;
  228. }
  229. int radeon_bo_unpin(struct radeon_bo *bo)
  230. {
  231. int r, i;
  232. if (!bo->pin_count) {
  233. dev_warn(bo->rdev->dev, "%p unpin not necessary\n", bo);
  234. return 0;
  235. }
  236. bo->pin_count--;
  237. if (bo->pin_count)
  238. return 0;
  239. for (i = 0; i < bo->placement.num_placement; i++)
  240. bo->placements[i] &= ~TTM_PL_FLAG_NO_EVICT;
  241. r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false, false);
  242. if (unlikely(r != 0))
  243. dev_err(bo->rdev->dev, "%p validate failed for unpin\n", bo);
  244. return r;
  245. }
  246. int radeon_bo_evict_vram(struct radeon_device *rdev)
  247. {
  248. /* late 2.6.33 fix IGP hibernate - we need pm ops to do this correct */
  249. if (0 && (rdev->flags & RADEON_IS_IGP)) {
  250. if (rdev->mc.igp_sideport_enabled == false)
  251. /* Useless to evict on IGP chips */
  252. return 0;
  253. }
  254. return ttm_bo_evict_mm(&rdev->mman.bdev, TTM_PL_VRAM);
  255. }
  256. void radeon_bo_force_delete(struct radeon_device *rdev)
  257. {
  258. struct radeon_bo *bo, *n;
  259. if (list_empty(&rdev->gem.objects)) {
  260. return;
  261. }
  262. dev_err(rdev->dev, "Userspace still has active objects !\n");
  263. list_for_each_entry_safe(bo, n, &rdev->gem.objects, list) {
  264. mutex_lock(&rdev->ddev->struct_mutex);
  265. dev_err(rdev->dev, "%p %p %lu %lu force free\n",
  266. &bo->gem_base, bo, (unsigned long)bo->gem_base.size,
  267. *((unsigned long *)&bo->gem_base.refcount));
  268. mutex_lock(&bo->rdev->gem.mutex);
  269. list_del_init(&bo->list);
  270. mutex_unlock(&bo->rdev->gem.mutex);
  271. /* this should unref the ttm bo */
  272. drm_gem_object_unreference(&bo->gem_base);
  273. mutex_unlock(&rdev->ddev->struct_mutex);
  274. }
  275. }
  276. int radeon_bo_init(struct radeon_device *rdev)
  277. {
  278. /* Add an MTRR for the VRAM */
  279. rdev->mc.vram_mtrr = mtrr_add(rdev->mc.aper_base, rdev->mc.aper_size,
  280. MTRR_TYPE_WRCOMB, 1);
  281. DRM_INFO("Detected VRAM RAM=%lluM, BAR=%lluM\n",
  282. rdev->mc.mc_vram_size >> 20,
  283. (unsigned long long)rdev->mc.aper_size >> 20);
  284. DRM_INFO("RAM width %dbits %cDR\n",
  285. rdev->mc.vram_width, rdev->mc.vram_is_ddr ? 'D' : 'S');
  286. return radeon_ttm_init(rdev);
  287. }
  288. void radeon_bo_fini(struct radeon_device *rdev)
  289. {
  290. radeon_ttm_fini(rdev);
  291. }
  292. void radeon_bo_list_add_object(struct radeon_bo_list *lobj,
  293. struct list_head *head)
  294. {
  295. if (lobj->wdomain) {
  296. list_add(&lobj->tv.head, head);
  297. } else {
  298. list_add_tail(&lobj->tv.head, head);
  299. }
  300. }
  301. int radeon_bo_list_validate(struct list_head *head)
  302. {
  303. struct radeon_bo_list *lobj;
  304. struct radeon_bo *bo;
  305. u32 domain;
  306. int r;
  307. r = ttm_eu_reserve_buffers(head);
  308. if (unlikely(r != 0)) {
  309. return r;
  310. }
  311. list_for_each_entry(lobj, head, tv.head) {
  312. bo = lobj->bo;
  313. if (!bo->pin_count) {
  314. domain = lobj->wdomain ? lobj->wdomain : lobj->rdomain;
  315. retry:
  316. radeon_ttm_placement_from_domain(bo, domain);
  317. r = ttm_bo_validate(&bo->tbo, &bo->placement,
  318. true, false, false);
  319. if (unlikely(r)) {
  320. if (r != -ERESTARTSYS && domain == RADEON_GEM_DOMAIN_VRAM) {
  321. domain |= RADEON_GEM_DOMAIN_GTT;
  322. goto retry;
  323. }
  324. return r;
  325. }
  326. }
  327. lobj->gpu_offset = radeon_bo_gpu_offset(bo);
  328. lobj->tiling_flags = bo->tiling_flags;
  329. }
  330. return 0;
  331. }
  332. int radeon_bo_fbdev_mmap(struct radeon_bo *bo,
  333. struct vm_area_struct *vma)
  334. {
  335. return ttm_fbdev_mmap(vma, &bo->tbo);
  336. }
  337. int radeon_bo_get_surface_reg(struct radeon_bo *bo)
  338. {
  339. struct radeon_device *rdev = bo->rdev;
  340. struct radeon_surface_reg *reg;
  341. struct radeon_bo *old_object;
  342. int steal;
  343. int i;
  344. BUG_ON(!atomic_read(&bo->tbo.reserved));
  345. if (!bo->tiling_flags)
  346. return 0;
  347. if (bo->surface_reg >= 0) {
  348. reg = &rdev->surface_regs[bo->surface_reg];
  349. i = bo->surface_reg;
  350. goto out;
  351. }
  352. steal = -1;
  353. for (i = 0; i < RADEON_GEM_MAX_SURFACES; i++) {
  354. reg = &rdev->surface_regs[i];
  355. if (!reg->bo)
  356. break;
  357. old_object = reg->bo;
  358. if (old_object->pin_count == 0)
  359. steal = i;
  360. }
  361. /* if we are all out */
  362. if (i == RADEON_GEM_MAX_SURFACES) {
  363. if (steal == -1)
  364. return -ENOMEM;
  365. /* find someone with a surface reg and nuke their BO */
  366. reg = &rdev->surface_regs[steal];
  367. old_object = reg->bo;
  368. /* blow away the mapping */
  369. DRM_DEBUG("stealing surface reg %d from %p\n", steal, old_object);
  370. ttm_bo_unmap_virtual(&old_object->tbo);
  371. old_object->surface_reg = -1;
  372. i = steal;
  373. }
  374. bo->surface_reg = i;
  375. reg->bo = bo;
  376. out:
  377. radeon_set_surface_reg(rdev, i, bo->tiling_flags, bo->pitch,
  378. bo->tbo.mem.start << PAGE_SHIFT,
  379. bo->tbo.num_pages << PAGE_SHIFT);
  380. return 0;
  381. }
  382. static void radeon_bo_clear_surface_reg(struct radeon_bo *bo)
  383. {
  384. struct radeon_device *rdev = bo->rdev;
  385. struct radeon_surface_reg *reg;
  386. if (bo->surface_reg == -1)
  387. return;
  388. reg = &rdev->surface_regs[bo->surface_reg];
  389. radeon_clear_surface_reg(rdev, bo->surface_reg);
  390. reg->bo = NULL;
  391. bo->surface_reg = -1;
  392. }
  393. int radeon_bo_set_tiling_flags(struct radeon_bo *bo,
  394. uint32_t tiling_flags, uint32_t pitch)
  395. {
  396. int r;
  397. r = radeon_bo_reserve(bo, false);
  398. if (unlikely(r != 0))
  399. return r;
  400. bo->tiling_flags = tiling_flags;
  401. bo->pitch = pitch;
  402. radeon_bo_unreserve(bo);
  403. return 0;
  404. }
  405. void radeon_bo_get_tiling_flags(struct radeon_bo *bo,
  406. uint32_t *tiling_flags,
  407. uint32_t *pitch)
  408. {
  409. BUG_ON(!atomic_read(&bo->tbo.reserved));
  410. if (tiling_flags)
  411. *tiling_flags = bo->tiling_flags;
  412. if (pitch)
  413. *pitch = bo->pitch;
  414. }
  415. int radeon_bo_check_tiling(struct radeon_bo *bo, bool has_moved,
  416. bool force_drop)
  417. {
  418. BUG_ON(!atomic_read(&bo->tbo.reserved));
  419. if (!(bo->tiling_flags & RADEON_TILING_SURFACE))
  420. return 0;
  421. if (force_drop) {
  422. radeon_bo_clear_surface_reg(bo);
  423. return 0;
  424. }
  425. if (bo->tbo.mem.mem_type != TTM_PL_VRAM) {
  426. if (!has_moved)
  427. return 0;
  428. if (bo->surface_reg >= 0)
  429. radeon_bo_clear_surface_reg(bo);
  430. return 0;
  431. }
  432. if ((bo->surface_reg >= 0) && !has_moved)
  433. return 0;
  434. return radeon_bo_get_surface_reg(bo);
  435. }
  436. void radeon_bo_move_notify(struct ttm_buffer_object *bo,
  437. struct ttm_mem_reg *mem)
  438. {
  439. struct radeon_bo *rbo;
  440. if (!radeon_ttm_bo_is_radeon_bo(bo))
  441. return;
  442. rbo = container_of(bo, struct radeon_bo, tbo);
  443. radeon_bo_check_tiling(rbo, 0, 1);
  444. radeon_vm_bo_invalidate(rbo->rdev, rbo);
  445. }
  446. int radeon_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
  447. {
  448. struct radeon_device *rdev;
  449. struct radeon_bo *rbo;
  450. unsigned long offset, size;
  451. int r;
  452. if (!radeon_ttm_bo_is_radeon_bo(bo))
  453. return 0;
  454. rbo = container_of(bo, struct radeon_bo, tbo);
  455. radeon_bo_check_tiling(rbo, 0, 0);
  456. rdev = rbo->rdev;
  457. if (bo->mem.mem_type == TTM_PL_VRAM) {
  458. size = bo->mem.num_pages << PAGE_SHIFT;
  459. offset = bo->mem.start << PAGE_SHIFT;
  460. if ((offset + size) > rdev->mc.visible_vram_size) {
  461. /* hurrah the memory is not visible ! */
  462. radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_VRAM);
  463. rbo->placement.lpfn = rdev->mc.visible_vram_size >> PAGE_SHIFT;
  464. r = ttm_bo_validate(bo, &rbo->placement, false, true, false);
  465. if (unlikely(r != 0))
  466. return r;
  467. offset = bo->mem.start << PAGE_SHIFT;
  468. /* this should not happen */
  469. if ((offset + size) > rdev->mc.visible_vram_size)
  470. return -EINVAL;
  471. }
  472. }
  473. return 0;
  474. }
  475. int radeon_bo_wait(struct radeon_bo *bo, u32 *mem_type, bool no_wait)
  476. {
  477. int r;
  478. r = ttm_bo_reserve(&bo->tbo, true, no_wait, false, 0);
  479. if (unlikely(r != 0))
  480. return r;
  481. spin_lock(&bo->tbo.bdev->fence_lock);
  482. if (mem_type)
  483. *mem_type = bo->tbo.mem.mem_type;
  484. if (bo->tbo.sync_obj)
  485. r = ttm_bo_wait(&bo->tbo, true, true, no_wait);
  486. spin_unlock(&bo->tbo.bdev->fence_lock);
  487. ttm_bo_unreserve(&bo->tbo);
  488. return r;
  489. }
  490. /**
  491. * radeon_bo_reserve - reserve bo
  492. * @bo: bo structure
  493. * @no_wait: don't sleep while trying to reserve (return -EBUSY)
  494. *
  495. * Returns:
  496. * -EBUSY: buffer is busy and @no_wait is true
  497. * -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by
  498. * a signal. Release all buffer reservations and return to user-space.
  499. */
  500. int radeon_bo_reserve(struct radeon_bo *bo, bool no_wait)
  501. {
  502. int r;
  503. r = ttm_bo_reserve(&bo->tbo, true, no_wait, false, 0);
  504. if (unlikely(r != 0)) {
  505. if (r != -ERESTARTSYS)
  506. dev_err(bo->rdev->dev, "%p reserve failed\n", bo);
  507. return r;
  508. }
  509. return 0;
  510. }
  511. /* object have to be reserved */
  512. struct radeon_bo_va *radeon_bo_va(struct radeon_bo *rbo, struct radeon_vm *vm)
  513. {
  514. struct radeon_bo_va *bo_va;
  515. list_for_each_entry(bo_va, &rbo->va, bo_list) {
  516. if (bo_va->vm == vm) {
  517. return bo_va;
  518. }
  519. }
  520. return NULL;
  521. }