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/console.h> 29771fe6b9SJerome Glisse #include <drm/drmP.h> 30771fe6b9SJerome Glisse #include <drm/drm_crtc_helper.h> 31771fe6b9SJerome Glisse #include <drm/radeon_drm.h> 32*28d52043SDave Airlie #include <linux/vgaarb.h> 33771fe6b9SJerome Glisse #include "radeon_reg.h" 34771fe6b9SJerome Glisse #include "radeon.h" 35771fe6b9SJerome Glisse #include "radeon_asic.h" 36771fe6b9SJerome Glisse #include "atom.h" 37771fe6b9SJerome Glisse 38771fe6b9SJerome Glisse /* 39b1e3a6d1SMichel Dänzer * Clear GPU surface registers. 40b1e3a6d1SMichel Dänzer */ 413ce0a23dSJerome Glisse void radeon_surface_init(struct radeon_device *rdev) 42b1e3a6d1SMichel Dänzer { 43b1e3a6d1SMichel Dänzer /* FIXME: check this out */ 44b1e3a6d1SMichel Dänzer if (rdev->family < CHIP_R600) { 45b1e3a6d1SMichel Dänzer int i; 46b1e3a6d1SMichel Dänzer 47b1e3a6d1SMichel Dänzer for (i = 0; i < 8; i++) { 48b1e3a6d1SMichel Dänzer WREG32(RADEON_SURFACE0_INFO + 49b1e3a6d1SMichel Dänzer i * (RADEON_SURFACE1_INFO - RADEON_SURFACE0_INFO), 50b1e3a6d1SMichel Dänzer 0); 51b1e3a6d1SMichel Dänzer } 52e024e110SDave Airlie /* enable surfaces */ 53e024e110SDave Airlie WREG32(RADEON_SURFACE_CNTL, 0); 54b1e3a6d1SMichel Dänzer } 55b1e3a6d1SMichel Dänzer } 56b1e3a6d1SMichel Dänzer 57b1e3a6d1SMichel Dänzer /* 58771fe6b9SJerome Glisse * GPU scratch registers helpers function. 59771fe6b9SJerome Glisse */ 603ce0a23dSJerome Glisse void radeon_scratch_init(struct radeon_device *rdev) 61771fe6b9SJerome Glisse { 62771fe6b9SJerome Glisse int i; 63771fe6b9SJerome Glisse 64771fe6b9SJerome Glisse /* FIXME: check this out */ 65771fe6b9SJerome Glisse if (rdev->family < CHIP_R300) { 66771fe6b9SJerome Glisse rdev->scratch.num_reg = 5; 67771fe6b9SJerome Glisse } else { 68771fe6b9SJerome Glisse rdev->scratch.num_reg = 7; 69771fe6b9SJerome Glisse } 70771fe6b9SJerome Glisse for (i = 0; i < rdev->scratch.num_reg; i++) { 71771fe6b9SJerome Glisse rdev->scratch.free[i] = true; 72771fe6b9SJerome Glisse rdev->scratch.reg[i] = RADEON_SCRATCH_REG0 + (i * 4); 73771fe6b9SJerome Glisse } 74771fe6b9SJerome Glisse } 75771fe6b9SJerome Glisse 76771fe6b9SJerome Glisse int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg) 77771fe6b9SJerome Glisse { 78771fe6b9SJerome Glisse int i; 79771fe6b9SJerome Glisse 80771fe6b9SJerome Glisse for (i = 0; i < rdev->scratch.num_reg; i++) { 81771fe6b9SJerome Glisse if (rdev->scratch.free[i]) { 82771fe6b9SJerome Glisse rdev->scratch.free[i] = false; 83771fe6b9SJerome Glisse *reg = rdev->scratch.reg[i]; 84771fe6b9SJerome Glisse return 0; 85771fe6b9SJerome Glisse } 86771fe6b9SJerome Glisse } 87771fe6b9SJerome Glisse return -EINVAL; 88771fe6b9SJerome Glisse } 89771fe6b9SJerome Glisse 90771fe6b9SJerome Glisse void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg) 91771fe6b9SJerome Glisse { 92771fe6b9SJerome Glisse int i; 93771fe6b9SJerome Glisse 94771fe6b9SJerome Glisse for (i = 0; i < rdev->scratch.num_reg; i++) { 95771fe6b9SJerome Glisse if (rdev->scratch.reg[i] == reg) { 96771fe6b9SJerome Glisse rdev->scratch.free[i] = true; 97771fe6b9SJerome Glisse return; 98771fe6b9SJerome Glisse } 99771fe6b9SJerome Glisse } 100771fe6b9SJerome Glisse } 101771fe6b9SJerome Glisse 102771fe6b9SJerome Glisse /* 103771fe6b9SJerome Glisse * MC common functions 104771fe6b9SJerome Glisse */ 105771fe6b9SJerome Glisse int radeon_mc_setup(struct radeon_device *rdev) 106771fe6b9SJerome Glisse { 107771fe6b9SJerome Glisse uint32_t tmp; 108771fe6b9SJerome Glisse 109771fe6b9SJerome Glisse /* Some chips have an "issue" with the memory controller, the 110771fe6b9SJerome Glisse * location must be aligned to the size. We just align it down, 111771fe6b9SJerome Glisse * too bad if we walk over the top of system memory, we don't 112771fe6b9SJerome Glisse * use DMA without a remapped anyway. 113771fe6b9SJerome Glisse * Affected chips are rv280, all r3xx, and all r4xx, but not IGP 114771fe6b9SJerome Glisse */ 115771fe6b9SJerome Glisse /* FGLRX seems to setup like this, VRAM a 0, then GART. 116771fe6b9SJerome Glisse */ 117771fe6b9SJerome Glisse /* 118771fe6b9SJerome Glisse * Note: from R6xx the address space is 40bits but here we only 119771fe6b9SJerome Glisse * use 32bits (still have to see a card which would exhaust 4G 120771fe6b9SJerome Glisse * address space). 121771fe6b9SJerome Glisse */ 122771fe6b9SJerome Glisse if (rdev->mc.vram_location != 0xFFFFFFFFUL) { 123771fe6b9SJerome Glisse /* vram location was already setup try to put gtt after 124771fe6b9SJerome Glisse * if it fits */ 1257a50f01aSDave Airlie tmp = rdev->mc.vram_location + rdev->mc.mc_vram_size; 126771fe6b9SJerome Glisse tmp = (tmp + rdev->mc.gtt_size - 1) & ~(rdev->mc.gtt_size - 1); 127771fe6b9SJerome Glisse if ((0xFFFFFFFFUL - tmp) >= rdev->mc.gtt_size) { 128771fe6b9SJerome Glisse rdev->mc.gtt_location = tmp; 129771fe6b9SJerome Glisse } else { 130771fe6b9SJerome Glisse if (rdev->mc.gtt_size >= rdev->mc.vram_location) { 131771fe6b9SJerome Glisse printk(KERN_ERR "[drm] GTT too big to fit " 132771fe6b9SJerome Glisse "before or after vram location.\n"); 133771fe6b9SJerome Glisse return -EINVAL; 134771fe6b9SJerome Glisse } 135771fe6b9SJerome Glisse rdev->mc.gtt_location = 0; 136771fe6b9SJerome Glisse } 137771fe6b9SJerome Glisse } else if (rdev->mc.gtt_location != 0xFFFFFFFFUL) { 138771fe6b9SJerome Glisse /* gtt location was already setup try to put vram before 139771fe6b9SJerome Glisse * if it fits */ 1407a50f01aSDave Airlie if (rdev->mc.mc_vram_size < rdev->mc.gtt_location) { 141771fe6b9SJerome Glisse rdev->mc.vram_location = 0; 142771fe6b9SJerome Glisse } else { 143771fe6b9SJerome Glisse tmp = rdev->mc.gtt_location + rdev->mc.gtt_size; 1447a50f01aSDave Airlie tmp += (rdev->mc.mc_vram_size - 1); 1457a50f01aSDave Airlie tmp &= ~(rdev->mc.mc_vram_size - 1); 1467a50f01aSDave Airlie if ((0xFFFFFFFFUL - tmp) >= rdev->mc.mc_vram_size) { 147771fe6b9SJerome Glisse rdev->mc.vram_location = tmp; 148771fe6b9SJerome Glisse } else { 149771fe6b9SJerome Glisse printk(KERN_ERR "[drm] vram too big to fit " 150771fe6b9SJerome Glisse "before or after GTT location.\n"); 151771fe6b9SJerome Glisse return -EINVAL; 152771fe6b9SJerome Glisse } 153771fe6b9SJerome Glisse } 154771fe6b9SJerome Glisse } else { 155771fe6b9SJerome Glisse rdev->mc.vram_location = 0; 15617332925SDave Airlie tmp = rdev->mc.mc_vram_size; 15717332925SDave Airlie tmp = (tmp + rdev->mc.gtt_size - 1) & ~(rdev->mc.gtt_size - 1); 15817332925SDave Airlie rdev->mc.gtt_location = tmp; 159771fe6b9SJerome Glisse } 1609f022ddfSJerome Glisse rdev->mc.vram_start = rdev->mc.vram_location; 1619f022ddfSJerome Glisse rdev->mc.vram_end = rdev->mc.vram_location + rdev->mc.mc_vram_size - 1; 1629f022ddfSJerome Glisse rdev->mc.gtt_start = rdev->mc.gtt_location; 1639f022ddfSJerome Glisse rdev->mc.gtt_end = rdev->mc.gtt_location + rdev->mc.gtt_size - 1; 1643ce0a23dSJerome Glisse DRM_INFO("radeon: VRAM %uM\n", (unsigned)(rdev->mc.mc_vram_size >> 20)); 165771fe6b9SJerome Glisse DRM_INFO("radeon: VRAM from 0x%08X to 0x%08X\n", 1663ce0a23dSJerome Glisse (unsigned)rdev->mc.vram_location, 1673ce0a23dSJerome Glisse (unsigned)(rdev->mc.vram_location + rdev->mc.mc_vram_size - 1)); 1683ce0a23dSJerome Glisse DRM_INFO("radeon: GTT %uM\n", (unsigned)(rdev->mc.gtt_size >> 20)); 169771fe6b9SJerome Glisse DRM_INFO("radeon: GTT from 0x%08X to 0x%08X\n", 1703ce0a23dSJerome Glisse (unsigned)rdev->mc.gtt_location, 1713ce0a23dSJerome Glisse (unsigned)(rdev->mc.gtt_location + rdev->mc.gtt_size - 1)); 172771fe6b9SJerome Glisse return 0; 173771fe6b9SJerome Glisse } 174771fe6b9SJerome Glisse 175771fe6b9SJerome Glisse 176771fe6b9SJerome Glisse /* 177771fe6b9SJerome Glisse * GPU helpers function. 178771fe6b9SJerome Glisse */ 1799f022ddfSJerome Glisse bool radeon_card_posted(struct radeon_device *rdev) 180771fe6b9SJerome Glisse { 181771fe6b9SJerome Glisse uint32_t reg; 182771fe6b9SJerome Glisse 183771fe6b9SJerome Glisse /* first check CRTCs */ 184771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev)) { 185771fe6b9SJerome Glisse reg = RREG32(AVIVO_D1CRTC_CONTROL) | 186771fe6b9SJerome Glisse RREG32(AVIVO_D2CRTC_CONTROL); 187771fe6b9SJerome Glisse if (reg & AVIVO_CRTC_EN) { 188771fe6b9SJerome Glisse return true; 189771fe6b9SJerome Glisse } 190771fe6b9SJerome Glisse } else { 191771fe6b9SJerome Glisse reg = RREG32(RADEON_CRTC_GEN_CNTL) | 192771fe6b9SJerome Glisse RREG32(RADEON_CRTC2_GEN_CNTL); 193771fe6b9SJerome Glisse if (reg & RADEON_CRTC_EN) { 194771fe6b9SJerome Glisse return true; 195771fe6b9SJerome Glisse } 196771fe6b9SJerome Glisse } 197771fe6b9SJerome Glisse 198771fe6b9SJerome Glisse /* then check MEM_SIZE, in case the crtcs are off */ 199771fe6b9SJerome Glisse if (rdev->family >= CHIP_R600) 200771fe6b9SJerome Glisse reg = RREG32(R600_CONFIG_MEMSIZE); 201771fe6b9SJerome Glisse else 202771fe6b9SJerome Glisse reg = RREG32(RADEON_CONFIG_MEMSIZE); 203771fe6b9SJerome Glisse 204771fe6b9SJerome Glisse if (reg) 205771fe6b9SJerome Glisse return true; 206771fe6b9SJerome Glisse 207771fe6b9SJerome Glisse return false; 208771fe6b9SJerome Glisse 209771fe6b9SJerome Glisse } 210771fe6b9SJerome Glisse 2113ce0a23dSJerome Glisse int radeon_dummy_page_init(struct radeon_device *rdev) 2123ce0a23dSJerome Glisse { 2133ce0a23dSJerome Glisse rdev->dummy_page.page = alloc_page(GFP_DMA32 | GFP_KERNEL | __GFP_ZERO); 2143ce0a23dSJerome Glisse if (rdev->dummy_page.page == NULL) 2153ce0a23dSJerome Glisse return -ENOMEM; 2163ce0a23dSJerome Glisse rdev->dummy_page.addr = pci_map_page(rdev->pdev, rdev->dummy_page.page, 2173ce0a23dSJerome Glisse 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 2183ce0a23dSJerome Glisse if (!rdev->dummy_page.addr) { 2193ce0a23dSJerome Glisse __free_page(rdev->dummy_page.page); 2203ce0a23dSJerome Glisse rdev->dummy_page.page = NULL; 2213ce0a23dSJerome Glisse return -ENOMEM; 2223ce0a23dSJerome Glisse } 2233ce0a23dSJerome Glisse return 0; 2243ce0a23dSJerome Glisse } 2253ce0a23dSJerome Glisse 2263ce0a23dSJerome Glisse void radeon_dummy_page_fini(struct radeon_device *rdev) 2273ce0a23dSJerome Glisse { 2283ce0a23dSJerome Glisse if (rdev->dummy_page.page == NULL) 2293ce0a23dSJerome Glisse return; 2303ce0a23dSJerome Glisse pci_unmap_page(rdev->pdev, rdev->dummy_page.addr, 2313ce0a23dSJerome Glisse PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 2323ce0a23dSJerome Glisse __free_page(rdev->dummy_page.page); 2333ce0a23dSJerome Glisse rdev->dummy_page.page = NULL; 2343ce0a23dSJerome Glisse } 2353ce0a23dSJerome Glisse 236771fe6b9SJerome Glisse 237771fe6b9SJerome Glisse /* 238771fe6b9SJerome Glisse * Registers accessors functions. 239771fe6b9SJerome Glisse */ 240771fe6b9SJerome Glisse uint32_t radeon_invalid_rreg(struct radeon_device *rdev, uint32_t reg) 241771fe6b9SJerome Glisse { 242771fe6b9SJerome Glisse DRM_ERROR("Invalid callback to read register 0x%04X\n", reg); 243771fe6b9SJerome Glisse BUG_ON(1); 244771fe6b9SJerome Glisse return 0; 245771fe6b9SJerome Glisse } 246771fe6b9SJerome Glisse 247771fe6b9SJerome Glisse void radeon_invalid_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v) 248771fe6b9SJerome Glisse { 249771fe6b9SJerome Glisse DRM_ERROR("Invalid callback to write register 0x%04X with 0x%08X\n", 250771fe6b9SJerome Glisse reg, v); 251771fe6b9SJerome Glisse BUG_ON(1); 252771fe6b9SJerome Glisse } 253771fe6b9SJerome Glisse 254771fe6b9SJerome Glisse void radeon_register_accessor_init(struct radeon_device *rdev) 255771fe6b9SJerome Glisse { 256771fe6b9SJerome Glisse rdev->mc_rreg = &radeon_invalid_rreg; 257771fe6b9SJerome Glisse rdev->mc_wreg = &radeon_invalid_wreg; 258771fe6b9SJerome Glisse rdev->pll_rreg = &radeon_invalid_rreg; 259771fe6b9SJerome Glisse rdev->pll_wreg = &radeon_invalid_wreg; 260771fe6b9SJerome Glisse rdev->pciep_rreg = &radeon_invalid_rreg; 261771fe6b9SJerome Glisse rdev->pciep_wreg = &radeon_invalid_wreg; 262771fe6b9SJerome Glisse 263771fe6b9SJerome Glisse /* Don't change order as we are overridding accessor. */ 264771fe6b9SJerome Glisse if (rdev->family < CHIP_RV515) { 265de1b2898SDave Airlie rdev->pcie_reg_mask = 0xff; 266de1b2898SDave Airlie } else { 267de1b2898SDave Airlie rdev->pcie_reg_mask = 0x7ff; 268771fe6b9SJerome Glisse } 269771fe6b9SJerome Glisse /* FIXME: not sure here */ 270771fe6b9SJerome Glisse if (rdev->family <= CHIP_R580) { 271771fe6b9SJerome Glisse rdev->pll_rreg = &r100_pll_rreg; 272771fe6b9SJerome Glisse rdev->pll_wreg = &r100_pll_wreg; 273771fe6b9SJerome Glisse } 274905b6822SJerome Glisse if (rdev->family >= CHIP_R420) { 275905b6822SJerome Glisse rdev->mc_rreg = &r420_mc_rreg; 276905b6822SJerome Glisse rdev->mc_wreg = &r420_mc_wreg; 277905b6822SJerome Glisse } 278771fe6b9SJerome Glisse if (rdev->family >= CHIP_RV515) { 279771fe6b9SJerome Glisse rdev->mc_rreg = &rv515_mc_rreg; 280771fe6b9SJerome Glisse rdev->mc_wreg = &rv515_mc_wreg; 281771fe6b9SJerome Glisse } 282771fe6b9SJerome Glisse if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480) { 283771fe6b9SJerome Glisse rdev->mc_rreg = &rs400_mc_rreg; 284771fe6b9SJerome Glisse rdev->mc_wreg = &rs400_mc_wreg; 285771fe6b9SJerome Glisse } 286771fe6b9SJerome Glisse if (rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) { 287771fe6b9SJerome Glisse rdev->mc_rreg = &rs690_mc_rreg; 288771fe6b9SJerome Glisse rdev->mc_wreg = &rs690_mc_wreg; 289771fe6b9SJerome Glisse } 290771fe6b9SJerome Glisse if (rdev->family == CHIP_RS600) { 291771fe6b9SJerome Glisse rdev->mc_rreg = &rs600_mc_rreg; 292771fe6b9SJerome Glisse rdev->mc_wreg = &rs600_mc_wreg; 293771fe6b9SJerome Glisse } 294771fe6b9SJerome Glisse if (rdev->family >= CHIP_R600) { 295771fe6b9SJerome Glisse rdev->pciep_rreg = &r600_pciep_rreg; 296771fe6b9SJerome Glisse rdev->pciep_wreg = &r600_pciep_wreg; 297771fe6b9SJerome Glisse } 298771fe6b9SJerome Glisse } 299771fe6b9SJerome Glisse 300771fe6b9SJerome Glisse 301771fe6b9SJerome Glisse /* 302771fe6b9SJerome Glisse * ASIC 303771fe6b9SJerome Glisse */ 304771fe6b9SJerome Glisse int radeon_asic_init(struct radeon_device *rdev) 305771fe6b9SJerome Glisse { 306771fe6b9SJerome Glisse radeon_register_accessor_init(rdev); 307771fe6b9SJerome Glisse switch (rdev->family) { 308771fe6b9SJerome Glisse case CHIP_R100: 309771fe6b9SJerome Glisse case CHIP_RV100: 310771fe6b9SJerome Glisse case CHIP_RS100: 311771fe6b9SJerome Glisse case CHIP_RV200: 312771fe6b9SJerome Glisse case CHIP_RS200: 313771fe6b9SJerome Glisse case CHIP_R200: 314771fe6b9SJerome Glisse case CHIP_RV250: 315771fe6b9SJerome Glisse case CHIP_RS300: 316771fe6b9SJerome Glisse case CHIP_RV280: 317771fe6b9SJerome Glisse rdev->asic = &r100_asic; 318771fe6b9SJerome Glisse break; 319771fe6b9SJerome Glisse case CHIP_R300: 320771fe6b9SJerome Glisse case CHIP_R350: 321771fe6b9SJerome Glisse case CHIP_RV350: 322771fe6b9SJerome Glisse case CHIP_RV380: 323771fe6b9SJerome Glisse rdev->asic = &r300_asic; 3244aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCIE) { 3254aac0473SJerome Glisse rdev->asic->gart_init = &rv370_pcie_gart_init; 3264aac0473SJerome Glisse rdev->asic->gart_fini = &rv370_pcie_gart_fini; 3274aac0473SJerome Glisse rdev->asic->gart_enable = &rv370_pcie_gart_enable; 3284aac0473SJerome Glisse rdev->asic->gart_disable = &rv370_pcie_gart_disable; 3294aac0473SJerome Glisse rdev->asic->gart_tlb_flush = &rv370_pcie_gart_tlb_flush; 3304aac0473SJerome Glisse rdev->asic->gart_set_page = &rv370_pcie_gart_set_page; 3314aac0473SJerome Glisse } 332771fe6b9SJerome Glisse break; 333771fe6b9SJerome Glisse case CHIP_R420: 334771fe6b9SJerome Glisse case CHIP_R423: 335771fe6b9SJerome Glisse case CHIP_RV410: 336771fe6b9SJerome Glisse rdev->asic = &r420_asic; 337771fe6b9SJerome Glisse break; 338771fe6b9SJerome Glisse case CHIP_RS400: 339771fe6b9SJerome Glisse case CHIP_RS480: 340771fe6b9SJerome Glisse rdev->asic = &rs400_asic; 341771fe6b9SJerome Glisse break; 342771fe6b9SJerome Glisse case CHIP_RS600: 343771fe6b9SJerome Glisse rdev->asic = &rs600_asic; 344771fe6b9SJerome Glisse break; 345771fe6b9SJerome Glisse case CHIP_RS690: 346771fe6b9SJerome Glisse case CHIP_RS740: 347771fe6b9SJerome Glisse rdev->asic = &rs690_asic; 348771fe6b9SJerome Glisse break; 349771fe6b9SJerome Glisse case CHIP_RV515: 350771fe6b9SJerome Glisse rdev->asic = &rv515_asic; 351771fe6b9SJerome Glisse break; 352771fe6b9SJerome Glisse case CHIP_R520: 353771fe6b9SJerome Glisse case CHIP_RV530: 354771fe6b9SJerome Glisse case CHIP_RV560: 355771fe6b9SJerome Glisse case CHIP_RV570: 356771fe6b9SJerome Glisse case CHIP_R580: 357771fe6b9SJerome Glisse rdev->asic = &r520_asic; 358771fe6b9SJerome Glisse break; 359771fe6b9SJerome Glisse case CHIP_R600: 360771fe6b9SJerome Glisse case CHIP_RV610: 361771fe6b9SJerome Glisse case CHIP_RV630: 362771fe6b9SJerome Glisse case CHIP_RV620: 363771fe6b9SJerome Glisse case CHIP_RV635: 364771fe6b9SJerome Glisse case CHIP_RV670: 365771fe6b9SJerome Glisse case CHIP_RS780: 3663ce0a23dSJerome Glisse case CHIP_RS880: 3673ce0a23dSJerome Glisse rdev->asic = &r600_asic; 3683ce0a23dSJerome Glisse break; 369771fe6b9SJerome Glisse case CHIP_RV770: 370771fe6b9SJerome Glisse case CHIP_RV730: 371771fe6b9SJerome Glisse case CHIP_RV710: 3723ce0a23dSJerome Glisse case CHIP_RV740: 3733ce0a23dSJerome Glisse rdev->asic = &rv770_asic; 3743ce0a23dSJerome Glisse break; 375771fe6b9SJerome Glisse default: 376771fe6b9SJerome Glisse /* FIXME: not supported yet */ 377771fe6b9SJerome Glisse return -EINVAL; 378771fe6b9SJerome Glisse } 379771fe6b9SJerome Glisse return 0; 380771fe6b9SJerome Glisse } 381771fe6b9SJerome Glisse 382771fe6b9SJerome Glisse 383771fe6b9SJerome Glisse /* 384771fe6b9SJerome Glisse * Wrapper around modesetting bits. 385771fe6b9SJerome Glisse */ 386771fe6b9SJerome Glisse int radeon_clocks_init(struct radeon_device *rdev) 387771fe6b9SJerome Glisse { 388771fe6b9SJerome Glisse int r; 389771fe6b9SJerome Glisse 390771fe6b9SJerome Glisse r = radeon_static_clocks_init(rdev->ddev); 391771fe6b9SJerome Glisse if (r) { 392771fe6b9SJerome Glisse return r; 393771fe6b9SJerome Glisse } 394771fe6b9SJerome Glisse DRM_INFO("Clocks initialized !\n"); 395771fe6b9SJerome Glisse return 0; 396771fe6b9SJerome Glisse } 397771fe6b9SJerome Glisse 398771fe6b9SJerome Glisse void radeon_clocks_fini(struct radeon_device *rdev) 399771fe6b9SJerome Glisse { 400771fe6b9SJerome Glisse } 401771fe6b9SJerome Glisse 402771fe6b9SJerome Glisse /* ATOM accessor methods */ 403771fe6b9SJerome Glisse static uint32_t cail_pll_read(struct card_info *info, uint32_t reg) 404771fe6b9SJerome Glisse { 405771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 406771fe6b9SJerome Glisse uint32_t r; 407771fe6b9SJerome Glisse 408771fe6b9SJerome Glisse r = rdev->pll_rreg(rdev, reg); 409771fe6b9SJerome Glisse return r; 410771fe6b9SJerome Glisse } 411771fe6b9SJerome Glisse 412771fe6b9SJerome Glisse static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val) 413771fe6b9SJerome Glisse { 414771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 415771fe6b9SJerome Glisse 416771fe6b9SJerome Glisse rdev->pll_wreg(rdev, reg, val); 417771fe6b9SJerome Glisse } 418771fe6b9SJerome Glisse 419771fe6b9SJerome Glisse static uint32_t cail_mc_read(struct card_info *info, uint32_t reg) 420771fe6b9SJerome Glisse { 421771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 422771fe6b9SJerome Glisse uint32_t r; 423771fe6b9SJerome Glisse 424771fe6b9SJerome Glisse r = rdev->mc_rreg(rdev, reg); 425771fe6b9SJerome Glisse return r; 426771fe6b9SJerome Glisse } 427771fe6b9SJerome Glisse 428771fe6b9SJerome Glisse static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val) 429771fe6b9SJerome Glisse { 430771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 431771fe6b9SJerome Glisse 432771fe6b9SJerome Glisse rdev->mc_wreg(rdev, reg, val); 433771fe6b9SJerome Glisse } 434771fe6b9SJerome Glisse 435771fe6b9SJerome Glisse static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val) 436771fe6b9SJerome Glisse { 437771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 438771fe6b9SJerome Glisse 439771fe6b9SJerome Glisse WREG32(reg*4, val); 440771fe6b9SJerome Glisse } 441771fe6b9SJerome Glisse 442771fe6b9SJerome Glisse static uint32_t cail_reg_read(struct card_info *info, uint32_t reg) 443771fe6b9SJerome Glisse { 444771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 445771fe6b9SJerome Glisse uint32_t r; 446771fe6b9SJerome Glisse 447771fe6b9SJerome Glisse r = RREG32(reg*4); 448771fe6b9SJerome Glisse return r; 449771fe6b9SJerome Glisse } 450771fe6b9SJerome Glisse 451771fe6b9SJerome Glisse static struct card_info atom_card_info = { 452771fe6b9SJerome Glisse .dev = NULL, 453771fe6b9SJerome Glisse .reg_read = cail_reg_read, 454771fe6b9SJerome Glisse .reg_write = cail_reg_write, 455771fe6b9SJerome Glisse .mc_read = cail_mc_read, 456771fe6b9SJerome Glisse .mc_write = cail_mc_write, 457771fe6b9SJerome Glisse .pll_read = cail_pll_read, 458771fe6b9SJerome Glisse .pll_write = cail_pll_write, 459771fe6b9SJerome Glisse }; 460771fe6b9SJerome Glisse 461771fe6b9SJerome Glisse int radeon_atombios_init(struct radeon_device *rdev) 462771fe6b9SJerome Glisse { 463771fe6b9SJerome Glisse atom_card_info.dev = rdev->ddev; 464771fe6b9SJerome Glisse rdev->mode_info.atom_context = atom_parse(&atom_card_info, rdev->bios); 465771fe6b9SJerome Glisse radeon_atom_initialize_bios_scratch_regs(rdev->ddev); 466771fe6b9SJerome Glisse return 0; 467771fe6b9SJerome Glisse } 468771fe6b9SJerome Glisse 469771fe6b9SJerome Glisse void radeon_atombios_fini(struct radeon_device *rdev) 470771fe6b9SJerome Glisse { 471771fe6b9SJerome Glisse kfree(rdev->mode_info.atom_context); 472771fe6b9SJerome Glisse } 473771fe6b9SJerome Glisse 474771fe6b9SJerome Glisse int radeon_combios_init(struct radeon_device *rdev) 475771fe6b9SJerome Glisse { 476771fe6b9SJerome Glisse radeon_combios_initialize_bios_scratch_regs(rdev->ddev); 477771fe6b9SJerome Glisse return 0; 478771fe6b9SJerome Glisse } 479771fe6b9SJerome Glisse 480771fe6b9SJerome Glisse void radeon_combios_fini(struct radeon_device *rdev) 481771fe6b9SJerome Glisse { 482771fe6b9SJerome Glisse } 483771fe6b9SJerome Glisse 484*28d52043SDave Airlie /* if we get transitioned to only one device, tak VGA back */ 485*28d52043SDave Airlie static unsigned int radeon_vga_set_decode(void *cookie, bool state) 486*28d52043SDave Airlie { 487*28d52043SDave Airlie struct radeon_device *rdev = cookie; 488771fe6b9SJerome Glisse 489*28d52043SDave Airlie radeon_vga_set_state(rdev, state); 490*28d52043SDave Airlie if (state) 491*28d52043SDave Airlie return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | 492*28d52043SDave Airlie VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; 493*28d52043SDave Airlie else 494*28d52043SDave Airlie return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; 495*28d52043SDave Airlie } 496771fe6b9SJerome Glisse /* 497771fe6b9SJerome Glisse * Radeon device. 498771fe6b9SJerome Glisse */ 499771fe6b9SJerome Glisse int radeon_device_init(struct radeon_device *rdev, 500771fe6b9SJerome Glisse struct drm_device *ddev, 501771fe6b9SJerome Glisse struct pci_dev *pdev, 502771fe6b9SJerome Glisse uint32_t flags) 503771fe6b9SJerome Glisse { 5046cf8a3f5SJerome Glisse int r; 505ad49f501SDave Airlie int dma_bits; 506771fe6b9SJerome Glisse 507771fe6b9SJerome Glisse DRM_INFO("radeon: Initializing kernel modesetting.\n"); 508771fe6b9SJerome Glisse rdev->shutdown = false; 5099f022ddfSJerome Glisse rdev->dev = &pdev->dev; 510771fe6b9SJerome Glisse rdev->ddev = ddev; 511771fe6b9SJerome Glisse rdev->pdev = pdev; 512771fe6b9SJerome Glisse rdev->flags = flags; 513771fe6b9SJerome Glisse rdev->family = flags & RADEON_FAMILY_MASK; 514771fe6b9SJerome Glisse rdev->is_atom_bios = false; 515771fe6b9SJerome Glisse rdev->usec_timeout = RADEON_MAX_USEC_TIMEOUT; 516771fe6b9SJerome Glisse rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; 517771fe6b9SJerome Glisse rdev->gpu_lockup = false; 518733289c2SJerome Glisse rdev->accel_working = false; 519771fe6b9SJerome Glisse /* mutex initialization are all done here so we 520771fe6b9SJerome Glisse * can recall function without having locking issues */ 521771fe6b9SJerome Glisse mutex_init(&rdev->cs_mutex); 522771fe6b9SJerome Glisse mutex_init(&rdev->ib_pool.mutex); 523771fe6b9SJerome Glisse mutex_init(&rdev->cp.mutex); 524771fe6b9SJerome Glisse rwlock_init(&rdev->fence_drv.lock); 5259f022ddfSJerome Glisse INIT_LIST_HEAD(&rdev->gem.objects); 526771fe6b9SJerome Glisse 5274aac0473SJerome Glisse /* Set asic functions */ 5284aac0473SJerome Glisse r = radeon_asic_init(rdev); 5294aac0473SJerome Glisse if (r) { 5304aac0473SJerome Glisse return r; 5314aac0473SJerome Glisse } 5324aac0473SJerome Glisse 533771fe6b9SJerome Glisse if (radeon_agpmode == -1) { 534771fe6b9SJerome Glisse rdev->flags &= ~RADEON_IS_AGP; 535c000273eSJerome Glisse if (rdev->family >= CHIP_RV515 || 536771fe6b9SJerome Glisse rdev->family == CHIP_RV380 || 537771fe6b9SJerome Glisse rdev->family == CHIP_RV410 || 538771fe6b9SJerome Glisse rdev->family == CHIP_R423) { 539771fe6b9SJerome Glisse DRM_INFO("Forcing AGP to PCIE mode\n"); 540771fe6b9SJerome Glisse rdev->flags |= RADEON_IS_PCIE; 5414aac0473SJerome Glisse rdev->asic->gart_init = &rv370_pcie_gart_init; 5424aac0473SJerome Glisse rdev->asic->gart_fini = &rv370_pcie_gart_fini; 5434aac0473SJerome Glisse rdev->asic->gart_enable = &rv370_pcie_gart_enable; 5444aac0473SJerome Glisse rdev->asic->gart_disable = &rv370_pcie_gart_disable; 5454aac0473SJerome Glisse rdev->asic->gart_tlb_flush = &rv370_pcie_gart_tlb_flush; 5464aac0473SJerome Glisse rdev->asic->gart_set_page = &rv370_pcie_gart_set_page; 547771fe6b9SJerome Glisse } else { 548771fe6b9SJerome Glisse DRM_INFO("Forcing AGP to PCI mode\n"); 549771fe6b9SJerome Glisse rdev->flags |= RADEON_IS_PCI; 5504aac0473SJerome Glisse rdev->asic->gart_init = &r100_pci_gart_init; 5514aac0473SJerome Glisse rdev->asic->gart_fini = &r100_pci_gart_fini; 5524aac0473SJerome Glisse rdev->asic->gart_enable = &r100_pci_gart_enable; 5534aac0473SJerome Glisse rdev->asic->gart_disable = &r100_pci_gart_disable; 5544aac0473SJerome Glisse rdev->asic->gart_tlb_flush = &r100_pci_gart_tlb_flush; 5554aac0473SJerome Glisse rdev->asic->gart_set_page = &r100_pci_gart_set_page; 556771fe6b9SJerome Glisse } 557771fe6b9SJerome Glisse } 558771fe6b9SJerome Glisse 559ad49f501SDave Airlie /* set DMA mask + need_dma32 flags. 560ad49f501SDave Airlie * PCIE - can handle 40-bits. 561ad49f501SDave Airlie * IGP - can handle 40-bits (in theory) 562ad49f501SDave Airlie * AGP - generally dma32 is safest 563ad49f501SDave Airlie * PCI - only dma32 564ad49f501SDave Airlie */ 565ad49f501SDave Airlie rdev->need_dma32 = false; 566ad49f501SDave Airlie if (rdev->flags & RADEON_IS_AGP) 567ad49f501SDave Airlie rdev->need_dma32 = true; 568ad49f501SDave Airlie if (rdev->flags & RADEON_IS_PCI) 569ad49f501SDave Airlie rdev->need_dma32 = true; 570ad49f501SDave Airlie 571ad49f501SDave Airlie dma_bits = rdev->need_dma32 ? 32 : 40; 572ad49f501SDave Airlie r = pci_set_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits)); 573771fe6b9SJerome Glisse if (r) { 574771fe6b9SJerome Glisse printk(KERN_WARNING "radeon: No suitable DMA available.\n"); 575771fe6b9SJerome Glisse } 576771fe6b9SJerome Glisse 577771fe6b9SJerome Glisse /* Registers mapping */ 578771fe6b9SJerome Glisse /* TODO: block userspace mapping of io register */ 579771fe6b9SJerome Glisse rdev->rmmio_base = drm_get_resource_start(rdev->ddev, 2); 580771fe6b9SJerome Glisse rdev->rmmio_size = drm_get_resource_len(rdev->ddev, 2); 581771fe6b9SJerome Glisse rdev->rmmio = ioremap(rdev->rmmio_base, rdev->rmmio_size); 582771fe6b9SJerome Glisse if (rdev->rmmio == NULL) { 583771fe6b9SJerome Glisse return -ENOMEM; 584771fe6b9SJerome Glisse } 585771fe6b9SJerome Glisse DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)rdev->rmmio_base); 586771fe6b9SJerome Glisse DRM_INFO("register mmio size: %u\n", (unsigned)rdev->rmmio_size); 587771fe6b9SJerome Glisse 5883ce0a23dSJerome Glisse rdev->new_init_path = false; 5893ce0a23dSJerome Glisse r = radeon_init(rdev); 5903ce0a23dSJerome Glisse if (r) { 5913ce0a23dSJerome Glisse return r; 5923ce0a23dSJerome Glisse } 593*28d52043SDave Airlie 594*28d52043SDave Airlie /* if we have > 1 VGA cards, then disable the radeon VGA resources */ 595*28d52043SDave Airlie r = vga_client_register(rdev->pdev, rdev, NULL, radeon_vga_set_decode); 596*28d52043SDave Airlie if (r) { 597*28d52043SDave Airlie return -EINVAL; 598*28d52043SDave Airlie } 599*28d52043SDave Airlie 6003ce0a23dSJerome Glisse if (!rdev->new_init_path) { 601771fe6b9SJerome Glisse /* Setup errata flags */ 602771fe6b9SJerome Glisse radeon_errata(rdev); 603771fe6b9SJerome Glisse /* Initialize scratch registers */ 604771fe6b9SJerome Glisse radeon_scratch_init(rdev); 605b1e3a6d1SMichel Dänzer /* Initialize surface registers */ 606b1e3a6d1SMichel Dänzer radeon_surface_init(rdev); 607b1e3a6d1SMichel Dänzer 608771fe6b9SJerome Glisse /* BIOS*/ 609771fe6b9SJerome Glisse if (!radeon_get_bios(rdev)) { 610771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev)) 611771fe6b9SJerome Glisse return -EINVAL; 612771fe6b9SJerome Glisse } 613771fe6b9SJerome Glisse if (rdev->is_atom_bios) { 614771fe6b9SJerome Glisse r = radeon_atombios_init(rdev); 615771fe6b9SJerome Glisse if (r) { 616771fe6b9SJerome Glisse return r; 617771fe6b9SJerome Glisse } 618771fe6b9SJerome Glisse } else { 619771fe6b9SJerome Glisse r = radeon_combios_init(rdev); 620771fe6b9SJerome Glisse if (r) { 621771fe6b9SJerome Glisse return r; 622771fe6b9SJerome Glisse } 623771fe6b9SJerome Glisse } 624771fe6b9SJerome Glisse /* Reset gpu before posting otherwise ATOM will enter infinite loop */ 625771fe6b9SJerome Glisse if (radeon_gpu_reset(rdev)) { 626771fe6b9SJerome Glisse /* FIXME: what do we want to do here ? */ 627771fe6b9SJerome Glisse } 628771fe6b9SJerome Glisse /* check if cards are posted or not */ 629771fe6b9SJerome Glisse if (!radeon_card_posted(rdev) && rdev->bios) { 630771fe6b9SJerome Glisse DRM_INFO("GPU not posted. posting now...\n"); 631771fe6b9SJerome Glisse if (rdev->is_atom_bios) { 632771fe6b9SJerome Glisse atom_asic_init(rdev->mode_info.atom_context); 633771fe6b9SJerome Glisse } else { 634771fe6b9SJerome Glisse radeon_combios_asic_init(rdev->ddev); 635771fe6b9SJerome Glisse } 636771fe6b9SJerome Glisse } 6375e6dde7eSMichel Dänzer /* Get clock & vram information */ 6385e6dde7eSMichel Dänzer radeon_get_clock_info(rdev->ddev); 63995a8f1bfSMichel Dänzer radeon_vram_info(rdev); 640c93bb85bSJerome Glisse /* Initialize clocks */ 641c93bb85bSJerome Glisse r = radeon_clocks_init(rdev); 642c93bb85bSJerome Glisse if (r) { 643c93bb85bSJerome Glisse return r; 644c93bb85bSJerome Glisse } 6452a0f8918SDave Airlie 646771fe6b9SJerome Glisse /* Initialize memory controller (also test AGP) */ 647771fe6b9SJerome Glisse r = radeon_mc_init(rdev); 648771fe6b9SJerome Glisse if (r) { 649771fe6b9SJerome Glisse return r; 650771fe6b9SJerome Glisse } 651771fe6b9SJerome Glisse /* Fence driver */ 652771fe6b9SJerome Glisse r = radeon_fence_driver_init(rdev); 653771fe6b9SJerome Glisse if (r) { 654771fe6b9SJerome Glisse return r; 655771fe6b9SJerome Glisse } 656771fe6b9SJerome Glisse r = radeon_irq_kms_init(rdev); 657771fe6b9SJerome Glisse if (r) { 658771fe6b9SJerome Glisse return r; 659771fe6b9SJerome Glisse } 660771fe6b9SJerome Glisse /* Memory manager */ 661771fe6b9SJerome Glisse r = radeon_object_init(rdev); 662771fe6b9SJerome Glisse if (r) { 663771fe6b9SJerome Glisse return r; 664771fe6b9SJerome Glisse } 6654aac0473SJerome Glisse r = radeon_gpu_gart_init(rdev); 6664aac0473SJerome Glisse if (r) 6674aac0473SJerome Glisse return r; 668771fe6b9SJerome Glisse /* Initialize GART (initialize after TTM so we can allocate 669771fe6b9SJerome Glisse * memory through TTM but finalize after TTM) */ 670771fe6b9SJerome Glisse r = radeon_gart_enable(rdev); 671733289c2SJerome Glisse if (r) 672733289c2SJerome Glisse return 0; 673771fe6b9SJerome Glisse r = radeon_gem_init(rdev); 674733289c2SJerome Glisse if (r) 675733289c2SJerome Glisse return 0; 676771fe6b9SJerome Glisse 677771fe6b9SJerome Glisse /* 1M ring buffer */ 678771fe6b9SJerome Glisse r = radeon_cp_init(rdev, 1024 * 1024); 679733289c2SJerome Glisse if (r) 680733289c2SJerome Glisse return 0; 681771fe6b9SJerome Glisse r = radeon_wb_init(rdev); 682733289c2SJerome Glisse if (r) 683771fe6b9SJerome Glisse DRM_ERROR("radeon: failled initializing WB (%d).\n", r); 684771fe6b9SJerome Glisse r = radeon_ib_pool_init(rdev); 685733289c2SJerome Glisse if (r) 686733289c2SJerome Glisse return 0; 687771fe6b9SJerome Glisse r = radeon_ib_test(rdev); 688733289c2SJerome Glisse if (r) 689733289c2SJerome Glisse return 0; 690733289c2SJerome Glisse rdev->accel_working = true; 6913ce0a23dSJerome Glisse } 692771fe6b9SJerome Glisse DRM_INFO("radeon: kernel modesetting successfully initialized.\n"); 693ecc0b326SMichel Dänzer if (radeon_testing) { 694ecc0b326SMichel Dänzer radeon_test_moves(rdev); 695ecc0b326SMichel Dänzer } 696771fe6b9SJerome Glisse if (radeon_benchmarking) { 697771fe6b9SJerome Glisse radeon_benchmark(rdev); 698771fe6b9SJerome Glisse } 6996cf8a3f5SJerome Glisse return 0; 700771fe6b9SJerome Glisse } 701771fe6b9SJerome Glisse 702771fe6b9SJerome Glisse void radeon_device_fini(struct radeon_device *rdev) 703771fe6b9SJerome Glisse { 704771fe6b9SJerome Glisse DRM_INFO("radeon: finishing device.\n"); 705771fe6b9SJerome Glisse rdev->shutdown = true; 706771fe6b9SJerome Glisse /* Order matter so becarefull if you rearrange anythings */ 7073ce0a23dSJerome Glisse if (!rdev->new_init_path) { 708771fe6b9SJerome Glisse radeon_ib_pool_fini(rdev); 709771fe6b9SJerome Glisse radeon_cp_fini(rdev); 710771fe6b9SJerome Glisse radeon_wb_fini(rdev); 7114aac0473SJerome Glisse radeon_gpu_gart_fini(rdev); 712771fe6b9SJerome Glisse radeon_gem_fini(rdev); 713771fe6b9SJerome Glisse radeon_mc_fini(rdev); 714771fe6b9SJerome Glisse #if __OS_HAS_AGP 715771fe6b9SJerome Glisse radeon_agp_fini(rdev); 716771fe6b9SJerome Glisse #endif 717771fe6b9SJerome Glisse radeon_irq_kms_fini(rdev); 718*28d52043SDave Airlie vga_client_register(rdev->pdev, NULL, NULL, NULL); 719771fe6b9SJerome Glisse radeon_fence_driver_fini(rdev); 720771fe6b9SJerome Glisse radeon_clocks_fini(rdev); 7213ce0a23dSJerome Glisse radeon_object_fini(rdev); 722771fe6b9SJerome Glisse if (rdev->is_atom_bios) { 723771fe6b9SJerome Glisse radeon_atombios_fini(rdev); 724771fe6b9SJerome Glisse } else { 725771fe6b9SJerome Glisse radeon_combios_fini(rdev); 726771fe6b9SJerome Glisse } 727771fe6b9SJerome Glisse kfree(rdev->bios); 728771fe6b9SJerome Glisse rdev->bios = NULL; 7293ce0a23dSJerome Glisse } else { 7303ce0a23dSJerome Glisse radeon_fini(rdev); 7313ce0a23dSJerome Glisse } 732771fe6b9SJerome Glisse iounmap(rdev->rmmio); 733771fe6b9SJerome Glisse rdev->rmmio = NULL; 734771fe6b9SJerome Glisse } 735771fe6b9SJerome Glisse 736771fe6b9SJerome Glisse 737771fe6b9SJerome Glisse /* 738771fe6b9SJerome Glisse * Suspend & resume. 739771fe6b9SJerome Glisse */ 740771fe6b9SJerome Glisse int radeon_suspend_kms(struct drm_device *dev, pm_message_t state) 741771fe6b9SJerome Glisse { 742771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 743771fe6b9SJerome Glisse struct drm_crtc *crtc; 744771fe6b9SJerome Glisse 745771fe6b9SJerome Glisse if (dev == NULL || rdev == NULL) { 746771fe6b9SJerome Glisse return -ENODEV; 747771fe6b9SJerome Glisse } 748771fe6b9SJerome Glisse if (state.event == PM_EVENT_PRETHAW) { 749771fe6b9SJerome Glisse return 0; 750771fe6b9SJerome Glisse } 751771fe6b9SJerome Glisse /* unpin the front buffers */ 752771fe6b9SJerome Glisse list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 753771fe6b9SJerome Glisse struct radeon_framebuffer *rfb = to_radeon_framebuffer(crtc->fb); 754771fe6b9SJerome Glisse struct radeon_object *robj; 755771fe6b9SJerome Glisse 756771fe6b9SJerome Glisse if (rfb == NULL || rfb->obj == NULL) { 757771fe6b9SJerome Glisse continue; 758771fe6b9SJerome Glisse } 759771fe6b9SJerome Glisse robj = rfb->obj->driver_private; 760771fe6b9SJerome Glisse if (robj != rdev->fbdev_robj) { 761771fe6b9SJerome Glisse radeon_object_unpin(robj); 762771fe6b9SJerome Glisse } 763771fe6b9SJerome Glisse } 764771fe6b9SJerome Glisse /* evict vram memory */ 765771fe6b9SJerome Glisse radeon_object_evict_vram(rdev); 766771fe6b9SJerome Glisse /* wait for gpu to finish processing current batch */ 767771fe6b9SJerome Glisse radeon_fence_wait_last(rdev); 768771fe6b9SJerome Glisse 769f657c2a7SYang Zhao radeon_save_bios_scratch_regs(rdev); 770f657c2a7SYang Zhao 7713ce0a23dSJerome Glisse if (!rdev->new_init_path) { 772771fe6b9SJerome Glisse radeon_cp_disable(rdev); 773771fe6b9SJerome Glisse radeon_gart_disable(rdev); 7749f022ddfSJerome Glisse rdev->irq.sw_int = false; 7759f022ddfSJerome Glisse radeon_irq_set(rdev); 7763ce0a23dSJerome Glisse } else { 7773ce0a23dSJerome Glisse radeon_suspend(rdev); 7783ce0a23dSJerome Glisse } 779771fe6b9SJerome Glisse /* evict remaining vram memory */ 780771fe6b9SJerome Glisse radeon_object_evict_vram(rdev); 781771fe6b9SJerome Glisse 782771fe6b9SJerome Glisse pci_save_state(dev->pdev); 783771fe6b9SJerome Glisse if (state.event == PM_EVENT_SUSPEND) { 784771fe6b9SJerome Glisse /* Shut down the device */ 785771fe6b9SJerome Glisse pci_disable_device(dev->pdev); 786771fe6b9SJerome Glisse pci_set_power_state(dev->pdev, PCI_D3hot); 787771fe6b9SJerome Glisse } 788771fe6b9SJerome Glisse acquire_console_sem(); 789771fe6b9SJerome Glisse fb_set_suspend(rdev->fbdev_info, 1); 790771fe6b9SJerome Glisse release_console_sem(); 791771fe6b9SJerome Glisse return 0; 792771fe6b9SJerome Glisse } 793771fe6b9SJerome Glisse 794771fe6b9SJerome Glisse int radeon_resume_kms(struct drm_device *dev) 795771fe6b9SJerome Glisse { 796771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 797771fe6b9SJerome Glisse int r; 798771fe6b9SJerome Glisse 799771fe6b9SJerome Glisse acquire_console_sem(); 800771fe6b9SJerome Glisse pci_set_power_state(dev->pdev, PCI_D0); 801771fe6b9SJerome Glisse pci_restore_state(dev->pdev); 802771fe6b9SJerome Glisse if (pci_enable_device(dev->pdev)) { 803771fe6b9SJerome Glisse release_console_sem(); 804771fe6b9SJerome Glisse return -1; 805771fe6b9SJerome Glisse } 806771fe6b9SJerome Glisse pci_set_master(dev->pdev); 807771fe6b9SJerome Glisse /* Reset gpu before posting otherwise ATOM will enter infinite loop */ 8089f022ddfSJerome Glisse if (!rdev->new_init_path) { 809771fe6b9SJerome Glisse if (radeon_gpu_reset(rdev)) { 810771fe6b9SJerome Glisse /* FIXME: what do we want to do here ? */ 811771fe6b9SJerome Glisse } 812771fe6b9SJerome Glisse /* post card */ 813771fe6b9SJerome Glisse if (rdev->is_atom_bios) { 814771fe6b9SJerome Glisse atom_asic_init(rdev->mode_info.atom_context); 815771fe6b9SJerome Glisse } else { 816771fe6b9SJerome Glisse radeon_combios_asic_init(rdev->ddev); 817771fe6b9SJerome Glisse } 818771fe6b9SJerome Glisse /* Initialize clocks */ 819771fe6b9SJerome Glisse r = radeon_clocks_init(rdev); 820771fe6b9SJerome Glisse if (r) { 821771fe6b9SJerome Glisse release_console_sem(); 822771fe6b9SJerome Glisse return r; 823771fe6b9SJerome Glisse } 824771fe6b9SJerome Glisse /* Enable IRQ */ 825771fe6b9SJerome Glisse rdev->irq.sw_int = true; 826771fe6b9SJerome Glisse radeon_irq_set(rdev); 827771fe6b9SJerome Glisse /* Initialize GPU Memory Controller */ 828771fe6b9SJerome Glisse r = radeon_mc_init(rdev); 829771fe6b9SJerome Glisse if (r) { 830771fe6b9SJerome Glisse goto out; 831771fe6b9SJerome Glisse } 832771fe6b9SJerome Glisse r = radeon_gart_enable(rdev); 833771fe6b9SJerome Glisse if (r) { 834771fe6b9SJerome Glisse goto out; 835771fe6b9SJerome Glisse } 836771fe6b9SJerome Glisse r = radeon_cp_init(rdev, rdev->cp.ring_size); 837771fe6b9SJerome Glisse if (r) { 838771fe6b9SJerome Glisse goto out; 839771fe6b9SJerome Glisse } 8403ce0a23dSJerome Glisse } else { 8413ce0a23dSJerome Glisse radeon_resume(rdev); 8423ce0a23dSJerome Glisse } 843771fe6b9SJerome Glisse out: 844f657c2a7SYang Zhao radeon_restore_bios_scratch_regs(rdev); 845771fe6b9SJerome Glisse fb_set_suspend(rdev->fbdev_info, 0); 846771fe6b9SJerome Glisse release_console_sem(); 847771fe6b9SJerome Glisse 848771fe6b9SJerome Glisse /* blat the mode back in */ 849771fe6b9SJerome Glisse drm_helper_resume_force_mode(dev); 850771fe6b9SJerome Glisse return 0; 851771fe6b9SJerome Glisse } 852771fe6b9SJerome Glisse 853771fe6b9SJerome Glisse 854771fe6b9SJerome Glisse /* 855771fe6b9SJerome Glisse * Debugfs 856771fe6b9SJerome Glisse */ 857771fe6b9SJerome Glisse struct radeon_debugfs { 858771fe6b9SJerome Glisse struct drm_info_list *files; 859771fe6b9SJerome Glisse unsigned num_files; 860771fe6b9SJerome Glisse }; 861771fe6b9SJerome Glisse static struct radeon_debugfs _radeon_debugfs[RADEON_DEBUGFS_MAX_NUM_FILES]; 862771fe6b9SJerome Glisse static unsigned _radeon_debugfs_count = 0; 863771fe6b9SJerome Glisse 864771fe6b9SJerome Glisse int radeon_debugfs_add_files(struct radeon_device *rdev, 865771fe6b9SJerome Glisse struct drm_info_list *files, 866771fe6b9SJerome Glisse unsigned nfiles) 867771fe6b9SJerome Glisse { 868771fe6b9SJerome Glisse unsigned i; 869771fe6b9SJerome Glisse 870771fe6b9SJerome Glisse for (i = 0; i < _radeon_debugfs_count; i++) { 871771fe6b9SJerome Glisse if (_radeon_debugfs[i].files == files) { 872771fe6b9SJerome Glisse /* Already registered */ 873771fe6b9SJerome Glisse return 0; 874771fe6b9SJerome Glisse } 875771fe6b9SJerome Glisse } 876771fe6b9SJerome Glisse if ((_radeon_debugfs_count + nfiles) > RADEON_DEBUGFS_MAX_NUM_FILES) { 877771fe6b9SJerome Glisse DRM_ERROR("Reached maximum number of debugfs files.\n"); 878771fe6b9SJerome Glisse DRM_ERROR("Report so we increase RADEON_DEBUGFS_MAX_NUM_FILES.\n"); 879771fe6b9SJerome Glisse return -EINVAL; 880771fe6b9SJerome Glisse } 881771fe6b9SJerome Glisse _radeon_debugfs[_radeon_debugfs_count].files = files; 882771fe6b9SJerome Glisse _radeon_debugfs[_radeon_debugfs_count].num_files = nfiles; 883771fe6b9SJerome Glisse _radeon_debugfs_count++; 884771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 885771fe6b9SJerome Glisse drm_debugfs_create_files(files, nfiles, 886771fe6b9SJerome Glisse rdev->ddev->control->debugfs_root, 887771fe6b9SJerome Glisse rdev->ddev->control); 888771fe6b9SJerome Glisse drm_debugfs_create_files(files, nfiles, 889771fe6b9SJerome Glisse rdev->ddev->primary->debugfs_root, 890771fe6b9SJerome Glisse rdev->ddev->primary); 891771fe6b9SJerome Glisse #endif 892771fe6b9SJerome Glisse return 0; 893771fe6b9SJerome Glisse } 894771fe6b9SJerome Glisse 895771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 896771fe6b9SJerome Glisse int radeon_debugfs_init(struct drm_minor *minor) 897771fe6b9SJerome Glisse { 898771fe6b9SJerome Glisse return 0; 899771fe6b9SJerome Glisse } 900771fe6b9SJerome Glisse 901771fe6b9SJerome Glisse void radeon_debugfs_cleanup(struct drm_minor *minor) 902771fe6b9SJerome Glisse { 903771fe6b9SJerome Glisse unsigned i; 904771fe6b9SJerome Glisse 905771fe6b9SJerome Glisse for (i = 0; i < _radeon_debugfs_count; i++) { 906771fe6b9SJerome Glisse drm_debugfs_remove_files(_radeon_debugfs[i].files, 907771fe6b9SJerome Glisse _radeon_debugfs[i].num_files, minor); 908771fe6b9SJerome Glisse } 909771fe6b9SJerome Glisse } 910771fe6b9SJerome Glisse #endif 911