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 103771fe6b9SJerome Glisse /* 104771fe6b9SJerome Glisse * MC common functions 105771fe6b9SJerome Glisse */ 106771fe6b9SJerome Glisse int radeon_mc_setup(struct radeon_device *rdev) 107771fe6b9SJerome Glisse { 108771fe6b9SJerome Glisse uint32_t tmp; 109771fe6b9SJerome Glisse 110771fe6b9SJerome Glisse /* Some chips have an "issue" with the memory controller, the 111771fe6b9SJerome Glisse * location must be aligned to the size. We just align it down, 112771fe6b9SJerome Glisse * too bad if we walk over the top of system memory, we don't 113771fe6b9SJerome Glisse * use DMA without a remapped anyway. 114771fe6b9SJerome Glisse * Affected chips are rv280, all r3xx, and all r4xx, but not IGP 115771fe6b9SJerome Glisse */ 116771fe6b9SJerome Glisse /* FGLRX seems to setup like this, VRAM a 0, then GART. 117771fe6b9SJerome Glisse */ 118771fe6b9SJerome Glisse /* 119771fe6b9SJerome Glisse * Note: from R6xx the address space is 40bits but here we only 120771fe6b9SJerome Glisse * use 32bits (still have to see a card which would exhaust 4G 121771fe6b9SJerome Glisse * address space). 122771fe6b9SJerome Glisse */ 123771fe6b9SJerome Glisse if (rdev->mc.vram_location != 0xFFFFFFFFUL) { 124771fe6b9SJerome Glisse /* vram location was already setup try to put gtt after 125771fe6b9SJerome Glisse * if it fits */ 1267a50f01aSDave Airlie tmp = rdev->mc.vram_location + rdev->mc.mc_vram_size; 127771fe6b9SJerome Glisse tmp = (tmp + rdev->mc.gtt_size - 1) & ~(rdev->mc.gtt_size - 1); 128771fe6b9SJerome Glisse if ((0xFFFFFFFFUL - tmp) >= rdev->mc.gtt_size) { 129771fe6b9SJerome Glisse rdev->mc.gtt_location = tmp; 130771fe6b9SJerome Glisse } else { 131771fe6b9SJerome Glisse if (rdev->mc.gtt_size >= rdev->mc.vram_location) { 132771fe6b9SJerome Glisse printk(KERN_ERR "[drm] GTT too big to fit " 133771fe6b9SJerome Glisse "before or after vram location.\n"); 134771fe6b9SJerome Glisse return -EINVAL; 135771fe6b9SJerome Glisse } 136771fe6b9SJerome Glisse rdev->mc.gtt_location = 0; 137771fe6b9SJerome Glisse } 138771fe6b9SJerome Glisse } else if (rdev->mc.gtt_location != 0xFFFFFFFFUL) { 139771fe6b9SJerome Glisse /* gtt location was already setup try to put vram before 140771fe6b9SJerome Glisse * if it fits */ 1417a50f01aSDave Airlie if (rdev->mc.mc_vram_size < rdev->mc.gtt_location) { 142771fe6b9SJerome Glisse rdev->mc.vram_location = 0; 143771fe6b9SJerome Glisse } else { 144771fe6b9SJerome Glisse tmp = rdev->mc.gtt_location + rdev->mc.gtt_size; 1457a50f01aSDave Airlie tmp += (rdev->mc.mc_vram_size - 1); 1467a50f01aSDave Airlie tmp &= ~(rdev->mc.mc_vram_size - 1); 1477a50f01aSDave Airlie if ((0xFFFFFFFFUL - tmp) >= rdev->mc.mc_vram_size) { 148771fe6b9SJerome Glisse rdev->mc.vram_location = tmp; 149771fe6b9SJerome Glisse } else { 150771fe6b9SJerome Glisse printk(KERN_ERR "[drm] vram too big to fit " 151771fe6b9SJerome Glisse "before or after GTT location.\n"); 152771fe6b9SJerome Glisse return -EINVAL; 153771fe6b9SJerome Glisse } 154771fe6b9SJerome Glisse } 155771fe6b9SJerome Glisse } else { 156771fe6b9SJerome Glisse rdev->mc.vram_location = 0; 15717332925SDave Airlie tmp = rdev->mc.mc_vram_size; 15817332925SDave Airlie tmp = (tmp + rdev->mc.gtt_size - 1) & ~(rdev->mc.gtt_size - 1); 15917332925SDave Airlie rdev->mc.gtt_location = tmp; 160771fe6b9SJerome Glisse } 1619f022ddfSJerome Glisse rdev->mc.vram_start = rdev->mc.vram_location; 1629f022ddfSJerome Glisse rdev->mc.vram_end = rdev->mc.vram_location + rdev->mc.mc_vram_size - 1; 1639f022ddfSJerome Glisse rdev->mc.gtt_start = rdev->mc.gtt_location; 1649f022ddfSJerome Glisse rdev->mc.gtt_end = rdev->mc.gtt_location + rdev->mc.gtt_size - 1; 1653ce0a23dSJerome Glisse DRM_INFO("radeon: VRAM %uM\n", (unsigned)(rdev->mc.mc_vram_size >> 20)); 166771fe6b9SJerome Glisse DRM_INFO("radeon: VRAM from 0x%08X to 0x%08X\n", 1673ce0a23dSJerome Glisse (unsigned)rdev->mc.vram_location, 1683ce0a23dSJerome Glisse (unsigned)(rdev->mc.vram_location + rdev->mc.mc_vram_size - 1)); 1693ce0a23dSJerome Glisse DRM_INFO("radeon: GTT %uM\n", (unsigned)(rdev->mc.gtt_size >> 20)); 170771fe6b9SJerome Glisse DRM_INFO("radeon: GTT from 0x%08X to 0x%08X\n", 1713ce0a23dSJerome Glisse (unsigned)rdev->mc.gtt_location, 1723ce0a23dSJerome Glisse (unsigned)(rdev->mc.gtt_location + rdev->mc.gtt_size - 1)); 173771fe6b9SJerome Glisse return 0; 174771fe6b9SJerome Glisse } 175771fe6b9SJerome Glisse 176771fe6b9SJerome Glisse 177771fe6b9SJerome Glisse /* 178771fe6b9SJerome Glisse * GPU helpers function. 179771fe6b9SJerome Glisse */ 1809f022ddfSJerome Glisse bool radeon_card_posted(struct radeon_device *rdev) 181771fe6b9SJerome Glisse { 182771fe6b9SJerome Glisse uint32_t reg; 183771fe6b9SJerome Glisse 184771fe6b9SJerome Glisse /* first check CRTCs */ 185bcc1c2a1SAlex Deucher if (ASIC_IS_DCE4(rdev)) { 186bcc1c2a1SAlex Deucher reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) | 187bcc1c2a1SAlex Deucher RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) | 188bcc1c2a1SAlex Deucher RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) | 189bcc1c2a1SAlex Deucher RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) | 190bcc1c2a1SAlex Deucher RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) | 191bcc1c2a1SAlex Deucher RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET); 192bcc1c2a1SAlex Deucher if (reg & EVERGREEN_CRTC_MASTER_EN) 193bcc1c2a1SAlex Deucher return true; 194bcc1c2a1SAlex Deucher } else if (ASIC_IS_AVIVO(rdev)) { 195771fe6b9SJerome Glisse reg = RREG32(AVIVO_D1CRTC_CONTROL) | 196771fe6b9SJerome Glisse RREG32(AVIVO_D2CRTC_CONTROL); 197771fe6b9SJerome Glisse if (reg & AVIVO_CRTC_EN) { 198771fe6b9SJerome Glisse return true; 199771fe6b9SJerome Glisse } 200771fe6b9SJerome Glisse } else { 201771fe6b9SJerome Glisse reg = RREG32(RADEON_CRTC_GEN_CNTL) | 202771fe6b9SJerome Glisse RREG32(RADEON_CRTC2_GEN_CNTL); 203771fe6b9SJerome Glisse if (reg & RADEON_CRTC_EN) { 204771fe6b9SJerome Glisse return true; 205771fe6b9SJerome Glisse } 206771fe6b9SJerome Glisse } 207771fe6b9SJerome Glisse 208771fe6b9SJerome Glisse /* then check MEM_SIZE, in case the crtcs are off */ 209771fe6b9SJerome Glisse if (rdev->family >= CHIP_R600) 210771fe6b9SJerome Glisse reg = RREG32(R600_CONFIG_MEMSIZE); 211771fe6b9SJerome Glisse else 212771fe6b9SJerome Glisse reg = RREG32(RADEON_CONFIG_MEMSIZE); 213771fe6b9SJerome Glisse 214771fe6b9SJerome Glisse if (reg) 215771fe6b9SJerome Glisse return true; 216771fe6b9SJerome Glisse 217771fe6b9SJerome Glisse return false; 218771fe6b9SJerome Glisse 219771fe6b9SJerome Glisse } 220771fe6b9SJerome Glisse 22172542d77SDave Airlie bool radeon_boot_test_post_card(struct radeon_device *rdev) 22272542d77SDave Airlie { 22372542d77SDave Airlie if (radeon_card_posted(rdev)) 22472542d77SDave Airlie return true; 22572542d77SDave Airlie 22672542d77SDave Airlie if (rdev->bios) { 22772542d77SDave Airlie DRM_INFO("GPU not posted. posting now...\n"); 22872542d77SDave Airlie if (rdev->is_atom_bios) 22972542d77SDave Airlie atom_asic_init(rdev->mode_info.atom_context); 23072542d77SDave Airlie else 23172542d77SDave Airlie radeon_combios_asic_init(rdev->ddev); 23272542d77SDave Airlie return true; 23372542d77SDave Airlie } else { 23472542d77SDave Airlie dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n"); 23572542d77SDave Airlie return false; 23672542d77SDave Airlie } 23772542d77SDave Airlie } 23872542d77SDave Airlie 2393ce0a23dSJerome Glisse int radeon_dummy_page_init(struct radeon_device *rdev) 2403ce0a23dSJerome Glisse { 24182568565SDave Airlie if (rdev->dummy_page.page) 24282568565SDave Airlie return 0; 2433ce0a23dSJerome Glisse rdev->dummy_page.page = alloc_page(GFP_DMA32 | GFP_KERNEL | __GFP_ZERO); 2443ce0a23dSJerome Glisse if (rdev->dummy_page.page == NULL) 2453ce0a23dSJerome Glisse return -ENOMEM; 2463ce0a23dSJerome Glisse rdev->dummy_page.addr = pci_map_page(rdev->pdev, rdev->dummy_page.page, 2473ce0a23dSJerome Glisse 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 2483ce0a23dSJerome Glisse if (!rdev->dummy_page.addr) { 2493ce0a23dSJerome Glisse __free_page(rdev->dummy_page.page); 2503ce0a23dSJerome Glisse rdev->dummy_page.page = NULL; 2513ce0a23dSJerome Glisse return -ENOMEM; 2523ce0a23dSJerome Glisse } 2533ce0a23dSJerome Glisse return 0; 2543ce0a23dSJerome Glisse } 2553ce0a23dSJerome Glisse 2563ce0a23dSJerome Glisse void radeon_dummy_page_fini(struct radeon_device *rdev) 2573ce0a23dSJerome Glisse { 2583ce0a23dSJerome Glisse if (rdev->dummy_page.page == NULL) 2593ce0a23dSJerome Glisse return; 2603ce0a23dSJerome Glisse pci_unmap_page(rdev->pdev, rdev->dummy_page.addr, 2613ce0a23dSJerome Glisse PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 2623ce0a23dSJerome Glisse __free_page(rdev->dummy_page.page); 2633ce0a23dSJerome Glisse rdev->dummy_page.page = NULL; 2643ce0a23dSJerome Glisse } 2653ce0a23dSJerome Glisse 266771fe6b9SJerome Glisse 267771fe6b9SJerome Glisse /* 268771fe6b9SJerome Glisse * Registers accessors functions. 269771fe6b9SJerome Glisse */ 270771fe6b9SJerome Glisse uint32_t radeon_invalid_rreg(struct radeon_device *rdev, uint32_t reg) 271771fe6b9SJerome Glisse { 272771fe6b9SJerome Glisse DRM_ERROR("Invalid callback to read register 0x%04X\n", reg); 273771fe6b9SJerome Glisse BUG_ON(1); 274771fe6b9SJerome Glisse return 0; 275771fe6b9SJerome Glisse } 276771fe6b9SJerome Glisse 277771fe6b9SJerome Glisse void radeon_invalid_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v) 278771fe6b9SJerome Glisse { 279771fe6b9SJerome Glisse DRM_ERROR("Invalid callback to write register 0x%04X with 0x%08X\n", 280771fe6b9SJerome Glisse reg, v); 281771fe6b9SJerome Glisse BUG_ON(1); 282771fe6b9SJerome Glisse } 283771fe6b9SJerome Glisse 284771fe6b9SJerome Glisse void radeon_register_accessor_init(struct radeon_device *rdev) 285771fe6b9SJerome Glisse { 286771fe6b9SJerome Glisse rdev->mc_rreg = &radeon_invalid_rreg; 287771fe6b9SJerome Glisse rdev->mc_wreg = &radeon_invalid_wreg; 288771fe6b9SJerome Glisse rdev->pll_rreg = &radeon_invalid_rreg; 289771fe6b9SJerome Glisse rdev->pll_wreg = &radeon_invalid_wreg; 290771fe6b9SJerome Glisse rdev->pciep_rreg = &radeon_invalid_rreg; 291771fe6b9SJerome Glisse rdev->pciep_wreg = &radeon_invalid_wreg; 292771fe6b9SJerome Glisse 293771fe6b9SJerome Glisse /* Don't change order as we are overridding accessor. */ 294771fe6b9SJerome Glisse if (rdev->family < CHIP_RV515) { 295de1b2898SDave Airlie rdev->pcie_reg_mask = 0xff; 296de1b2898SDave Airlie } else { 297de1b2898SDave Airlie rdev->pcie_reg_mask = 0x7ff; 298771fe6b9SJerome Glisse } 299771fe6b9SJerome Glisse /* FIXME: not sure here */ 300771fe6b9SJerome Glisse if (rdev->family <= CHIP_R580) { 301771fe6b9SJerome Glisse rdev->pll_rreg = &r100_pll_rreg; 302771fe6b9SJerome Glisse rdev->pll_wreg = &r100_pll_wreg; 303771fe6b9SJerome Glisse } 304905b6822SJerome Glisse if (rdev->family >= CHIP_R420) { 305905b6822SJerome Glisse rdev->mc_rreg = &r420_mc_rreg; 306905b6822SJerome Glisse rdev->mc_wreg = &r420_mc_wreg; 307905b6822SJerome Glisse } 308771fe6b9SJerome Glisse if (rdev->family >= CHIP_RV515) { 309771fe6b9SJerome Glisse rdev->mc_rreg = &rv515_mc_rreg; 310771fe6b9SJerome Glisse rdev->mc_wreg = &rv515_mc_wreg; 311771fe6b9SJerome Glisse } 312771fe6b9SJerome Glisse if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480) { 313771fe6b9SJerome Glisse rdev->mc_rreg = &rs400_mc_rreg; 314771fe6b9SJerome Glisse rdev->mc_wreg = &rs400_mc_wreg; 315771fe6b9SJerome Glisse } 316771fe6b9SJerome Glisse if (rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) { 317771fe6b9SJerome Glisse rdev->mc_rreg = &rs690_mc_rreg; 318771fe6b9SJerome Glisse rdev->mc_wreg = &rs690_mc_wreg; 319771fe6b9SJerome Glisse } 320771fe6b9SJerome Glisse if (rdev->family == CHIP_RS600) { 321771fe6b9SJerome Glisse rdev->mc_rreg = &rs600_mc_rreg; 322771fe6b9SJerome Glisse rdev->mc_wreg = &rs600_mc_wreg; 323771fe6b9SJerome Glisse } 324bcc1c2a1SAlex Deucher if ((rdev->family >= CHIP_R600) && (rdev->family <= CHIP_RV740)) { 325771fe6b9SJerome Glisse rdev->pciep_rreg = &r600_pciep_rreg; 326771fe6b9SJerome Glisse rdev->pciep_wreg = &r600_pciep_wreg; 327771fe6b9SJerome Glisse } 328771fe6b9SJerome Glisse } 329771fe6b9SJerome Glisse 330771fe6b9SJerome Glisse 331771fe6b9SJerome Glisse /* 332771fe6b9SJerome Glisse * ASIC 333771fe6b9SJerome Glisse */ 334771fe6b9SJerome Glisse int radeon_asic_init(struct radeon_device *rdev) 335771fe6b9SJerome Glisse { 336771fe6b9SJerome Glisse radeon_register_accessor_init(rdev); 337771fe6b9SJerome Glisse switch (rdev->family) { 338771fe6b9SJerome Glisse case CHIP_R100: 339771fe6b9SJerome Glisse case CHIP_RV100: 340771fe6b9SJerome Glisse case CHIP_RS100: 341771fe6b9SJerome Glisse case CHIP_RV200: 342771fe6b9SJerome Glisse case CHIP_RS200: 343*44ca7478SPauli Nieminen rdev->asic = &r100_asic; 344*44ca7478SPauli Nieminen break; 345771fe6b9SJerome Glisse case CHIP_R200: 346771fe6b9SJerome Glisse case CHIP_RV250: 347771fe6b9SJerome Glisse case CHIP_RS300: 348771fe6b9SJerome Glisse case CHIP_RV280: 349*44ca7478SPauli Nieminen rdev->asic = &r200_asic; 350771fe6b9SJerome Glisse break; 351771fe6b9SJerome Glisse case CHIP_R300: 352771fe6b9SJerome Glisse case CHIP_R350: 353771fe6b9SJerome Glisse case CHIP_RV350: 354771fe6b9SJerome Glisse case CHIP_RV380: 355d80eeb0fSPauli Nieminen if (rdev->flags & RADEON_IS_PCIE) 356d80eeb0fSPauli Nieminen rdev->asic = &r300_asic_pcie; 357d80eeb0fSPauli Nieminen else 358771fe6b9SJerome Glisse rdev->asic = &r300_asic; 359771fe6b9SJerome Glisse break; 360771fe6b9SJerome Glisse case CHIP_R420: 361771fe6b9SJerome Glisse case CHIP_R423: 362771fe6b9SJerome Glisse case CHIP_RV410: 363771fe6b9SJerome Glisse rdev->asic = &r420_asic; 364771fe6b9SJerome Glisse break; 365771fe6b9SJerome Glisse case CHIP_RS400: 366771fe6b9SJerome Glisse case CHIP_RS480: 367771fe6b9SJerome Glisse rdev->asic = &rs400_asic; 368771fe6b9SJerome Glisse break; 369771fe6b9SJerome Glisse case CHIP_RS600: 370771fe6b9SJerome Glisse rdev->asic = &rs600_asic; 371771fe6b9SJerome Glisse break; 372771fe6b9SJerome Glisse case CHIP_RS690: 373771fe6b9SJerome Glisse case CHIP_RS740: 374771fe6b9SJerome Glisse rdev->asic = &rs690_asic; 375771fe6b9SJerome Glisse break; 376771fe6b9SJerome Glisse case CHIP_RV515: 377771fe6b9SJerome Glisse rdev->asic = &rv515_asic; 378771fe6b9SJerome Glisse break; 379771fe6b9SJerome Glisse case CHIP_R520: 380771fe6b9SJerome Glisse case CHIP_RV530: 381771fe6b9SJerome Glisse case CHIP_RV560: 382771fe6b9SJerome Glisse case CHIP_RV570: 383771fe6b9SJerome Glisse case CHIP_R580: 384771fe6b9SJerome Glisse rdev->asic = &r520_asic; 385771fe6b9SJerome Glisse break; 386771fe6b9SJerome Glisse case CHIP_R600: 387771fe6b9SJerome Glisse case CHIP_RV610: 388771fe6b9SJerome Glisse case CHIP_RV630: 389771fe6b9SJerome Glisse case CHIP_RV620: 390771fe6b9SJerome Glisse case CHIP_RV635: 391771fe6b9SJerome Glisse case CHIP_RV670: 392771fe6b9SJerome Glisse case CHIP_RS780: 3933ce0a23dSJerome Glisse case CHIP_RS880: 3943ce0a23dSJerome Glisse rdev->asic = &r600_asic; 3953ce0a23dSJerome Glisse break; 396771fe6b9SJerome Glisse case CHIP_RV770: 397771fe6b9SJerome Glisse case CHIP_RV730: 398771fe6b9SJerome Glisse case CHIP_RV710: 3993ce0a23dSJerome Glisse case CHIP_RV740: 4003ce0a23dSJerome Glisse rdev->asic = &rv770_asic; 4013ce0a23dSJerome Glisse break; 402bcc1c2a1SAlex Deucher case CHIP_CEDAR: 403bcc1c2a1SAlex Deucher case CHIP_REDWOOD: 404bcc1c2a1SAlex Deucher case CHIP_JUNIPER: 405bcc1c2a1SAlex Deucher case CHIP_CYPRESS: 406bcc1c2a1SAlex Deucher case CHIP_HEMLOCK: 407bcc1c2a1SAlex Deucher rdev->asic = &evergreen_asic; 408bcc1c2a1SAlex Deucher break; 409771fe6b9SJerome Glisse default: 410771fe6b9SJerome Glisse /* FIXME: not supported yet */ 411771fe6b9SJerome Glisse return -EINVAL; 412771fe6b9SJerome Glisse } 4135ea597f3SRafał Miłecki 4145ea597f3SRafał Miłecki if (rdev->flags & RADEON_IS_IGP) { 4155ea597f3SRafał Miłecki rdev->asic->get_memory_clock = NULL; 4165ea597f3SRafał Miłecki rdev->asic->set_memory_clock = NULL; 4175ea597f3SRafał Miłecki } 4185ea597f3SRafał Miłecki 419771fe6b9SJerome Glisse return 0; 420771fe6b9SJerome Glisse } 421771fe6b9SJerome Glisse 422771fe6b9SJerome Glisse 423771fe6b9SJerome Glisse /* 424771fe6b9SJerome Glisse * Wrapper around modesetting bits. 425771fe6b9SJerome Glisse */ 426771fe6b9SJerome Glisse int radeon_clocks_init(struct radeon_device *rdev) 427771fe6b9SJerome Glisse { 428771fe6b9SJerome Glisse int r; 429771fe6b9SJerome Glisse 430771fe6b9SJerome Glisse r = radeon_static_clocks_init(rdev->ddev); 431771fe6b9SJerome Glisse if (r) { 432771fe6b9SJerome Glisse return r; 433771fe6b9SJerome Glisse } 434771fe6b9SJerome Glisse DRM_INFO("Clocks initialized !\n"); 435771fe6b9SJerome Glisse return 0; 436771fe6b9SJerome Glisse } 437771fe6b9SJerome Glisse 438771fe6b9SJerome Glisse void radeon_clocks_fini(struct radeon_device *rdev) 439771fe6b9SJerome Glisse { 440771fe6b9SJerome Glisse } 441771fe6b9SJerome Glisse 442771fe6b9SJerome Glisse /* ATOM accessor methods */ 443771fe6b9SJerome Glisse static uint32_t cail_pll_read(struct card_info *info, uint32_t reg) 444771fe6b9SJerome Glisse { 445771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 446771fe6b9SJerome Glisse uint32_t r; 447771fe6b9SJerome Glisse 448771fe6b9SJerome Glisse r = rdev->pll_rreg(rdev, reg); 449771fe6b9SJerome Glisse return r; 450771fe6b9SJerome Glisse } 451771fe6b9SJerome Glisse 452771fe6b9SJerome Glisse static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val) 453771fe6b9SJerome Glisse { 454771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 455771fe6b9SJerome Glisse 456771fe6b9SJerome Glisse rdev->pll_wreg(rdev, reg, val); 457771fe6b9SJerome Glisse } 458771fe6b9SJerome Glisse 459771fe6b9SJerome Glisse static uint32_t cail_mc_read(struct card_info *info, uint32_t reg) 460771fe6b9SJerome Glisse { 461771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 462771fe6b9SJerome Glisse uint32_t r; 463771fe6b9SJerome Glisse 464771fe6b9SJerome Glisse r = rdev->mc_rreg(rdev, reg); 465771fe6b9SJerome Glisse return r; 466771fe6b9SJerome Glisse } 467771fe6b9SJerome Glisse 468771fe6b9SJerome Glisse static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val) 469771fe6b9SJerome Glisse { 470771fe6b9SJerome Glisse struct radeon_device *rdev = info->dev->dev_private; 471771fe6b9SJerome Glisse 472771fe6b9SJerome Glisse rdev->mc_wreg(rdev, reg, val); 473771fe6b9SJerome Glisse } 474771fe6b9SJerome Glisse 475771fe6b9SJerome Glisse static void cail_reg_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 WREG32(reg*4, val); 480771fe6b9SJerome Glisse } 481771fe6b9SJerome Glisse 482771fe6b9SJerome Glisse static uint32_t cail_reg_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 = RREG32(reg*4); 488771fe6b9SJerome Glisse return r; 489771fe6b9SJerome Glisse } 490771fe6b9SJerome Glisse 491771fe6b9SJerome Glisse int radeon_atombios_init(struct radeon_device *rdev) 492771fe6b9SJerome Glisse { 49361c4b24bSMathias Fröhlich struct card_info *atom_card_info = 49461c4b24bSMathias Fröhlich kzalloc(sizeof(struct card_info), GFP_KERNEL); 49561c4b24bSMathias Fröhlich 49661c4b24bSMathias Fröhlich if (!atom_card_info) 49761c4b24bSMathias Fröhlich return -ENOMEM; 49861c4b24bSMathias Fröhlich 49961c4b24bSMathias Fröhlich rdev->mode_info.atom_card_info = atom_card_info; 50061c4b24bSMathias Fröhlich atom_card_info->dev = rdev->ddev; 50161c4b24bSMathias Fröhlich atom_card_info->reg_read = cail_reg_read; 50261c4b24bSMathias Fröhlich atom_card_info->reg_write = cail_reg_write; 50361c4b24bSMathias Fröhlich atom_card_info->mc_read = cail_mc_read; 50461c4b24bSMathias Fröhlich atom_card_info->mc_write = cail_mc_write; 50561c4b24bSMathias Fröhlich atom_card_info->pll_read = cail_pll_read; 50661c4b24bSMathias Fröhlich atom_card_info->pll_write = cail_pll_write; 50761c4b24bSMathias Fröhlich 50861c4b24bSMathias Fröhlich rdev->mode_info.atom_context = atom_parse(atom_card_info, rdev->bios); 509c31ad97fSRafał Miłecki mutex_init(&rdev->mode_info.atom_context->mutex); 510771fe6b9SJerome Glisse radeon_atom_initialize_bios_scratch_regs(rdev->ddev); 511d904ef9bSDave Airlie atom_allocate_fb_scratch(rdev->mode_info.atom_context); 512771fe6b9SJerome Glisse return 0; 513771fe6b9SJerome Glisse } 514771fe6b9SJerome Glisse 515771fe6b9SJerome Glisse void radeon_atombios_fini(struct radeon_device *rdev) 516771fe6b9SJerome Glisse { 5174a04a844SJerome Glisse if (rdev->mode_info.atom_context) { 518d904ef9bSDave Airlie kfree(rdev->mode_info.atom_context->scratch); 519771fe6b9SJerome Glisse kfree(rdev->mode_info.atom_context); 5204a04a844SJerome Glisse } 52161c4b24bSMathias Fröhlich kfree(rdev->mode_info.atom_card_info); 522771fe6b9SJerome Glisse } 523771fe6b9SJerome Glisse 524771fe6b9SJerome Glisse int radeon_combios_init(struct radeon_device *rdev) 525771fe6b9SJerome Glisse { 526771fe6b9SJerome Glisse radeon_combios_initialize_bios_scratch_regs(rdev->ddev); 527771fe6b9SJerome Glisse return 0; 528771fe6b9SJerome Glisse } 529771fe6b9SJerome Glisse 530771fe6b9SJerome Glisse void radeon_combios_fini(struct radeon_device *rdev) 531771fe6b9SJerome Glisse { 532771fe6b9SJerome Glisse } 533771fe6b9SJerome Glisse 53428d52043SDave Airlie /* if we get transitioned to only one device, tak VGA back */ 53528d52043SDave Airlie static unsigned int radeon_vga_set_decode(void *cookie, bool state) 53628d52043SDave Airlie { 53728d52043SDave Airlie struct radeon_device *rdev = cookie; 53828d52043SDave Airlie radeon_vga_set_state(rdev, state); 53928d52043SDave Airlie if (state) 54028d52043SDave Airlie return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | 54128d52043SDave Airlie VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; 54228d52043SDave Airlie else 54328d52043SDave Airlie return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; 54428d52043SDave Airlie } 545c1176d6fSDave Airlie 546b574f251SJerome Glisse void radeon_agp_disable(struct radeon_device *rdev) 547b574f251SJerome Glisse { 548b574f251SJerome Glisse rdev->flags &= ~RADEON_IS_AGP; 549b574f251SJerome Glisse if (rdev->family >= CHIP_R600) { 550b574f251SJerome Glisse DRM_INFO("Forcing AGP to PCIE mode\n"); 551b574f251SJerome Glisse rdev->flags |= RADEON_IS_PCIE; 552b574f251SJerome Glisse } else if (rdev->family >= CHIP_RV515 || 553b574f251SJerome Glisse rdev->family == CHIP_RV380 || 554b574f251SJerome Glisse rdev->family == CHIP_RV410 || 555b574f251SJerome Glisse rdev->family == CHIP_R423) { 556b574f251SJerome Glisse DRM_INFO("Forcing AGP to PCIE mode\n"); 557b574f251SJerome Glisse rdev->flags |= RADEON_IS_PCIE; 558b574f251SJerome Glisse rdev->asic->gart_tlb_flush = &rv370_pcie_gart_tlb_flush; 559b574f251SJerome Glisse rdev->asic->gart_set_page = &rv370_pcie_gart_set_page; 560b574f251SJerome Glisse } else { 561b574f251SJerome Glisse DRM_INFO("Forcing AGP to PCI mode\n"); 562b574f251SJerome Glisse rdev->flags |= RADEON_IS_PCI; 563b574f251SJerome Glisse rdev->asic->gart_tlb_flush = &r100_pci_gart_tlb_flush; 564b574f251SJerome Glisse rdev->asic->gart_set_page = &r100_pci_gart_set_page; 565b574f251SJerome Glisse } 566700a0cc0SJerome Glisse rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; 567b574f251SJerome Glisse } 568771fe6b9SJerome Glisse 56936421338SJerome Glisse void radeon_check_arguments(struct radeon_device *rdev) 57036421338SJerome Glisse { 57136421338SJerome Glisse /* vramlimit must be a power of two */ 57236421338SJerome Glisse switch (radeon_vram_limit) { 57336421338SJerome Glisse case 0: 57436421338SJerome Glisse case 4: 57536421338SJerome Glisse case 8: 57636421338SJerome Glisse case 16: 57736421338SJerome Glisse case 32: 57836421338SJerome Glisse case 64: 57936421338SJerome Glisse case 128: 58036421338SJerome Glisse case 256: 58136421338SJerome Glisse case 512: 58236421338SJerome Glisse case 1024: 58336421338SJerome Glisse case 2048: 58436421338SJerome Glisse case 4096: 58536421338SJerome Glisse break; 58636421338SJerome Glisse default: 58736421338SJerome Glisse dev_warn(rdev->dev, "vram limit (%d) must be a power of 2\n", 58836421338SJerome Glisse radeon_vram_limit); 58936421338SJerome Glisse radeon_vram_limit = 0; 59036421338SJerome Glisse break; 59136421338SJerome Glisse } 59236421338SJerome Glisse radeon_vram_limit = radeon_vram_limit << 20; 59336421338SJerome Glisse /* gtt size must be power of two and greater or equal to 32M */ 59436421338SJerome Glisse switch (radeon_gart_size) { 59536421338SJerome Glisse case 4: 59636421338SJerome Glisse case 8: 59736421338SJerome Glisse case 16: 59836421338SJerome Glisse dev_warn(rdev->dev, "gart size (%d) too small forcing to 512M\n", 59936421338SJerome Glisse radeon_gart_size); 60036421338SJerome Glisse radeon_gart_size = 512; 60136421338SJerome Glisse break; 60236421338SJerome Glisse case 32: 60336421338SJerome Glisse case 64: 60436421338SJerome Glisse case 128: 60536421338SJerome Glisse case 256: 60636421338SJerome Glisse case 512: 60736421338SJerome Glisse case 1024: 60836421338SJerome Glisse case 2048: 60936421338SJerome Glisse case 4096: 61036421338SJerome Glisse break; 61136421338SJerome Glisse default: 61236421338SJerome Glisse dev_warn(rdev->dev, "gart size (%d) must be a power of 2\n", 61336421338SJerome Glisse radeon_gart_size); 61436421338SJerome Glisse radeon_gart_size = 512; 61536421338SJerome Glisse break; 61636421338SJerome Glisse } 61736421338SJerome Glisse rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; 61836421338SJerome Glisse /* AGP mode can only be -1, 1, 2, 4, 8 */ 61936421338SJerome Glisse switch (radeon_agpmode) { 62036421338SJerome Glisse case -1: 62136421338SJerome Glisse case 0: 62236421338SJerome Glisse case 1: 62336421338SJerome Glisse case 2: 62436421338SJerome Glisse case 4: 62536421338SJerome Glisse case 8: 62636421338SJerome Glisse break; 62736421338SJerome Glisse default: 62836421338SJerome Glisse dev_warn(rdev->dev, "invalid AGP mode %d (valid mode: " 62936421338SJerome Glisse "-1, 0, 1, 2, 4, 8)\n", radeon_agpmode); 63036421338SJerome Glisse radeon_agpmode = 0; 63136421338SJerome Glisse break; 63236421338SJerome Glisse } 63336421338SJerome Glisse } 63436421338SJerome Glisse 635771fe6b9SJerome Glisse int radeon_device_init(struct radeon_device *rdev, 636771fe6b9SJerome Glisse struct drm_device *ddev, 637771fe6b9SJerome Glisse struct pci_dev *pdev, 638771fe6b9SJerome Glisse uint32_t flags) 639771fe6b9SJerome Glisse { 6406cf8a3f5SJerome Glisse int r; 641ad49f501SDave Airlie int dma_bits; 642771fe6b9SJerome Glisse 643771fe6b9SJerome Glisse DRM_INFO("radeon: Initializing kernel modesetting.\n"); 644771fe6b9SJerome Glisse rdev->shutdown = false; 6459f022ddfSJerome Glisse rdev->dev = &pdev->dev; 646771fe6b9SJerome Glisse rdev->ddev = ddev; 647771fe6b9SJerome Glisse rdev->pdev = pdev; 648771fe6b9SJerome Glisse rdev->flags = flags; 649771fe6b9SJerome Glisse rdev->family = flags & RADEON_FAMILY_MASK; 650771fe6b9SJerome Glisse rdev->is_atom_bios = false; 651771fe6b9SJerome Glisse rdev->usec_timeout = RADEON_MAX_USEC_TIMEOUT; 652771fe6b9SJerome Glisse rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; 653771fe6b9SJerome Glisse rdev->gpu_lockup = false; 654733289c2SJerome Glisse rdev->accel_working = false; 655771fe6b9SJerome Glisse /* mutex initialization are all done here so we 656771fe6b9SJerome Glisse * can recall function without having locking issues */ 657771fe6b9SJerome Glisse mutex_init(&rdev->cs_mutex); 658771fe6b9SJerome Glisse mutex_init(&rdev->ib_pool.mutex); 659771fe6b9SJerome Glisse mutex_init(&rdev->cp.mutex); 66040bacf16SAlex Deucher mutex_init(&rdev->dc_hw_i2c_mutex); 661d8f60cfcSAlex Deucher if (rdev->family >= CHIP_R600) 662d8f60cfcSAlex Deucher spin_lock_init(&rdev->ih.lock); 6634c788679SJerome Glisse mutex_init(&rdev->gem.mutex); 664c913e23aSRafał Miłecki mutex_init(&rdev->pm.mutex); 665771fe6b9SJerome Glisse rwlock_init(&rdev->fence_drv.lock); 6669f022ddfSJerome Glisse INIT_LIST_HEAD(&rdev->gem.objects); 66773a6d3fcSRafał Miłecki init_waitqueue_head(&rdev->irq.vblank_queue); 668771fe6b9SJerome Glisse 669d4877cf2SAlex Deucher /* setup workqueue */ 670d4877cf2SAlex Deucher rdev->wq = create_workqueue("radeon"); 671d4877cf2SAlex Deucher if (rdev->wq == NULL) 672d4877cf2SAlex Deucher return -ENOMEM; 673d4877cf2SAlex Deucher 6744aac0473SJerome Glisse /* Set asic functions */ 6754aac0473SJerome Glisse r = radeon_asic_init(rdev); 67636421338SJerome Glisse if (r) 6774aac0473SJerome Glisse return r; 67836421338SJerome Glisse radeon_check_arguments(rdev); 6794aac0473SJerome Glisse 68030256a3fSJerome Glisse if (rdev->flags & RADEON_IS_AGP && radeon_agpmode == -1) { 681b574f251SJerome Glisse radeon_agp_disable(rdev); 682771fe6b9SJerome Glisse } 683771fe6b9SJerome Glisse 684ad49f501SDave Airlie /* set DMA mask + need_dma32 flags. 685ad49f501SDave Airlie * PCIE - can handle 40-bits. 686ad49f501SDave Airlie * IGP - can handle 40-bits (in theory) 687ad49f501SDave Airlie * AGP - generally dma32 is safest 688ad49f501SDave Airlie * PCI - only dma32 689ad49f501SDave Airlie */ 690ad49f501SDave Airlie rdev->need_dma32 = false; 691ad49f501SDave Airlie if (rdev->flags & RADEON_IS_AGP) 692ad49f501SDave Airlie rdev->need_dma32 = true; 693ad49f501SDave Airlie if (rdev->flags & RADEON_IS_PCI) 694ad49f501SDave Airlie rdev->need_dma32 = true; 695ad49f501SDave Airlie 696ad49f501SDave Airlie dma_bits = rdev->need_dma32 ? 32 : 40; 697ad49f501SDave Airlie r = pci_set_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits)); 698771fe6b9SJerome Glisse if (r) { 699771fe6b9SJerome Glisse printk(KERN_WARNING "radeon: No suitable DMA available.\n"); 700771fe6b9SJerome Glisse } 701771fe6b9SJerome Glisse 702771fe6b9SJerome Glisse /* Registers mapping */ 703771fe6b9SJerome Glisse /* TODO: block userspace mapping of io register */ 704771fe6b9SJerome Glisse rdev->rmmio_base = drm_get_resource_start(rdev->ddev, 2); 705771fe6b9SJerome Glisse rdev->rmmio_size = drm_get_resource_len(rdev->ddev, 2); 706771fe6b9SJerome Glisse rdev->rmmio = ioremap(rdev->rmmio_base, rdev->rmmio_size); 707771fe6b9SJerome Glisse if (rdev->rmmio == NULL) { 708771fe6b9SJerome Glisse return -ENOMEM; 709771fe6b9SJerome Glisse } 710771fe6b9SJerome Glisse DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)rdev->rmmio_base); 711771fe6b9SJerome Glisse DRM_INFO("register mmio size: %u\n", (unsigned)rdev->rmmio_size); 712771fe6b9SJerome Glisse 71328d52043SDave Airlie /* if we have > 1 VGA cards, then disable the radeon VGA resources */ 71493239ea1SDave Airlie /* this will fail for cards that aren't VGA class devices, just 71593239ea1SDave Airlie * ignore it */ 71693239ea1SDave Airlie vga_client_register(rdev->pdev, rdev, NULL, radeon_vga_set_decode); 71728d52043SDave Airlie 7183ce0a23dSJerome Glisse r = radeon_init(rdev); 719b574f251SJerome Glisse if (r) 720b574f251SJerome Glisse return r; 721b1e3a6d1SMichel Dänzer 722b574f251SJerome Glisse if (rdev->flags & RADEON_IS_AGP && !rdev->accel_working) { 723b574f251SJerome Glisse /* Acceleration not working on AGP card try again 724b574f251SJerome Glisse * with fallback to PCI or PCIE GART 725b574f251SJerome Glisse */ 7261a029b76SJerome Glisse radeon_gpu_reset(rdev); 727b574f251SJerome Glisse radeon_fini(rdev); 728b574f251SJerome Glisse radeon_agp_disable(rdev); 729b574f251SJerome Glisse r = radeon_init(rdev); 7304aac0473SJerome Glisse if (r) 7314aac0473SJerome Glisse return r; 7323ce0a23dSJerome Glisse } 733ecc0b326SMichel Dänzer if (radeon_testing) { 734ecc0b326SMichel Dänzer radeon_test_moves(rdev); 735ecc0b326SMichel Dänzer } 736771fe6b9SJerome Glisse if (radeon_benchmarking) { 737771fe6b9SJerome Glisse radeon_benchmark(rdev); 738771fe6b9SJerome Glisse } 7396cf8a3f5SJerome Glisse return 0; 740771fe6b9SJerome Glisse } 741771fe6b9SJerome Glisse 742771fe6b9SJerome Glisse void radeon_device_fini(struct radeon_device *rdev) 743771fe6b9SJerome Glisse { 744771fe6b9SJerome Glisse DRM_INFO("radeon: finishing device.\n"); 745771fe6b9SJerome Glisse rdev->shutdown = true; 7463ce0a23dSJerome Glisse radeon_fini(rdev); 747d4877cf2SAlex Deucher destroy_workqueue(rdev->wq); 748c1176d6fSDave Airlie vga_client_register(rdev->pdev, NULL, NULL, NULL); 749771fe6b9SJerome Glisse iounmap(rdev->rmmio); 750771fe6b9SJerome Glisse rdev->rmmio = NULL; 751771fe6b9SJerome Glisse } 752771fe6b9SJerome Glisse 753771fe6b9SJerome Glisse 754771fe6b9SJerome Glisse /* 755771fe6b9SJerome Glisse * Suspend & resume. 756771fe6b9SJerome Glisse */ 757771fe6b9SJerome Glisse int radeon_suspend_kms(struct drm_device *dev, pm_message_t state) 758771fe6b9SJerome Glisse { 759875c1866SDarren Jenkins struct radeon_device *rdev; 760771fe6b9SJerome Glisse struct drm_crtc *crtc; 7614c788679SJerome Glisse int r; 762771fe6b9SJerome Glisse 763875c1866SDarren Jenkins if (dev == NULL || dev->dev_private == NULL) { 764771fe6b9SJerome Glisse return -ENODEV; 765771fe6b9SJerome Glisse } 766771fe6b9SJerome Glisse if (state.event == PM_EVENT_PRETHAW) { 767771fe6b9SJerome Glisse return 0; 768771fe6b9SJerome Glisse } 769875c1866SDarren Jenkins rdev = dev->dev_private; 770875c1866SDarren Jenkins 771771fe6b9SJerome Glisse /* unpin the front buffers */ 772771fe6b9SJerome Glisse list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 773771fe6b9SJerome Glisse struct radeon_framebuffer *rfb = to_radeon_framebuffer(crtc->fb); 7744c788679SJerome Glisse struct radeon_bo *robj; 775771fe6b9SJerome Glisse 776771fe6b9SJerome Glisse if (rfb == NULL || rfb->obj == NULL) { 777771fe6b9SJerome Glisse continue; 778771fe6b9SJerome Glisse } 779771fe6b9SJerome Glisse robj = rfb->obj->driver_private; 7804c788679SJerome Glisse if (robj != rdev->fbdev_rbo) { 7814c788679SJerome Glisse r = radeon_bo_reserve(robj, false); 7824c788679SJerome Glisse if (unlikely(r == 0)) { 7834c788679SJerome Glisse radeon_bo_unpin(robj); 7844c788679SJerome Glisse radeon_bo_unreserve(robj); 7854c788679SJerome Glisse } 786771fe6b9SJerome Glisse } 787771fe6b9SJerome Glisse } 788771fe6b9SJerome Glisse /* evict vram memory */ 7894c788679SJerome Glisse radeon_bo_evict_vram(rdev); 790771fe6b9SJerome Glisse /* wait for gpu to finish processing current batch */ 791771fe6b9SJerome Glisse radeon_fence_wait_last(rdev); 792771fe6b9SJerome Glisse 793f657c2a7SYang Zhao radeon_save_bios_scratch_regs(rdev); 794f657c2a7SYang Zhao 7953ce0a23dSJerome Glisse radeon_suspend(rdev); 796d4877cf2SAlex Deucher radeon_hpd_fini(rdev); 797771fe6b9SJerome Glisse /* evict remaining vram memory */ 7984c788679SJerome Glisse radeon_bo_evict_vram(rdev); 799771fe6b9SJerome Glisse 800771fe6b9SJerome Glisse pci_save_state(dev->pdev); 801771fe6b9SJerome Glisse if (state.event == PM_EVENT_SUSPEND) { 802771fe6b9SJerome Glisse /* Shut down the device */ 803771fe6b9SJerome Glisse pci_disable_device(dev->pdev); 804771fe6b9SJerome Glisse pci_set_power_state(dev->pdev, PCI_D3hot); 805771fe6b9SJerome Glisse } 806771fe6b9SJerome Glisse acquire_console_sem(); 807771fe6b9SJerome Glisse fb_set_suspend(rdev->fbdev_info, 1); 808771fe6b9SJerome Glisse release_console_sem(); 809771fe6b9SJerome Glisse return 0; 810771fe6b9SJerome Glisse } 811771fe6b9SJerome Glisse 812771fe6b9SJerome Glisse int radeon_resume_kms(struct drm_device *dev) 813771fe6b9SJerome Glisse { 814771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 815771fe6b9SJerome Glisse 816771fe6b9SJerome Glisse acquire_console_sem(); 817771fe6b9SJerome Glisse pci_set_power_state(dev->pdev, PCI_D0); 818771fe6b9SJerome Glisse pci_restore_state(dev->pdev); 819771fe6b9SJerome Glisse if (pci_enable_device(dev->pdev)) { 820771fe6b9SJerome Glisse release_console_sem(); 821771fe6b9SJerome Glisse return -1; 822771fe6b9SJerome Glisse } 823771fe6b9SJerome Glisse pci_set_master(dev->pdev); 8240ebf1717SDave Airlie /* resume AGP if in use */ 8250ebf1717SDave Airlie radeon_agp_resume(rdev); 8263ce0a23dSJerome Glisse radeon_resume(rdev); 827f657c2a7SYang Zhao radeon_restore_bios_scratch_regs(rdev); 828771fe6b9SJerome Glisse fb_set_suspend(rdev->fbdev_info, 0); 829771fe6b9SJerome Glisse release_console_sem(); 830771fe6b9SJerome Glisse 831d4877cf2SAlex Deucher /* reset hpd state */ 832d4877cf2SAlex Deucher radeon_hpd_init(rdev); 833771fe6b9SJerome Glisse /* blat the mode back in */ 834771fe6b9SJerome Glisse drm_helper_resume_force_mode(dev); 835771fe6b9SJerome Glisse return 0; 836771fe6b9SJerome Glisse } 837771fe6b9SJerome Glisse 838771fe6b9SJerome Glisse 839771fe6b9SJerome Glisse /* 840771fe6b9SJerome Glisse * Debugfs 841771fe6b9SJerome Glisse */ 842771fe6b9SJerome Glisse struct radeon_debugfs { 843771fe6b9SJerome Glisse struct drm_info_list *files; 844771fe6b9SJerome Glisse unsigned num_files; 845771fe6b9SJerome Glisse }; 846771fe6b9SJerome Glisse static struct radeon_debugfs _radeon_debugfs[RADEON_DEBUGFS_MAX_NUM_FILES]; 847771fe6b9SJerome Glisse static unsigned _radeon_debugfs_count = 0; 848771fe6b9SJerome Glisse 849771fe6b9SJerome Glisse int radeon_debugfs_add_files(struct radeon_device *rdev, 850771fe6b9SJerome Glisse struct drm_info_list *files, 851771fe6b9SJerome Glisse unsigned nfiles) 852771fe6b9SJerome Glisse { 853771fe6b9SJerome Glisse unsigned i; 854771fe6b9SJerome Glisse 855771fe6b9SJerome Glisse for (i = 0; i < _radeon_debugfs_count; i++) { 856771fe6b9SJerome Glisse if (_radeon_debugfs[i].files == files) { 857771fe6b9SJerome Glisse /* Already registered */ 858771fe6b9SJerome Glisse return 0; 859771fe6b9SJerome Glisse } 860771fe6b9SJerome Glisse } 861771fe6b9SJerome Glisse if ((_radeon_debugfs_count + nfiles) > RADEON_DEBUGFS_MAX_NUM_FILES) { 862771fe6b9SJerome Glisse DRM_ERROR("Reached maximum number of debugfs files.\n"); 863771fe6b9SJerome Glisse DRM_ERROR("Report so we increase RADEON_DEBUGFS_MAX_NUM_FILES.\n"); 864771fe6b9SJerome Glisse return -EINVAL; 865771fe6b9SJerome Glisse } 866771fe6b9SJerome Glisse _radeon_debugfs[_radeon_debugfs_count].files = files; 867771fe6b9SJerome Glisse _radeon_debugfs[_radeon_debugfs_count].num_files = nfiles; 868771fe6b9SJerome Glisse _radeon_debugfs_count++; 869771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 870771fe6b9SJerome Glisse drm_debugfs_create_files(files, nfiles, 871771fe6b9SJerome Glisse rdev->ddev->control->debugfs_root, 872771fe6b9SJerome Glisse rdev->ddev->control); 873771fe6b9SJerome Glisse drm_debugfs_create_files(files, nfiles, 874771fe6b9SJerome Glisse rdev->ddev->primary->debugfs_root, 875771fe6b9SJerome Glisse rdev->ddev->primary); 876771fe6b9SJerome Glisse #endif 877771fe6b9SJerome Glisse return 0; 878771fe6b9SJerome Glisse } 879771fe6b9SJerome Glisse 880771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 881771fe6b9SJerome Glisse int radeon_debugfs_init(struct drm_minor *minor) 882771fe6b9SJerome Glisse { 883771fe6b9SJerome Glisse return 0; 884771fe6b9SJerome Glisse } 885771fe6b9SJerome Glisse 886771fe6b9SJerome Glisse void radeon_debugfs_cleanup(struct drm_minor *minor) 887771fe6b9SJerome Glisse { 888771fe6b9SJerome Glisse unsigned i; 889771fe6b9SJerome Glisse 890771fe6b9SJerome Glisse for (i = 0; i < _radeon_debugfs_count; i++) { 891771fe6b9SJerome Glisse drm_debugfs_remove_files(_radeon_debugfs[i].files, 892771fe6b9SJerome Glisse _radeon_debugfs[i].num_files, minor); 893771fe6b9SJerome Glisse } 894771fe6b9SJerome Glisse } 895771fe6b9SJerome Glisse #endif 896