drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c
Extension
.c
Size
8310 bytes
Lines
329
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 (info.link != 0xff) {
			int ret = nvkm_volt_map_min(volt, info.link);
			if (ret < 0)
				return ret;
			info.min += ret;
		}
		return info.min;
	}

	return id ? id * 10000 : -ENODEV;
}

int
nvkm_volt_map(struct nvkm_volt *volt, u8 id, u8 temp)
{
	struct nvkm_bios *bios = volt->subdev.device->bios;
	struct nvbios_vmap_entry info;
	u8  ver, len;
	u32 vmap;

	vmap = nvbios_vmap_entry_parse(bios, id, &ver, &len, &info);
	if (vmap) {
		s64 result;

		if (volt->speedo < 0)
			return volt->speedo;

		if (ver == 0x10 || (ver == 0x20 && info.mode == 0)) {
			result  = div64_s64((s64)info.arg[0], 10);
			result += div64_s64((s64)info.arg[1] * volt->speedo, 10);
			result += div64_s64((s64)info.arg[2] * volt->speedo * volt->speedo, 100000);
		} else if (ver == 0x20) {
			switch (info.mode) {
			/* 0x0 handled above! */
			case 0x1:
				result =  ((s64)info.arg[0] * 15625) >> 18;
				result += ((s64)info.arg[1] * volt->speedo * 15625) >> 18;
				result += ((s64)info.arg[2] * temp * 15625) >> 10;
				result += ((s64)info.arg[3] * volt->speedo * temp * 15625) >> 18;
				result += ((s64)info.arg[4] * volt->speedo * volt->speedo * 15625) >> 30;
				result += ((s64)info.arg[5] * temp * temp * 15625) >> 18;
				break;
			case 0x3:
				result = (info.min + info.max) / 2;
				break;
			case 0x2:
			default:
				result = info.min;
				break;
			}
		} else {
			return -ENODEV;
		}

		result = clamp(result, (s64)info.min, (s64)info.max);

		if (info.link != 0xff) {
			int ret = nvkm_volt_map(volt, info.link, temp);
			if (ret < 0)
				return ret;
			result += ret;
		}
		return result;
	}

	return id ? id * 10000 : -ENODEV;
}

int
nvkm_volt_set_id(struct nvkm_volt *volt, u8 id, u8 min_id, u8 temp,
		 int condition)
{
	int ret;

	if (volt->func->set_id)
		return volt->func->set_id(volt, id, condition);

	ret = nvkm_volt_map(volt, id, temp);
	if (ret >= 0) {
		int prev = nvkm_volt_get(volt);
		if (!condition || prev < 0 ||
		    (condition < 0 && ret < prev) ||
		    (condition > 0 && ret > prev)) {
			int min = nvkm_volt_map(volt, min_id, temp);
			if (min >= 0)
				ret = max(min, ret);
			ret = nvkm_volt_set(volt, ret);
		} else {
			ret = 0;
		}

Annotation

Implementation Notes