Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Media device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2010 Nokia Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	     Sakari Ailus <sakari.ailus@iki.fi>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/media.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/version.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <trace/hooks/v4l2mc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <media/media-device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <media/media-devnode.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <media/media-entity.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <media/media-request.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #ifdef CONFIG_MEDIA_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * Legacy defines from linux/media.h. This is the only place we need this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * so we just define it here. The media.h header doesn't expose it to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * kernel to prevent it from being used by drivers, but here (and only here!)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * we need it to handle the legacy behavior.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define MEDIA_ENT_SUBTYPE_MASK			0x0000ffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define MEDIA_ENT_T_DEVNODE_UNKNOWN		(MEDIA_ENT_F_OLD_BASE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 						 MEDIA_ENT_SUBTYPE_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) /* -----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * Userspace API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static inline void __user *media_get_uptr(__u64 arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	return (void __user *)(uintptr_t)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static int media_device_open(struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static int media_device_close(struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static long media_device_get_info(struct media_device *dev, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct media_device_info *info = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	memset(info, 0, sizeof(*info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (dev->driver_name[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		strscpy(info->driver, dev->driver_name, sizeof(info->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		strscpy(info->driver, dev->dev->driver->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			sizeof(info->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	strscpy(info->model, dev->model, sizeof(info->model));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	strscpy(info->serial, dev->serial, sizeof(info->serial));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	strscpy(info->bus_info, dev->bus_info, sizeof(info->bus_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	info->media_version = LINUX_VERSION_CODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	info->driver_version = info->media_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	info->hw_revision = dev->hw_revision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static struct media_entity *find_entity(struct media_device *mdev, u32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct media_entity *entity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	int next = id & MEDIA_ENT_ID_FLAG_NEXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	id &= ~MEDIA_ENT_ID_FLAG_NEXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	media_device_for_each_entity(entity, mdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		if (((media_entity_id(entity) == id) && !next) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		    ((media_entity_id(entity) > id) && next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			return entity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static long media_device_enum_entities(struct media_device *mdev, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct media_entity_desc *entd = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct media_entity *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	ent = find_entity(mdev, entd->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (ent == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	memset(entd, 0, sizeof(*entd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	entd->id = media_entity_id(ent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (ent->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		strscpy(entd->name, ent->name, sizeof(entd->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	entd->type = ent->function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	entd->revision = 0;		/* Unused */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	entd->flags = ent->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	entd->group_id = 0;		/* Unused */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	entd->pads = ent->num_pads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	entd->links = ent->num_links - ent->num_backlinks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 * Workaround for a bug at media-ctl <= v1.10 that makes it to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	 * do the wrong thing if the entity function doesn't belong to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	 * either MEDIA_ENT_F_OLD_BASE or MEDIA_ENT_F_OLD_SUBDEV_BASE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 * Ranges.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	 * Non-subdevices are expected to be at the MEDIA_ENT_F_OLD_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	 * or, otherwise, will be silently ignored by media-ctl when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	 * printing the graphviz diagram. So, map them into the devnode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	 * old range.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (ent->function < MEDIA_ENT_F_OLD_BASE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	    ent->function > MEDIA_ENT_F_TUNER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		if (is_media_entity_v4l2_subdev(ent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			entd->type = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		else if (ent->function != MEDIA_ENT_F_IO_V4L)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			entd->type = MEDIA_ENT_T_DEVNODE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	memcpy(&entd->raw, &ent->info, sizeof(ent->info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static void media_device_kpad_to_upad(const struct media_pad *kpad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 				      struct media_pad_desc *upad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	upad->entity = media_entity_id(kpad->entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	upad->index = kpad->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	upad->flags = kpad->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static long media_device_enum_links(struct media_device *mdev, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct media_links_enum *links = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct media_entity *entity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	entity = find_entity(mdev, links->entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (entity == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (links->pads) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		unsigned int p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		for (p = 0; p < entity->num_pads; p++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			struct media_pad_desc pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			memset(&pad, 0, sizeof(pad));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			media_device_kpad_to_upad(&entity->pads[p], &pad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			if (copy_to_user(&links->pads[p], &pad, sizeof(pad)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (links->links) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		struct media_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		struct media_link_desc __user *ulink_desc = links->links;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		list_for_each_entry(link, &entity->links, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			struct media_link_desc klink_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			/* Ignore backlinks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			if (link->source->entity != entity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			memset(&klink_desc, 0, sizeof(klink_desc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			media_device_kpad_to_upad(link->source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 						  &klink_desc.source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			media_device_kpad_to_upad(link->sink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 						  &klink_desc.sink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			klink_desc.flags = link->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			if (copy_to_user(ulink_desc, &klink_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 					 sizeof(*ulink_desc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			ulink_desc++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	memset(links->reserved, 0, sizeof(links->reserved));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static long media_device_setup_link(struct media_device *mdev, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct media_link_desc *linkd = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct media_link *link = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	struct media_entity *source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	struct media_entity *sink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	/* Find the source and sink entities and link.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	source = find_entity(mdev, linkd->source.entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	sink = find_entity(mdev, linkd->sink.entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (source == NULL || sink == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (linkd->source.index >= source->num_pads ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	    linkd->sink.index >= sink->num_pads)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	link = media_entity_find_link(&source->pads[linkd->source.index],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				      &sink->pads[linkd->sink.index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (link == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	/* Setup the link on both entities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	trace_android_vh_media_device_setup_link(link, linkd, &ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	trace_android_rvh_media_device_setup_link(link, linkd, &ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	memset(linkd->reserved, 0, sizeof(linkd->reserved));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	return __media_entity_setup_link(link, linkd->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static long media_device_get_topology(struct media_device *mdev, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	struct media_v2_topology *topo = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct media_entity *entity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct media_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	struct media_pad *pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct media_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	struct media_v2_entity kentity, __user *uentity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct media_v2_interface kintf, __user *uintf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	struct media_v2_pad kpad, __user *upad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	struct media_v2_link klink, __user *ulink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	topo->topology_version = mdev->topology_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	/* Get entities and number of entities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	uentity = media_get_uptr(topo->ptr_entities);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	media_device_for_each_entity(entity, mdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		if (ret || !uentity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		if (i > topo->num_entities) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			ret = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		/* Copy fields to userspace struct if not error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		memset(&kentity, 0, sizeof(kentity));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		kentity.id = entity->graph_obj.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		kentity.function = entity->function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		kentity.flags = entity->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		strscpy(kentity.name, entity->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			sizeof(kentity.name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		if (copy_to_user(uentity, &kentity, sizeof(kentity)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		uentity++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	topo->num_entities = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	topo->reserved1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	/* Get interfaces and number of interfaces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	uintf = media_get_uptr(topo->ptr_interfaces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	media_device_for_each_intf(intf, mdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		if (ret || !uintf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		if (i > topo->num_interfaces) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			ret = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		memset(&kintf, 0, sizeof(kintf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		/* Copy intf fields to userspace struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		kintf.id = intf->graph_obj.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		kintf.intf_type = intf->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		kintf.flags = intf->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			struct media_intf_devnode *devnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			devnode = intf_to_devnode(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			kintf.devnode.major = devnode->major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			kintf.devnode.minor = devnode->minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		if (copy_to_user(uintf, &kintf, sizeof(kintf)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		uintf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	topo->num_interfaces = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	topo->reserved2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	/* Get pads and number of pads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	upad = media_get_uptr(topo->ptr_pads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	media_device_for_each_pad(pad, mdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		if (ret || !upad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		if (i > topo->num_pads) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			ret = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		memset(&kpad, 0, sizeof(kpad));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		/* Copy pad fields to userspace struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		kpad.id = pad->graph_obj.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		kpad.entity_id = pad->entity->graph_obj.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		kpad.flags = pad->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		kpad.index = pad->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		if (copy_to_user(upad, &kpad, sizeof(kpad)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		upad++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	topo->num_pads = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	topo->reserved3 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	/* Get links and number of links */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	ulink = media_get_uptr(topo->ptr_links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	media_device_for_each_link(link, mdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		if (link->is_backlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		if (ret || !ulink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		if (i > topo->num_links) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			ret = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		memset(&klink, 0, sizeof(klink));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		/* Copy link fields to userspace struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		klink.id = link->graph_obj.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		klink.source_id = link->gobj0->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		klink.sink_id = link->gobj1->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		klink.flags = link->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		if (copy_to_user(ulink, &klink, sizeof(klink)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		ulink++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	topo->num_links = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	topo->reserved4 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static long media_device_request_alloc(struct media_device *mdev, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) #ifdef CONFIG_MEDIA_CONTROLLER_REQUEST_API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	int *alloc_fd = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	if (!mdev->ops || !mdev->ops->req_validate || !mdev->ops->req_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	return media_request_alloc(mdev, alloc_fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static long copy_arg_from_user(void *karg, void __user *uarg, unsigned int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	if ((_IOC_DIR(cmd) & _IOC_WRITE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	    copy_from_user(karg, uarg, _IOC_SIZE(cmd)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static long copy_arg_to_user(void __user *uarg, void *karg, unsigned int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	if ((_IOC_DIR(cmd) & _IOC_READ) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	    copy_to_user(uarg, karg, _IOC_SIZE(cmd)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /* Do acquire the graph mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) #define MEDIA_IOC_FL_GRAPH_MUTEX	BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) #define MEDIA_IOC_ARG(__cmd, func, fl, from_user, to_user)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	[_IOC_NR(MEDIA_IOC_##__cmd)] = {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		.cmd = MEDIA_IOC_##__cmd,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		.fn = func,						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		.flags = fl,						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		.arg_from_user = from_user,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		.arg_to_user = to_user,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) #define MEDIA_IOC(__cmd, func, fl)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	MEDIA_IOC_ARG(__cmd, func, fl, copy_arg_from_user, copy_arg_to_user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) /* the table is indexed by _IOC_NR(cmd) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) struct media_ioctl_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	unsigned int cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	unsigned short flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	long (*fn)(struct media_device *dev, void *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	long (*arg_from_user)(void *karg, void __user *uarg, unsigned int cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	long (*arg_to_user)(void __user *uarg, void *karg, unsigned int cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static const struct media_ioctl_info ioctl_info[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	MEDIA_IOC(DEVICE_INFO, media_device_get_info, MEDIA_IOC_FL_GRAPH_MUTEX),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities, MEDIA_IOC_FL_GRAPH_MUTEX),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	MEDIA_IOC(ENUM_LINKS, media_device_enum_links, MEDIA_IOC_FL_GRAPH_MUTEX),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	MEDIA_IOC(SETUP_LINK, media_device_setup_link, MEDIA_IOC_FL_GRAPH_MUTEX),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	MEDIA_IOC(G_TOPOLOGY, media_device_get_topology, MEDIA_IOC_FL_GRAPH_MUTEX),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	MEDIA_IOC(REQUEST_ALLOC, media_device_request_alloc, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static long media_device_ioctl(struct file *filp, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 			       unsigned long __arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	struct media_devnode *devnode = media_devnode_data(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	struct media_device *dev = devnode->media_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	const struct media_ioctl_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	void __user *arg = (void __user *)__arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	char __karg[256], *karg = __karg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	long ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	if (_IOC_NR(cmd) >= ARRAY_SIZE(ioctl_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	    || ioctl_info[_IOC_NR(cmd)].cmd != cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	info = &ioctl_info[_IOC_NR(cmd)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	if (_IOC_SIZE(info->cmd) > sizeof(__karg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		karg = kmalloc(_IOC_SIZE(info->cmd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		if (!karg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	if (info->arg_from_user) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		ret = info->arg_from_user(karg, arg, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 			goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	if (info->flags & MEDIA_IOC_FL_GRAPH_MUTEX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		mutex_lock(&dev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	ret = info->fn(dev, karg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	if (info->flags & MEDIA_IOC_FL_GRAPH_MUTEX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		mutex_unlock(&dev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	if (!ret && info->arg_to_user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		ret = info->arg_to_user(arg, karg, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if (karg != __karg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		kfree(karg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) struct media_links_enum32 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	__u32 entity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	compat_uptr_t pads; /* struct media_pad_desc * */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	compat_uptr_t links; /* struct media_link_desc * */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	__u32 reserved[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static long media_device_enum_links32(struct media_device *mdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 				      struct media_links_enum32 __user *ulinks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	struct media_links_enum links;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	compat_uptr_t pads_ptr, links_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	memset(&links, 0, sizeof(links));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	if (get_user(links.entity, &ulinks->entity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	    || get_user(pads_ptr, &ulinks->pads)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	    || get_user(links_ptr, &ulinks->links))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	links.pads = compat_ptr(pads_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	links.links = compat_ptr(links_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	ret = media_device_enum_links(mdev, &links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	if (copy_to_user(ulinks->reserved, links.reserved,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 			 sizeof(ulinks->reserved)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) #define MEDIA_IOC_ENUM_LINKS32		_IOWR('|', 0x02, struct media_links_enum32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 				      unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	struct media_devnode *devnode = media_devnode_data(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	struct media_device *dev = devnode->media_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	long ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	case MEDIA_IOC_ENUM_LINKS32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		mutex_lock(&dev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		ret = media_device_enum_links32(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 				(struct media_links_enum32 __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		mutex_unlock(&dev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		return media_device_ioctl(filp, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) #endif /* CONFIG_COMPAT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) static const struct media_file_operations media_device_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	.open = media_device_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	.ioctl = media_device_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	.compat_ioctl = media_device_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) #endif /* CONFIG_COMPAT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	.release = media_device_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) /* -----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)  * sysfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static ssize_t show_model(struct device *cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 			  struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	struct media_devnode *devnode = to_media_devnode(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	struct media_device *mdev = devnode->media_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	return sprintf(buf, "%.*s\n", (int)sizeof(mdev->model), mdev->model);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) /* -----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)  * Registration/unregistration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) static void media_device_release(struct media_devnode *devnode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	dev_dbg(devnode->parent, "Media device released\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static void __media_device_unregister_entity(struct media_entity *entity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	struct media_device *mdev = entity->graph_obj.mdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	struct media_link *link, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	struct media_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	ida_free(&mdev->entity_internal_idx, entity->internal_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	/* Remove all interface links pointing to this entity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	list_for_each_entry(intf, &mdev->interfaces, graph_obj.list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 		list_for_each_entry_safe(link, tmp, &intf->links, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 			if (link->entity == entity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 				__media_remove_intf_link(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	/* Remove all data links that belong to this entity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	__media_entity_remove_links(entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	/* Remove all pads that belong to this entity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	for (i = 0; i < entity->num_pads; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 		media_gobj_destroy(&entity->pads[i].graph_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	/* Remove the entity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	media_gobj_destroy(&entity->graph_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	/* invoke entity_notify callbacks to handle entity removal?? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	entity->graph_obj.mdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)  * media_device_register_entity - Register an entity with a media device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)  * @mdev:	The media device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)  * @entity:	The entity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) int __must_check media_device_register_entity(struct media_device *mdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 					      struct media_entity *entity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	struct media_entity_notify *notify, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	if (entity->function == MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	    entity->function == MEDIA_ENT_F_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		dev_warn(mdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 			 "Entity type for entity %s was not initialized!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 			 entity->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	/* Warn if we apparently re-register an entity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	WARN_ON(entity->graph_obj.mdev != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	entity->graph_obj.mdev = mdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	INIT_LIST_HEAD(&entity->links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	entity->num_links = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	entity->num_backlinks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	ret = ida_alloc_min(&mdev->entity_internal_idx, 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	entity->internal_idx = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	mutex_lock(&mdev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	mdev->entity_internal_idx_max =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 		max(mdev->entity_internal_idx_max, entity->internal_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	/* Initialize media_gobj embedded at the entity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	media_gobj_create(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	/* Initialize objects at the pads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	for (i = 0; i < entity->num_pads; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 		media_gobj_create(mdev, MEDIA_GRAPH_PAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 			       &entity->pads[i].graph_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	/* invoke entity_notify callbacks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	list_for_each_entry_safe(notify, next, &mdev->entity_notify, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		notify->notify(entity, notify->notify_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	if (mdev->entity_internal_idx_max
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	    >= mdev->pm_count_walk.ent_enum.idx_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		struct media_graph new = { .top = 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 		 * Initialise the new graph walk before cleaning up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 		 * the old one in order not to spoil the graph walk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 		 * object of the media device if graph walk init fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		ret = media_graph_walk_init(&new, mdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 			__media_device_unregister_entity(entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 			mutex_unlock(&mdev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 		media_graph_walk_cleanup(&mdev->pm_count_walk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		mdev->pm_count_walk = new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	mutex_unlock(&mdev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) EXPORT_SYMBOL_GPL(media_device_register_entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) void media_device_unregister_entity(struct media_entity *entity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	struct media_device *mdev = entity->graph_obj.mdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	if (mdev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	mutex_lock(&mdev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	__media_device_unregister_entity(entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	mutex_unlock(&mdev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) EXPORT_SYMBOL_GPL(media_device_unregister_entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)  * media_device_init() - initialize a media device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)  * @mdev:	The media device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)  * The caller is responsible for initializing the media device before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)  * registration. The following fields must be set:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)  * - dev must point to the parent device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)  * - model must be filled with the device model name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) void media_device_init(struct media_device *mdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	INIT_LIST_HEAD(&mdev->entities);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	INIT_LIST_HEAD(&mdev->interfaces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	INIT_LIST_HEAD(&mdev->pads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	INIT_LIST_HEAD(&mdev->links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	INIT_LIST_HEAD(&mdev->entity_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	mutex_init(&mdev->req_queue_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	mutex_init(&mdev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	ida_init(&mdev->entity_internal_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	atomic_set(&mdev->request_id, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	dev_dbg(mdev->dev, "Media device initialized\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) EXPORT_SYMBOL_GPL(media_device_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) void media_device_cleanup(struct media_device *mdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	ida_destroy(&mdev->entity_internal_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	mdev->entity_internal_idx_max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	media_graph_walk_cleanup(&mdev->pm_count_walk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	mutex_destroy(&mdev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	mutex_destroy(&mdev->req_queue_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) EXPORT_SYMBOL_GPL(media_device_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) int __must_check __media_device_register(struct media_device *mdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 					 struct module *owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	struct media_devnode *devnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	devnode = kzalloc(sizeof(*devnode), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	if (!devnode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	/* Register the device node. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	mdev->devnode = devnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	devnode->fops = &media_device_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	devnode->parent = mdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	devnode->release = media_device_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	/* Set version 0 to indicate user-space that the graph is static */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	mdev->topology_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 	ret = media_devnode_register(mdev, devnode, owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 		/* devnode free is handled in media_devnode_*() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 		mdev->devnode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	ret = device_create_file(&devnode->dev, &dev_attr_model);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 		/* devnode free is handled in media_devnode_*() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 		mdev->devnode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 		media_devnode_unregister_prepare(devnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 		media_devnode_unregister(devnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 	dev_dbg(mdev->dev, "Media device registered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) EXPORT_SYMBOL_GPL(__media_device_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) int __must_check media_device_register_entity_notify(struct media_device *mdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 					struct media_entity_notify *nptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 	mutex_lock(&mdev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 	list_add_tail(&nptr->list, &mdev->entity_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 	mutex_unlock(&mdev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) EXPORT_SYMBOL_GPL(media_device_register_entity_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)  * Note: Should be called with mdev->lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) static void __media_device_unregister_entity_notify(struct media_device *mdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 					struct media_entity_notify *nptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	list_del(&nptr->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) void media_device_unregister_entity_notify(struct media_device *mdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 					struct media_entity_notify *nptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 	mutex_lock(&mdev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	__media_device_unregister_entity_notify(mdev, nptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 	mutex_unlock(&mdev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) EXPORT_SYMBOL_GPL(media_device_unregister_entity_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) void media_device_unregister(struct media_device *mdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 	struct media_entity *entity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 	struct media_entity *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 	struct media_interface *intf, *tmp_intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	struct media_entity_notify *notify, *nextp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 	if (mdev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	mutex_lock(&mdev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 	/* Check if mdev was ever registered at all */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 	if (!media_devnode_is_registered(mdev->devnode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 		mutex_unlock(&mdev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 	/* Clear the devnode register bit to avoid races with media dev open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	media_devnode_unregister_prepare(mdev->devnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 	/* Remove all entities from the media device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 		__media_device_unregister_entity(entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 	/* Remove all entity_notify callbacks from the media device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	list_for_each_entry_safe(notify, nextp, &mdev->entity_notify, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 		__media_device_unregister_entity_notify(mdev, notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 	/* Remove all interfaces from the media device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 	list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 				 graph_obj.list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 		 * Unlink the interface, but don't free it here; the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 		 * module which created it is responsible for freeing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 		 * it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 		__media_remove_intf_links(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 		media_gobj_destroy(&intf->graph_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	mutex_unlock(&mdev->graph_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 	dev_dbg(mdev->dev, "Media device unregistered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 	device_remove_file(&mdev->devnode->dev, &dev_attr_model);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 	media_devnode_unregister(mdev->devnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 	/* devnode free is handled in media_devnode_*() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 	mdev->devnode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) EXPORT_SYMBOL_GPL(media_device_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) #if IS_ENABLED(CONFIG_PCI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) void media_device_pci_init(struct media_device *mdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 			   struct pci_dev *pci_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 			   const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 	mdev->dev = &pci_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 	if (name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 		strscpy(mdev->model, name, sizeof(mdev->model));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 		strscpy(mdev->model, pci_name(pci_dev), sizeof(mdev->model));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 	sprintf(mdev->bus_info, "PCI:%s", pci_name(pci_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 	mdev->hw_revision = (pci_dev->subsystem_vendor << 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 			    | pci_dev->subsystem_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 	media_device_init(mdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) EXPORT_SYMBOL_GPL(media_device_pci_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) #if IS_ENABLED(CONFIG_USB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) void __media_device_usb_init(struct media_device *mdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 			     struct usb_device *udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 			     const char *board_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 			     const char *driver_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 	mdev->dev = &udev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 	if (driver_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) 		strscpy(mdev->driver_name, driver_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 			sizeof(mdev->driver_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) 	if (board_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) 		strscpy(mdev->model, board_name, sizeof(mdev->model));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) 	else if (udev->product)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) 		strscpy(mdev->model, udev->product, sizeof(mdev->model));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) 		strscpy(mdev->model, "unknown model", sizeof(mdev->model));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) 	if (udev->serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) 		strscpy(mdev->serial, udev->serial, sizeof(mdev->serial));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) 	usb_make_path(udev, mdev->bus_info, sizeof(mdev->bus_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) 	mdev->hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) 	media_device_init(mdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) EXPORT_SYMBOL_GPL(__media_device_usb_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) #endif /* CONFIG_MEDIA_CONTROLLER */