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 47550e2d92SDave Airlie for (i = 0; i < RADEON_GEM_MAX_SURFACES; i++) { 48550e2d92SDave Airlie if (rdev->surface_regs[i].bo) 49550e2d92SDave Airlie radeon_bo_get_surface_reg(rdev->surface_regs[i].bo); 50550e2d92SDave Airlie else 51550e2d92SDave Airlie radeon_clear_surface_reg(rdev, i); 52b1e3a6d1SMichel Dänzer } 53e024e110SDave Airlie /* enable surfaces */ 54e024e110SDave Airlie WREG32(RADEON_SURFACE_CNTL, 0); 55b1e3a6d1SMichel Dänzer } 56b1e3a6d1SMichel Dänzer } 57b1e3a6d1SMichel Dänzer 58b1e3a6d1SMichel Dänzer /* 59771fe6b9SJerome Glisse * GPU scratch registers helpers function. 60771fe6b9SJerome Glisse */ 613ce0a23dSJerome Glisse void radeon_scratch_init(struct radeon_device *rdev) 62771fe6b9SJerome Glisse { 63771fe6b9SJerome Glisse int i; 64771fe6b9SJerome Glisse 65771fe6b9SJerome Glisse /* FIXME: check this out */ 66771fe6b9SJerome Glisse if (rdev->family < CHIP_R300) { 67771fe6b9SJerome Glisse rdev->scratch.num_reg = 5; 68771fe6b9SJerome Glisse } else { 69771fe6b9SJerome Glisse rdev->scratch.num_reg = 7; 70771fe6b9SJerome Glisse } 71771fe6b9SJerome Glisse for (i = 0; i < rdev->scratch.num_reg; i++) { 72771fe6b9SJerome Glisse rdev->scratch.free[i] = true; 73771fe6b9SJerome Glisse rdev->scratch.reg[i] = RADEON_SCRATCH_REG0 + (i * 4); 74771fe6b9SJerome Glisse } 75771fe6b9SJerome Glisse } 76771fe6b9SJerome Glisse 77771fe6b9SJerome Glisse int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg) 78771fe6b9SJerome Glisse { 79771fe6b9SJerome Glisse int i; 80771fe6b9SJerome Glisse 81771fe6b9SJerome Glisse for (i = 0; i < rdev->scratch.num_reg; i++) { 82771fe6b9SJerome Glisse if (rdev->scratch.free[i]) { 83771fe6b9SJerome Glisse rdev->scratch.free[i] = false; 84771fe6b9SJerome Glisse *reg = rdev->scratch.reg[i]; 85771fe6b9SJerome Glisse return 0; 86771fe6b9SJerome Glisse } 87771fe6b9SJerome Glisse } 88771fe6b9SJerome Glisse return -EINVAL; 89771fe6b9SJerome Glisse } 90771fe6b9SJerome Glisse 91771fe6b9SJerome Glisse void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg) 92771fe6b9SJerome Glisse { 93771fe6b9SJerome Glisse int i; 94771fe6b9SJerome Glisse 95771fe6b9SJerome Glisse for (i = 0; i < rdev->scratch.num_reg; i++) { 96771fe6b9SJerome Glisse if (rdev->scratch.reg[i] == reg) { 97771fe6b9SJerome Glisse rdev->scratch.free[i] = true; 98771fe6b9SJerome Glisse return; 99771fe6b9SJerome Glisse } 100771fe6b9SJerome Glisse } 101771fe6b9SJerome Glisse } 102771fe6b9SJerome Glisse 103*d594e46aSJerome Glisse /** 104*d594e46aSJerome Glisse * radeon_vram_location - try to find VRAM location 105*d594e46aSJerome Glisse * @rdev: radeon device structure holding all necessary informations 106*d594e46aSJerome Glisse * @mc: memory controller structure holding memory informations 107*d594e46aSJerome Glisse * @base: base address at which to put VRAM 108*d594e46aSJerome Glisse * 109*d594e46aSJerome Glisse * Function will place try to place VRAM at base address provided 110*d594e46aSJerome Glisse * as parameter (which is so far either PCI aperture address or 111*d594e46aSJerome Glisse * for IGP TOM base address). 112*d594e46aSJerome Glisse * 113*d594e46aSJerome Glisse * If there is not enough space to fit the unvisible VRAM in the 32bits 114*d594e46aSJerome Glisse * address space then we limit the VRAM size to the aperture. 115*d594e46aSJerome Glisse * 116*d594e46aSJerome Glisse * If we are using AGP and if the AGP aperture doesn't allow us to have 117*d594e46aSJerome Glisse * room for all the VRAM than we restrict the VRAM to the PCI aperture 118*d594e46aSJerome Glisse * size and print a warning. 119*d594e46aSJerome Glisse * 120*d594e46aSJerome Glisse * This function will never fails, worst case are limiting VRAM. 121*d594e46aSJerome Glisse * 122*d594e46aSJerome Glisse * Note: GTT start, end, size should be initialized before calling this 123*d594e46aSJerome Glisse * function on AGP platform. 124*d594e46aSJerome Glisse * 125*d594e46aSJerome Glisse * Note: We don't explictly enforce VRAM start to be aligned on VRAM size, 126*d594e46aSJerome Glisse * this shouldn't be a problem as we are using the PCI aperture as a reference. 127*d594e46aSJerome Glisse * Otherwise this would be needed for rv280, all r3xx, and all r4xx, but 128*d594e46aSJerome Glisse * not IGP. 129*d594e46aSJerome Glisse * 130*d594e46aSJerome Glisse * Note: we use mc_vram_size as on some board we need to program the mc to 131*d594e46aSJerome Glisse * cover the whole aperture even if VRAM size is inferior to aperture size 132*d594e46aSJerome Glisse * Novell bug 204882 + along with lots of ubuntu ones 133*d594e46aSJerome Glisse * 134*d594e46aSJerome Glisse * Note: when limiting vram it's safe to overwritte real_vram_size because 135*d594e46aSJerome Glisse * we are not in case where real_vram_size is inferior to mc_vram_size (ie 136*d594e46aSJerome Glisse * note afected by bogus hw of Novell bug 204882 + along with lots of ubuntu 137*d594e46aSJerome Glisse * ones) 138*d594e46aSJerome Glisse * 139*d594e46aSJerome Glisse * Note: IGP TOM addr should be the same as the aperture addr, we don't 140*d594e46aSJerome Glisse * explicitly check for that thought. 141*d594e46aSJerome Glisse * 142*d594e46aSJerome Glisse * FIXME: when reducing VRAM size align new size on power of 2. 143771fe6b9SJerome Glisse */ 144*d594e46aSJerome Glisse void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base) 145771fe6b9SJerome Glisse { 146*d594e46aSJerome Glisse mc->vram_start = base; 147*d594e46aSJerome Glisse if (mc->mc_vram_size > (0xFFFFFFFF - base + 1)) { 148*d594e46aSJerome Glisse dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n"); 149*d594e46aSJerome Glisse mc->real_vram_size = mc->aper_size; 150*d594e46aSJerome Glisse mc->mc_vram_size = mc->aper_size; 151771fe6b9SJerome Glisse } 152*d594e46aSJerome Glisse mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; 153*d594e46aSJerome Glisse if (rdev->flags & RADEON_IS_AGP && mc->vram_end > mc->gtt_start && mc->vram_end <= mc->gtt_end) { 154*d594e46aSJerome Glisse dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n"); 155*d594e46aSJerome Glisse mc->real_vram_size = mc->aper_size; 156*d594e46aSJerome Glisse mc->mc_vram_size = mc->aper_size; 157771fe6b9SJerome Glisse } 158*d594e46aSJerome Glisse mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; 159*d594e46aSJerome Glisse dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n", 160*d594e46aSJerome Glisse mc->mc_vram_size >> 20, mc->vram_start, 161*d594e46aSJerome Glisse mc->vram_end, mc->real_vram_size >> 20); 162771fe6b9SJerome Glisse } 163771fe6b9SJerome Glisse 164*d594e46aSJerome Glisse /** 165*d594e46aSJerome Glisse * radeon_gtt_location - try to find GTT location 166*d594e46aSJerome Glisse * @rdev: radeon device structure holding all necessary informations 167*d594e46aSJerome Glisse * @mc: memory controller structure holding memory informations 168*d594e46aSJerome Glisse * 169*d594e46aSJerome Glisse * Function will place try to place GTT before or after VRAM. 170*d594e46aSJerome Glisse * 171*d594e46aSJerome Glisse * If GTT size is bigger than space left then we ajust GTT size. 172*d594e46aSJerome Glisse * Thus function will never fails. 173*d594e46aSJerome Glisse * 174*d594e46aSJerome Glisse * FIXME: when reducing GTT size align new size on power of 2. 175*d594e46aSJerome Glisse */ 176*d594e46aSJerome Glisse void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc) 177*d594e46aSJerome Glisse { 178*d594e46aSJerome Glisse u64 size_af, size_bf; 179*d594e46aSJerome Glisse 180*d594e46aSJerome Glisse size_af = 0xFFFFFFFF - mc->vram_end; 181*d594e46aSJerome Glisse size_bf = mc->vram_start; 182*d594e46aSJerome Glisse if (size_bf > size_af) { 183*d594e46aSJerome Glisse if (mc->gtt_size > size_bf) { 184*d594e46aSJerome Glisse dev_warn(rdev->dev, "limiting GTT\n"); 185*d594e46aSJerome Glisse mc->gtt_size = size_bf; 186*d594e46aSJerome Glisse } 187*d594e46aSJerome Glisse mc->gtt_start = mc->vram_start - mc->gtt_size; 188*d594e46aSJerome Glisse } else { 189*d594e46aSJerome Glisse if (mc->gtt_size > size_af) { 190*d594e46aSJerome Glisse dev_warn(rdev->dev, "limiting GTT\n"); 191*d594e46aSJerome Glisse mc->gtt_size = size_af; 192*d594e46aSJerome Glisse } 193*d594e46aSJerome Glisse mc->gtt_start = mc->vram_end + 1; 194*d594e46aSJerome Glisse } 195*d594e46aSJerome Glisse mc->gtt_end = mc->gtt_start + mc->gtt_size - 1; 196*d594e46aSJerome Glisse dev_info(rdev->dev, "GTT: %lluM 0x%08llX - 0x%08llX\n", 197*d594e46aSJerome Glisse mc->gtt_size >> 20, mc->gtt_start, mc->gtt_end); 198*d594e46aSJerome Glisse } 199771fe6b9SJerome Glisse 200771fe6b9SJerome Glisse /* 201771fe6b9SJerome Glisse * GPU helpers function. 202771fe6b9SJerome Glisse */ 2039f022ddfSJerome Glisse bool radeon_card_posted(struct radeon_device *rdev) 204771fe6b9SJerome Glisse { 205771fe6b9SJerome Glisse uint32_t reg; 206771fe6b9SJerome Glisse 207771fe6b9SJerome Glisse /* first check CRTCs */ 208bcc1c2a1SAlex Deucher if (ASIC_IS_DCE4(rdev)) { 209bcc1c2a1SAlex Deucher reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) | 210bcc1c2a1SAlex Deucher RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) | 211bcc1c2a1SAlex Deucher RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) | 212bcc1c2a1SAlex Deucher RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) | 213bcc1c2a1SAlex Deucher RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) | 214bcc1c2a1SAlex Deucher RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET); 215bcc1c2a1SAlex Deucher if (reg & EVERGREEN_CRTC_MASTER_EN) 216bcc1c2a1SAlex Deucher return true; 217bcc1c2a1SAlex Deucher } else if (ASIC_IS_AVIVO(rdev)) { 218771fe6b9SJerome Glisse reg = RREG32(AVIVO_D1CRTC_CONTROL) | 219771fe6b9SJerome Glisse RREG32(AVIVO_D2CRTC_CONTROL); 220771fe6b9SJerome Glisse if (reg & AVIVO_CRTC_EN) { 221771fe6b9SJerome Glisse return true; 222771fe6b9SJerome Glisse } 223771fe6b9SJerome Glisse } else { 224771fe6b9SJerome Glisse reg = RREG32(RADEON_CRTC_GEN_CNTL) | 225771fe6b9SJerome Glisse RREG32(RADEON_CRTC2_GEN_CNTL); 226771fe6b9SJerome Glisse if (reg & RADEON_CRTC_EN) { 227771fe6b9SJerome Glisse return true; 228771fe6b9SJerome Glisse } 229771fe6b9SJerome Glisse } 230771fe6b9SJerome Glisse 231771fe6b9SJerome Glisse /* then check MEM_SIZE, in case the crtcs are off */ 232771fe6b9SJerome Glisse if (rdev->family >= CHIP_R600) 233771fe6b9SJerome Glisse reg = RREG32(R600_CONFIG_MEMSIZE); 234771fe6b9SJerome Glisse else 235771fe6b9SJerome Glisse reg = RREG32(RADEON_CONFIG_MEMSIZE); 236771fe6b9SJerome Glisse 237771fe6b9SJerome Glisse if (reg) 238771fe6b9SJerome Glisse return true; 239771fe6b9SJerome Glisse 240771fe6b9SJerome Glisse return false; 241771fe6b9SJerome Glisse 242771fe6b9SJerome Glisse } 243771fe6b9SJerome Glisse 24472542d77SDave Airlie bool radeon_boot_test_post_card(struct radeon_device *rdev) 24572542d77SDave Airlie { 24672542d77SDave Airlie if (radeon_card_posted(rdev)) 24772542d77SDave Airlie return true; 24872542d77SDave Airlie 24972542d77SDave Airlie if (rdev->bios) { 25072542d77SDave Airlie DRM_INFO("GPU not posted. posting now...\n"); 25172542d77SDave Airlie if (rdev->is_atom_bios) 25272542d77SDave Airlie atom_asic_init(rdev->mode_info.atom_context); 25372542d77SDave Airlie else 25472542d77SDave Airlie radeon_combios_asic_init(rdev->ddev); 25572542d77SDave Airlie return true; 25672542d77SDave Airlie } else { 25772542d77SDave Airlie dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n"); 25872542d77SDave Airlie return false; 25972542d77SDave Airlie } 26072542d77SDave Airlie } 26172542d77SDave Airlie 2623ce0a23dSJerome Glisse int radeon_dummy_page_init(struct radeon_device *rdev) 2633ce0a23dSJerome Glisse { 26482568565SDave Airlie if (rdev->dummy_page.page) 26582568565SDave Airlie return 0; 2663ce0a23dSJerome Glisse rdev->dummy_page.page = alloc_page(GFP_DMA32 | GFP_KERNEL | __GFP_ZERO); 2673ce0a23dSJerome Glisse if (rdev->dummy_page.page == NULL) 2683ce0a23dSJerome Glisse return -ENOMEM; 2693ce0a23dSJerome Glisse rdev->dummy_page.addr = pci_map_page(rdev->pdev, rdev->dummy_page.page, 2703ce0a23dSJerome Glisse 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 2713ce0a23dSJerome Glisse if (!rdev->dummy_page.addr) { 2723ce0a23dSJerome Glisse __free_page(rdev->dummy_page.page); 2733ce0a23dSJerome Glisse rdev->dummy_page.page = NULL; 2743ce0a23dSJerome Glisse return -ENOMEM; 2753ce0a23dSJerome Glisse } 2763ce0a23dSJerome Glisse return 0; 2773ce0a23dSJerome Glisse } 2783ce0a23dSJerome Glisse 2793ce0a23dSJerome Glisse void radeon_dummy_page_fini(struct radeon_device *rdev) 2803ce0a23dSJerome Glisse { 2813ce0a23dSJerome Glisse if (rdev->dummy_page.page == NULL) 2823ce0a23dSJerome Glisse return; 2833ce0a23dSJerome Glisse pci_unmap_page(rdev->pdev, rdev->dummy_page.addr, 2843ce0a23dSJerome Glisse PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 2853ce0a23dSJerome Glisse __free_page(rdev->dummy_page.page); 2863ce0a23dSJerome Glisse rdev->dummy_page.page = NULL; 2873ce0a23dSJerome Glisse } 2883ce0a23dSJerome Glisse 289771fe6b9SJerome Glisse 290771fe6b9SJerome Glisse /* 291771fe6b9SJerome Glisse * Registers accessors functions. 292771fe6b9SJerome Glisse */ 293771fe6b9SJerome Glisse uint32_t radeon_invalid_rreg(struct radeon_device *rdev, uint32_t reg) 294771fe6b9SJerome Glisse { 295771fe6b9SJerome Glisse DRM_ERROR("Invalid callback to read register 0x%04X\n", reg); 296771fe6b9SJerome Glisse BUG_ON(1); 297771fe6b9SJerome Glisse return 0; 298771fe6b9SJerome Glisse } 299771fe6b9SJerome Glisse 300771fe6b9SJerome Glisse void radeon_invalid_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v) 301771fe6b9SJerome Glisse { 302771fe6b9SJerome Glisse DRM_ERROR("Invalid callback to write register 0x%04X with 0x%08X\n", 303771fe6b9SJerome Glisse reg, v); 304771fe6b9SJerome Glisse BUG_ON(1); 305771fe6b9SJerome Glisse } 306771fe6b9SJerome Glisse 307771fe6b9SJerome Glisse void radeon_register_accessor_init(struct radeon_device *rdev) 308771fe6b9SJerome Glisse { 309771fe6b9SJerome Glisse rdev->mc_rreg = &radeon_invalid_rreg; 310771fe6b9SJerome Glisse rdev->mc_wreg = &radeon_invalid_wreg; 311771fe6b9SJerome Glisse rdev->pll_rreg = &radeon_invalid_rreg; 312771fe6b9SJerome Glisse rdev->pll_wreg = &radeon_invalid_wreg; 313771fe6b9SJerome Glisse rdev->pciep_rreg = &radeon_invalid_rreg; 314771fe6b9SJerome Glisse rdev->pciep_wreg = &radeon_invalid_wreg; 315771fe6b9SJerome Glisse 316771fe6b9SJerome Glisse /* Don't change order as we are overridding accessor. */ 317771fe6b9SJerome Glisse if (rdev->family < CHIP_RV515) { 318de1b2898SDave Airlie rdev->pcie_reg_mask = 0xff; 319de1b2898SDave Airlie } else { 320de1b2898SDave Airlie rdev->pcie_reg_mask = 0x7ff; 321771fe6b9SJerome Glisse } 322771fe6b9SJerome Glisse /* FIXME: not sure here */ 323771fe6b9SJerome Glisse if (rdev->family <= CHIP_R580) { 324771fe6b9SJerome Glisse rdev->pll_rreg = &r100_pll_rreg; 325771fe6b9SJerome Glisse rdev->pll_wreg = &r100_pll_wreg; 326771fe6b9SJerome Glisse } 327905b6822SJerome Glisse if (rdev->family >= CHIP_R420) { 328905b6822SJerome Glisse rdev->mc_rreg = &r420_mc_rreg; 329905b6822SJerome Glisse rdev->mc_wreg = &r420_mc_wreg; 330905b6822SJerome Glisse } 331771fe6b9SJerome Glisse if (rdev->family >= CHIP_RV515) { 332771fe6b9SJerome Glisse rdev->mc_rreg = &rv515_mc_rreg; 333771fe6b9SJerome Glisse rdev->mc_wreg = &rv515_mc_wreg; 334771fe6b9SJerome Glisse } 335771fe6b9SJerome Glisse if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480) { 336771fe6b9SJerome Glisse rdev->mc_rreg = &rs400_mc_rreg; 337771fe6b9SJerome Glisse rdev->mc_wreg = &rs400_mc_wreg; 338771fe6b9SJerome Glisse } 339771fe6b9SJerome Glisse if (rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) { 340771fe6b9SJerome Glisse rdev->mc_rreg = &rs690_mc_rreg; 341771fe6b9SJerome Glisse rdev->mc_wreg = &rs690_mc_wreg; 342771fe6b9SJerome Glisse } 343771fe6b9SJerome Glisse if (rdev->family == CHIP_RS600) { 344771fe6b9SJerome Glisse rdev->mc_rreg = &rs600_mc_rreg; 345771fe6b9SJerome Glisse rdev->mc_wreg = &rs600_mc_wreg; 346771fe6b9SJerome Glisse } 347bcc1c2a1SAlex Deucher if ((rdev->family >= CHIP_R600) && (rdev->family <= CHIP_RV740)) { 348771fe6b9SJerome Glisse rdev->pciep_rreg = &r600_pciep_rreg; 349771fe6b9SJerome Glisse rdev->pciep_wreg = &r600_pciep_wreg; 350771fe6b9SJerome Glisse } 351771fe6b9SJerome Glisse } 352771fe6b9SJerome Glisse 353771fe6b9SJerome Glisse 354771fe6b9SJerome Glisse /* 355771fe6b9SJerome Glisse * ASIC 356771fe6b9SJerome Glisse */ 357771fe6b9SJerome Glisse int radeon_asic_init(struct radeon_device *rdev) 358771fe6b9SJerome Glisse { 359771fe6b9SJerome Glisse radeon_register_accessor_init(rdev); 360771fe6b9SJerome Glisse switch (rdev->family) { 361771fe6b9SJerome Glisse case CHIP_R100: 362771fe6b9SJerome Glisse case CHIP_RV100: 363771fe6b9SJerome Glisse case CHIP_RS100: 364771fe6b9SJerome Glisse case CHIP_RV200: 365771fe6b9SJerome Glisse case CHIP_RS200: 36644ca7478SPauli Nieminen rdev->asic = &r100_asic; 36744ca7478SPauli Nieminen break; 368771fe6b9SJerome Glisse case CHIP_R200: 369771fe6b9SJerome Glisse case CHIP_RV250: 370771fe6b9SJerome Glisse case CHIP_RS300: 371771fe6b9SJerome Glisse case CHIP_RV280: 37244ca7478SPauli Nieminen rdev->asic = &r200_asic; 373771fe6b9SJerome Glisse break; 374771fe6b9SJerome Glisse case CHIP_R300: 375771fe6b9SJerome Glisse case CHIP_R350: 376771fe6b9SJerome Glisse case CHIP_RV350: 377771fe6b9SJerome Glisse case CHIP_RV380: 378d80eeb0fSPauli Nieminen if (rdev->flags & RADEON_IS_PCIE) 379d80eeb0fSPauli Nieminen rdev->asic = &r300_asic_pcie; 380d80eeb0fSPauli Nieminen else 381771fe6b9SJerome Glisse rdev->asic = &r300_asic; 382771fe6b9SJerome Glisse break; 383771fe6b9SJerome Glisse case CHIP_R420: 384771fe6b9SJerome Glisse case CHIP_R423: 385771fe6b9SJerome Glisse case CHIP_RV410: 386771fe6b9SJerome Glisse rdev->asic = &r420_asic; 387771fe6b9SJerome Glisse break; 388771fe6b9SJerome Glisse case CHIP_RS400: 389771fe6b9SJerome Glisse case CHIP_RS480: 390771fe6b9SJerome Glisse rdev->asic = &rs400_asic; 391771fe6b9SJerome Glisse break; 392771fe6b9SJerome Glisse case CHIP_RS600: 393771fe6b9SJerome Glisse rdev->asic = &rs600_asic; 394771fe6b9SJerome Glisse break; 395771fe6b9SJerome Glisse case CHIP_RS690: 396771fe6b9SJerome Glisse case CHIP_RS740: 397771fe6b9SJerome Glisse rdev->asic = &rs690_asic; 398771fe6b9SJerome Glisse break; 399771fe6b9SJerome Glisse case CHIP_RV515: 400771fe6b9SJerome Glisse rdev->asic = &rv515_asic; 401771fe6b9SJerome Glisse break; 402771fe6b9SJerome Glisse case CHIP_R520: 403771fe6b9SJerome Glisse case CHIP_RV530: 404771fe6b9SJerome Glisse case CHIP_RV560: 405771fe6b9SJerome Glisse case CHIP_RV570: 406771fe6b9SJerome Glisse case CHIP_R580: 407771fe6b9SJerome Glisse rdev->asic = &r520_asic; 408771fe6b9SJerome Glisse break; 409771fe6b9SJerome Glisse case CHIP_R600: 410771fe6b9SJerome Glisse case CHIP_RV610: 411771fe6b9SJerome Glisse case CHIP_RV630: 412771fe6b9SJerome Glisse case CHIP_RV620: 413771fe6b9SJerome Glisse case CHIP_RV635: 414771fe6b9SJerome Glisse case CHIP_RV670: 415771fe6b9SJerome Glisse case CHIP_RS780: 4163ce0a23dSJerome Glisse case CHIP_RS880: 4173ce0a23dSJerome Glisse rdev->asic = &r600_asic; 4183ce0a23dSJerome Glisse break; 419771fe6b9SJerome Glisse case CHIP_RV770: 420771fe6b9SJerome Glisse case CHIP_RV730: 421771fe6b9SJerome Glisse case CHIP_RV710: 4223ce0a23dSJerome Glisse case CHIP_RV740: 4233ce0a23dSJerome Glisse rdev->asic = &rv770_asic; 4243ce0a23dSJerome Glisse break; 425bcc1c2a1SAlex Deucher case CHIP_CEDAR: 426bcc1c2a1SAlex Deucher case CHIP_REDWOOD: 427bcc1c2a1SAlex Deucher case CHIP_JUNIPER: 428bcc1c2a1SAlex Deucher case CHIP_CYPRESS: 429bcc1c2a1SAlex Deucher case CHIP_HEMLOCK: 430bcc1c2a1SAlex Deucher rdev->asic = &evergreen_asic; 431bcc1c2a1SAlex Deucher break; 432771fe6b9SJerome Glisse default: 433771fe6b9SJerome Glisse /* FIXME: not supported yet */ 434771fe6b9SJerome Glisse return -EINVAL; 435771fe6b9SJerome Glisse } 4365ea597f3SRafał Miłecki 4375ea597f3SRafał Miłecki if (rdev->flags & RADEON_IS_IGP) { 4385ea597f3SRafał Miłecki rdev->asic->get_memory_clock = NULL; 4395ea597f3SRafał Miłecki rdev->asic->set_memory_clock = NULL; 4405ea597f3SRafał Miłecki } 4415ea597f3SRafał Miłecki 442771fe6b9SJerome Glisse return 0; 443771fe6b9SJerome Glisse } 444771fe6b9SJerome Glisse 445771fe6b9SJerome Glisse 446771fe6b9SJerome Glisse /* 447771fe6b9SJerome Glisse * Wrapper around modesetting bits. 448771fe6b9SJerome Glisse */ 449771fe6b9SJerome Glisse int radeon_clocks_init(struct radeon_device *rdev) 450771fe6b9SJerome Glisse { 451771fe6b9SJerome Glisse int r; 452771fe6b9SJerome Glisse 453771fe6b9SJerome Glisse r = radeon_static_clocks_init(rdev->ddev); 454771fe6b9SJerome Glisse if (r) { 455771fe6b9SJerome Glisse return r; 456771fe6b9SJerome Glisse } 457771fe6b9SJerome Glisse DRM_INFO("Clocks initialized !\n"); 458771fe6b9SJerome Glisse return 0; 459771fe6b9SJerome Glisse } 460771fe6b9SJerome Glisse 461771fe6b9SJerome Glisse void radeon_clocks_fini(struct radeon_device *rdev) 462771fe6b9SJerome Glisse { 463771fe6b9SJerome Glisse } 464771fe6b9SJerome Glisse 465771fe6b9SJerome Glisse /* ATOM accessor methods */ 466771fe6b9SJerome Glisse static uint32_t cail_pll_read(struct card_info *info, uint32_t reg) 467771fe6b9SJerome Glisse { 468771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 469771fe6b9SJerome Glisse uint32_t r; 470771fe6b9SJerome Glisse 471771fe6b9SJerome Glisse r = rdev->pll_rreg(rdev, reg); 472771fe6b9SJerome Glisse return r; 473771fe6b9SJerome Glisse } 474771fe6b9SJerome Glisse 475771fe6b9SJerome Glisse static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val) 476771fe6b9SJerome Glisse { 477771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 478771fe6b9SJerome Glisse 479771fe6b9SJerome Glisse rdev->pll_wreg(rdev, reg, val); 480771fe6b9SJerome Glisse } 481771fe6b9SJerome Glisse 482771fe6b9SJerome Glisse static uint32_t cail_mc_read(struct card_info *info, uint32_t reg) 483771fe6b9SJerome Glisse { 484771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 485771fe6b9SJerome Glisse uint32_t r; 486771fe6b9SJerome Glisse 487771fe6b9SJerome Glisse r = rdev->mc_rreg(rdev, reg); 488771fe6b9SJerome Glisse return r; 489771fe6b9SJerome Glisse } 490771fe6b9SJerome Glisse 491771fe6b9SJerome Glisse static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val) 492771fe6b9SJerome Glisse { 493771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 494771fe6b9SJerome Glisse 495771fe6b9SJerome Glisse rdev->mc_wreg(rdev, reg, val); 496771fe6b9SJerome Glisse } 497771fe6b9SJerome Glisse 498771fe6b9SJerome Glisse static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val) 499771fe6b9SJerome Glisse { 500771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 501771fe6b9SJerome Glisse 502771fe6b9SJerome Glisse WREG32(reg*4, val); 503771fe6b9SJerome Glisse } 504771fe6b9SJerome Glisse 505771fe6b9SJerome Glisse static uint32_t cail_reg_read(struct card_info *info, uint32_t reg) 506771fe6b9SJerome Glisse { 507771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 508771fe6b9SJerome Glisse uint32_t r; 509771fe6b9SJerome Glisse 510771fe6b9SJerome Glisse r = RREG32(reg*4); 511771fe6b9SJerome Glisse return r; 512771fe6b9SJerome Glisse } 513771fe6b9SJerome Glisse 514771fe6b9SJerome Glisse int radeon_atombios_init(struct radeon_device *rdev) 515771fe6b9SJerome Glisse { 51661c4b24bSMathias Fröhlich struct card_info *atom_card_info = 51761c4b24bSMathias Fröhlich kzalloc(sizeof(struct card_info), GFP_KERNEL); 51861c4b24bSMathias Fröhlich 51961c4b24bSMathias Fröhlich if (!atom_card_info) 52061c4b24bSMathias Fröhlich return -ENOMEM; 52161c4b24bSMathias Fröhlich 52261c4b24bSMathias Fröhlich rdev->mode_info.atom_card_info = atom_card_info; 52361c4b24bSMathias Fröhlich atom_card_info->dev = rdev->ddev; 52461c4b24bSMathias Fröhlich atom_card_info->reg_read = cail_reg_read; 52561c4b24bSMathias Fröhlich atom_card_info->reg_write = cail_reg_write; 52661c4b24bSMathias Fröhlich atom_card_info->mc_read = cail_mc_read; 52761c4b24bSMathias Fröhlich atom_card_info->mc_write = cail_mc_write; 52861c4b24bSMathias Fröhlich atom_card_info->pll_read = cail_pll_read; 52961c4b24bSMathias Fröhlich atom_card_info->pll_write = cail_pll_write; 53061c4b24bSMathias Fröhlich 53161c4b24bSMathias Fröhlich rdev->mode_info.atom_context = atom_parse(atom_card_info, rdev->bios); 532c31ad97fSRafał Miłecki mutex_init(&rdev->mode_info.atom_context->mutex); 533771fe6b9SJerome Glisse radeon_atom_initialize_bios_scratch_regs(rdev->ddev); 534d904ef9bSDave Airlie atom_allocate_fb_scratch(rdev->mode_info.atom_context); 535771fe6b9SJerome Glisse return 0; 536771fe6b9SJerome Glisse } 537771fe6b9SJerome Glisse 538771fe6b9SJerome Glisse void radeon_atombios_fini(struct radeon_device *rdev) 539771fe6b9SJerome Glisse { 5404a04a844SJerome Glisse if (rdev->mode_info.atom_context) { 541d904ef9bSDave Airlie kfree(rdev->mode_info.atom_context->scratch); 542771fe6b9SJerome Glisse kfree(rdev->mode_info.atom_context); 5434a04a844SJerome Glisse } 54461c4b24bSMathias Fröhlich kfree(rdev->mode_info.atom_card_info); 545771fe6b9SJerome Glisse } 546771fe6b9SJerome Glisse 547771fe6b9SJerome Glisse int radeon_combios_init(struct radeon_device *rdev) 548771fe6b9SJerome Glisse { 549771fe6b9SJerome Glisse radeon_combios_initialize_bios_scratch_regs(rdev->ddev); 550771fe6b9SJerome Glisse return 0; 551771fe6b9SJerome Glisse } 552771fe6b9SJerome Glisse 553771fe6b9SJerome Glisse void radeon_combios_fini(struct radeon_device *rdev) 554771fe6b9SJerome Glisse { 555771fe6b9SJerome Glisse } 556771fe6b9SJerome Glisse 55728d52043SDave Airlie /* if we get transitioned to only one device, tak VGA back */ 55828d52043SDave Airlie static unsigned int radeon_vga_set_decode(void *cookie, bool state) 55928d52043SDave Airlie { 56028d52043SDave Airlie struct radeon_device *rdev = cookie; 56128d52043SDave Airlie radeon_vga_set_state(rdev, state); 56228d52043SDave Airlie if (state) 56328d52043SDave Airlie return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | 56428d52043SDave Airlie VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; 56528d52043SDave Airlie else 56628d52043SDave Airlie return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; 56728d52043SDave Airlie } 568c1176d6fSDave Airlie 569b574f251SJerome Glisse void radeon_agp_disable(struct radeon_device *rdev) 570b574f251SJerome Glisse { 571b574f251SJerome Glisse rdev->flags &= ~RADEON_IS_AGP; 572b574f251SJerome Glisse if (rdev->family >= CHIP_R600) { 573b574f251SJerome Glisse DRM_INFO("Forcing AGP to PCIE mode\n"); 574b574f251SJerome Glisse rdev->flags |= RADEON_IS_PCIE; 575b574f251SJerome Glisse } else if (rdev->family >= CHIP_RV515 || 576b574f251SJerome Glisse rdev->family == CHIP_RV380 || 577b574f251SJerome Glisse rdev->family == CHIP_RV410 || 578b574f251SJerome Glisse rdev->family == CHIP_R423) { 579b574f251SJerome Glisse DRM_INFO("Forcing AGP to PCIE mode\n"); 580b574f251SJerome Glisse rdev->flags |= RADEON_IS_PCIE; 581b574f251SJerome Glisse rdev->asic->gart_tlb_flush = &rv370_pcie_gart_tlb_flush; 582b574f251SJerome Glisse rdev->asic->gart_set_page = &rv370_pcie_gart_set_page; 583b574f251SJerome Glisse } else { 584b574f251SJerome Glisse DRM_INFO("Forcing AGP to PCI mode\n"); 585b574f251SJerome Glisse rdev->flags |= RADEON_IS_PCI; 586b574f251SJerome Glisse rdev->asic->gart_tlb_flush = &r100_pci_gart_tlb_flush; 587b574f251SJerome Glisse rdev->asic->gart_set_page = &r100_pci_gart_set_page; 588b574f251SJerome Glisse } 589700a0cc0SJerome Glisse rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; 590b574f251SJerome Glisse } 591771fe6b9SJerome Glisse 59236421338SJerome Glisse void radeon_check_arguments(struct radeon_device *rdev) 59336421338SJerome Glisse { 59436421338SJerome Glisse /* vramlimit must be a power of two */ 59536421338SJerome Glisse switch (radeon_vram_limit) { 59636421338SJerome Glisse case 0: 59736421338SJerome Glisse case 4: 59836421338SJerome Glisse case 8: 59936421338SJerome Glisse case 16: 60036421338SJerome Glisse case 32: 60136421338SJerome Glisse case 64: 60236421338SJerome Glisse case 128: 60336421338SJerome Glisse case 256: 60436421338SJerome Glisse case 512: 60536421338SJerome Glisse case 1024: 60636421338SJerome Glisse case 2048: 60736421338SJerome Glisse case 4096: 60836421338SJerome Glisse break; 60936421338SJerome Glisse default: 61036421338SJerome Glisse dev_warn(rdev->dev, "vram limit (%d) must be a power of 2\n", 61136421338SJerome Glisse radeon_vram_limit); 61236421338SJerome Glisse radeon_vram_limit = 0; 61336421338SJerome Glisse break; 61436421338SJerome Glisse } 61536421338SJerome Glisse radeon_vram_limit = radeon_vram_limit << 20; 61636421338SJerome Glisse /* gtt size must be power of two and greater or equal to 32M */ 61736421338SJerome Glisse switch (radeon_gart_size) { 61836421338SJerome Glisse case 4: 61936421338SJerome Glisse case 8: 62036421338SJerome Glisse case 16: 62136421338SJerome Glisse dev_warn(rdev->dev, "gart size (%d) too small forcing to 512M\n", 62236421338SJerome Glisse radeon_gart_size); 62336421338SJerome Glisse radeon_gart_size = 512; 62436421338SJerome Glisse break; 62536421338SJerome Glisse case 32: 62636421338SJerome Glisse case 64: 62736421338SJerome Glisse case 128: 62836421338SJerome Glisse case 256: 62936421338SJerome Glisse case 512: 63036421338SJerome Glisse case 1024: 63136421338SJerome Glisse case 2048: 63236421338SJerome Glisse case 4096: 63336421338SJerome Glisse break; 63436421338SJerome Glisse default: 63536421338SJerome Glisse dev_warn(rdev->dev, "gart size (%d) must be a power of 2\n", 63636421338SJerome Glisse radeon_gart_size); 63736421338SJerome Glisse radeon_gart_size = 512; 63836421338SJerome Glisse break; 63936421338SJerome Glisse } 64036421338SJerome Glisse rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; 64136421338SJerome Glisse /* AGP mode can only be -1, 1, 2, 4, 8 */ 64236421338SJerome Glisse switch (radeon_agpmode) { 64336421338SJerome Glisse case -1: 64436421338SJerome Glisse case 0: 64536421338SJerome Glisse case 1: 64636421338SJerome Glisse case 2: 64736421338SJerome Glisse case 4: 64836421338SJerome Glisse case 8: 64936421338SJerome Glisse break; 65036421338SJerome Glisse default: 65136421338SJerome Glisse dev_warn(rdev->dev, "invalid AGP mode %d (valid mode: " 65236421338SJerome Glisse "-1, 0, 1, 2, 4, 8)\n", radeon_agpmode); 65336421338SJerome Glisse radeon_agpmode = 0; 65436421338SJerome Glisse break; 65536421338SJerome Glisse } 65636421338SJerome Glisse } 65736421338SJerome Glisse 658771fe6b9SJerome Glisse int radeon_device_init(struct radeon_device *rdev, 659771fe6b9SJerome Glisse struct drm_device *ddev, 660771fe6b9SJerome Glisse struct pci_dev *pdev, 661771fe6b9SJerome Glisse uint32_t flags) 662771fe6b9SJerome Glisse { 6636cf8a3f5SJerome Glisse int r; 664ad49f501SDave Airlie int dma_bits; 665771fe6b9SJerome Glisse 666771fe6b9SJerome Glisse DRM_INFO("radeon: Initializing kernel modesetting.\n"); 667771fe6b9SJerome Glisse rdev->shutdown = false; 6689f022ddfSJerome Glisse rdev->dev = &pdev->dev; 669771fe6b9SJerome Glisse rdev->ddev = ddev; 670771fe6b9SJerome Glisse rdev->pdev = pdev; 671771fe6b9SJerome Glisse rdev->flags = flags; 672771fe6b9SJerome Glisse rdev->family = flags & RADEON_FAMILY_MASK; 673771fe6b9SJerome Glisse rdev->is_atom_bios = false; 674771fe6b9SJerome Glisse rdev->usec_timeout = RADEON_MAX_USEC_TIMEOUT; 675771fe6b9SJerome Glisse rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; 676771fe6b9SJerome Glisse rdev->gpu_lockup = false; 677733289c2SJerome Glisse rdev->accel_working = false; 678771fe6b9SJerome Glisse /* mutex initialization are all done here so we 679771fe6b9SJerome Glisse * can recall function without having locking issues */ 680771fe6b9SJerome Glisse mutex_init(&rdev->cs_mutex); 681771fe6b9SJerome Glisse mutex_init(&rdev->ib_pool.mutex); 682771fe6b9SJerome Glisse mutex_init(&rdev->cp.mutex); 68340bacf16SAlex Deucher mutex_init(&rdev->dc_hw_i2c_mutex); 684d8f60cfcSAlex Deucher if (rdev->family >= CHIP_R600) 685d8f60cfcSAlex Deucher spin_lock_init(&rdev->ih.lock); 6864c788679SJerome Glisse mutex_init(&rdev->gem.mutex); 687c913e23aSRafał Miłecki mutex_init(&rdev->pm.mutex); 688771fe6b9SJerome Glisse rwlock_init(&rdev->fence_drv.lock); 6899f022ddfSJerome Glisse INIT_LIST_HEAD(&rdev->gem.objects); 69073a6d3fcSRafał Miłecki init_waitqueue_head(&rdev->irq.vblank_queue); 691771fe6b9SJerome Glisse 692d4877cf2SAlex Deucher /* setup workqueue */ 693d4877cf2SAlex Deucher rdev->wq = create_workqueue("radeon"); 694d4877cf2SAlex Deucher if (rdev->wq == NULL) 695d4877cf2SAlex Deucher return -ENOMEM; 696d4877cf2SAlex Deucher 6974aac0473SJerome Glisse /* Set asic functions */ 6984aac0473SJerome Glisse r = radeon_asic_init(rdev); 69936421338SJerome Glisse if (r) 7004aac0473SJerome Glisse return r; 70136421338SJerome Glisse radeon_check_arguments(rdev); 7024aac0473SJerome Glisse 70330256a3fSJerome Glisse if (rdev->flags & RADEON_IS_AGP && radeon_agpmode == -1) { 704b574f251SJerome Glisse radeon_agp_disable(rdev); 705771fe6b9SJerome Glisse } 706771fe6b9SJerome Glisse 707ad49f501SDave Airlie /* set DMA mask + need_dma32 flags. 708ad49f501SDave Airlie * PCIE - can handle 40-bits. 709ad49f501SDave Airlie * IGP - can handle 40-bits (in theory) 710ad49f501SDave Airlie * AGP - generally dma32 is safest 711ad49f501SDave Airlie * PCI - only dma32 712ad49f501SDave Airlie */ 713ad49f501SDave Airlie rdev->need_dma32 = false; 714ad49f501SDave Airlie if (rdev->flags & RADEON_IS_AGP) 715ad49f501SDave Airlie rdev->need_dma32 = true; 716ad49f501SDave Airlie if (rdev->flags & RADEON_IS_PCI) 717ad49f501SDave Airlie rdev->need_dma32 = true; 718ad49f501SDave Airlie 719ad49f501SDave Airlie dma_bits = rdev->need_dma32 ? 32 : 40; 720ad49f501SDave Airlie r = pci_set_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits)); 721771fe6b9SJerome Glisse if (r) { 722771fe6b9SJerome Glisse printk(KERN_WARNING "radeon: No suitable DMA available.\n"); 723771fe6b9SJerome Glisse } 724771fe6b9SJerome Glisse 725771fe6b9SJerome Glisse /* Registers mapping */ 726771fe6b9SJerome Glisse /* TODO: block userspace mapping of io register */ 727771fe6b9SJerome Glisse rdev->rmmio_base = drm_get_resource_start(rdev->ddev, 2); 728771fe6b9SJerome Glisse rdev->rmmio_size = drm_get_resource_len(rdev->ddev, 2); 729771fe6b9SJerome Glisse rdev->rmmio = ioremap(rdev->rmmio_base, rdev->rmmio_size); 730771fe6b9SJerome Glisse if (rdev->rmmio == NULL) { 731771fe6b9SJerome Glisse return -ENOMEM; 732771fe6b9SJerome Glisse } 733771fe6b9SJerome Glisse DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)rdev->rmmio_base); 734771fe6b9SJerome Glisse DRM_INFO("register mmio size: %u\n", (unsigned)rdev->rmmio_size); 735771fe6b9SJerome Glisse 73628d52043SDave Airlie /* if we have > 1 VGA cards, then disable the radeon VGA resources */ 73793239ea1SDave Airlie /* this will fail for cards that aren't VGA class devices, just 73893239ea1SDave Airlie * ignore it */ 73993239ea1SDave Airlie vga_client_register(rdev->pdev, rdev, NULL, radeon_vga_set_decode); 74028d52043SDave Airlie 7413ce0a23dSJerome Glisse r = radeon_init(rdev); 742b574f251SJerome Glisse if (r) 743b574f251SJerome Glisse return r; 744b1e3a6d1SMichel Dänzer 745b574f251SJerome Glisse if (rdev->flags & RADEON_IS_AGP && !rdev->accel_working) { 746b574f251SJerome Glisse /* Acceleration not working on AGP card try again 747b574f251SJerome Glisse * with fallback to PCI or PCIE GART 748b574f251SJerome Glisse */ 7491a029b76SJerome Glisse radeon_gpu_reset(rdev); 750b574f251SJerome Glisse radeon_fini(rdev); 751b574f251SJerome Glisse radeon_agp_disable(rdev); 752b574f251SJerome Glisse r = radeon_init(rdev); 7534aac0473SJerome Glisse if (r) 7544aac0473SJerome Glisse return r; 7553ce0a23dSJerome Glisse } 756ecc0b326SMichel Dänzer if (radeon_testing) { 757ecc0b326SMichel Dänzer radeon_test_moves(rdev); 758ecc0b326SMichel Dänzer } 759771fe6b9SJerome Glisse if (radeon_benchmarking) { 760771fe6b9SJerome Glisse radeon_benchmark(rdev); 761771fe6b9SJerome Glisse } 7626cf8a3f5SJerome Glisse return 0; 763771fe6b9SJerome Glisse } 764771fe6b9SJerome Glisse 765771fe6b9SJerome Glisse void radeon_device_fini(struct radeon_device *rdev) 766771fe6b9SJerome Glisse { 767771fe6b9SJerome Glisse DRM_INFO("radeon: finishing device.\n"); 768771fe6b9SJerome Glisse rdev->shutdown = true; 7693ce0a23dSJerome Glisse radeon_fini(rdev); 770d4877cf2SAlex Deucher destroy_workqueue(rdev->wq); 771c1176d6fSDave Airlie vga_client_register(rdev->pdev, NULL, NULL, NULL); 772771fe6b9SJerome Glisse iounmap(rdev->rmmio); 773771fe6b9SJerome Glisse rdev->rmmio = NULL; 774771fe6b9SJerome Glisse } 775771fe6b9SJerome Glisse 776771fe6b9SJerome Glisse 777771fe6b9SJerome Glisse /* 778771fe6b9SJerome Glisse * Suspend & resume. 779771fe6b9SJerome Glisse */ 780771fe6b9SJerome Glisse int radeon_suspend_kms(struct drm_device *dev, pm_message_t state) 781771fe6b9SJerome Glisse { 782875c1866SDarren Jenkins struct radeon_device *rdev; 783771fe6b9SJerome Glisse struct drm_crtc *crtc; 7844c788679SJerome Glisse int r; 785771fe6b9SJerome Glisse 786875c1866SDarren Jenkins if (dev == NULL || dev->dev_private == NULL) { 787771fe6b9SJerome Glisse return -ENODEV; 788771fe6b9SJerome Glisse } 789771fe6b9SJerome Glisse if (state.event == PM_EVENT_PRETHAW) { 790771fe6b9SJerome Glisse return 0; 791771fe6b9SJerome Glisse } 792875c1866SDarren Jenkins rdev = dev->dev_private; 793875c1866SDarren Jenkins 794771fe6b9SJerome Glisse /* unpin the front buffers */ 795771fe6b9SJerome Glisse list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 796771fe6b9SJerome Glisse struct radeon_framebuffer *rfb = to_radeon_framebuffer(crtc->fb); 7974c788679SJerome Glisse struct radeon_bo *robj; 798771fe6b9SJerome Glisse 799771fe6b9SJerome Glisse if (rfb == NULL || rfb->obj == NULL) { 800771fe6b9SJerome Glisse continue; 801771fe6b9SJerome Glisse } 802771fe6b9SJerome Glisse robj = rfb->obj->driver_private; 8034c788679SJerome Glisse if (robj != rdev->fbdev_rbo) { 8044c788679SJerome Glisse r = radeon_bo_reserve(robj, false); 8054c788679SJerome Glisse if (unlikely(r == 0)) { 8064c788679SJerome Glisse radeon_bo_unpin(robj); 8074c788679SJerome Glisse radeon_bo_unreserve(robj); 8084c788679SJerome Glisse } 809771fe6b9SJerome Glisse } 810771fe6b9SJerome Glisse } 811771fe6b9SJerome Glisse /* evict vram memory */ 8124c788679SJerome Glisse radeon_bo_evict_vram(rdev); 813771fe6b9SJerome Glisse /* wait for gpu to finish processing current batch */ 814771fe6b9SJerome Glisse radeon_fence_wait_last(rdev); 815771fe6b9SJerome Glisse 816f657c2a7SYang Zhao radeon_save_bios_scratch_regs(rdev); 817f657c2a7SYang Zhao 8183ce0a23dSJerome Glisse radeon_suspend(rdev); 819d4877cf2SAlex Deucher radeon_hpd_fini(rdev); 820771fe6b9SJerome Glisse /* evict remaining vram memory */ 8214c788679SJerome Glisse radeon_bo_evict_vram(rdev); 822771fe6b9SJerome Glisse 823771fe6b9SJerome Glisse pci_save_state(dev->pdev); 824771fe6b9SJerome Glisse if (state.event == PM_EVENT_SUSPEND) { 825771fe6b9SJerome Glisse /* Shut down the device */ 826771fe6b9SJerome Glisse pci_disable_device(dev->pdev); 827771fe6b9SJerome Glisse pci_set_power_state(dev->pdev, PCI_D3hot); 828771fe6b9SJerome Glisse } 829771fe6b9SJerome Glisse acquire_console_sem(); 830771fe6b9SJerome Glisse fb_set_suspend(rdev->fbdev_info, 1); 831771fe6b9SJerome Glisse release_console_sem(); 832771fe6b9SJerome Glisse return 0; 833771fe6b9SJerome Glisse } 834771fe6b9SJerome Glisse 835771fe6b9SJerome Glisse int radeon_resume_kms(struct drm_device *dev) 836771fe6b9SJerome Glisse { 837771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 838771fe6b9SJerome Glisse 839771fe6b9SJerome Glisse acquire_console_sem(); 840771fe6b9SJerome Glisse pci_set_power_state(dev->pdev, PCI_D0); 841771fe6b9SJerome Glisse pci_restore_state(dev->pdev); 842771fe6b9SJerome Glisse if (pci_enable_device(dev->pdev)) { 843771fe6b9SJerome Glisse release_console_sem(); 844771fe6b9SJerome Glisse return -1; 845771fe6b9SJerome Glisse } 846771fe6b9SJerome Glisse pci_set_master(dev->pdev); 8470ebf1717SDave Airlie /* resume AGP if in use */ 8480ebf1717SDave Airlie radeon_agp_resume(rdev); 8493ce0a23dSJerome Glisse radeon_resume(rdev); 850f657c2a7SYang Zhao radeon_restore_bios_scratch_regs(rdev); 851771fe6b9SJerome Glisse fb_set_suspend(rdev->fbdev_info, 0); 852771fe6b9SJerome Glisse release_console_sem(); 853771fe6b9SJerome Glisse 854d4877cf2SAlex Deucher /* reset hpd state */ 855d4877cf2SAlex Deucher radeon_hpd_init(rdev); 856771fe6b9SJerome Glisse /* blat the mode back in */ 857771fe6b9SJerome Glisse drm_helper_resume_force_mode(dev); 858771fe6b9SJerome Glisse return 0; 859771fe6b9SJerome Glisse } 860771fe6b9SJerome Glisse 861771fe6b9SJerome Glisse 862771fe6b9SJerome Glisse /* 863771fe6b9SJerome Glisse * Debugfs 864771fe6b9SJerome Glisse */ 865771fe6b9SJerome Glisse struct radeon_debugfs { 866771fe6b9SJerome Glisse struct drm_info_list *files; 867771fe6b9SJerome Glisse unsigned num_files; 868771fe6b9SJerome Glisse }; 869771fe6b9SJerome Glisse static struct radeon_debugfs _radeon_debugfs[RADEON_DEBUGFS_MAX_NUM_FILES]; 870771fe6b9SJerome Glisse static unsigned _radeon_debugfs_count = 0; 871771fe6b9SJerome Glisse 872771fe6b9SJerome Glisse int radeon_debugfs_add_files(struct radeon_device *rdev, 873771fe6b9SJerome Glisse struct drm_info_list *files, 874771fe6b9SJerome Glisse unsigned nfiles) 875771fe6b9SJerome Glisse { 876771fe6b9SJerome Glisse unsigned i; 877771fe6b9SJerome Glisse 878771fe6b9SJerome Glisse for (i = 0; i < _radeon_debugfs_count; i++) { 879771fe6b9SJerome Glisse if (_radeon_debugfs[i].files == files) { 880771fe6b9SJerome Glisse /* Already registered */ 881771fe6b9SJerome Glisse return 0; 882771fe6b9SJerome Glisse } 883771fe6b9SJerome Glisse } 884771fe6b9SJerome Glisse if ((_radeon_debugfs_count + nfiles) > RADEON_DEBUGFS_MAX_NUM_FILES) { 885771fe6b9SJerome Glisse DRM_ERROR("Reached maximum number of debugfs files.\n"); 886771fe6b9SJerome Glisse DRM_ERROR("Report so we increase RADEON_DEBUGFS_MAX_NUM_FILES.\n"); 887771fe6b9SJerome Glisse return -EINVAL; 888771fe6b9SJerome Glisse } 889771fe6b9SJerome Glisse _radeon_debugfs[_radeon_debugfs_count].files = files; 890771fe6b9SJerome Glisse _radeon_debugfs[_radeon_debugfs_count].num_files = nfiles; 891771fe6b9SJerome Glisse _radeon_debugfs_count++; 892771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 893771fe6b9SJerome Glisse drm_debugfs_create_files(files, nfiles, 894771fe6b9SJerome Glisse rdev->ddev->control->debugfs_root, 895771fe6b9SJerome Glisse rdev->ddev->control); 896771fe6b9SJerome Glisse drm_debugfs_create_files(files, nfiles, 897771fe6b9SJerome Glisse rdev->ddev->primary->debugfs_root, 898771fe6b9SJerome Glisse rdev->ddev->primary); 899771fe6b9SJerome Glisse #endif 900771fe6b9SJerome Glisse return 0; 901771fe6b9SJerome Glisse } 902771fe6b9SJerome Glisse 903771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 904771fe6b9SJerome Glisse int radeon_debugfs_init(struct drm_minor *minor) 905771fe6b9SJerome Glisse { 906771fe6b9SJerome Glisse return 0; 907771fe6b9SJerome Glisse } 908771fe6b9SJerome Glisse 909771fe6b9SJerome Glisse void radeon_debugfs_cleanup(struct drm_minor *minor) 910771fe6b9SJerome Glisse { 911771fe6b9SJerome Glisse unsigned i; 912771fe6b9SJerome Glisse 913771fe6b9SJerome Glisse for (i = 0; i < _radeon_debugfs_count; i++) { 914771fe6b9SJerome Glisse drm_debugfs_remove_files(_radeon_debugfs[i].files, 915771fe6b9SJerome Glisse _radeon_debugfs[i].num_files, minor); 916771fe6b9SJerome Glisse } 917771fe6b9SJerome Glisse } 918771fe6b9SJerome Glisse #endif 919