| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: amdgpu_device.c,v 1.17 2022/09/20 23:01:42 mrg Exp $ */ | | 1 | /* $NetBSD: amdgpu_device.c,v 1.17.4.1 2023/02/24 14:11:29 martin Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright 2008 Advanced Micro Devices, Inc. | | 4 | * Copyright 2008 Advanced Micro Devices, Inc. |
5 | * Copyright 2008 Red Hat Inc. | | 5 | * Copyright 2008 Red Hat Inc. |
6 | * Copyright 2009 Jerome Glisse. | | 6 | * Copyright 2009 Jerome Glisse. |
7 | * | | 7 | * |
8 | * Permission is hereby granted, free of charge, to any person obtaining a | | 8 | * Permission is hereby granted, free of charge, to any person obtaining a |
9 | * copy of this software and associated documentation files (the "Software"), | | 9 | * copy of this software and associated documentation files (the "Software"), |
10 | * to deal in the Software without restriction, including without limitation | | 10 | * to deal in the Software without restriction, including without limitation |
11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | | 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
12 | * and/or sell copies of the Software, and to permit persons to whom the | | 12 | * and/or sell copies of the Software, and to permit persons to whom the |
13 | * Software is furnished to do so, subject to the following conditions: | | 13 | * Software is furnished to do so, subject to the following conditions: |
14 | * | | 14 | * |
| @@ -18,27 +18,27 @@ | | | @@ -18,27 +18,27 @@ |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | | 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
21 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR | | 21 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
22 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | | 22 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
23 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | | 23 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
24 | * OTHER DEALINGS IN THE SOFTWARE. | | 24 | * OTHER DEALINGS IN THE SOFTWARE. |
25 | * | | 25 | * |
26 | * Authors: Dave Airlie | | 26 | * Authors: Dave Airlie |
27 | * Alex Deucher | | 27 | * Alex Deucher |
28 | * Jerome Glisse | | 28 | * Jerome Glisse |
29 | */ | | 29 | */ |
30 | #include <sys/cdefs.h> | | 30 | #include <sys/cdefs.h> |
31 | __KERNEL_RCSID(0, "$NetBSD: amdgpu_device.c,v 1.17 2022/09/20 23:01:42 mrg Exp $"); | | 31 | __KERNEL_RCSID(0, "$NetBSD: amdgpu_device.c,v 1.17.4.1 2023/02/24 14:11:29 martin Exp $"); |
32 | | | 32 | |
33 | #include <linux/power_supply.h> | | 33 | #include <linux/power_supply.h> |
34 | #include <linux/kthread.h> | | 34 | #include <linux/kthread.h> |
35 | #include <linux/module.h> | | 35 | #include <linux/module.h> |
36 | #include <linux/console.h> | | 36 | #include <linux/console.h> |
37 | #include <linux/slab.h> | | 37 | #include <linux/slab.h> |
38 | #include <linux/reboot.h> | | 38 | #include <linux/reboot.h> |
39 | | | 39 | |
40 | #include <drm/drm_atomic_helper.h> | | 40 | #include <drm/drm_atomic_helper.h> |
41 | #include <drm/drm_probe_helper.h> | | 41 | #include <drm/drm_probe_helper.h> |
42 | #include <drm/amdgpu_drm.h> | | 42 | #include <drm/amdgpu_drm.h> |
43 | #include <linux/vgaarb.h> | | 43 | #include <linux/vgaarb.h> |
44 | #include <linux/vga_switcheroo.h> | | 44 | #include <linux/vga_switcheroo.h> |
| @@ -473,39 +473,39 @@ void amdgpu_mm_wdoorbell(struct amdgpu_d | | | @@ -473,39 +473,39 @@ void amdgpu_mm_wdoorbell(struct amdgpu_d |
473 | * | | 473 | * |
474 | * @adev: amdgpu_device pointer | | 474 | * @adev: amdgpu_device pointer |
475 | * @index: doorbell index | | 475 | * @index: doorbell index |
476 | * | | 476 | * |
477 | * Returns the value in the doorbell aperture at the | | 477 | * Returns the value in the doorbell aperture at the |
478 | * requested doorbell index (VEGA10+). | | 478 | * requested doorbell index (VEGA10+). |
479 | */ | | 479 | */ |
480 | u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index) | | 480 | u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index) |
481 | { | | 481 | { |
482 | if (index < adev->doorbell.num_doorbells) { | | 482 | if (index < adev->doorbell.num_doorbells) { |
483 | #ifdef __NetBSD__ | | 483 | #ifdef __NetBSD__ |
484 | #ifdef _LP64 | | 484 | #ifdef _LP64 |
485 | return bus_space_read_8(adev->doorbell.bst, adev->doorbell.bsh, | | 485 | return bus_space_read_8(adev->doorbell.bst, adev->doorbell.bsh, |
486 | 8*index); | | 486 | 4*index); |
487 | #else | | 487 | #else |
488 | uint64_t lo, hi; | | 488 | uint64_t lo, hi; |
489 | #if _BYTE_ORDER == _LITTLE_ENDIAN | | 489 | #if _BYTE_ORDER == _LITTLE_ENDIAN |
490 | lo = bus_space_read_4(adev->doorbell.bst, adev->doorbell.bsh, | | 490 | lo = bus_space_read_4(adev->doorbell.bst, adev->doorbell.bsh, |
491 | 8*index); | | 491 | 4*index); |
492 | hi = bus_space_read_4(adev->doorbell.bst, adev->doorbell.bsh, | | 492 | hi = bus_space_read_4(adev->doorbell.bst, adev->doorbell.bsh, |
493 | 8*index + 4); | | 493 | 4*index + 4); |
494 | #else | | 494 | #else |
495 | hi = bus_space_read_4(adev->doorbell.bst, adev->doorbell.bsh, | | 495 | hi = bus_space_read_4(adev->doorbell.bst, adev->doorbell.bsh, |
496 | 8*index); | | 496 | 4*index); |
497 | lo = bus_space_read_4(adev->doorbell.bst, adev->doorbell.bsh, | | 497 | lo = bus_space_read_4(adev->doorbell.bst, adev->doorbell.bsh, |
498 | 8*index + 4); | | 498 | 4*index + 4); |
499 | #endif | | 499 | #endif |
500 | return lo | (hi << 32); | | 500 | return lo | (hi << 32); |
501 | #endif | | 501 | #endif |
502 | #else | | 502 | #else |
503 | return atomic64_read((atomic64_t *)(adev->doorbell.ptr + index)); | | 503 | return atomic64_read((atomic64_t *)(adev->doorbell.ptr + index)); |
504 | #endif | | 504 | #endif |
505 | } else { | | 505 | } else { |
506 | DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index); | | 506 | DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index); |
507 | return 0; | | 507 | return 0; |
508 | } | | 508 | } |
509 | } | | 509 | } |
510 | | | 510 | |
511 | /** | | 511 | /** |
| @@ -514,41 +514,41 @@ u64 amdgpu_mm_rdoorbell64(struct amdgpu_ | | | @@ -514,41 +514,41 @@ u64 amdgpu_mm_rdoorbell64(struct amdgpu_ |
514 | * @adev: amdgpu_device pointer | | 514 | * @adev: amdgpu_device pointer |
515 | * @index: doorbell index | | 515 | * @index: doorbell index |
516 | * @v: value to write | | 516 | * @v: value to write |
517 | * | | 517 | * |
518 | * Writes @v to the doorbell aperture at the | | 518 | * Writes @v to the doorbell aperture at the |
519 | * requested doorbell index (VEGA10+). | | 519 | * requested doorbell index (VEGA10+). |
520 | */ | | 520 | */ |
521 | void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v) | | 521 | void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v) |
522 | { | | 522 | { |
523 | if (index < adev->doorbell.num_doorbells) { | | 523 | if (index < adev->doorbell.num_doorbells) { |
524 | #ifdef __NetBSD__ | | 524 | #ifdef __NetBSD__ |
525 | #ifdef _LP64 | | 525 | #ifdef _LP64 |
526 | bus_space_write_8(adev->doorbell.bst, adev->doorbell.bsh, | | 526 | bus_space_write_8(adev->doorbell.bst, adev->doorbell.bsh, |
527 | 8*index, v); | | 527 | 4*index, v); |
528 | #else | | 528 | #else |
529 | /* | | 529 | /* |
530 | * XXX This might not be as atomic as one might hope... | | 530 | * XXX This might not be as atomic as one might hope... |
531 | */ | | 531 | */ |
532 | #if _BYTE_ORDER == _LITTLE_ENDIAN | | 532 | #if _BYTE_ORDER == _LITTLE_ENDIAN |
533 | bus_space_write_4(adev->doorbell.bst, adev->doorbell.bsh, | | 533 | bus_space_write_4(adev->doorbell.bst, adev->doorbell.bsh, |
534 | 8*index, v & 0xffffffffU); | | 534 | 4*index, v & 0xffffffffU); |
535 | bus_space_write_4(adev->doorbell.bst, adev->doorbell.bsh, | | 535 | bus_space_write_4(adev->doorbell.bst, adev->doorbell.bsh, |
536 | 8*index + 4, v >> 32); | | 536 | 4*index + 4, v >> 32); |
537 | #else | | 537 | #else |
538 | bus_space_write_4(adev->doorbell.bst, adev->doorbell.bsh, | | 538 | bus_space_write_4(adev->doorbell.bst, adev->doorbell.bsh, |
539 | 8*index, v >> 32); | | 539 | 4*index, v >> 32); |
540 | bus_space_write_4(adev->doorbell.bst, adev->doorbell.bsh, | | 540 | bus_space_write_4(adev->doorbell.bst, adev->doorbell.bsh, |
541 | 8*index + 4, v & 0xffffffffU); | | 541 | 4*index + 4, v & 0xffffffffU); |
542 | #endif | | 542 | #endif |
543 | #endif | | 543 | #endif |
544 | #else | | 544 | #else |
545 | atomic64_set((atomic64_t *)(adev->doorbell.ptr + index), v); | | 545 | atomic64_set((atomic64_t *)(adev->doorbell.ptr + index), v); |
546 | #endif | | 546 | #endif |
547 | } else { | | 547 | } else { |
548 | DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index); | | 548 | DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index); |
549 | } | | 549 | } |
550 | } | | 550 | } |
551 | | | 551 | |
552 | /** | | 552 | /** |
553 | * amdgpu_invalid_rreg - dummy reg read function | | 553 | * amdgpu_invalid_rreg - dummy reg read function |
554 | * | | 554 | * |