Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Media entity |
| 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 | |
Laurent Pinchart | 5c7b25b | 2013-06-07 12:45:11 -0300 | [diff] [blame] | 23 | #include <linux/bitmap.h> |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 24 | #include <linux/module.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <media/media-entity.h> |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 27 | #include <media/media-device.h> |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 28 | |
Mauro Carvalho Chehab | 39a956c | 2015-08-13 14:42:42 -0300 | [diff] [blame] | 29 | static inline const char *gobj_type(enum media_gobj_type type) |
| 30 | { |
| 31 | switch (type) { |
| 32 | case MEDIA_GRAPH_ENTITY: |
| 33 | return "entity"; |
| 34 | case MEDIA_GRAPH_PAD: |
| 35 | return "pad"; |
| 36 | case MEDIA_GRAPH_LINK: |
| 37 | return "link"; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 38 | case MEDIA_GRAPH_INTF_DEVNODE: |
| 39 | return "intf-devnode"; |
Mauro Carvalho Chehab | 39a956c | 2015-08-13 14:42:42 -0300 | [diff] [blame] | 40 | default: |
| 41 | return "unknown"; |
| 42 | } |
| 43 | } |
| 44 | |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 45 | static inline const char *intf_type(struct media_interface *intf) |
| 46 | { |
| 47 | switch (intf->type) { |
| 48 | case MEDIA_INTF_T_DVB_FE: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 49 | return "dvb-frontend"; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 50 | case MEDIA_INTF_T_DVB_DEMUX: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 51 | return "dvb-demux"; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 52 | case MEDIA_INTF_T_DVB_DVR: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 53 | return "dvb-dvr"; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 54 | case MEDIA_INTF_T_DVB_CA: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 55 | return "dvb-ca"; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 56 | case MEDIA_INTF_T_DVB_NET: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 57 | return "dvb-net"; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 58 | case MEDIA_INTF_T_V4L_VIDEO: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 59 | return "v4l-video"; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 60 | case MEDIA_INTF_T_V4L_VBI: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 61 | return "v4l-vbi"; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 62 | case MEDIA_INTF_T_V4L_RADIO: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 63 | return "v4l-radio"; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 64 | case MEDIA_INTF_T_V4L_SUBDEV: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 65 | return "v4l-subdev"; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 66 | case MEDIA_INTF_T_V4L_SWRADIO: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 67 | return "v4l-swradio"; |
Nick Dyer | b2fe22d | 2016-07-18 18:10:30 -0300 | [diff] [blame] | 68 | case MEDIA_INTF_T_V4L_TOUCH: |
| 69 | return "v4l-touch"; |
Shuah Khan | 5af557a | 2016-02-11 21:41:18 -0200 | [diff] [blame] | 70 | case MEDIA_INTF_T_ALSA_PCM_CAPTURE: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 71 | return "alsa-pcm-capture"; |
Shuah Khan | 5af557a | 2016-02-11 21:41:18 -0200 | [diff] [blame] | 72 | case MEDIA_INTF_T_ALSA_PCM_PLAYBACK: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 73 | return "alsa-pcm-playback"; |
Shuah Khan | 5af557a | 2016-02-11 21:41:18 -0200 | [diff] [blame] | 74 | case MEDIA_INTF_T_ALSA_CONTROL: |
| 75 | return "alsa-control"; |
| 76 | case MEDIA_INTF_T_ALSA_COMPRESS: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 77 | return "alsa-compress"; |
Shuah Khan | 5af557a | 2016-02-11 21:41:18 -0200 | [diff] [blame] | 78 | case MEDIA_INTF_T_ALSA_RAWMIDI: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 79 | return "alsa-rawmidi"; |
Shuah Khan | 5af557a | 2016-02-11 21:41:18 -0200 | [diff] [blame] | 80 | case MEDIA_INTF_T_ALSA_HWDEP: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 81 | return "alsa-hwdep"; |
Shuah Khan | 5af557a | 2016-02-11 21:41:18 -0200 | [diff] [blame] | 82 | case MEDIA_INTF_T_ALSA_SEQUENCER: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 83 | return "alsa-sequencer"; |
Shuah Khan | 5af557a | 2016-02-11 21:41:18 -0200 | [diff] [blame] | 84 | case MEDIA_INTF_T_ALSA_TIMER: |
Shuah Khan | 66c1db1 | 2016-03-04 18:14:05 -0300 | [diff] [blame] | 85 | return "alsa-timer"; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 86 | default: |
| 87 | return "unknown-intf"; |
| 88 | } |
| 89 | }; |
| 90 | |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 91 | __must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum, |
| 92 | int idx_max) |
| 93 | { |
Sakari Ailus | f7b5dff | 2016-01-27 12:47:54 -0200 | [diff] [blame] | 94 | idx_max = ALIGN(idx_max, BITS_PER_LONG); |
| 95 | ent_enum->bmap = kcalloc(idx_max / BITS_PER_LONG, sizeof(long), |
| 96 | GFP_KERNEL); |
Sakari Ailus | 030e89e | 2015-12-16 11:32:36 -0200 | [diff] [blame] | 97 | if (!ent_enum->bmap) |
| 98 | return -ENOMEM; |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 99 | |
| 100 | bitmap_zero(ent_enum->bmap, idx_max); |
| 101 | ent_enum->idx_max = idx_max; |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | EXPORT_SYMBOL_GPL(__media_entity_enum_init); |
| 106 | |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 107 | void media_entity_enum_cleanup(struct media_entity_enum *ent_enum) |
| 108 | { |
Sakari Ailus | 030e89e | 2015-12-16 11:32:36 -0200 | [diff] [blame] | 109 | kfree(ent_enum->bmap); |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 110 | } |
| 111 | EXPORT_SYMBOL_GPL(media_entity_enum_cleanup); |
| 112 | |
| 113 | /** |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 114 | * dev_dbg_obj - Prints in debug mode a change on some object |
| 115 | * |
| 116 | * @event_name: Name of the event to report. Could be __func__ |
| 117 | * @gobj: Pointer to the object |
| 118 | * |
| 119 | * Enabled only if DEBUG or CONFIG_DYNAMIC_DEBUG. Otherwise, it |
| 120 | * won't produce any code. |
| 121 | */ |
Mauro Carvalho Chehab | 39a956c | 2015-08-13 14:42:42 -0300 | [diff] [blame] | 122 | static void dev_dbg_obj(const char *event_name, struct media_gobj *gobj) |
| 123 | { |
| 124 | #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG) |
| 125 | switch (media_type(gobj)) { |
| 126 | case MEDIA_GRAPH_ENTITY: |
| 127 | dev_dbg(gobj->mdev->dev, |
Mauro Carvalho Chehab | 05b3b77 | 2015-12-16 14:28:01 -0200 | [diff] [blame] | 128 | "%s id %u: entity '%s'\n", |
| 129 | event_name, media_id(gobj), |
Mauro Carvalho Chehab | 39a956c | 2015-08-13 14:42:42 -0300 | [diff] [blame] | 130 | gobj_to_entity(gobj)->name); |
| 131 | break; |
| 132 | case MEDIA_GRAPH_LINK: |
| 133 | { |
| 134 | struct media_link *link = gobj_to_link(gobj); |
| 135 | |
| 136 | dev_dbg(gobj->mdev->dev, |
Mauro Carvalho Chehab | 05b3b77 | 2015-12-16 14:28:01 -0200 | [diff] [blame] | 137 | "%s id %u: %s link id %u ==> id %u\n", |
| 138 | event_name, media_id(gobj), |
| 139 | media_type(link->gobj0) == MEDIA_GRAPH_PAD ? |
| 140 | "data" : "interface", |
| 141 | media_id(link->gobj0), |
| 142 | media_id(link->gobj1)); |
Mauro Carvalho Chehab | 39a956c | 2015-08-13 14:42:42 -0300 | [diff] [blame] | 143 | break; |
| 144 | } |
| 145 | case MEDIA_GRAPH_PAD: |
| 146 | { |
| 147 | struct media_pad *pad = gobj_to_pad(gobj); |
| 148 | |
| 149 | dev_dbg(gobj->mdev->dev, |
Mauro Carvalho Chehab | 05b3b77 | 2015-12-16 14:28:01 -0200 | [diff] [blame] | 150 | "%s id %u: %s%spad '%s':%d\n", |
| 151 | event_name, media_id(gobj), |
| 152 | pad->flags & MEDIA_PAD_FL_SINK ? "sink " : "", |
Mauro Carvalho Chehab | 6c24d46 | 2015-08-21 18:26:42 -0300 | [diff] [blame] | 153 | pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "", |
Mauro Carvalho Chehab | 39a956c | 2015-08-13 14:42:42 -0300 | [diff] [blame] | 154 | pad->entity->name, pad->index); |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 155 | break; |
| 156 | } |
| 157 | case MEDIA_GRAPH_INTF_DEVNODE: |
| 158 | { |
| 159 | struct media_interface *intf = gobj_to_intf(gobj); |
| 160 | struct media_intf_devnode *devnode = intf_to_devnode(intf); |
| 161 | |
| 162 | dev_dbg(gobj->mdev->dev, |
Mauro Carvalho Chehab | 05b3b77 | 2015-12-16 14:28:01 -0200 | [diff] [blame] | 163 | "%s id %u: intf_devnode %s - major: %d, minor: %d\n", |
| 164 | event_name, media_id(gobj), |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 165 | intf_type(intf), |
| 166 | devnode->major, devnode->minor); |
| 167 | break; |
Mauro Carvalho Chehab | 39a956c | 2015-08-13 14:42:42 -0300 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | #endif |
| 171 | } |
| 172 | |
Mauro Carvalho Chehab | c350ef8 | 2015-12-11 11:55:40 -0200 | [diff] [blame] | 173 | void media_gobj_create(struct media_device *mdev, |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 174 | enum media_gobj_type type, |
| 175 | struct media_gobj *gobj) |
| 176 | { |
Mauro Carvalho Chehab | 8f6d368 | 2015-08-19 20:18:35 -0300 | [diff] [blame] | 177 | BUG_ON(!mdev); |
| 178 | |
Mauro Carvalho Chehab | 39a956c | 2015-08-13 14:42:42 -0300 | [diff] [blame] | 179 | gobj->mdev = mdev; |
| 180 | |
Mauro Carvalho Chehab | bfab2aac | 2015-08-14 12:47:48 -0300 | [diff] [blame] | 181 | /* Create a per-type unique object ID */ |
Mauro Carvalho Chehab | 05b3b77 | 2015-12-16 14:28:01 -0200 | [diff] [blame] | 182 | gobj->id = media_gobj_gen_id(type, ++mdev->id); |
| 183 | |
Mauro Carvalho Chehab | bfab2aac | 2015-08-14 12:47:48 -0300 | [diff] [blame] | 184 | switch (type) { |
| 185 | case MEDIA_GRAPH_ENTITY: |
Mauro Carvalho Chehab | 05bfa9f | 2015-08-23 07:51:33 -0300 | [diff] [blame] | 186 | list_add_tail(&gobj->list, &mdev->entities); |
Mauro Carvalho Chehab | bfab2aac | 2015-08-14 12:47:48 -0300 | [diff] [blame] | 187 | break; |
Mauro Carvalho Chehab | 18710dc | 2015-08-14 12:50:08 -0300 | [diff] [blame] | 188 | case MEDIA_GRAPH_PAD: |
Mauro Carvalho Chehab | 9155d85 | 2015-08-23 08:00:33 -0300 | [diff] [blame] | 189 | list_add_tail(&gobj->list, &mdev->pads); |
Mauro Carvalho Chehab | 18710dc | 2015-08-14 12:50:08 -0300 | [diff] [blame] | 190 | break; |
Mauro Carvalho Chehab | 6b6a427 | 2015-08-14 12:54:36 -0300 | [diff] [blame] | 191 | case MEDIA_GRAPH_LINK: |
Mauro Carvalho Chehab | 9155d85 | 2015-08-23 08:00:33 -0300 | [diff] [blame] | 192 | list_add_tail(&gobj->list, &mdev->links); |
Mauro Carvalho Chehab | 6b6a427 | 2015-08-14 12:54:36 -0300 | [diff] [blame] | 193 | break; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 194 | case MEDIA_GRAPH_INTF_DEVNODE: |
Mauro Carvalho Chehab | 9155d85 | 2015-08-23 08:00:33 -0300 | [diff] [blame] | 195 | list_add_tail(&gobj->list, &mdev->interfaces); |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 196 | break; |
Mauro Carvalho Chehab | bfab2aac | 2015-08-14 12:47:48 -0300 | [diff] [blame] | 197 | } |
Mauro Carvalho Chehab | 2521fda | 2015-08-23 09:40:26 -0300 | [diff] [blame] | 198 | |
| 199 | mdev->topology_version++; |
| 200 | |
Mauro Carvalho Chehab | 39a956c | 2015-08-13 14:42:42 -0300 | [diff] [blame] | 201 | dev_dbg_obj(__func__, gobj); |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 202 | } |
| 203 | |
Mauro Carvalho Chehab | c350ef8 | 2015-12-11 11:55:40 -0200 | [diff] [blame] | 204 | void media_gobj_destroy(struct media_gobj *gobj) |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 205 | { |
Mauro Carvalho Chehab | 39a956c | 2015-08-13 14:42:42 -0300 | [diff] [blame] | 206 | dev_dbg_obj(__func__, gobj); |
Mauro Carvalho Chehab | 9155d85 | 2015-08-23 08:00:33 -0300 | [diff] [blame] | 207 | |
Max Kellermann | 6753743 | 2016-08-09 23:32:57 +0200 | [diff] [blame] | 208 | /* Do nothing if the object is not linked. */ |
| 209 | if (gobj->mdev == NULL) |
| 210 | return; |
| 211 | |
Mauro Carvalho Chehab | 2521fda | 2015-08-23 09:40:26 -0300 | [diff] [blame] | 212 | gobj->mdev->topology_version++; |
| 213 | |
Mauro Carvalho Chehab | 9155d85 | 2015-08-23 08:00:33 -0300 | [diff] [blame] | 214 | /* Remove the object from mdev list */ |
| 215 | list_del(&gobj->list); |
Max Kellermann | 6753743 | 2016-08-09 23:32:57 +0200 | [diff] [blame] | 216 | |
| 217 | gobj->mdev = NULL; |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 218 | } |
| 219 | |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 220 | int media_entity_pads_init(struct media_entity *entity, u16 num_pads, |
| 221 | struct media_pad *pads) |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 222 | { |
Javier Martinez Canillas | db141a3 | 2015-09-08 14:10:56 -0300 | [diff] [blame] | 223 | struct media_device *mdev = entity->graph_obj.mdev; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 224 | unsigned int i; |
| 225 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 226 | entity->num_pads = num_pads; |
| 227 | entity->pads = pads; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 228 | |
Javier Martinez Canillas | db141a3 | 2015-09-08 14:10:56 -0300 | [diff] [blame] | 229 | if (mdev) |
Mauro Carvalho Chehab | e2c91d4 | 2016-04-06 10:55:24 -0300 | [diff] [blame] | 230 | mutex_lock(&mdev->graph_mutex); |
Javier Martinez Canillas | db141a3 | 2015-09-08 14:10:56 -0300 | [diff] [blame] | 231 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 232 | for (i = 0; i < num_pads; i++) { |
| 233 | pads[i].entity = entity; |
| 234 | pads[i].index = i; |
Javier Martinez Canillas | db141a3 | 2015-09-08 14:10:56 -0300 | [diff] [blame] | 235 | if (mdev) |
Mauro Carvalho Chehab | c350ef8 | 2015-12-11 11:55:40 -0200 | [diff] [blame] | 236 | media_gobj_create(mdev, MEDIA_GRAPH_PAD, |
Javier Martinez Canillas | db141a3 | 2015-09-08 14:10:56 -0300 | [diff] [blame] | 237 | &entity->pads[i].graph_obj); |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 238 | } |
| 239 | |
Javier Martinez Canillas | db141a3 | 2015-09-08 14:10:56 -0300 | [diff] [blame] | 240 | if (mdev) |
Mauro Carvalho Chehab | e2c91d4 | 2016-04-06 10:55:24 -0300 | [diff] [blame] | 241 | mutex_unlock(&mdev->graph_mutex); |
Javier Martinez Canillas | db141a3 | 2015-09-08 14:10:56 -0300 | [diff] [blame] | 242 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 243 | return 0; |
| 244 | } |
Mauro Carvalho Chehab | ab22e77 | 2015-12-11 07:44:40 -0200 | [diff] [blame] | 245 | EXPORT_SYMBOL_GPL(media_entity_pads_init); |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 246 | |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 247 | /* ----------------------------------------------------------------------------- |
| 248 | * Graph traversal |
| 249 | */ |
| 250 | |
| 251 | static struct media_entity * |
| 252 | media_entity_other(struct media_entity *entity, struct media_link *link) |
| 253 | { |
| 254 | if (link->source->entity == entity) |
| 255 | return link->sink->entity; |
| 256 | else |
| 257 | return link->source->entity; |
| 258 | } |
| 259 | |
| 260 | /* push an entity to traversal stack */ |
| 261 | static void stack_push(struct media_entity_graph *graph, |
| 262 | struct media_entity *entity) |
| 263 | { |
| 264 | if (graph->top == MEDIA_ENTITY_ENUM_MAX_DEPTH - 1) { |
| 265 | WARN_ON(1); |
| 266 | return; |
| 267 | } |
| 268 | graph->top++; |
Javier Martinez Canillas | 313895f | 2015-12-11 15:16:36 -0200 | [diff] [blame] | 269 | graph->stack[graph->top].link = entity->links.next; |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 270 | graph->stack[graph->top].entity = entity; |
| 271 | } |
| 272 | |
| 273 | static struct media_entity *stack_pop(struct media_entity_graph *graph) |
| 274 | { |
| 275 | struct media_entity *entity; |
| 276 | |
| 277 | entity = graph->stack[graph->top].entity; |
| 278 | graph->top--; |
| 279 | |
| 280 | return entity; |
| 281 | } |
| 282 | |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 283 | #define link_top(en) ((en)->stack[(en)->top].link) |
| 284 | #define stack_top(en) ((en)->stack[(en)->top].entity) |
| 285 | |
Sakari Ailus | 0798ce4 | 2015-12-16 11:32:37 -0200 | [diff] [blame] | 286 | /* |
| 287 | * TODO: Get rid of this. |
| 288 | */ |
Mauro Carvalho Chehab | 430a672 | 2015-12-16 15:18:25 -0200 | [diff] [blame] | 289 | #define MEDIA_ENTITY_MAX_PADS 512 |
Sakari Ailus | 0798ce4 | 2015-12-16 11:32:37 -0200 | [diff] [blame] | 290 | |
Sakari Ailus | e03d220 | 2015-12-16 11:32:22 -0200 | [diff] [blame] | 291 | /** |
| 292 | * media_entity_graph_walk_init - Allocate resources for graph walk |
| 293 | * @graph: Media graph structure that will be used to walk the graph |
| 294 | * @mdev: Media device |
| 295 | * |
| 296 | * Reserve resources for graph walk in media device's current |
| 297 | * state. The memory must be released using |
| 298 | * media_entity_graph_walk_free(). |
| 299 | * |
| 300 | * Returns error on failure, zero on success. |
| 301 | */ |
| 302 | __must_check int media_entity_graph_walk_init( |
| 303 | struct media_entity_graph *graph, struct media_device *mdev) |
| 304 | { |
Sakari Ailus | 29d8da0 | 2015-12-16 11:32:28 -0200 | [diff] [blame] | 305 | return media_entity_enum_init(&graph->ent_enum, mdev); |
Sakari Ailus | e03d220 | 2015-12-16 11:32:22 -0200 | [diff] [blame] | 306 | } |
| 307 | EXPORT_SYMBOL_GPL(media_entity_graph_walk_init); |
| 308 | |
| 309 | /** |
| 310 | * media_entity_graph_walk_cleanup - Release resources related to graph walking |
| 311 | * @graph: Media graph structure that was used to walk the graph |
| 312 | */ |
| 313 | void media_entity_graph_walk_cleanup(struct media_entity_graph *graph) |
| 314 | { |
Sakari Ailus | 29d8da0 | 2015-12-16 11:32:28 -0200 | [diff] [blame] | 315 | media_entity_enum_cleanup(&graph->ent_enum); |
Sakari Ailus | e03d220 | 2015-12-16 11:32:22 -0200 | [diff] [blame] | 316 | } |
| 317 | EXPORT_SYMBOL_GPL(media_entity_graph_walk_cleanup); |
| 318 | |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 319 | void media_entity_graph_walk_start(struct media_entity_graph *graph, |
| 320 | struct media_entity *entity) |
| 321 | { |
Sakari Ailus | 29d8da0 | 2015-12-16 11:32:28 -0200 | [diff] [blame] | 322 | media_entity_enum_zero(&graph->ent_enum); |
| 323 | media_entity_enum_set(&graph->ent_enum, entity); |
| 324 | |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 325 | graph->top = 0; |
| 326 | graph->stack[graph->top].entity = NULL; |
| 327 | stack_push(graph, entity); |
| 328 | } |
| 329 | EXPORT_SYMBOL_GPL(media_entity_graph_walk_start); |
| 330 | |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 331 | struct media_entity * |
| 332 | media_entity_graph_walk_next(struct media_entity_graph *graph) |
| 333 | { |
| 334 | if (stack_top(graph) == NULL) |
| 335 | return NULL; |
| 336 | |
| 337 | /* |
| 338 | * Depth first search. Push entity to stack and continue from |
| 339 | * top of the stack until no more entities on the level can be |
| 340 | * found. |
| 341 | */ |
Javier Martinez Canillas | 313895f | 2015-12-11 15:16:36 -0200 | [diff] [blame] | 342 | while (link_top(graph) != &stack_top(graph)->links) { |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 343 | struct media_entity *entity = stack_top(graph); |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 344 | struct media_link *link; |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 345 | struct media_entity *next; |
| 346 | |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 347 | link = list_entry(link_top(graph), typeof(*link), list); |
| 348 | |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 349 | /* The link is not enabled so we do not follow. */ |
| 350 | if (!(link->flags & MEDIA_LNK_FL_ENABLED)) { |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 351 | link_top(graph) = link_top(graph)->next; |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 352 | continue; |
| 353 | } |
| 354 | |
| 355 | /* Get the entity in the other end of the link . */ |
| 356 | next = media_entity_other(entity, link); |
| 357 | |
Laurent Pinchart | 5c7b25b | 2013-06-07 12:45:11 -0300 | [diff] [blame] | 358 | /* Has the entity already been visited? */ |
Sakari Ailus | 29d8da0 | 2015-12-16 11:32:28 -0200 | [diff] [blame] | 359 | if (media_entity_enum_test_and_set(&graph->ent_enum, next)) { |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 360 | link_top(graph) = link_top(graph)->next; |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 361 | continue; |
| 362 | } |
| 363 | |
| 364 | /* Push the new entity to stack and start over. */ |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 365 | link_top(graph) = link_top(graph)->next; |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 366 | stack_push(graph, next); |
| 367 | } |
| 368 | |
| 369 | return stack_pop(graph); |
| 370 | } |
| 371 | EXPORT_SYMBOL_GPL(media_entity_graph_walk_next); |
| 372 | |
| 373 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 374 | * Pipeline management |
| 375 | */ |
| 376 | |
Shuah Khan | fb49f20 | 2016-02-11 21:41:24 -0200 | [diff] [blame] | 377 | __must_check int __media_entity_pipeline_start(struct media_entity *entity, |
| 378 | struct media_pipeline *pipe) |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 379 | { |
Javier Martinez Canillas | d10c989 | 2015-08-19 12:35:21 -0300 | [diff] [blame] | 380 | struct media_device *mdev = entity->graph_obj.mdev; |
Sakari Ailus | 5dd8775 | 2015-12-16 11:32:21 -0200 | [diff] [blame] | 381 | struct media_entity_graph *graph = &pipe->graph; |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 382 | struct media_entity *entity_err = entity; |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 383 | struct media_link *link; |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 384 | int ret; |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 385 | |
Sakari Ailus | 74a41330 | 2015-12-16 11:32:29 -0200 | [diff] [blame] | 386 | if (!pipe->streaming_count++) { |
| 387 | ret = media_entity_graph_walk_init(&pipe->graph, mdev); |
| 388 | if (ret) |
| 389 | goto error_graph_walk_start; |
Sakari Ailus | 106b990 | 2015-12-16 15:32:23 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | media_entity_graph_walk_start(&pipe->graph, entity); |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 393 | |
Sakari Ailus | 5dd8775 | 2015-12-16 11:32:21 -0200 | [diff] [blame] | 394 | while ((entity = media_entity_graph_walk_next(graph))) { |
Mauro Carvalho Chehab | ef69ee1 | 2015-10-01 18:07:53 -0300 | [diff] [blame] | 395 | DECLARE_BITMAP(active, MEDIA_ENTITY_MAX_PADS); |
| 396 | DECLARE_BITMAP(has_no_links, MEDIA_ENTITY_MAX_PADS); |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 397 | |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 398 | entity->stream_count++; |
Sakari Ailus | 8aaf62b | 2015-11-29 17:20:02 -0200 | [diff] [blame] | 399 | |
| 400 | if (WARN_ON(entity->pipe && entity->pipe != pipe)) { |
| 401 | ret = -EBUSY; |
| 402 | goto error; |
| 403 | } |
| 404 | |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 405 | entity->pipe = pipe; |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 406 | |
| 407 | /* Already streaming --- no need to check. */ |
| 408 | if (entity->stream_count > 1) |
| 409 | continue; |
| 410 | |
| 411 | if (!entity->ops || !entity->ops->link_validate) |
| 412 | continue; |
| 413 | |
Sakari Ailus | de49c28 | 2013-10-13 08:00:26 -0300 | [diff] [blame] | 414 | bitmap_zero(active, entity->num_pads); |
| 415 | bitmap_fill(has_no_links, entity->num_pads); |
| 416 | |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 417 | list_for_each_entry(link, &entity->links, list) { |
Sakari Ailus | de49c28 | 2013-10-13 08:00:26 -0300 | [diff] [blame] | 418 | struct media_pad *pad = link->sink->entity == entity |
| 419 | ? link->sink : link->source; |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 420 | |
Sakari Ailus | de49c28 | 2013-10-13 08:00:26 -0300 | [diff] [blame] | 421 | /* Mark that a pad is connected by a link. */ |
| 422 | bitmap_clear(has_no_links, pad->index, 1); |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 423 | |
Sakari Ailus | de49c28 | 2013-10-13 08:00:26 -0300 | [diff] [blame] | 424 | /* |
| 425 | * Pads that either do not need to connect or |
| 426 | * are connected through an enabled link are |
| 427 | * fine. |
| 428 | */ |
| 429 | if (!(pad->flags & MEDIA_PAD_FL_MUST_CONNECT) || |
| 430 | link->flags & MEDIA_LNK_FL_ENABLED) |
| 431 | bitmap_set(active, pad->index, 1); |
| 432 | |
| 433 | /* |
| 434 | * Link validation will only take place for |
| 435 | * sink ends of the link that are enabled. |
| 436 | */ |
| 437 | if (link->sink != pad || |
| 438 | !(link->flags & MEDIA_LNK_FL_ENABLED)) |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 439 | continue; |
| 440 | |
| 441 | ret = entity->ops->link_validate(link); |
Sakari Ailus | fab9d30 | 2014-10-28 20:35:04 -0300 | [diff] [blame] | 442 | if (ret < 0 && ret != -ENOIOCTLCMD) { |
Javier Martinez Canillas | d10c989 | 2015-08-19 12:35:21 -0300 | [diff] [blame] | 443 | dev_dbg(entity->graph_obj.mdev->dev, |
Sakari Ailus | fab9d30 | 2014-10-28 20:35:04 -0300 | [diff] [blame] | 444 | "link validation failed for \"%s\":%u -> \"%s\":%u, error %d\n", |
Sakari Ailus | 823ea2a | 2015-02-12 11:43:11 -0200 | [diff] [blame] | 445 | link->source->entity->name, |
| 446 | link->source->index, |
| 447 | entity->name, link->sink->index, ret); |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 448 | goto error; |
Sakari Ailus | fab9d30 | 2014-10-28 20:35:04 -0300 | [diff] [blame] | 449 | } |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 450 | } |
Sakari Ailus | de49c28 | 2013-10-13 08:00:26 -0300 | [diff] [blame] | 451 | |
| 452 | /* Either no links or validated links are fine. */ |
| 453 | bitmap_or(active, active, has_no_links, entity->num_pads); |
| 454 | |
| 455 | if (!bitmap_full(active, entity->num_pads)) { |
Helen Mae Koike Fornazier | 47dfdb3 | 2015-06-28 16:14:10 -0300 | [diff] [blame] | 456 | ret = -ENOLINK; |
Javier Martinez Canillas | d10c989 | 2015-08-19 12:35:21 -0300 | [diff] [blame] | 457 | dev_dbg(entity->graph_obj.mdev->dev, |
Sakari Ailus | fab9d30 | 2014-10-28 20:35:04 -0300 | [diff] [blame] | 458 | "\"%s\":%u must be connected by an enabled link\n", |
| 459 | entity->name, |
Sakari Ailus | 094f1ca | 2014-11-03 17:55:51 -0300 | [diff] [blame] | 460 | (unsigned)find_first_zero_bit( |
| 461 | active, entity->num_pads)); |
Sakari Ailus | de49c28 | 2013-10-13 08:00:26 -0300 | [diff] [blame] | 462 | goto error; |
| 463 | } |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 464 | } |
| 465 | |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 466 | return 0; |
| 467 | |
| 468 | error: |
| 469 | /* |
| 470 | * Link validation on graph failed. We revert what we did and |
| 471 | * return the error. |
| 472 | */ |
Sakari Ailus | 5dd8775 | 2015-12-16 11:32:21 -0200 | [diff] [blame] | 473 | media_entity_graph_walk_start(graph, entity_err); |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 474 | |
Sakari Ailus | 5dd8775 | 2015-12-16 11:32:21 -0200 | [diff] [blame] | 475 | while ((entity_err = media_entity_graph_walk_next(graph))) { |
Shuah Khan | 3801bc7 | 2016-01-30 18:10:52 -0200 | [diff] [blame] | 476 | /* don't let the stream_count go negative */ |
| 477 | if (entity->stream_count > 0) { |
| 478 | entity_err->stream_count--; |
| 479 | if (entity_err->stream_count == 0) |
| 480 | entity_err->pipe = NULL; |
| 481 | } |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 482 | |
| 483 | /* |
| 484 | * We haven't increased stream_count further than this |
| 485 | * so we quit here. |
| 486 | */ |
| 487 | if (entity_err == entity) |
| 488 | break; |
| 489 | } |
| 490 | |
Sakari Ailus | 74a41330 | 2015-12-16 11:32:29 -0200 | [diff] [blame] | 491 | error_graph_walk_start: |
| 492 | if (!--pipe->streaming_count) |
| 493 | media_entity_graph_walk_cleanup(graph); |
Sakari Ailus | 106b990 | 2015-12-16 15:32:23 +0200 | [diff] [blame] | 494 | |
Shuah Khan | fb49f20 | 2016-02-11 21:41:24 -0200 | [diff] [blame] | 495 | return ret; |
| 496 | } |
| 497 | EXPORT_SYMBOL_GPL(__media_entity_pipeline_start); |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 498 | |
Shuah Khan | fb49f20 | 2016-02-11 21:41:24 -0200 | [diff] [blame] | 499 | __must_check int media_entity_pipeline_start(struct media_entity *entity, |
| 500 | struct media_pipeline *pipe) |
| 501 | { |
| 502 | struct media_device *mdev = entity->graph_obj.mdev; |
| 503 | int ret; |
| 504 | |
| 505 | mutex_lock(&mdev->graph_mutex); |
| 506 | ret = __media_entity_pipeline_start(entity, pipe); |
| 507 | mutex_unlock(&mdev->graph_mutex); |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 508 | return ret; |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 509 | } |
| 510 | EXPORT_SYMBOL_GPL(media_entity_pipeline_start); |
| 511 | |
Shuah Khan | fb49f20 | 2016-02-11 21:41:24 -0200 | [diff] [blame] | 512 | void __media_entity_pipeline_stop(struct media_entity *entity) |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 513 | { |
Sakari Ailus | 5dd8775 | 2015-12-16 11:32:21 -0200 | [diff] [blame] | 514 | struct media_entity_graph *graph = &entity->pipe->graph; |
Sakari Ailus | 74a41330 | 2015-12-16 11:32:29 -0200 | [diff] [blame] | 515 | struct media_pipeline *pipe = entity->pipe; |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 516 | |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 517 | |
Sakari Ailus | 74a41330 | 2015-12-16 11:32:29 -0200 | [diff] [blame] | 518 | WARN_ON(!pipe->streaming_count); |
Sakari Ailus | 5dd8775 | 2015-12-16 11:32:21 -0200 | [diff] [blame] | 519 | media_entity_graph_walk_start(graph, entity); |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 520 | |
Sakari Ailus | 5dd8775 | 2015-12-16 11:32:21 -0200 | [diff] [blame] | 521 | while ((entity = media_entity_graph_walk_next(graph))) { |
Shuah Khan | 3801bc7 | 2016-01-30 18:10:52 -0200 | [diff] [blame] | 522 | /* don't let the stream_count go negative */ |
| 523 | if (entity->stream_count > 0) { |
| 524 | entity->stream_count--; |
| 525 | if (entity->stream_count == 0) |
| 526 | entity->pipe = NULL; |
| 527 | } |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 528 | } |
| 529 | |
Sakari Ailus | 74a41330 | 2015-12-16 11:32:29 -0200 | [diff] [blame] | 530 | if (!--pipe->streaming_count) |
| 531 | media_entity_graph_walk_cleanup(graph); |
Sakari Ailus | 106b990 | 2015-12-16 15:32:23 +0200 | [diff] [blame] | 532 | |
Shuah Khan | fb49f20 | 2016-02-11 21:41:24 -0200 | [diff] [blame] | 533 | } |
| 534 | EXPORT_SYMBOL_GPL(__media_entity_pipeline_stop); |
| 535 | |
| 536 | void media_entity_pipeline_stop(struct media_entity *entity) |
| 537 | { |
| 538 | struct media_device *mdev = entity->graph_obj.mdev; |
| 539 | |
| 540 | mutex_lock(&mdev->graph_mutex); |
| 541 | __media_entity_pipeline_stop(entity); |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 542 | mutex_unlock(&mdev->graph_mutex); |
| 543 | } |
| 544 | EXPORT_SYMBOL_GPL(media_entity_pipeline_stop); |
| 545 | |
| 546 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 547 | * Module use count |
| 548 | */ |
| 549 | |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 550 | struct media_entity *media_entity_get(struct media_entity *entity) |
| 551 | { |
| 552 | if (entity == NULL) |
| 553 | return NULL; |
| 554 | |
Javier Martinez Canillas | d10c989 | 2015-08-19 12:35:21 -0300 | [diff] [blame] | 555 | if (entity->graph_obj.mdev->dev && |
| 556 | !try_module_get(entity->graph_obj.mdev->dev->driver->owner)) |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 557 | return NULL; |
| 558 | |
| 559 | return entity; |
| 560 | } |
| 561 | EXPORT_SYMBOL_GPL(media_entity_get); |
| 562 | |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 563 | void media_entity_put(struct media_entity *entity) |
| 564 | { |
| 565 | if (entity == NULL) |
| 566 | return; |
| 567 | |
Javier Martinez Canillas | d10c989 | 2015-08-19 12:35:21 -0300 | [diff] [blame] | 568 | if (entity->graph_obj.mdev->dev) |
| 569 | module_put(entity->graph_obj.mdev->dev->driver->owner); |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 570 | } |
| 571 | EXPORT_SYMBOL_GPL(media_entity_put); |
| 572 | |
| 573 | /* ----------------------------------------------------------------------------- |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 574 | * Links management |
| 575 | */ |
| 576 | |
Mauro Carvalho Chehab | 23615de | 2015-08-20 08:21:35 -0300 | [diff] [blame] | 577 | static struct media_link *media_add_link(struct list_head *head) |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 578 | { |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 579 | struct media_link *link; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 580 | |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 581 | link = kzalloc(sizeof(*link), GFP_KERNEL); |
| 582 | if (link == NULL) |
| 583 | return NULL; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 584 | |
Mauro Carvalho Chehab | 23615de | 2015-08-20 08:21:35 -0300 | [diff] [blame] | 585 | list_add_tail(&link->list, head); |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 586 | |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 587 | return link; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 588 | } |
| 589 | |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 590 | static void __media_entity_remove_link(struct media_entity *entity, |
Mauro Carvalho Chehab | 5abad22 | 2015-12-11 11:19:38 -0200 | [diff] [blame] | 591 | struct media_link *link) |
| 592 | { |
| 593 | struct media_link *rlink, *tmp; |
| 594 | struct media_entity *remote; |
Mauro Carvalho Chehab | 5abad22 | 2015-12-11 11:19:38 -0200 | [diff] [blame] | 595 | |
| 596 | if (link->source->entity == entity) |
| 597 | remote = link->sink->entity; |
| 598 | else |
| 599 | remote = link->source->entity; |
| 600 | |
| 601 | list_for_each_entry_safe(rlink, tmp, &remote->links, list) { |
Mauro Carvalho Chehab | 58f69ee | 2015-12-11 11:25:23 -0200 | [diff] [blame] | 602 | if (rlink != link->reverse) |
Mauro Carvalho Chehab | 5abad22 | 2015-12-11 11:19:38 -0200 | [diff] [blame] | 603 | continue; |
Mauro Carvalho Chehab | 5abad22 | 2015-12-11 11:19:38 -0200 | [diff] [blame] | 604 | |
| 605 | if (link->source->entity == entity) |
| 606 | remote->num_backlinks--; |
| 607 | |
| 608 | /* Remove the remote link */ |
| 609 | list_del(&rlink->list); |
Mauro Carvalho Chehab | c350ef8 | 2015-12-11 11:55:40 -0200 | [diff] [blame] | 610 | media_gobj_destroy(&rlink->graph_obj); |
Mauro Carvalho Chehab | 5abad22 | 2015-12-11 11:19:38 -0200 | [diff] [blame] | 611 | kfree(rlink); |
| 612 | |
| 613 | if (--remote->num_links == 0) |
| 614 | break; |
| 615 | } |
| 616 | list_del(&link->list); |
Mauro Carvalho Chehab | c350ef8 | 2015-12-11 11:55:40 -0200 | [diff] [blame] | 617 | media_gobj_destroy(&link->graph_obj); |
Mauro Carvalho Chehab | 5abad22 | 2015-12-11 11:19:38 -0200 | [diff] [blame] | 618 | kfree(link); |
| 619 | } |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 620 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 621 | int |
Mauro Carvalho Chehab | 8df00a1 | 2015-08-07 08:14:38 -0300 | [diff] [blame] | 622 | media_create_pad_link(struct media_entity *source, u16 source_pad, |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 623 | struct media_entity *sink, u16 sink_pad, u32 flags) |
| 624 | { |
| 625 | struct media_link *link; |
| 626 | struct media_link *backlink; |
| 627 | |
| 628 | BUG_ON(source == NULL || sink == NULL); |
| 629 | BUG_ON(source_pad >= source->num_pads); |
| 630 | BUG_ON(sink_pad >= sink->num_pads); |
| 631 | |
Mauro Carvalho Chehab | 23615de | 2015-08-20 08:21:35 -0300 | [diff] [blame] | 632 | link = media_add_link(&source->links); |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 633 | if (link == NULL) |
| 634 | return -ENOMEM; |
| 635 | |
| 636 | link->source = &source->pads[source_pad]; |
| 637 | link->sink = &sink->pads[sink_pad]; |
Mauro Carvalho Chehab | 82ae2a5 | 2015-12-11 18:09:13 -0200 | [diff] [blame] | 638 | link->flags = flags & ~MEDIA_LNK_FL_INTERFACE_LINK; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 639 | |
Mauro Carvalho Chehab | 6b6a427 | 2015-08-14 12:54:36 -0300 | [diff] [blame] | 640 | /* Initialize graph object embedded at the new link */ |
Mauro Carvalho Chehab | c350ef8 | 2015-12-11 11:55:40 -0200 | [diff] [blame] | 641 | media_gobj_create(source->graph_obj.mdev, MEDIA_GRAPH_LINK, |
Javier Martinez Canillas | d10c989 | 2015-08-19 12:35:21 -0300 | [diff] [blame] | 642 | &link->graph_obj); |
Mauro Carvalho Chehab | 6b6a427 | 2015-08-14 12:54:36 -0300 | [diff] [blame] | 643 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 644 | /* Create the backlink. Backlinks are used to help graph traversal and |
| 645 | * are not reported to userspace. |
| 646 | */ |
Mauro Carvalho Chehab | 23615de | 2015-08-20 08:21:35 -0300 | [diff] [blame] | 647 | backlink = media_add_link(&sink->links); |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 648 | if (backlink == NULL) { |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 649 | __media_entity_remove_link(source, link); |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 650 | return -ENOMEM; |
| 651 | } |
| 652 | |
| 653 | backlink->source = &source->pads[source_pad]; |
| 654 | backlink->sink = &sink->pads[sink_pad]; |
| 655 | backlink->flags = flags; |
Mauro Carvalho Chehab | 39d1ebc6 | 2015-08-30 09:53:57 -0300 | [diff] [blame] | 656 | backlink->is_backlink = true; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 657 | |
Mauro Carvalho Chehab | 6b6a427 | 2015-08-14 12:54:36 -0300 | [diff] [blame] | 658 | /* Initialize graph object embedded at the new link */ |
Mauro Carvalho Chehab | c350ef8 | 2015-12-11 11:55:40 -0200 | [diff] [blame] | 659 | media_gobj_create(sink->graph_obj.mdev, MEDIA_GRAPH_LINK, |
Javier Martinez Canillas | d10c989 | 2015-08-19 12:35:21 -0300 | [diff] [blame] | 660 | &backlink->graph_obj); |
Mauro Carvalho Chehab | 6b6a427 | 2015-08-14 12:54:36 -0300 | [diff] [blame] | 661 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 662 | link->reverse = backlink; |
| 663 | backlink->reverse = link; |
| 664 | |
| 665 | sink->num_backlinks++; |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 666 | sink->num_links++; |
| 667 | source->num_links++; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 668 | |
| 669 | return 0; |
| 670 | } |
Mauro Carvalho Chehab | 8df00a1 | 2015-08-07 08:14:38 -0300 | [diff] [blame] | 671 | EXPORT_SYMBOL_GPL(media_create_pad_link); |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 672 | |
Mauro Carvalho Chehab | b01cc9c | 2015-12-30 09:45:48 -0200 | [diff] [blame] | 673 | int media_create_pad_links(const struct media_device *mdev, |
| 674 | const u32 source_function, |
| 675 | struct media_entity *source, |
| 676 | const u16 source_pad, |
| 677 | const u32 sink_function, |
| 678 | struct media_entity *sink, |
| 679 | const u16 sink_pad, |
| 680 | u32 flags, |
| 681 | const bool allow_both_undefined) |
| 682 | { |
| 683 | struct media_entity *entity; |
| 684 | unsigned function; |
| 685 | int ret; |
| 686 | |
| 687 | /* Trivial case: 1:1 relation */ |
| 688 | if (source && sink) |
| 689 | return media_create_pad_link(source, source_pad, |
| 690 | sink, sink_pad, flags); |
| 691 | |
| 692 | /* Worse case scenario: n:n relation */ |
| 693 | if (!source && !sink) { |
| 694 | if (!allow_both_undefined) |
| 695 | return 0; |
| 696 | media_device_for_each_entity(source, mdev) { |
| 697 | if (source->function != source_function) |
| 698 | continue; |
| 699 | media_device_for_each_entity(sink, mdev) { |
| 700 | if (sink->function != sink_function) |
| 701 | continue; |
| 702 | ret = media_create_pad_link(source, source_pad, |
| 703 | sink, sink_pad, |
| 704 | flags); |
| 705 | if (ret) |
| 706 | return ret; |
| 707 | flags &= ~(MEDIA_LNK_FL_ENABLED | |
| 708 | MEDIA_LNK_FL_IMMUTABLE); |
| 709 | } |
| 710 | } |
| 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | /* Handle 1:n and n:1 cases */ |
| 715 | if (source) |
| 716 | function = sink_function; |
| 717 | else |
| 718 | function = source_function; |
| 719 | |
| 720 | media_device_for_each_entity(entity, mdev) { |
| 721 | if (entity->function != function) |
| 722 | continue; |
| 723 | |
| 724 | if (source) |
| 725 | ret = media_create_pad_link(source, source_pad, |
| 726 | entity, sink_pad, flags); |
| 727 | else |
| 728 | ret = media_create_pad_link(entity, source_pad, |
| 729 | sink, sink_pad, flags); |
| 730 | if (ret) |
| 731 | return ret; |
| 732 | flags &= ~(MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE); |
| 733 | } |
| 734 | return 0; |
| 735 | } |
| 736 | EXPORT_SYMBOL_GPL(media_create_pad_links); |
| 737 | |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 738 | void __media_entity_remove_links(struct media_entity *entity) |
| 739 | { |
| 740 | struct media_link *link, *tmp; |
| 741 | |
| 742 | list_for_each_entry_safe(link, tmp, &entity->links, list) |
| 743 | __media_entity_remove_link(entity, link); |
Sylwester Nawrocki | 7349cec | 2013-05-09 08:29:32 -0300 | [diff] [blame] | 744 | |
| 745 | entity->num_links = 0; |
| 746 | entity->num_backlinks = 0; |
| 747 | } |
| 748 | EXPORT_SYMBOL_GPL(__media_entity_remove_links); |
| 749 | |
| 750 | void media_entity_remove_links(struct media_entity *entity) |
| 751 | { |
Mauro Carvalho Chehab | cc4a825 | 2015-12-15 08:01:13 -0200 | [diff] [blame] | 752 | struct media_device *mdev = entity->graph_obj.mdev; |
| 753 | |
Sylwester Nawrocki | 7349cec | 2013-05-09 08:29:32 -0300 | [diff] [blame] | 754 | /* Do nothing if the entity is not registered. */ |
Mauro Carvalho Chehab | cc4a825 | 2015-12-15 08:01:13 -0200 | [diff] [blame] | 755 | if (mdev == NULL) |
Sylwester Nawrocki | 7349cec | 2013-05-09 08:29:32 -0300 | [diff] [blame] | 756 | return; |
| 757 | |
Mauro Carvalho Chehab | e2c91d4 | 2016-04-06 10:55:24 -0300 | [diff] [blame] | 758 | mutex_lock(&mdev->graph_mutex); |
Sylwester Nawrocki | 7349cec | 2013-05-09 08:29:32 -0300 | [diff] [blame] | 759 | __media_entity_remove_links(entity); |
Mauro Carvalho Chehab | e2c91d4 | 2016-04-06 10:55:24 -0300 | [diff] [blame] | 760 | mutex_unlock(&mdev->graph_mutex); |
Sylwester Nawrocki | 7349cec | 2013-05-09 08:29:32 -0300 | [diff] [blame] | 761 | } |
| 762 | EXPORT_SYMBOL_GPL(media_entity_remove_links); |
| 763 | |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 764 | static int __media_entity_setup_link_notify(struct media_link *link, u32 flags) |
| 765 | { |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 766 | int ret; |
| 767 | |
| 768 | /* Notify both entities. */ |
| 769 | ret = media_entity_call(link->source->entity, link_setup, |
| 770 | link->source, link->sink, flags); |
| 771 | if (ret < 0 && ret != -ENOIOCTLCMD) |
| 772 | return ret; |
| 773 | |
| 774 | ret = media_entity_call(link->sink->entity, link_setup, |
| 775 | link->sink, link->source, flags); |
| 776 | if (ret < 0 && ret != -ENOIOCTLCMD) { |
| 777 | media_entity_call(link->source->entity, link_setup, |
| 778 | link->source, link->sink, link->flags); |
| 779 | return ret; |
| 780 | } |
| 781 | |
Laurent Pinchart | 7a6f0b2 | 2011-03-11 11:34:35 -0300 | [diff] [blame] | 782 | link->flags = flags; |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 783 | link->reverse->flags = link->flags; |
| 784 | |
| 785 | return 0; |
| 786 | } |
| 787 | |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 788 | int __media_entity_setup_link(struct media_link *link, u32 flags) |
| 789 | { |
Laurent Pinchart | 7a6f0b2 | 2011-03-11 11:34:35 -0300 | [diff] [blame] | 790 | const u32 mask = MEDIA_LNK_FL_ENABLED; |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 791 | struct media_device *mdev; |
| 792 | struct media_entity *source, *sink; |
| 793 | int ret = -EBUSY; |
| 794 | |
| 795 | if (link == NULL) |
| 796 | return -EINVAL; |
| 797 | |
Laurent Pinchart | 7a6f0b2 | 2011-03-11 11:34:35 -0300 | [diff] [blame] | 798 | /* The non-modifiable link flags must not be modified. */ |
| 799 | if ((link->flags & ~mask) != (flags & ~mask)) |
| 800 | return -EINVAL; |
| 801 | |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 802 | if (link->flags & MEDIA_LNK_FL_IMMUTABLE) |
| 803 | return link->flags == flags ? 0 : -EINVAL; |
| 804 | |
| 805 | if (link->flags == flags) |
| 806 | return 0; |
| 807 | |
| 808 | source = link->source->entity; |
| 809 | sink = link->sink->entity; |
| 810 | |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 811 | if (!(link->flags & MEDIA_LNK_FL_DYNAMIC) && |
| 812 | (source->stream_count || sink->stream_count)) |
| 813 | return -EBUSY; |
| 814 | |
Javier Martinez Canillas | d10c989 | 2015-08-19 12:35:21 -0300 | [diff] [blame] | 815 | mdev = source->graph_obj.mdev; |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 816 | |
Laurent Pinchart | 68429f5 | 2015-11-03 00:27:51 -0200 | [diff] [blame] | 817 | if (mdev->ops && mdev->ops->link_notify) { |
| 818 | ret = mdev->ops->link_notify(link, flags, |
| 819 | MEDIA_DEV_NOTIFY_PRE_LINK_CH); |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 820 | if (ret < 0) |
| 821 | return ret; |
| 822 | } |
| 823 | |
| 824 | ret = __media_entity_setup_link_notify(link, flags); |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 825 | |
Laurent Pinchart | 68429f5 | 2015-11-03 00:27:51 -0200 | [diff] [blame] | 826 | if (mdev->ops && mdev->ops->link_notify) |
| 827 | mdev->ops->link_notify(link, flags, |
| 828 | MEDIA_DEV_NOTIFY_POST_LINK_CH); |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 829 | |
| 830 | return ret; |
| 831 | } |
Shuah Khan | efc7027 | 2016-02-11 21:41:23 -0200 | [diff] [blame] | 832 | EXPORT_SYMBOL_GPL(__media_entity_setup_link); |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 833 | |
| 834 | int media_entity_setup_link(struct media_link *link, u32 flags) |
| 835 | { |
| 836 | int ret; |
| 837 | |
Mauro Carvalho Chehab | 5c883ed | 2015-12-15 07:58:18 -0200 | [diff] [blame] | 838 | mutex_lock(&link->graph_obj.mdev->graph_mutex); |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 839 | ret = __media_entity_setup_link(link, flags); |
Mauro Carvalho Chehab | 5c883ed | 2015-12-15 07:58:18 -0200 | [diff] [blame] | 840 | mutex_unlock(&link->graph_obj.mdev->graph_mutex); |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 841 | |
| 842 | return ret; |
| 843 | } |
| 844 | EXPORT_SYMBOL_GPL(media_entity_setup_link); |
| 845 | |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 846 | struct media_link * |
| 847 | media_entity_find_link(struct media_pad *source, struct media_pad *sink) |
| 848 | { |
| 849 | struct media_link *link; |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 850 | |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 851 | list_for_each_entry(link, &source->entity->links, list) { |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 852 | if (link->source->entity == source->entity && |
| 853 | link->source->index == source->index && |
| 854 | link->sink->entity == sink->entity && |
| 855 | link->sink->index == sink->index) |
| 856 | return link; |
| 857 | } |
| 858 | |
| 859 | return NULL; |
| 860 | } |
| 861 | EXPORT_SYMBOL_GPL(media_entity_find_link); |
| 862 | |
Andrzej Hajda | 1bddf1b | 2013-06-03 05:16:13 -0300 | [diff] [blame] | 863 | struct media_pad *media_entity_remote_pad(struct media_pad *pad) |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 864 | { |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 865 | struct media_link *link; |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 866 | |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 867 | list_for_each_entry(link, &pad->entity->links, list) { |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 868 | if (!(link->flags & MEDIA_LNK_FL_ENABLED)) |
| 869 | continue; |
| 870 | |
| 871 | if (link->source == pad) |
| 872 | return link->sink; |
| 873 | |
| 874 | if (link->sink == pad) |
| 875 | return link->source; |
| 876 | } |
| 877 | |
| 878 | return NULL; |
| 879 | |
| 880 | } |
Andrzej Hajda | 1bddf1b | 2013-06-03 05:16:13 -0300 | [diff] [blame] | 881 | EXPORT_SYMBOL_GPL(media_entity_remote_pad); |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 882 | |
Mauro Carvalho Chehab | 1283f84 | 2015-08-28 15:43:36 -0300 | [diff] [blame] | 883 | static void media_interface_init(struct media_device *mdev, |
| 884 | struct media_interface *intf, |
| 885 | u32 gobj_type, |
| 886 | u32 intf_type, u32 flags) |
| 887 | { |
| 888 | intf->type = intf_type; |
| 889 | intf->flags = flags; |
| 890 | INIT_LIST_HEAD(&intf->links); |
| 891 | |
Mauro Carvalho Chehab | c350ef8 | 2015-12-11 11:55:40 -0200 | [diff] [blame] | 892 | media_gobj_create(mdev, gobj_type, &intf->graph_obj); |
Mauro Carvalho Chehab | 1283f84 | 2015-08-28 15:43:36 -0300 | [diff] [blame] | 893 | } |
| 894 | |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 895 | /* Functions related to the media interface via device nodes */ |
| 896 | |
| 897 | struct media_intf_devnode *media_devnode_create(struct media_device *mdev, |
| 898 | u32 type, u32 flags, |
Mauro Carvalho Chehab | 0b3b72df9 | 2015-09-09 08:19:25 -0300 | [diff] [blame] | 899 | u32 major, u32 minor) |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 900 | { |
| 901 | struct media_intf_devnode *devnode; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 902 | |
Mauro Carvalho Chehab | 0b3b72df9 | 2015-09-09 08:19:25 -0300 | [diff] [blame] | 903 | devnode = kzalloc(sizeof(*devnode), GFP_KERNEL); |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 904 | if (!devnode) |
| 905 | return NULL; |
| 906 | |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 907 | devnode->major = major; |
| 908 | devnode->minor = minor; |
| 909 | |
Mauro Carvalho Chehab | 1283f84 | 2015-08-28 15:43:36 -0300 | [diff] [blame] | 910 | media_interface_init(mdev, &devnode->intf, MEDIA_GRAPH_INTF_DEVNODE, |
| 911 | type, flags); |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 912 | |
| 913 | return devnode; |
| 914 | } |
| 915 | EXPORT_SYMBOL_GPL(media_devnode_create); |
| 916 | |
| 917 | void media_devnode_remove(struct media_intf_devnode *devnode) |
| 918 | { |
Mauro Carvalho Chehab | 7c4696a | 2015-08-24 08:46:46 -0300 | [diff] [blame] | 919 | media_remove_intf_links(&devnode->intf); |
Mauro Carvalho Chehab | c350ef8 | 2015-12-11 11:55:40 -0200 | [diff] [blame] | 920 | media_gobj_destroy(&devnode->intf.graph_obj); |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 921 | kfree(devnode); |
| 922 | } |
| 923 | EXPORT_SYMBOL_GPL(media_devnode_remove); |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 924 | |
| 925 | struct media_link *media_create_intf_link(struct media_entity *entity, |
| 926 | struct media_interface *intf, |
| 927 | u32 flags) |
| 928 | { |
| 929 | struct media_link *link; |
| 930 | |
| 931 | link = media_add_link(&intf->links); |
| 932 | if (link == NULL) |
| 933 | return NULL; |
| 934 | |
| 935 | link->intf = intf; |
| 936 | link->entity = entity; |
Mauro Carvalho Chehab | 82ae2a5 | 2015-12-11 18:09:13 -0200 | [diff] [blame] | 937 | link->flags = flags | MEDIA_LNK_FL_INTERFACE_LINK; |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 938 | |
| 939 | /* Initialize graph object embedded at the new link */ |
Mauro Carvalho Chehab | c350ef8 | 2015-12-11 11:55:40 -0200 | [diff] [blame] | 940 | media_gobj_create(intf->graph_obj.mdev, MEDIA_GRAPH_LINK, |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 941 | &link->graph_obj); |
| 942 | |
| 943 | return link; |
| 944 | } |
| 945 | EXPORT_SYMBOL_GPL(media_create_intf_link); |
| 946 | |
Mauro Carvalho Chehab | d47109f | 2015-08-29 21:23:44 -0300 | [diff] [blame] | 947 | void __media_remove_intf_link(struct media_link *link) |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 948 | { |
Mauro Carvalho Chehab | d47109f | 2015-08-29 21:23:44 -0300 | [diff] [blame] | 949 | list_del(&link->list); |
Mauro Carvalho Chehab | c350ef8 | 2015-12-11 11:55:40 -0200 | [diff] [blame] | 950 | media_gobj_destroy(&link->graph_obj); |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 951 | kfree(link); |
| 952 | } |
Mauro Carvalho Chehab | d47109f | 2015-08-29 21:23:44 -0300 | [diff] [blame] | 953 | EXPORT_SYMBOL_GPL(__media_remove_intf_link); |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 954 | |
| 955 | void media_remove_intf_link(struct media_link *link) |
| 956 | { |
Mauro Carvalho Chehab | cc4a825 | 2015-12-15 08:01:13 -0200 | [diff] [blame] | 957 | struct media_device *mdev = link->graph_obj.mdev; |
| 958 | |
| 959 | /* Do nothing if the intf is not registered. */ |
| 960 | if (mdev == NULL) |
| 961 | return; |
| 962 | |
Mauro Carvalho Chehab | e2c91d4 | 2016-04-06 10:55:24 -0300 | [diff] [blame] | 963 | mutex_lock(&mdev->graph_mutex); |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 964 | __media_remove_intf_link(link); |
Mauro Carvalho Chehab | e2c91d4 | 2016-04-06 10:55:24 -0300 | [diff] [blame] | 965 | mutex_unlock(&mdev->graph_mutex); |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 966 | } |
| 967 | EXPORT_SYMBOL_GPL(media_remove_intf_link); |
Mauro Carvalho Chehab | 7c4696a | 2015-08-24 08:46:46 -0300 | [diff] [blame] | 968 | |
| 969 | void __media_remove_intf_links(struct media_interface *intf) |
| 970 | { |
| 971 | struct media_link *link, *tmp; |
| 972 | |
| 973 | list_for_each_entry_safe(link, tmp, &intf->links, list) |
| 974 | __media_remove_intf_link(link); |
| 975 | |
| 976 | } |
| 977 | EXPORT_SYMBOL_GPL(__media_remove_intf_links); |
| 978 | |
| 979 | void media_remove_intf_links(struct media_interface *intf) |
| 980 | { |
Mauro Carvalho Chehab | cc4a825 | 2015-12-15 08:01:13 -0200 | [diff] [blame] | 981 | struct media_device *mdev = intf->graph_obj.mdev; |
| 982 | |
Mauro Carvalho Chehab | 7c4696a | 2015-08-24 08:46:46 -0300 | [diff] [blame] | 983 | /* Do nothing if the intf is not registered. */ |
Mauro Carvalho Chehab | cc4a825 | 2015-12-15 08:01:13 -0200 | [diff] [blame] | 984 | if (mdev == NULL) |
Mauro Carvalho Chehab | 7c4696a | 2015-08-24 08:46:46 -0300 | [diff] [blame] | 985 | return; |
| 986 | |
Mauro Carvalho Chehab | e2c91d4 | 2016-04-06 10:55:24 -0300 | [diff] [blame] | 987 | mutex_lock(&mdev->graph_mutex); |
Mauro Carvalho Chehab | 7c4696a | 2015-08-24 08:46:46 -0300 | [diff] [blame] | 988 | __media_remove_intf_links(intf); |
Mauro Carvalho Chehab | e2c91d4 | 2016-04-06 10:55:24 -0300 | [diff] [blame] | 989 | mutex_unlock(&mdev->graph_mutex); |
Mauro Carvalho Chehab | 7c4696a | 2015-08-24 08:46:46 -0300 | [diff] [blame] | 990 | } |
| 991 | EXPORT_SYMBOL_GPL(media_remove_intf_links); |