Commit e5aaad61 authored by Ville Syrjälä's avatar Ville Syrjälä

drm/i915: Extract mchbar_reg()

Stop repeating the same logic to determine the correct
config space register for MCHBAR.
Signed-off-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20231101114212.9345-4-ville.syrjala@linux.intel.comReviewed-by: default avatarJani Nikula <jani.nikula@intel.com>
parent f18020a5
...@@ -33,18 +33,22 @@ int intel_gmch_bridge_setup(struct drm_i915_private *i915) ...@@ -33,18 +33,22 @@ int intel_gmch_bridge_setup(struct drm_i915_private *i915)
i915->gmch.pdev); i915->gmch.pdev);
} }
static int mchbar_reg(struct drm_i915_private *i915)
{
return GRAPHICS_VER(i915) >= 4 ? MCHBAR_I965 : MCHBAR_I915;
}
/* Allocate space for the MCH regs if needed, return nonzero on error */ /* Allocate space for the MCH regs if needed, return nonzero on error */
static int static int
intel_alloc_mchbar_resource(struct drm_i915_private *i915) intel_alloc_mchbar_resource(struct drm_i915_private *i915)
{ {
int reg = GRAPHICS_VER(i915) >= 4 ? MCHBAR_I965 : MCHBAR_I915;
u32 temp_lo, temp_hi = 0; u32 temp_lo, temp_hi = 0;
u64 mchbar_addr; u64 mchbar_addr;
int ret; int ret;
if (GRAPHICS_VER(i915) >= 4) if (GRAPHICS_VER(i915) >= 4)
pci_read_config_dword(i915->gmch.pdev, reg + 4, &temp_hi); pci_read_config_dword(i915->gmch.pdev, mchbar_reg(i915) + 4, &temp_hi);
pci_read_config_dword(i915->gmch.pdev, reg, &temp_lo); pci_read_config_dword(i915->gmch.pdev, mchbar_reg(i915), &temp_lo);
mchbar_addr = ((u64)temp_hi << 32) | temp_lo; mchbar_addr = ((u64)temp_hi << 32) | temp_lo;
/* If ACPI doesn't have it, assume we need to allocate it ourselves */ /* If ACPI doesn't have it, assume we need to allocate it ourselves */
...@@ -68,10 +72,10 @@ intel_alloc_mchbar_resource(struct drm_i915_private *i915) ...@@ -68,10 +72,10 @@ intel_alloc_mchbar_resource(struct drm_i915_private *i915)
} }
if (GRAPHICS_VER(i915) >= 4) if (GRAPHICS_VER(i915) >= 4)
pci_write_config_dword(i915->gmch.pdev, reg + 4, pci_write_config_dword(i915->gmch.pdev, mchbar_reg(i915) + 4,
upper_32_bits(i915->gmch.mch_res.start)); upper_32_bits(i915->gmch.mch_res.start));
pci_write_config_dword(i915->gmch.pdev, reg, pci_write_config_dword(i915->gmch.pdev, mchbar_reg(i915),
lower_32_bits(i915->gmch.mch_res.start)); lower_32_bits(i915->gmch.mch_res.start));
return 0; return 0;
} }
...@@ -79,7 +83,6 @@ intel_alloc_mchbar_resource(struct drm_i915_private *i915) ...@@ -79,7 +83,6 @@ intel_alloc_mchbar_resource(struct drm_i915_private *i915)
/* Setup MCHBAR if possible, return true if we should disable it again */ /* Setup MCHBAR if possible, return true if we should disable it again */
void intel_gmch_bar_setup(struct drm_i915_private *i915) void intel_gmch_bar_setup(struct drm_i915_private *i915)
{ {
int mchbar_reg = GRAPHICS_VER(i915) >= 4 ? MCHBAR_I965 : MCHBAR_I915;
u32 temp; u32 temp;
bool enabled; bool enabled;
...@@ -92,7 +95,7 @@ void intel_gmch_bar_setup(struct drm_i915_private *i915) ...@@ -92,7 +95,7 @@ void intel_gmch_bar_setup(struct drm_i915_private *i915)
pci_read_config_dword(i915->gmch.pdev, DEVEN, &temp); pci_read_config_dword(i915->gmch.pdev, DEVEN, &temp);
enabled = !!(temp & DEVEN_MCHBAR_EN); enabled = !!(temp & DEVEN_MCHBAR_EN);
} else { } else {
pci_read_config_dword(i915->gmch.pdev, mchbar_reg, &temp); pci_read_config_dword(i915->gmch.pdev, mchbar_reg(i915), &temp);
enabled = temp & 1; enabled = temp & 1;
} }
...@@ -110,15 +113,13 @@ void intel_gmch_bar_setup(struct drm_i915_private *i915) ...@@ -110,15 +113,13 @@ void intel_gmch_bar_setup(struct drm_i915_private *i915)
pci_write_config_dword(i915->gmch.pdev, DEVEN, pci_write_config_dword(i915->gmch.pdev, DEVEN,
temp | DEVEN_MCHBAR_EN); temp | DEVEN_MCHBAR_EN);
} else { } else {
pci_read_config_dword(i915->gmch.pdev, mchbar_reg, &temp); pci_read_config_dword(i915->gmch.pdev, mchbar_reg(i915), &temp);
pci_write_config_dword(i915->gmch.pdev, mchbar_reg, temp | 1); pci_write_config_dword(i915->gmch.pdev, mchbar_reg(i915), temp | 1);
} }
} }
void intel_gmch_bar_teardown(struct drm_i915_private *i915) void intel_gmch_bar_teardown(struct drm_i915_private *i915)
{ {
int mchbar_reg = GRAPHICS_VER(i915) >= 4 ? MCHBAR_I965 : MCHBAR_I915;
if (i915->gmch.mchbar_need_disable) { if (i915->gmch.mchbar_need_disable) {
if (IS_I915G(i915) || IS_I915GM(i915)) { if (IS_I915G(i915) || IS_I915GM(i915)) {
u32 deven_val; u32 deven_val;
...@@ -131,10 +132,10 @@ void intel_gmch_bar_teardown(struct drm_i915_private *i915) ...@@ -131,10 +132,10 @@ void intel_gmch_bar_teardown(struct drm_i915_private *i915)
} else { } else {
u32 mchbar_val; u32 mchbar_val;
pci_read_config_dword(i915->gmch.pdev, mchbar_reg, pci_read_config_dword(i915->gmch.pdev, mchbar_reg(i915),
&mchbar_val); &mchbar_val);
mchbar_val &= ~1; mchbar_val &= ~1;
pci_write_config_dword(i915->gmch.pdev, mchbar_reg, pci_write_config_dword(i915->gmch.pdev, mchbar_reg(i915),
mchbar_val); mchbar_val);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment