/* * Copyright 2008 Advanced Micro Devices, Inc. * Copyright 2008 Red Hat Inc. * Copyright 2009 Jerome Glisse. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Authors: Dave Airlie * Alex Deucher * Jerome Glisse */ #include <linux/console.h> #include <linux/efi.h> #include <linux/pci.h> #include <linux/pm_runtime.h> #include <linux/slab.h> #include <linux/vga_switcheroo.h> #include <linux/vgaarb.h> #include <drm/drm_cache.h> #include <drm/drm_crtc_helper.h> #include <drm/drm_device.h> #include <drm/drm_file.h> #include <drm/drm_framebuffer.h> #include <drm/drm_probe_helper.h> #include <drm/radeon_drm.h> #include "radeon_device.h" #include "radeon_reg.h" #include "radeon.h" #include "atom.h" static const char radeon_family_name[][16] = …; #if defined(CONFIG_VGA_SWITCHEROO) bool radeon_has_atpx_dgpu_power_cntl(void); bool radeon_is_atpx_hybrid(void); #else static inline bool radeon_has_atpx_dgpu_power_cntl(void) { return false; } static inline bool radeon_is_atpx_hybrid(void) { return false; } #endif #define RADEON_PX_QUIRK_DISABLE_PX … struct radeon_px_quirk { … }; static struct radeon_px_quirk radeon_px_quirk_list[] = …; bool radeon_is_px(struct drm_device *dev) { … } static void radeon_device_handle_px_quirks(struct radeon_device *rdev) { … } /** * radeon_program_register_sequence - program an array of registers. * * @rdev: radeon_device pointer * @registers: pointer to the register array * @array_size: size of the register array * * Programs an array or registers with and and or masks. * This is a helper for setting golden registers. */ void radeon_program_register_sequence(struct radeon_device *rdev, const u32 *registers, const u32 array_size) { … } void radeon_pci_config_reset(struct radeon_device *rdev) { … } /** * radeon_surface_init - Clear GPU surface registers. * * @rdev: radeon_device pointer * * Clear GPU surface registers (r1xx-r5xx). */ void radeon_surface_init(struct radeon_device *rdev) { … } /* * GPU scratch registers helpers function. */ /** * radeon_scratch_init - Init scratch register driver information. * * @rdev: radeon_device pointer * * Init CP scratch register driver information (r1xx-r5xx) */ void radeon_scratch_init(struct radeon_device *rdev) { … } /** * radeon_scratch_get - Allocate a scratch register * * @rdev: radeon_device pointer * @reg: scratch register mmio offset * * Allocate a CP scratch register for use by the driver (all asics). * Returns 0 on success or -EINVAL on failure. */ int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg) { … } /** * radeon_scratch_free - Free a scratch register * * @rdev: radeon_device pointer * @reg: scratch register mmio offset * * Free a CP scratch register allocated for use by the driver (all asics) */ void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg) { … } /* * GPU doorbell aperture helpers function. */ /** * radeon_doorbell_init - Init doorbell driver information. * * @rdev: radeon_device pointer * * Init doorbell driver information (CIK) * Returns 0 on success, error on failure. */ static int radeon_doorbell_init(struct radeon_device *rdev) { … } /** * radeon_doorbell_fini - Tear down doorbell driver information. * * @rdev: radeon_device pointer * * Tear down doorbell driver information (CIK) */ static void radeon_doorbell_fini(struct radeon_device *rdev) { … } /** * radeon_doorbell_get - Allocate a doorbell entry * * @rdev: radeon_device pointer * @doorbell: doorbell index * * Allocate a doorbell for use by the driver (all asics). * Returns 0 on success or -EINVAL on failure. */ int radeon_doorbell_get(struct radeon_device *rdev, u32 *doorbell) { … } /** * radeon_doorbell_free - Free a doorbell entry * * @rdev: radeon_device pointer * @doorbell: doorbell index * * Free a doorbell allocated for use by the driver (all asics) */ void radeon_doorbell_free(struct radeon_device *rdev, u32 doorbell) { … } /* * radeon_wb_*() * Writeback is the method by which the GPU updates special pages * in memory with the status of certain GPU events (fences, ring pointers, * etc.). */ /** * radeon_wb_disable - Disable Writeback * * @rdev: radeon_device pointer * * Disables Writeback (all asics). Used for suspend. */ void radeon_wb_disable(struct radeon_device *rdev) { … } /** * radeon_wb_fini - Disable Writeback and free memory * * @rdev: radeon_device pointer * * Disables Writeback and frees the Writeback memory (all asics). * Used at driver shutdown. */ void radeon_wb_fini(struct radeon_device *rdev) { … } /** * radeon_wb_init- Init Writeback driver info and allocate memory * * @rdev: radeon_device pointer * * Disables Writeback and frees the Writeback memory (all asics). * Used at driver startup. * Returns 0 on success or an -error on failure. */ int radeon_wb_init(struct radeon_device *rdev) { … } /** * radeon_vram_location - try to find VRAM location * @rdev: radeon device structure holding all necessary informations * @mc: memory controller structure holding memory informations * @base: base address at which to put VRAM * * Function will place try to place VRAM at base address provided * as parameter (which is so far either PCI aperture address or * for IGP TOM base address). * * If there is not enough space to fit the unvisible VRAM in the 32bits * address space then we limit the VRAM size to the aperture. * * If we are using AGP and if the AGP aperture doesn't allow us to have * room for all the VRAM than we restrict the VRAM to the PCI aperture * size and print a warning. * * This function will never fails, worst case are limiting VRAM. * * Note: GTT start, end, size should be initialized before calling this * function on AGP platform. * * Note 1: We don't explicitly enforce VRAM start to be aligned on VRAM size, * this shouldn't be a problem as we are using the PCI aperture as a reference. * Otherwise this would be needed for rv280, all r3xx, and all r4xx, but * not IGP. * * Note 2: we use mc_vram_size as on some board we need to program the mc to * cover the whole aperture even if VRAM size is inferior to aperture size * Novell bug 204882 + along with lots of ubuntu ones * * Note 3: when limiting vram it's safe to overwritte real_vram_size because * we are not in case where real_vram_size is inferior to mc_vram_size (ie * note afected by bogus hw of Novell bug 204882 + along with lots of ubuntu * ones) * * Note 4: IGP TOM addr should be the same as the aperture addr, we don't * explicitly check for that thought. * * FIXME: when reducing VRAM size align new size on power of 2. */ void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base) { … } /** * radeon_gtt_location - try to find GTT location * @rdev: radeon device structure holding all necessary informations * @mc: memory controller structure holding memory informations * * Function will place try to place GTT before or after VRAM. * * If GTT size is bigger than space left then we ajust GTT size. * Thus function will never fails. * * FIXME: when reducing GTT size align new size on power of 2. */ void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc) { … } /* * GPU helpers function. */ /* * radeon_device_is_virtual - check if we are running is a virtual environment * * Check if the asic has been passed through to a VM (all asics). * Used at driver startup. * Returns true if virtual or false if not. */ bool radeon_device_is_virtual(void) { … } /** * radeon_card_posted - check if the hw has already been initialized * * @rdev: radeon_device pointer * * Check if the asic has been initialized (all asics). * Used at driver startup. * Returns true if initialized or false if not. */ bool radeon_card_posted(struct radeon_device *rdev) { … } /** * radeon_update_bandwidth_info - update display bandwidth params * * @rdev: radeon_device pointer * * Used when sclk/mclk are switched or display modes are set. * params are used to calculate display watermarks (all asics) */ void radeon_update_bandwidth_info(struct radeon_device *rdev) { … } /** * radeon_boot_test_post_card - check and possibly initialize the hw * * @rdev: radeon_device pointer * * Check if the asic is initialized and if not, attempt to initialize * it (all asics). * Returns true if initialized or false if not. */ bool radeon_boot_test_post_card(struct radeon_device *rdev) { … } /** * radeon_dummy_page_init - init dummy page used by the driver * * @rdev: radeon_device pointer * * Allocate the dummy page used by the driver (all asics). * This dummy page is used by the driver as a filler for gart entries * when pages are taken out of the GART * Returns 0 on sucess, -ENOMEM on failure. */ int radeon_dummy_page_init(struct radeon_device *rdev) { … } /** * radeon_dummy_page_fini - free dummy page used by the driver * * @rdev: radeon_device pointer * * Frees the dummy page used by the driver (all asics). */ void radeon_dummy_page_fini(struct radeon_device *rdev) { … } /* ATOM accessor methods */ /* * ATOM is an interpreted byte code stored in tables in the vbios. The * driver registers callbacks to access registers and the interpreter * in the driver parses the tables and executes then to program specific * actions (set display modes, asic init, etc.). See radeon_atombios.c, * atombios.h, and atom.c */ /** * cail_pll_read - read PLL register * * @info: atom card_info pointer * @reg: PLL register offset * * Provides a PLL register accessor for the atom interpreter (r4xx+). * Returns the value of the PLL register. */ static uint32_t cail_pll_read(struct card_info *info, uint32_t reg) { … } /** * cail_pll_write - write PLL register * * @info: atom card_info pointer * @reg: PLL register offset * @val: value to write to the pll register * * Provides a PLL register accessor for the atom interpreter (r4xx+). */ static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val) { … } /** * cail_mc_read - read MC (Memory Controller) register * * @info: atom card_info pointer * @reg: MC register offset * * Provides an MC register accessor for the atom interpreter (r4xx+). * Returns the value of the MC register. */ static uint32_t cail_mc_read(struct card_info *info, uint32_t reg) { … } /** * cail_mc_write - write MC (Memory Controller) register * * @info: atom card_info pointer * @reg: MC register offset * @val: value to write to the pll register * * Provides a MC register accessor for the atom interpreter (r4xx+). */ static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val) { … } /** * cail_reg_write - write MMIO register * * @info: atom card_info pointer * @reg: MMIO register offset * @val: value to write to the pll register * * Provides a MMIO register accessor for the atom interpreter (r4xx+). */ static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val) { … } /** * cail_reg_read - read MMIO register * * @info: atom card_info pointer * @reg: MMIO register offset * * Provides an MMIO register accessor for the atom interpreter (r4xx+). * Returns the value of the MMIO register. */ static uint32_t cail_reg_read(struct card_info *info, uint32_t reg) { … } /** * cail_ioreg_write - write IO register * * @info: atom card_info pointer * @reg: IO register offset * @val: value to write to the pll register * * Provides a IO register accessor for the atom interpreter (r4xx+). */ static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val) { … } /** * cail_ioreg_read - read IO register * * @info: atom card_info pointer * @reg: IO register offset * * Provides an IO register accessor for the atom interpreter (r4xx+). * Returns the value of the IO register. */ static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg) { … } /** * radeon_atombios_init - init the driver info and callbacks for atombios * * @rdev: radeon_device pointer * * Initializes the driver info and register access callbacks for the * ATOM interpreter (r4xx+). * Returns 0 on sucess, -ENOMEM on failure. * Called at driver startup. */ int radeon_atombios_init(struct radeon_device *rdev) { … } /** * radeon_atombios_fini - free the driver info and callbacks for atombios * * @rdev: radeon_device pointer * * Frees the driver info and register access callbacks for the ATOM * interpreter (r4xx+). * Called at driver shutdown. */ void radeon_atombios_fini(struct radeon_device *rdev) { … } /* COMBIOS */ /* * COMBIOS is the bios format prior to ATOM. It provides * command tables similar to ATOM, but doesn't have a unified * parser. See radeon_combios.c */ /** * radeon_combios_init - init the driver info for combios * * @rdev: radeon_device pointer * * Initializes the driver info for combios (r1xx-r3xx). * Returns 0 on sucess. * Called at driver startup. */ int radeon_combios_init(struct radeon_device *rdev) { … } /** * radeon_combios_fini - free the driver info for combios * * @rdev: radeon_device pointer * * Frees the driver info for combios (r1xx-r3xx). * Called at driver shutdown. */ void radeon_combios_fini(struct radeon_device *rdev) { … } /* if we get transitioned to only one device, take VGA back */ /** * radeon_vga_set_decode - enable/disable vga decode * * @pdev: PCI device * @state: enable/disable vga decode * * Enable/disable vga decode (all asics). * Returns VGA resource flags. */ static unsigned int radeon_vga_set_decode(struct pci_dev *pdev, bool state) { … } /** * radeon_gart_size_auto - Determine a sensible default GART size * according to ASIC family. * * @family: ASIC family name */ static int radeon_gart_size_auto(enum radeon_family family) { … } /** * radeon_check_arguments - validate module params * * @rdev: radeon_device pointer * * Validates certain module parameters and updates * the associated values used by the driver (all asics). */ static void radeon_check_arguments(struct radeon_device *rdev) { … } /** * radeon_switcheroo_set_state - set switcheroo state * * @pdev: pci dev pointer * @state: vga_switcheroo state * * Callback for the switcheroo driver. Suspends or resumes * the asics before or after it is powered up using ACPI methods. */ static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state) { … } /** * radeon_switcheroo_can_switch - see if switcheroo state can change * * @pdev: pci dev pointer * * Callback for the switcheroo driver. Check of the switcheroo * state can be changed. * Returns true if the state can be changed, false if not. */ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev) { … } static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = …; /** * radeon_device_init - initialize the driver * * @rdev: radeon_device pointer * @ddev: drm dev pointer * @pdev: pci dev pointer * @flags: driver flags * * Initializes the driver info and hw (all asics). * Returns 0 for success or an error on failure. * Called at driver startup. */ int radeon_device_init(struct radeon_device *rdev, struct drm_device *ddev, struct pci_dev *pdev, uint32_t flags) { … } /** * radeon_device_fini - tear down the driver * * @rdev: radeon_device pointer * * Tear down the driver info (all asics). * Called at driver shutdown. */ void radeon_device_fini(struct radeon_device *rdev) { … } /* * Suspend & resume. */ /* * radeon_suspend_kms - initiate device suspend * * Puts the hw in the suspend state (all asics). * Returns 0 for success or an error on failure. * Called at driver suspend. */ int radeon_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon, bool freeze) { … } /* * radeon_resume_kms - initiate device resume * * Bring the hw back to operating state (all asics). * Returns 0 for success or an error on failure. * Called at driver resume. */ int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon) { … } /** * radeon_gpu_reset - reset the asic * * @rdev: radeon device pointer * * Attempt the reset the GPU if it has hung (all asics). * Returns 0 for success or an error on failure. */ int radeon_gpu_reset(struct radeon_device *rdev) { … }