drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
Extension
.c
Size
191309 bytes
Lines
6975
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (memory_carved >= SZ_1G/SZ_1M) {
			size += sysfs_emit_at(buf, size, "%d: %s (%u GB)\n",
					      i,
					      uma_info->entries[i].name,
					      memory_carved >> 10);
		} else {
			size += sysfs_emit_at(buf, size, "%d: %s (%u MB)\n",
					      i,
					      uma_info->entries[i].name,
					      memory_carved);
		}
	}

	return size;
}
static DEVICE_ATTR_RO(carveout_options);

/**
 * DOC: uma/carveout
 *
 * This file is both readable and writable. When read, it shows the
 * index of the current setting. Writing a valid index to this file
 * allows users to change the UMA carveout size to the selected option
 * on the next boot.
 *
 * The available options and their corresponding indices can be read
 * from the uma/carveout_options file.
 */
static ssize_t carveout_show(struct device *dev,
			     struct device_attribute *attr,
			     char *buf)
{
	struct drm_device *ddev = dev_get_drvdata(dev);
	struct amdgpu_device *adev = drm_to_adev(ddev);

	return sysfs_emit(buf, "%u\n", adev->uma_info.uma_option_index);
}

static ssize_t carveout_store(struct device *dev,
			      struct device_attribute *attr,
			      const char *buf, size_t count)
{
	struct drm_device *ddev = dev_get_drvdata(dev);
	struct amdgpu_device *adev = drm_to_adev(ddev);
	struct amdgpu_uma_carveout_info *uma_info = &adev->uma_info;
	struct amdgpu_uma_carveout_option *opt;
	unsigned long val;
	uint8_t flags;
	int r;

	r = kstrtoul(buf, 10, &val);
	if (r)
		return r;

	if (val >= uma_info->num_entries)
		return -EINVAL;

	val = array_index_nospec(val, uma_info->num_entries);
	opt = &uma_info->entries[val];

	if (!(opt->flags & AMDGPU_UMA_FLAG_AUTO) &&
	    !(opt->flags & AMDGPU_UMA_FLAG_CUSTOM)) {
		drm_err_once(ddev, "Option %lu not supported due to lack of Custom/Auto flag", val);
		return -EINVAL;
	}

	flags = opt->flags;
	flags &= ~((flags & AMDGPU_UMA_FLAG_AUTO) >> 1);

	guard(mutex)(&uma_info->update_lock);

	r = amdgpu_acpi_set_uma_allocation_size(adev, val, flags);
	if (r)
		return r;

	uma_info->uma_option_index = val;

	return count;
}
static DEVICE_ATTR_RW(carveout);

static struct attribute *amdgpu_uma_attrs[] = {
	&dev_attr_carveout.attr,
	&dev_attr_carveout_options.attr,
	NULL
};

const struct attribute_group amdgpu_uma_attr_group = {
	.name = "uma",
	.attrs = amdgpu_uma_attrs

Annotation

Implementation Notes