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