1771fe6b9SJerome Glisse /* 2771fe6b9SJerome Glisse * Copyright 2008 Advanced Micro Devices, Inc. 3771fe6b9SJerome Glisse * Copyright 2008 Red Hat Inc. 4771fe6b9SJerome Glisse * Copyright 2009 Jerome Glisse. 5771fe6b9SJerome Glisse * 6771fe6b9SJerome Glisse * Permission is hereby granted, free of charge, to any person obtaining a 7771fe6b9SJerome Glisse * copy of this software and associated documentation files (the "Software"), 8771fe6b9SJerome Glisse * to deal in the Software without restriction, including without limitation 9771fe6b9SJerome Glisse * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10771fe6b9SJerome Glisse * and/or sell copies of the Software, and to permit persons to whom the 11771fe6b9SJerome Glisse * Software is furnished to do so, subject to the following conditions: 12771fe6b9SJerome Glisse * 13771fe6b9SJerome Glisse * The above copyright notice and this permission notice shall be included in 14771fe6b9SJerome Glisse * all copies or substantial portions of the Software. 15771fe6b9SJerome Glisse * 16771fe6b9SJerome Glisse * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17771fe6b9SJerome Glisse * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18771fe6b9SJerome Glisse * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19771fe6b9SJerome Glisse * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20771fe6b9SJerome Glisse * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21771fe6b9SJerome Glisse * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22771fe6b9SJerome Glisse * OTHER DEALINGS IN THE SOFTWARE. 23771fe6b9SJerome Glisse * 24771fe6b9SJerome Glisse * Authors: Dave Airlie 25771fe6b9SJerome Glisse * Alex Deucher 26771fe6b9SJerome Glisse * Jerome Glisse 27771fe6b9SJerome Glisse */ 28771fe6b9SJerome Glisse #include <linux/seq_file.h> 29771fe6b9SJerome Glisse #include "drmP.h" 30771fe6b9SJerome Glisse #include "drm.h" 31771fe6b9SJerome Glisse #include "radeon_drm.h" 32771fe6b9SJerome Glisse #include "radeon_reg.h" 33771fe6b9SJerome Glisse #include "radeon.h" 34e6990375SDaniel Vetter #include "radeon_asic.h" 353ce0a23dSJerome Glisse #include "r100d.h" 36d4550907SJerome Glisse #include "rs100d.h" 37d4550907SJerome Glisse #include "rv200d.h" 38d4550907SJerome Glisse #include "rv250d.h" 393ce0a23dSJerome Glisse 4070967ab9SBen Hutchings #include <linux/firmware.h> 4170967ab9SBen Hutchings #include <linux/platform_device.h> 4270967ab9SBen Hutchings 43551ebd83SDave Airlie #include "r100_reg_safe.h" 44551ebd83SDave Airlie #include "rn50_reg_safe.h" 45551ebd83SDave Airlie 4670967ab9SBen Hutchings /* Firmware Names */ 4770967ab9SBen Hutchings #define FIRMWARE_R100 "radeon/R100_cp.bin" 4870967ab9SBen Hutchings #define FIRMWARE_R200 "radeon/R200_cp.bin" 4970967ab9SBen Hutchings #define FIRMWARE_R300 "radeon/R300_cp.bin" 5070967ab9SBen Hutchings #define FIRMWARE_R420 "radeon/R420_cp.bin" 5170967ab9SBen Hutchings #define FIRMWARE_RS690 "radeon/RS690_cp.bin" 5270967ab9SBen Hutchings #define FIRMWARE_RS600 "radeon/RS600_cp.bin" 5370967ab9SBen Hutchings #define FIRMWARE_R520 "radeon/R520_cp.bin" 5470967ab9SBen Hutchings 5570967ab9SBen Hutchings MODULE_FIRMWARE(FIRMWARE_R100); 5670967ab9SBen Hutchings MODULE_FIRMWARE(FIRMWARE_R200); 5770967ab9SBen Hutchings MODULE_FIRMWARE(FIRMWARE_R300); 5870967ab9SBen Hutchings MODULE_FIRMWARE(FIRMWARE_R420); 5970967ab9SBen Hutchings MODULE_FIRMWARE(FIRMWARE_RS690); 6070967ab9SBen Hutchings MODULE_FIRMWARE(FIRMWARE_RS600); 6170967ab9SBen Hutchings MODULE_FIRMWARE(FIRMWARE_R520); 62771fe6b9SJerome Glisse 63551ebd83SDave Airlie #include "r100_track.h" 64551ebd83SDave Airlie 65771fe6b9SJerome Glisse /* This files gather functions specifics to: 66771fe6b9SJerome Glisse * r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280 67771fe6b9SJerome Glisse */ 68771fe6b9SJerome Glisse 6905a05c50SAlex Deucher /* hpd for digital panel detect/disconnect */ 7005a05c50SAlex Deucher bool r100_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd) 7105a05c50SAlex Deucher { 7205a05c50SAlex Deucher bool connected = false; 7305a05c50SAlex Deucher 7405a05c50SAlex Deucher switch (hpd) { 7505a05c50SAlex Deucher case RADEON_HPD_1: 7605a05c50SAlex Deucher if (RREG32(RADEON_FP_GEN_CNTL) & RADEON_FP_DETECT_SENSE) 7705a05c50SAlex Deucher connected = true; 7805a05c50SAlex Deucher break; 7905a05c50SAlex Deucher case RADEON_HPD_2: 8005a05c50SAlex Deucher if (RREG32(RADEON_FP2_GEN_CNTL) & RADEON_FP2_DETECT_SENSE) 8105a05c50SAlex Deucher connected = true; 8205a05c50SAlex Deucher break; 8305a05c50SAlex Deucher default: 8405a05c50SAlex Deucher break; 8505a05c50SAlex Deucher } 8605a05c50SAlex Deucher return connected; 8705a05c50SAlex Deucher } 8805a05c50SAlex Deucher 8905a05c50SAlex Deucher void r100_hpd_set_polarity(struct radeon_device *rdev, 9005a05c50SAlex Deucher enum radeon_hpd_id hpd) 9105a05c50SAlex Deucher { 9205a05c50SAlex Deucher u32 tmp; 9305a05c50SAlex Deucher bool connected = r100_hpd_sense(rdev, hpd); 9405a05c50SAlex Deucher 9505a05c50SAlex Deucher switch (hpd) { 9605a05c50SAlex Deucher case RADEON_HPD_1: 9705a05c50SAlex Deucher tmp = RREG32(RADEON_FP_GEN_CNTL); 9805a05c50SAlex Deucher if (connected) 9905a05c50SAlex Deucher tmp &= ~RADEON_FP_DETECT_INT_POL; 10005a05c50SAlex Deucher else 10105a05c50SAlex Deucher tmp |= RADEON_FP_DETECT_INT_POL; 10205a05c50SAlex Deucher WREG32(RADEON_FP_GEN_CNTL, tmp); 10305a05c50SAlex Deucher break; 10405a05c50SAlex Deucher case RADEON_HPD_2: 10505a05c50SAlex Deucher tmp = RREG32(RADEON_FP2_GEN_CNTL); 10605a05c50SAlex Deucher if (connected) 10705a05c50SAlex Deucher tmp &= ~RADEON_FP2_DETECT_INT_POL; 10805a05c50SAlex Deucher else 10905a05c50SAlex Deucher tmp |= RADEON_FP2_DETECT_INT_POL; 11005a05c50SAlex Deucher WREG32(RADEON_FP2_GEN_CNTL, tmp); 11105a05c50SAlex Deucher break; 11205a05c50SAlex Deucher default: 11305a05c50SAlex Deucher break; 11405a05c50SAlex Deucher } 11505a05c50SAlex Deucher } 11605a05c50SAlex Deucher 11705a05c50SAlex Deucher void r100_hpd_init(struct radeon_device *rdev) 11805a05c50SAlex Deucher { 11905a05c50SAlex Deucher struct drm_device *dev = rdev->ddev; 12005a05c50SAlex Deucher struct drm_connector *connector; 12105a05c50SAlex Deucher 12205a05c50SAlex Deucher list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 12305a05c50SAlex Deucher struct radeon_connector *radeon_connector = to_radeon_connector(connector); 12405a05c50SAlex Deucher switch (radeon_connector->hpd.hpd) { 12505a05c50SAlex Deucher case RADEON_HPD_1: 12605a05c50SAlex Deucher rdev->irq.hpd[0] = true; 12705a05c50SAlex Deucher break; 12805a05c50SAlex Deucher case RADEON_HPD_2: 12905a05c50SAlex Deucher rdev->irq.hpd[1] = true; 13005a05c50SAlex Deucher break; 13105a05c50SAlex Deucher default: 13205a05c50SAlex Deucher break; 13305a05c50SAlex Deucher } 13405a05c50SAlex Deucher } 135003e69f9SJerome Glisse if (rdev->irq.installed) 13605a05c50SAlex Deucher r100_irq_set(rdev); 13705a05c50SAlex Deucher } 13805a05c50SAlex Deucher 13905a05c50SAlex Deucher void r100_hpd_fini(struct radeon_device *rdev) 14005a05c50SAlex Deucher { 14105a05c50SAlex Deucher struct drm_device *dev = rdev->ddev; 14205a05c50SAlex Deucher struct drm_connector *connector; 14305a05c50SAlex Deucher 14405a05c50SAlex Deucher list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 14505a05c50SAlex Deucher struct radeon_connector *radeon_connector = to_radeon_connector(connector); 14605a05c50SAlex Deucher switch (radeon_connector->hpd.hpd) { 14705a05c50SAlex Deucher case RADEON_HPD_1: 14805a05c50SAlex Deucher rdev->irq.hpd[0] = false; 14905a05c50SAlex Deucher break; 15005a05c50SAlex Deucher case RADEON_HPD_2: 15105a05c50SAlex Deucher rdev->irq.hpd[1] = false; 15205a05c50SAlex Deucher break; 15305a05c50SAlex Deucher default: 15405a05c50SAlex Deucher break; 15505a05c50SAlex Deucher } 15605a05c50SAlex Deucher } 15705a05c50SAlex Deucher } 15805a05c50SAlex Deucher 159771fe6b9SJerome Glisse /* 160771fe6b9SJerome Glisse * PCI GART 161771fe6b9SJerome Glisse */ 162771fe6b9SJerome Glisse void r100_pci_gart_tlb_flush(struct radeon_device *rdev) 163771fe6b9SJerome Glisse { 164771fe6b9SJerome Glisse /* TODO: can we do somethings here ? */ 165771fe6b9SJerome Glisse /* It seems hw only cache one entry so we should discard this 166771fe6b9SJerome Glisse * entry otherwise if first GPU GART read hit this entry it 167771fe6b9SJerome Glisse * could end up in wrong address. */ 168771fe6b9SJerome Glisse } 169771fe6b9SJerome Glisse 1704aac0473SJerome Glisse int r100_pci_gart_init(struct radeon_device *rdev) 1714aac0473SJerome Glisse { 1724aac0473SJerome Glisse int r; 1734aac0473SJerome Glisse 1744aac0473SJerome Glisse if (rdev->gart.table.ram.ptr) { 1754aac0473SJerome Glisse WARN(1, "R100 PCI GART already initialized.\n"); 1764aac0473SJerome Glisse return 0; 1774aac0473SJerome Glisse } 1784aac0473SJerome Glisse /* Initialize common gart structure */ 1794aac0473SJerome Glisse r = radeon_gart_init(rdev); 1804aac0473SJerome Glisse if (r) 1814aac0473SJerome Glisse return r; 1824aac0473SJerome Glisse rdev->gart.table_size = rdev->gart.num_gpu_pages * 4; 1834aac0473SJerome Glisse rdev->asic->gart_tlb_flush = &r100_pci_gart_tlb_flush; 1844aac0473SJerome Glisse rdev->asic->gart_set_page = &r100_pci_gart_set_page; 1854aac0473SJerome Glisse return radeon_gart_table_ram_alloc(rdev); 1864aac0473SJerome Glisse } 1874aac0473SJerome Glisse 18817e15b0cSDave Airlie /* required on r1xx, r2xx, r300, r(v)350, r420/r481, rs400/rs480 */ 18917e15b0cSDave Airlie void r100_enable_bm(struct radeon_device *rdev) 19017e15b0cSDave Airlie { 19117e15b0cSDave Airlie uint32_t tmp; 19217e15b0cSDave Airlie /* Enable bus mastering */ 19317e15b0cSDave Airlie tmp = RREG32(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS; 19417e15b0cSDave Airlie WREG32(RADEON_BUS_CNTL, tmp); 19517e15b0cSDave Airlie } 19617e15b0cSDave Airlie 197771fe6b9SJerome Glisse int r100_pci_gart_enable(struct radeon_device *rdev) 198771fe6b9SJerome Glisse { 199771fe6b9SJerome Glisse uint32_t tmp; 200771fe6b9SJerome Glisse 20182568565SDave Airlie radeon_gart_restore(rdev); 202771fe6b9SJerome Glisse /* discard memory request outside of configured range */ 203771fe6b9SJerome Glisse tmp = RREG32(RADEON_AIC_CNTL) | RADEON_DIS_OUT_OF_PCI_GART_ACCESS; 204771fe6b9SJerome Glisse WREG32(RADEON_AIC_CNTL, tmp); 205771fe6b9SJerome Glisse /* set address range for PCI address translate */ 206d594e46aSJerome Glisse WREG32(RADEON_AIC_LO_ADDR, rdev->mc.gtt_start); 207d594e46aSJerome Glisse WREG32(RADEON_AIC_HI_ADDR, rdev->mc.gtt_end); 208771fe6b9SJerome Glisse /* set PCI GART page-table base address */ 209771fe6b9SJerome Glisse WREG32(RADEON_AIC_PT_BASE, rdev->gart.table_addr); 210771fe6b9SJerome Glisse tmp = RREG32(RADEON_AIC_CNTL) | RADEON_PCIGART_TRANSLATE_EN; 211771fe6b9SJerome Glisse WREG32(RADEON_AIC_CNTL, tmp); 212771fe6b9SJerome Glisse r100_pci_gart_tlb_flush(rdev); 213771fe6b9SJerome Glisse rdev->gart.ready = true; 214771fe6b9SJerome Glisse return 0; 215771fe6b9SJerome Glisse } 216771fe6b9SJerome Glisse 217771fe6b9SJerome Glisse void r100_pci_gart_disable(struct radeon_device *rdev) 218771fe6b9SJerome Glisse { 219771fe6b9SJerome Glisse uint32_t tmp; 220771fe6b9SJerome Glisse 221771fe6b9SJerome Glisse /* discard memory request outside of configured range */ 222771fe6b9SJerome Glisse tmp = RREG32(RADEON_AIC_CNTL) | RADEON_DIS_OUT_OF_PCI_GART_ACCESS; 223771fe6b9SJerome Glisse WREG32(RADEON_AIC_CNTL, tmp & ~RADEON_PCIGART_TRANSLATE_EN); 224771fe6b9SJerome Glisse WREG32(RADEON_AIC_LO_ADDR, 0); 225771fe6b9SJerome Glisse WREG32(RADEON_AIC_HI_ADDR, 0); 226771fe6b9SJerome Glisse } 227771fe6b9SJerome Glisse 228771fe6b9SJerome Glisse int r100_pci_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr) 229771fe6b9SJerome Glisse { 230771fe6b9SJerome Glisse if (i < 0 || i > rdev->gart.num_gpu_pages) { 231771fe6b9SJerome Glisse return -EINVAL; 232771fe6b9SJerome Glisse } 233ed10f95dSDave Airlie rdev->gart.table.ram.ptr[i] = cpu_to_le32(lower_32_bits(addr)); 234771fe6b9SJerome Glisse return 0; 235771fe6b9SJerome Glisse } 236771fe6b9SJerome Glisse 2374aac0473SJerome Glisse void r100_pci_gart_fini(struct radeon_device *rdev) 238771fe6b9SJerome Glisse { 239f9274562SJerome Glisse radeon_gart_fini(rdev); 240771fe6b9SJerome Glisse r100_pci_gart_disable(rdev); 2414aac0473SJerome Glisse radeon_gart_table_ram_free(rdev); 242771fe6b9SJerome Glisse } 243771fe6b9SJerome Glisse 2447ed220d7SMichel Dänzer int r100_irq_set(struct radeon_device *rdev) 2457ed220d7SMichel Dänzer { 2467ed220d7SMichel Dänzer uint32_t tmp = 0; 2477ed220d7SMichel Dänzer 248003e69f9SJerome Glisse if (!rdev->irq.installed) { 249003e69f9SJerome Glisse WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n"); 250003e69f9SJerome Glisse WREG32(R_000040_GEN_INT_CNTL, 0); 251003e69f9SJerome Glisse return -EINVAL; 252003e69f9SJerome Glisse } 2537ed220d7SMichel Dänzer if (rdev->irq.sw_int) { 2547ed220d7SMichel Dänzer tmp |= RADEON_SW_INT_ENABLE; 2557ed220d7SMichel Dänzer } 2567ed220d7SMichel Dänzer if (rdev->irq.crtc_vblank_int[0]) { 2577ed220d7SMichel Dänzer tmp |= RADEON_CRTC_VBLANK_MASK; 2587ed220d7SMichel Dänzer } 2597ed220d7SMichel Dänzer if (rdev->irq.crtc_vblank_int[1]) { 2607ed220d7SMichel Dänzer tmp |= RADEON_CRTC2_VBLANK_MASK; 2617ed220d7SMichel Dänzer } 26205a05c50SAlex Deucher if (rdev->irq.hpd[0]) { 26305a05c50SAlex Deucher tmp |= RADEON_FP_DETECT_MASK; 26405a05c50SAlex Deucher } 26505a05c50SAlex Deucher if (rdev->irq.hpd[1]) { 26605a05c50SAlex Deucher tmp |= RADEON_FP2_DETECT_MASK; 26705a05c50SAlex Deucher } 2687ed220d7SMichel Dänzer WREG32(RADEON_GEN_INT_CNTL, tmp); 2697ed220d7SMichel Dänzer return 0; 2707ed220d7SMichel Dänzer } 2717ed220d7SMichel Dänzer 2729f022ddfSJerome Glisse void r100_irq_disable(struct radeon_device *rdev) 2739f022ddfSJerome Glisse { 2749f022ddfSJerome Glisse u32 tmp; 2759f022ddfSJerome Glisse 2769f022ddfSJerome Glisse WREG32(R_000040_GEN_INT_CNTL, 0); 2779f022ddfSJerome Glisse /* Wait and acknowledge irq */ 2789f022ddfSJerome Glisse mdelay(1); 2799f022ddfSJerome Glisse tmp = RREG32(R_000044_GEN_INT_STATUS); 2809f022ddfSJerome Glisse WREG32(R_000044_GEN_INT_STATUS, tmp); 2819f022ddfSJerome Glisse } 2829f022ddfSJerome Glisse 2837ed220d7SMichel Dänzer static inline uint32_t r100_irq_ack(struct radeon_device *rdev) 2847ed220d7SMichel Dänzer { 2857ed220d7SMichel Dänzer uint32_t irqs = RREG32(RADEON_GEN_INT_STATUS); 28605a05c50SAlex Deucher uint32_t irq_mask = RADEON_SW_INT_TEST | 28705a05c50SAlex Deucher RADEON_CRTC_VBLANK_STAT | RADEON_CRTC2_VBLANK_STAT | 28805a05c50SAlex Deucher RADEON_FP_DETECT_STAT | RADEON_FP2_DETECT_STAT; 2897ed220d7SMichel Dänzer 2907ed220d7SMichel Dänzer if (irqs) { 2917ed220d7SMichel Dänzer WREG32(RADEON_GEN_INT_STATUS, irqs); 2927ed220d7SMichel Dänzer } 2937ed220d7SMichel Dänzer return irqs & irq_mask; 2947ed220d7SMichel Dänzer } 2957ed220d7SMichel Dänzer 2967ed220d7SMichel Dänzer int r100_irq_process(struct radeon_device *rdev) 2977ed220d7SMichel Dänzer { 2983e5cb98dSAlex Deucher uint32_t status, msi_rearm; 299d4877cf2SAlex Deucher bool queue_hotplug = false; 3007ed220d7SMichel Dänzer 3017ed220d7SMichel Dänzer status = r100_irq_ack(rdev); 3027ed220d7SMichel Dänzer if (!status) { 3037ed220d7SMichel Dänzer return IRQ_NONE; 3047ed220d7SMichel Dänzer } 305a513c184SJerome Glisse if (rdev->shutdown) { 306a513c184SJerome Glisse return IRQ_NONE; 307a513c184SJerome Glisse } 3087ed220d7SMichel Dänzer while (status) { 3097ed220d7SMichel Dänzer /* SW interrupt */ 3107ed220d7SMichel Dänzer if (status & RADEON_SW_INT_TEST) { 3117ed220d7SMichel Dänzer radeon_fence_process(rdev); 3127ed220d7SMichel Dänzer } 3137ed220d7SMichel Dänzer /* Vertical blank interrupts */ 3147ed220d7SMichel Dänzer if (status & RADEON_CRTC_VBLANK_STAT) { 3157ed220d7SMichel Dänzer drm_handle_vblank(rdev->ddev, 0); 316839461d3SRafał Miłecki rdev->pm.vblank_sync = true; 31773a6d3fcSRafał Miłecki wake_up(&rdev->irq.vblank_queue); 3187ed220d7SMichel Dänzer } 3197ed220d7SMichel Dänzer if (status & RADEON_CRTC2_VBLANK_STAT) { 3207ed220d7SMichel Dänzer drm_handle_vblank(rdev->ddev, 1); 321839461d3SRafał Miłecki rdev->pm.vblank_sync = true; 32273a6d3fcSRafał Miłecki wake_up(&rdev->irq.vblank_queue); 3237ed220d7SMichel Dänzer } 32405a05c50SAlex Deucher if (status & RADEON_FP_DETECT_STAT) { 325d4877cf2SAlex Deucher queue_hotplug = true; 326d4877cf2SAlex Deucher DRM_DEBUG("HPD1\n"); 32705a05c50SAlex Deucher } 32805a05c50SAlex Deucher if (status & RADEON_FP2_DETECT_STAT) { 329d4877cf2SAlex Deucher queue_hotplug = true; 330d4877cf2SAlex Deucher DRM_DEBUG("HPD2\n"); 33105a05c50SAlex Deucher } 3327ed220d7SMichel Dänzer status = r100_irq_ack(rdev); 3337ed220d7SMichel Dänzer } 334d4877cf2SAlex Deucher if (queue_hotplug) 335d4877cf2SAlex Deucher queue_work(rdev->wq, &rdev->hotplug_work); 3363e5cb98dSAlex Deucher if (rdev->msi_enabled) { 3373e5cb98dSAlex Deucher switch (rdev->family) { 3383e5cb98dSAlex Deucher case CHIP_RS400: 3393e5cb98dSAlex Deucher case CHIP_RS480: 3403e5cb98dSAlex Deucher msi_rearm = RREG32(RADEON_AIC_CNTL) & ~RS400_MSI_REARM; 3413e5cb98dSAlex Deucher WREG32(RADEON_AIC_CNTL, msi_rearm); 3423e5cb98dSAlex Deucher WREG32(RADEON_AIC_CNTL, msi_rearm | RS400_MSI_REARM); 3433e5cb98dSAlex Deucher break; 3443e5cb98dSAlex Deucher default: 3453e5cb98dSAlex Deucher msi_rearm = RREG32(RADEON_MSI_REARM_EN) & ~RV370_MSI_REARM_EN; 3463e5cb98dSAlex Deucher WREG32(RADEON_MSI_REARM_EN, msi_rearm); 3473e5cb98dSAlex Deucher WREG32(RADEON_MSI_REARM_EN, msi_rearm | RV370_MSI_REARM_EN); 3483e5cb98dSAlex Deucher break; 3493e5cb98dSAlex Deucher } 3503e5cb98dSAlex Deucher } 3517ed220d7SMichel Dänzer return IRQ_HANDLED; 3527ed220d7SMichel Dänzer } 3537ed220d7SMichel Dänzer 3547ed220d7SMichel Dänzer u32 r100_get_vblank_counter(struct radeon_device *rdev, int crtc) 3557ed220d7SMichel Dänzer { 3567ed220d7SMichel Dänzer if (crtc == 0) 3577ed220d7SMichel Dänzer return RREG32(RADEON_CRTC_CRNT_FRAME); 3587ed220d7SMichel Dänzer else 3597ed220d7SMichel Dänzer return RREG32(RADEON_CRTC2_CRNT_FRAME); 3607ed220d7SMichel Dänzer } 3617ed220d7SMichel Dänzer 3629e5b2af7SPauli Nieminen /* Who ever call radeon_fence_emit should call ring_lock and ask 3639e5b2af7SPauli Nieminen * for enough space (today caller are ib schedule and buffer move) */ 364771fe6b9SJerome Glisse void r100_fence_ring_emit(struct radeon_device *rdev, 365771fe6b9SJerome Glisse struct radeon_fence *fence) 366771fe6b9SJerome Glisse { 3679e5b2af7SPauli Nieminen /* We have to make sure that caches are flushed before 3689e5b2af7SPauli Nieminen * CPU might read something from VRAM. */ 3699e5b2af7SPauli Nieminen radeon_ring_write(rdev, PACKET0(RADEON_RB3D_DSTCACHE_CTLSTAT, 0)); 3709e5b2af7SPauli Nieminen radeon_ring_write(rdev, RADEON_RB3D_DC_FLUSH_ALL); 3719e5b2af7SPauli Nieminen radeon_ring_write(rdev, PACKET0(RADEON_RB3D_ZCACHE_CTLSTAT, 0)); 3729e5b2af7SPauli Nieminen radeon_ring_write(rdev, RADEON_RB3D_ZC_FLUSH_ALL); 373771fe6b9SJerome Glisse /* Wait until IDLE & CLEAN */ 3744612dc97SAlex Deucher radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0)); 3754612dc97SAlex Deucher radeon_ring_write(rdev, RADEON_WAIT_2D_IDLECLEAN | RADEON_WAIT_3D_IDLECLEAN); 376cafe6609SJerome Glisse radeon_ring_write(rdev, PACKET0(RADEON_HOST_PATH_CNTL, 0)); 377cafe6609SJerome Glisse radeon_ring_write(rdev, rdev->config.r100.hdp_cntl | 378cafe6609SJerome Glisse RADEON_HDP_READ_BUFFER_INVALIDATE); 379cafe6609SJerome Glisse radeon_ring_write(rdev, PACKET0(RADEON_HOST_PATH_CNTL, 0)); 380cafe6609SJerome Glisse radeon_ring_write(rdev, rdev->config.r100.hdp_cntl); 381771fe6b9SJerome Glisse /* Emit fence sequence & fire IRQ */ 382771fe6b9SJerome Glisse radeon_ring_write(rdev, PACKET0(rdev->fence_drv.scratch_reg, 0)); 383771fe6b9SJerome Glisse radeon_ring_write(rdev, fence->seq); 384771fe6b9SJerome Glisse radeon_ring_write(rdev, PACKET0(RADEON_GEN_INT_STATUS, 0)); 385771fe6b9SJerome Glisse radeon_ring_write(rdev, RADEON_SW_INT_FIRE); 386771fe6b9SJerome Glisse } 387771fe6b9SJerome Glisse 388771fe6b9SJerome Glisse int r100_wb_init(struct radeon_device *rdev) 389771fe6b9SJerome Glisse { 390771fe6b9SJerome Glisse int r; 391771fe6b9SJerome Glisse 392771fe6b9SJerome Glisse if (rdev->wb.wb_obj == NULL) { 3934c788679SJerome Glisse r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE, true, 394771fe6b9SJerome Glisse RADEON_GEM_DOMAIN_GTT, 3954c788679SJerome Glisse &rdev->wb.wb_obj); 396771fe6b9SJerome Glisse if (r) { 3974c788679SJerome Glisse dev_err(rdev->dev, "(%d) create WB buffer failed\n", r); 398771fe6b9SJerome Glisse return r; 399771fe6b9SJerome Glisse } 4004c788679SJerome Glisse r = radeon_bo_reserve(rdev->wb.wb_obj, false); 4014c788679SJerome Glisse if (unlikely(r != 0)) 4024c788679SJerome Glisse return r; 4034c788679SJerome Glisse r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT, 404771fe6b9SJerome Glisse &rdev->wb.gpu_addr); 405771fe6b9SJerome Glisse if (r) { 4064c788679SJerome Glisse dev_err(rdev->dev, "(%d) pin WB buffer failed\n", r); 4074c788679SJerome Glisse radeon_bo_unreserve(rdev->wb.wb_obj); 408771fe6b9SJerome Glisse return r; 409771fe6b9SJerome Glisse } 4104c788679SJerome Glisse r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb); 4114c788679SJerome Glisse radeon_bo_unreserve(rdev->wb.wb_obj); 412771fe6b9SJerome Glisse if (r) { 4134c788679SJerome Glisse dev_err(rdev->dev, "(%d) map WB buffer failed\n", r); 414771fe6b9SJerome Glisse return r; 415771fe6b9SJerome Glisse } 416771fe6b9SJerome Glisse } 4179f022ddfSJerome Glisse WREG32(R_000774_SCRATCH_ADDR, rdev->wb.gpu_addr); 4189f022ddfSJerome Glisse WREG32(R_00070C_CP_RB_RPTR_ADDR, 4199f022ddfSJerome Glisse S_00070C_RB_RPTR_ADDR((rdev->wb.gpu_addr + 1024) >> 2)); 4209f022ddfSJerome Glisse WREG32(R_000770_SCRATCH_UMSK, 0xff); 421771fe6b9SJerome Glisse return 0; 422771fe6b9SJerome Glisse } 423771fe6b9SJerome Glisse 4249f022ddfSJerome Glisse void r100_wb_disable(struct radeon_device *rdev) 4259f022ddfSJerome Glisse { 4269f022ddfSJerome Glisse WREG32(R_000770_SCRATCH_UMSK, 0); 4279f022ddfSJerome Glisse } 4289f022ddfSJerome Glisse 429771fe6b9SJerome Glisse void r100_wb_fini(struct radeon_device *rdev) 430771fe6b9SJerome Glisse { 4314c788679SJerome Glisse int r; 4324c788679SJerome Glisse 4339f022ddfSJerome Glisse r100_wb_disable(rdev); 434771fe6b9SJerome Glisse if (rdev->wb.wb_obj) { 4354c788679SJerome Glisse r = radeon_bo_reserve(rdev->wb.wb_obj, false); 4364c788679SJerome Glisse if (unlikely(r != 0)) { 4374c788679SJerome Glisse dev_err(rdev->dev, "(%d) can't finish WB\n", r); 4384c788679SJerome Glisse return; 4394c788679SJerome Glisse } 4404c788679SJerome Glisse radeon_bo_kunmap(rdev->wb.wb_obj); 4414c788679SJerome Glisse radeon_bo_unpin(rdev->wb.wb_obj); 4424c788679SJerome Glisse radeon_bo_unreserve(rdev->wb.wb_obj); 4434c788679SJerome Glisse radeon_bo_unref(&rdev->wb.wb_obj); 444771fe6b9SJerome Glisse rdev->wb.wb = NULL; 445771fe6b9SJerome Glisse rdev->wb.wb_obj = NULL; 446771fe6b9SJerome Glisse } 447771fe6b9SJerome Glisse } 448771fe6b9SJerome Glisse 449771fe6b9SJerome Glisse int r100_copy_blit(struct radeon_device *rdev, 450771fe6b9SJerome Glisse uint64_t src_offset, 451771fe6b9SJerome Glisse uint64_t dst_offset, 452771fe6b9SJerome Glisse unsigned num_pages, 453771fe6b9SJerome Glisse struct radeon_fence *fence) 454771fe6b9SJerome Glisse { 455771fe6b9SJerome Glisse uint32_t cur_pages; 456771fe6b9SJerome Glisse uint32_t stride_bytes = PAGE_SIZE; 457771fe6b9SJerome Glisse uint32_t pitch; 458771fe6b9SJerome Glisse uint32_t stride_pixels; 459771fe6b9SJerome Glisse unsigned ndw; 460771fe6b9SJerome Glisse int num_loops; 461771fe6b9SJerome Glisse int r = 0; 462771fe6b9SJerome Glisse 463771fe6b9SJerome Glisse /* radeon limited to 16k stride */ 464771fe6b9SJerome Glisse stride_bytes &= 0x3fff; 465771fe6b9SJerome Glisse /* radeon pitch is /64 */ 466771fe6b9SJerome Glisse pitch = stride_bytes / 64; 467771fe6b9SJerome Glisse stride_pixels = stride_bytes / 4; 468771fe6b9SJerome Glisse num_loops = DIV_ROUND_UP(num_pages, 8191); 469771fe6b9SJerome Glisse 470771fe6b9SJerome Glisse /* Ask for enough room for blit + flush + fence */ 471771fe6b9SJerome Glisse ndw = 64 + (10 * num_loops); 472771fe6b9SJerome Glisse r = radeon_ring_lock(rdev, ndw); 473771fe6b9SJerome Glisse if (r) { 474771fe6b9SJerome Glisse DRM_ERROR("radeon: moving bo (%d) asking for %u dw.\n", r, ndw); 475771fe6b9SJerome Glisse return -EINVAL; 476771fe6b9SJerome Glisse } 477771fe6b9SJerome Glisse while (num_pages > 0) { 478771fe6b9SJerome Glisse cur_pages = num_pages; 479771fe6b9SJerome Glisse if (cur_pages > 8191) { 480771fe6b9SJerome Glisse cur_pages = 8191; 481771fe6b9SJerome Glisse } 482771fe6b9SJerome Glisse num_pages -= cur_pages; 483771fe6b9SJerome Glisse 484771fe6b9SJerome Glisse /* pages are in Y direction - height 485771fe6b9SJerome Glisse page width in X direction - width */ 486771fe6b9SJerome Glisse radeon_ring_write(rdev, PACKET3(PACKET3_BITBLT_MULTI, 8)); 487771fe6b9SJerome Glisse radeon_ring_write(rdev, 488771fe6b9SJerome Glisse RADEON_GMC_SRC_PITCH_OFFSET_CNTL | 489771fe6b9SJerome Glisse RADEON_GMC_DST_PITCH_OFFSET_CNTL | 490771fe6b9SJerome Glisse RADEON_GMC_SRC_CLIPPING | 491771fe6b9SJerome Glisse RADEON_GMC_DST_CLIPPING | 492771fe6b9SJerome Glisse RADEON_GMC_BRUSH_NONE | 493771fe6b9SJerome Glisse (RADEON_COLOR_FORMAT_ARGB8888 << 8) | 494771fe6b9SJerome Glisse RADEON_GMC_SRC_DATATYPE_COLOR | 495771fe6b9SJerome Glisse RADEON_ROP3_S | 496771fe6b9SJerome Glisse RADEON_DP_SRC_SOURCE_MEMORY | 497771fe6b9SJerome Glisse RADEON_GMC_CLR_CMP_CNTL_DIS | 498771fe6b9SJerome Glisse RADEON_GMC_WR_MSK_DIS); 499771fe6b9SJerome Glisse radeon_ring_write(rdev, (pitch << 22) | (src_offset >> 10)); 500771fe6b9SJerome Glisse radeon_ring_write(rdev, (pitch << 22) | (dst_offset >> 10)); 501771fe6b9SJerome Glisse radeon_ring_write(rdev, (0x1fff) | (0x1fff << 16)); 502771fe6b9SJerome Glisse radeon_ring_write(rdev, 0); 503771fe6b9SJerome Glisse radeon_ring_write(rdev, (0x1fff) | (0x1fff << 16)); 504771fe6b9SJerome Glisse radeon_ring_write(rdev, num_pages); 505771fe6b9SJerome Glisse radeon_ring_write(rdev, num_pages); 506771fe6b9SJerome Glisse radeon_ring_write(rdev, cur_pages | (stride_pixels << 16)); 507771fe6b9SJerome Glisse } 508771fe6b9SJerome Glisse radeon_ring_write(rdev, PACKET0(RADEON_DSTCACHE_CTLSTAT, 0)); 509771fe6b9SJerome Glisse radeon_ring_write(rdev, RADEON_RB2D_DC_FLUSH_ALL); 510771fe6b9SJerome Glisse radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0)); 511771fe6b9SJerome Glisse radeon_ring_write(rdev, 512771fe6b9SJerome Glisse RADEON_WAIT_2D_IDLECLEAN | 513771fe6b9SJerome Glisse RADEON_WAIT_HOST_IDLECLEAN | 514771fe6b9SJerome Glisse RADEON_WAIT_DMA_GUI_IDLE); 515771fe6b9SJerome Glisse if (fence) { 516771fe6b9SJerome Glisse r = radeon_fence_emit(rdev, fence); 517771fe6b9SJerome Glisse } 518771fe6b9SJerome Glisse radeon_ring_unlock_commit(rdev); 519771fe6b9SJerome Glisse return r; 520771fe6b9SJerome Glisse } 521771fe6b9SJerome Glisse 52245600232SJerome Glisse static int r100_cp_wait_for_idle(struct radeon_device *rdev) 52345600232SJerome Glisse { 52445600232SJerome Glisse unsigned i; 52545600232SJerome Glisse u32 tmp; 52645600232SJerome Glisse 52745600232SJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 52845600232SJerome Glisse tmp = RREG32(R_000E40_RBBM_STATUS); 52945600232SJerome Glisse if (!G_000E40_CP_CMDSTRM_BUSY(tmp)) { 53045600232SJerome Glisse return 0; 53145600232SJerome Glisse } 53245600232SJerome Glisse udelay(1); 53345600232SJerome Glisse } 53445600232SJerome Glisse return -1; 53545600232SJerome Glisse } 53645600232SJerome Glisse 537771fe6b9SJerome Glisse void r100_ring_start(struct radeon_device *rdev) 538771fe6b9SJerome Glisse { 539771fe6b9SJerome Glisse int r; 540771fe6b9SJerome Glisse 541771fe6b9SJerome Glisse r = radeon_ring_lock(rdev, 2); 542771fe6b9SJerome Glisse if (r) { 543771fe6b9SJerome Glisse return; 544771fe6b9SJerome Glisse } 545771fe6b9SJerome Glisse radeon_ring_write(rdev, PACKET0(RADEON_ISYNC_CNTL, 0)); 546771fe6b9SJerome Glisse radeon_ring_write(rdev, 547771fe6b9SJerome Glisse RADEON_ISYNC_ANY2D_IDLE3D | 548771fe6b9SJerome Glisse RADEON_ISYNC_ANY3D_IDLE2D | 549771fe6b9SJerome Glisse RADEON_ISYNC_WAIT_IDLEGUI | 550771fe6b9SJerome Glisse RADEON_ISYNC_CPSCRATCH_IDLEGUI); 551771fe6b9SJerome Glisse radeon_ring_unlock_commit(rdev); 552771fe6b9SJerome Glisse } 553771fe6b9SJerome Glisse 55470967ab9SBen Hutchings 55570967ab9SBen Hutchings /* Load the microcode for the CP */ 55670967ab9SBen Hutchings static int r100_cp_init_microcode(struct radeon_device *rdev) 557771fe6b9SJerome Glisse { 55870967ab9SBen Hutchings struct platform_device *pdev; 55970967ab9SBen Hutchings const char *fw_name = NULL; 56070967ab9SBen Hutchings int err; 561771fe6b9SJerome Glisse 56270967ab9SBen Hutchings DRM_DEBUG("\n"); 56370967ab9SBen Hutchings 56470967ab9SBen Hutchings pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0); 56570967ab9SBen Hutchings err = IS_ERR(pdev); 56670967ab9SBen Hutchings if (err) { 56770967ab9SBen Hutchings printk(KERN_ERR "radeon_cp: Failed to register firmware\n"); 56870967ab9SBen Hutchings return -EINVAL; 569771fe6b9SJerome Glisse } 570771fe6b9SJerome Glisse if ((rdev->family == CHIP_R100) || (rdev->family == CHIP_RV100) || 571771fe6b9SJerome Glisse (rdev->family == CHIP_RV200) || (rdev->family == CHIP_RS100) || 572771fe6b9SJerome Glisse (rdev->family == CHIP_RS200)) { 573771fe6b9SJerome Glisse DRM_INFO("Loading R100 Microcode\n"); 57470967ab9SBen Hutchings fw_name = FIRMWARE_R100; 575771fe6b9SJerome Glisse } else if ((rdev->family == CHIP_R200) || 576771fe6b9SJerome Glisse (rdev->family == CHIP_RV250) || 577771fe6b9SJerome Glisse (rdev->family == CHIP_RV280) || 578771fe6b9SJerome Glisse (rdev->family == CHIP_RS300)) { 579771fe6b9SJerome Glisse DRM_INFO("Loading R200 Microcode\n"); 58070967ab9SBen Hutchings fw_name = FIRMWARE_R200; 581771fe6b9SJerome Glisse } else if ((rdev->family == CHIP_R300) || 582771fe6b9SJerome Glisse (rdev->family == CHIP_R350) || 583771fe6b9SJerome Glisse (rdev->family == CHIP_RV350) || 584771fe6b9SJerome Glisse (rdev->family == CHIP_RV380) || 585771fe6b9SJerome Glisse (rdev->family == CHIP_RS400) || 586771fe6b9SJerome Glisse (rdev->family == CHIP_RS480)) { 587771fe6b9SJerome Glisse DRM_INFO("Loading R300 Microcode\n"); 58870967ab9SBen Hutchings fw_name = FIRMWARE_R300; 589771fe6b9SJerome Glisse } else if ((rdev->family == CHIP_R420) || 590771fe6b9SJerome Glisse (rdev->family == CHIP_R423) || 591771fe6b9SJerome Glisse (rdev->family == CHIP_RV410)) { 592771fe6b9SJerome Glisse DRM_INFO("Loading R400 Microcode\n"); 59370967ab9SBen Hutchings fw_name = FIRMWARE_R420; 594771fe6b9SJerome Glisse } else if ((rdev->family == CHIP_RS690) || 595771fe6b9SJerome Glisse (rdev->family == CHIP_RS740)) { 596771fe6b9SJerome Glisse DRM_INFO("Loading RS690/RS740 Microcode\n"); 59770967ab9SBen Hutchings fw_name = FIRMWARE_RS690; 598771fe6b9SJerome Glisse } else if (rdev->family == CHIP_RS600) { 599771fe6b9SJerome Glisse DRM_INFO("Loading RS600 Microcode\n"); 60070967ab9SBen Hutchings fw_name = FIRMWARE_RS600; 601771fe6b9SJerome Glisse } else if ((rdev->family == CHIP_RV515) || 602771fe6b9SJerome Glisse (rdev->family == CHIP_R520) || 603771fe6b9SJerome Glisse (rdev->family == CHIP_RV530) || 604771fe6b9SJerome Glisse (rdev->family == CHIP_R580) || 605771fe6b9SJerome Glisse (rdev->family == CHIP_RV560) || 606771fe6b9SJerome Glisse (rdev->family == CHIP_RV570)) { 607771fe6b9SJerome Glisse DRM_INFO("Loading R500 Microcode\n"); 60870967ab9SBen Hutchings fw_name = FIRMWARE_R520; 60970967ab9SBen Hutchings } 61070967ab9SBen Hutchings 6113ce0a23dSJerome Glisse err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev); 61270967ab9SBen Hutchings platform_device_unregister(pdev); 61370967ab9SBen Hutchings if (err) { 61470967ab9SBen Hutchings printk(KERN_ERR "radeon_cp: Failed to load firmware \"%s\"\n", 61570967ab9SBen Hutchings fw_name); 6163ce0a23dSJerome Glisse } else if (rdev->me_fw->size % 8) { 61770967ab9SBen Hutchings printk(KERN_ERR 61870967ab9SBen Hutchings "radeon_cp: Bogus length %zu in firmware \"%s\"\n", 6193ce0a23dSJerome Glisse rdev->me_fw->size, fw_name); 62070967ab9SBen Hutchings err = -EINVAL; 6213ce0a23dSJerome Glisse release_firmware(rdev->me_fw); 6223ce0a23dSJerome Glisse rdev->me_fw = NULL; 62370967ab9SBen Hutchings } 62470967ab9SBen Hutchings return err; 62570967ab9SBen Hutchings } 626d4550907SJerome Glisse 62770967ab9SBen Hutchings static void r100_cp_load_microcode(struct radeon_device *rdev) 62870967ab9SBen Hutchings { 62970967ab9SBen Hutchings const __be32 *fw_data; 63070967ab9SBen Hutchings int i, size; 63170967ab9SBen Hutchings 63270967ab9SBen Hutchings if (r100_gui_wait_for_idle(rdev)) { 63370967ab9SBen Hutchings printk(KERN_WARNING "Failed to wait GUI idle while " 63470967ab9SBen Hutchings "programming pipes. Bad things might happen.\n"); 63570967ab9SBen Hutchings } 63670967ab9SBen Hutchings 6373ce0a23dSJerome Glisse if (rdev->me_fw) { 6383ce0a23dSJerome Glisse size = rdev->me_fw->size / 4; 6393ce0a23dSJerome Glisse fw_data = (const __be32 *)&rdev->me_fw->data[0]; 64070967ab9SBen Hutchings WREG32(RADEON_CP_ME_RAM_ADDR, 0); 64170967ab9SBen Hutchings for (i = 0; i < size; i += 2) { 64270967ab9SBen Hutchings WREG32(RADEON_CP_ME_RAM_DATAH, 64370967ab9SBen Hutchings be32_to_cpup(&fw_data[i])); 64470967ab9SBen Hutchings WREG32(RADEON_CP_ME_RAM_DATAL, 64570967ab9SBen Hutchings be32_to_cpup(&fw_data[i + 1])); 646771fe6b9SJerome Glisse } 647771fe6b9SJerome Glisse } 648771fe6b9SJerome Glisse } 649771fe6b9SJerome Glisse 650771fe6b9SJerome Glisse int r100_cp_init(struct radeon_device *rdev, unsigned ring_size) 651771fe6b9SJerome Glisse { 652771fe6b9SJerome Glisse unsigned rb_bufsz; 653771fe6b9SJerome Glisse unsigned rb_blksz; 654771fe6b9SJerome Glisse unsigned max_fetch; 655771fe6b9SJerome Glisse unsigned pre_write_timer; 656771fe6b9SJerome Glisse unsigned pre_write_limit; 657771fe6b9SJerome Glisse unsigned indirect2_start; 658771fe6b9SJerome Glisse unsigned indirect1_start; 659771fe6b9SJerome Glisse uint32_t tmp; 660771fe6b9SJerome Glisse int r; 661771fe6b9SJerome Glisse 662771fe6b9SJerome Glisse if (r100_debugfs_cp_init(rdev)) { 663771fe6b9SJerome Glisse DRM_ERROR("Failed to register debugfs file for CP !\n"); 664771fe6b9SJerome Glisse } 665771fe6b9SJerome Glisse /* Reset CP */ 666771fe6b9SJerome Glisse tmp = RREG32(RADEON_CP_CSQ_STAT); 667771fe6b9SJerome Glisse if ((tmp & (1 << 31))) { 668771fe6b9SJerome Glisse DRM_INFO("radeon: cp busy (0x%08X) resetting\n", tmp); 669771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_MODE, 0); 670771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_CNTL, 0); 671771fe6b9SJerome Glisse WREG32(RADEON_RBBM_SOFT_RESET, RADEON_SOFT_RESET_CP); 672771fe6b9SJerome Glisse tmp = RREG32(RADEON_RBBM_SOFT_RESET); 673771fe6b9SJerome Glisse mdelay(2); 674771fe6b9SJerome Glisse WREG32(RADEON_RBBM_SOFT_RESET, 0); 675771fe6b9SJerome Glisse tmp = RREG32(RADEON_RBBM_SOFT_RESET); 676771fe6b9SJerome Glisse mdelay(2); 677771fe6b9SJerome Glisse tmp = RREG32(RADEON_CP_CSQ_STAT); 678771fe6b9SJerome Glisse if ((tmp & (1 << 31))) { 679771fe6b9SJerome Glisse DRM_INFO("radeon: cp reset failed (0x%08X)\n", tmp); 680771fe6b9SJerome Glisse } 681771fe6b9SJerome Glisse } else { 682771fe6b9SJerome Glisse DRM_INFO("radeon: cp idle (0x%08X)\n", tmp); 683771fe6b9SJerome Glisse } 68470967ab9SBen Hutchings 6853ce0a23dSJerome Glisse if (!rdev->me_fw) { 68670967ab9SBen Hutchings r = r100_cp_init_microcode(rdev); 68770967ab9SBen Hutchings if (r) { 68870967ab9SBen Hutchings DRM_ERROR("Failed to load firmware!\n"); 68970967ab9SBen Hutchings return r; 69070967ab9SBen Hutchings } 69170967ab9SBen Hutchings } 69270967ab9SBen Hutchings 693771fe6b9SJerome Glisse /* Align ring size */ 694771fe6b9SJerome Glisse rb_bufsz = drm_order(ring_size / 8); 695771fe6b9SJerome Glisse ring_size = (1 << (rb_bufsz + 1)) * 4; 696771fe6b9SJerome Glisse r100_cp_load_microcode(rdev); 697771fe6b9SJerome Glisse r = radeon_ring_init(rdev, ring_size); 698771fe6b9SJerome Glisse if (r) { 699771fe6b9SJerome Glisse return r; 700771fe6b9SJerome Glisse } 701771fe6b9SJerome Glisse /* Each time the cp read 1024 bytes (16 dword/quadword) update 702771fe6b9SJerome Glisse * the rptr copy in system ram */ 703771fe6b9SJerome Glisse rb_blksz = 9; 704771fe6b9SJerome Glisse /* cp will read 128bytes at a time (4 dwords) */ 705771fe6b9SJerome Glisse max_fetch = 1; 706771fe6b9SJerome Glisse rdev->cp.align_mask = 16 - 1; 707771fe6b9SJerome Glisse /* Write to CP_RB_WPTR will be delayed for pre_write_timer clocks */ 708771fe6b9SJerome Glisse pre_write_timer = 64; 709771fe6b9SJerome Glisse /* Force CP_RB_WPTR write if written more than one time before the 710771fe6b9SJerome Glisse * delay expire 711771fe6b9SJerome Glisse */ 712771fe6b9SJerome Glisse pre_write_limit = 0; 713771fe6b9SJerome Glisse /* Setup the cp cache like this (cache size is 96 dwords) : 714771fe6b9SJerome Glisse * RING 0 to 15 715771fe6b9SJerome Glisse * INDIRECT1 16 to 79 716771fe6b9SJerome Glisse * INDIRECT2 80 to 95 717771fe6b9SJerome Glisse * So ring cache size is 16dwords (> (2 * max_fetch = 2 * 4dwords)) 718771fe6b9SJerome Glisse * indirect1 cache size is 64dwords (> (2 * max_fetch = 2 * 4dwords)) 719771fe6b9SJerome Glisse * indirect2 cache size is 16dwords (> (2 * max_fetch = 2 * 4dwords)) 720771fe6b9SJerome Glisse * Idea being that most of the gpu cmd will be through indirect1 buffer 721771fe6b9SJerome Glisse * so it gets the bigger cache. 722771fe6b9SJerome Glisse */ 723771fe6b9SJerome Glisse indirect2_start = 80; 724771fe6b9SJerome Glisse indirect1_start = 16; 725771fe6b9SJerome Glisse /* cp setup */ 726771fe6b9SJerome Glisse WREG32(0x718, pre_write_timer | (pre_write_limit << 28)); 727d6f28938SAlex Deucher tmp = (REG_SET(RADEON_RB_BUFSZ, rb_bufsz) | 728771fe6b9SJerome Glisse REG_SET(RADEON_RB_BLKSZ, rb_blksz) | 729771fe6b9SJerome Glisse REG_SET(RADEON_MAX_FETCH, max_fetch) | 730771fe6b9SJerome Glisse RADEON_RB_NO_UPDATE); 731d6f28938SAlex Deucher #ifdef __BIG_ENDIAN 732d6f28938SAlex Deucher tmp |= RADEON_BUF_SWAP_32BIT; 733d6f28938SAlex Deucher #endif 734d6f28938SAlex Deucher WREG32(RADEON_CP_RB_CNTL, tmp); 735d6f28938SAlex Deucher 736771fe6b9SJerome Glisse /* Set ring address */ 737771fe6b9SJerome Glisse DRM_INFO("radeon: ring at 0x%016lX\n", (unsigned long)rdev->cp.gpu_addr); 738771fe6b9SJerome Glisse WREG32(RADEON_CP_RB_BASE, rdev->cp.gpu_addr); 739771fe6b9SJerome Glisse /* Force read & write ptr to 0 */ 740771fe6b9SJerome Glisse WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_RPTR_WR_ENA); 741771fe6b9SJerome Glisse WREG32(RADEON_CP_RB_RPTR_WR, 0); 742771fe6b9SJerome Glisse WREG32(RADEON_CP_RB_WPTR, 0); 743771fe6b9SJerome Glisse WREG32(RADEON_CP_RB_CNTL, tmp); 744771fe6b9SJerome Glisse udelay(10); 745771fe6b9SJerome Glisse rdev->cp.rptr = RREG32(RADEON_CP_RB_RPTR); 746771fe6b9SJerome Glisse rdev->cp.wptr = RREG32(RADEON_CP_RB_WPTR); 747771fe6b9SJerome Glisse /* Set cp mode to bus mastering & enable cp*/ 748771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_MODE, 749771fe6b9SJerome Glisse REG_SET(RADEON_INDIRECT2_START, indirect2_start) | 750771fe6b9SJerome Glisse REG_SET(RADEON_INDIRECT1_START, indirect1_start)); 751771fe6b9SJerome Glisse WREG32(0x718, 0); 752771fe6b9SJerome Glisse WREG32(0x744, 0x00004D4D); 753771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_CNTL, RADEON_CSQ_PRIBM_INDBM); 754771fe6b9SJerome Glisse radeon_ring_start(rdev); 755771fe6b9SJerome Glisse r = radeon_ring_test(rdev); 756771fe6b9SJerome Glisse if (r) { 757771fe6b9SJerome Glisse DRM_ERROR("radeon: cp isn't working (%d).\n", r); 758771fe6b9SJerome Glisse return r; 759771fe6b9SJerome Glisse } 760771fe6b9SJerome Glisse rdev->cp.ready = true; 761771fe6b9SJerome Glisse return 0; 762771fe6b9SJerome Glisse } 763771fe6b9SJerome Glisse 764771fe6b9SJerome Glisse void r100_cp_fini(struct radeon_device *rdev) 765771fe6b9SJerome Glisse { 76645600232SJerome Glisse if (r100_cp_wait_for_idle(rdev)) { 76745600232SJerome Glisse DRM_ERROR("Wait for CP idle timeout, shutting down CP.\n"); 76845600232SJerome Glisse } 769771fe6b9SJerome Glisse /* Disable ring */ 770a18d7ea1SJerome Glisse r100_cp_disable(rdev); 771771fe6b9SJerome Glisse radeon_ring_fini(rdev); 772771fe6b9SJerome Glisse DRM_INFO("radeon: cp finalized\n"); 773771fe6b9SJerome Glisse } 774771fe6b9SJerome Glisse 775771fe6b9SJerome Glisse void r100_cp_disable(struct radeon_device *rdev) 776771fe6b9SJerome Glisse { 777771fe6b9SJerome Glisse /* Disable ring */ 778771fe6b9SJerome Glisse rdev->cp.ready = false; 779771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_MODE, 0); 780771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_CNTL, 0); 781771fe6b9SJerome Glisse if (r100_gui_wait_for_idle(rdev)) { 782771fe6b9SJerome Glisse printk(KERN_WARNING "Failed to wait GUI idle while " 783771fe6b9SJerome Glisse "programming pipes. Bad things might happen.\n"); 784771fe6b9SJerome Glisse } 785771fe6b9SJerome Glisse } 786771fe6b9SJerome Glisse 787771fe6b9SJerome Glisse int r100_cp_reset(struct radeon_device *rdev) 788771fe6b9SJerome Glisse { 789771fe6b9SJerome Glisse uint32_t tmp; 790771fe6b9SJerome Glisse bool reinit_cp; 791771fe6b9SJerome Glisse int i; 792771fe6b9SJerome Glisse 793771fe6b9SJerome Glisse reinit_cp = rdev->cp.ready; 794771fe6b9SJerome Glisse rdev->cp.ready = false; 795771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_MODE, 0); 796771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_CNTL, 0); 797771fe6b9SJerome Glisse WREG32(RADEON_RBBM_SOFT_RESET, RADEON_SOFT_RESET_CP); 798771fe6b9SJerome Glisse (void)RREG32(RADEON_RBBM_SOFT_RESET); 799771fe6b9SJerome Glisse udelay(200); 800771fe6b9SJerome Glisse WREG32(RADEON_RBBM_SOFT_RESET, 0); 801771fe6b9SJerome Glisse /* Wait to prevent race in RBBM_STATUS */ 802771fe6b9SJerome Glisse mdelay(1); 803771fe6b9SJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 804771fe6b9SJerome Glisse tmp = RREG32(RADEON_RBBM_STATUS); 805771fe6b9SJerome Glisse if (!(tmp & (1 << 16))) { 806771fe6b9SJerome Glisse DRM_INFO("CP reset succeed (RBBM_STATUS=0x%08X)\n", 807771fe6b9SJerome Glisse tmp); 808771fe6b9SJerome Glisse if (reinit_cp) { 809771fe6b9SJerome Glisse return r100_cp_init(rdev, rdev->cp.ring_size); 810771fe6b9SJerome Glisse } 811771fe6b9SJerome Glisse return 0; 812771fe6b9SJerome Glisse } 813771fe6b9SJerome Glisse DRM_UDELAY(1); 814771fe6b9SJerome Glisse } 815771fe6b9SJerome Glisse tmp = RREG32(RADEON_RBBM_STATUS); 816771fe6b9SJerome Glisse DRM_ERROR("Failed to reset CP (RBBM_STATUS=0x%08X)!\n", tmp); 817771fe6b9SJerome Glisse return -1; 818771fe6b9SJerome Glisse } 819771fe6b9SJerome Glisse 8203ce0a23dSJerome Glisse void r100_cp_commit(struct radeon_device *rdev) 8213ce0a23dSJerome Glisse { 8223ce0a23dSJerome Glisse WREG32(RADEON_CP_RB_WPTR, rdev->cp.wptr); 8233ce0a23dSJerome Glisse (void)RREG32(RADEON_CP_RB_WPTR); 8243ce0a23dSJerome Glisse } 8253ce0a23dSJerome Glisse 826771fe6b9SJerome Glisse 827771fe6b9SJerome Glisse /* 828771fe6b9SJerome Glisse * CS functions 829771fe6b9SJerome Glisse */ 830771fe6b9SJerome Glisse int r100_cs_parse_packet0(struct radeon_cs_parser *p, 831771fe6b9SJerome Glisse struct radeon_cs_packet *pkt, 832068a117cSJerome Glisse const unsigned *auth, unsigned n, 833771fe6b9SJerome Glisse radeon_packet0_check_t check) 834771fe6b9SJerome Glisse { 835771fe6b9SJerome Glisse unsigned reg; 836771fe6b9SJerome Glisse unsigned i, j, m; 837771fe6b9SJerome Glisse unsigned idx; 838771fe6b9SJerome Glisse int r; 839771fe6b9SJerome Glisse 840771fe6b9SJerome Glisse idx = pkt->idx + 1; 841771fe6b9SJerome Glisse reg = pkt->reg; 842068a117cSJerome Glisse /* Check that register fall into register range 843068a117cSJerome Glisse * determined by the number of entry (n) in the 844068a117cSJerome Glisse * safe register bitmap. 845068a117cSJerome Glisse */ 846771fe6b9SJerome Glisse if (pkt->one_reg_wr) { 847771fe6b9SJerome Glisse if ((reg >> 7) > n) { 848771fe6b9SJerome Glisse return -EINVAL; 849771fe6b9SJerome Glisse } 850771fe6b9SJerome Glisse } else { 851771fe6b9SJerome Glisse if (((reg + (pkt->count << 2)) >> 7) > n) { 852771fe6b9SJerome Glisse return -EINVAL; 853771fe6b9SJerome Glisse } 854771fe6b9SJerome Glisse } 855771fe6b9SJerome Glisse for (i = 0; i <= pkt->count; i++, idx++) { 856771fe6b9SJerome Glisse j = (reg >> 7); 857771fe6b9SJerome Glisse m = 1 << ((reg >> 2) & 31); 858771fe6b9SJerome Glisse if (auth[j] & m) { 859771fe6b9SJerome Glisse r = check(p, pkt, idx, reg); 860771fe6b9SJerome Glisse if (r) { 861771fe6b9SJerome Glisse return r; 862771fe6b9SJerome Glisse } 863771fe6b9SJerome Glisse } 864771fe6b9SJerome Glisse if (pkt->one_reg_wr) { 865771fe6b9SJerome Glisse if (!(auth[j] & m)) { 866771fe6b9SJerome Glisse break; 867771fe6b9SJerome Glisse } 868771fe6b9SJerome Glisse } else { 869771fe6b9SJerome Glisse reg += 4; 870771fe6b9SJerome Glisse } 871771fe6b9SJerome Glisse } 872771fe6b9SJerome Glisse return 0; 873771fe6b9SJerome Glisse } 874771fe6b9SJerome Glisse 875771fe6b9SJerome Glisse void r100_cs_dump_packet(struct radeon_cs_parser *p, 876771fe6b9SJerome Glisse struct radeon_cs_packet *pkt) 877771fe6b9SJerome Glisse { 878771fe6b9SJerome Glisse volatile uint32_t *ib; 879771fe6b9SJerome Glisse unsigned i; 880771fe6b9SJerome Glisse unsigned idx; 881771fe6b9SJerome Glisse 882771fe6b9SJerome Glisse ib = p->ib->ptr; 883771fe6b9SJerome Glisse idx = pkt->idx; 884771fe6b9SJerome Glisse for (i = 0; i <= (pkt->count + 1); i++, idx++) { 885771fe6b9SJerome Glisse DRM_INFO("ib[%d]=0x%08X\n", idx, ib[idx]); 886771fe6b9SJerome Glisse } 887771fe6b9SJerome Glisse } 888771fe6b9SJerome Glisse 889771fe6b9SJerome Glisse /** 890771fe6b9SJerome Glisse * r100_cs_packet_parse() - parse cp packet and point ib index to next packet 891771fe6b9SJerome Glisse * @parser: parser structure holding parsing context. 892771fe6b9SJerome Glisse * @pkt: where to store packet informations 893771fe6b9SJerome Glisse * 894771fe6b9SJerome Glisse * Assume that chunk_ib_index is properly set. Will return -EINVAL 895771fe6b9SJerome Glisse * if packet is bigger than remaining ib size. or if packets is unknown. 896771fe6b9SJerome Glisse **/ 897771fe6b9SJerome Glisse int r100_cs_packet_parse(struct radeon_cs_parser *p, 898771fe6b9SJerome Glisse struct radeon_cs_packet *pkt, 899771fe6b9SJerome Glisse unsigned idx) 900771fe6b9SJerome Glisse { 901771fe6b9SJerome Glisse struct radeon_cs_chunk *ib_chunk = &p->chunks[p->chunk_ib_idx]; 902fa99239cSRoel Kluin uint32_t header; 903771fe6b9SJerome Glisse 904771fe6b9SJerome Glisse if (idx >= ib_chunk->length_dw) { 905771fe6b9SJerome Glisse DRM_ERROR("Can not parse packet at %d after CS end %d !\n", 906771fe6b9SJerome Glisse idx, ib_chunk->length_dw); 907771fe6b9SJerome Glisse return -EINVAL; 908771fe6b9SJerome Glisse } 909513bcb46SDave Airlie header = radeon_get_ib_value(p, idx); 910771fe6b9SJerome Glisse pkt->idx = idx; 911771fe6b9SJerome Glisse pkt->type = CP_PACKET_GET_TYPE(header); 912771fe6b9SJerome Glisse pkt->count = CP_PACKET_GET_COUNT(header); 913771fe6b9SJerome Glisse switch (pkt->type) { 914771fe6b9SJerome Glisse case PACKET_TYPE0: 915771fe6b9SJerome Glisse pkt->reg = CP_PACKET0_GET_REG(header); 916771fe6b9SJerome Glisse pkt->one_reg_wr = CP_PACKET0_GET_ONE_REG_WR(header); 917771fe6b9SJerome Glisse break; 918771fe6b9SJerome Glisse case PACKET_TYPE3: 919771fe6b9SJerome Glisse pkt->opcode = CP_PACKET3_GET_OPCODE(header); 920771fe6b9SJerome Glisse break; 921771fe6b9SJerome Glisse case PACKET_TYPE2: 922771fe6b9SJerome Glisse pkt->count = -1; 923771fe6b9SJerome Glisse break; 924771fe6b9SJerome Glisse default: 925771fe6b9SJerome Glisse DRM_ERROR("Unknown packet type %d at %d !\n", pkt->type, idx); 926771fe6b9SJerome Glisse return -EINVAL; 927771fe6b9SJerome Glisse } 928771fe6b9SJerome Glisse if ((pkt->count + 1 + pkt->idx) >= ib_chunk->length_dw) { 929771fe6b9SJerome Glisse DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n", 930771fe6b9SJerome Glisse pkt->idx, pkt->type, pkt->count, ib_chunk->length_dw); 931771fe6b9SJerome Glisse return -EINVAL; 932771fe6b9SJerome Glisse } 933771fe6b9SJerome Glisse return 0; 934771fe6b9SJerome Glisse } 935771fe6b9SJerome Glisse 936771fe6b9SJerome Glisse /** 937531369e6SDave Airlie * r100_cs_packet_next_vline() - parse userspace VLINE packet 938531369e6SDave Airlie * @parser: parser structure holding parsing context. 939531369e6SDave Airlie * 940531369e6SDave Airlie * Userspace sends a special sequence for VLINE waits. 941531369e6SDave Airlie * PACKET0 - VLINE_START_END + value 942531369e6SDave Airlie * PACKET0 - WAIT_UNTIL +_value 943531369e6SDave Airlie * RELOC (P3) - crtc_id in reloc. 944531369e6SDave Airlie * 945531369e6SDave Airlie * This function parses this and relocates the VLINE START END 946531369e6SDave Airlie * and WAIT UNTIL packets to the correct crtc. 947531369e6SDave Airlie * It also detects a switched off crtc and nulls out the 948531369e6SDave Airlie * wait in that case. 949531369e6SDave Airlie */ 950531369e6SDave Airlie int r100_cs_packet_parse_vline(struct radeon_cs_parser *p) 951531369e6SDave Airlie { 952531369e6SDave Airlie struct drm_mode_object *obj; 953531369e6SDave Airlie struct drm_crtc *crtc; 954531369e6SDave Airlie struct radeon_crtc *radeon_crtc; 955531369e6SDave Airlie struct radeon_cs_packet p3reloc, waitreloc; 956531369e6SDave Airlie int crtc_id; 957531369e6SDave Airlie int r; 958531369e6SDave Airlie uint32_t header, h_idx, reg; 959513bcb46SDave Airlie volatile uint32_t *ib; 960531369e6SDave Airlie 961513bcb46SDave Airlie ib = p->ib->ptr; 962531369e6SDave Airlie 963531369e6SDave Airlie /* parse the wait until */ 964531369e6SDave Airlie r = r100_cs_packet_parse(p, &waitreloc, p->idx); 965531369e6SDave Airlie if (r) 966531369e6SDave Airlie return r; 967531369e6SDave Airlie 968531369e6SDave Airlie /* check its a wait until and only 1 count */ 969531369e6SDave Airlie if (waitreloc.reg != RADEON_WAIT_UNTIL || 970531369e6SDave Airlie waitreloc.count != 0) { 971531369e6SDave Airlie DRM_ERROR("vline wait had illegal wait until segment\n"); 972531369e6SDave Airlie r = -EINVAL; 973531369e6SDave Airlie return r; 974531369e6SDave Airlie } 975531369e6SDave Airlie 976513bcb46SDave Airlie if (radeon_get_ib_value(p, waitreloc.idx + 1) != RADEON_WAIT_CRTC_VLINE) { 977531369e6SDave Airlie DRM_ERROR("vline wait had illegal wait until\n"); 978531369e6SDave Airlie r = -EINVAL; 979531369e6SDave Airlie return r; 980531369e6SDave Airlie } 981531369e6SDave Airlie 982531369e6SDave Airlie /* jump over the NOP */ 98390ebd065SAlex Deucher r = r100_cs_packet_parse(p, &p3reloc, p->idx + waitreloc.count + 2); 984531369e6SDave Airlie if (r) 985531369e6SDave Airlie return r; 986531369e6SDave Airlie 987531369e6SDave Airlie h_idx = p->idx - 2; 98890ebd065SAlex Deucher p->idx += waitreloc.count + 2; 98990ebd065SAlex Deucher p->idx += p3reloc.count + 2; 990531369e6SDave Airlie 991513bcb46SDave Airlie header = radeon_get_ib_value(p, h_idx); 992513bcb46SDave Airlie crtc_id = radeon_get_ib_value(p, h_idx + 5); 993d4ac6a05SDave Airlie reg = CP_PACKET0_GET_REG(header); 994531369e6SDave Airlie mutex_lock(&p->rdev->ddev->mode_config.mutex); 995531369e6SDave Airlie obj = drm_mode_object_find(p->rdev->ddev, crtc_id, DRM_MODE_OBJECT_CRTC); 996531369e6SDave Airlie if (!obj) { 997531369e6SDave Airlie DRM_ERROR("cannot find crtc %d\n", crtc_id); 998531369e6SDave Airlie r = -EINVAL; 999531369e6SDave Airlie goto out; 1000531369e6SDave Airlie } 1001531369e6SDave Airlie crtc = obj_to_crtc(obj); 1002531369e6SDave Airlie radeon_crtc = to_radeon_crtc(crtc); 1003531369e6SDave Airlie crtc_id = radeon_crtc->crtc_id; 1004531369e6SDave Airlie 1005531369e6SDave Airlie if (!crtc->enabled) { 1006531369e6SDave Airlie /* if the CRTC isn't enabled - we need to nop out the wait until */ 1007513bcb46SDave Airlie ib[h_idx + 2] = PACKET2(0); 1008513bcb46SDave Airlie ib[h_idx + 3] = PACKET2(0); 1009531369e6SDave Airlie } else if (crtc_id == 1) { 1010531369e6SDave Airlie switch (reg) { 1011531369e6SDave Airlie case AVIVO_D1MODE_VLINE_START_END: 101290ebd065SAlex Deucher header &= ~R300_CP_PACKET0_REG_MASK; 1013531369e6SDave Airlie header |= AVIVO_D2MODE_VLINE_START_END >> 2; 1014531369e6SDave Airlie break; 1015531369e6SDave Airlie case RADEON_CRTC_GUI_TRIG_VLINE: 101690ebd065SAlex Deucher header &= ~R300_CP_PACKET0_REG_MASK; 1017531369e6SDave Airlie header |= RADEON_CRTC2_GUI_TRIG_VLINE >> 2; 1018531369e6SDave Airlie break; 1019531369e6SDave Airlie default: 1020531369e6SDave Airlie DRM_ERROR("unknown crtc reloc\n"); 1021531369e6SDave Airlie r = -EINVAL; 1022531369e6SDave Airlie goto out; 1023531369e6SDave Airlie } 1024513bcb46SDave Airlie ib[h_idx] = header; 1025513bcb46SDave Airlie ib[h_idx + 3] |= RADEON_ENG_DISPLAY_SELECT_CRTC1; 1026531369e6SDave Airlie } 1027531369e6SDave Airlie out: 1028531369e6SDave Airlie mutex_unlock(&p->rdev->ddev->mode_config.mutex); 1029531369e6SDave Airlie return r; 1030531369e6SDave Airlie } 1031531369e6SDave Airlie 1032531369e6SDave Airlie /** 1033771fe6b9SJerome Glisse * r100_cs_packet_next_reloc() - parse next packet which should be reloc packet3 1034771fe6b9SJerome Glisse * @parser: parser structure holding parsing context. 1035771fe6b9SJerome Glisse * @data: pointer to relocation data 1036771fe6b9SJerome Glisse * @offset_start: starting offset 1037771fe6b9SJerome Glisse * @offset_mask: offset mask (to align start offset on) 1038771fe6b9SJerome Glisse * @reloc: reloc informations 1039771fe6b9SJerome Glisse * 1040771fe6b9SJerome Glisse * Check next packet is relocation packet3, do bo validation and compute 1041771fe6b9SJerome Glisse * GPU offset using the provided start. 1042771fe6b9SJerome Glisse **/ 1043771fe6b9SJerome Glisse int r100_cs_packet_next_reloc(struct radeon_cs_parser *p, 1044771fe6b9SJerome Glisse struct radeon_cs_reloc **cs_reloc) 1045771fe6b9SJerome Glisse { 1046771fe6b9SJerome Glisse struct radeon_cs_chunk *relocs_chunk; 1047771fe6b9SJerome Glisse struct radeon_cs_packet p3reloc; 1048771fe6b9SJerome Glisse unsigned idx; 1049771fe6b9SJerome Glisse int r; 1050771fe6b9SJerome Glisse 1051771fe6b9SJerome Glisse if (p->chunk_relocs_idx == -1) { 1052771fe6b9SJerome Glisse DRM_ERROR("No relocation chunk !\n"); 1053771fe6b9SJerome Glisse return -EINVAL; 1054771fe6b9SJerome Glisse } 1055771fe6b9SJerome Glisse *cs_reloc = NULL; 1056771fe6b9SJerome Glisse relocs_chunk = &p->chunks[p->chunk_relocs_idx]; 1057771fe6b9SJerome Glisse r = r100_cs_packet_parse(p, &p3reloc, p->idx); 1058771fe6b9SJerome Glisse if (r) { 1059771fe6b9SJerome Glisse return r; 1060771fe6b9SJerome Glisse } 1061771fe6b9SJerome Glisse p->idx += p3reloc.count + 2; 1062771fe6b9SJerome Glisse if (p3reloc.type != PACKET_TYPE3 || p3reloc.opcode != PACKET3_NOP) { 1063771fe6b9SJerome Glisse DRM_ERROR("No packet3 for relocation for packet at %d.\n", 1064771fe6b9SJerome Glisse p3reloc.idx); 1065771fe6b9SJerome Glisse r100_cs_dump_packet(p, &p3reloc); 1066771fe6b9SJerome Glisse return -EINVAL; 1067771fe6b9SJerome Glisse } 1068513bcb46SDave Airlie idx = radeon_get_ib_value(p, p3reloc.idx + 1); 1069771fe6b9SJerome Glisse if (idx >= relocs_chunk->length_dw) { 1070771fe6b9SJerome Glisse DRM_ERROR("Relocs at %d after relocations chunk end %d !\n", 1071771fe6b9SJerome Glisse idx, relocs_chunk->length_dw); 1072771fe6b9SJerome Glisse r100_cs_dump_packet(p, &p3reloc); 1073771fe6b9SJerome Glisse return -EINVAL; 1074771fe6b9SJerome Glisse } 1075771fe6b9SJerome Glisse /* FIXME: we assume reloc size is 4 dwords */ 1076771fe6b9SJerome Glisse *cs_reloc = p->relocs_ptr[(idx / 4)]; 1077771fe6b9SJerome Glisse return 0; 1078771fe6b9SJerome Glisse } 1079771fe6b9SJerome Glisse 1080551ebd83SDave Airlie static int r100_get_vtx_size(uint32_t vtx_fmt) 1081551ebd83SDave Airlie { 1082551ebd83SDave Airlie int vtx_size; 1083551ebd83SDave Airlie vtx_size = 2; 1084551ebd83SDave Airlie /* ordered according to bits in spec */ 1085551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_W0) 1086551ebd83SDave Airlie vtx_size++; 1087551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_FPCOLOR) 1088551ebd83SDave Airlie vtx_size += 3; 1089551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_FPALPHA) 1090551ebd83SDave Airlie vtx_size++; 1091551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_PKCOLOR) 1092551ebd83SDave Airlie vtx_size++; 1093551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_FPSPEC) 1094551ebd83SDave Airlie vtx_size += 3; 1095551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_FPFOG) 1096551ebd83SDave Airlie vtx_size++; 1097551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_PKSPEC) 1098551ebd83SDave Airlie vtx_size++; 1099551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_ST0) 1100551ebd83SDave Airlie vtx_size += 2; 1101551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_ST1) 1102551ebd83SDave Airlie vtx_size += 2; 1103551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_Q1) 1104551ebd83SDave Airlie vtx_size++; 1105551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_ST2) 1106551ebd83SDave Airlie vtx_size += 2; 1107551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_Q2) 1108551ebd83SDave Airlie vtx_size++; 1109551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_ST3) 1110551ebd83SDave Airlie vtx_size += 2; 1111551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_Q3) 1112551ebd83SDave Airlie vtx_size++; 1113551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_Q0) 1114551ebd83SDave Airlie vtx_size++; 1115551ebd83SDave Airlie /* blend weight */ 1116551ebd83SDave Airlie if (vtx_fmt & (0x7 << 15)) 1117551ebd83SDave Airlie vtx_size += (vtx_fmt >> 15) & 0x7; 1118551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_N0) 1119551ebd83SDave Airlie vtx_size += 3; 1120551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_XY1) 1121551ebd83SDave Airlie vtx_size += 2; 1122551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_Z1) 1123551ebd83SDave Airlie vtx_size++; 1124551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_W1) 1125551ebd83SDave Airlie vtx_size++; 1126551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_N1) 1127551ebd83SDave Airlie vtx_size++; 1128551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_Z) 1129551ebd83SDave Airlie vtx_size++; 1130551ebd83SDave Airlie return vtx_size; 1131551ebd83SDave Airlie } 1132551ebd83SDave Airlie 1133771fe6b9SJerome Glisse static int r100_packet0_check(struct radeon_cs_parser *p, 1134551ebd83SDave Airlie struct radeon_cs_packet *pkt, 1135551ebd83SDave Airlie unsigned idx, unsigned reg) 1136771fe6b9SJerome Glisse { 1137771fe6b9SJerome Glisse struct radeon_cs_reloc *reloc; 1138551ebd83SDave Airlie struct r100_cs_track *track; 1139771fe6b9SJerome Glisse volatile uint32_t *ib; 1140771fe6b9SJerome Glisse uint32_t tmp; 1141771fe6b9SJerome Glisse int r; 1142551ebd83SDave Airlie int i, face; 1143e024e110SDave Airlie u32 tile_flags = 0; 1144513bcb46SDave Airlie u32 idx_value; 1145771fe6b9SJerome Glisse 1146771fe6b9SJerome Glisse ib = p->ib->ptr; 1147551ebd83SDave Airlie track = (struct r100_cs_track *)p->track; 1148551ebd83SDave Airlie 1149513bcb46SDave Airlie idx_value = radeon_get_ib_value(p, idx); 1150513bcb46SDave Airlie 1151771fe6b9SJerome Glisse switch (reg) { 1152531369e6SDave Airlie case RADEON_CRTC_GUI_TRIG_VLINE: 1153531369e6SDave Airlie r = r100_cs_packet_parse_vline(p); 1154531369e6SDave Airlie if (r) { 1155531369e6SDave Airlie DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1156531369e6SDave Airlie idx, reg); 1157531369e6SDave Airlie r100_cs_dump_packet(p, pkt); 1158531369e6SDave Airlie return r; 1159531369e6SDave Airlie } 1160531369e6SDave Airlie break; 1161771fe6b9SJerome Glisse /* FIXME: only allow PACKET3 blit? easier to check for out of 1162771fe6b9SJerome Glisse * range access */ 1163771fe6b9SJerome Glisse case RADEON_DST_PITCH_OFFSET: 1164771fe6b9SJerome Glisse case RADEON_SRC_PITCH_OFFSET: 1165551ebd83SDave Airlie r = r100_reloc_pitch_offset(p, pkt, idx, reg); 1166551ebd83SDave Airlie if (r) 1167551ebd83SDave Airlie return r; 1168551ebd83SDave Airlie break; 1169551ebd83SDave Airlie case RADEON_RB3D_DEPTHOFFSET: 1170771fe6b9SJerome Glisse r = r100_cs_packet_next_reloc(p, &reloc); 1171771fe6b9SJerome Glisse if (r) { 1172771fe6b9SJerome Glisse DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1173771fe6b9SJerome Glisse idx, reg); 1174771fe6b9SJerome Glisse r100_cs_dump_packet(p, pkt); 1175771fe6b9SJerome Glisse return r; 1176771fe6b9SJerome Glisse } 1177551ebd83SDave Airlie track->zb.robj = reloc->robj; 1178513bcb46SDave Airlie track->zb.offset = idx_value; 1179513bcb46SDave Airlie ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); 1180771fe6b9SJerome Glisse break; 1181771fe6b9SJerome Glisse case RADEON_RB3D_COLOROFFSET: 1182551ebd83SDave Airlie r = r100_cs_packet_next_reloc(p, &reloc); 1183551ebd83SDave Airlie if (r) { 1184551ebd83SDave Airlie DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1185551ebd83SDave Airlie idx, reg); 1186551ebd83SDave Airlie r100_cs_dump_packet(p, pkt); 1187551ebd83SDave Airlie return r; 1188551ebd83SDave Airlie } 1189551ebd83SDave Airlie track->cb[0].robj = reloc->robj; 1190513bcb46SDave Airlie track->cb[0].offset = idx_value; 1191513bcb46SDave Airlie ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); 1192551ebd83SDave Airlie break; 1193771fe6b9SJerome Glisse case RADEON_PP_TXOFFSET_0: 1194771fe6b9SJerome Glisse case RADEON_PP_TXOFFSET_1: 1195771fe6b9SJerome Glisse case RADEON_PP_TXOFFSET_2: 1196551ebd83SDave Airlie i = (reg - RADEON_PP_TXOFFSET_0) / 24; 1197771fe6b9SJerome Glisse r = r100_cs_packet_next_reloc(p, &reloc); 1198771fe6b9SJerome Glisse if (r) { 1199771fe6b9SJerome Glisse DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1200771fe6b9SJerome Glisse idx, reg); 1201771fe6b9SJerome Glisse r100_cs_dump_packet(p, pkt); 1202771fe6b9SJerome Glisse return r; 1203771fe6b9SJerome Glisse } 1204513bcb46SDave Airlie ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); 1205551ebd83SDave Airlie track->textures[i].robj = reloc->robj; 1206771fe6b9SJerome Glisse break; 1207551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T0_0: 1208551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T0_1: 1209551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T0_2: 1210551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T0_3: 1211551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T0_4: 1212551ebd83SDave Airlie i = (reg - RADEON_PP_CUBIC_OFFSET_T0_0) / 4; 1213551ebd83SDave Airlie r = r100_cs_packet_next_reloc(p, &reloc); 1214551ebd83SDave Airlie if (r) { 1215551ebd83SDave Airlie DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1216551ebd83SDave Airlie idx, reg); 1217551ebd83SDave Airlie r100_cs_dump_packet(p, pkt); 1218551ebd83SDave Airlie return r; 1219551ebd83SDave Airlie } 1220513bcb46SDave Airlie track->textures[0].cube_info[i].offset = idx_value; 1221513bcb46SDave Airlie ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); 1222551ebd83SDave Airlie track->textures[0].cube_info[i].robj = reloc->robj; 1223551ebd83SDave Airlie break; 1224551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T1_0: 1225551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T1_1: 1226551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T1_2: 1227551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T1_3: 1228551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T1_4: 1229551ebd83SDave Airlie i = (reg - RADEON_PP_CUBIC_OFFSET_T1_0) / 4; 1230551ebd83SDave Airlie r = r100_cs_packet_next_reloc(p, &reloc); 1231551ebd83SDave Airlie if (r) { 1232551ebd83SDave Airlie DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1233551ebd83SDave Airlie idx, reg); 1234551ebd83SDave Airlie r100_cs_dump_packet(p, pkt); 1235551ebd83SDave Airlie return r; 1236551ebd83SDave Airlie } 1237513bcb46SDave Airlie track->textures[1].cube_info[i].offset = idx_value; 1238513bcb46SDave Airlie ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); 1239551ebd83SDave Airlie track->textures[1].cube_info[i].robj = reloc->robj; 1240551ebd83SDave Airlie break; 1241551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T2_0: 1242551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T2_1: 1243551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T2_2: 1244551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T2_3: 1245551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T2_4: 1246551ebd83SDave Airlie i = (reg - RADEON_PP_CUBIC_OFFSET_T2_0) / 4; 1247551ebd83SDave Airlie r = r100_cs_packet_next_reloc(p, &reloc); 1248551ebd83SDave Airlie if (r) { 1249551ebd83SDave Airlie DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1250551ebd83SDave Airlie idx, reg); 1251551ebd83SDave Airlie r100_cs_dump_packet(p, pkt); 1252551ebd83SDave Airlie return r; 1253551ebd83SDave Airlie } 1254513bcb46SDave Airlie track->textures[2].cube_info[i].offset = idx_value; 1255513bcb46SDave Airlie ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); 1256551ebd83SDave Airlie track->textures[2].cube_info[i].robj = reloc->robj; 1257551ebd83SDave Airlie break; 1258551ebd83SDave Airlie case RADEON_RE_WIDTH_HEIGHT: 1259513bcb46SDave Airlie track->maxy = ((idx_value >> 16) & 0x7FF); 1260551ebd83SDave Airlie break; 1261e024e110SDave Airlie case RADEON_RB3D_COLORPITCH: 1262e024e110SDave Airlie r = r100_cs_packet_next_reloc(p, &reloc); 1263e024e110SDave Airlie if (r) { 1264e024e110SDave Airlie DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1265e024e110SDave Airlie idx, reg); 1266e024e110SDave Airlie r100_cs_dump_packet(p, pkt); 1267e024e110SDave Airlie return r; 1268e024e110SDave Airlie } 1269e024e110SDave Airlie 1270e024e110SDave Airlie if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) 1271e024e110SDave Airlie tile_flags |= RADEON_COLOR_TILE_ENABLE; 1272e024e110SDave Airlie if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) 1273e024e110SDave Airlie tile_flags |= RADEON_COLOR_MICROTILE_ENABLE; 1274e024e110SDave Airlie 1275513bcb46SDave Airlie tmp = idx_value & ~(0x7 << 16); 1276e024e110SDave Airlie tmp |= tile_flags; 1277e024e110SDave Airlie ib[idx] = tmp; 1278551ebd83SDave Airlie 1279513bcb46SDave Airlie track->cb[0].pitch = idx_value & RADEON_COLORPITCH_MASK; 1280551ebd83SDave Airlie break; 1281551ebd83SDave Airlie case RADEON_RB3D_DEPTHPITCH: 1282513bcb46SDave Airlie track->zb.pitch = idx_value & RADEON_DEPTHPITCH_MASK; 1283551ebd83SDave Airlie break; 1284551ebd83SDave Airlie case RADEON_RB3D_CNTL: 1285513bcb46SDave Airlie switch ((idx_value >> RADEON_RB3D_COLOR_FORMAT_SHIFT) & 0x1f) { 1286551ebd83SDave Airlie case 7: 1287551ebd83SDave Airlie case 8: 1288551ebd83SDave Airlie case 9: 1289551ebd83SDave Airlie case 11: 1290551ebd83SDave Airlie case 12: 1291551ebd83SDave Airlie track->cb[0].cpp = 1; 1292551ebd83SDave Airlie break; 1293551ebd83SDave Airlie case 3: 1294551ebd83SDave Airlie case 4: 1295551ebd83SDave Airlie case 15: 1296551ebd83SDave Airlie track->cb[0].cpp = 2; 1297551ebd83SDave Airlie break; 1298551ebd83SDave Airlie case 6: 1299551ebd83SDave Airlie track->cb[0].cpp = 4; 1300551ebd83SDave Airlie break; 1301551ebd83SDave Airlie default: 1302551ebd83SDave Airlie DRM_ERROR("Invalid color buffer format (%d) !\n", 1303513bcb46SDave Airlie ((idx_value >> RADEON_RB3D_COLOR_FORMAT_SHIFT) & 0x1f)); 1304551ebd83SDave Airlie return -EINVAL; 1305551ebd83SDave Airlie } 1306513bcb46SDave Airlie track->z_enabled = !!(idx_value & RADEON_Z_ENABLE); 1307551ebd83SDave Airlie break; 1308551ebd83SDave Airlie case RADEON_RB3D_ZSTENCILCNTL: 1309513bcb46SDave Airlie switch (idx_value & 0xf) { 1310551ebd83SDave Airlie case 0: 1311551ebd83SDave Airlie track->zb.cpp = 2; 1312551ebd83SDave Airlie break; 1313551ebd83SDave Airlie case 2: 1314551ebd83SDave Airlie case 3: 1315551ebd83SDave Airlie case 4: 1316551ebd83SDave Airlie case 5: 1317551ebd83SDave Airlie case 9: 1318551ebd83SDave Airlie case 11: 1319551ebd83SDave Airlie track->zb.cpp = 4; 1320551ebd83SDave Airlie break; 1321551ebd83SDave Airlie default: 1322551ebd83SDave Airlie break; 1323551ebd83SDave Airlie } 1324e024e110SDave Airlie break; 132517782d99SDave Airlie case RADEON_RB3D_ZPASS_ADDR: 132617782d99SDave Airlie r = r100_cs_packet_next_reloc(p, &reloc); 132717782d99SDave Airlie if (r) { 132817782d99SDave Airlie DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 132917782d99SDave Airlie idx, reg); 133017782d99SDave Airlie r100_cs_dump_packet(p, pkt); 133117782d99SDave Airlie return r; 133217782d99SDave Airlie } 1333513bcb46SDave Airlie ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); 133417782d99SDave Airlie break; 1335551ebd83SDave Airlie case RADEON_PP_CNTL: 1336551ebd83SDave Airlie { 1337513bcb46SDave Airlie uint32_t temp = idx_value >> 4; 1338551ebd83SDave Airlie for (i = 0; i < track->num_texture; i++) 1339551ebd83SDave Airlie track->textures[i].enabled = !!(temp & (1 << i)); 1340551ebd83SDave Airlie } 1341551ebd83SDave Airlie break; 1342551ebd83SDave Airlie case RADEON_SE_VF_CNTL: 1343513bcb46SDave Airlie track->vap_vf_cntl = idx_value; 1344551ebd83SDave Airlie break; 1345551ebd83SDave Airlie case RADEON_SE_VTX_FMT: 1346513bcb46SDave Airlie track->vtx_size = r100_get_vtx_size(idx_value); 1347551ebd83SDave Airlie break; 1348551ebd83SDave Airlie case RADEON_PP_TEX_SIZE_0: 1349551ebd83SDave Airlie case RADEON_PP_TEX_SIZE_1: 1350551ebd83SDave Airlie case RADEON_PP_TEX_SIZE_2: 1351551ebd83SDave Airlie i = (reg - RADEON_PP_TEX_SIZE_0) / 8; 1352513bcb46SDave Airlie track->textures[i].width = (idx_value & RADEON_TEX_USIZE_MASK) + 1; 1353513bcb46SDave Airlie track->textures[i].height = ((idx_value & RADEON_TEX_VSIZE_MASK) >> RADEON_TEX_VSIZE_SHIFT) + 1; 1354551ebd83SDave Airlie break; 1355551ebd83SDave Airlie case RADEON_PP_TEX_PITCH_0: 1356551ebd83SDave Airlie case RADEON_PP_TEX_PITCH_1: 1357551ebd83SDave Airlie case RADEON_PP_TEX_PITCH_2: 1358551ebd83SDave Airlie i = (reg - RADEON_PP_TEX_PITCH_0) / 8; 1359513bcb46SDave Airlie track->textures[i].pitch = idx_value + 32; 1360551ebd83SDave Airlie break; 1361551ebd83SDave Airlie case RADEON_PP_TXFILTER_0: 1362551ebd83SDave Airlie case RADEON_PP_TXFILTER_1: 1363551ebd83SDave Airlie case RADEON_PP_TXFILTER_2: 1364551ebd83SDave Airlie i = (reg - RADEON_PP_TXFILTER_0) / 24; 1365513bcb46SDave Airlie track->textures[i].num_levels = ((idx_value & RADEON_MAX_MIP_LEVEL_MASK) 1366551ebd83SDave Airlie >> RADEON_MAX_MIP_LEVEL_SHIFT); 1367513bcb46SDave Airlie tmp = (idx_value >> 23) & 0x7; 1368551ebd83SDave Airlie if (tmp == 2 || tmp == 6) 1369551ebd83SDave Airlie track->textures[i].roundup_w = false; 1370513bcb46SDave Airlie tmp = (idx_value >> 27) & 0x7; 1371551ebd83SDave Airlie if (tmp == 2 || tmp == 6) 1372551ebd83SDave Airlie track->textures[i].roundup_h = false; 1373551ebd83SDave Airlie break; 1374551ebd83SDave Airlie case RADEON_PP_TXFORMAT_0: 1375551ebd83SDave Airlie case RADEON_PP_TXFORMAT_1: 1376551ebd83SDave Airlie case RADEON_PP_TXFORMAT_2: 1377551ebd83SDave Airlie i = (reg - RADEON_PP_TXFORMAT_0) / 24; 1378513bcb46SDave Airlie if (idx_value & RADEON_TXFORMAT_NON_POWER2) { 1379551ebd83SDave Airlie track->textures[i].use_pitch = 1; 1380551ebd83SDave Airlie } else { 1381551ebd83SDave Airlie track->textures[i].use_pitch = 0; 1382513bcb46SDave Airlie track->textures[i].width = 1 << ((idx_value >> RADEON_TXFORMAT_WIDTH_SHIFT) & RADEON_TXFORMAT_WIDTH_MASK); 1383513bcb46SDave Airlie track->textures[i].height = 1 << ((idx_value >> RADEON_TXFORMAT_HEIGHT_SHIFT) & RADEON_TXFORMAT_HEIGHT_MASK); 1384551ebd83SDave Airlie } 1385513bcb46SDave Airlie if (idx_value & RADEON_TXFORMAT_CUBIC_MAP_ENABLE) 1386551ebd83SDave Airlie track->textures[i].tex_coord_type = 2; 1387513bcb46SDave Airlie switch ((idx_value & RADEON_TXFORMAT_FORMAT_MASK)) { 1388551ebd83SDave Airlie case RADEON_TXFORMAT_I8: 1389551ebd83SDave Airlie case RADEON_TXFORMAT_RGB332: 1390551ebd83SDave Airlie case RADEON_TXFORMAT_Y8: 1391551ebd83SDave Airlie track->textures[i].cpp = 1; 1392551ebd83SDave Airlie break; 1393551ebd83SDave Airlie case RADEON_TXFORMAT_AI88: 1394551ebd83SDave Airlie case RADEON_TXFORMAT_ARGB1555: 1395551ebd83SDave Airlie case RADEON_TXFORMAT_RGB565: 1396551ebd83SDave Airlie case RADEON_TXFORMAT_ARGB4444: 1397551ebd83SDave Airlie case RADEON_TXFORMAT_VYUY422: 1398551ebd83SDave Airlie case RADEON_TXFORMAT_YVYU422: 1399551ebd83SDave Airlie case RADEON_TXFORMAT_SHADOW16: 1400551ebd83SDave Airlie case RADEON_TXFORMAT_LDUDV655: 1401551ebd83SDave Airlie case RADEON_TXFORMAT_DUDV88: 1402551ebd83SDave Airlie track->textures[i].cpp = 2; 1403551ebd83SDave Airlie break; 1404551ebd83SDave Airlie case RADEON_TXFORMAT_ARGB8888: 1405551ebd83SDave Airlie case RADEON_TXFORMAT_RGBA8888: 1406551ebd83SDave Airlie case RADEON_TXFORMAT_SHADOW32: 1407551ebd83SDave Airlie case RADEON_TXFORMAT_LDUDUV8888: 1408551ebd83SDave Airlie track->textures[i].cpp = 4; 1409551ebd83SDave Airlie break; 1410d785d78bSDave Airlie case RADEON_TXFORMAT_DXT1: 1411d785d78bSDave Airlie track->textures[i].cpp = 1; 1412d785d78bSDave Airlie track->textures[i].compress_format = R100_TRACK_COMP_DXT1; 1413d785d78bSDave Airlie break; 1414d785d78bSDave Airlie case RADEON_TXFORMAT_DXT23: 1415d785d78bSDave Airlie case RADEON_TXFORMAT_DXT45: 1416d785d78bSDave Airlie track->textures[i].cpp = 1; 1417d785d78bSDave Airlie track->textures[i].compress_format = R100_TRACK_COMP_DXT35; 1418d785d78bSDave Airlie break; 1419551ebd83SDave Airlie } 1420513bcb46SDave Airlie track->textures[i].cube_info[4].width = 1 << ((idx_value >> 16) & 0xf); 1421513bcb46SDave Airlie track->textures[i].cube_info[4].height = 1 << ((idx_value >> 20) & 0xf); 1422551ebd83SDave Airlie break; 1423551ebd83SDave Airlie case RADEON_PP_CUBIC_FACES_0: 1424551ebd83SDave Airlie case RADEON_PP_CUBIC_FACES_1: 1425551ebd83SDave Airlie case RADEON_PP_CUBIC_FACES_2: 1426513bcb46SDave Airlie tmp = idx_value; 1427551ebd83SDave Airlie i = (reg - RADEON_PP_CUBIC_FACES_0) / 4; 1428551ebd83SDave Airlie for (face = 0; face < 4; face++) { 1429551ebd83SDave Airlie track->textures[i].cube_info[face].width = 1 << ((tmp >> (face * 8)) & 0xf); 1430551ebd83SDave Airlie track->textures[i].cube_info[face].height = 1 << ((tmp >> ((face * 8) + 4)) & 0xf); 1431551ebd83SDave Airlie } 1432551ebd83SDave Airlie break; 1433771fe6b9SJerome Glisse default: 1434551ebd83SDave Airlie printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n", 1435551ebd83SDave Airlie reg, idx); 1436551ebd83SDave Airlie return -EINVAL; 1437771fe6b9SJerome Glisse } 1438771fe6b9SJerome Glisse return 0; 1439771fe6b9SJerome Glisse } 1440771fe6b9SJerome Glisse 1441068a117cSJerome Glisse int r100_cs_track_check_pkt3_indx_buffer(struct radeon_cs_parser *p, 1442068a117cSJerome Glisse struct radeon_cs_packet *pkt, 14434c788679SJerome Glisse struct radeon_bo *robj) 1444068a117cSJerome Glisse { 1445068a117cSJerome Glisse unsigned idx; 1446513bcb46SDave Airlie u32 value; 1447068a117cSJerome Glisse idx = pkt->idx + 1; 1448513bcb46SDave Airlie value = radeon_get_ib_value(p, idx + 2); 14494c788679SJerome Glisse if ((value + 1) > radeon_bo_size(robj)) { 1450068a117cSJerome Glisse DRM_ERROR("[drm] Buffer too small for PACKET3 INDX_BUFFER " 1451068a117cSJerome Glisse "(need %u have %lu) !\n", 1452513bcb46SDave Airlie value + 1, 14534c788679SJerome Glisse radeon_bo_size(robj)); 1454068a117cSJerome Glisse return -EINVAL; 1455068a117cSJerome Glisse } 1456068a117cSJerome Glisse return 0; 1457068a117cSJerome Glisse } 1458068a117cSJerome Glisse 1459771fe6b9SJerome Glisse static int r100_packet3_check(struct radeon_cs_parser *p, 1460771fe6b9SJerome Glisse struct radeon_cs_packet *pkt) 1461771fe6b9SJerome Glisse { 1462771fe6b9SJerome Glisse struct radeon_cs_reloc *reloc; 1463551ebd83SDave Airlie struct r100_cs_track *track; 1464771fe6b9SJerome Glisse unsigned idx; 1465771fe6b9SJerome Glisse volatile uint32_t *ib; 1466771fe6b9SJerome Glisse int r; 1467771fe6b9SJerome Glisse 1468771fe6b9SJerome Glisse ib = p->ib->ptr; 1469771fe6b9SJerome Glisse idx = pkt->idx + 1; 1470551ebd83SDave Airlie track = (struct r100_cs_track *)p->track; 1471771fe6b9SJerome Glisse switch (pkt->opcode) { 1472771fe6b9SJerome Glisse case PACKET3_3D_LOAD_VBPNTR: 1473513bcb46SDave Airlie r = r100_packet3_load_vbpntr(p, pkt, idx); 1474513bcb46SDave Airlie if (r) 1475771fe6b9SJerome Glisse return r; 1476771fe6b9SJerome Glisse break; 1477771fe6b9SJerome Glisse case PACKET3_INDX_BUFFER: 1478771fe6b9SJerome Glisse r = r100_cs_packet_next_reloc(p, &reloc); 1479771fe6b9SJerome Glisse if (r) { 1480771fe6b9SJerome Glisse DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode); 1481771fe6b9SJerome Glisse r100_cs_dump_packet(p, pkt); 1482771fe6b9SJerome Glisse return r; 1483771fe6b9SJerome Glisse } 1484513bcb46SDave Airlie ib[idx+1] = radeon_get_ib_value(p, idx+1) + ((u32)reloc->lobj.gpu_offset); 1485068a117cSJerome Glisse r = r100_cs_track_check_pkt3_indx_buffer(p, pkt, reloc->robj); 1486068a117cSJerome Glisse if (r) { 1487068a117cSJerome Glisse return r; 1488068a117cSJerome Glisse } 1489771fe6b9SJerome Glisse break; 1490771fe6b9SJerome Glisse case 0x23: 1491771fe6b9SJerome Glisse /* 3D_RNDR_GEN_INDX_PRIM on r100/r200 */ 1492771fe6b9SJerome Glisse r = r100_cs_packet_next_reloc(p, &reloc); 1493771fe6b9SJerome Glisse if (r) { 1494771fe6b9SJerome Glisse DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode); 1495771fe6b9SJerome Glisse r100_cs_dump_packet(p, pkt); 1496771fe6b9SJerome Glisse return r; 1497771fe6b9SJerome Glisse } 1498513bcb46SDave Airlie ib[idx] = radeon_get_ib_value(p, idx) + ((u32)reloc->lobj.gpu_offset); 1499551ebd83SDave Airlie track->num_arrays = 1; 1500513bcb46SDave Airlie track->vtx_size = r100_get_vtx_size(radeon_get_ib_value(p, idx + 2)); 1501551ebd83SDave Airlie 1502551ebd83SDave Airlie track->arrays[0].robj = reloc->robj; 1503551ebd83SDave Airlie track->arrays[0].esize = track->vtx_size; 1504551ebd83SDave Airlie 1505513bcb46SDave Airlie track->max_indx = radeon_get_ib_value(p, idx+1); 1506551ebd83SDave Airlie 1507513bcb46SDave Airlie track->vap_vf_cntl = radeon_get_ib_value(p, idx+3); 1508551ebd83SDave Airlie track->immd_dwords = pkt->count - 1; 1509551ebd83SDave Airlie r = r100_cs_track_check(p->rdev, track); 1510551ebd83SDave Airlie if (r) 1511551ebd83SDave Airlie return r; 1512771fe6b9SJerome Glisse break; 1513771fe6b9SJerome Glisse case PACKET3_3D_DRAW_IMMD: 1514513bcb46SDave Airlie if (((radeon_get_ib_value(p, idx + 1) >> 4) & 0x3) != 3) { 1515551ebd83SDave Airlie DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n"); 1516551ebd83SDave Airlie return -EINVAL; 1517551ebd83SDave Airlie } 1518cf57fc7aSAlex Deucher track->vtx_size = r100_get_vtx_size(radeon_get_ib_value(p, idx + 0)); 1519513bcb46SDave Airlie track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1); 1520551ebd83SDave Airlie track->immd_dwords = pkt->count - 1; 1521551ebd83SDave Airlie r = r100_cs_track_check(p->rdev, track); 1522551ebd83SDave Airlie if (r) 1523551ebd83SDave Airlie return r; 1524551ebd83SDave Airlie break; 1525771fe6b9SJerome Glisse /* triggers drawing using in-packet vertex data */ 1526771fe6b9SJerome Glisse case PACKET3_3D_DRAW_IMMD_2: 1527513bcb46SDave Airlie if (((radeon_get_ib_value(p, idx) >> 4) & 0x3) != 3) { 1528551ebd83SDave Airlie DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n"); 1529551ebd83SDave Airlie return -EINVAL; 1530551ebd83SDave Airlie } 1531513bcb46SDave Airlie track->vap_vf_cntl = radeon_get_ib_value(p, idx); 1532551ebd83SDave Airlie track->immd_dwords = pkt->count; 1533551ebd83SDave Airlie r = r100_cs_track_check(p->rdev, track); 1534551ebd83SDave Airlie if (r) 1535551ebd83SDave Airlie return r; 1536551ebd83SDave Airlie break; 1537771fe6b9SJerome Glisse /* triggers drawing using in-packet vertex data */ 1538771fe6b9SJerome Glisse case PACKET3_3D_DRAW_VBUF_2: 1539513bcb46SDave Airlie track->vap_vf_cntl = radeon_get_ib_value(p, idx); 1540551ebd83SDave Airlie r = r100_cs_track_check(p->rdev, track); 1541551ebd83SDave Airlie if (r) 1542551ebd83SDave Airlie return r; 1543551ebd83SDave Airlie break; 1544771fe6b9SJerome Glisse /* triggers drawing of vertex buffers setup elsewhere */ 1545771fe6b9SJerome Glisse case PACKET3_3D_DRAW_INDX_2: 1546513bcb46SDave Airlie track->vap_vf_cntl = radeon_get_ib_value(p, idx); 1547551ebd83SDave Airlie r = r100_cs_track_check(p->rdev, track); 1548551ebd83SDave Airlie if (r) 1549551ebd83SDave Airlie return r; 1550551ebd83SDave Airlie break; 1551771fe6b9SJerome Glisse /* triggers drawing using indices to vertex buffer */ 1552771fe6b9SJerome Glisse case PACKET3_3D_DRAW_VBUF: 1553513bcb46SDave Airlie track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1); 1554551ebd83SDave Airlie r = r100_cs_track_check(p->rdev, track); 1555551ebd83SDave Airlie if (r) 1556551ebd83SDave Airlie return r; 1557551ebd83SDave Airlie break; 1558771fe6b9SJerome Glisse /* triggers drawing of vertex buffers setup elsewhere */ 1559771fe6b9SJerome Glisse case PACKET3_3D_DRAW_INDX: 1560513bcb46SDave Airlie track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1); 1561551ebd83SDave Airlie r = r100_cs_track_check(p->rdev, track); 1562551ebd83SDave Airlie if (r) 1563551ebd83SDave Airlie return r; 1564551ebd83SDave Airlie break; 1565771fe6b9SJerome Glisse /* triggers drawing using indices to vertex buffer */ 1566771fe6b9SJerome Glisse case PACKET3_NOP: 1567771fe6b9SJerome Glisse break; 1568771fe6b9SJerome Glisse default: 1569771fe6b9SJerome Glisse DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode); 1570771fe6b9SJerome Glisse return -EINVAL; 1571771fe6b9SJerome Glisse } 1572771fe6b9SJerome Glisse return 0; 1573771fe6b9SJerome Glisse } 1574771fe6b9SJerome Glisse 1575771fe6b9SJerome Glisse int r100_cs_parse(struct radeon_cs_parser *p) 1576771fe6b9SJerome Glisse { 1577771fe6b9SJerome Glisse struct radeon_cs_packet pkt; 15789f022ddfSJerome Glisse struct r100_cs_track *track; 1579771fe6b9SJerome Glisse int r; 1580771fe6b9SJerome Glisse 15819f022ddfSJerome Glisse track = kzalloc(sizeof(*track), GFP_KERNEL); 15829f022ddfSJerome Glisse r100_cs_track_clear(p->rdev, track); 15839f022ddfSJerome Glisse p->track = track; 1584771fe6b9SJerome Glisse do { 1585771fe6b9SJerome Glisse r = r100_cs_packet_parse(p, &pkt, p->idx); 1586771fe6b9SJerome Glisse if (r) { 1587771fe6b9SJerome Glisse return r; 1588771fe6b9SJerome Glisse } 1589771fe6b9SJerome Glisse p->idx += pkt.count + 2; 1590771fe6b9SJerome Glisse switch (pkt.type) { 1591771fe6b9SJerome Glisse case PACKET_TYPE0: 1592551ebd83SDave Airlie if (p->rdev->family >= CHIP_R200) 1593551ebd83SDave Airlie r = r100_cs_parse_packet0(p, &pkt, 1594551ebd83SDave Airlie p->rdev->config.r100.reg_safe_bm, 1595551ebd83SDave Airlie p->rdev->config.r100.reg_safe_bm_size, 1596551ebd83SDave Airlie &r200_packet0_check); 1597551ebd83SDave Airlie else 1598551ebd83SDave Airlie r = r100_cs_parse_packet0(p, &pkt, 1599551ebd83SDave Airlie p->rdev->config.r100.reg_safe_bm, 1600551ebd83SDave Airlie p->rdev->config.r100.reg_safe_bm_size, 1601551ebd83SDave Airlie &r100_packet0_check); 1602771fe6b9SJerome Glisse break; 1603771fe6b9SJerome Glisse case PACKET_TYPE2: 1604771fe6b9SJerome Glisse break; 1605771fe6b9SJerome Glisse case PACKET_TYPE3: 1606771fe6b9SJerome Glisse r = r100_packet3_check(p, &pkt); 1607771fe6b9SJerome Glisse break; 1608771fe6b9SJerome Glisse default: 1609771fe6b9SJerome Glisse DRM_ERROR("Unknown packet type %d !\n", 1610771fe6b9SJerome Glisse pkt.type); 1611771fe6b9SJerome Glisse return -EINVAL; 1612771fe6b9SJerome Glisse } 1613771fe6b9SJerome Glisse if (r) { 1614771fe6b9SJerome Glisse return r; 1615771fe6b9SJerome Glisse } 1616771fe6b9SJerome Glisse } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw); 1617771fe6b9SJerome Glisse return 0; 1618771fe6b9SJerome Glisse } 1619771fe6b9SJerome Glisse 1620771fe6b9SJerome Glisse 1621771fe6b9SJerome Glisse /* 1622771fe6b9SJerome Glisse * Global GPU functions 1623771fe6b9SJerome Glisse */ 1624771fe6b9SJerome Glisse void r100_errata(struct radeon_device *rdev) 1625771fe6b9SJerome Glisse { 1626771fe6b9SJerome Glisse rdev->pll_errata = 0; 1627771fe6b9SJerome Glisse 1628771fe6b9SJerome Glisse if (rdev->family == CHIP_RV200 || rdev->family == CHIP_RS200) { 1629771fe6b9SJerome Glisse rdev->pll_errata |= CHIP_ERRATA_PLL_DUMMYREADS; 1630771fe6b9SJerome Glisse } 1631771fe6b9SJerome Glisse 1632771fe6b9SJerome Glisse if (rdev->family == CHIP_RV100 || 1633771fe6b9SJerome Glisse rdev->family == CHIP_RS100 || 1634771fe6b9SJerome Glisse rdev->family == CHIP_RS200) { 1635771fe6b9SJerome Glisse rdev->pll_errata |= CHIP_ERRATA_PLL_DELAY; 1636771fe6b9SJerome Glisse } 1637771fe6b9SJerome Glisse } 1638771fe6b9SJerome Glisse 1639771fe6b9SJerome Glisse /* Wait for vertical sync on primary CRTC */ 1640771fe6b9SJerome Glisse void r100_gpu_wait_for_vsync(struct radeon_device *rdev) 1641771fe6b9SJerome Glisse { 1642771fe6b9SJerome Glisse uint32_t crtc_gen_cntl, tmp; 1643771fe6b9SJerome Glisse int i; 1644771fe6b9SJerome Glisse 1645771fe6b9SJerome Glisse crtc_gen_cntl = RREG32(RADEON_CRTC_GEN_CNTL); 1646771fe6b9SJerome Glisse if ((crtc_gen_cntl & RADEON_CRTC_DISP_REQ_EN_B) || 1647771fe6b9SJerome Glisse !(crtc_gen_cntl & RADEON_CRTC_EN)) { 1648771fe6b9SJerome Glisse return; 1649771fe6b9SJerome Glisse } 1650771fe6b9SJerome Glisse /* Clear the CRTC_VBLANK_SAVE bit */ 1651771fe6b9SJerome Glisse WREG32(RADEON_CRTC_STATUS, RADEON_CRTC_VBLANK_SAVE_CLEAR); 1652771fe6b9SJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 1653771fe6b9SJerome Glisse tmp = RREG32(RADEON_CRTC_STATUS); 1654771fe6b9SJerome Glisse if (tmp & RADEON_CRTC_VBLANK_SAVE) { 1655771fe6b9SJerome Glisse return; 1656771fe6b9SJerome Glisse } 1657771fe6b9SJerome Glisse DRM_UDELAY(1); 1658771fe6b9SJerome Glisse } 1659771fe6b9SJerome Glisse } 1660771fe6b9SJerome Glisse 1661771fe6b9SJerome Glisse /* Wait for vertical sync on secondary CRTC */ 1662771fe6b9SJerome Glisse void r100_gpu_wait_for_vsync2(struct radeon_device *rdev) 1663771fe6b9SJerome Glisse { 1664771fe6b9SJerome Glisse uint32_t crtc2_gen_cntl, tmp; 1665771fe6b9SJerome Glisse int i; 1666771fe6b9SJerome Glisse 1667771fe6b9SJerome Glisse crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL); 1668771fe6b9SJerome Glisse if ((crtc2_gen_cntl & RADEON_CRTC2_DISP_REQ_EN_B) || 1669771fe6b9SJerome Glisse !(crtc2_gen_cntl & RADEON_CRTC2_EN)) 1670771fe6b9SJerome Glisse return; 1671771fe6b9SJerome Glisse 1672771fe6b9SJerome Glisse /* Clear the CRTC_VBLANK_SAVE bit */ 1673771fe6b9SJerome Glisse WREG32(RADEON_CRTC2_STATUS, RADEON_CRTC2_VBLANK_SAVE_CLEAR); 1674771fe6b9SJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 1675771fe6b9SJerome Glisse tmp = RREG32(RADEON_CRTC2_STATUS); 1676771fe6b9SJerome Glisse if (tmp & RADEON_CRTC2_VBLANK_SAVE) { 1677771fe6b9SJerome Glisse return; 1678771fe6b9SJerome Glisse } 1679771fe6b9SJerome Glisse DRM_UDELAY(1); 1680771fe6b9SJerome Glisse } 1681771fe6b9SJerome Glisse } 1682771fe6b9SJerome Glisse 1683771fe6b9SJerome Glisse int r100_rbbm_fifo_wait_for_entry(struct radeon_device *rdev, unsigned n) 1684771fe6b9SJerome Glisse { 1685771fe6b9SJerome Glisse unsigned i; 1686771fe6b9SJerome Glisse uint32_t tmp; 1687771fe6b9SJerome Glisse 1688771fe6b9SJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 1689771fe6b9SJerome Glisse tmp = RREG32(RADEON_RBBM_STATUS) & RADEON_RBBM_FIFOCNT_MASK; 1690771fe6b9SJerome Glisse if (tmp >= n) { 1691771fe6b9SJerome Glisse return 0; 1692771fe6b9SJerome Glisse } 1693771fe6b9SJerome Glisse DRM_UDELAY(1); 1694771fe6b9SJerome Glisse } 1695771fe6b9SJerome Glisse return -1; 1696771fe6b9SJerome Glisse } 1697771fe6b9SJerome Glisse 1698771fe6b9SJerome Glisse int r100_gui_wait_for_idle(struct radeon_device *rdev) 1699771fe6b9SJerome Glisse { 1700771fe6b9SJerome Glisse unsigned i; 1701771fe6b9SJerome Glisse uint32_t tmp; 1702771fe6b9SJerome Glisse 1703771fe6b9SJerome Glisse if (r100_rbbm_fifo_wait_for_entry(rdev, 64)) { 1704771fe6b9SJerome Glisse printk(KERN_WARNING "radeon: wait for empty RBBM fifo failed !" 1705771fe6b9SJerome Glisse " Bad things might happen.\n"); 1706771fe6b9SJerome Glisse } 1707771fe6b9SJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 1708771fe6b9SJerome Glisse tmp = RREG32(RADEON_RBBM_STATUS); 17094612dc97SAlex Deucher if (!(tmp & RADEON_RBBM_ACTIVE)) { 1710771fe6b9SJerome Glisse return 0; 1711771fe6b9SJerome Glisse } 1712771fe6b9SJerome Glisse DRM_UDELAY(1); 1713771fe6b9SJerome Glisse } 1714771fe6b9SJerome Glisse return -1; 1715771fe6b9SJerome Glisse } 1716771fe6b9SJerome Glisse 1717771fe6b9SJerome Glisse int r100_mc_wait_for_idle(struct radeon_device *rdev) 1718771fe6b9SJerome Glisse { 1719771fe6b9SJerome Glisse unsigned i; 1720771fe6b9SJerome Glisse uint32_t tmp; 1721771fe6b9SJerome Glisse 1722771fe6b9SJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 1723771fe6b9SJerome Glisse /* read MC_STATUS */ 17244612dc97SAlex Deucher tmp = RREG32(RADEON_MC_STATUS); 17254612dc97SAlex Deucher if (tmp & RADEON_MC_IDLE) { 1726771fe6b9SJerome Glisse return 0; 1727771fe6b9SJerome Glisse } 1728771fe6b9SJerome Glisse DRM_UDELAY(1); 1729771fe6b9SJerome Glisse } 1730771fe6b9SJerome Glisse return -1; 1731771fe6b9SJerome Glisse } 1732771fe6b9SJerome Glisse 1733771fe6b9SJerome Glisse void r100_gpu_init(struct radeon_device *rdev) 1734771fe6b9SJerome Glisse { 1735771fe6b9SJerome Glisse /* TODO: anythings to do here ? pipes ? */ 1736771fe6b9SJerome Glisse r100_hdp_reset(rdev); 1737771fe6b9SJerome Glisse } 1738771fe6b9SJerome Glisse 1739771fe6b9SJerome Glisse void r100_hdp_reset(struct radeon_device *rdev) 1740771fe6b9SJerome Glisse { 1741771fe6b9SJerome Glisse uint32_t tmp; 1742771fe6b9SJerome Glisse 1743771fe6b9SJerome Glisse tmp = RREG32(RADEON_HOST_PATH_CNTL) & RADEON_HDP_APER_CNTL; 1744771fe6b9SJerome Glisse tmp |= (7 << 28); 1745771fe6b9SJerome Glisse WREG32(RADEON_HOST_PATH_CNTL, tmp | RADEON_HDP_SOFT_RESET | RADEON_HDP_READ_BUFFER_INVALIDATE); 1746771fe6b9SJerome Glisse (void)RREG32(RADEON_HOST_PATH_CNTL); 1747771fe6b9SJerome Glisse udelay(200); 1748771fe6b9SJerome Glisse WREG32(RADEON_RBBM_SOFT_RESET, 0); 1749771fe6b9SJerome Glisse WREG32(RADEON_HOST_PATH_CNTL, tmp); 1750771fe6b9SJerome Glisse (void)RREG32(RADEON_HOST_PATH_CNTL); 1751771fe6b9SJerome Glisse } 1752771fe6b9SJerome Glisse 1753771fe6b9SJerome Glisse int r100_rb2d_reset(struct radeon_device *rdev) 1754771fe6b9SJerome Glisse { 1755771fe6b9SJerome Glisse uint32_t tmp; 1756771fe6b9SJerome Glisse int i; 1757771fe6b9SJerome Glisse 1758771fe6b9SJerome Glisse WREG32(RADEON_RBBM_SOFT_RESET, RADEON_SOFT_RESET_E2); 1759771fe6b9SJerome Glisse (void)RREG32(RADEON_RBBM_SOFT_RESET); 1760771fe6b9SJerome Glisse udelay(200); 1761771fe6b9SJerome Glisse WREG32(RADEON_RBBM_SOFT_RESET, 0); 1762771fe6b9SJerome Glisse /* Wait to prevent race in RBBM_STATUS */ 1763771fe6b9SJerome Glisse mdelay(1); 1764771fe6b9SJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 1765771fe6b9SJerome Glisse tmp = RREG32(RADEON_RBBM_STATUS); 1766771fe6b9SJerome Glisse if (!(tmp & (1 << 26))) { 1767771fe6b9SJerome Glisse DRM_INFO("RB2D reset succeed (RBBM_STATUS=0x%08X)\n", 1768771fe6b9SJerome Glisse tmp); 1769771fe6b9SJerome Glisse return 0; 1770771fe6b9SJerome Glisse } 1771771fe6b9SJerome Glisse DRM_UDELAY(1); 1772771fe6b9SJerome Glisse } 1773771fe6b9SJerome Glisse tmp = RREG32(RADEON_RBBM_STATUS); 1774771fe6b9SJerome Glisse DRM_ERROR("Failed to reset RB2D (RBBM_STATUS=0x%08X)!\n", tmp); 1775771fe6b9SJerome Glisse return -1; 1776771fe6b9SJerome Glisse } 1777771fe6b9SJerome Glisse 1778771fe6b9SJerome Glisse int r100_gpu_reset(struct radeon_device *rdev) 1779771fe6b9SJerome Glisse { 1780771fe6b9SJerome Glisse uint32_t status; 1781771fe6b9SJerome Glisse 1782771fe6b9SJerome Glisse /* reset order likely matter */ 1783771fe6b9SJerome Glisse status = RREG32(RADEON_RBBM_STATUS); 1784771fe6b9SJerome Glisse /* reset HDP */ 1785771fe6b9SJerome Glisse r100_hdp_reset(rdev); 1786771fe6b9SJerome Glisse /* reset rb2d */ 1787771fe6b9SJerome Glisse if (status & ((1 << 17) | (1 << 18) | (1 << 27))) { 1788771fe6b9SJerome Glisse r100_rb2d_reset(rdev); 1789771fe6b9SJerome Glisse } 1790771fe6b9SJerome Glisse /* TODO: reset 3D engine */ 1791771fe6b9SJerome Glisse /* reset CP */ 1792771fe6b9SJerome Glisse status = RREG32(RADEON_RBBM_STATUS); 1793771fe6b9SJerome Glisse if (status & (1 << 16)) { 1794771fe6b9SJerome Glisse r100_cp_reset(rdev); 1795771fe6b9SJerome Glisse } 1796771fe6b9SJerome Glisse /* Check if GPU is idle */ 1797771fe6b9SJerome Glisse status = RREG32(RADEON_RBBM_STATUS); 17984612dc97SAlex Deucher if (status & RADEON_RBBM_ACTIVE) { 1799771fe6b9SJerome Glisse DRM_ERROR("Failed to reset GPU (RBBM_STATUS=0x%08X)\n", status); 1800771fe6b9SJerome Glisse return -1; 1801771fe6b9SJerome Glisse } 1802771fe6b9SJerome Glisse DRM_INFO("GPU reset succeed (RBBM_STATUS=0x%08X)\n", status); 1803771fe6b9SJerome Glisse return 0; 1804771fe6b9SJerome Glisse } 1805771fe6b9SJerome Glisse 180692cde00cSAlex Deucher void r100_set_common_regs(struct radeon_device *rdev) 180792cde00cSAlex Deucher { 18082739d49cSAlex Deucher struct drm_device *dev = rdev->ddev; 18092739d49cSAlex Deucher bool force_dac2 = false; 18102739d49cSAlex Deucher 181192cde00cSAlex Deucher /* set these so they don't interfere with anything */ 181292cde00cSAlex Deucher WREG32(RADEON_OV0_SCALE_CNTL, 0); 181392cde00cSAlex Deucher WREG32(RADEON_SUBPIC_CNTL, 0); 181492cde00cSAlex Deucher WREG32(RADEON_VIPH_CONTROL, 0); 181592cde00cSAlex Deucher WREG32(RADEON_I2C_CNTL_1, 0); 181692cde00cSAlex Deucher WREG32(RADEON_DVI_I2C_CNTL_1, 0); 181792cde00cSAlex Deucher WREG32(RADEON_CAP0_TRIG_CNTL, 0); 181892cde00cSAlex Deucher WREG32(RADEON_CAP1_TRIG_CNTL, 0); 18192739d49cSAlex Deucher 18202739d49cSAlex Deucher /* always set up dac2 on rn50 and some rv100 as lots 18212739d49cSAlex Deucher * of servers seem to wire it up to a VGA port but 18222739d49cSAlex Deucher * don't report it in the bios connector 18232739d49cSAlex Deucher * table. 18242739d49cSAlex Deucher */ 18252739d49cSAlex Deucher switch (dev->pdev->device) { 18262739d49cSAlex Deucher /* RN50 */ 18272739d49cSAlex Deucher case 0x515e: 18282739d49cSAlex Deucher case 0x5969: 18292739d49cSAlex Deucher force_dac2 = true; 18302739d49cSAlex Deucher break; 18312739d49cSAlex Deucher /* RV100*/ 18322739d49cSAlex Deucher case 0x5159: 18332739d49cSAlex Deucher case 0x515a: 18342739d49cSAlex Deucher /* DELL triple head servers */ 18352739d49cSAlex Deucher if ((dev->pdev->subsystem_vendor == 0x1028 /* DELL */) && 18362739d49cSAlex Deucher ((dev->pdev->subsystem_device == 0x016c) || 18372739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x016d) || 18382739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x016e) || 18392739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x016f) || 18402739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x0170) || 18412739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x017d) || 18422739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x017e) || 18432739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x0183) || 18442739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x018a) || 18452739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x019a))) 18462739d49cSAlex Deucher force_dac2 = true; 18472739d49cSAlex Deucher break; 18482739d49cSAlex Deucher } 18492739d49cSAlex Deucher 18502739d49cSAlex Deucher if (force_dac2) { 18512739d49cSAlex Deucher u32 disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG); 18522739d49cSAlex Deucher u32 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL); 18532739d49cSAlex Deucher u32 dac2_cntl = RREG32(RADEON_DAC_CNTL2); 18542739d49cSAlex Deucher 18552739d49cSAlex Deucher /* For CRT on DAC2, don't turn it on if BIOS didn't 18562739d49cSAlex Deucher enable it, even it's detected. 18572739d49cSAlex Deucher */ 18582739d49cSAlex Deucher 18592739d49cSAlex Deucher /* force it to crtc0 */ 18602739d49cSAlex Deucher dac2_cntl &= ~RADEON_DAC2_DAC_CLK_SEL; 18612739d49cSAlex Deucher dac2_cntl |= RADEON_DAC2_DAC2_CLK_SEL; 18622739d49cSAlex Deucher disp_hw_debug |= RADEON_CRT2_DISP1_SEL; 18632739d49cSAlex Deucher 18642739d49cSAlex Deucher /* set up the TV DAC */ 18652739d49cSAlex Deucher tv_dac_cntl &= ~(RADEON_TV_DAC_PEDESTAL | 18662739d49cSAlex Deucher RADEON_TV_DAC_STD_MASK | 18672739d49cSAlex Deucher RADEON_TV_DAC_RDACPD | 18682739d49cSAlex Deucher RADEON_TV_DAC_GDACPD | 18692739d49cSAlex Deucher RADEON_TV_DAC_BDACPD | 18702739d49cSAlex Deucher RADEON_TV_DAC_BGADJ_MASK | 18712739d49cSAlex Deucher RADEON_TV_DAC_DACADJ_MASK); 18722739d49cSAlex Deucher tv_dac_cntl |= (RADEON_TV_DAC_NBLANK | 18732739d49cSAlex Deucher RADEON_TV_DAC_NHOLD | 18742739d49cSAlex Deucher RADEON_TV_DAC_STD_PS2 | 18752739d49cSAlex Deucher (0x58 << 16)); 18762739d49cSAlex Deucher 18772739d49cSAlex Deucher WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl); 18782739d49cSAlex Deucher WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug); 18792739d49cSAlex Deucher WREG32(RADEON_DAC_CNTL2, dac2_cntl); 18802739d49cSAlex Deucher } 188192cde00cSAlex Deucher } 1882771fe6b9SJerome Glisse 1883771fe6b9SJerome Glisse /* 1884771fe6b9SJerome Glisse * VRAM info 1885771fe6b9SJerome Glisse */ 1886771fe6b9SJerome Glisse static void r100_vram_get_type(struct radeon_device *rdev) 1887771fe6b9SJerome Glisse { 1888771fe6b9SJerome Glisse uint32_t tmp; 1889771fe6b9SJerome Glisse 1890771fe6b9SJerome Glisse rdev->mc.vram_is_ddr = false; 1891771fe6b9SJerome Glisse if (rdev->flags & RADEON_IS_IGP) 1892771fe6b9SJerome Glisse rdev->mc.vram_is_ddr = true; 1893771fe6b9SJerome Glisse else if (RREG32(RADEON_MEM_SDRAM_MODE_REG) & RADEON_MEM_CFG_TYPE_DDR) 1894771fe6b9SJerome Glisse rdev->mc.vram_is_ddr = true; 1895771fe6b9SJerome Glisse if ((rdev->family == CHIP_RV100) || 1896771fe6b9SJerome Glisse (rdev->family == CHIP_RS100) || 1897771fe6b9SJerome Glisse (rdev->family == CHIP_RS200)) { 1898771fe6b9SJerome Glisse tmp = RREG32(RADEON_MEM_CNTL); 1899771fe6b9SJerome Glisse if (tmp & RV100_HALF_MODE) { 1900771fe6b9SJerome Glisse rdev->mc.vram_width = 32; 1901771fe6b9SJerome Glisse } else { 1902771fe6b9SJerome Glisse rdev->mc.vram_width = 64; 1903771fe6b9SJerome Glisse } 1904771fe6b9SJerome Glisse if (rdev->flags & RADEON_SINGLE_CRTC) { 1905771fe6b9SJerome Glisse rdev->mc.vram_width /= 4; 1906771fe6b9SJerome Glisse rdev->mc.vram_is_ddr = true; 1907771fe6b9SJerome Glisse } 1908771fe6b9SJerome Glisse } else if (rdev->family <= CHIP_RV280) { 1909771fe6b9SJerome Glisse tmp = RREG32(RADEON_MEM_CNTL); 1910771fe6b9SJerome Glisse if (tmp & RADEON_MEM_NUM_CHANNELS_MASK) { 1911771fe6b9SJerome Glisse rdev->mc.vram_width = 128; 1912771fe6b9SJerome Glisse } else { 1913771fe6b9SJerome Glisse rdev->mc.vram_width = 64; 1914771fe6b9SJerome Glisse } 1915771fe6b9SJerome Glisse } else { 1916771fe6b9SJerome Glisse /* newer IGPs */ 1917771fe6b9SJerome Glisse rdev->mc.vram_width = 128; 1918771fe6b9SJerome Glisse } 1919771fe6b9SJerome Glisse } 1920771fe6b9SJerome Glisse 19212a0f8918SDave Airlie static u32 r100_get_accessible_vram(struct radeon_device *rdev) 1922771fe6b9SJerome Glisse { 19232a0f8918SDave Airlie u32 aper_size; 19242a0f8918SDave Airlie u8 byte; 19252a0f8918SDave Airlie 19262a0f8918SDave Airlie aper_size = RREG32(RADEON_CONFIG_APER_SIZE); 19272a0f8918SDave Airlie 19282a0f8918SDave Airlie /* Set HDP_APER_CNTL only on cards that are known not to be broken, 19292a0f8918SDave Airlie * that is has the 2nd generation multifunction PCI interface 19302a0f8918SDave Airlie */ 19312a0f8918SDave Airlie if (rdev->family == CHIP_RV280 || 19322a0f8918SDave Airlie rdev->family >= CHIP_RV350) { 19332a0f8918SDave Airlie WREG32_P(RADEON_HOST_PATH_CNTL, RADEON_HDP_APER_CNTL, 19342a0f8918SDave Airlie ~RADEON_HDP_APER_CNTL); 19352a0f8918SDave Airlie DRM_INFO("Generation 2 PCI interface, using max accessible memory\n"); 19362a0f8918SDave Airlie return aper_size * 2; 19372a0f8918SDave Airlie } 19382a0f8918SDave Airlie 19392a0f8918SDave Airlie /* Older cards have all sorts of funny issues to deal with. First 19402a0f8918SDave Airlie * check if it's a multifunction card by reading the PCI config 19412a0f8918SDave Airlie * header type... Limit those to one aperture size 19422a0f8918SDave Airlie */ 19432a0f8918SDave Airlie pci_read_config_byte(rdev->pdev, 0xe, &byte); 19442a0f8918SDave Airlie if (byte & 0x80) { 19452a0f8918SDave Airlie DRM_INFO("Generation 1 PCI interface in multifunction mode\n"); 19462a0f8918SDave Airlie DRM_INFO("Limiting VRAM to one aperture\n"); 19472a0f8918SDave Airlie return aper_size; 19482a0f8918SDave Airlie } 19492a0f8918SDave Airlie 19502a0f8918SDave Airlie /* Single function older card. We read HDP_APER_CNTL to see how the BIOS 19512a0f8918SDave Airlie * have set it up. We don't write this as it's broken on some ASICs but 19522a0f8918SDave Airlie * we expect the BIOS to have done the right thing (might be too optimistic...) 19532a0f8918SDave Airlie */ 19542a0f8918SDave Airlie if (RREG32(RADEON_HOST_PATH_CNTL) & RADEON_HDP_APER_CNTL) 19552a0f8918SDave Airlie return aper_size * 2; 19562a0f8918SDave Airlie return aper_size; 19572a0f8918SDave Airlie } 19582a0f8918SDave Airlie 19592a0f8918SDave Airlie void r100_vram_init_sizes(struct radeon_device *rdev) 19602a0f8918SDave Airlie { 19612a0f8918SDave Airlie u64 config_aper_size; 19622a0f8918SDave Airlie 1963d594e46aSJerome Glisse /* work out accessible VRAM */ 1964d594e46aSJerome Glisse rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0); 1965d594e46aSJerome Glisse rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0); 196651e5fcd3SJerome Glisse rdev->mc.visible_vram_size = r100_get_accessible_vram(rdev); 196751e5fcd3SJerome Glisse /* FIXME we don't use the second aperture yet when we could use it */ 196851e5fcd3SJerome Glisse if (rdev->mc.visible_vram_size > rdev->mc.aper_size) 196951e5fcd3SJerome Glisse rdev->mc.visible_vram_size = rdev->mc.aper_size; 19702a0f8918SDave Airlie config_aper_size = RREG32(RADEON_CONFIG_APER_SIZE); 1971771fe6b9SJerome Glisse if (rdev->flags & RADEON_IS_IGP) { 1972771fe6b9SJerome Glisse uint32_t tom; 1973771fe6b9SJerome Glisse /* read NB_TOM to get the amount of ram stolen for the GPU */ 1974771fe6b9SJerome Glisse tom = RREG32(RADEON_NB_TOM); 19757a50f01aSDave Airlie rdev->mc.real_vram_size = (((tom >> 16) - (tom & 0xffff) + 1) << 16); 19767a50f01aSDave Airlie WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.real_vram_size); 19777a50f01aSDave Airlie rdev->mc.mc_vram_size = rdev->mc.real_vram_size; 1978771fe6b9SJerome Glisse } else { 19797a50f01aSDave Airlie rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE); 1980771fe6b9SJerome Glisse /* Some production boards of m6 will report 0 1981771fe6b9SJerome Glisse * if it's 8 MB 1982771fe6b9SJerome Glisse */ 19837a50f01aSDave Airlie if (rdev->mc.real_vram_size == 0) { 19847a50f01aSDave Airlie rdev->mc.real_vram_size = 8192 * 1024; 19857a50f01aSDave Airlie WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.real_vram_size); 1986771fe6b9SJerome Glisse } 19872a0f8918SDave Airlie /* Fix for RN50, M6, M7 with 8/16/32(??) MBs of VRAM - 1988d594e46aSJerome Glisse * Novell bug 204882 + along with lots of ubuntu ones 1989d594e46aSJerome Glisse */ 19907a50f01aSDave Airlie if (config_aper_size > rdev->mc.real_vram_size) 19917a50f01aSDave Airlie rdev->mc.mc_vram_size = config_aper_size; 19927a50f01aSDave Airlie else 19937a50f01aSDave Airlie rdev->mc.mc_vram_size = rdev->mc.real_vram_size; 1994771fe6b9SJerome Glisse } 1995d594e46aSJerome Glisse /* FIXME remove this once we support unmappable VRAM */ 1996d594e46aSJerome Glisse if (rdev->mc.mc_vram_size > rdev->mc.aper_size) { 19977a50f01aSDave Airlie rdev->mc.mc_vram_size = rdev->mc.aper_size; 19987a50f01aSDave Airlie rdev->mc.real_vram_size = rdev->mc.aper_size; 19992a0f8918SDave Airlie } 2000d594e46aSJerome Glisse } 20012a0f8918SDave Airlie 200228d52043SDave Airlie void r100_vga_set_state(struct radeon_device *rdev, bool state) 200328d52043SDave Airlie { 200428d52043SDave Airlie uint32_t temp; 200528d52043SDave Airlie 200628d52043SDave Airlie temp = RREG32(RADEON_CONFIG_CNTL); 200728d52043SDave Airlie if (state == false) { 200828d52043SDave Airlie temp &= ~(1<<8); 200928d52043SDave Airlie temp |= (1<<9); 201028d52043SDave Airlie } else { 201128d52043SDave Airlie temp &= ~(1<<9); 201228d52043SDave Airlie } 201328d52043SDave Airlie WREG32(RADEON_CONFIG_CNTL, temp); 201428d52043SDave Airlie } 201528d52043SDave Airlie 2016d594e46aSJerome Glisse void r100_mc_init(struct radeon_device *rdev) 20172a0f8918SDave Airlie { 2018d594e46aSJerome Glisse u64 base; 20192a0f8918SDave Airlie 2020d594e46aSJerome Glisse r100_vram_get_type(rdev); 20212a0f8918SDave Airlie r100_vram_init_sizes(rdev); 2022d594e46aSJerome Glisse base = rdev->mc.aper_base; 2023d594e46aSJerome Glisse if (rdev->flags & RADEON_IS_IGP) 2024d594e46aSJerome Glisse base = (RREG32(RADEON_NB_TOM) & 0xffff) << 16; 2025d594e46aSJerome Glisse radeon_vram_location(rdev, &rdev->mc, base); 2026d594e46aSJerome Glisse if (!(rdev->flags & RADEON_IS_AGP)) 2027d594e46aSJerome Glisse radeon_gtt_location(rdev, &rdev->mc); 2028f47299c5SAlex Deucher radeon_update_bandwidth_info(rdev); 2029771fe6b9SJerome Glisse } 2030771fe6b9SJerome Glisse 2031771fe6b9SJerome Glisse 2032771fe6b9SJerome Glisse /* 2033771fe6b9SJerome Glisse * Indirect registers accessor 2034771fe6b9SJerome Glisse */ 2035771fe6b9SJerome Glisse void r100_pll_errata_after_index(struct radeon_device *rdev) 2036771fe6b9SJerome Glisse { 2037771fe6b9SJerome Glisse if (!(rdev->pll_errata & CHIP_ERRATA_PLL_DUMMYREADS)) { 2038771fe6b9SJerome Glisse return; 2039771fe6b9SJerome Glisse } 2040771fe6b9SJerome Glisse (void)RREG32(RADEON_CLOCK_CNTL_DATA); 2041771fe6b9SJerome Glisse (void)RREG32(RADEON_CRTC_GEN_CNTL); 2042771fe6b9SJerome Glisse } 2043771fe6b9SJerome Glisse 2044771fe6b9SJerome Glisse static void r100_pll_errata_after_data(struct radeon_device *rdev) 2045771fe6b9SJerome Glisse { 2046771fe6b9SJerome Glisse /* This workarounds is necessary on RV100, RS100 and RS200 chips 2047771fe6b9SJerome Glisse * or the chip could hang on a subsequent access 2048771fe6b9SJerome Glisse */ 2049771fe6b9SJerome Glisse if (rdev->pll_errata & CHIP_ERRATA_PLL_DELAY) { 2050771fe6b9SJerome Glisse udelay(5000); 2051771fe6b9SJerome Glisse } 2052771fe6b9SJerome Glisse 2053771fe6b9SJerome Glisse /* This function is required to workaround a hardware bug in some (all?) 2054771fe6b9SJerome Glisse * revisions of the R300. This workaround should be called after every 2055771fe6b9SJerome Glisse * CLOCK_CNTL_INDEX register access. If not, register reads afterward 2056771fe6b9SJerome Glisse * may not be correct. 2057771fe6b9SJerome Glisse */ 2058771fe6b9SJerome Glisse if (rdev->pll_errata & CHIP_ERRATA_R300_CG) { 2059771fe6b9SJerome Glisse uint32_t save, tmp; 2060771fe6b9SJerome Glisse 2061771fe6b9SJerome Glisse save = RREG32(RADEON_CLOCK_CNTL_INDEX); 2062771fe6b9SJerome Glisse tmp = save & ~(0x3f | RADEON_PLL_WR_EN); 2063771fe6b9SJerome Glisse WREG32(RADEON_CLOCK_CNTL_INDEX, tmp); 2064771fe6b9SJerome Glisse tmp = RREG32(RADEON_CLOCK_CNTL_DATA); 2065771fe6b9SJerome Glisse WREG32(RADEON_CLOCK_CNTL_INDEX, save); 2066771fe6b9SJerome Glisse } 2067771fe6b9SJerome Glisse } 2068771fe6b9SJerome Glisse 2069771fe6b9SJerome Glisse uint32_t r100_pll_rreg(struct radeon_device *rdev, uint32_t reg) 2070771fe6b9SJerome Glisse { 2071771fe6b9SJerome Glisse uint32_t data; 2072771fe6b9SJerome Glisse 2073771fe6b9SJerome Glisse WREG8(RADEON_CLOCK_CNTL_INDEX, reg & 0x3f); 2074771fe6b9SJerome Glisse r100_pll_errata_after_index(rdev); 2075771fe6b9SJerome Glisse data = RREG32(RADEON_CLOCK_CNTL_DATA); 2076771fe6b9SJerome Glisse r100_pll_errata_after_data(rdev); 2077771fe6b9SJerome Glisse return data; 2078771fe6b9SJerome Glisse } 2079771fe6b9SJerome Glisse 2080771fe6b9SJerome Glisse void r100_pll_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v) 2081771fe6b9SJerome Glisse { 2082771fe6b9SJerome Glisse WREG8(RADEON_CLOCK_CNTL_INDEX, ((reg & 0x3f) | RADEON_PLL_WR_EN)); 2083771fe6b9SJerome Glisse r100_pll_errata_after_index(rdev); 2084771fe6b9SJerome Glisse WREG32(RADEON_CLOCK_CNTL_DATA, v); 2085771fe6b9SJerome Glisse r100_pll_errata_after_data(rdev); 2086771fe6b9SJerome Glisse } 2087771fe6b9SJerome Glisse 2088d4550907SJerome Glisse void r100_set_safe_registers(struct radeon_device *rdev) 2089068a117cSJerome Glisse { 2090551ebd83SDave Airlie if (ASIC_IS_RN50(rdev)) { 2091551ebd83SDave Airlie rdev->config.r100.reg_safe_bm = rn50_reg_safe_bm; 2092551ebd83SDave Airlie rdev->config.r100.reg_safe_bm_size = ARRAY_SIZE(rn50_reg_safe_bm); 2093551ebd83SDave Airlie } else if (rdev->family < CHIP_R200) { 2094551ebd83SDave Airlie rdev->config.r100.reg_safe_bm = r100_reg_safe_bm; 2095551ebd83SDave Airlie rdev->config.r100.reg_safe_bm_size = ARRAY_SIZE(r100_reg_safe_bm); 2096551ebd83SDave Airlie } else { 2097d4550907SJerome Glisse r200_set_safe_registers(rdev); 2098551ebd83SDave Airlie } 2099068a117cSJerome Glisse } 2100068a117cSJerome Glisse 2101771fe6b9SJerome Glisse /* 2102771fe6b9SJerome Glisse * Debugfs info 2103771fe6b9SJerome Glisse */ 2104771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 2105771fe6b9SJerome Glisse static int r100_debugfs_rbbm_info(struct seq_file *m, void *data) 2106771fe6b9SJerome Glisse { 2107771fe6b9SJerome Glisse struct drm_info_node *node = (struct drm_info_node *) m->private; 2108771fe6b9SJerome Glisse struct drm_device *dev = node->minor->dev; 2109771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 2110771fe6b9SJerome Glisse uint32_t reg, value; 2111771fe6b9SJerome Glisse unsigned i; 2112771fe6b9SJerome Glisse 2113771fe6b9SJerome Glisse seq_printf(m, "RBBM_STATUS 0x%08x\n", RREG32(RADEON_RBBM_STATUS)); 2114771fe6b9SJerome Glisse seq_printf(m, "RBBM_CMDFIFO_STAT 0x%08x\n", RREG32(0xE7C)); 2115771fe6b9SJerome Glisse seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT)); 2116771fe6b9SJerome Glisse for (i = 0; i < 64; i++) { 2117771fe6b9SJerome Glisse WREG32(RADEON_RBBM_CMDFIFO_ADDR, i | 0x100); 2118771fe6b9SJerome Glisse reg = (RREG32(RADEON_RBBM_CMDFIFO_DATA) - 1) >> 2; 2119771fe6b9SJerome Glisse WREG32(RADEON_RBBM_CMDFIFO_ADDR, i); 2120771fe6b9SJerome Glisse value = RREG32(RADEON_RBBM_CMDFIFO_DATA); 2121771fe6b9SJerome Glisse seq_printf(m, "[0x%03X] 0x%04X=0x%08X\n", i, reg, value); 2122771fe6b9SJerome Glisse } 2123771fe6b9SJerome Glisse return 0; 2124771fe6b9SJerome Glisse } 2125771fe6b9SJerome Glisse 2126771fe6b9SJerome Glisse static int r100_debugfs_cp_ring_info(struct seq_file *m, void *data) 2127771fe6b9SJerome Glisse { 2128771fe6b9SJerome Glisse struct drm_info_node *node = (struct drm_info_node *) m->private; 2129771fe6b9SJerome Glisse struct drm_device *dev = node->minor->dev; 2130771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 2131771fe6b9SJerome Glisse uint32_t rdp, wdp; 2132771fe6b9SJerome Glisse unsigned count, i, j; 2133771fe6b9SJerome Glisse 2134771fe6b9SJerome Glisse radeon_ring_free_size(rdev); 2135771fe6b9SJerome Glisse rdp = RREG32(RADEON_CP_RB_RPTR); 2136771fe6b9SJerome Glisse wdp = RREG32(RADEON_CP_RB_WPTR); 2137771fe6b9SJerome Glisse count = (rdp + rdev->cp.ring_size - wdp) & rdev->cp.ptr_mask; 2138771fe6b9SJerome Glisse seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT)); 2139771fe6b9SJerome Glisse seq_printf(m, "CP_RB_WPTR 0x%08x\n", wdp); 2140771fe6b9SJerome Glisse seq_printf(m, "CP_RB_RPTR 0x%08x\n", rdp); 2141771fe6b9SJerome Glisse seq_printf(m, "%u free dwords in ring\n", rdev->cp.ring_free_dw); 2142771fe6b9SJerome Glisse seq_printf(m, "%u dwords in ring\n", count); 2143771fe6b9SJerome Glisse for (j = 0; j <= count; j++) { 2144771fe6b9SJerome Glisse i = (rdp + j) & rdev->cp.ptr_mask; 2145771fe6b9SJerome Glisse seq_printf(m, "r[%04d]=0x%08x\n", i, rdev->cp.ring[i]); 2146771fe6b9SJerome Glisse } 2147771fe6b9SJerome Glisse return 0; 2148771fe6b9SJerome Glisse } 2149771fe6b9SJerome Glisse 2150771fe6b9SJerome Glisse 2151771fe6b9SJerome Glisse static int r100_debugfs_cp_csq_fifo(struct seq_file *m, void *data) 2152771fe6b9SJerome Glisse { 2153771fe6b9SJerome Glisse struct drm_info_node *node = (struct drm_info_node *) m->private; 2154771fe6b9SJerome Glisse struct drm_device *dev = node->minor->dev; 2155771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 2156771fe6b9SJerome Glisse uint32_t csq_stat, csq2_stat, tmp; 2157771fe6b9SJerome Glisse unsigned r_rptr, r_wptr, ib1_rptr, ib1_wptr, ib2_rptr, ib2_wptr; 2158771fe6b9SJerome Glisse unsigned i; 2159771fe6b9SJerome Glisse 2160771fe6b9SJerome Glisse seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT)); 2161771fe6b9SJerome Glisse seq_printf(m, "CP_CSQ_MODE 0x%08x\n", RREG32(RADEON_CP_CSQ_MODE)); 2162771fe6b9SJerome Glisse csq_stat = RREG32(RADEON_CP_CSQ_STAT); 2163771fe6b9SJerome Glisse csq2_stat = RREG32(RADEON_CP_CSQ2_STAT); 2164771fe6b9SJerome Glisse r_rptr = (csq_stat >> 0) & 0x3ff; 2165771fe6b9SJerome Glisse r_wptr = (csq_stat >> 10) & 0x3ff; 2166771fe6b9SJerome Glisse ib1_rptr = (csq_stat >> 20) & 0x3ff; 2167771fe6b9SJerome Glisse ib1_wptr = (csq2_stat >> 0) & 0x3ff; 2168771fe6b9SJerome Glisse ib2_rptr = (csq2_stat >> 10) & 0x3ff; 2169771fe6b9SJerome Glisse ib2_wptr = (csq2_stat >> 20) & 0x3ff; 2170771fe6b9SJerome Glisse seq_printf(m, "CP_CSQ_STAT 0x%08x\n", csq_stat); 2171771fe6b9SJerome Glisse seq_printf(m, "CP_CSQ2_STAT 0x%08x\n", csq2_stat); 2172771fe6b9SJerome Glisse seq_printf(m, "Ring rptr %u\n", r_rptr); 2173771fe6b9SJerome Glisse seq_printf(m, "Ring wptr %u\n", r_wptr); 2174771fe6b9SJerome Glisse seq_printf(m, "Indirect1 rptr %u\n", ib1_rptr); 2175771fe6b9SJerome Glisse seq_printf(m, "Indirect1 wptr %u\n", ib1_wptr); 2176771fe6b9SJerome Glisse seq_printf(m, "Indirect2 rptr %u\n", ib2_rptr); 2177771fe6b9SJerome Glisse seq_printf(m, "Indirect2 wptr %u\n", ib2_wptr); 2178771fe6b9SJerome Glisse /* FIXME: 0, 128, 640 depends on fifo setup see cp_init_kms 2179771fe6b9SJerome Glisse * 128 = indirect1_start * 8 & 640 = indirect2_start * 8 */ 2180771fe6b9SJerome Glisse seq_printf(m, "Ring fifo:\n"); 2181771fe6b9SJerome Glisse for (i = 0; i < 256; i++) { 2182771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_ADDR, i << 2); 2183771fe6b9SJerome Glisse tmp = RREG32(RADEON_CP_CSQ_DATA); 2184771fe6b9SJerome Glisse seq_printf(m, "rfifo[%04d]=0x%08X\n", i, tmp); 2185771fe6b9SJerome Glisse } 2186771fe6b9SJerome Glisse seq_printf(m, "Indirect1 fifo:\n"); 2187771fe6b9SJerome Glisse for (i = 256; i <= 512; i++) { 2188771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_ADDR, i << 2); 2189771fe6b9SJerome Glisse tmp = RREG32(RADEON_CP_CSQ_DATA); 2190771fe6b9SJerome Glisse seq_printf(m, "ib1fifo[%04d]=0x%08X\n", i, tmp); 2191771fe6b9SJerome Glisse } 2192771fe6b9SJerome Glisse seq_printf(m, "Indirect2 fifo:\n"); 2193771fe6b9SJerome Glisse for (i = 640; i < ib1_wptr; i++) { 2194771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_ADDR, i << 2); 2195771fe6b9SJerome Glisse tmp = RREG32(RADEON_CP_CSQ_DATA); 2196771fe6b9SJerome Glisse seq_printf(m, "ib2fifo[%04d]=0x%08X\n", i, tmp); 2197771fe6b9SJerome Glisse } 2198771fe6b9SJerome Glisse return 0; 2199771fe6b9SJerome Glisse } 2200771fe6b9SJerome Glisse 2201771fe6b9SJerome Glisse static int r100_debugfs_mc_info(struct seq_file *m, void *data) 2202771fe6b9SJerome Glisse { 2203771fe6b9SJerome Glisse struct drm_info_node *node = (struct drm_info_node *) m->private; 2204771fe6b9SJerome Glisse struct drm_device *dev = node->minor->dev; 2205771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 2206771fe6b9SJerome Glisse uint32_t tmp; 2207771fe6b9SJerome Glisse 2208771fe6b9SJerome Glisse tmp = RREG32(RADEON_CONFIG_MEMSIZE); 2209771fe6b9SJerome Glisse seq_printf(m, "CONFIG_MEMSIZE 0x%08x\n", tmp); 2210771fe6b9SJerome Glisse tmp = RREG32(RADEON_MC_FB_LOCATION); 2211771fe6b9SJerome Glisse seq_printf(m, "MC_FB_LOCATION 0x%08x\n", tmp); 2212771fe6b9SJerome Glisse tmp = RREG32(RADEON_BUS_CNTL); 2213771fe6b9SJerome Glisse seq_printf(m, "BUS_CNTL 0x%08x\n", tmp); 2214771fe6b9SJerome Glisse tmp = RREG32(RADEON_MC_AGP_LOCATION); 2215771fe6b9SJerome Glisse seq_printf(m, "MC_AGP_LOCATION 0x%08x\n", tmp); 2216771fe6b9SJerome Glisse tmp = RREG32(RADEON_AGP_BASE); 2217771fe6b9SJerome Glisse seq_printf(m, "AGP_BASE 0x%08x\n", tmp); 2218771fe6b9SJerome Glisse tmp = RREG32(RADEON_HOST_PATH_CNTL); 2219771fe6b9SJerome Glisse seq_printf(m, "HOST_PATH_CNTL 0x%08x\n", tmp); 2220771fe6b9SJerome Glisse tmp = RREG32(0x01D0); 2221771fe6b9SJerome Glisse seq_printf(m, "AIC_CTRL 0x%08x\n", tmp); 2222771fe6b9SJerome Glisse tmp = RREG32(RADEON_AIC_LO_ADDR); 2223771fe6b9SJerome Glisse seq_printf(m, "AIC_LO_ADDR 0x%08x\n", tmp); 2224771fe6b9SJerome Glisse tmp = RREG32(RADEON_AIC_HI_ADDR); 2225771fe6b9SJerome Glisse seq_printf(m, "AIC_HI_ADDR 0x%08x\n", tmp); 2226771fe6b9SJerome Glisse tmp = RREG32(0x01E4); 2227771fe6b9SJerome Glisse seq_printf(m, "AIC_TLB_ADDR 0x%08x\n", tmp); 2228771fe6b9SJerome Glisse return 0; 2229771fe6b9SJerome Glisse } 2230771fe6b9SJerome Glisse 2231771fe6b9SJerome Glisse static struct drm_info_list r100_debugfs_rbbm_list[] = { 2232771fe6b9SJerome Glisse {"r100_rbbm_info", r100_debugfs_rbbm_info, 0, NULL}, 2233771fe6b9SJerome Glisse }; 2234771fe6b9SJerome Glisse 2235771fe6b9SJerome Glisse static struct drm_info_list r100_debugfs_cp_list[] = { 2236771fe6b9SJerome Glisse {"r100_cp_ring_info", r100_debugfs_cp_ring_info, 0, NULL}, 2237771fe6b9SJerome Glisse {"r100_cp_csq_fifo", r100_debugfs_cp_csq_fifo, 0, NULL}, 2238771fe6b9SJerome Glisse }; 2239771fe6b9SJerome Glisse 2240771fe6b9SJerome Glisse static struct drm_info_list r100_debugfs_mc_info_list[] = { 2241771fe6b9SJerome Glisse {"r100_mc_info", r100_debugfs_mc_info, 0, NULL}, 2242771fe6b9SJerome Glisse }; 2243771fe6b9SJerome Glisse #endif 2244771fe6b9SJerome Glisse 2245771fe6b9SJerome Glisse int r100_debugfs_rbbm_init(struct radeon_device *rdev) 2246771fe6b9SJerome Glisse { 2247771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 2248771fe6b9SJerome Glisse return radeon_debugfs_add_files(rdev, r100_debugfs_rbbm_list, 1); 2249771fe6b9SJerome Glisse #else 2250771fe6b9SJerome Glisse return 0; 2251771fe6b9SJerome Glisse #endif 2252771fe6b9SJerome Glisse } 2253771fe6b9SJerome Glisse 2254771fe6b9SJerome Glisse int r100_debugfs_cp_init(struct radeon_device *rdev) 2255771fe6b9SJerome Glisse { 2256771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 2257771fe6b9SJerome Glisse return radeon_debugfs_add_files(rdev, r100_debugfs_cp_list, 2); 2258771fe6b9SJerome Glisse #else 2259771fe6b9SJerome Glisse return 0; 2260771fe6b9SJerome Glisse #endif 2261771fe6b9SJerome Glisse } 2262771fe6b9SJerome Glisse 2263771fe6b9SJerome Glisse int r100_debugfs_mc_info_init(struct radeon_device *rdev) 2264771fe6b9SJerome Glisse { 2265771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 2266771fe6b9SJerome Glisse return radeon_debugfs_add_files(rdev, r100_debugfs_mc_info_list, 1); 2267771fe6b9SJerome Glisse #else 2268771fe6b9SJerome Glisse return 0; 2269771fe6b9SJerome Glisse #endif 2270771fe6b9SJerome Glisse } 2271e024e110SDave Airlie 2272e024e110SDave Airlie int r100_set_surface_reg(struct radeon_device *rdev, int reg, 2273e024e110SDave Airlie uint32_t tiling_flags, uint32_t pitch, 2274e024e110SDave Airlie uint32_t offset, uint32_t obj_size) 2275e024e110SDave Airlie { 2276e024e110SDave Airlie int surf_index = reg * 16; 2277e024e110SDave Airlie int flags = 0; 2278e024e110SDave Airlie 2279e024e110SDave Airlie /* r100/r200 divide by 16 */ 2280e024e110SDave Airlie if (rdev->family < CHIP_R300) 2281e024e110SDave Airlie flags = pitch / 16; 2282e024e110SDave Airlie else 2283e024e110SDave Airlie flags = pitch / 8; 2284e024e110SDave Airlie 2285e024e110SDave Airlie if (rdev->family <= CHIP_RS200) { 2286e024e110SDave Airlie if ((tiling_flags & (RADEON_TILING_MACRO|RADEON_TILING_MICRO)) 2287e024e110SDave Airlie == (RADEON_TILING_MACRO|RADEON_TILING_MICRO)) 2288e024e110SDave Airlie flags |= RADEON_SURF_TILE_COLOR_BOTH; 2289e024e110SDave Airlie if (tiling_flags & RADEON_TILING_MACRO) 2290e024e110SDave Airlie flags |= RADEON_SURF_TILE_COLOR_MACRO; 2291e024e110SDave Airlie } else if (rdev->family <= CHIP_RV280) { 2292e024e110SDave Airlie if (tiling_flags & (RADEON_TILING_MACRO)) 2293e024e110SDave Airlie flags |= R200_SURF_TILE_COLOR_MACRO; 2294e024e110SDave Airlie if (tiling_flags & RADEON_TILING_MICRO) 2295e024e110SDave Airlie flags |= R200_SURF_TILE_COLOR_MICRO; 2296e024e110SDave Airlie } else { 2297e024e110SDave Airlie if (tiling_flags & RADEON_TILING_MACRO) 2298e024e110SDave Airlie flags |= R300_SURF_TILE_MACRO; 2299e024e110SDave Airlie if (tiling_flags & RADEON_TILING_MICRO) 2300e024e110SDave Airlie flags |= R300_SURF_TILE_MICRO; 2301e024e110SDave Airlie } 2302e024e110SDave Airlie 2303c88f9f0cSMichel Dänzer if (tiling_flags & RADEON_TILING_SWAP_16BIT) 2304c88f9f0cSMichel Dänzer flags |= RADEON_SURF_AP0_SWP_16BPP | RADEON_SURF_AP1_SWP_16BPP; 2305c88f9f0cSMichel Dänzer if (tiling_flags & RADEON_TILING_SWAP_32BIT) 2306c88f9f0cSMichel Dänzer flags |= RADEON_SURF_AP0_SWP_32BPP | RADEON_SURF_AP1_SWP_32BPP; 2307c88f9f0cSMichel Dänzer 2308e024e110SDave Airlie DRM_DEBUG("writing surface %d %d %x %x\n", reg, flags, offset, offset+obj_size-1); 2309e024e110SDave Airlie WREG32(RADEON_SURFACE0_INFO + surf_index, flags); 2310e024e110SDave Airlie WREG32(RADEON_SURFACE0_LOWER_BOUND + surf_index, offset); 2311e024e110SDave Airlie WREG32(RADEON_SURFACE0_UPPER_BOUND + surf_index, offset + obj_size - 1); 2312e024e110SDave Airlie return 0; 2313e024e110SDave Airlie } 2314e024e110SDave Airlie 2315e024e110SDave Airlie void r100_clear_surface_reg(struct radeon_device *rdev, int reg) 2316e024e110SDave Airlie { 2317e024e110SDave Airlie int surf_index = reg * 16; 2318e024e110SDave Airlie WREG32(RADEON_SURFACE0_INFO + surf_index, 0); 2319e024e110SDave Airlie } 2320c93bb85bSJerome Glisse 2321c93bb85bSJerome Glisse void r100_bandwidth_update(struct radeon_device *rdev) 2322c93bb85bSJerome Glisse { 2323c93bb85bSJerome Glisse fixed20_12 trcd_ff, trp_ff, tras_ff, trbs_ff, tcas_ff; 2324c93bb85bSJerome Glisse fixed20_12 sclk_ff, mclk_ff, sclk_eff_ff, sclk_delay_ff; 2325c93bb85bSJerome Glisse fixed20_12 peak_disp_bw, mem_bw, pix_clk, pix_clk2, temp_ff, crit_point_ff; 2326c93bb85bSJerome Glisse uint32_t temp, data, mem_trcd, mem_trp, mem_tras; 2327c93bb85bSJerome Glisse fixed20_12 memtcas_ff[8] = { 2328c93bb85bSJerome Glisse fixed_init(1), 2329c93bb85bSJerome Glisse fixed_init(2), 2330c93bb85bSJerome Glisse fixed_init(3), 2331c93bb85bSJerome Glisse fixed_init(0), 2332c93bb85bSJerome Glisse fixed_init_half(1), 2333c93bb85bSJerome Glisse fixed_init_half(2), 2334c93bb85bSJerome Glisse fixed_init(0), 2335c93bb85bSJerome Glisse }; 2336c93bb85bSJerome Glisse fixed20_12 memtcas_rs480_ff[8] = { 2337c93bb85bSJerome Glisse fixed_init(0), 2338c93bb85bSJerome Glisse fixed_init(1), 2339c93bb85bSJerome Glisse fixed_init(2), 2340c93bb85bSJerome Glisse fixed_init(3), 2341c93bb85bSJerome Glisse fixed_init(0), 2342c93bb85bSJerome Glisse fixed_init_half(1), 2343c93bb85bSJerome Glisse fixed_init_half(2), 2344c93bb85bSJerome Glisse fixed_init_half(3), 2345c93bb85bSJerome Glisse }; 2346c93bb85bSJerome Glisse fixed20_12 memtcas2_ff[8] = { 2347c93bb85bSJerome Glisse fixed_init(0), 2348c93bb85bSJerome Glisse fixed_init(1), 2349c93bb85bSJerome Glisse fixed_init(2), 2350c93bb85bSJerome Glisse fixed_init(3), 2351c93bb85bSJerome Glisse fixed_init(4), 2352c93bb85bSJerome Glisse fixed_init(5), 2353c93bb85bSJerome Glisse fixed_init(6), 2354c93bb85bSJerome Glisse fixed_init(7), 2355c93bb85bSJerome Glisse }; 2356c93bb85bSJerome Glisse fixed20_12 memtrbs[8] = { 2357c93bb85bSJerome Glisse fixed_init(1), 2358c93bb85bSJerome Glisse fixed_init_half(1), 2359c93bb85bSJerome Glisse fixed_init(2), 2360c93bb85bSJerome Glisse fixed_init_half(2), 2361c93bb85bSJerome Glisse fixed_init(3), 2362c93bb85bSJerome Glisse fixed_init_half(3), 2363c93bb85bSJerome Glisse fixed_init(4), 2364c93bb85bSJerome Glisse fixed_init_half(4) 2365c93bb85bSJerome Glisse }; 2366c93bb85bSJerome Glisse fixed20_12 memtrbs_r4xx[8] = { 2367c93bb85bSJerome Glisse fixed_init(4), 2368c93bb85bSJerome Glisse fixed_init(5), 2369c93bb85bSJerome Glisse fixed_init(6), 2370c93bb85bSJerome Glisse fixed_init(7), 2371c93bb85bSJerome Glisse fixed_init(8), 2372c93bb85bSJerome Glisse fixed_init(9), 2373c93bb85bSJerome Glisse fixed_init(10), 2374c93bb85bSJerome Glisse fixed_init(11) 2375c93bb85bSJerome Glisse }; 2376c93bb85bSJerome Glisse fixed20_12 min_mem_eff; 2377c93bb85bSJerome Glisse fixed20_12 mc_latency_sclk, mc_latency_mclk, k1; 2378c93bb85bSJerome Glisse fixed20_12 cur_latency_mclk, cur_latency_sclk; 2379c93bb85bSJerome Glisse fixed20_12 disp_latency, disp_latency_overhead, disp_drain_rate, 2380c93bb85bSJerome Glisse disp_drain_rate2, read_return_rate; 2381c93bb85bSJerome Glisse fixed20_12 time_disp1_drop_priority; 2382c93bb85bSJerome Glisse int c; 2383c93bb85bSJerome Glisse int cur_size = 16; /* in octawords */ 2384c93bb85bSJerome Glisse int critical_point = 0, critical_point2; 2385c93bb85bSJerome Glisse /* uint32_t read_return_rate, time_disp1_drop_priority; */ 2386c93bb85bSJerome Glisse int stop_req, max_stop_req; 2387c93bb85bSJerome Glisse struct drm_display_mode *mode1 = NULL; 2388c93bb85bSJerome Glisse struct drm_display_mode *mode2 = NULL; 2389c93bb85bSJerome Glisse uint32_t pixel_bytes1 = 0; 2390c93bb85bSJerome Glisse uint32_t pixel_bytes2 = 0; 2391c93bb85bSJerome Glisse 2392*f46c0120SAlex Deucher radeon_update_display_priority(rdev); 2393*f46c0120SAlex Deucher 2394c93bb85bSJerome Glisse if (rdev->mode_info.crtcs[0]->base.enabled) { 2395c93bb85bSJerome Glisse mode1 = &rdev->mode_info.crtcs[0]->base.mode; 2396c93bb85bSJerome Glisse pixel_bytes1 = rdev->mode_info.crtcs[0]->base.fb->bits_per_pixel / 8; 2397c93bb85bSJerome Glisse } 2398dfee5614SDave Airlie if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 2399c93bb85bSJerome Glisse if (rdev->mode_info.crtcs[1]->base.enabled) { 2400c93bb85bSJerome Glisse mode2 = &rdev->mode_info.crtcs[1]->base.mode; 2401c93bb85bSJerome Glisse pixel_bytes2 = rdev->mode_info.crtcs[1]->base.fb->bits_per_pixel / 8; 2402c93bb85bSJerome Glisse } 2403dfee5614SDave Airlie } 2404c93bb85bSJerome Glisse 2405c93bb85bSJerome Glisse min_mem_eff.full = rfixed_const_8(0); 2406c93bb85bSJerome Glisse /* get modes */ 2407c93bb85bSJerome Glisse if ((rdev->disp_priority == 2) && ASIC_IS_R300(rdev)) { 2408c93bb85bSJerome Glisse uint32_t mc_init_misc_lat_timer = RREG32(R300_MC_INIT_MISC_LAT_TIMER); 2409c93bb85bSJerome Glisse mc_init_misc_lat_timer &= ~(R300_MC_DISP1R_INIT_LAT_MASK << R300_MC_DISP1R_INIT_LAT_SHIFT); 2410c93bb85bSJerome Glisse mc_init_misc_lat_timer &= ~(R300_MC_DISP0R_INIT_LAT_MASK << R300_MC_DISP0R_INIT_LAT_SHIFT); 2411c93bb85bSJerome Glisse /* check crtc enables */ 2412c93bb85bSJerome Glisse if (mode2) 2413c93bb85bSJerome Glisse mc_init_misc_lat_timer |= (1 << R300_MC_DISP1R_INIT_LAT_SHIFT); 2414c93bb85bSJerome Glisse if (mode1) 2415c93bb85bSJerome Glisse mc_init_misc_lat_timer |= (1 << R300_MC_DISP0R_INIT_LAT_SHIFT); 2416c93bb85bSJerome Glisse WREG32(R300_MC_INIT_MISC_LAT_TIMER, mc_init_misc_lat_timer); 2417c93bb85bSJerome Glisse } 2418c93bb85bSJerome Glisse 2419c93bb85bSJerome Glisse /* 2420c93bb85bSJerome Glisse * determine is there is enough bw for current mode 2421c93bb85bSJerome Glisse */ 2422f47299c5SAlex Deucher sclk_ff = rdev->pm.sclk; 2423f47299c5SAlex Deucher mclk_ff = rdev->pm.mclk; 2424c93bb85bSJerome Glisse 2425c93bb85bSJerome Glisse temp = (rdev->mc.vram_width / 8) * (rdev->mc.vram_is_ddr ? 2 : 1); 2426c93bb85bSJerome Glisse temp_ff.full = rfixed_const(temp); 2427c93bb85bSJerome Glisse mem_bw.full = rfixed_mul(mclk_ff, temp_ff); 2428c93bb85bSJerome Glisse 2429c93bb85bSJerome Glisse pix_clk.full = 0; 2430c93bb85bSJerome Glisse pix_clk2.full = 0; 2431c93bb85bSJerome Glisse peak_disp_bw.full = 0; 2432c93bb85bSJerome Glisse if (mode1) { 2433c93bb85bSJerome Glisse temp_ff.full = rfixed_const(1000); 2434c93bb85bSJerome Glisse pix_clk.full = rfixed_const(mode1->clock); /* convert to fixed point */ 2435c93bb85bSJerome Glisse pix_clk.full = rfixed_div(pix_clk, temp_ff); 2436c93bb85bSJerome Glisse temp_ff.full = rfixed_const(pixel_bytes1); 2437c93bb85bSJerome Glisse peak_disp_bw.full += rfixed_mul(pix_clk, temp_ff); 2438c93bb85bSJerome Glisse } 2439c93bb85bSJerome Glisse if (mode2) { 2440c93bb85bSJerome Glisse temp_ff.full = rfixed_const(1000); 2441c93bb85bSJerome Glisse pix_clk2.full = rfixed_const(mode2->clock); /* convert to fixed point */ 2442c93bb85bSJerome Glisse pix_clk2.full = rfixed_div(pix_clk2, temp_ff); 2443c93bb85bSJerome Glisse temp_ff.full = rfixed_const(pixel_bytes2); 2444c93bb85bSJerome Glisse peak_disp_bw.full += rfixed_mul(pix_clk2, temp_ff); 2445c93bb85bSJerome Glisse } 2446c93bb85bSJerome Glisse 2447c93bb85bSJerome Glisse mem_bw.full = rfixed_mul(mem_bw, min_mem_eff); 2448c93bb85bSJerome Glisse if (peak_disp_bw.full >= mem_bw.full) { 2449c93bb85bSJerome Glisse DRM_ERROR("You may not have enough display bandwidth for current mode\n" 2450c93bb85bSJerome Glisse "If you have flickering problem, try to lower resolution, refresh rate, or color depth\n"); 2451c93bb85bSJerome Glisse } 2452c93bb85bSJerome Glisse 2453c93bb85bSJerome Glisse /* Get values from the EXT_MEM_CNTL register...converting its contents. */ 2454c93bb85bSJerome Glisse temp = RREG32(RADEON_MEM_TIMING_CNTL); 2455c93bb85bSJerome Glisse if ((rdev->family == CHIP_RV100) || (rdev->flags & RADEON_IS_IGP)) { /* RV100, M6, IGPs */ 2456c93bb85bSJerome Glisse mem_trcd = ((temp >> 2) & 0x3) + 1; 2457c93bb85bSJerome Glisse mem_trp = ((temp & 0x3)) + 1; 2458c93bb85bSJerome Glisse mem_tras = ((temp & 0x70) >> 4) + 1; 2459c93bb85bSJerome Glisse } else if (rdev->family == CHIP_R300 || 2460c93bb85bSJerome Glisse rdev->family == CHIP_R350) { /* r300, r350 */ 2461c93bb85bSJerome Glisse mem_trcd = (temp & 0x7) + 1; 2462c93bb85bSJerome Glisse mem_trp = ((temp >> 8) & 0x7) + 1; 2463c93bb85bSJerome Glisse mem_tras = ((temp >> 11) & 0xf) + 4; 2464c93bb85bSJerome Glisse } else if (rdev->family == CHIP_RV350 || 2465c93bb85bSJerome Glisse rdev->family <= CHIP_RV380) { 2466c93bb85bSJerome Glisse /* rv3x0 */ 2467c93bb85bSJerome Glisse mem_trcd = (temp & 0x7) + 3; 2468c93bb85bSJerome Glisse mem_trp = ((temp >> 8) & 0x7) + 3; 2469c93bb85bSJerome Glisse mem_tras = ((temp >> 11) & 0xf) + 6; 2470c93bb85bSJerome Glisse } else if (rdev->family == CHIP_R420 || 2471c93bb85bSJerome Glisse rdev->family == CHIP_R423 || 2472c93bb85bSJerome Glisse rdev->family == CHIP_RV410) { 2473c93bb85bSJerome Glisse /* r4xx */ 2474c93bb85bSJerome Glisse mem_trcd = (temp & 0xf) + 3; 2475c93bb85bSJerome Glisse if (mem_trcd > 15) 2476c93bb85bSJerome Glisse mem_trcd = 15; 2477c93bb85bSJerome Glisse mem_trp = ((temp >> 8) & 0xf) + 3; 2478c93bb85bSJerome Glisse if (mem_trp > 15) 2479c93bb85bSJerome Glisse mem_trp = 15; 2480c93bb85bSJerome Glisse mem_tras = ((temp >> 12) & 0x1f) + 6; 2481c93bb85bSJerome Glisse if (mem_tras > 31) 2482c93bb85bSJerome Glisse mem_tras = 31; 2483c93bb85bSJerome Glisse } else { /* RV200, R200 */ 2484c93bb85bSJerome Glisse mem_trcd = (temp & 0x7) + 1; 2485c93bb85bSJerome Glisse mem_trp = ((temp >> 8) & 0x7) + 1; 2486c93bb85bSJerome Glisse mem_tras = ((temp >> 12) & 0xf) + 4; 2487c93bb85bSJerome Glisse } 2488c93bb85bSJerome Glisse /* convert to FF */ 2489c93bb85bSJerome Glisse trcd_ff.full = rfixed_const(mem_trcd); 2490c93bb85bSJerome Glisse trp_ff.full = rfixed_const(mem_trp); 2491c93bb85bSJerome Glisse tras_ff.full = rfixed_const(mem_tras); 2492c93bb85bSJerome Glisse 2493c93bb85bSJerome Glisse /* Get values from the MEM_SDRAM_MODE_REG register...converting its */ 2494c93bb85bSJerome Glisse temp = RREG32(RADEON_MEM_SDRAM_MODE_REG); 2495c93bb85bSJerome Glisse data = (temp & (7 << 20)) >> 20; 2496c93bb85bSJerome Glisse if ((rdev->family == CHIP_RV100) || rdev->flags & RADEON_IS_IGP) { 2497c93bb85bSJerome Glisse if (rdev->family == CHIP_RS480) /* don't think rs400 */ 2498c93bb85bSJerome Glisse tcas_ff = memtcas_rs480_ff[data]; 2499c93bb85bSJerome Glisse else 2500c93bb85bSJerome Glisse tcas_ff = memtcas_ff[data]; 2501c93bb85bSJerome Glisse } else 2502c93bb85bSJerome Glisse tcas_ff = memtcas2_ff[data]; 2503c93bb85bSJerome Glisse 2504c93bb85bSJerome Glisse if (rdev->family == CHIP_RS400 || 2505c93bb85bSJerome Glisse rdev->family == CHIP_RS480) { 2506c93bb85bSJerome Glisse /* extra cas latency stored in bits 23-25 0-4 clocks */ 2507c93bb85bSJerome Glisse data = (temp >> 23) & 0x7; 2508c93bb85bSJerome Glisse if (data < 5) 2509c93bb85bSJerome Glisse tcas_ff.full += rfixed_const(data); 2510c93bb85bSJerome Glisse } 2511c93bb85bSJerome Glisse 2512c93bb85bSJerome Glisse if (ASIC_IS_R300(rdev) && !(rdev->flags & RADEON_IS_IGP)) { 2513c93bb85bSJerome Glisse /* on the R300, Tcas is included in Trbs. 2514c93bb85bSJerome Glisse */ 2515c93bb85bSJerome Glisse temp = RREG32(RADEON_MEM_CNTL); 2516c93bb85bSJerome Glisse data = (R300_MEM_NUM_CHANNELS_MASK & temp); 2517c93bb85bSJerome Glisse if (data == 1) { 2518c93bb85bSJerome Glisse if (R300_MEM_USE_CD_CH_ONLY & temp) { 2519c93bb85bSJerome Glisse temp = RREG32(R300_MC_IND_INDEX); 2520c93bb85bSJerome Glisse temp &= ~R300_MC_IND_ADDR_MASK; 2521c93bb85bSJerome Glisse temp |= R300_MC_READ_CNTL_CD_mcind; 2522c93bb85bSJerome Glisse WREG32(R300_MC_IND_INDEX, temp); 2523c93bb85bSJerome Glisse temp = RREG32(R300_MC_IND_DATA); 2524c93bb85bSJerome Glisse data = (R300_MEM_RBS_POSITION_C_MASK & temp); 2525c93bb85bSJerome Glisse } else { 2526c93bb85bSJerome Glisse temp = RREG32(R300_MC_READ_CNTL_AB); 2527c93bb85bSJerome Glisse data = (R300_MEM_RBS_POSITION_A_MASK & temp); 2528c93bb85bSJerome Glisse } 2529c93bb85bSJerome Glisse } else { 2530c93bb85bSJerome Glisse temp = RREG32(R300_MC_READ_CNTL_AB); 2531c93bb85bSJerome Glisse data = (R300_MEM_RBS_POSITION_A_MASK & temp); 2532c93bb85bSJerome Glisse } 2533c93bb85bSJerome Glisse if (rdev->family == CHIP_RV410 || 2534c93bb85bSJerome Glisse rdev->family == CHIP_R420 || 2535c93bb85bSJerome Glisse rdev->family == CHIP_R423) 2536c93bb85bSJerome Glisse trbs_ff = memtrbs_r4xx[data]; 2537c93bb85bSJerome Glisse else 2538c93bb85bSJerome Glisse trbs_ff = memtrbs[data]; 2539c93bb85bSJerome Glisse tcas_ff.full += trbs_ff.full; 2540c93bb85bSJerome Glisse } 2541c93bb85bSJerome Glisse 2542c93bb85bSJerome Glisse sclk_eff_ff.full = sclk_ff.full; 2543c93bb85bSJerome Glisse 2544c93bb85bSJerome Glisse if (rdev->flags & RADEON_IS_AGP) { 2545c93bb85bSJerome Glisse fixed20_12 agpmode_ff; 2546c93bb85bSJerome Glisse agpmode_ff.full = rfixed_const(radeon_agpmode); 2547c93bb85bSJerome Glisse temp_ff.full = rfixed_const_666(16); 2548c93bb85bSJerome Glisse sclk_eff_ff.full -= rfixed_mul(agpmode_ff, temp_ff); 2549c93bb85bSJerome Glisse } 2550c93bb85bSJerome Glisse /* TODO PCIE lanes may affect this - agpmode == 16?? */ 2551c93bb85bSJerome Glisse 2552c93bb85bSJerome Glisse if (ASIC_IS_R300(rdev)) { 2553c93bb85bSJerome Glisse sclk_delay_ff.full = rfixed_const(250); 2554c93bb85bSJerome Glisse } else { 2555c93bb85bSJerome Glisse if ((rdev->family == CHIP_RV100) || 2556c93bb85bSJerome Glisse rdev->flags & RADEON_IS_IGP) { 2557c93bb85bSJerome Glisse if (rdev->mc.vram_is_ddr) 2558c93bb85bSJerome Glisse sclk_delay_ff.full = rfixed_const(41); 2559c93bb85bSJerome Glisse else 2560c93bb85bSJerome Glisse sclk_delay_ff.full = rfixed_const(33); 2561c93bb85bSJerome Glisse } else { 2562c93bb85bSJerome Glisse if (rdev->mc.vram_width == 128) 2563c93bb85bSJerome Glisse sclk_delay_ff.full = rfixed_const(57); 2564c93bb85bSJerome Glisse else 2565c93bb85bSJerome Glisse sclk_delay_ff.full = rfixed_const(41); 2566c93bb85bSJerome Glisse } 2567c93bb85bSJerome Glisse } 2568c93bb85bSJerome Glisse 2569c93bb85bSJerome Glisse mc_latency_sclk.full = rfixed_div(sclk_delay_ff, sclk_eff_ff); 2570c93bb85bSJerome Glisse 2571c93bb85bSJerome Glisse if (rdev->mc.vram_is_ddr) { 2572c93bb85bSJerome Glisse if (rdev->mc.vram_width == 32) { 2573c93bb85bSJerome Glisse k1.full = rfixed_const(40); 2574c93bb85bSJerome Glisse c = 3; 2575c93bb85bSJerome Glisse } else { 2576c93bb85bSJerome Glisse k1.full = rfixed_const(20); 2577c93bb85bSJerome Glisse c = 1; 2578c93bb85bSJerome Glisse } 2579c93bb85bSJerome Glisse } else { 2580c93bb85bSJerome Glisse k1.full = rfixed_const(40); 2581c93bb85bSJerome Glisse c = 3; 2582c93bb85bSJerome Glisse } 2583c93bb85bSJerome Glisse 2584c93bb85bSJerome Glisse temp_ff.full = rfixed_const(2); 2585c93bb85bSJerome Glisse mc_latency_mclk.full = rfixed_mul(trcd_ff, temp_ff); 2586c93bb85bSJerome Glisse temp_ff.full = rfixed_const(c); 2587c93bb85bSJerome Glisse mc_latency_mclk.full += rfixed_mul(tcas_ff, temp_ff); 2588c93bb85bSJerome Glisse temp_ff.full = rfixed_const(4); 2589c93bb85bSJerome Glisse mc_latency_mclk.full += rfixed_mul(tras_ff, temp_ff); 2590c93bb85bSJerome Glisse mc_latency_mclk.full += rfixed_mul(trp_ff, temp_ff); 2591c93bb85bSJerome Glisse mc_latency_mclk.full += k1.full; 2592c93bb85bSJerome Glisse 2593c93bb85bSJerome Glisse mc_latency_mclk.full = rfixed_div(mc_latency_mclk, mclk_ff); 2594c93bb85bSJerome Glisse mc_latency_mclk.full += rfixed_div(temp_ff, sclk_eff_ff); 2595c93bb85bSJerome Glisse 2596c93bb85bSJerome Glisse /* 2597c93bb85bSJerome Glisse HW cursor time assuming worst case of full size colour cursor. 2598c93bb85bSJerome Glisse */ 2599c93bb85bSJerome Glisse temp_ff.full = rfixed_const((2 * (cur_size - (rdev->mc.vram_is_ddr + 1)))); 2600c93bb85bSJerome Glisse temp_ff.full += trcd_ff.full; 2601c93bb85bSJerome Glisse if (temp_ff.full < tras_ff.full) 2602c93bb85bSJerome Glisse temp_ff.full = tras_ff.full; 2603c93bb85bSJerome Glisse cur_latency_mclk.full = rfixed_div(temp_ff, mclk_ff); 2604c93bb85bSJerome Glisse 2605c93bb85bSJerome Glisse temp_ff.full = rfixed_const(cur_size); 2606c93bb85bSJerome Glisse cur_latency_sclk.full = rfixed_div(temp_ff, sclk_eff_ff); 2607c93bb85bSJerome Glisse /* 2608c93bb85bSJerome Glisse Find the total latency for the display data. 2609c93bb85bSJerome Glisse */ 2610b5fc9010SMichel Dänzer disp_latency_overhead.full = rfixed_const(8); 2611c93bb85bSJerome Glisse disp_latency_overhead.full = rfixed_div(disp_latency_overhead, sclk_ff); 2612c93bb85bSJerome Glisse mc_latency_mclk.full += disp_latency_overhead.full + cur_latency_mclk.full; 2613c93bb85bSJerome Glisse mc_latency_sclk.full += disp_latency_overhead.full + cur_latency_sclk.full; 2614c93bb85bSJerome Glisse 2615c93bb85bSJerome Glisse if (mc_latency_mclk.full > mc_latency_sclk.full) 2616c93bb85bSJerome Glisse disp_latency.full = mc_latency_mclk.full; 2617c93bb85bSJerome Glisse else 2618c93bb85bSJerome Glisse disp_latency.full = mc_latency_sclk.full; 2619c93bb85bSJerome Glisse 2620c93bb85bSJerome Glisse /* setup Max GRPH_STOP_REQ default value */ 2621c93bb85bSJerome Glisse if (ASIC_IS_RV100(rdev)) 2622c93bb85bSJerome Glisse max_stop_req = 0x5c; 2623c93bb85bSJerome Glisse else 2624c93bb85bSJerome Glisse max_stop_req = 0x7c; 2625c93bb85bSJerome Glisse 2626c93bb85bSJerome Glisse if (mode1) { 2627c93bb85bSJerome Glisse /* CRTC1 2628c93bb85bSJerome Glisse Set GRPH_BUFFER_CNTL register using h/w defined optimal values. 2629c93bb85bSJerome Glisse GRPH_STOP_REQ <= MIN[ 0x7C, (CRTC_H_DISP + 1) * (bit depth) / 0x10 ] 2630c93bb85bSJerome Glisse */ 2631c93bb85bSJerome Glisse stop_req = mode1->hdisplay * pixel_bytes1 / 16; 2632c93bb85bSJerome Glisse 2633c93bb85bSJerome Glisse if (stop_req > max_stop_req) 2634c93bb85bSJerome Glisse stop_req = max_stop_req; 2635c93bb85bSJerome Glisse 2636c93bb85bSJerome Glisse /* 2637c93bb85bSJerome Glisse Find the drain rate of the display buffer. 2638c93bb85bSJerome Glisse */ 2639c93bb85bSJerome Glisse temp_ff.full = rfixed_const((16/pixel_bytes1)); 2640c93bb85bSJerome Glisse disp_drain_rate.full = rfixed_div(pix_clk, temp_ff); 2641c93bb85bSJerome Glisse 2642c93bb85bSJerome Glisse /* 2643c93bb85bSJerome Glisse Find the critical point of the display buffer. 2644c93bb85bSJerome Glisse */ 2645c93bb85bSJerome Glisse crit_point_ff.full = rfixed_mul(disp_drain_rate, disp_latency); 2646c93bb85bSJerome Glisse crit_point_ff.full += rfixed_const_half(0); 2647c93bb85bSJerome Glisse 2648c93bb85bSJerome Glisse critical_point = rfixed_trunc(crit_point_ff); 2649c93bb85bSJerome Glisse 2650c93bb85bSJerome Glisse if (rdev->disp_priority == 2) { 2651c93bb85bSJerome Glisse critical_point = 0; 2652c93bb85bSJerome Glisse } 2653c93bb85bSJerome Glisse 2654c93bb85bSJerome Glisse /* 2655c93bb85bSJerome Glisse The critical point should never be above max_stop_req-4. Setting 2656c93bb85bSJerome Glisse GRPH_CRITICAL_CNTL = 0 will thus force high priority all the time. 2657c93bb85bSJerome Glisse */ 2658c93bb85bSJerome Glisse if (max_stop_req - critical_point < 4) 2659c93bb85bSJerome Glisse critical_point = 0; 2660c93bb85bSJerome Glisse 2661c93bb85bSJerome Glisse if (critical_point == 0 && mode2 && rdev->family == CHIP_R300) { 2662c93bb85bSJerome Glisse /* some R300 cards have problem with this set to 0, when CRTC2 is enabled.*/ 2663c93bb85bSJerome Glisse critical_point = 0x10; 2664c93bb85bSJerome Glisse } 2665c93bb85bSJerome Glisse 2666c93bb85bSJerome Glisse temp = RREG32(RADEON_GRPH_BUFFER_CNTL); 2667c93bb85bSJerome Glisse temp &= ~(RADEON_GRPH_STOP_REQ_MASK); 2668c93bb85bSJerome Glisse temp |= (stop_req << RADEON_GRPH_STOP_REQ_SHIFT); 2669c93bb85bSJerome Glisse temp &= ~(RADEON_GRPH_START_REQ_MASK); 2670c93bb85bSJerome Glisse if ((rdev->family == CHIP_R350) && 2671c93bb85bSJerome Glisse (stop_req > 0x15)) { 2672c93bb85bSJerome Glisse stop_req -= 0x10; 2673c93bb85bSJerome Glisse } 2674c93bb85bSJerome Glisse temp |= (stop_req << RADEON_GRPH_START_REQ_SHIFT); 2675c93bb85bSJerome Glisse temp |= RADEON_GRPH_BUFFER_SIZE; 2676c93bb85bSJerome Glisse temp &= ~(RADEON_GRPH_CRITICAL_CNTL | 2677c93bb85bSJerome Glisse RADEON_GRPH_CRITICAL_AT_SOF | 2678c93bb85bSJerome Glisse RADEON_GRPH_STOP_CNTL); 2679c93bb85bSJerome Glisse /* 2680c93bb85bSJerome Glisse Write the result into the register. 2681c93bb85bSJerome Glisse */ 2682c93bb85bSJerome Glisse WREG32(RADEON_GRPH_BUFFER_CNTL, ((temp & ~RADEON_GRPH_CRITICAL_POINT_MASK) | 2683c93bb85bSJerome Glisse (critical_point << RADEON_GRPH_CRITICAL_POINT_SHIFT))); 2684c93bb85bSJerome Glisse 2685c93bb85bSJerome Glisse #if 0 2686c93bb85bSJerome Glisse if ((rdev->family == CHIP_RS400) || 2687c93bb85bSJerome Glisse (rdev->family == CHIP_RS480)) { 2688c93bb85bSJerome Glisse /* attempt to program RS400 disp regs correctly ??? */ 2689c93bb85bSJerome Glisse temp = RREG32(RS400_DISP1_REG_CNTL); 2690c93bb85bSJerome Glisse temp &= ~(RS400_DISP1_START_REQ_LEVEL_MASK | 2691c93bb85bSJerome Glisse RS400_DISP1_STOP_REQ_LEVEL_MASK); 2692c93bb85bSJerome Glisse WREG32(RS400_DISP1_REQ_CNTL1, (temp | 2693c93bb85bSJerome Glisse (critical_point << RS400_DISP1_START_REQ_LEVEL_SHIFT) | 2694c93bb85bSJerome Glisse (critical_point << RS400_DISP1_STOP_REQ_LEVEL_SHIFT))); 2695c93bb85bSJerome Glisse temp = RREG32(RS400_DMIF_MEM_CNTL1); 2696c93bb85bSJerome Glisse temp &= ~(RS400_DISP1_CRITICAL_POINT_START_MASK | 2697c93bb85bSJerome Glisse RS400_DISP1_CRITICAL_POINT_STOP_MASK); 2698c93bb85bSJerome Glisse WREG32(RS400_DMIF_MEM_CNTL1, (temp | 2699c93bb85bSJerome Glisse (critical_point << RS400_DISP1_CRITICAL_POINT_START_SHIFT) | 2700c93bb85bSJerome Glisse (critical_point << RS400_DISP1_CRITICAL_POINT_STOP_SHIFT))); 2701c93bb85bSJerome Glisse } 2702c93bb85bSJerome Glisse #endif 2703c93bb85bSJerome Glisse 2704c93bb85bSJerome Glisse DRM_DEBUG("GRPH_BUFFER_CNTL from to %x\n", 2705c93bb85bSJerome Glisse /* (unsigned int)info->SavedReg->grph_buffer_cntl, */ 2706c93bb85bSJerome Glisse (unsigned int)RREG32(RADEON_GRPH_BUFFER_CNTL)); 2707c93bb85bSJerome Glisse } 2708c93bb85bSJerome Glisse 2709c93bb85bSJerome Glisse if (mode2) { 2710c93bb85bSJerome Glisse u32 grph2_cntl; 2711c93bb85bSJerome Glisse stop_req = mode2->hdisplay * pixel_bytes2 / 16; 2712c93bb85bSJerome Glisse 2713c93bb85bSJerome Glisse if (stop_req > max_stop_req) 2714c93bb85bSJerome Glisse stop_req = max_stop_req; 2715c93bb85bSJerome Glisse 2716c93bb85bSJerome Glisse /* 2717c93bb85bSJerome Glisse Find the drain rate of the display buffer. 2718c93bb85bSJerome Glisse */ 2719c93bb85bSJerome Glisse temp_ff.full = rfixed_const((16/pixel_bytes2)); 2720c93bb85bSJerome Glisse disp_drain_rate2.full = rfixed_div(pix_clk2, temp_ff); 2721c93bb85bSJerome Glisse 2722c93bb85bSJerome Glisse grph2_cntl = RREG32(RADEON_GRPH2_BUFFER_CNTL); 2723c93bb85bSJerome Glisse grph2_cntl &= ~(RADEON_GRPH_STOP_REQ_MASK); 2724c93bb85bSJerome Glisse grph2_cntl |= (stop_req << RADEON_GRPH_STOP_REQ_SHIFT); 2725c93bb85bSJerome Glisse grph2_cntl &= ~(RADEON_GRPH_START_REQ_MASK); 2726c93bb85bSJerome Glisse if ((rdev->family == CHIP_R350) && 2727c93bb85bSJerome Glisse (stop_req > 0x15)) { 2728c93bb85bSJerome Glisse stop_req -= 0x10; 2729c93bb85bSJerome Glisse } 2730c93bb85bSJerome Glisse grph2_cntl |= (stop_req << RADEON_GRPH_START_REQ_SHIFT); 2731c93bb85bSJerome Glisse grph2_cntl |= RADEON_GRPH_BUFFER_SIZE; 2732c93bb85bSJerome Glisse grph2_cntl &= ~(RADEON_GRPH_CRITICAL_CNTL | 2733c93bb85bSJerome Glisse RADEON_GRPH_CRITICAL_AT_SOF | 2734c93bb85bSJerome Glisse RADEON_GRPH_STOP_CNTL); 2735c93bb85bSJerome Glisse 2736c93bb85bSJerome Glisse if ((rdev->family == CHIP_RS100) || 2737c93bb85bSJerome Glisse (rdev->family == CHIP_RS200)) 2738c93bb85bSJerome Glisse critical_point2 = 0; 2739c93bb85bSJerome Glisse else { 2740c93bb85bSJerome Glisse temp = (rdev->mc.vram_width * rdev->mc.vram_is_ddr + 1)/128; 2741c93bb85bSJerome Glisse temp_ff.full = rfixed_const(temp); 2742c93bb85bSJerome Glisse temp_ff.full = rfixed_mul(mclk_ff, temp_ff); 2743c93bb85bSJerome Glisse if (sclk_ff.full < temp_ff.full) 2744c93bb85bSJerome Glisse temp_ff.full = sclk_ff.full; 2745c93bb85bSJerome Glisse 2746c93bb85bSJerome Glisse read_return_rate.full = temp_ff.full; 2747c93bb85bSJerome Glisse 2748c93bb85bSJerome Glisse if (mode1) { 2749c93bb85bSJerome Glisse temp_ff.full = read_return_rate.full - disp_drain_rate.full; 2750c93bb85bSJerome Glisse time_disp1_drop_priority.full = rfixed_div(crit_point_ff, temp_ff); 2751c93bb85bSJerome Glisse } else { 2752c93bb85bSJerome Glisse time_disp1_drop_priority.full = 0; 2753c93bb85bSJerome Glisse } 2754c93bb85bSJerome Glisse crit_point_ff.full = disp_latency.full + time_disp1_drop_priority.full + disp_latency.full; 2755c93bb85bSJerome Glisse crit_point_ff.full = rfixed_mul(crit_point_ff, disp_drain_rate2); 2756c93bb85bSJerome Glisse crit_point_ff.full += rfixed_const_half(0); 2757c93bb85bSJerome Glisse 2758c93bb85bSJerome Glisse critical_point2 = rfixed_trunc(crit_point_ff); 2759c93bb85bSJerome Glisse 2760c93bb85bSJerome Glisse if (rdev->disp_priority == 2) { 2761c93bb85bSJerome Glisse critical_point2 = 0; 2762c93bb85bSJerome Glisse } 2763c93bb85bSJerome Glisse 2764c93bb85bSJerome Glisse if (max_stop_req - critical_point2 < 4) 2765c93bb85bSJerome Glisse critical_point2 = 0; 2766c93bb85bSJerome Glisse 2767c93bb85bSJerome Glisse } 2768c93bb85bSJerome Glisse 2769c93bb85bSJerome Glisse if (critical_point2 == 0 && rdev->family == CHIP_R300) { 2770c93bb85bSJerome Glisse /* some R300 cards have problem with this set to 0 */ 2771c93bb85bSJerome Glisse critical_point2 = 0x10; 2772c93bb85bSJerome Glisse } 2773c93bb85bSJerome Glisse 2774c93bb85bSJerome Glisse WREG32(RADEON_GRPH2_BUFFER_CNTL, ((grph2_cntl & ~RADEON_GRPH_CRITICAL_POINT_MASK) | 2775c93bb85bSJerome Glisse (critical_point2 << RADEON_GRPH_CRITICAL_POINT_SHIFT))); 2776c93bb85bSJerome Glisse 2777c93bb85bSJerome Glisse if ((rdev->family == CHIP_RS400) || 2778c93bb85bSJerome Glisse (rdev->family == CHIP_RS480)) { 2779c93bb85bSJerome Glisse #if 0 2780c93bb85bSJerome Glisse /* attempt to program RS400 disp2 regs correctly ??? */ 2781c93bb85bSJerome Glisse temp = RREG32(RS400_DISP2_REQ_CNTL1); 2782c93bb85bSJerome Glisse temp &= ~(RS400_DISP2_START_REQ_LEVEL_MASK | 2783c93bb85bSJerome Glisse RS400_DISP2_STOP_REQ_LEVEL_MASK); 2784c93bb85bSJerome Glisse WREG32(RS400_DISP2_REQ_CNTL1, (temp | 2785c93bb85bSJerome Glisse (critical_point2 << RS400_DISP1_START_REQ_LEVEL_SHIFT) | 2786c93bb85bSJerome Glisse (critical_point2 << RS400_DISP1_STOP_REQ_LEVEL_SHIFT))); 2787c93bb85bSJerome Glisse temp = RREG32(RS400_DISP2_REQ_CNTL2); 2788c93bb85bSJerome Glisse temp &= ~(RS400_DISP2_CRITICAL_POINT_START_MASK | 2789c93bb85bSJerome Glisse RS400_DISP2_CRITICAL_POINT_STOP_MASK); 2790c93bb85bSJerome Glisse WREG32(RS400_DISP2_REQ_CNTL2, (temp | 2791c93bb85bSJerome Glisse (critical_point2 << RS400_DISP2_CRITICAL_POINT_START_SHIFT) | 2792c93bb85bSJerome Glisse (critical_point2 << RS400_DISP2_CRITICAL_POINT_STOP_SHIFT))); 2793c93bb85bSJerome Glisse #endif 2794c93bb85bSJerome Glisse WREG32(RS400_DISP2_REQ_CNTL1, 0x105DC1CC); 2795c93bb85bSJerome Glisse WREG32(RS400_DISP2_REQ_CNTL2, 0x2749D000); 2796c93bb85bSJerome Glisse WREG32(RS400_DMIF_MEM_CNTL1, 0x29CA71DC); 2797c93bb85bSJerome Glisse WREG32(RS400_DISP1_REQ_CNTL1, 0x28FBC3AC); 2798c93bb85bSJerome Glisse } 2799c93bb85bSJerome Glisse 2800c93bb85bSJerome Glisse DRM_DEBUG("GRPH2_BUFFER_CNTL from to %x\n", 2801c93bb85bSJerome Glisse (unsigned int)RREG32(RADEON_GRPH2_BUFFER_CNTL)); 2802c93bb85bSJerome Glisse } 2803c93bb85bSJerome Glisse } 2804551ebd83SDave Airlie 2805551ebd83SDave Airlie static inline void r100_cs_track_texture_print(struct r100_cs_track_texture *t) 2806551ebd83SDave Airlie { 2807551ebd83SDave Airlie DRM_ERROR("pitch %d\n", t->pitch); 2808ceb776bcSMathias Fröhlich DRM_ERROR("use_pitch %d\n", t->use_pitch); 2809551ebd83SDave Airlie DRM_ERROR("width %d\n", t->width); 2810ceb776bcSMathias Fröhlich DRM_ERROR("width_11 %d\n", t->width_11); 2811551ebd83SDave Airlie DRM_ERROR("height %d\n", t->height); 2812ceb776bcSMathias Fröhlich DRM_ERROR("height_11 %d\n", t->height_11); 2813551ebd83SDave Airlie DRM_ERROR("num levels %d\n", t->num_levels); 2814551ebd83SDave Airlie DRM_ERROR("depth %d\n", t->txdepth); 2815551ebd83SDave Airlie DRM_ERROR("bpp %d\n", t->cpp); 2816551ebd83SDave Airlie DRM_ERROR("coordinate type %d\n", t->tex_coord_type); 2817551ebd83SDave Airlie DRM_ERROR("width round to power of 2 %d\n", t->roundup_w); 2818551ebd83SDave Airlie DRM_ERROR("height round to power of 2 %d\n", t->roundup_h); 2819d785d78bSDave Airlie DRM_ERROR("compress format %d\n", t->compress_format); 2820551ebd83SDave Airlie } 2821551ebd83SDave Airlie 2822551ebd83SDave Airlie static int r100_cs_track_cube(struct radeon_device *rdev, 2823551ebd83SDave Airlie struct r100_cs_track *track, unsigned idx) 2824551ebd83SDave Airlie { 2825551ebd83SDave Airlie unsigned face, w, h; 28264c788679SJerome Glisse struct radeon_bo *cube_robj; 2827551ebd83SDave Airlie unsigned long size; 2828551ebd83SDave Airlie 2829551ebd83SDave Airlie for (face = 0; face < 5; face++) { 2830551ebd83SDave Airlie cube_robj = track->textures[idx].cube_info[face].robj; 2831551ebd83SDave Airlie w = track->textures[idx].cube_info[face].width; 2832551ebd83SDave Airlie h = track->textures[idx].cube_info[face].height; 2833551ebd83SDave Airlie 2834551ebd83SDave Airlie size = w * h; 2835551ebd83SDave Airlie size *= track->textures[idx].cpp; 2836551ebd83SDave Airlie 2837551ebd83SDave Airlie size += track->textures[idx].cube_info[face].offset; 2838551ebd83SDave Airlie 28394c788679SJerome Glisse if (size > radeon_bo_size(cube_robj)) { 2840551ebd83SDave Airlie DRM_ERROR("Cube texture offset greater than object size %lu %lu\n", 28414c788679SJerome Glisse size, radeon_bo_size(cube_robj)); 2842551ebd83SDave Airlie r100_cs_track_texture_print(&track->textures[idx]); 2843551ebd83SDave Airlie return -1; 2844551ebd83SDave Airlie } 2845551ebd83SDave Airlie } 2846551ebd83SDave Airlie return 0; 2847551ebd83SDave Airlie } 2848551ebd83SDave Airlie 2849d785d78bSDave Airlie static int r100_track_compress_size(int compress_format, int w, int h) 2850d785d78bSDave Airlie { 2851d785d78bSDave Airlie int block_width, block_height, block_bytes; 2852d785d78bSDave Airlie int wblocks, hblocks; 2853d785d78bSDave Airlie int min_wblocks; 2854d785d78bSDave Airlie int sz; 2855d785d78bSDave Airlie 2856d785d78bSDave Airlie block_width = 4; 2857d785d78bSDave Airlie block_height = 4; 2858d785d78bSDave Airlie 2859d785d78bSDave Airlie switch (compress_format) { 2860d785d78bSDave Airlie case R100_TRACK_COMP_DXT1: 2861d785d78bSDave Airlie block_bytes = 8; 2862d785d78bSDave Airlie min_wblocks = 4; 2863d785d78bSDave Airlie break; 2864d785d78bSDave Airlie default: 2865d785d78bSDave Airlie case R100_TRACK_COMP_DXT35: 2866d785d78bSDave Airlie block_bytes = 16; 2867d785d78bSDave Airlie min_wblocks = 2; 2868d785d78bSDave Airlie break; 2869d785d78bSDave Airlie } 2870d785d78bSDave Airlie 2871d785d78bSDave Airlie hblocks = (h + block_height - 1) / block_height; 2872d785d78bSDave Airlie wblocks = (w + block_width - 1) / block_width; 2873d785d78bSDave Airlie if (wblocks < min_wblocks) 2874d785d78bSDave Airlie wblocks = min_wblocks; 2875d785d78bSDave Airlie sz = wblocks * hblocks * block_bytes; 2876d785d78bSDave Airlie return sz; 2877d785d78bSDave Airlie } 2878d785d78bSDave Airlie 2879551ebd83SDave Airlie static int r100_cs_track_texture_check(struct radeon_device *rdev, 2880551ebd83SDave Airlie struct r100_cs_track *track) 2881551ebd83SDave Airlie { 28824c788679SJerome Glisse struct radeon_bo *robj; 2883551ebd83SDave Airlie unsigned long size; 2884551ebd83SDave Airlie unsigned u, i, w, h; 2885551ebd83SDave Airlie int ret; 2886551ebd83SDave Airlie 2887551ebd83SDave Airlie for (u = 0; u < track->num_texture; u++) { 2888551ebd83SDave Airlie if (!track->textures[u].enabled) 2889551ebd83SDave Airlie continue; 2890551ebd83SDave Airlie robj = track->textures[u].robj; 2891551ebd83SDave Airlie if (robj == NULL) { 2892551ebd83SDave Airlie DRM_ERROR("No texture bound to unit %u\n", u); 2893551ebd83SDave Airlie return -EINVAL; 2894551ebd83SDave Airlie } 2895551ebd83SDave Airlie size = 0; 2896551ebd83SDave Airlie for (i = 0; i <= track->textures[u].num_levels; i++) { 2897551ebd83SDave Airlie if (track->textures[u].use_pitch) { 2898551ebd83SDave Airlie if (rdev->family < CHIP_R300) 2899551ebd83SDave Airlie w = (track->textures[u].pitch / track->textures[u].cpp) / (1 << i); 2900551ebd83SDave Airlie else 2901551ebd83SDave Airlie w = track->textures[u].pitch / (1 << i); 2902551ebd83SDave Airlie } else { 2903ceb776bcSMathias Fröhlich w = track->textures[u].width; 2904551ebd83SDave Airlie if (rdev->family >= CHIP_RV515) 2905551ebd83SDave Airlie w |= track->textures[u].width_11; 2906ceb776bcSMathias Fröhlich w = w / (1 << i); 2907551ebd83SDave Airlie if (track->textures[u].roundup_w) 2908551ebd83SDave Airlie w = roundup_pow_of_two(w); 2909551ebd83SDave Airlie } 2910ceb776bcSMathias Fröhlich h = track->textures[u].height; 2911551ebd83SDave Airlie if (rdev->family >= CHIP_RV515) 2912551ebd83SDave Airlie h |= track->textures[u].height_11; 2913ceb776bcSMathias Fröhlich h = h / (1 << i); 2914551ebd83SDave Airlie if (track->textures[u].roundup_h) 2915551ebd83SDave Airlie h = roundup_pow_of_two(h); 2916d785d78bSDave Airlie if (track->textures[u].compress_format) { 2917d785d78bSDave Airlie 2918d785d78bSDave Airlie size += r100_track_compress_size(track->textures[u].compress_format, w, h); 2919d785d78bSDave Airlie /* compressed textures are block based */ 2920d785d78bSDave Airlie } else 2921551ebd83SDave Airlie size += w * h; 2922551ebd83SDave Airlie } 2923551ebd83SDave Airlie size *= track->textures[u].cpp; 2924d785d78bSDave Airlie 2925551ebd83SDave Airlie switch (track->textures[u].tex_coord_type) { 2926551ebd83SDave Airlie case 0: 2927551ebd83SDave Airlie break; 2928551ebd83SDave Airlie case 1: 2929551ebd83SDave Airlie size *= (1 << track->textures[u].txdepth); 2930551ebd83SDave Airlie break; 2931551ebd83SDave Airlie case 2: 2932551ebd83SDave Airlie if (track->separate_cube) { 2933551ebd83SDave Airlie ret = r100_cs_track_cube(rdev, track, u); 2934551ebd83SDave Airlie if (ret) 2935551ebd83SDave Airlie return ret; 2936551ebd83SDave Airlie } else 2937551ebd83SDave Airlie size *= 6; 2938551ebd83SDave Airlie break; 2939551ebd83SDave Airlie default: 2940551ebd83SDave Airlie DRM_ERROR("Invalid texture coordinate type %u for unit " 2941551ebd83SDave Airlie "%u\n", track->textures[u].tex_coord_type, u); 2942551ebd83SDave Airlie return -EINVAL; 2943551ebd83SDave Airlie } 29444c788679SJerome Glisse if (size > radeon_bo_size(robj)) { 2945551ebd83SDave Airlie DRM_ERROR("Texture of unit %u needs %lu bytes but is " 29464c788679SJerome Glisse "%lu\n", u, size, radeon_bo_size(robj)); 2947551ebd83SDave Airlie r100_cs_track_texture_print(&track->textures[u]); 2948551ebd83SDave Airlie return -EINVAL; 2949551ebd83SDave Airlie } 2950551ebd83SDave Airlie } 2951551ebd83SDave Airlie return 0; 2952551ebd83SDave Airlie } 2953551ebd83SDave Airlie 2954551ebd83SDave Airlie int r100_cs_track_check(struct radeon_device *rdev, struct r100_cs_track *track) 2955551ebd83SDave Airlie { 2956551ebd83SDave Airlie unsigned i; 2957551ebd83SDave Airlie unsigned long size; 2958551ebd83SDave Airlie unsigned prim_walk; 2959551ebd83SDave Airlie unsigned nverts; 2960551ebd83SDave Airlie 2961551ebd83SDave Airlie for (i = 0; i < track->num_cb; i++) { 2962551ebd83SDave Airlie if (track->cb[i].robj == NULL) { 296346c64d4bSMarek Olšák if (!(track->fastfill || track->color_channel_mask || 296446c64d4bSMarek Olšák track->blend_read_enable)) { 296546c64d4bSMarek Olšák continue; 296646c64d4bSMarek Olšák } 2967551ebd83SDave Airlie DRM_ERROR("[drm] No buffer for color buffer %d !\n", i); 2968551ebd83SDave Airlie return -EINVAL; 2969551ebd83SDave Airlie } 2970551ebd83SDave Airlie size = track->cb[i].pitch * track->cb[i].cpp * track->maxy; 2971551ebd83SDave Airlie size += track->cb[i].offset; 29724c788679SJerome Glisse if (size > radeon_bo_size(track->cb[i].robj)) { 2973551ebd83SDave Airlie DRM_ERROR("[drm] Buffer too small for color buffer %d " 2974551ebd83SDave Airlie "(need %lu have %lu) !\n", i, size, 29754c788679SJerome Glisse radeon_bo_size(track->cb[i].robj)); 2976551ebd83SDave Airlie DRM_ERROR("[drm] color buffer %d (%u %u %u %u)\n", 2977551ebd83SDave Airlie i, track->cb[i].pitch, track->cb[i].cpp, 2978551ebd83SDave Airlie track->cb[i].offset, track->maxy); 2979551ebd83SDave Airlie return -EINVAL; 2980551ebd83SDave Airlie } 2981551ebd83SDave Airlie } 2982551ebd83SDave Airlie if (track->z_enabled) { 2983551ebd83SDave Airlie if (track->zb.robj == NULL) { 2984551ebd83SDave Airlie DRM_ERROR("[drm] No buffer for z buffer !\n"); 2985551ebd83SDave Airlie return -EINVAL; 2986551ebd83SDave Airlie } 2987551ebd83SDave Airlie size = track->zb.pitch * track->zb.cpp * track->maxy; 2988551ebd83SDave Airlie size += track->zb.offset; 29894c788679SJerome Glisse if (size > radeon_bo_size(track->zb.robj)) { 2990551ebd83SDave Airlie DRM_ERROR("[drm] Buffer too small for z buffer " 2991551ebd83SDave Airlie "(need %lu have %lu) !\n", size, 29924c788679SJerome Glisse radeon_bo_size(track->zb.robj)); 2993551ebd83SDave Airlie DRM_ERROR("[drm] zbuffer (%u %u %u %u)\n", 2994551ebd83SDave Airlie track->zb.pitch, track->zb.cpp, 2995551ebd83SDave Airlie track->zb.offset, track->maxy); 2996551ebd83SDave Airlie return -EINVAL; 2997551ebd83SDave Airlie } 2998551ebd83SDave Airlie } 2999551ebd83SDave Airlie prim_walk = (track->vap_vf_cntl >> 4) & 0x3; 3000551ebd83SDave Airlie nverts = (track->vap_vf_cntl >> 16) & 0xFFFF; 3001551ebd83SDave Airlie switch (prim_walk) { 3002551ebd83SDave Airlie case 1: 3003551ebd83SDave Airlie for (i = 0; i < track->num_arrays; i++) { 3004551ebd83SDave Airlie size = track->arrays[i].esize * track->max_indx * 4; 3005551ebd83SDave Airlie if (track->arrays[i].robj == NULL) { 3006551ebd83SDave Airlie DRM_ERROR("(PW %u) Vertex array %u no buffer " 3007551ebd83SDave Airlie "bound\n", prim_walk, i); 3008551ebd83SDave Airlie return -EINVAL; 3009551ebd83SDave Airlie } 30104c788679SJerome Glisse if (size > radeon_bo_size(track->arrays[i].robj)) { 30114c788679SJerome Glisse dev_err(rdev->dev, "(PW %u) Vertex array %u " 30124c788679SJerome Glisse "need %lu dwords have %lu dwords\n", 30134c788679SJerome Glisse prim_walk, i, size >> 2, 30144c788679SJerome Glisse radeon_bo_size(track->arrays[i].robj) 30154c788679SJerome Glisse >> 2); 3016551ebd83SDave Airlie DRM_ERROR("Max indices %u\n", track->max_indx); 3017551ebd83SDave Airlie return -EINVAL; 3018551ebd83SDave Airlie } 3019551ebd83SDave Airlie } 3020551ebd83SDave Airlie break; 3021551ebd83SDave Airlie case 2: 3022551ebd83SDave Airlie for (i = 0; i < track->num_arrays; i++) { 3023551ebd83SDave Airlie size = track->arrays[i].esize * (nverts - 1) * 4; 3024551ebd83SDave Airlie if (track->arrays[i].robj == NULL) { 3025551ebd83SDave Airlie DRM_ERROR("(PW %u) Vertex array %u no buffer " 3026551ebd83SDave Airlie "bound\n", prim_walk, i); 3027551ebd83SDave Airlie return -EINVAL; 3028551ebd83SDave Airlie } 30294c788679SJerome Glisse if (size > radeon_bo_size(track->arrays[i].robj)) { 30304c788679SJerome Glisse dev_err(rdev->dev, "(PW %u) Vertex array %u " 30314c788679SJerome Glisse "need %lu dwords have %lu dwords\n", 30324c788679SJerome Glisse prim_walk, i, size >> 2, 30334c788679SJerome Glisse radeon_bo_size(track->arrays[i].robj) 30344c788679SJerome Glisse >> 2); 3035551ebd83SDave Airlie return -EINVAL; 3036551ebd83SDave Airlie } 3037551ebd83SDave Airlie } 3038551ebd83SDave Airlie break; 3039551ebd83SDave Airlie case 3: 3040551ebd83SDave Airlie size = track->vtx_size * nverts; 3041551ebd83SDave Airlie if (size != track->immd_dwords) { 3042551ebd83SDave Airlie DRM_ERROR("IMMD draw %u dwors but needs %lu dwords\n", 3043551ebd83SDave Airlie track->immd_dwords, size); 3044551ebd83SDave Airlie DRM_ERROR("VAP_VF_CNTL.NUM_VERTICES %u, VTX_SIZE %u\n", 3045551ebd83SDave Airlie nverts, track->vtx_size); 3046551ebd83SDave Airlie return -EINVAL; 3047551ebd83SDave Airlie } 3048551ebd83SDave Airlie break; 3049551ebd83SDave Airlie default: 3050551ebd83SDave Airlie DRM_ERROR("[drm] Invalid primitive walk %d for VAP_VF_CNTL\n", 3051551ebd83SDave Airlie prim_walk); 3052551ebd83SDave Airlie return -EINVAL; 3053551ebd83SDave Airlie } 3054551ebd83SDave Airlie return r100_cs_track_texture_check(rdev, track); 3055551ebd83SDave Airlie } 3056551ebd83SDave Airlie 3057551ebd83SDave Airlie void r100_cs_track_clear(struct radeon_device *rdev, struct r100_cs_track *track) 3058551ebd83SDave Airlie { 3059551ebd83SDave Airlie unsigned i, face; 3060551ebd83SDave Airlie 3061551ebd83SDave Airlie if (rdev->family < CHIP_R300) { 3062551ebd83SDave Airlie track->num_cb = 1; 3063551ebd83SDave Airlie if (rdev->family <= CHIP_RS200) 3064551ebd83SDave Airlie track->num_texture = 3; 3065551ebd83SDave Airlie else 3066551ebd83SDave Airlie track->num_texture = 6; 3067551ebd83SDave Airlie track->maxy = 2048; 3068551ebd83SDave Airlie track->separate_cube = 1; 3069551ebd83SDave Airlie } else { 3070551ebd83SDave Airlie track->num_cb = 4; 3071551ebd83SDave Airlie track->num_texture = 16; 3072551ebd83SDave Airlie track->maxy = 4096; 3073551ebd83SDave Airlie track->separate_cube = 0; 3074551ebd83SDave Airlie } 3075551ebd83SDave Airlie 3076551ebd83SDave Airlie for (i = 0; i < track->num_cb; i++) { 3077551ebd83SDave Airlie track->cb[i].robj = NULL; 3078551ebd83SDave Airlie track->cb[i].pitch = 8192; 3079551ebd83SDave Airlie track->cb[i].cpp = 16; 3080551ebd83SDave Airlie track->cb[i].offset = 0; 3081551ebd83SDave Airlie } 3082551ebd83SDave Airlie track->z_enabled = true; 3083551ebd83SDave Airlie track->zb.robj = NULL; 3084551ebd83SDave Airlie track->zb.pitch = 8192; 3085551ebd83SDave Airlie track->zb.cpp = 4; 3086551ebd83SDave Airlie track->zb.offset = 0; 3087551ebd83SDave Airlie track->vtx_size = 0x7F; 3088551ebd83SDave Airlie track->immd_dwords = 0xFFFFFFFFUL; 3089551ebd83SDave Airlie track->num_arrays = 11; 3090551ebd83SDave Airlie track->max_indx = 0x00FFFFFFUL; 3091551ebd83SDave Airlie for (i = 0; i < track->num_arrays; i++) { 3092551ebd83SDave Airlie track->arrays[i].robj = NULL; 3093551ebd83SDave Airlie track->arrays[i].esize = 0x7F; 3094551ebd83SDave Airlie } 3095551ebd83SDave Airlie for (i = 0; i < track->num_texture; i++) { 3096d785d78bSDave Airlie track->textures[i].compress_format = R100_TRACK_COMP_NONE; 3097551ebd83SDave Airlie track->textures[i].pitch = 16536; 3098551ebd83SDave Airlie track->textures[i].width = 16536; 3099551ebd83SDave Airlie track->textures[i].height = 16536; 3100551ebd83SDave Airlie track->textures[i].width_11 = 1 << 11; 3101551ebd83SDave Airlie track->textures[i].height_11 = 1 << 11; 3102551ebd83SDave Airlie track->textures[i].num_levels = 12; 3103551ebd83SDave Airlie if (rdev->family <= CHIP_RS200) { 3104551ebd83SDave Airlie track->textures[i].tex_coord_type = 0; 3105551ebd83SDave Airlie track->textures[i].txdepth = 0; 3106551ebd83SDave Airlie } else { 3107551ebd83SDave Airlie track->textures[i].txdepth = 16; 3108551ebd83SDave Airlie track->textures[i].tex_coord_type = 1; 3109551ebd83SDave Airlie } 3110551ebd83SDave Airlie track->textures[i].cpp = 64; 3111551ebd83SDave Airlie track->textures[i].robj = NULL; 3112551ebd83SDave Airlie /* CS IB emission code makes sure texture unit are disabled */ 3113551ebd83SDave Airlie track->textures[i].enabled = false; 3114551ebd83SDave Airlie track->textures[i].roundup_w = true; 3115551ebd83SDave Airlie track->textures[i].roundup_h = true; 3116551ebd83SDave Airlie if (track->separate_cube) 3117551ebd83SDave Airlie for (face = 0; face < 5; face++) { 3118551ebd83SDave Airlie track->textures[i].cube_info[face].robj = NULL; 3119551ebd83SDave Airlie track->textures[i].cube_info[face].width = 16536; 3120551ebd83SDave Airlie track->textures[i].cube_info[face].height = 16536; 3121551ebd83SDave Airlie track->textures[i].cube_info[face].offset = 0; 3122551ebd83SDave Airlie } 3123551ebd83SDave Airlie } 3124551ebd83SDave Airlie } 31253ce0a23dSJerome Glisse 31263ce0a23dSJerome Glisse int r100_ring_test(struct radeon_device *rdev) 31273ce0a23dSJerome Glisse { 31283ce0a23dSJerome Glisse uint32_t scratch; 31293ce0a23dSJerome Glisse uint32_t tmp = 0; 31303ce0a23dSJerome Glisse unsigned i; 31313ce0a23dSJerome Glisse int r; 31323ce0a23dSJerome Glisse 31333ce0a23dSJerome Glisse r = radeon_scratch_get(rdev, &scratch); 31343ce0a23dSJerome Glisse if (r) { 31353ce0a23dSJerome Glisse DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r); 31363ce0a23dSJerome Glisse return r; 31373ce0a23dSJerome Glisse } 31383ce0a23dSJerome Glisse WREG32(scratch, 0xCAFEDEAD); 31393ce0a23dSJerome Glisse r = radeon_ring_lock(rdev, 2); 31403ce0a23dSJerome Glisse if (r) { 31413ce0a23dSJerome Glisse DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r); 31423ce0a23dSJerome Glisse radeon_scratch_free(rdev, scratch); 31433ce0a23dSJerome Glisse return r; 31443ce0a23dSJerome Glisse } 31453ce0a23dSJerome Glisse radeon_ring_write(rdev, PACKET0(scratch, 0)); 31463ce0a23dSJerome Glisse radeon_ring_write(rdev, 0xDEADBEEF); 31473ce0a23dSJerome Glisse radeon_ring_unlock_commit(rdev); 31483ce0a23dSJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 31493ce0a23dSJerome Glisse tmp = RREG32(scratch); 31503ce0a23dSJerome Glisse if (tmp == 0xDEADBEEF) { 31513ce0a23dSJerome Glisse break; 31523ce0a23dSJerome Glisse } 31533ce0a23dSJerome Glisse DRM_UDELAY(1); 31543ce0a23dSJerome Glisse } 31553ce0a23dSJerome Glisse if (i < rdev->usec_timeout) { 31563ce0a23dSJerome Glisse DRM_INFO("ring test succeeded in %d usecs\n", i); 31573ce0a23dSJerome Glisse } else { 31583ce0a23dSJerome Glisse DRM_ERROR("radeon: ring test failed (sracth(0x%04X)=0x%08X)\n", 31593ce0a23dSJerome Glisse scratch, tmp); 31603ce0a23dSJerome Glisse r = -EINVAL; 31613ce0a23dSJerome Glisse } 31623ce0a23dSJerome Glisse radeon_scratch_free(rdev, scratch); 31633ce0a23dSJerome Glisse return r; 31643ce0a23dSJerome Glisse } 31653ce0a23dSJerome Glisse 31663ce0a23dSJerome Glisse void r100_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib) 31673ce0a23dSJerome Glisse { 31683ce0a23dSJerome Glisse radeon_ring_write(rdev, PACKET0(RADEON_CP_IB_BASE, 1)); 31693ce0a23dSJerome Glisse radeon_ring_write(rdev, ib->gpu_addr); 31703ce0a23dSJerome Glisse radeon_ring_write(rdev, ib->length_dw); 31713ce0a23dSJerome Glisse } 31723ce0a23dSJerome Glisse 31733ce0a23dSJerome Glisse int r100_ib_test(struct radeon_device *rdev) 31743ce0a23dSJerome Glisse { 31753ce0a23dSJerome Glisse struct radeon_ib *ib; 31763ce0a23dSJerome Glisse uint32_t scratch; 31773ce0a23dSJerome Glisse uint32_t tmp = 0; 31783ce0a23dSJerome Glisse unsigned i; 31793ce0a23dSJerome Glisse int r; 31803ce0a23dSJerome Glisse 31813ce0a23dSJerome Glisse r = radeon_scratch_get(rdev, &scratch); 31823ce0a23dSJerome Glisse if (r) { 31833ce0a23dSJerome Glisse DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r); 31843ce0a23dSJerome Glisse return r; 31853ce0a23dSJerome Glisse } 31863ce0a23dSJerome Glisse WREG32(scratch, 0xCAFEDEAD); 31873ce0a23dSJerome Glisse r = radeon_ib_get(rdev, &ib); 31883ce0a23dSJerome Glisse if (r) { 31893ce0a23dSJerome Glisse return r; 31903ce0a23dSJerome Glisse } 31913ce0a23dSJerome Glisse ib->ptr[0] = PACKET0(scratch, 0); 31923ce0a23dSJerome Glisse ib->ptr[1] = 0xDEADBEEF; 31933ce0a23dSJerome Glisse ib->ptr[2] = PACKET2(0); 31943ce0a23dSJerome Glisse ib->ptr[3] = PACKET2(0); 31953ce0a23dSJerome Glisse ib->ptr[4] = PACKET2(0); 31963ce0a23dSJerome Glisse ib->ptr[5] = PACKET2(0); 31973ce0a23dSJerome Glisse ib->ptr[6] = PACKET2(0); 31983ce0a23dSJerome Glisse ib->ptr[7] = PACKET2(0); 31993ce0a23dSJerome Glisse ib->length_dw = 8; 32003ce0a23dSJerome Glisse r = radeon_ib_schedule(rdev, ib); 32013ce0a23dSJerome Glisse if (r) { 32023ce0a23dSJerome Glisse radeon_scratch_free(rdev, scratch); 32033ce0a23dSJerome Glisse radeon_ib_free(rdev, &ib); 32043ce0a23dSJerome Glisse return r; 32053ce0a23dSJerome Glisse } 32063ce0a23dSJerome Glisse r = radeon_fence_wait(ib->fence, false); 32073ce0a23dSJerome Glisse if (r) { 32083ce0a23dSJerome Glisse return r; 32093ce0a23dSJerome Glisse } 32103ce0a23dSJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 32113ce0a23dSJerome Glisse tmp = RREG32(scratch); 32123ce0a23dSJerome Glisse if (tmp == 0xDEADBEEF) { 32133ce0a23dSJerome Glisse break; 32143ce0a23dSJerome Glisse } 32153ce0a23dSJerome Glisse DRM_UDELAY(1); 32163ce0a23dSJerome Glisse } 32173ce0a23dSJerome Glisse if (i < rdev->usec_timeout) { 32183ce0a23dSJerome Glisse DRM_INFO("ib test succeeded in %u usecs\n", i); 32193ce0a23dSJerome Glisse } else { 32203ce0a23dSJerome Glisse DRM_ERROR("radeon: ib test failed (sracth(0x%04X)=0x%08X)\n", 32213ce0a23dSJerome Glisse scratch, tmp); 32223ce0a23dSJerome Glisse r = -EINVAL; 32233ce0a23dSJerome Glisse } 32243ce0a23dSJerome Glisse radeon_scratch_free(rdev, scratch); 32253ce0a23dSJerome Glisse radeon_ib_free(rdev, &ib); 32263ce0a23dSJerome Glisse return r; 32273ce0a23dSJerome Glisse } 32289f022ddfSJerome Glisse 32299f022ddfSJerome Glisse void r100_ib_fini(struct radeon_device *rdev) 32309f022ddfSJerome Glisse { 32319f022ddfSJerome Glisse radeon_ib_pool_fini(rdev); 32329f022ddfSJerome Glisse } 32339f022ddfSJerome Glisse 32349f022ddfSJerome Glisse int r100_ib_init(struct radeon_device *rdev) 32359f022ddfSJerome Glisse { 32369f022ddfSJerome Glisse int r; 32379f022ddfSJerome Glisse 32389f022ddfSJerome Glisse r = radeon_ib_pool_init(rdev); 32399f022ddfSJerome Glisse if (r) { 32409f022ddfSJerome Glisse dev_err(rdev->dev, "failled initializing IB pool (%d).\n", r); 32419f022ddfSJerome Glisse r100_ib_fini(rdev); 32429f022ddfSJerome Glisse return r; 32439f022ddfSJerome Glisse } 32449f022ddfSJerome Glisse r = r100_ib_test(rdev); 32459f022ddfSJerome Glisse if (r) { 32469f022ddfSJerome Glisse dev_err(rdev->dev, "failled testing IB (%d).\n", r); 32479f022ddfSJerome Glisse r100_ib_fini(rdev); 32489f022ddfSJerome Glisse return r; 32499f022ddfSJerome Glisse } 32509f022ddfSJerome Glisse return 0; 32519f022ddfSJerome Glisse } 32529f022ddfSJerome Glisse 32539f022ddfSJerome Glisse void r100_mc_stop(struct radeon_device *rdev, struct r100_mc_save *save) 32549f022ddfSJerome Glisse { 32559f022ddfSJerome Glisse /* Shutdown CP we shouldn't need to do that but better be safe than 32569f022ddfSJerome Glisse * sorry 32579f022ddfSJerome Glisse */ 32589f022ddfSJerome Glisse rdev->cp.ready = false; 32599f022ddfSJerome Glisse WREG32(R_000740_CP_CSQ_CNTL, 0); 32609f022ddfSJerome Glisse 32619f022ddfSJerome Glisse /* Save few CRTC registers */ 3262ca6ffc64SJerome Glisse save->GENMO_WT = RREG8(R_0003C2_GENMO_WT); 32639f022ddfSJerome Glisse save->CRTC_EXT_CNTL = RREG32(R_000054_CRTC_EXT_CNTL); 32649f022ddfSJerome Glisse save->CRTC_GEN_CNTL = RREG32(R_000050_CRTC_GEN_CNTL); 32659f022ddfSJerome Glisse save->CUR_OFFSET = RREG32(R_000260_CUR_OFFSET); 32669f022ddfSJerome Glisse if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 32679f022ddfSJerome Glisse save->CRTC2_GEN_CNTL = RREG32(R_0003F8_CRTC2_GEN_CNTL); 32689f022ddfSJerome Glisse save->CUR2_OFFSET = RREG32(R_000360_CUR2_OFFSET); 32699f022ddfSJerome Glisse } 32709f022ddfSJerome Glisse 32719f022ddfSJerome Glisse /* Disable VGA aperture access */ 3272ca6ffc64SJerome Glisse WREG8(R_0003C2_GENMO_WT, C_0003C2_VGA_RAM_EN & save->GENMO_WT); 32739f022ddfSJerome Glisse /* Disable cursor, overlay, crtc */ 32749f022ddfSJerome Glisse WREG32(R_000260_CUR_OFFSET, save->CUR_OFFSET | S_000260_CUR_LOCK(1)); 32759f022ddfSJerome Glisse WREG32(R_000054_CRTC_EXT_CNTL, save->CRTC_EXT_CNTL | 32769f022ddfSJerome Glisse S_000054_CRTC_DISPLAY_DIS(1)); 32779f022ddfSJerome Glisse WREG32(R_000050_CRTC_GEN_CNTL, 32789f022ddfSJerome Glisse (C_000050_CRTC_CUR_EN & save->CRTC_GEN_CNTL) | 32799f022ddfSJerome Glisse S_000050_CRTC_DISP_REQ_EN_B(1)); 32809f022ddfSJerome Glisse WREG32(R_000420_OV0_SCALE_CNTL, 32819f022ddfSJerome Glisse C_000420_OV0_OVERLAY_EN & RREG32(R_000420_OV0_SCALE_CNTL)); 32829f022ddfSJerome Glisse WREG32(R_000260_CUR_OFFSET, C_000260_CUR_LOCK & save->CUR_OFFSET); 32839f022ddfSJerome Glisse if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 32849f022ddfSJerome Glisse WREG32(R_000360_CUR2_OFFSET, save->CUR2_OFFSET | 32859f022ddfSJerome Glisse S_000360_CUR2_LOCK(1)); 32869f022ddfSJerome Glisse WREG32(R_0003F8_CRTC2_GEN_CNTL, 32879f022ddfSJerome Glisse (C_0003F8_CRTC2_CUR_EN & save->CRTC2_GEN_CNTL) | 32889f022ddfSJerome Glisse S_0003F8_CRTC2_DISPLAY_DIS(1) | 32899f022ddfSJerome Glisse S_0003F8_CRTC2_DISP_REQ_EN_B(1)); 32909f022ddfSJerome Glisse WREG32(R_000360_CUR2_OFFSET, 32919f022ddfSJerome Glisse C_000360_CUR2_LOCK & save->CUR2_OFFSET); 32929f022ddfSJerome Glisse } 32939f022ddfSJerome Glisse } 32949f022ddfSJerome Glisse 32959f022ddfSJerome Glisse void r100_mc_resume(struct radeon_device *rdev, struct r100_mc_save *save) 32969f022ddfSJerome Glisse { 32979f022ddfSJerome Glisse /* Update base address for crtc */ 3298d594e46aSJerome Glisse WREG32(R_00023C_DISPLAY_BASE_ADDR, rdev->mc.vram_start); 32999f022ddfSJerome Glisse if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 3300d594e46aSJerome Glisse WREG32(R_00033C_CRTC2_DISPLAY_BASE_ADDR, rdev->mc.vram_start); 33019f022ddfSJerome Glisse } 33029f022ddfSJerome Glisse /* Restore CRTC registers */ 3303ca6ffc64SJerome Glisse WREG8(R_0003C2_GENMO_WT, save->GENMO_WT); 33049f022ddfSJerome Glisse WREG32(R_000054_CRTC_EXT_CNTL, save->CRTC_EXT_CNTL); 33059f022ddfSJerome Glisse WREG32(R_000050_CRTC_GEN_CNTL, save->CRTC_GEN_CNTL); 33069f022ddfSJerome Glisse if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 33079f022ddfSJerome Glisse WREG32(R_0003F8_CRTC2_GEN_CNTL, save->CRTC2_GEN_CNTL); 33089f022ddfSJerome Glisse } 33099f022ddfSJerome Glisse } 3310ca6ffc64SJerome Glisse 3311ca6ffc64SJerome Glisse void r100_vga_render_disable(struct radeon_device *rdev) 3312ca6ffc64SJerome Glisse { 3313ca6ffc64SJerome Glisse u32 tmp; 3314ca6ffc64SJerome Glisse 3315ca6ffc64SJerome Glisse tmp = RREG8(R_0003C2_GENMO_WT); 3316ca6ffc64SJerome Glisse WREG8(R_0003C2_GENMO_WT, C_0003C2_VGA_RAM_EN & tmp); 3317ca6ffc64SJerome Glisse } 3318d4550907SJerome Glisse 3319d4550907SJerome Glisse static void r100_debugfs(struct radeon_device *rdev) 3320d4550907SJerome Glisse { 3321d4550907SJerome Glisse int r; 3322d4550907SJerome Glisse 3323d4550907SJerome Glisse r = r100_debugfs_mc_info_init(rdev); 3324d4550907SJerome Glisse if (r) 3325d4550907SJerome Glisse dev_warn(rdev->dev, "Failed to create r100_mc debugfs file.\n"); 3326d4550907SJerome Glisse } 3327d4550907SJerome Glisse 3328d4550907SJerome Glisse static void r100_mc_program(struct radeon_device *rdev) 3329d4550907SJerome Glisse { 3330d4550907SJerome Glisse struct r100_mc_save save; 3331d4550907SJerome Glisse 3332d4550907SJerome Glisse /* Stops all mc clients */ 3333d4550907SJerome Glisse r100_mc_stop(rdev, &save); 3334d4550907SJerome Glisse if (rdev->flags & RADEON_IS_AGP) { 3335d4550907SJerome Glisse WREG32(R_00014C_MC_AGP_LOCATION, 3336d4550907SJerome Glisse S_00014C_MC_AGP_START(rdev->mc.gtt_start >> 16) | 3337d4550907SJerome Glisse S_00014C_MC_AGP_TOP(rdev->mc.gtt_end >> 16)); 3338d4550907SJerome Glisse WREG32(R_000170_AGP_BASE, lower_32_bits(rdev->mc.agp_base)); 3339d4550907SJerome Glisse if (rdev->family > CHIP_RV200) 3340d4550907SJerome Glisse WREG32(R_00015C_AGP_BASE_2, 3341d4550907SJerome Glisse upper_32_bits(rdev->mc.agp_base) & 0xff); 3342d4550907SJerome Glisse } else { 3343d4550907SJerome Glisse WREG32(R_00014C_MC_AGP_LOCATION, 0x0FFFFFFF); 3344d4550907SJerome Glisse WREG32(R_000170_AGP_BASE, 0); 3345d4550907SJerome Glisse if (rdev->family > CHIP_RV200) 3346d4550907SJerome Glisse WREG32(R_00015C_AGP_BASE_2, 0); 3347d4550907SJerome Glisse } 3348d4550907SJerome Glisse /* Wait for mc idle */ 3349d4550907SJerome Glisse if (r100_mc_wait_for_idle(rdev)) 3350d4550907SJerome Glisse dev_warn(rdev->dev, "Wait for MC idle timeout.\n"); 3351d4550907SJerome Glisse /* Program MC, should be a 32bits limited address space */ 3352d4550907SJerome Glisse WREG32(R_000148_MC_FB_LOCATION, 3353d4550907SJerome Glisse S_000148_MC_FB_START(rdev->mc.vram_start >> 16) | 3354d4550907SJerome Glisse S_000148_MC_FB_TOP(rdev->mc.vram_end >> 16)); 3355d4550907SJerome Glisse r100_mc_resume(rdev, &save); 3356d4550907SJerome Glisse } 3357d4550907SJerome Glisse 3358d4550907SJerome Glisse void r100_clock_startup(struct radeon_device *rdev) 3359d4550907SJerome Glisse { 3360d4550907SJerome Glisse u32 tmp; 3361d4550907SJerome Glisse 3362d4550907SJerome Glisse if (radeon_dynclks != -1 && radeon_dynclks) 3363d4550907SJerome Glisse radeon_legacy_set_clock_gating(rdev, 1); 3364d4550907SJerome Glisse /* We need to force on some of the block */ 3365d4550907SJerome Glisse tmp = RREG32_PLL(R_00000D_SCLK_CNTL); 3366d4550907SJerome Glisse tmp |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1); 3367d4550907SJerome Glisse if ((rdev->family == CHIP_RV250) || (rdev->family == CHIP_RV280)) 3368d4550907SJerome Glisse tmp |= S_00000D_FORCE_DISP1(1) | S_00000D_FORCE_DISP2(1); 3369d4550907SJerome Glisse WREG32_PLL(R_00000D_SCLK_CNTL, tmp); 3370d4550907SJerome Glisse } 3371d4550907SJerome Glisse 3372d4550907SJerome Glisse static int r100_startup(struct radeon_device *rdev) 3373d4550907SJerome Glisse { 3374d4550907SJerome Glisse int r; 3375d4550907SJerome Glisse 337692cde00cSAlex Deucher /* set common regs */ 337792cde00cSAlex Deucher r100_set_common_regs(rdev); 337892cde00cSAlex Deucher /* program mc */ 3379d4550907SJerome Glisse r100_mc_program(rdev); 3380d4550907SJerome Glisse /* Resume clock */ 3381d4550907SJerome Glisse r100_clock_startup(rdev); 3382d4550907SJerome Glisse /* Initialize GPU configuration (# pipes, ...) */ 3383d4550907SJerome Glisse r100_gpu_init(rdev); 3384d4550907SJerome Glisse /* Initialize GART (initialize after TTM so we can allocate 3385d4550907SJerome Glisse * memory through TTM but finalize after TTM) */ 338617e15b0cSDave Airlie r100_enable_bm(rdev); 3387d4550907SJerome Glisse if (rdev->flags & RADEON_IS_PCI) { 3388d4550907SJerome Glisse r = r100_pci_gart_enable(rdev); 3389d4550907SJerome Glisse if (r) 3390d4550907SJerome Glisse return r; 3391d4550907SJerome Glisse } 3392d4550907SJerome Glisse /* Enable IRQ */ 3393d4550907SJerome Glisse r100_irq_set(rdev); 3394cafe6609SJerome Glisse rdev->config.r100.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL); 3395d4550907SJerome Glisse /* 1M ring buffer */ 3396d4550907SJerome Glisse r = r100_cp_init(rdev, 1024 * 1024); 3397d4550907SJerome Glisse if (r) { 3398d4550907SJerome Glisse dev_err(rdev->dev, "failled initializing CP (%d).\n", r); 3399d4550907SJerome Glisse return r; 3400d4550907SJerome Glisse } 3401d4550907SJerome Glisse r = r100_wb_init(rdev); 3402d4550907SJerome Glisse if (r) 3403d4550907SJerome Glisse dev_err(rdev->dev, "failled initializing WB (%d).\n", r); 3404d4550907SJerome Glisse r = r100_ib_init(rdev); 3405d4550907SJerome Glisse if (r) { 3406d4550907SJerome Glisse dev_err(rdev->dev, "failled initializing IB (%d).\n", r); 3407d4550907SJerome Glisse return r; 3408d4550907SJerome Glisse } 3409d4550907SJerome Glisse return 0; 3410d4550907SJerome Glisse } 3411d4550907SJerome Glisse 3412d4550907SJerome Glisse int r100_resume(struct radeon_device *rdev) 3413d4550907SJerome Glisse { 3414d4550907SJerome Glisse /* Make sur GART are not working */ 3415d4550907SJerome Glisse if (rdev->flags & RADEON_IS_PCI) 3416d4550907SJerome Glisse r100_pci_gart_disable(rdev); 3417d4550907SJerome Glisse /* Resume clock before doing reset */ 3418d4550907SJerome Glisse r100_clock_startup(rdev); 3419d4550907SJerome Glisse /* Reset gpu before posting otherwise ATOM will enter infinite loop */ 3420d4550907SJerome Glisse if (radeon_gpu_reset(rdev)) { 3421d4550907SJerome Glisse dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", 3422d4550907SJerome Glisse RREG32(R_000E40_RBBM_STATUS), 3423d4550907SJerome Glisse RREG32(R_0007C0_CP_STAT)); 3424d4550907SJerome Glisse } 3425d4550907SJerome Glisse /* post */ 3426d4550907SJerome Glisse radeon_combios_asic_init(rdev->ddev); 3427d4550907SJerome Glisse /* Resume clock after posting */ 3428d4550907SJerome Glisse r100_clock_startup(rdev); 3429550e2d92SDave Airlie /* Initialize surface registers */ 3430550e2d92SDave Airlie radeon_surface_init(rdev); 3431d4550907SJerome Glisse return r100_startup(rdev); 3432d4550907SJerome Glisse } 3433d4550907SJerome Glisse 3434d4550907SJerome Glisse int r100_suspend(struct radeon_device *rdev) 3435d4550907SJerome Glisse { 3436d4550907SJerome Glisse r100_cp_disable(rdev); 3437d4550907SJerome Glisse r100_wb_disable(rdev); 3438d4550907SJerome Glisse r100_irq_disable(rdev); 3439d4550907SJerome Glisse if (rdev->flags & RADEON_IS_PCI) 3440d4550907SJerome Glisse r100_pci_gart_disable(rdev); 3441d4550907SJerome Glisse return 0; 3442d4550907SJerome Glisse } 3443d4550907SJerome Glisse 3444d4550907SJerome Glisse void r100_fini(struct radeon_device *rdev) 3445d4550907SJerome Glisse { 344629fb52caSAlex Deucher radeon_pm_fini(rdev); 3447d4550907SJerome Glisse r100_cp_fini(rdev); 3448d4550907SJerome Glisse r100_wb_fini(rdev); 3449d4550907SJerome Glisse r100_ib_fini(rdev); 3450d4550907SJerome Glisse radeon_gem_fini(rdev); 3451d4550907SJerome Glisse if (rdev->flags & RADEON_IS_PCI) 3452d4550907SJerome Glisse r100_pci_gart_fini(rdev); 3453d0269ed8SJerome Glisse radeon_agp_fini(rdev); 3454d4550907SJerome Glisse radeon_irq_kms_fini(rdev); 3455d4550907SJerome Glisse radeon_fence_driver_fini(rdev); 34564c788679SJerome Glisse radeon_bo_fini(rdev); 3457d4550907SJerome Glisse radeon_atombios_fini(rdev); 3458d4550907SJerome Glisse kfree(rdev->bios); 3459d4550907SJerome Glisse rdev->bios = NULL; 3460d4550907SJerome Glisse } 3461d4550907SJerome Glisse 3462d4550907SJerome Glisse int r100_init(struct radeon_device *rdev) 3463d4550907SJerome Glisse { 3464d4550907SJerome Glisse int r; 3465d4550907SJerome Glisse 3466d4550907SJerome Glisse /* Register debugfs file specific to this group of asics */ 3467d4550907SJerome Glisse r100_debugfs(rdev); 3468d4550907SJerome Glisse /* Disable VGA */ 3469d4550907SJerome Glisse r100_vga_render_disable(rdev); 3470d4550907SJerome Glisse /* Initialize scratch registers */ 3471d4550907SJerome Glisse radeon_scratch_init(rdev); 3472d4550907SJerome Glisse /* Initialize surface registers */ 3473d4550907SJerome Glisse radeon_surface_init(rdev); 3474d4550907SJerome Glisse /* TODO: disable VGA need to use VGA request */ 3475d4550907SJerome Glisse /* BIOS*/ 3476d4550907SJerome Glisse if (!radeon_get_bios(rdev)) { 3477d4550907SJerome Glisse if (ASIC_IS_AVIVO(rdev)) 3478d4550907SJerome Glisse return -EINVAL; 3479d4550907SJerome Glisse } 3480d4550907SJerome Glisse if (rdev->is_atom_bios) { 3481d4550907SJerome Glisse dev_err(rdev->dev, "Expecting combios for RS400/RS480 GPU\n"); 3482d4550907SJerome Glisse return -EINVAL; 3483d4550907SJerome Glisse } else { 3484d4550907SJerome Glisse r = radeon_combios_init(rdev); 3485d4550907SJerome Glisse if (r) 3486d4550907SJerome Glisse return r; 3487d4550907SJerome Glisse } 3488d4550907SJerome Glisse /* Reset gpu before posting otherwise ATOM will enter infinite loop */ 3489d4550907SJerome Glisse if (radeon_gpu_reset(rdev)) { 3490d4550907SJerome Glisse dev_warn(rdev->dev, 3491d4550907SJerome Glisse "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", 3492d4550907SJerome Glisse RREG32(R_000E40_RBBM_STATUS), 3493d4550907SJerome Glisse RREG32(R_0007C0_CP_STAT)); 3494d4550907SJerome Glisse } 3495d4550907SJerome Glisse /* check if cards are posted or not */ 349672542d77SDave Airlie if (radeon_boot_test_post_card(rdev) == false) 349772542d77SDave Airlie return -EINVAL; 3498d4550907SJerome Glisse /* Set asic errata */ 3499d4550907SJerome Glisse r100_errata(rdev); 3500d4550907SJerome Glisse /* Initialize clocks */ 3501d4550907SJerome Glisse radeon_get_clock_info(rdev->ddev); 35026234077dSRafał Miłecki /* Initialize power management */ 35036234077dSRafał Miłecki radeon_pm_init(rdev); 3504d594e46aSJerome Glisse /* initialize AGP */ 3505d594e46aSJerome Glisse if (rdev->flags & RADEON_IS_AGP) { 3506d594e46aSJerome Glisse r = radeon_agp_init(rdev); 3507d594e46aSJerome Glisse if (r) { 3508d594e46aSJerome Glisse radeon_agp_disable(rdev); 3509d594e46aSJerome Glisse } 3510d594e46aSJerome Glisse } 3511d594e46aSJerome Glisse /* initialize VRAM */ 3512d594e46aSJerome Glisse r100_mc_init(rdev); 3513d4550907SJerome Glisse /* Fence driver */ 3514d4550907SJerome Glisse r = radeon_fence_driver_init(rdev); 3515d4550907SJerome Glisse if (r) 3516d4550907SJerome Glisse return r; 3517d4550907SJerome Glisse r = radeon_irq_kms_init(rdev); 3518d4550907SJerome Glisse if (r) 3519d4550907SJerome Glisse return r; 3520d4550907SJerome Glisse /* Memory manager */ 35214c788679SJerome Glisse r = radeon_bo_init(rdev); 3522d4550907SJerome Glisse if (r) 3523d4550907SJerome Glisse return r; 3524d4550907SJerome Glisse if (rdev->flags & RADEON_IS_PCI) { 3525d4550907SJerome Glisse r = r100_pci_gart_init(rdev); 3526d4550907SJerome Glisse if (r) 3527d4550907SJerome Glisse return r; 3528d4550907SJerome Glisse } 3529d4550907SJerome Glisse r100_set_safe_registers(rdev); 3530d4550907SJerome Glisse rdev->accel_working = true; 3531d4550907SJerome Glisse r = r100_startup(rdev); 3532d4550907SJerome Glisse if (r) { 3533d4550907SJerome Glisse /* Somethings want wront with the accel init stop accel */ 3534d4550907SJerome Glisse dev_err(rdev->dev, "Disabling GPU acceleration\n"); 3535d4550907SJerome Glisse r100_cp_fini(rdev); 3536d4550907SJerome Glisse r100_wb_fini(rdev); 3537d4550907SJerome Glisse r100_ib_fini(rdev); 3538655efd3dSJerome Glisse radeon_irq_kms_fini(rdev); 3539d4550907SJerome Glisse if (rdev->flags & RADEON_IS_PCI) 3540d4550907SJerome Glisse r100_pci_gart_fini(rdev); 3541d4550907SJerome Glisse rdev->accel_working = false; 3542d4550907SJerome Glisse } 3543d4550907SJerome Glisse return 0; 3544d4550907SJerome Glisse } 3545