Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a0f8918 authored by Dave Airlie's avatar Dave Airlie Committed by Dave Airlie
Browse files

drm/radeon/kms: fix VRAM sizing like DDX does it.



Doing this like the DDX seems like the most sure fire way to avoid
having to reinvent it slowly and painfully. At the moment we keep
getting things wrong with aper vs vram, so we know the DDX does it right.

booted on PCI r100, PCIE rv370, IGP rs400.

Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent ad49f501
Loading
Loading
Loading
Loading
+63 −2
Original line number Original line Diff line number Diff line
@@ -1360,9 +1360,50 @@ static void r100_vram_get_type(struct radeon_device *rdev)
	}
	}
}
}


void r100_vram_info(struct radeon_device *rdev)
static u32 r100_get_accessible_vram(struct radeon_device *rdev)
{
{
	r100_vram_get_type(rdev);
	u32 aper_size;
	u8 byte;

	aper_size = RREG32(RADEON_CONFIG_APER_SIZE);

	/* Set HDP_APER_CNTL only on cards that are known not to be broken,
	 * that is has the 2nd generation multifunction PCI interface
	 */
	if (rdev->family == CHIP_RV280 ||
	    rdev->family >= CHIP_RV350) {
		WREG32_P(RADEON_HOST_PATH_CNTL, RADEON_HDP_APER_CNTL,
		       ~RADEON_HDP_APER_CNTL);
		DRM_INFO("Generation 2 PCI interface, using max accessible memory\n");
		return aper_size * 2;
	}

	/* Older cards have all sorts of funny issues to deal with. First
	 * check if it's a multifunction card by reading the PCI config
	 * header type... Limit those to one aperture size
	 */
	pci_read_config_byte(rdev->pdev, 0xe, &byte);
	if (byte & 0x80) {
		DRM_INFO("Generation 1 PCI interface in multifunction mode\n");
		DRM_INFO("Limiting VRAM to one aperture\n");
		return aper_size;
	}

	/* Single function older card. We read HDP_APER_CNTL to see how the BIOS
	 * have set it up. We don't write this as it's broken on some ASICs but
	 * we expect the BIOS to have done the right thing (might be too optimistic...)
	 */
	if (RREG32(RADEON_HOST_PATH_CNTL) & RADEON_HDP_APER_CNTL)
		return aper_size * 2;
	return aper_size;
}

void r100_vram_init_sizes(struct radeon_device *rdev)
{
	u64 config_aper_size;
	u32 accessible;

	config_aper_size = RREG32(RADEON_CONFIG_APER_SIZE);


	if (rdev->flags & RADEON_IS_IGP) {
	if (rdev->flags & RADEON_IS_IGP) {
		uint32_t tom;
		uint32_t tom;
@@ -1383,10 +1424,30 @@ void r100_vram_info(struct radeon_device *rdev)
		}
		}
		/* let driver place VRAM */
		/* let driver place VRAM */
		rdev->mc.vram_location = 0xFFFFFFFFUL;
		rdev->mc.vram_location = 0xFFFFFFFFUL;
		 /* Fix for RN50, M6, M7 with 8/16/32(??) MBs of VRAM - 
		  * Novell bug 204882 + along with lots of ubuntu ones */
		if (config_aper_size > rdev->mc.vram_size)
			rdev->mc.vram_size = config_aper_size;
	}
	}


	/* work out accessible VRAM */
	accessible = r100_get_accessible_vram(rdev);

	rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
	rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
	rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
	rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);

	if (accessible > rdev->mc.aper_size)
		accessible = rdev->mc.aper_size;

	if (rdev->mc.vram_size > rdev->mc.aper_size)
		rdev->mc.vram_size = rdev->mc.aper_size;
}

void r100_vram_info(struct radeon_device *rdev)
{
	r100_vram_get_type(rdev);

	r100_vram_init_sizes(rdev);
}
}




+1 −3
Original line number Original line Diff line number Diff line
@@ -585,10 +585,8 @@ void r300_vram_info(struct radeon_device *rdev)
	} else {
	} else {
		rdev->mc.vram_width = 64;
		rdev->mc.vram_width = 64;
	}
	}
	rdev->mc.vram_size = RREG32(RADEON_CONFIG_MEMSIZE);


	rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
	r100_vram_init_sizes(rdev);
	rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
}
}




+1 −3
Original line number Original line Diff line number Diff line
@@ -227,8 +227,6 @@ static void r520_vram_get_type(struct radeon_device *rdev)
void r520_vram_info(struct radeon_device *rdev)
void r520_vram_info(struct radeon_device *rdev)
{
{
	r520_vram_get_type(rdev);
	r520_vram_get_type(rdev);
	rdev->mc.vram_size = RREG32(RADEON_CONFIG_MEMSIZE);


	rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
	r100_vram_init_sizes(rdev);
	rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
}
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -541,6 +541,8 @@ union radeon_asic_config {
	struct r300_asic	r300;
	struct r300_asic	r300;
};
};


/* r100 */
void r100_vram_init_sizes(struct radeon_device *rdev);


/*
/*
 * IOCTL.
 * IOCTL.
+1 −6
Original line number Original line Diff line number Diff line
@@ -561,12 +561,7 @@ int radeon_device_init(struct radeon_device *rdev,
	}
	}
	/* Get vram informations */
	/* Get vram informations */
	radeon_vram_info(rdev);
	radeon_vram_info(rdev);
	/* Device is severly broken if aper size > vram size.

	 * for RN50/M6/M7 - Novell bug 204882 ?
	 */
	if (rdev->mc.vram_size < rdev->mc.aper_size) {
		rdev->mc.vram_size = rdev->mc.aper_size;
	}
	/* Add an MTRR for the VRAM */
	/* Add an MTRR for the VRAM */
	rdev->mc.vram_mtrr = mtrr_add(rdev->mc.aper_base, rdev->mc.aper_size,
	rdev->mc.vram_mtrr = mtrr_add(rdev->mc.aper_base, rdev->mc.aper_size,
				      MTRR_TYPE_WRCOMB, 1);
				      MTRR_TYPE_WRCOMB, 1);
Loading