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> 3228d52043SDave 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 21172542d77SDave Airlie bool radeon_boot_test_post_card(struct radeon_device *rdev) 21272542d77SDave Airlie { 21372542d77SDave Airlie if (radeon_card_posted(rdev)) 21472542d77SDave Airlie return true; 21572542d77SDave Airlie 21672542d77SDave Airlie if (rdev->bios) { 21772542d77SDave Airlie DRM_INFO("GPU not posted. posting now...\n"); 21872542d77SDave Airlie if (rdev->is_atom_bios) 21972542d77SDave Airlie atom_asic_init(rdev->mode_info.atom_context); 22072542d77SDave Airlie else 22172542d77SDave Airlie radeon_combios_asic_init(rdev->ddev); 22272542d77SDave Airlie return true; 22372542d77SDave Airlie } else { 22472542d77SDave Airlie dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n"); 22572542d77SDave Airlie return false; 22672542d77SDave Airlie } 22772542d77SDave Airlie } 22872542d77SDave Airlie 2293ce0a23dSJerome Glisse int radeon_dummy_page_init(struct radeon_device *rdev) 2303ce0a23dSJerome Glisse { 2313ce0a23dSJerome Glisse rdev->dummy_page.page = alloc_page(GFP_DMA32 | GFP_KERNEL | __GFP_ZERO); 2323ce0a23dSJerome Glisse if (rdev->dummy_page.page == NULL) 2333ce0a23dSJerome Glisse return -ENOMEM; 2343ce0a23dSJerome Glisse rdev->dummy_page.addr = pci_map_page(rdev->pdev, rdev->dummy_page.page, 2353ce0a23dSJerome Glisse 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 2363ce0a23dSJerome Glisse if (!rdev->dummy_page.addr) { 2373ce0a23dSJerome Glisse __free_page(rdev->dummy_page.page); 2383ce0a23dSJerome Glisse rdev->dummy_page.page = NULL; 2393ce0a23dSJerome Glisse return -ENOMEM; 2403ce0a23dSJerome Glisse } 2413ce0a23dSJerome Glisse return 0; 2423ce0a23dSJerome Glisse } 2433ce0a23dSJerome Glisse 2443ce0a23dSJerome Glisse void radeon_dummy_page_fini(struct radeon_device *rdev) 2453ce0a23dSJerome Glisse { 2463ce0a23dSJerome Glisse if (rdev->dummy_page.page == NULL) 2473ce0a23dSJerome Glisse return; 2483ce0a23dSJerome Glisse pci_unmap_page(rdev->pdev, rdev->dummy_page.addr, 2493ce0a23dSJerome Glisse PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 2503ce0a23dSJerome Glisse __free_page(rdev->dummy_page.page); 2513ce0a23dSJerome Glisse rdev->dummy_page.page = NULL; 2523ce0a23dSJerome Glisse } 2533ce0a23dSJerome Glisse 254771fe6b9SJerome Glisse 255771fe6b9SJerome Glisse /* 256771fe6b9SJerome Glisse * Registers accessors functions. 257771fe6b9SJerome Glisse */ 258771fe6b9SJerome Glisse uint32_t radeon_invalid_rreg(struct radeon_device *rdev, uint32_t reg) 259771fe6b9SJerome Glisse { 260771fe6b9SJerome Glisse DRM_ERROR("Invalid callback to read register 0x%04X\n", reg); 261771fe6b9SJerome Glisse BUG_ON(1); 262771fe6b9SJerome Glisse return 0; 263771fe6b9SJerome Glisse } 264771fe6b9SJerome Glisse 265771fe6b9SJerome Glisse void radeon_invalid_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v) 266771fe6b9SJerome Glisse { 267771fe6b9SJerome Glisse DRM_ERROR("Invalid callback to write register 0x%04X with 0x%08X\n", 268771fe6b9SJerome Glisse reg, v); 269771fe6b9SJerome Glisse BUG_ON(1); 270771fe6b9SJerome Glisse } 271771fe6b9SJerome Glisse 272771fe6b9SJerome Glisse void radeon_register_accessor_init(struct radeon_device *rdev) 273771fe6b9SJerome Glisse { 274771fe6b9SJerome Glisse rdev->mc_rreg = &radeon_invalid_rreg; 275771fe6b9SJerome Glisse rdev->mc_wreg = &radeon_invalid_wreg; 276771fe6b9SJerome Glisse rdev->pll_rreg = &radeon_invalid_rreg; 277771fe6b9SJerome Glisse rdev->pll_wreg = &radeon_invalid_wreg; 278771fe6b9SJerome Glisse rdev->pciep_rreg = &radeon_invalid_rreg; 279771fe6b9SJerome Glisse rdev->pciep_wreg = &radeon_invalid_wreg; 280771fe6b9SJerome Glisse 281771fe6b9SJerome Glisse /* Don't change order as we are overridding accessor. */ 282771fe6b9SJerome Glisse if (rdev->family < CHIP_RV515) { 283de1b2898SDave Airlie rdev->pcie_reg_mask = 0xff; 284de1b2898SDave Airlie } else { 285de1b2898SDave Airlie rdev->pcie_reg_mask = 0x7ff; 286771fe6b9SJerome Glisse } 287771fe6b9SJerome Glisse /* FIXME: not sure here */ 288771fe6b9SJerome Glisse if (rdev->family <= CHIP_R580) { 289771fe6b9SJerome Glisse rdev->pll_rreg = &r100_pll_rreg; 290771fe6b9SJerome Glisse rdev->pll_wreg = &r100_pll_wreg; 291771fe6b9SJerome Glisse } 292905b6822SJerome Glisse if (rdev->family >= CHIP_R420) { 293905b6822SJerome Glisse rdev->mc_rreg = &r420_mc_rreg; 294905b6822SJerome Glisse rdev->mc_wreg = &r420_mc_wreg; 295905b6822SJerome Glisse } 296771fe6b9SJerome Glisse if (rdev->family >= CHIP_RV515) { 297771fe6b9SJerome Glisse rdev->mc_rreg = &rv515_mc_rreg; 298771fe6b9SJerome Glisse rdev->mc_wreg = &rv515_mc_wreg; 299771fe6b9SJerome Glisse } 300771fe6b9SJerome Glisse if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480) { 301771fe6b9SJerome Glisse rdev->mc_rreg = &rs400_mc_rreg; 302771fe6b9SJerome Glisse rdev->mc_wreg = &rs400_mc_wreg; 303771fe6b9SJerome Glisse } 304771fe6b9SJerome Glisse if (rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) { 305771fe6b9SJerome Glisse rdev->mc_rreg = &rs690_mc_rreg; 306771fe6b9SJerome Glisse rdev->mc_wreg = &rs690_mc_wreg; 307771fe6b9SJerome Glisse } 308771fe6b9SJerome Glisse if (rdev->family == CHIP_RS600) { 309771fe6b9SJerome Glisse rdev->mc_rreg = &rs600_mc_rreg; 310771fe6b9SJerome Glisse rdev->mc_wreg = &rs600_mc_wreg; 311771fe6b9SJerome Glisse } 312771fe6b9SJerome Glisse if (rdev->family >= CHIP_R600) { 313771fe6b9SJerome Glisse rdev->pciep_rreg = &r600_pciep_rreg; 314771fe6b9SJerome Glisse rdev->pciep_wreg = &r600_pciep_wreg; 315771fe6b9SJerome Glisse } 316771fe6b9SJerome Glisse } 317771fe6b9SJerome Glisse 318771fe6b9SJerome Glisse 319771fe6b9SJerome Glisse /* 320771fe6b9SJerome Glisse * ASIC 321771fe6b9SJerome Glisse */ 322771fe6b9SJerome Glisse int radeon_asic_init(struct radeon_device *rdev) 323771fe6b9SJerome Glisse { 324771fe6b9SJerome Glisse radeon_register_accessor_init(rdev); 325771fe6b9SJerome Glisse switch (rdev->family) { 326771fe6b9SJerome Glisse case CHIP_R100: 327771fe6b9SJerome Glisse case CHIP_RV100: 328771fe6b9SJerome Glisse case CHIP_RS100: 329771fe6b9SJerome Glisse case CHIP_RV200: 330771fe6b9SJerome Glisse case CHIP_RS200: 331771fe6b9SJerome Glisse case CHIP_R200: 332771fe6b9SJerome Glisse case CHIP_RV250: 333771fe6b9SJerome Glisse case CHIP_RS300: 334771fe6b9SJerome Glisse case CHIP_RV280: 335771fe6b9SJerome Glisse rdev->asic = &r100_asic; 336771fe6b9SJerome Glisse break; 337771fe6b9SJerome Glisse case CHIP_R300: 338771fe6b9SJerome Glisse case CHIP_R350: 339771fe6b9SJerome Glisse case CHIP_RV350: 340771fe6b9SJerome Glisse case CHIP_RV380: 341771fe6b9SJerome Glisse rdev->asic = &r300_asic; 3424aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCIE) { 3434aac0473SJerome Glisse rdev->asic->gart_tlb_flush = &rv370_pcie_gart_tlb_flush; 3444aac0473SJerome Glisse rdev->asic->gart_set_page = &rv370_pcie_gart_set_page; 3454aac0473SJerome Glisse } 346771fe6b9SJerome Glisse break; 347771fe6b9SJerome Glisse case CHIP_R420: 348771fe6b9SJerome Glisse case CHIP_R423: 349771fe6b9SJerome Glisse case CHIP_RV410: 350771fe6b9SJerome Glisse rdev->asic = &r420_asic; 351771fe6b9SJerome Glisse break; 352771fe6b9SJerome Glisse case CHIP_RS400: 353771fe6b9SJerome Glisse case CHIP_RS480: 354771fe6b9SJerome Glisse rdev->asic = &rs400_asic; 355771fe6b9SJerome Glisse break; 356771fe6b9SJerome Glisse case CHIP_RS600: 357771fe6b9SJerome Glisse rdev->asic = &rs600_asic; 358771fe6b9SJerome Glisse break; 359771fe6b9SJerome Glisse case CHIP_RS690: 360771fe6b9SJerome Glisse case CHIP_RS740: 361771fe6b9SJerome Glisse rdev->asic = &rs690_asic; 362771fe6b9SJerome Glisse break; 363771fe6b9SJerome Glisse case CHIP_RV515: 364771fe6b9SJerome Glisse rdev->asic = &rv515_asic; 365771fe6b9SJerome Glisse break; 366771fe6b9SJerome Glisse case CHIP_R520: 367771fe6b9SJerome Glisse case CHIP_RV530: 368771fe6b9SJerome Glisse case CHIP_RV560: 369771fe6b9SJerome Glisse case CHIP_RV570: 370771fe6b9SJerome Glisse case CHIP_R580: 371771fe6b9SJerome Glisse rdev->asic = &r520_asic; 372771fe6b9SJerome Glisse break; 373771fe6b9SJerome Glisse case CHIP_R600: 374771fe6b9SJerome Glisse case CHIP_RV610: 375771fe6b9SJerome Glisse case CHIP_RV630: 376771fe6b9SJerome Glisse case CHIP_RV620: 377771fe6b9SJerome Glisse case CHIP_RV635: 378771fe6b9SJerome Glisse case CHIP_RV670: 379771fe6b9SJerome Glisse case CHIP_RS780: 3803ce0a23dSJerome Glisse case CHIP_RS880: 3813ce0a23dSJerome Glisse rdev->asic = &r600_asic; 3823ce0a23dSJerome Glisse break; 383771fe6b9SJerome Glisse case CHIP_RV770: 384771fe6b9SJerome Glisse case CHIP_RV730: 385771fe6b9SJerome Glisse case CHIP_RV710: 3863ce0a23dSJerome Glisse case CHIP_RV740: 3873ce0a23dSJerome Glisse rdev->asic = &rv770_asic; 3883ce0a23dSJerome Glisse break; 389771fe6b9SJerome Glisse default: 390771fe6b9SJerome Glisse /* FIXME: not supported yet */ 391771fe6b9SJerome Glisse return -EINVAL; 392771fe6b9SJerome Glisse } 393771fe6b9SJerome Glisse return 0; 394771fe6b9SJerome Glisse } 395771fe6b9SJerome Glisse 396771fe6b9SJerome Glisse 397771fe6b9SJerome Glisse /* 398771fe6b9SJerome Glisse * Wrapper around modesetting bits. 399771fe6b9SJerome Glisse */ 400771fe6b9SJerome Glisse int radeon_clocks_init(struct radeon_device *rdev) 401771fe6b9SJerome Glisse { 402771fe6b9SJerome Glisse int r; 403771fe6b9SJerome Glisse 404771fe6b9SJerome Glisse r = radeon_static_clocks_init(rdev->ddev); 405771fe6b9SJerome Glisse if (r) { 406771fe6b9SJerome Glisse return r; 407771fe6b9SJerome Glisse } 408771fe6b9SJerome Glisse DRM_INFO("Clocks initialized !\n"); 409771fe6b9SJerome Glisse return 0; 410771fe6b9SJerome Glisse } 411771fe6b9SJerome Glisse 412771fe6b9SJerome Glisse void radeon_clocks_fini(struct radeon_device *rdev) 413771fe6b9SJerome Glisse { 414771fe6b9SJerome Glisse } 415771fe6b9SJerome Glisse 416771fe6b9SJerome Glisse /* ATOM accessor methods */ 417771fe6b9SJerome Glisse static uint32_t cail_pll_read(struct card_info *info, uint32_t reg) 418771fe6b9SJerome Glisse { 419771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 420771fe6b9SJerome Glisse uint32_t r; 421771fe6b9SJerome Glisse 422771fe6b9SJerome Glisse r = rdev->pll_rreg(rdev, reg); 423771fe6b9SJerome Glisse return r; 424771fe6b9SJerome Glisse } 425771fe6b9SJerome Glisse 426771fe6b9SJerome Glisse static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val) 427771fe6b9SJerome Glisse { 428771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 429771fe6b9SJerome Glisse 430771fe6b9SJerome Glisse rdev->pll_wreg(rdev, reg, val); 431771fe6b9SJerome Glisse } 432771fe6b9SJerome Glisse 433771fe6b9SJerome Glisse static uint32_t cail_mc_read(struct card_info *info, uint32_t reg) 434771fe6b9SJerome Glisse { 435771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 436771fe6b9SJerome Glisse uint32_t r; 437771fe6b9SJerome Glisse 438771fe6b9SJerome Glisse r = rdev->mc_rreg(rdev, reg); 439771fe6b9SJerome Glisse return r; 440771fe6b9SJerome Glisse } 441771fe6b9SJerome Glisse 442771fe6b9SJerome Glisse static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val) 443771fe6b9SJerome Glisse { 444771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 445771fe6b9SJerome Glisse 446771fe6b9SJerome Glisse rdev->mc_wreg(rdev, reg, val); 447771fe6b9SJerome Glisse } 448771fe6b9SJerome Glisse 449771fe6b9SJerome Glisse static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val) 450771fe6b9SJerome Glisse { 451771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 452771fe6b9SJerome Glisse 453771fe6b9SJerome Glisse WREG32(reg*4, val); 454771fe6b9SJerome Glisse } 455771fe6b9SJerome Glisse 456771fe6b9SJerome Glisse static uint32_t cail_reg_read(struct card_info *info, uint32_t reg) 457771fe6b9SJerome Glisse { 458771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 459771fe6b9SJerome Glisse uint32_t r; 460771fe6b9SJerome Glisse 461771fe6b9SJerome Glisse r = RREG32(reg*4); 462771fe6b9SJerome Glisse return r; 463771fe6b9SJerome Glisse } 464771fe6b9SJerome Glisse 465771fe6b9SJerome Glisse int radeon_atombios_init(struct radeon_device *rdev) 466771fe6b9SJerome Glisse { 46761c4b24bSMathias Fröhlich struct card_info *atom_card_info = 46861c4b24bSMathias Fröhlich kzalloc(sizeof(struct card_info), GFP_KERNEL); 46961c4b24bSMathias Fröhlich 47061c4b24bSMathias Fröhlich if (!atom_card_info) 47161c4b24bSMathias Fröhlich return -ENOMEM; 47261c4b24bSMathias Fröhlich 47361c4b24bSMathias Fröhlich rdev->mode_info.atom_card_info = atom_card_info; 47461c4b24bSMathias Fröhlich atom_card_info->dev = rdev->ddev; 47561c4b24bSMathias Fröhlich atom_card_info->reg_read = cail_reg_read; 47661c4b24bSMathias Fröhlich atom_card_info->reg_write = cail_reg_write; 47761c4b24bSMathias Fröhlich atom_card_info->mc_read = cail_mc_read; 47861c4b24bSMathias Fröhlich atom_card_info->mc_write = cail_mc_write; 47961c4b24bSMathias Fröhlich atom_card_info->pll_read = cail_pll_read; 48061c4b24bSMathias Fröhlich atom_card_info->pll_write = cail_pll_write; 48161c4b24bSMathias Fröhlich 48261c4b24bSMathias Fröhlich rdev->mode_info.atom_context = atom_parse(atom_card_info, rdev->bios); 483771fe6b9SJerome Glisse radeon_atom_initialize_bios_scratch_regs(rdev->ddev); 484d904ef9bSDave Airlie atom_allocate_fb_scratch(rdev->mode_info.atom_context); 485771fe6b9SJerome Glisse return 0; 486771fe6b9SJerome Glisse } 487771fe6b9SJerome Glisse 488771fe6b9SJerome Glisse void radeon_atombios_fini(struct radeon_device *rdev) 489771fe6b9SJerome Glisse { 490*4a04a844SJerome Glisse if (rdev->mode_info.atom_context) { 491d904ef9bSDave Airlie kfree(rdev->mode_info.atom_context->scratch); 492771fe6b9SJerome Glisse kfree(rdev->mode_info.atom_context); 493*4a04a844SJerome Glisse } 49461c4b24bSMathias Fröhlich kfree(rdev->mode_info.atom_card_info); 495771fe6b9SJerome Glisse } 496771fe6b9SJerome Glisse 497771fe6b9SJerome Glisse int radeon_combios_init(struct radeon_device *rdev) 498771fe6b9SJerome Glisse { 499771fe6b9SJerome Glisse radeon_combios_initialize_bios_scratch_regs(rdev->ddev); 500771fe6b9SJerome Glisse return 0; 501771fe6b9SJerome Glisse } 502771fe6b9SJerome Glisse 503771fe6b9SJerome Glisse void radeon_combios_fini(struct radeon_device *rdev) 504771fe6b9SJerome Glisse { 505771fe6b9SJerome Glisse } 506771fe6b9SJerome Glisse 50728d52043SDave Airlie /* if we get transitioned to only one device, tak VGA back */ 50828d52043SDave Airlie static unsigned int radeon_vga_set_decode(void *cookie, bool state) 50928d52043SDave Airlie { 51028d52043SDave Airlie struct radeon_device *rdev = cookie; 51128d52043SDave Airlie radeon_vga_set_state(rdev, state); 51228d52043SDave Airlie if (state) 51328d52043SDave Airlie return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | 51428d52043SDave Airlie VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; 51528d52043SDave Airlie else 51628d52043SDave Airlie return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; 51728d52043SDave Airlie } 518c1176d6fSDave Airlie 519b574f251SJerome Glisse void radeon_agp_disable(struct radeon_device *rdev) 520b574f251SJerome Glisse { 521b574f251SJerome Glisse rdev->flags &= ~RADEON_IS_AGP; 522b574f251SJerome Glisse if (rdev->family >= CHIP_R600) { 523b574f251SJerome Glisse DRM_INFO("Forcing AGP to PCIE mode\n"); 524b574f251SJerome Glisse rdev->flags |= RADEON_IS_PCIE; 525b574f251SJerome Glisse } else if (rdev->family >= CHIP_RV515 || 526b574f251SJerome Glisse rdev->family == CHIP_RV380 || 527b574f251SJerome Glisse rdev->family == CHIP_RV410 || 528b574f251SJerome Glisse rdev->family == CHIP_R423) { 529b574f251SJerome Glisse DRM_INFO("Forcing AGP to PCIE mode\n"); 530b574f251SJerome Glisse rdev->flags |= RADEON_IS_PCIE; 531b574f251SJerome Glisse rdev->asic->gart_tlb_flush = &rv370_pcie_gart_tlb_flush; 532b574f251SJerome Glisse rdev->asic->gart_set_page = &rv370_pcie_gart_set_page; 533b574f251SJerome Glisse } else { 534b574f251SJerome Glisse DRM_INFO("Forcing AGP to PCI mode\n"); 535b574f251SJerome Glisse rdev->flags |= RADEON_IS_PCI; 536b574f251SJerome Glisse rdev->asic->gart_tlb_flush = &r100_pci_gart_tlb_flush; 537b574f251SJerome Glisse rdev->asic->gart_set_page = &r100_pci_gart_set_page; 538b574f251SJerome Glisse } 539b574f251SJerome Glisse } 540771fe6b9SJerome Glisse 541771fe6b9SJerome Glisse /* 542771fe6b9SJerome Glisse * Radeon device. 543771fe6b9SJerome Glisse */ 544771fe6b9SJerome Glisse int radeon_device_init(struct radeon_device *rdev, 545771fe6b9SJerome Glisse struct drm_device *ddev, 546771fe6b9SJerome Glisse struct pci_dev *pdev, 547771fe6b9SJerome Glisse uint32_t flags) 548771fe6b9SJerome Glisse { 5496cf8a3f5SJerome Glisse int r; 550ad49f501SDave Airlie int dma_bits; 551771fe6b9SJerome Glisse 552771fe6b9SJerome Glisse DRM_INFO("radeon: Initializing kernel modesetting.\n"); 553771fe6b9SJerome Glisse rdev->shutdown = false; 5549f022ddfSJerome Glisse rdev->dev = &pdev->dev; 555771fe6b9SJerome Glisse rdev->ddev = ddev; 556771fe6b9SJerome Glisse rdev->pdev = pdev; 557771fe6b9SJerome Glisse rdev->flags = flags; 558771fe6b9SJerome Glisse rdev->family = flags & RADEON_FAMILY_MASK; 559771fe6b9SJerome Glisse rdev->is_atom_bios = false; 560771fe6b9SJerome Glisse rdev->usec_timeout = RADEON_MAX_USEC_TIMEOUT; 561771fe6b9SJerome Glisse rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; 562771fe6b9SJerome Glisse rdev->gpu_lockup = false; 563733289c2SJerome Glisse rdev->accel_working = false; 564771fe6b9SJerome Glisse /* mutex initialization are all done here so we 565771fe6b9SJerome Glisse * can recall function without having locking issues */ 566771fe6b9SJerome Glisse mutex_init(&rdev->cs_mutex); 567771fe6b9SJerome Glisse mutex_init(&rdev->ib_pool.mutex); 568771fe6b9SJerome Glisse mutex_init(&rdev->cp.mutex); 569d8f60cfcSAlex Deucher if (rdev->family >= CHIP_R600) 570d8f60cfcSAlex Deucher spin_lock_init(&rdev->ih.lock); 5714c788679SJerome Glisse mutex_init(&rdev->gem.mutex); 572771fe6b9SJerome Glisse rwlock_init(&rdev->fence_drv.lock); 5739f022ddfSJerome Glisse INIT_LIST_HEAD(&rdev->gem.objects); 574771fe6b9SJerome Glisse 575d4877cf2SAlex Deucher /* setup workqueue */ 576d4877cf2SAlex Deucher rdev->wq = create_workqueue("radeon"); 577d4877cf2SAlex Deucher if (rdev->wq == NULL) 578d4877cf2SAlex Deucher return -ENOMEM; 579d4877cf2SAlex Deucher 5804aac0473SJerome Glisse /* Set asic functions */ 5814aac0473SJerome Glisse r = radeon_asic_init(rdev); 5824aac0473SJerome Glisse if (r) { 5834aac0473SJerome Glisse return r; 5844aac0473SJerome Glisse } 5854aac0473SJerome Glisse 58630256a3fSJerome Glisse if (rdev->flags & RADEON_IS_AGP && radeon_agpmode == -1) { 587b574f251SJerome Glisse radeon_agp_disable(rdev); 588771fe6b9SJerome Glisse } 589771fe6b9SJerome Glisse 590ad49f501SDave Airlie /* set DMA mask + need_dma32 flags. 591ad49f501SDave Airlie * PCIE - can handle 40-bits. 592ad49f501SDave Airlie * IGP - can handle 40-bits (in theory) 593ad49f501SDave Airlie * AGP - generally dma32 is safest 594ad49f501SDave Airlie * PCI - only dma32 595ad49f501SDave Airlie */ 596ad49f501SDave Airlie rdev->need_dma32 = false; 597ad49f501SDave Airlie if (rdev->flags & RADEON_IS_AGP) 598ad49f501SDave Airlie rdev->need_dma32 = true; 599ad49f501SDave Airlie if (rdev->flags & RADEON_IS_PCI) 600ad49f501SDave Airlie rdev->need_dma32 = true; 601ad49f501SDave Airlie 602ad49f501SDave Airlie dma_bits = rdev->need_dma32 ? 32 : 40; 603ad49f501SDave Airlie r = pci_set_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits)); 604771fe6b9SJerome Glisse if (r) { 605771fe6b9SJerome Glisse printk(KERN_WARNING "radeon: No suitable DMA available.\n"); 606771fe6b9SJerome Glisse } 607771fe6b9SJerome Glisse 608771fe6b9SJerome Glisse /* Registers mapping */ 609771fe6b9SJerome Glisse /* TODO: block userspace mapping of io register */ 610771fe6b9SJerome Glisse rdev->rmmio_base = drm_get_resource_start(rdev->ddev, 2); 611771fe6b9SJerome Glisse rdev->rmmio_size = drm_get_resource_len(rdev->ddev, 2); 612771fe6b9SJerome Glisse rdev->rmmio = ioremap(rdev->rmmio_base, rdev->rmmio_size); 613771fe6b9SJerome Glisse if (rdev->rmmio == NULL) { 614771fe6b9SJerome Glisse return -ENOMEM; 615771fe6b9SJerome Glisse } 616771fe6b9SJerome Glisse DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)rdev->rmmio_base); 617771fe6b9SJerome Glisse DRM_INFO("register mmio size: %u\n", (unsigned)rdev->rmmio_size); 618771fe6b9SJerome Glisse 61928d52043SDave Airlie /* if we have > 1 VGA cards, then disable the radeon VGA resources */ 62093239ea1SDave Airlie /* this will fail for cards that aren't VGA class devices, just 62193239ea1SDave Airlie * ignore it */ 62293239ea1SDave Airlie vga_client_register(rdev->pdev, rdev, NULL, radeon_vga_set_decode); 62328d52043SDave Airlie 6243ce0a23dSJerome Glisse r = radeon_init(rdev); 625b574f251SJerome Glisse if (r) 626b574f251SJerome Glisse return r; 627b1e3a6d1SMichel Dänzer 628b574f251SJerome Glisse if (rdev->flags & RADEON_IS_AGP && !rdev->accel_working) { 629b574f251SJerome Glisse /* Acceleration not working on AGP card try again 630b574f251SJerome Glisse * with fallback to PCI or PCIE GART 631b574f251SJerome Glisse */ 6321a029b76SJerome Glisse radeon_gpu_reset(rdev); 633b574f251SJerome Glisse radeon_fini(rdev); 634b574f251SJerome Glisse radeon_agp_disable(rdev); 635b574f251SJerome Glisse r = radeon_init(rdev); 6364aac0473SJerome Glisse if (r) 6374aac0473SJerome Glisse return r; 6383ce0a23dSJerome Glisse } 639ecc0b326SMichel Dänzer if (radeon_testing) { 640ecc0b326SMichel Dänzer radeon_test_moves(rdev); 641ecc0b326SMichel Dänzer } 642771fe6b9SJerome Glisse if (radeon_benchmarking) { 643771fe6b9SJerome Glisse radeon_benchmark(rdev); 644771fe6b9SJerome Glisse } 6456cf8a3f5SJerome Glisse return 0; 646771fe6b9SJerome Glisse } 647771fe6b9SJerome Glisse 648771fe6b9SJerome Glisse void radeon_device_fini(struct radeon_device *rdev) 649771fe6b9SJerome Glisse { 650771fe6b9SJerome Glisse DRM_INFO("radeon: finishing device.\n"); 651771fe6b9SJerome Glisse rdev->shutdown = true; 6523ce0a23dSJerome Glisse radeon_fini(rdev); 653d4877cf2SAlex Deucher destroy_workqueue(rdev->wq); 654c1176d6fSDave Airlie vga_client_register(rdev->pdev, NULL, NULL, NULL); 655771fe6b9SJerome Glisse iounmap(rdev->rmmio); 656771fe6b9SJerome Glisse rdev->rmmio = NULL; 657771fe6b9SJerome Glisse } 658771fe6b9SJerome Glisse 659771fe6b9SJerome Glisse 660771fe6b9SJerome Glisse /* 661771fe6b9SJerome Glisse * Suspend & resume. 662771fe6b9SJerome Glisse */ 663771fe6b9SJerome Glisse int radeon_suspend_kms(struct drm_device *dev, pm_message_t state) 664771fe6b9SJerome Glisse { 665771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 666771fe6b9SJerome Glisse struct drm_crtc *crtc; 6674c788679SJerome Glisse int r; 668771fe6b9SJerome Glisse 669771fe6b9SJerome Glisse if (dev == NULL || rdev == NULL) { 670771fe6b9SJerome Glisse return -ENODEV; 671771fe6b9SJerome Glisse } 672771fe6b9SJerome Glisse if (state.event == PM_EVENT_PRETHAW) { 673771fe6b9SJerome Glisse return 0; 674771fe6b9SJerome Glisse } 675771fe6b9SJerome Glisse /* unpin the front buffers */ 676771fe6b9SJerome Glisse list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 677771fe6b9SJerome Glisse struct radeon_framebuffer *rfb = to_radeon_framebuffer(crtc->fb); 6784c788679SJerome Glisse struct radeon_bo *robj; 679771fe6b9SJerome Glisse 680771fe6b9SJerome Glisse if (rfb == NULL || rfb->obj == NULL) { 681771fe6b9SJerome Glisse continue; 682771fe6b9SJerome Glisse } 683771fe6b9SJerome Glisse robj = rfb->obj->driver_private; 6844c788679SJerome Glisse if (robj != rdev->fbdev_rbo) { 6854c788679SJerome Glisse r = radeon_bo_reserve(robj, false); 6864c788679SJerome Glisse if (unlikely(r == 0)) { 6874c788679SJerome Glisse radeon_bo_unpin(robj); 6884c788679SJerome Glisse radeon_bo_unreserve(robj); 6894c788679SJerome Glisse } 690771fe6b9SJerome Glisse } 691771fe6b9SJerome Glisse } 692771fe6b9SJerome Glisse /* evict vram memory */ 6934c788679SJerome Glisse radeon_bo_evict_vram(rdev); 694771fe6b9SJerome Glisse /* wait for gpu to finish processing current batch */ 695771fe6b9SJerome Glisse radeon_fence_wait_last(rdev); 696771fe6b9SJerome Glisse 697f657c2a7SYang Zhao radeon_save_bios_scratch_regs(rdev); 698f657c2a7SYang Zhao 6993ce0a23dSJerome Glisse radeon_suspend(rdev); 700d4877cf2SAlex Deucher radeon_hpd_fini(rdev); 701771fe6b9SJerome Glisse /* evict remaining vram memory */ 7024c788679SJerome Glisse radeon_bo_evict_vram(rdev); 703771fe6b9SJerome Glisse 704771fe6b9SJerome Glisse pci_save_state(dev->pdev); 705771fe6b9SJerome Glisse if (state.event == PM_EVENT_SUSPEND) { 706771fe6b9SJerome Glisse /* Shut down the device */ 707771fe6b9SJerome Glisse pci_disable_device(dev->pdev); 708771fe6b9SJerome Glisse pci_set_power_state(dev->pdev, PCI_D3hot); 709771fe6b9SJerome Glisse } 710771fe6b9SJerome Glisse acquire_console_sem(); 711771fe6b9SJerome Glisse fb_set_suspend(rdev->fbdev_info, 1); 712771fe6b9SJerome Glisse release_console_sem(); 713771fe6b9SJerome Glisse return 0; 714771fe6b9SJerome Glisse } 715771fe6b9SJerome Glisse 716771fe6b9SJerome Glisse int radeon_resume_kms(struct drm_device *dev) 717771fe6b9SJerome Glisse { 718771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 719771fe6b9SJerome Glisse 720771fe6b9SJerome Glisse acquire_console_sem(); 721771fe6b9SJerome Glisse pci_set_power_state(dev->pdev, PCI_D0); 722771fe6b9SJerome Glisse pci_restore_state(dev->pdev); 723771fe6b9SJerome Glisse if (pci_enable_device(dev->pdev)) { 724771fe6b9SJerome Glisse release_console_sem(); 725771fe6b9SJerome Glisse return -1; 726771fe6b9SJerome Glisse } 727771fe6b9SJerome Glisse pci_set_master(dev->pdev); 7280ebf1717SDave Airlie /* resume AGP if in use */ 7290ebf1717SDave Airlie radeon_agp_resume(rdev); 7303ce0a23dSJerome Glisse radeon_resume(rdev); 731f657c2a7SYang Zhao radeon_restore_bios_scratch_regs(rdev); 732771fe6b9SJerome Glisse fb_set_suspend(rdev->fbdev_info, 0); 733771fe6b9SJerome Glisse release_console_sem(); 734771fe6b9SJerome Glisse 735d4877cf2SAlex Deucher /* reset hpd state */ 736d4877cf2SAlex Deucher radeon_hpd_init(rdev); 737771fe6b9SJerome Glisse /* blat the mode back in */ 738771fe6b9SJerome Glisse drm_helper_resume_force_mode(dev); 739771fe6b9SJerome Glisse return 0; 740771fe6b9SJerome Glisse } 741771fe6b9SJerome Glisse 742771fe6b9SJerome Glisse 743771fe6b9SJerome Glisse /* 744771fe6b9SJerome Glisse * Debugfs 745771fe6b9SJerome Glisse */ 746771fe6b9SJerome Glisse struct radeon_debugfs { 747771fe6b9SJerome Glisse struct drm_info_list *files; 748771fe6b9SJerome Glisse unsigned num_files; 749771fe6b9SJerome Glisse }; 750771fe6b9SJerome Glisse static struct radeon_debugfs _radeon_debugfs[RADEON_DEBUGFS_MAX_NUM_FILES]; 751771fe6b9SJerome Glisse static unsigned _radeon_debugfs_count = 0; 752771fe6b9SJerome Glisse 753771fe6b9SJerome Glisse int radeon_debugfs_add_files(struct radeon_device *rdev, 754771fe6b9SJerome Glisse struct drm_info_list *files, 755771fe6b9SJerome Glisse unsigned nfiles) 756771fe6b9SJerome Glisse { 757771fe6b9SJerome Glisse unsigned i; 758771fe6b9SJerome Glisse 759771fe6b9SJerome Glisse for (i = 0; i < _radeon_debugfs_count; i++) { 760771fe6b9SJerome Glisse if (_radeon_debugfs[i].files == files) { 761771fe6b9SJerome Glisse /* Already registered */ 762771fe6b9SJerome Glisse return 0; 763771fe6b9SJerome Glisse } 764771fe6b9SJerome Glisse } 765771fe6b9SJerome Glisse if ((_radeon_debugfs_count + nfiles) > RADEON_DEBUGFS_MAX_NUM_FILES) { 766771fe6b9SJerome Glisse DRM_ERROR("Reached maximum number of debugfs files.\n"); 767771fe6b9SJerome Glisse DRM_ERROR("Report so we increase RADEON_DEBUGFS_MAX_NUM_FILES.\n"); 768771fe6b9SJerome Glisse return -EINVAL; 769771fe6b9SJerome Glisse } 770771fe6b9SJerome Glisse _radeon_debugfs[_radeon_debugfs_count].files = files; 771771fe6b9SJerome Glisse _radeon_debugfs[_radeon_debugfs_count].num_files = nfiles; 772771fe6b9SJerome Glisse _radeon_debugfs_count++; 773771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 774771fe6b9SJerome Glisse drm_debugfs_create_files(files, nfiles, 775771fe6b9SJerome Glisse rdev->ddev->control->debugfs_root, 776771fe6b9SJerome Glisse rdev->ddev->control); 777771fe6b9SJerome Glisse drm_debugfs_create_files(files, nfiles, 778771fe6b9SJerome Glisse rdev->ddev->primary->debugfs_root, 779771fe6b9SJerome Glisse rdev->ddev->primary); 780771fe6b9SJerome Glisse #endif 781771fe6b9SJerome Glisse return 0; 782771fe6b9SJerome Glisse } 783771fe6b9SJerome Glisse 784771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 785771fe6b9SJerome Glisse int radeon_debugfs_init(struct drm_minor *minor) 786771fe6b9SJerome Glisse { 787771fe6b9SJerome Glisse return 0; 788771fe6b9SJerome Glisse } 789771fe6b9SJerome Glisse 790771fe6b9SJerome Glisse void radeon_debugfs_cleanup(struct drm_minor *minor) 791771fe6b9SJerome Glisse { 792771fe6b9SJerome Glisse unsigned i; 793771fe6b9SJerome Glisse 794771fe6b9SJerome Glisse for (i = 0; i < _radeon_debugfs_count; i++) { 795771fe6b9SJerome Glisse drm_debugfs_remove_files(_radeon_debugfs[i].files, 796771fe6b9SJerome Glisse _radeon_debugfs[i].num_files, minor); 797771fe6b9SJerome Glisse } 798771fe6b9SJerome Glisse } 799771fe6b9SJerome Glisse #endif 800