Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Media device |
| 3 | * |
| 4 | * Copyright (C) 2010 Nokia Corporation |
| 5 | * |
| 6 | * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com> |
| 7 | * Sakari Ailus <sakari.ailus@iki.fi> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
Sakari Ailus | b0a1f2a | 2013-01-22 12:27:56 -0300 | [diff] [blame] | 23 | #include <linux/compat.h> |
| 24 | #include <linux/export.h> |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 25 | #include <linux/ioctl.h> |
Laurent Pinchart | 140d881 | 2010-08-18 11:41:22 -0300 | [diff] [blame] | 26 | #include <linux/media.h> |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 27 | #include <linux/slab.h> |
Mauro Carvalho Chehab | 497e80c | 2015-12-11 07:23:09 -0200 | [diff] [blame] | 28 | #include <linux/types.h> |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 29 | |
| 30 | #include <media/media-device.h> |
| 31 | #include <media/media-devnode.h> |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 32 | #include <media/media-entity.h> |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 33 | |
Shuah Khan | e576d60 | 2015-06-05 17:11:54 -0300 | [diff] [blame] | 34 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 35 | |
Laurent Pinchart | 140d881 | 2010-08-18 11:41:22 -0300 | [diff] [blame] | 36 | /* ----------------------------------------------------------------------------- |
| 37 | * Userspace API |
| 38 | */ |
| 39 | |
| 40 | static int media_device_open(struct file *filp) |
| 41 | { |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static int media_device_close(struct file *filp) |
| 46 | { |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static int media_device_get_info(struct media_device *dev, |
| 51 | struct media_device_info __user *__info) |
| 52 | { |
| 53 | struct media_device_info info; |
| 54 | |
| 55 | memset(&info, 0, sizeof(info)); |
| 56 | |
| 57 | strlcpy(info.driver, dev->dev->driver->name, sizeof(info.driver)); |
| 58 | strlcpy(info.model, dev->model, sizeof(info.model)); |
| 59 | strlcpy(info.serial, dev->serial, sizeof(info.serial)); |
| 60 | strlcpy(info.bus_info, dev->bus_info, sizeof(info.bus_info)); |
| 61 | |
| 62 | info.media_version = MEDIA_API_VERSION; |
| 63 | info.hw_revision = dev->hw_revision; |
| 64 | info.driver_version = dev->driver_version; |
| 65 | |
Nicolas THERY | b17d394 | 2012-08-07 05:24:59 -0300 | [diff] [blame] | 66 | if (copy_to_user(__info, &info, sizeof(*__info))) |
| 67 | return -EFAULT; |
| 68 | return 0; |
Laurent Pinchart | 140d881 | 2010-08-18 11:41:22 -0300 | [diff] [blame] | 69 | } |
| 70 | |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 71 | static struct media_entity *find_entity(struct media_device *mdev, u32 id) |
| 72 | { |
| 73 | struct media_entity *entity; |
| 74 | int next = id & MEDIA_ENT_ID_FLAG_NEXT; |
| 75 | |
| 76 | id &= ~MEDIA_ENT_ID_FLAG_NEXT; |
| 77 | |
| 78 | spin_lock(&mdev->lock); |
| 79 | |
| 80 | media_device_for_each_entity(entity, mdev) { |
Mauro Carvalho Chehab | fa76239 | 2015-08-14 10:42:05 -0300 | [diff] [blame] | 81 | if (((media_entity_id(entity) == id) && !next) || |
| 82 | ((media_entity_id(entity) > id) && next)) { |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 83 | spin_unlock(&mdev->lock); |
| 84 | return entity; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | spin_unlock(&mdev->lock); |
| 89 | |
| 90 | return NULL; |
| 91 | } |
| 92 | |
| 93 | static long media_device_enum_entities(struct media_device *mdev, |
| 94 | struct media_entity_desc __user *uent) |
| 95 | { |
| 96 | struct media_entity *ent; |
| 97 | struct media_entity_desc u_ent; |
| 98 | |
Salva Peiró | e6a6234 | 2014-04-30 19:48:02 +0200 | [diff] [blame] | 99 | memset(&u_ent, 0, sizeof(u_ent)); |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 100 | if (copy_from_user(&u_ent.id, &uent->id, sizeof(u_ent.id))) |
| 101 | return -EFAULT; |
| 102 | |
| 103 | ent = find_entity(mdev, u_ent.id); |
| 104 | |
| 105 | if (ent == NULL) |
| 106 | return -EINVAL; |
| 107 | |
Mauro Carvalho Chehab | fa76239 | 2015-08-14 10:42:05 -0300 | [diff] [blame] | 108 | u_ent.id = media_entity_id(ent); |
Laurent Pinchart | de8eae3 | 2014-07-17 08:52:08 -0300 | [diff] [blame] | 109 | if (ent->name) |
| 110 | strlcpy(u_ent.name, ent->name, sizeof(u_ent.name)); |
Mauro Carvalho Chehab | 0e576b7 | 2015-09-06 09:33:39 -0300 | [diff] [blame] | 111 | u_ent.type = ent->function; |
Mauro Carvalho Chehab | 8ed8c88 | 2015-12-11 08:02:19 -0200 | [diff] [blame] | 112 | u_ent.revision = 0; /* Unused */ |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 113 | u_ent.flags = ent->flags; |
Mauro Carvalho Chehab | 8ed8c88 | 2015-12-11 08:02:19 -0200 | [diff] [blame] | 114 | u_ent.group_id = 0; /* Unused */ |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 115 | u_ent.pads = ent->num_pads; |
| 116 | u_ent.links = ent->num_links - ent->num_backlinks; |
Clemens Ladisch | fa5034c | 2011-11-05 18:42:01 -0300 | [diff] [blame] | 117 | memcpy(&u_ent.raw, &ent->info, sizeof(ent->info)); |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 118 | if (copy_to_user(uent, &u_ent, sizeof(u_ent))) |
| 119 | return -EFAULT; |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static void media_device_kpad_to_upad(const struct media_pad *kpad, |
| 124 | struct media_pad_desc *upad) |
| 125 | { |
Mauro Carvalho Chehab | fa76239 | 2015-08-14 10:42:05 -0300 | [diff] [blame] | 126 | upad->entity = media_entity_id(kpad->entity); |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 127 | upad->index = kpad->index; |
| 128 | upad->flags = kpad->flags; |
| 129 | } |
| 130 | |
Sakari Ailus | b0a1f2a | 2013-01-22 12:27:56 -0300 | [diff] [blame] | 131 | static long __media_device_enum_links(struct media_device *mdev, |
| 132 | struct media_links_enum *links) |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 133 | { |
| 134 | struct media_entity *entity; |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 135 | |
Sakari Ailus | b0a1f2a | 2013-01-22 12:27:56 -0300 | [diff] [blame] | 136 | entity = find_entity(mdev, links->entity); |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 137 | if (entity == NULL) |
| 138 | return -EINVAL; |
| 139 | |
Sakari Ailus | b0a1f2a | 2013-01-22 12:27:56 -0300 | [diff] [blame] | 140 | if (links->pads) { |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 141 | unsigned int p; |
| 142 | |
| 143 | for (p = 0; p < entity->num_pads; p++) { |
| 144 | struct media_pad_desc pad; |
Dan Carpenter | c88e739 | 2013-04-13 06:32:15 -0300 | [diff] [blame] | 145 | |
| 146 | memset(&pad, 0, sizeof(pad)); |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 147 | media_device_kpad_to_upad(&entity->pads[p], &pad); |
Sakari Ailus | b0a1f2a | 2013-01-22 12:27:56 -0300 | [diff] [blame] | 148 | if (copy_to_user(&links->pads[p], &pad, sizeof(pad))) |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 149 | return -EFAULT; |
| 150 | } |
| 151 | } |
| 152 | |
Sakari Ailus | b0a1f2a | 2013-01-22 12:27:56 -0300 | [diff] [blame] | 153 | if (links->links) { |
Mauro Carvalho Chehab | b83e250 | 2015-12-11 07:25:01 -0200 | [diff] [blame] | 154 | struct media_link *link; |
| 155 | struct media_link_desc __user *ulink_desc = links->links; |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 156 | |
Mauro Carvalho Chehab | b83e250 | 2015-12-11 07:25:01 -0200 | [diff] [blame] | 157 | list_for_each_entry(link, &entity->links, list) { |
| 158 | struct media_link_desc klink_desc; |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 159 | |
| 160 | /* Ignore backlinks. */ |
Mauro Carvalho Chehab | b83e250 | 2015-12-11 07:25:01 -0200 | [diff] [blame] | 161 | if (link->source->entity != entity) |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 162 | continue; |
Mauro Carvalho Chehab | b83e250 | 2015-12-11 07:25:01 -0200 | [diff] [blame] | 163 | memset(&klink_desc, 0, sizeof(klink_desc)); |
| 164 | media_device_kpad_to_upad(link->source, |
| 165 | &klink_desc.source); |
| 166 | media_device_kpad_to_upad(link->sink, |
| 167 | &klink_desc.sink); |
| 168 | klink_desc.flags = link->flags; |
| 169 | if (copy_to_user(ulink_desc, &klink_desc, |
| 170 | sizeof(*ulink_desc))) |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 171 | return -EFAULT; |
Mauro Carvalho Chehab | b83e250 | 2015-12-11 07:25:01 -0200 | [diff] [blame] | 172 | ulink_desc++; |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 173 | } |
| 174 | } |
Sakari Ailus | b0a1f2a | 2013-01-22 12:27:56 -0300 | [diff] [blame] | 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | static long media_device_enum_links(struct media_device *mdev, |
| 180 | struct media_links_enum __user *ulinks) |
| 181 | { |
| 182 | struct media_links_enum links; |
| 183 | int rval; |
| 184 | |
| 185 | if (copy_from_user(&links, ulinks, sizeof(links))) |
| 186 | return -EFAULT; |
| 187 | |
| 188 | rval = __media_device_enum_links(mdev, &links); |
| 189 | if (rval < 0) |
| 190 | return rval; |
| 191 | |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 192 | if (copy_to_user(ulinks, &links, sizeof(*ulinks))) |
| 193 | return -EFAULT; |
Sakari Ailus | b0a1f2a | 2013-01-22 12:27:56 -0300 | [diff] [blame] | 194 | |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 195 | return 0; |
| 196 | } |
| 197 | |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 198 | static long media_device_setup_link(struct media_device *mdev, |
| 199 | struct media_link_desc __user *_ulink) |
| 200 | { |
| 201 | struct media_link *link = NULL; |
| 202 | struct media_link_desc ulink; |
| 203 | struct media_entity *source; |
| 204 | struct media_entity *sink; |
| 205 | int ret; |
| 206 | |
| 207 | if (copy_from_user(&ulink, _ulink, sizeof(ulink))) |
| 208 | return -EFAULT; |
| 209 | |
| 210 | /* Find the source and sink entities and link. |
| 211 | */ |
| 212 | source = find_entity(mdev, ulink.source.entity); |
| 213 | sink = find_entity(mdev, ulink.sink.entity); |
| 214 | |
| 215 | if (source == NULL || sink == NULL) |
| 216 | return -EINVAL; |
| 217 | |
| 218 | if (ulink.source.index >= source->num_pads || |
| 219 | ulink.sink.index >= sink->num_pads) |
| 220 | return -EINVAL; |
| 221 | |
| 222 | link = media_entity_find_link(&source->pads[ulink.source.index], |
| 223 | &sink->pads[ulink.sink.index]); |
| 224 | if (link == NULL) |
| 225 | return -EINVAL; |
| 226 | |
| 227 | /* Setup the link on both entities. */ |
| 228 | ret = __media_entity_setup_link(link, ulink.flags); |
| 229 | |
| 230 | if (copy_to_user(_ulink, &ulink, sizeof(ulink))) |
| 231 | return -EFAULT; |
| 232 | |
| 233 | return ret; |
| 234 | } |
| 235 | |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 236 | static long __media_device_get_topology(struct media_device *mdev, |
| 237 | struct media_v2_topology *topo) |
| 238 | { |
| 239 | struct media_entity *entity; |
| 240 | struct media_interface *intf; |
| 241 | struct media_pad *pad; |
| 242 | struct media_link *link; |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 243 | struct media_v2_entity kentity, *uentity; |
| 244 | struct media_v2_interface kintf, *uintf; |
| 245 | struct media_v2_pad kpad, *upad; |
| 246 | struct media_v2_link klink, *ulink; |
Mauro Carvalho Chehab | 9033b1a | 2015-09-09 08:23:51 -0300 | [diff] [blame] | 247 | unsigned int i; |
| 248 | int ret = 0; |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 249 | |
| 250 | topo->topology_version = mdev->topology_version; |
| 251 | |
| 252 | /* Get entities and number of entities */ |
| 253 | i = 0; |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 254 | uentity = media_get_uptr(topo->ptr_entities); |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 255 | media_device_for_each_entity(entity, mdev) { |
| 256 | i++; |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 257 | if (ret || !uentity) |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 258 | continue; |
| 259 | |
| 260 | if (i > topo->num_entities) { |
| 261 | ret = -ENOSPC; |
| 262 | continue; |
| 263 | } |
| 264 | |
| 265 | /* Copy fields to userspace struct if not error */ |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 266 | memset(&kentity, 0, sizeof(kentity)); |
| 267 | kentity.id = entity->graph_obj.id; |
| 268 | kentity.function = entity->function; |
| 269 | strncpy(kentity.name, entity->name, |
| 270 | sizeof(kentity.name)); |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 271 | |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 272 | if (copy_to_user(uentity, &kentity, sizeof(kentity))) |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 273 | ret = -EFAULT; |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 274 | uentity++; |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 275 | } |
| 276 | topo->num_entities = i; |
| 277 | |
| 278 | /* Get interfaces and number of interfaces */ |
| 279 | i = 0; |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 280 | uintf = media_get_uptr(topo->ptr_interfaces); |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 281 | media_device_for_each_intf(intf, mdev) { |
| 282 | i++; |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 283 | if (ret || !uintf) |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 284 | continue; |
| 285 | |
| 286 | if (i > topo->num_interfaces) { |
| 287 | ret = -ENOSPC; |
| 288 | continue; |
| 289 | } |
| 290 | |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 291 | memset(&kintf, 0, sizeof(kintf)); |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 292 | |
| 293 | /* Copy intf fields to userspace struct */ |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 294 | kintf.id = intf->graph_obj.id; |
| 295 | kintf.intf_type = intf->type; |
| 296 | kintf.flags = intf->flags; |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 297 | |
| 298 | if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) { |
| 299 | struct media_intf_devnode *devnode; |
| 300 | |
| 301 | devnode = intf_to_devnode(intf); |
| 302 | |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 303 | kintf.devnode.major = devnode->major; |
| 304 | kintf.devnode.minor = devnode->minor; |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 305 | } |
| 306 | |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 307 | if (copy_to_user(uintf, &kintf, sizeof(kintf))) |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 308 | ret = -EFAULT; |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 309 | uintf++; |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 310 | } |
| 311 | topo->num_interfaces = i; |
| 312 | |
| 313 | /* Get pads and number of pads */ |
| 314 | i = 0; |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 315 | upad = media_get_uptr(topo->ptr_pads); |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 316 | media_device_for_each_pad(pad, mdev) { |
| 317 | i++; |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 318 | if (ret || !upad) |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 319 | continue; |
| 320 | |
| 321 | if (i > topo->num_pads) { |
| 322 | ret = -ENOSPC; |
| 323 | continue; |
| 324 | } |
| 325 | |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 326 | memset(&kpad, 0, sizeof(kpad)); |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 327 | |
| 328 | /* Copy pad fields to userspace struct */ |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 329 | kpad.id = pad->graph_obj.id; |
| 330 | kpad.entity_id = pad->entity->graph_obj.id; |
| 331 | kpad.flags = pad->flags; |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 332 | |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 333 | if (copy_to_user(upad, &kpad, sizeof(kpad))) |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 334 | ret = -EFAULT; |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 335 | upad++; |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 336 | } |
| 337 | topo->num_pads = i; |
| 338 | |
| 339 | /* Get links and number of links */ |
| 340 | i = 0; |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 341 | ulink = media_get_uptr(topo->ptr_links); |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 342 | media_device_for_each_link(link, mdev) { |
Mauro Carvalho Chehab | 39d1ebc6 | 2015-08-30 09:53:57 -0300 | [diff] [blame] | 343 | if (link->is_backlink) |
| 344 | continue; |
| 345 | |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 346 | i++; |
| 347 | |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 348 | if (ret || !ulink) |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 349 | continue; |
| 350 | |
| 351 | if (i > topo->num_links) { |
| 352 | ret = -ENOSPC; |
| 353 | continue; |
| 354 | } |
| 355 | |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 356 | memset(&klink, 0, sizeof(klink)); |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 357 | |
| 358 | /* Copy link fields to userspace struct */ |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 359 | klink.id = link->graph_obj.id; |
| 360 | klink.source_id = link->gobj0->id; |
| 361 | klink.sink_id = link->gobj1->id; |
| 362 | klink.flags = link->flags; |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 363 | |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 364 | if (copy_to_user(ulink, &klink, sizeof(klink))) |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 365 | ret = -EFAULT; |
Mauro Carvalho Chehab | b3b7a9f | 2015-12-11 16:07:57 -0200 | [diff] [blame] | 366 | ulink++; |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 367 | } |
| 368 | topo->num_links = i; |
| 369 | |
| 370 | return ret; |
| 371 | } |
| 372 | |
| 373 | static long media_device_get_topology(struct media_device *mdev, |
| 374 | struct media_v2_topology __user *utopo) |
| 375 | { |
| 376 | struct media_v2_topology ktopo; |
| 377 | int ret; |
| 378 | |
| 379 | ret = copy_from_user(&ktopo, utopo, sizeof(ktopo)); |
| 380 | |
| 381 | if (ret < 0) |
| 382 | return ret; |
| 383 | |
| 384 | ret = __media_device_get_topology(mdev, &ktopo); |
| 385 | if (ret < 0) |
| 386 | return ret; |
| 387 | |
| 388 | ret = copy_to_user(utopo, &ktopo, sizeof(*utopo)); |
| 389 | |
| 390 | return ret; |
| 391 | } |
| 392 | |
Laurent Pinchart | 140d881 | 2010-08-18 11:41:22 -0300 | [diff] [blame] | 393 | static long media_device_ioctl(struct file *filp, unsigned int cmd, |
| 394 | unsigned long arg) |
| 395 | { |
| 396 | struct media_devnode *devnode = media_devnode_data(filp); |
| 397 | struct media_device *dev = to_media_device(devnode); |
| 398 | long ret; |
| 399 | |
| 400 | switch (cmd) { |
| 401 | case MEDIA_IOC_DEVICE_INFO: |
| 402 | ret = media_device_get_info(dev, |
| 403 | (struct media_device_info __user *)arg); |
| 404 | break; |
| 405 | |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 406 | case MEDIA_IOC_ENUM_ENTITIES: |
| 407 | ret = media_device_enum_entities(dev, |
| 408 | (struct media_entity_desc __user *)arg); |
| 409 | break; |
| 410 | |
| 411 | case MEDIA_IOC_ENUM_LINKS: |
| 412 | mutex_lock(&dev->graph_mutex); |
| 413 | ret = media_device_enum_links(dev, |
| 414 | (struct media_links_enum __user *)arg); |
| 415 | mutex_unlock(&dev->graph_mutex); |
| 416 | break; |
| 417 | |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 418 | case MEDIA_IOC_SETUP_LINK: |
| 419 | mutex_lock(&dev->graph_mutex); |
| 420 | ret = media_device_setup_link(dev, |
| 421 | (struct media_link_desc __user *)arg); |
| 422 | mutex_unlock(&dev->graph_mutex); |
| 423 | break; |
| 424 | |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 425 | case MEDIA_IOC_G_TOPOLOGY: |
| 426 | mutex_lock(&dev->graph_mutex); |
| 427 | ret = media_device_get_topology(dev, |
| 428 | (struct media_v2_topology __user *)arg); |
| 429 | mutex_unlock(&dev->graph_mutex); |
| 430 | break; |
| 431 | |
Laurent Pinchart | 140d881 | 2010-08-18 11:41:22 -0300 | [diff] [blame] | 432 | default: |
| 433 | ret = -ENOIOCTLCMD; |
| 434 | } |
| 435 | |
| 436 | return ret; |
| 437 | } |
| 438 | |
Sakari Ailus | b0a1f2a | 2013-01-22 12:27:56 -0300 | [diff] [blame] | 439 | #ifdef CONFIG_COMPAT |
| 440 | |
| 441 | struct media_links_enum32 { |
| 442 | __u32 entity; |
| 443 | compat_uptr_t pads; /* struct media_pad_desc * */ |
| 444 | compat_uptr_t links; /* struct media_link_desc * */ |
| 445 | __u32 reserved[4]; |
| 446 | }; |
| 447 | |
| 448 | static long media_device_enum_links32(struct media_device *mdev, |
| 449 | struct media_links_enum32 __user *ulinks) |
| 450 | { |
| 451 | struct media_links_enum links; |
| 452 | compat_uptr_t pads_ptr, links_ptr; |
| 453 | |
| 454 | memset(&links, 0, sizeof(links)); |
| 455 | |
| 456 | if (get_user(links.entity, &ulinks->entity) |
| 457 | || get_user(pads_ptr, &ulinks->pads) |
| 458 | || get_user(links_ptr, &ulinks->links)) |
| 459 | return -EFAULT; |
| 460 | |
| 461 | links.pads = compat_ptr(pads_ptr); |
| 462 | links.links = compat_ptr(links_ptr); |
| 463 | |
| 464 | return __media_device_enum_links(mdev, &links); |
| 465 | } |
| 466 | |
| 467 | #define MEDIA_IOC_ENUM_LINKS32 _IOWR('|', 0x02, struct media_links_enum32) |
| 468 | |
| 469 | static long media_device_compat_ioctl(struct file *filp, unsigned int cmd, |
| 470 | unsigned long arg) |
| 471 | { |
| 472 | struct media_devnode *devnode = media_devnode_data(filp); |
| 473 | struct media_device *dev = to_media_device(devnode); |
| 474 | long ret; |
| 475 | |
| 476 | switch (cmd) { |
| 477 | case MEDIA_IOC_DEVICE_INFO: |
| 478 | case MEDIA_IOC_ENUM_ENTITIES: |
| 479 | case MEDIA_IOC_SETUP_LINK: |
Mauro Carvalho Chehab | 8309f47 | 2015-08-23 10:36:41 -0300 | [diff] [blame] | 480 | case MEDIA_IOC_G_TOPOLOGY: |
Sakari Ailus | b0a1f2a | 2013-01-22 12:27:56 -0300 | [diff] [blame] | 481 | return media_device_ioctl(filp, cmd, arg); |
| 482 | |
| 483 | case MEDIA_IOC_ENUM_LINKS32: |
| 484 | mutex_lock(&dev->graph_mutex); |
| 485 | ret = media_device_enum_links32(dev, |
| 486 | (struct media_links_enum32 __user *)arg); |
| 487 | mutex_unlock(&dev->graph_mutex); |
| 488 | break; |
| 489 | |
| 490 | default: |
| 491 | ret = -ENOIOCTLCMD; |
| 492 | } |
| 493 | |
| 494 | return ret; |
| 495 | } |
| 496 | #endif /* CONFIG_COMPAT */ |
| 497 | |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 498 | static const struct media_file_operations media_device_fops = { |
| 499 | .owner = THIS_MODULE, |
Laurent Pinchart | 140d881 | 2010-08-18 11:41:22 -0300 | [diff] [blame] | 500 | .open = media_device_open, |
| 501 | .ioctl = media_device_ioctl, |
Sakari Ailus | b0a1f2a | 2013-01-22 12:27:56 -0300 | [diff] [blame] | 502 | #ifdef CONFIG_COMPAT |
| 503 | .compat_ioctl = media_device_compat_ioctl, |
| 504 | #endif /* CONFIG_COMPAT */ |
Laurent Pinchart | 140d881 | 2010-08-18 11:41:22 -0300 | [diff] [blame] | 505 | .release = media_device_close, |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 506 | }; |
| 507 | |
| 508 | /* ----------------------------------------------------------------------------- |
| 509 | * sysfs |
| 510 | */ |
| 511 | |
| 512 | static ssize_t show_model(struct device *cd, |
| 513 | struct device_attribute *attr, char *buf) |
| 514 | { |
| 515 | struct media_device *mdev = to_media_device(to_media_devnode(cd)); |
| 516 | |
| 517 | return sprintf(buf, "%.*s\n", (int)sizeof(mdev->model), mdev->model); |
| 518 | } |
| 519 | |
| 520 | static DEVICE_ATTR(model, S_IRUGO, show_model, NULL); |
| 521 | |
| 522 | /* ----------------------------------------------------------------------------- |
| 523 | * Registration/unregistration |
| 524 | */ |
| 525 | |
| 526 | static void media_device_release(struct media_devnode *mdev) |
| 527 | { |
Mauro Carvalho Chehab | 8f5a318 | 2015-08-13 15:22:24 -0300 | [diff] [blame] | 528 | dev_dbg(mdev->parent, "Media device released\n"); |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /** |
Mauro Carvalho Chehab | b2ed8af | 2015-12-15 08:26:52 -0200 | [diff] [blame] | 532 | * media_device_register_entity - Register an entity with a media device |
| 533 | * @mdev: The media device |
| 534 | * @entity: The entity |
| 535 | */ |
| 536 | int __must_check media_device_register_entity(struct media_device *mdev, |
| 537 | struct media_entity *entity) |
| 538 | { |
| 539 | unsigned int i; |
| 540 | |
| 541 | if (entity->function == MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN || |
| 542 | entity->function == MEDIA_ENT_F_UNKNOWN) |
| 543 | dev_warn(mdev->dev, |
| 544 | "Entity type for entity %s was not initialized!\n", |
| 545 | entity->name); |
| 546 | |
| 547 | /* Warn if we apparently re-register an entity */ |
| 548 | WARN_ON(entity->graph_obj.mdev != NULL); |
| 549 | entity->graph_obj.mdev = mdev; |
| 550 | INIT_LIST_HEAD(&entity->links); |
| 551 | entity->num_links = 0; |
| 552 | entity->num_backlinks = 0; |
| 553 | |
| 554 | spin_lock(&mdev->lock); |
| 555 | /* Initialize media_gobj embedded at the entity */ |
| 556 | media_gobj_create(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj); |
| 557 | |
| 558 | /* Initialize objects at the pads */ |
| 559 | for (i = 0; i < entity->num_pads; i++) |
| 560 | media_gobj_create(mdev, MEDIA_GRAPH_PAD, |
| 561 | &entity->pads[i].graph_obj); |
| 562 | |
| 563 | spin_unlock(&mdev->lock); |
| 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | EXPORT_SYMBOL_GPL(media_device_register_entity); |
| 568 | |
| 569 | /** |
| 570 | * media_device_unregister_entity - Unregister an entity |
| 571 | * @entity: The entity |
| 572 | * |
| 573 | * If the entity has never been registered this function will return |
| 574 | * immediately. |
| 575 | */ |
Mauro Carvalho Chehab | 821ed36 | 2015-12-15 08:36:51 -0200 | [diff] [blame] | 576 | static void __media_device_unregister_entity(struct media_entity *entity) |
Mauro Carvalho Chehab | b2ed8af | 2015-12-15 08:26:52 -0200 | [diff] [blame] | 577 | { |
| 578 | struct media_device *mdev = entity->graph_obj.mdev; |
| 579 | struct media_link *link, *tmp; |
| 580 | struct media_interface *intf; |
| 581 | unsigned int i; |
| 582 | |
Mauro Carvalho Chehab | b2ed8af | 2015-12-15 08:26:52 -0200 | [diff] [blame] | 583 | /* Remove all interface links pointing to this entity */ |
| 584 | list_for_each_entry(intf, &mdev->interfaces, graph_obj.list) { |
| 585 | list_for_each_entry_safe(link, tmp, &intf->links, list) { |
| 586 | if (link->entity == entity) |
| 587 | __media_remove_intf_link(link); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | /* Remove all data links that belong to this entity */ |
| 592 | __media_entity_remove_links(entity); |
| 593 | |
| 594 | /* Remove all pads that belong to this entity */ |
| 595 | for (i = 0; i < entity->num_pads; i++) |
| 596 | media_gobj_destroy(&entity->pads[i].graph_obj); |
| 597 | |
| 598 | /* Remove the entity */ |
| 599 | media_gobj_destroy(&entity->graph_obj); |
| 600 | |
Mauro Carvalho Chehab | b2ed8af | 2015-12-15 08:26:52 -0200 | [diff] [blame] | 601 | entity->graph_obj.mdev = NULL; |
| 602 | } |
Mauro Carvalho Chehab | 821ed36 | 2015-12-15 08:36:51 -0200 | [diff] [blame] | 603 | |
| 604 | void media_device_unregister_entity(struct media_entity *entity) |
| 605 | { |
| 606 | struct media_device *mdev = entity->graph_obj.mdev; |
| 607 | |
| 608 | if (mdev == NULL) |
| 609 | return; |
| 610 | |
| 611 | spin_lock(&mdev->lock); |
| 612 | __media_device_unregister_entity(entity); |
| 613 | spin_unlock(&mdev->lock); |
| 614 | } |
Mauro Carvalho Chehab | b2ed8af | 2015-12-15 08:26:52 -0200 | [diff] [blame] | 615 | EXPORT_SYMBOL_GPL(media_device_unregister_entity); |
| 616 | |
Mauro Carvalho Chehab | 821ed36 | 2015-12-15 08:36:51 -0200 | [diff] [blame] | 617 | |
Mauro Carvalho Chehab | b2ed8af | 2015-12-15 08:26:52 -0200 | [diff] [blame] | 618 | /** |
Javier Martinez Canillas | 9832e15 | 2015-12-11 20:57:08 -0200 | [diff] [blame] | 619 | * media_device_init() - initialize a media device |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 620 | * @mdev: The media device |
| 621 | * |
| 622 | * The caller is responsible for initializing the media device before |
| 623 | * registration. The following fields must be set: |
| 624 | * |
| 625 | * - dev must point to the parent device |
| 626 | * - model must be filled with the device model name |
| 627 | */ |
Javier Martinez Canillas | 9832e15 | 2015-12-11 20:57:08 -0200 | [diff] [blame] | 628 | void media_device_init(struct media_device *mdev) |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 629 | { |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 630 | INIT_LIST_HEAD(&mdev->entities); |
Mauro Carvalho Chehab | 57cf79b | 2015-08-21 09:23:22 -0300 | [diff] [blame] | 631 | INIT_LIST_HEAD(&mdev->interfaces); |
Mauro Carvalho Chehab | 9155d85 | 2015-08-23 08:00:33 -0300 | [diff] [blame] | 632 | INIT_LIST_HEAD(&mdev->pads); |
| 633 | INIT_LIST_HEAD(&mdev->links); |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 634 | spin_lock_init(&mdev->lock); |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 635 | mutex_init(&mdev->graph_mutex); |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 636 | |
Javier Martinez Canillas | 9832e15 | 2015-12-11 20:57:08 -0200 | [diff] [blame] | 637 | dev_dbg(mdev->dev, "Media device initialized\n"); |
| 638 | } |
| 639 | EXPORT_SYMBOL_GPL(media_device_init); |
| 640 | |
| 641 | /** |
| 642 | * media_device_cleanup() - Cleanup a media device |
| 643 | * @mdev: The media device |
| 644 | * |
| 645 | */ |
| 646 | void media_device_cleanup(struct media_device *mdev) |
| 647 | { |
| 648 | mutex_destroy(&mdev->graph_mutex); |
| 649 | } |
| 650 | EXPORT_SYMBOL_GPL(media_device_cleanup); |
| 651 | |
| 652 | /** |
| 653 | * __media_device_register() - register a media device |
| 654 | * @mdev: The media device |
| 655 | * @owner: The module owner |
| 656 | * |
| 657 | * returns zero on success or a negative error code. |
| 658 | */ |
| 659 | int __must_check __media_device_register(struct media_device *mdev, |
| 660 | struct module *owner) |
| 661 | { |
| 662 | int ret; |
| 663 | |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 664 | /* Register the device node. */ |
| 665 | mdev->devnode.fops = &media_device_fops; |
| 666 | mdev->devnode.parent = mdev->dev; |
| 667 | mdev->devnode.release = media_device_release; |
Javier Martinez Canillas | 8a95079 | 2015-12-11 20:57:09 -0200 | [diff] [blame^] | 668 | |
| 669 | /* Set version 0 to indicate user-space that the graph is static */ |
| 670 | mdev->topology_version = 0; |
| 671 | |
Sakari Ailus | 85de721 | 2013-12-12 12:38:17 -0300 | [diff] [blame] | 672 | ret = media_devnode_register(&mdev->devnode, owner); |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 673 | if (ret < 0) |
| 674 | return ret; |
| 675 | |
| 676 | ret = device_create_file(&mdev->devnode.dev, &dev_attr_model); |
| 677 | if (ret < 0) { |
| 678 | media_devnode_unregister(&mdev->devnode); |
| 679 | return ret; |
| 680 | } |
| 681 | |
Mauro Carvalho Chehab | 8f5a318 | 2015-08-13 15:22:24 -0300 | [diff] [blame] | 682 | dev_dbg(mdev->dev, "Media device registered\n"); |
| 683 | |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 684 | return 0; |
| 685 | } |
Sakari Ailus | 85de721 | 2013-12-12 12:38:17 -0300 | [diff] [blame] | 686 | EXPORT_SYMBOL_GPL(__media_device_register); |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 687 | |
| 688 | /** |
| 689 | * media_device_unregister - unregister a media device |
| 690 | * @mdev: The media device |
| 691 | * |
Javier Martinez Canillas | 223d19c | 2015-12-11 20:57:07 -0200 | [diff] [blame] | 692 | * It is safe to call this function on an unregistered |
| 693 | * (but initialised) media device. |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 694 | */ |
| 695 | void media_device_unregister(struct media_device *mdev) |
| 696 | { |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 697 | struct media_entity *entity; |
| 698 | struct media_entity *next; |
Mauro Carvalho Chehab | d47109f | 2015-08-29 21:23:44 -0300 | [diff] [blame] | 699 | struct media_interface *intf, *tmp_intf; |
| 700 | |
Mauro Carvalho Chehab | 821ed36 | 2015-12-15 08:36:51 -0200 | [diff] [blame] | 701 | if (mdev == NULL) |
Javier Martinez Canillas | 223d19c | 2015-12-11 20:57:07 -0200 | [diff] [blame] | 702 | return; |
| 703 | |
Mauro Carvalho Chehab | 821ed36 | 2015-12-15 08:36:51 -0200 | [diff] [blame] | 704 | spin_lock(&mdev->lock); |
| 705 | |
| 706 | /* Check if mdev was ever registered at all */ |
| 707 | if (!media_devnode_is_registered(&mdev->devnode)) { |
| 708 | spin_unlock(&mdev->lock); |
| 709 | return; |
| 710 | } |
| 711 | |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 712 | /* Remove all entities from the media device */ |
| 713 | list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list) |
Mauro Carvalho Chehab | 821ed36 | 2015-12-15 08:36:51 -0200 | [diff] [blame] | 714 | __media_device_unregister_entity(entity); |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 715 | |
Mauro Carvalho Chehab | d47109f | 2015-08-29 21:23:44 -0300 | [diff] [blame] | 716 | /* Remove all interfaces from the media device */ |
Mauro Carvalho Chehab | d47109f | 2015-08-29 21:23:44 -0300 | [diff] [blame] | 717 | list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces, |
| 718 | graph_obj.list) { |
| 719 | __media_remove_intf_links(intf); |
Mauro Carvalho Chehab | c350ef8 | 2015-12-11 11:55:40 -0200 | [diff] [blame] | 720 | media_gobj_destroy(&intf->graph_obj); |
Mauro Carvalho Chehab | d47109f | 2015-08-29 21:23:44 -0300 | [diff] [blame] | 721 | kfree(intf); |
| 722 | } |
Mauro Carvalho Chehab | 821ed36 | 2015-12-15 08:36:51 -0200 | [diff] [blame] | 723 | |
Mauro Carvalho Chehab | d47109f | 2015-08-29 21:23:44 -0300 | [diff] [blame] | 724 | spin_unlock(&mdev->lock); |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 725 | |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 726 | device_remove_file(&mdev->devnode.dev, &dev_attr_model); |
| 727 | media_devnode_unregister(&mdev->devnode); |
Mauro Carvalho Chehab | 8f5a318 | 2015-08-13 15:22:24 -0300 | [diff] [blame] | 728 | |
| 729 | dev_dbg(mdev->dev, "Media device unregistered\n"); |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 730 | } |
| 731 | EXPORT_SYMBOL_GPL(media_device_unregister); |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 732 | |
Shuah Khan | d062f91 | 2015-06-03 12:12:53 -0300 | [diff] [blame] | 733 | static void media_device_release_devres(struct device *dev, void *res) |
| 734 | { |
| 735 | } |
| 736 | |
Shuah Khan | d062f91 | 2015-06-03 12:12:53 -0300 | [diff] [blame] | 737 | struct media_device *media_device_get_devres(struct device *dev) |
| 738 | { |
| 739 | struct media_device *mdev; |
| 740 | |
| 741 | mdev = devres_find(dev, media_device_release_devres, NULL, NULL); |
| 742 | if (mdev) |
| 743 | return mdev; |
| 744 | |
| 745 | mdev = devres_alloc(media_device_release_devres, |
| 746 | sizeof(struct media_device), GFP_KERNEL); |
| 747 | if (!mdev) |
| 748 | return NULL; |
| 749 | return devres_get(dev, mdev, NULL, NULL); |
| 750 | } |
| 751 | EXPORT_SYMBOL_GPL(media_device_get_devres); |
| 752 | |
Shuah Khan | d062f91 | 2015-06-03 12:12:53 -0300 | [diff] [blame] | 753 | struct media_device *media_device_find_devres(struct device *dev) |
| 754 | { |
| 755 | return devres_find(dev, media_device_release_devres, NULL, NULL); |
| 756 | } |
| 757 | EXPORT_SYMBOL_GPL(media_device_find_devres); |
Shuah Khan | e576d60 | 2015-06-05 17:11:54 -0300 | [diff] [blame] | 758 | |
| 759 | #endif /* CONFIG_MEDIA_CONTROLLER */ |