All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v8 00/55] MC next generation patches
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: devel, Lars-Peter Clausen, Sylwester Nawrocki,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, linux-sh, Shuah Khan,
	Mauro Carvalho Chehab, Hans Verkuil, Javier Martinez Canillas,
	linux-samsung-soc, Laurent Pinchart, Sakari Ailus, linux-api,
	linux-arm-kernel

That's the 8th version of the MC next generation patches.

Differences from version 7:

- Patches reworked to make the reviewers happy;
- Bug fixes;
- ALSA changes got their own separate patches;
- Javier patches got integrated into this series;
- media-entity.h structs are now properly documented;
- Tested on both au0828 and omap3isp.

Due to the complexity of this change, other platform drivers may
require some fixes. 

As the patch series sent before, this is not meant to be sent
upstream yet. Its goal is to merge it for Kernel 4.4, in order to
give people enough time to review and fix pending issues.

Regards,
Mauro

Javier Martinez Canillas (6):
  [media] staging: omap4iss: get entity ID using media_entity_id()
  [media] omap3isp: get entity ID using media_entity_id()
  [media] media: use entity.graph_obj.mdev instead of .parent
  [media] media: remove media entity .parent field
  [media] omap3isp: separate links creation from entities init
  [media] omap3isp: create links after all subdevs have been bound

Mauro Carvalho Chehab (49):
  [media] media: create a macro to get entity ID
  [media] media: add a common struct to be embed on media graph objects
  [media] media: use media_gobj inside entities
  [media] media: use media_gobj inside pads
  [media] media: use media_gobj inside links
  [media] media: add messages when media device gets (un)registered
  [media] media: add a debug message to warn about gobj creation/removal
  [media] media: rename the function that create pad links
  [media] uapi/media.h: Declare interface types for V4L2 and DVB
  [media] media: add functions to allow creating interfaces
  [media] uapi/media.h: Declare interface types for ALSA
  [media] media: Don't accept early-created links
  [media] media: convert links from array to list
  [media] media: make add link more generic
  [media] media: make media_link more generic to handle interace links
  [media] media: make link debug printk more generic
  [media] media: add support to link interfaces and entities
  [media] media-entity: add a helper function to create interface
  [media] dvbdev: add support for interfaces
  [media] media: add a linked list to track interfaces by mdev
  [media] dvbdev: add support for indirect interface links
  [media] uapi/media.h: Fix entity namespace
  [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_V4L
  [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_DVB
  [media] media: add macros to check if subdev or V4L2 DMA
  [media] media: use macros to check for V4L2 subdev entities
  [media] omap3/omap4/davinci: get rid of MEDIA_ENT_T_V4L2_SUBDEV abuse
  [media] s5c73m3: fix subdev type
  [media] s5k5baf: fix subdev type
  [media] davinci_vbpe: stop MEDIA_ENT_T_V4L2_SUBDEV abuse
  [media] omap4iss: stop MEDIA_ENT_T_V4L2_SUBDEV abuse
  [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs
  [media] media controller: get rid of entity subtype on Kernel
  [media] media.h: don't use legacy entity macros at Kernel
  [media] DocBook: update descriptions for the media controller entities
  [media] dvb: modify core to implement interfaces/entities at MC new
    gen
  [media] media: report if a pad is sink or source at debug msg
  [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
  [media] media: Use a macro to interate between all interfaces
  [media] media: move mdev list init to gobj
  [media] media-device: add pads and links to media_device
  [media] media_device: add a topology version field
  [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  [media] media-entity: unregister entity links
  [media] remove interface links at media_entity_unregister()
  [media] media-device: remove interfaces and interface links
  [media] v4l2-core: create MC interfaces for devnodes
  [media] au0828: unregister MC at the end
  [media] media-entity.h: document all the structs

 .../DocBook/media/v4l/media-ioc-enum-entities.xml  |  57 +--
 Documentation/media-framework.txt                  |   2 +-
 drivers/media/dvb-core/dmxdev.c                    |   4 +-
 drivers/media/dvb-core/dvb_ca_en50221.c            |   2 +-
 drivers/media/dvb-core/dvb_frontend.c              |  11 +-
 drivers/media/dvb-core/dvb_net.c                   |   2 +-
 drivers/media/dvb-core/dvbdev.c                    | 278 +++++++++---
 drivers/media/dvb-core/dvbdev.h                    |  10 +-
 drivers/media/firewire/firedtv-ci.c                |   2 +-
 drivers/media/i2c/s5c73m3/s5c73m3-core.c           |   8 +-
 drivers/media/i2c/s5k5baf.c                        |   4 +-
 drivers/media/i2c/smiapp/smiapp-core.c             |   4 +-
 drivers/media/media-device.c                       | 245 +++++++++--
 drivers/media/media-entity.c                       | 473 +++++++++++++++++----
 drivers/media/pci/bt8xx/dst_ca.c                   |   3 +-
 drivers/media/pci/ddbridge/ddbridge-core.c         |   2 +-
 drivers/media/pci/ngene/ngene-core.c               |   2 +-
 drivers/media/pci/ttpci/av7110.c                   |   2 +-
 drivers/media/pci/ttpci/av7110_av.c                |   4 +-
 drivers/media/pci/ttpci/av7110_ca.c                |   2 +-
 drivers/media/platform/exynos4-is/common.c         |   3 +-
 drivers/media/platform/exynos4-is/fimc-capture.c   |   5 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.c |   9 +-
 drivers/media/platform/exynos4-is/fimc-lite.c      |  18 +-
 drivers/media/platform/exynos4-is/media-dev.c      |  25 +-
 drivers/media/platform/exynos4-is/media-dev.h      |   8 +-
 drivers/media/platform/omap3isp/isp.c              | 202 +++++----
 drivers/media/platform/omap3isp/ispccdc.c          |  39 +-
 drivers/media/platform/omap3isp/ispccdc.h          |   1 +
 drivers/media/platform/omap3isp/ispccp2.c          |  35 +-
 drivers/media/platform/omap3isp/ispccp2.h          |   1 +
 drivers/media/platform/omap3isp/ispcsi2.c          |  33 +-
 drivers/media/platform/omap3isp/ispcsi2.h          |   1 +
 drivers/media/platform/omap3isp/isppreview.c       |  48 ++-
 drivers/media/platform/omap3isp/isppreview.h       |   1 +
 drivers/media/platform/omap3isp/ispresizer.c       |  46 +-
 drivers/media/platform/omap3isp/ispresizer.h       |   1 +
 drivers/media/platform/omap3isp/ispvideo.c         |  17 +-
 drivers/media/platform/s3c-camif/camif-capture.c   |   2 +-
 drivers/media/platform/s3c-camif/camif-core.c      |   4 +-
 drivers/media/platform/vsp1/vsp1_drv.c             |   4 +-
 drivers/media/platform/vsp1/vsp1_rpf.c             |   2 +-
 drivers/media/platform/vsp1/vsp1_video.c           |  15 +-
 drivers/media/platform/vsp1/vsp1_wpf.c             |   2 +-
 drivers/media/platform/xilinx/xilinx-dma.c         |  10 +-
 drivers/media/platform/xilinx/xilinx-vipp.c        |   4 +-
 drivers/media/usb/au0828/au0828-core.c             |  18 +-
 drivers/media/usb/au0828/au0828-video.c            |   8 +-
 drivers/media/usb/cx231xx/cx231xx-cards.c          |   6 +-
 drivers/media/usb/cx231xx/cx231xx-video.c          |   8 +-
 drivers/media/usb/uvc/uvc_entity.c                 |   2 +-
 drivers/media/v4l2-core/v4l2-dev.c                 | 105 ++++-
 drivers/media/v4l2-core/v4l2-device.c              |  10 +-
 drivers/media/v4l2-core/v4l2-subdev.c              |   6 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipe.c   |   9 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipeif.c |  15 +-
 drivers/staging/media/davinci_vpfe/dm365_isif.c    |  15 +-
 drivers/staging/media/davinci_vpfe/dm365_resizer.c |  33 +-
 .../staging/media/davinci_vpfe/vpfe_mc_capture.c   |  10 +-
 drivers/staging/media/davinci_vpfe/vpfe_video.c    |  17 +-
 drivers/staging/media/omap4iss/iss.c               |  32 +-
 drivers/staging/media/omap4iss/iss_csi2.c          |  13 +-
 drivers/staging/media/omap4iss/iss_ipipe.c         |   9 +-
 drivers/staging/media/omap4iss/iss_ipipeif.c       |  15 +-
 drivers/staging/media/omap4iss/iss_resizer.c       |  13 +-
 drivers/staging/media/omap4iss/iss_video.c         |   9 +-
 include/media/media-device.h                       |  34 +-
 include/media/media-entity.h                       | 305 +++++++++++--
 include/media/v4l2-dev.h                           |   1 +
 include/uapi/linux/media.h                         | 205 ++++++++-
 70 files changed, 1924 insertions(+), 627 deletions(-)

-- 
2.4.3


^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH v8 00/55] MC next generation patches
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, devel,
	Greg Kroah-Hartman, Hans Verkuil, Javier Martinez Canillas,
	Lars-Peter Clausen, Laurent Pinchart, linux-api,
	linux-arm-kernel, linux-samsung-soc, linux-sh, Sakari Ailus,
	Shuah Khan, Sylwester Nawrocki

That's the 8th version of the MC next generation patches.

Differences from version 7:

- Patches reworked to make the reviewers happy;
- Bug fixes;
- ALSA changes got their own separate patches;
- Javier patches got integrated into this series;
- media-entity.h structs are now properly documented;
- Tested on both au0828 and omap3isp.

Due to the complexity of this change, other platform drivers may
require some fixes. 

As the patch series sent before, this is not meant to be sent
upstream yet. Its goal is to merge it for Kernel 4.4, in order to
give people enough time to review and fix pending issues.

Regards,
Mauro

Javier Martinez Canillas (6):
  [media] staging: omap4iss: get entity ID using media_entity_id()
  [media] omap3isp: get entity ID using media_entity_id()
  [media] media: use entity.graph_obj.mdev instead of .parent
  [media] media: remove media entity .parent field
  [media] omap3isp: separate links creation from entities init
  [media] omap3isp: create links after all subdevs have been bound

Mauro Carvalho Chehab (49):
  [media] media: create a macro to get entity ID
  [media] media: add a common struct to be embed on media graph objects
  [media] media: use media_gobj inside entities
  [media] media: use media_gobj inside pads
  [media] media: use media_gobj inside links
  [media] media: add messages when media device gets (un)registered
  [media] media: add a debug message to warn about gobj creation/removal
  [media] media: rename the function that create pad links
  [media] uapi/media.h: Declare interface types for V4L2 and DVB
  [media] media: add functions to allow creating interfaces
  [media] uapi/media.h: Declare interface types for ALSA
  [media] media: Don't accept early-created links
  [media] media: convert links from array to list
  [media] media: make add link more generic
  [media] media: make media_link more generic to handle interace links
  [media] media: make link debug printk more generic
  [media] media: add support to link interfaces and entities
  [media] media-entity: add a helper function to create interface
  [media] dvbdev: add support for interfaces
  [media] media: add a linked list to track interfaces by mdev
  [media] dvbdev: add support for indirect interface links
  [media] uapi/media.h: Fix entity namespace
  [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_V4L
  [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_DVB
  [media] media: add macros to check if subdev or V4L2 DMA
  [media] media: use macros to check for V4L2 subdev entities
  [media] omap3/omap4/davinci: get rid of MEDIA_ENT_T_V4L2_SUBDEV abuse
  [media] s5c73m3: fix subdev type
  [media] s5k5baf: fix subdev type
  [media] davinci_vbpe: stop MEDIA_ENT_T_V4L2_SUBDEV abuse
  [media] omap4iss: stop MEDIA_ENT_T_V4L2_SUBDEV abuse
  [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs
  [media] media controller: get rid of entity subtype on Kernel
  [media] media.h: don't use legacy entity macros at Kernel
  [media] DocBook: update descriptions for the media controller entities
  [media] dvb: modify core to implement interfaces/entities at MC new
    gen
  [media] media: report if a pad is sink or source at debug msg
  [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
  [media] media: Use a macro to interate between all interfaces
  [media] media: move mdev list init to gobj
  [media] media-device: add pads and links to media_device
  [media] media_device: add a topology version field
  [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  [media] media-entity: unregister entity links
  [media] remove interface links at media_entity_unregister()
  [media] media-device: remove interfaces and interface links
  [media] v4l2-core: create MC interfaces for devnodes
  [media] au0828: unregister MC at the end
  [media] media-entity.h: document all the structs

 .../DocBook/media/v4l/media-ioc-enum-entities.xml  |  57 +--
 Documentation/media-framework.txt                  |   2 +-
 drivers/media/dvb-core/dmxdev.c                    |   4 +-
 drivers/media/dvb-core/dvb_ca_en50221.c            |   2 +-
 drivers/media/dvb-core/dvb_frontend.c              |  11 +-
 drivers/media/dvb-core/dvb_net.c                   |   2 +-
 drivers/media/dvb-core/dvbdev.c                    | 278 +++++++++---
 drivers/media/dvb-core/dvbdev.h                    |  10 +-
 drivers/media/firewire/firedtv-ci.c                |   2 +-
 drivers/media/i2c/s5c73m3/s5c73m3-core.c           |   8 +-
 drivers/media/i2c/s5k5baf.c                        |   4 +-
 drivers/media/i2c/smiapp/smiapp-core.c             |   4 +-
 drivers/media/media-device.c                       | 245 +++++++++--
 drivers/media/media-entity.c                       | 473 +++++++++++++++++----
 drivers/media/pci/bt8xx/dst_ca.c                   |   3 +-
 drivers/media/pci/ddbridge/ddbridge-core.c         |   2 +-
 drivers/media/pci/ngene/ngene-core.c               |   2 +-
 drivers/media/pci/ttpci/av7110.c                   |   2 +-
 drivers/media/pci/ttpci/av7110_av.c                |   4 +-
 drivers/media/pci/ttpci/av7110_ca.c                |   2 +-
 drivers/media/platform/exynos4-is/common.c         |   3 +-
 drivers/media/platform/exynos4-is/fimc-capture.c   |   5 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.c |   9 +-
 drivers/media/platform/exynos4-is/fimc-lite.c      |  18 +-
 drivers/media/platform/exynos4-is/media-dev.c      |  25 +-
 drivers/media/platform/exynos4-is/media-dev.h      |   8 +-
 drivers/media/platform/omap3isp/isp.c              | 202 +++++----
 drivers/media/platform/omap3isp/ispccdc.c          |  39 +-
 drivers/media/platform/omap3isp/ispccdc.h          |   1 +
 drivers/media/platform/omap3isp/ispccp2.c          |  35 +-
 drivers/media/platform/omap3isp/ispccp2.h          |   1 +
 drivers/media/platform/omap3isp/ispcsi2.c          |  33 +-
 drivers/media/platform/omap3isp/ispcsi2.h          |   1 +
 drivers/media/platform/omap3isp/isppreview.c       |  48 ++-
 drivers/media/platform/omap3isp/isppreview.h       |   1 +
 drivers/media/platform/omap3isp/ispresizer.c       |  46 +-
 drivers/media/platform/omap3isp/ispresizer.h       |   1 +
 drivers/media/platform/omap3isp/ispvideo.c         |  17 +-
 drivers/media/platform/s3c-camif/camif-capture.c   |   2 +-
 drivers/media/platform/s3c-camif/camif-core.c      |   4 +-
 drivers/media/platform/vsp1/vsp1_drv.c             |   4 +-
 drivers/media/platform/vsp1/vsp1_rpf.c             |   2 +-
 drivers/media/platform/vsp1/vsp1_video.c           |  15 +-
 drivers/media/platform/vsp1/vsp1_wpf.c             |   2 +-
 drivers/media/platform/xilinx/xilinx-dma.c         |  10 +-
 drivers/media/platform/xilinx/xilinx-vipp.c        |   4 +-
 drivers/media/usb/au0828/au0828-core.c             |  18 +-
 drivers/media/usb/au0828/au0828-video.c            |   8 +-
 drivers/media/usb/cx231xx/cx231xx-cards.c          |   6 +-
 drivers/media/usb/cx231xx/cx231xx-video.c          |   8 +-
 drivers/media/usb/uvc/uvc_entity.c                 |   2 +-
 drivers/media/v4l2-core/v4l2-dev.c                 | 105 ++++-
 drivers/media/v4l2-core/v4l2-device.c              |  10 +-
 drivers/media/v4l2-core/v4l2-subdev.c              |   6 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipe.c   |   9 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipeif.c |  15 +-
 drivers/staging/media/davinci_vpfe/dm365_isif.c    |  15 +-
 drivers/staging/media/davinci_vpfe/dm365_resizer.c |  33 +-
 .../staging/media/davinci_vpfe/vpfe_mc_capture.c   |  10 +-
 drivers/staging/media/davinci_vpfe/vpfe_video.c    |  17 +-
 drivers/staging/media/omap4iss/iss.c               |  32 +-
 drivers/staging/media/omap4iss/iss_csi2.c          |  13 +-
 drivers/staging/media/omap4iss/iss_ipipe.c         |   9 +-
 drivers/staging/media/omap4iss/iss_ipipeif.c       |  15 +-
 drivers/staging/media/omap4iss/iss_resizer.c       |  13 +-
 drivers/staging/media/omap4iss/iss_video.c         |   9 +-
 include/media/media-device.h                       |  34 +-
 include/media/media-entity.h                       | 305 +++++++++++--
 include/media/v4l2-dev.h                           |   1 +
 include/uapi/linux/media.h                         | 205 ++++++++-
 70 files changed, 1924 insertions(+), 627 deletions(-)

-- 
2.4.3


^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH v8 00/55] MC next generation patches
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: devel, Lars-Peter Clausen, Sylwester Nawrocki,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, linux-sh, Shuah Khan,
	Mauro Carvalho Chehab, Hans Verkuil, Javier Martinez Canillas,
	linux-samsung-soc, Laurent Pinchart, Sakari Ailus, linux-api,
	linux-arm-kernel

That's the 8th version of the MC next generation patches.

Differences from version 7:

- Patches reworked to make the reviewers happy;
- Bug fixes;
- ALSA changes got their own separate patches;
- Javier patches got integrated into this series;
- media-entity.h structs are now properly documented;
- Tested on both au0828 and omap3isp.

Due to the complexity of this change, other platform drivers may
require some fixes. 

As the patch series sent before, this is not meant to be sent
upstream yet. Its goal is to merge it for Kernel 4.4, in order to
give people enough time to review and fix pending issues.

Regards,
Mauro

Javier Martinez Canillas (6):
  [media] staging: omap4iss: get entity ID using media_entity_id()
  [media] omap3isp: get entity ID using media_entity_id()
  [media] media: use entity.graph_obj.mdev instead of .parent
  [media] media: remove media entity .parent field
  [media] omap3isp: separate links creation from entities init
  [media] omap3isp: create links after all subdevs have been bound

Mauro Carvalho Chehab (49):
  [media] media: create a macro to get entity ID
  [media] media: add a common struct to be embed on media graph objects
  [media] media: use media_gobj inside entities
  [media] media: use media_gobj inside pads
  [media] media: use media_gobj inside links
  [media] media: add messages when media device gets (un)registered
  [media] media: add a debug message to warn about gobj creation/removal
  [media] media: rename the function that create pad links
  [media] uapi/media.h: Declare interface types for V4L2 and DVB
  [media] media: add functions to allow creating interfaces
  [media] uapi/media.h: Declare interface types for ALSA
  [media] media: Don't accept early-created links
  [media] media: convert links from array to list
  [media] media: make add link more generic
  [media] media: make media_link more generic to handle interace links
  [media] media: make link debug printk more generic
  [media] media: add support to link interfaces and entities
  [media] media-entity: add a helper function to create interface
  [media] dvbdev: add support for interfaces
  [media] media: add a linked list to track interfaces by mdev
  [media] dvbdev: add support for indirect interface links
  [media] uapi/media.h: Fix entity namespace
  [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_V4L
  [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_DVB
  [media] media: add macros to check if subdev or V4L2 DMA
  [media] media: use macros to check for V4L2 subdev entities
  [media] omap3/omap4/davinci: get rid of MEDIA_ENT_T_V4L2_SUBDEV abuse
  [media] s5c73m3: fix subdev type
  [media] s5k5baf: fix subdev type
  [media] davinci_vbpe: stop MEDIA_ENT_T_V4L2_SUBDEV abuse
  [media] omap4iss: stop MEDIA_ENT_T_V4L2_SUBDEV abuse
  [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs
  [media] media controller: get rid of entity subtype on Kernel
  [media] media.h: don't use legacy entity macros at Kernel
  [media] DocBook: update descriptions for the media controller entities
  [media] dvb: modify core to implement interfaces/entities at MC new
    gen
  [media] media: report if a pad is sink or source at debug msg
  [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
  [media] media: Use a macro to interate between all interfaces
  [media] media: move mdev list init to gobj
  [media] media-device: add pads and links to media_device
  [media] media_device: add a topology version field
  [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  [media] media-entity: unregister entity links
  [media] remove interface links at media_entity_unregister()
  [media] media-device: remove interfaces and interface links
  [media] v4l2-core: create MC interfaces for devnodes
  [media] au0828: unregister MC at the end
  [media] media-entity.h: document all the structs

 .../DocBook/media/v4l/media-ioc-enum-entities.xml  |  57 +--
 Documentation/media-framework.txt                  |   2 +-
 drivers/media/dvb-core/dmxdev.c                    |   4 +-
 drivers/media/dvb-core/dvb_ca_en50221.c            |   2 +-
 drivers/media/dvb-core/dvb_frontend.c              |  11 +-
 drivers/media/dvb-core/dvb_net.c                   |   2 +-
 drivers/media/dvb-core/dvbdev.c                    | 278 +++++++++---
 drivers/media/dvb-core/dvbdev.h                    |  10 +-
 drivers/media/firewire/firedtv-ci.c                |   2 +-
 drivers/media/i2c/s5c73m3/s5c73m3-core.c           |   8 +-
 drivers/media/i2c/s5k5baf.c                        |   4 +-
 drivers/media/i2c/smiapp/smiapp-core.c             |   4 +-
 drivers/media/media-device.c                       | 245 +++++++++--
 drivers/media/media-entity.c                       | 473 +++++++++++++++++----
 drivers/media/pci/bt8xx/dst_ca.c                   |   3 +-
 drivers/media/pci/ddbridge/ddbridge-core.c         |   2 +-
 drivers/media/pci/ngene/ngene-core.c               |   2 +-
 drivers/media/pci/ttpci/av7110.c                   |   2 +-
 drivers/media/pci/ttpci/av7110_av.c                |   4 +-
 drivers/media/pci/ttpci/av7110_ca.c                |   2 +-
 drivers/media/platform/exynos4-is/common.c         |   3 +-
 drivers/media/platform/exynos4-is/fimc-capture.c   |   5 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.c |   9 +-
 drivers/media/platform/exynos4-is/fimc-lite.c      |  18 +-
 drivers/media/platform/exynos4-is/media-dev.c      |  25 +-
 drivers/media/platform/exynos4-is/media-dev.h      |   8 +-
 drivers/media/platform/omap3isp/isp.c              | 202 +++++----
 drivers/media/platform/omap3isp/ispccdc.c          |  39 +-
 drivers/media/platform/omap3isp/ispccdc.h          |   1 +
 drivers/media/platform/omap3isp/ispccp2.c          |  35 +-
 drivers/media/platform/omap3isp/ispccp2.h          |   1 +
 drivers/media/platform/omap3isp/ispcsi2.c          |  33 +-
 drivers/media/platform/omap3isp/ispcsi2.h          |   1 +
 drivers/media/platform/omap3isp/isppreview.c       |  48 ++-
 drivers/media/platform/omap3isp/isppreview.h       |   1 +
 drivers/media/platform/omap3isp/ispresizer.c       |  46 +-
 drivers/media/platform/omap3isp/ispresizer.h       |   1 +
 drivers/media/platform/omap3isp/ispvideo.c         |  17 +-
 drivers/media/platform/s3c-camif/camif-capture.c   |   2 +-
 drivers/media/platform/s3c-camif/camif-core.c      |   4 +-
 drivers/media/platform/vsp1/vsp1_drv.c             |   4 +-
 drivers/media/platform/vsp1/vsp1_rpf.c             |   2 +-
 drivers/media/platform/vsp1/vsp1_video.c           |  15 +-
 drivers/media/platform/vsp1/vsp1_wpf.c             |   2 +-
 drivers/media/platform/xilinx/xilinx-dma.c         |  10 +-
 drivers/media/platform/xilinx/xilinx-vipp.c        |   4 +-
 drivers/media/usb/au0828/au0828-core.c             |  18 +-
 drivers/media/usb/au0828/au0828-video.c            |   8 +-
 drivers/media/usb/cx231xx/cx231xx-cards.c          |   6 +-
 drivers/media/usb/cx231xx/cx231xx-video.c          |   8 +-
 drivers/media/usb/uvc/uvc_entity.c                 |   2 +-
 drivers/media/v4l2-core/v4l2-dev.c                 | 105 ++++-
 drivers/media/v4l2-core/v4l2-device.c              |  10 +-
 drivers/media/v4l2-core/v4l2-subdev.c              |   6 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipe.c   |   9 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipeif.c |  15 +-
 drivers/staging/media/davinci_vpfe/dm365_isif.c    |  15 +-
 drivers/staging/media/davinci_vpfe/dm365_resizer.c |  33 +-
 .../staging/media/davinci_vpfe/vpfe_mc_capture.c   |  10 +-
 drivers/staging/media/davinci_vpfe/vpfe_video.c    |  17 +-
 drivers/staging/media/omap4iss/iss.c               |  32 +-
 drivers/staging/media/omap4iss/iss_csi2.c          |  13 +-
 drivers/staging/media/omap4iss/iss_ipipe.c         |   9 +-
 drivers/staging/media/omap4iss/iss_ipipeif.c       |  15 +-
 drivers/staging/media/omap4iss/iss_resizer.c       |  13 +-
 drivers/staging/media/omap4iss/iss_video.c         |   9 +-
 include/media/media-device.h                       |  34 +-
 include/media/media-entity.h                       | 305 +++++++++++--
 include/media/v4l2-dev.h                           |   1 +
 include/uapi/linux/media.h                         | 205 ++++++++-
 70 files changed, 1924 insertions(+), 627 deletions(-)

-- 
2.4.3

^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH v8 00/55] MC next generation patches
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: linux-arm-kernel

That's the 8th version of the MC next generation patches.

Differences from version 7:

- Patches reworked to make the reviewers happy;
- Bug fixes;
- ALSA changes got their own separate patches;
- Javier patches got integrated into this series;
- media-entity.h structs are now properly documented;
- Tested on both au0828 and omap3isp.

Due to the complexity of this change, other platform drivers may
require some fixes. 

As the patch series sent before, this is not meant to be sent
upstream yet. Its goal is to merge it for Kernel 4.4, in order to
give people enough time to review and fix pending issues.

Regards,
Mauro

Javier Martinez Canillas (6):
  [media] staging: omap4iss: get entity ID using media_entity_id()
  [media] omap3isp: get entity ID using media_entity_id()
  [media] media: use entity.graph_obj.mdev instead of .parent
  [media] media: remove media entity .parent field
  [media] omap3isp: separate links creation from entities init
  [media] omap3isp: create links after all subdevs have been bound

Mauro Carvalho Chehab (49):
  [media] media: create a macro to get entity ID
  [media] media: add a common struct to be embed on media graph objects
  [media] media: use media_gobj inside entities
  [media] media: use media_gobj inside pads
  [media] media: use media_gobj inside links
  [media] media: add messages when media device gets (un)registered
  [media] media: add a debug message to warn about gobj creation/removal
  [media] media: rename the function that create pad links
  [media] uapi/media.h: Declare interface types for V4L2 and DVB
  [media] media: add functions to allow creating interfaces
  [media] uapi/media.h: Declare interface types for ALSA
  [media] media: Don't accept early-created links
  [media] media: convert links from array to list
  [media] media: make add link more generic
  [media] media: make media_link more generic to handle interace links
  [media] media: make link debug printk more generic
  [media] media: add support to link interfaces and entities
  [media] media-entity: add a helper function to create interface
  [media] dvbdev: add support for interfaces
  [media] media: add a linked list to track interfaces by mdev
  [media] dvbdev: add support for indirect interface links
  [media] uapi/media.h: Fix entity namespace
  [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_V4L
  [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_DVB
  [media] media: add macros to check if subdev or V4L2 DMA
  [media] media: use macros to check for V4L2 subdev entities
  [media] omap3/omap4/davinci: get rid of MEDIA_ENT_T_V4L2_SUBDEV abuse
  [media] s5c73m3: fix subdev type
  [media] s5k5baf: fix subdev type
  [media] davinci_vbpe: stop MEDIA_ENT_T_V4L2_SUBDEV abuse
  [media] omap4iss: stop MEDIA_ENT_T_V4L2_SUBDEV abuse
  [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs
  [media] media controller: get rid of entity subtype on Kernel
  [media] media.h: don't use legacy entity macros at Kernel
  [media] DocBook: update descriptions for the media controller entities
  [media] dvb: modify core to implement interfaces/entities at MC new
    gen
  [media] media: report if a pad is sink or source at debug msg
  [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
  [media] media: Use a macro to interate between all interfaces
  [media] media: move mdev list init to gobj
  [media] media-device: add pads and links to media_device
  [media] media_device: add a topology version field
  [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  [media] media-entity: unregister entity links
  [media] remove interface links at media_entity_unregister()
  [media] media-device: remove interfaces and interface links
  [media] v4l2-core: create MC interfaces for devnodes
  [media] au0828: unregister MC at the end
  [media] media-entity.h: document all the structs

 .../DocBook/media/v4l/media-ioc-enum-entities.xml  |  57 +--
 Documentation/media-framework.txt                  |   2 +-
 drivers/media/dvb-core/dmxdev.c                    |   4 +-
 drivers/media/dvb-core/dvb_ca_en50221.c            |   2 +-
 drivers/media/dvb-core/dvb_frontend.c              |  11 +-
 drivers/media/dvb-core/dvb_net.c                   |   2 +-
 drivers/media/dvb-core/dvbdev.c                    | 278 +++++++++---
 drivers/media/dvb-core/dvbdev.h                    |  10 +-
 drivers/media/firewire/firedtv-ci.c                |   2 +-
 drivers/media/i2c/s5c73m3/s5c73m3-core.c           |   8 +-
 drivers/media/i2c/s5k5baf.c                        |   4 +-
 drivers/media/i2c/smiapp/smiapp-core.c             |   4 +-
 drivers/media/media-device.c                       | 245 +++++++++--
 drivers/media/media-entity.c                       | 473 +++++++++++++++++----
 drivers/media/pci/bt8xx/dst_ca.c                   |   3 +-
 drivers/media/pci/ddbridge/ddbridge-core.c         |   2 +-
 drivers/media/pci/ngene/ngene-core.c               |   2 +-
 drivers/media/pci/ttpci/av7110.c                   |   2 +-
 drivers/media/pci/ttpci/av7110_av.c                |   4 +-
 drivers/media/pci/ttpci/av7110_ca.c                |   2 +-
 drivers/media/platform/exynos4-is/common.c         |   3 +-
 drivers/media/platform/exynos4-is/fimc-capture.c   |   5 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.c |   9 +-
 drivers/media/platform/exynos4-is/fimc-lite.c      |  18 +-
 drivers/media/platform/exynos4-is/media-dev.c      |  25 +-
 drivers/media/platform/exynos4-is/media-dev.h      |   8 +-
 drivers/media/platform/omap3isp/isp.c              | 202 +++++----
 drivers/media/platform/omap3isp/ispccdc.c          |  39 +-
 drivers/media/platform/omap3isp/ispccdc.h          |   1 +
 drivers/media/platform/omap3isp/ispccp2.c          |  35 +-
 drivers/media/platform/omap3isp/ispccp2.h          |   1 +
 drivers/media/platform/omap3isp/ispcsi2.c          |  33 +-
 drivers/media/platform/omap3isp/ispcsi2.h          |   1 +
 drivers/media/platform/omap3isp/isppreview.c       |  48 ++-
 drivers/media/platform/omap3isp/isppreview.h       |   1 +
 drivers/media/platform/omap3isp/ispresizer.c       |  46 +-
 drivers/media/platform/omap3isp/ispresizer.h       |   1 +
 drivers/media/platform/omap3isp/ispvideo.c         |  17 +-
 drivers/media/platform/s3c-camif/camif-capture.c   |   2 +-
 drivers/media/platform/s3c-camif/camif-core.c      |   4 +-
 drivers/media/platform/vsp1/vsp1_drv.c             |   4 +-
 drivers/media/platform/vsp1/vsp1_rpf.c             |   2 +-
 drivers/media/platform/vsp1/vsp1_video.c           |  15 +-
 drivers/media/platform/vsp1/vsp1_wpf.c             |   2 +-
 drivers/media/platform/xilinx/xilinx-dma.c         |  10 +-
 drivers/media/platform/xilinx/xilinx-vipp.c        |   4 +-
 drivers/media/usb/au0828/au0828-core.c             |  18 +-
 drivers/media/usb/au0828/au0828-video.c            |   8 +-
 drivers/media/usb/cx231xx/cx231xx-cards.c          |   6 +-
 drivers/media/usb/cx231xx/cx231xx-video.c          |   8 +-
 drivers/media/usb/uvc/uvc_entity.c                 |   2 +-
 drivers/media/v4l2-core/v4l2-dev.c                 | 105 ++++-
 drivers/media/v4l2-core/v4l2-device.c              |  10 +-
 drivers/media/v4l2-core/v4l2-subdev.c              |   6 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipe.c   |   9 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipeif.c |  15 +-
 drivers/staging/media/davinci_vpfe/dm365_isif.c    |  15 +-
 drivers/staging/media/davinci_vpfe/dm365_resizer.c |  33 +-
 .../staging/media/davinci_vpfe/vpfe_mc_capture.c   |  10 +-
 drivers/staging/media/davinci_vpfe/vpfe_video.c    |  17 +-
 drivers/staging/media/omap4iss/iss.c               |  32 +-
 drivers/staging/media/omap4iss/iss_csi2.c          |  13 +-
 drivers/staging/media/omap4iss/iss_ipipe.c         |   9 +-
 drivers/staging/media/omap4iss/iss_ipipeif.c       |  15 +-
 drivers/staging/media/omap4iss/iss_resizer.c       |  13 +-
 drivers/staging/media/omap4iss/iss_video.c         |   9 +-
 include/media/media-device.h                       |  34 +-
 include/media/media-entity.h                       | 305 +++++++++++--
 include/media/v4l2-dev.h                           |   1 +
 include/uapi/linux/media.h                         | 205 ++++++++-
 70 files changed, 1924 insertions(+), 627 deletions(-)

-- 
2.4.3

^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH v8 01/55] [media] media: create a macro to get entity ID
  2015-08-30  3:06 ` Mauro Carvalho Chehab
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Laurent Pinchart, linux-sh

Instead of accessing directly entity.id, let's create a macro,
as this field will be moved into a common struct later on.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index c55ab5029323..e429605ca2c3 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -77,8 +77,8 @@ static struct media_entity *find_entity(struct media_device *mdev, u32 id)
 	spin_lock(&mdev->lock);
 
 	media_device_for_each_entity(entity, mdev) {
-		if ((entity->id = id && !next) ||
-		    (entity->id > id && next)) {
+		if (((media_entity_id(entity) = id) && !next) ||
+		    ((media_entity_id(entity) > id) && next)) {
 			spin_unlock(&mdev->lock);
 			return entity;
 		}
@@ -104,7 +104,7 @@ static long media_device_enum_entities(struct media_device *mdev,
 	if (ent = NULL)
 		return -EINVAL;
 
-	u_ent.id = ent->id;
+	u_ent.id = media_entity_id(ent);
 	if (ent->name)
 		strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
 	u_ent.type = ent->type;
@@ -122,7 +122,7 @@ static long media_device_enum_entities(struct media_device *mdev,
 static void media_device_kpad_to_upad(const struct media_pad *kpad,
 				      struct media_pad_desc *upad)
 {
-	upad->entity = kpad->entity->id;
+	upad->entity = media_entity_id(kpad->entity);
 	upad->index = kpad->index;
 	upad->flags = kpad->flags;
 }
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 949e5f92cbdc..cb0ac4e0dfa5 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -140,10 +140,10 @@ void media_entity_graph_walk_start(struct media_entity_graph *graph,
 	graph->stack[graph->top].entity = NULL;
 	bitmap_zero(graph->entities, MEDIA_ENTITY_ENUM_MAX_ID);
 
-	if (WARN_ON(entity->id >= MEDIA_ENTITY_ENUM_MAX_ID))
+	if (WARN_ON(media_entity_id(entity) >= MEDIA_ENTITY_ENUM_MAX_ID))
 		return;
 
-	__set_bit(entity->id, graph->entities);
+	__set_bit(media_entity_id(entity), graph->entities);
 	stack_push(graph, entity);
 }
 EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
@@ -184,11 +184,11 @@ media_entity_graph_walk_next(struct media_entity_graph *graph)
 
 		/* Get the entity in the other end of the link . */
 		next = media_entity_other(entity, link);
-		if (WARN_ON(next->id >= MEDIA_ENTITY_ENUM_MAX_ID))
+		if (WARN_ON(media_entity_id(next) >= MEDIA_ENTITY_ENUM_MAX_ID))
 			return NULL;
 
 		/* Has the entity already been visited? */
-		if (__test_and_set_bit(next->id, graph->entities)) {
+		if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
 			link_top(graph)++;
 			continue;
 		}
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index 17f08973f835..debe4e539df6 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -352,10 +352,10 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
 			break;
 
 		/* Ensure the branch has no loop. */
-		if (entities & (1 << entity->subdev.entity.id))
+		if (entities & (1 << media_entity_id(&entity->subdev.entity)))
 			return -EPIPE;
 
-		entities |= 1 << entity->subdev.entity.id;
+		entities |= 1 << media_entity_id(&entity->subdev.entity);
 
 		/* UDS can't be chained. */
 		if (entity->type = VSP1_ENTITY_UDS) {
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 8b21a4d920d9..0a66fc225559 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -113,6 +113,11 @@ static inline u32 media_entity_subtype(struct media_entity *entity)
 	return entity->type & MEDIA_ENT_SUBTYPE_MASK;
 }
 
+static inline u32 media_entity_id(struct media_entity *entity)
+{
+	return entity->id;
+}
+
 #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
 #define MEDIA_ENTITY_ENUM_MAX_ID	64
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 01/55] [media] media: create a macro to get entity ID
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Laurent Pinchart, linux-sh

Instead of accessing directly entity.id, let's create a macro,
as this field will be moved into a common struct later on.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index c55ab5029323..e429605ca2c3 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -77,8 +77,8 @@ static struct media_entity *find_entity(struct media_device *mdev, u32 id)
 	spin_lock(&mdev->lock);
 
 	media_device_for_each_entity(entity, mdev) {
-		if ((entity->id == id && !next) ||
-		    (entity->id > id && next)) {
+		if (((media_entity_id(entity) == id) && !next) ||
+		    ((media_entity_id(entity) > id) && next)) {
 			spin_unlock(&mdev->lock);
 			return entity;
 		}
@@ -104,7 +104,7 @@ static long media_device_enum_entities(struct media_device *mdev,
 	if (ent == NULL)
 		return -EINVAL;
 
-	u_ent.id = ent->id;
+	u_ent.id = media_entity_id(ent);
 	if (ent->name)
 		strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
 	u_ent.type = ent->type;
@@ -122,7 +122,7 @@ static long media_device_enum_entities(struct media_device *mdev,
 static void media_device_kpad_to_upad(const struct media_pad *kpad,
 				      struct media_pad_desc *upad)
 {
-	upad->entity = kpad->entity->id;
+	upad->entity = media_entity_id(kpad->entity);
 	upad->index = kpad->index;
 	upad->flags = kpad->flags;
 }
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 949e5f92cbdc..cb0ac4e0dfa5 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -140,10 +140,10 @@ void media_entity_graph_walk_start(struct media_entity_graph *graph,
 	graph->stack[graph->top].entity = NULL;
 	bitmap_zero(graph->entities, MEDIA_ENTITY_ENUM_MAX_ID);
 
-	if (WARN_ON(entity->id >= MEDIA_ENTITY_ENUM_MAX_ID))
+	if (WARN_ON(media_entity_id(entity) >= MEDIA_ENTITY_ENUM_MAX_ID))
 		return;
 
-	__set_bit(entity->id, graph->entities);
+	__set_bit(media_entity_id(entity), graph->entities);
 	stack_push(graph, entity);
 }
 EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
@@ -184,11 +184,11 @@ media_entity_graph_walk_next(struct media_entity_graph *graph)
 
 		/* Get the entity in the other end of the link . */
 		next = media_entity_other(entity, link);
-		if (WARN_ON(next->id >= MEDIA_ENTITY_ENUM_MAX_ID))
+		if (WARN_ON(media_entity_id(next) >= MEDIA_ENTITY_ENUM_MAX_ID))
 			return NULL;
 
 		/* Has the entity already been visited? */
-		if (__test_and_set_bit(next->id, graph->entities)) {
+		if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
 			link_top(graph)++;
 			continue;
 		}
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index 17f08973f835..debe4e539df6 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -352,10 +352,10 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
 			break;
 
 		/* Ensure the branch has no loop. */
-		if (entities & (1 << entity->subdev.entity.id))
+		if (entities & (1 << media_entity_id(&entity->subdev.entity)))
 			return -EPIPE;
 
-		entities |= 1 << entity->subdev.entity.id;
+		entities |= 1 << media_entity_id(&entity->subdev.entity);
 
 		/* UDS can't be chained. */
 		if (entity->type == VSP1_ENTITY_UDS) {
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 8b21a4d920d9..0a66fc225559 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -113,6 +113,11 @@ static inline u32 media_entity_subtype(struct media_entity *entity)
 	return entity->type & MEDIA_ENT_SUBTYPE_MASK;
 }
 
+static inline u32 media_entity_id(struct media_entity *entity)
+{
+	return entity->id;
+}
+
 #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
 #define MEDIA_ENTITY_ENUM_MAX_ID	64
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 02/55] [media] staging: omap4iss: get entity ID using media_entity_id()
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (3 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-12-06  3:18   ` Laurent Pinchart
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Javier Martinez Canillas, Mauro Carvalho Chehab,
	Laurent Pinchart, Greg Kroah-Hartman, devel,
	Mauro Carvalho Chehab

From: Javier Martinez Canillas <javier@osg.samsung.com>

Assessing media_entity ID should now use media_entity_id() macro to
obtain the entity ID, as a next patch will remove the .id field from
struct media_entity .

So, get rid of it, otherwise the omap4iss driver will fail to build.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 9bfb725b9986..e54a7afd31de 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -607,7 +607,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
 			 * crashed. Mark it as such, the ISS will be reset when
 			 * applications will release it.
 			 */
-			iss->crashed |= 1U << subdev->entity.id;
+			iss->crashed |= 1U << media_entity_id(&subdev->entity);
 			failure = -ETIMEDOUT;
 		}
 	}
diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
index bae67742706f..25e9e7a6b99d 100644
--- a/drivers/staging/media/omap4iss/iss_video.c
+++ b/drivers/staging/media/omap4iss/iss_video.c
@@ -784,7 +784,7 @@ iss_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 	entity = &video->video.entity;
 	media_entity_graph_walk_start(&graph, entity);
 	while ((entity = media_entity_graph_walk_next(&graph)))
-		pipe->entities |= 1 << entity->id;
+		pipe->entities |= 1 << media_entity_id(entity);
 
 	/* Verify that the currently configured format matches the output of
 	 * the connected subdev.
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 03/55] [media] omap3isp: get entity ID using media_entity_id()
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (4 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 10:10   ` Hans Verkuil
  2015-12-06  3:16   ` Laurent Pinchart
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Javier Martinez Canillas, Mauro Carvalho Chehab,
	Laurent Pinchart, Mauro Carvalho Chehab

From: Javier Martinez Canillas <javier@osg.samsung.com>

Assessing media_entity ID should now use media_entity_id() macro to
obtain the entity ID, as a next patch will remove the .id field from
struct media_entity .

So, get rid of it, otherwise the omap3isp driver will fail to build.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 56e683b19a73..e08183f9d0f7 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -975,6 +975,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
 	struct v4l2_subdev *subdev;
 	int failure = 0;
 	int ret;
+	u32 id;
 
 	/*
 	 * We need to stop all the modules after CCDC first or they'll
@@ -1027,8 +1028,10 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
 		if (ret) {
 			dev_info(isp->dev, "Unable to stop %s\n", subdev->name);
 			isp->stop_failure = true;
-			if (subdev == &isp->isp_prev.subdev)
-				isp->crashed |= 1U << subdev->entity.id;
+			if (subdev == &isp->isp_prev.subdev) {
+				id = media_entity_id(&subdev->entity);
+				isp->crashed |= 1U << id;
+			}
 			failure = -ETIMEDOUT;
 		}
 	}
diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c
index 3b10304b580b..d96e3be5e252 100644
--- a/drivers/media/platform/omap3isp/ispccdc.c
+++ b/drivers/media/platform/omap3isp/ispccdc.c
@@ -1608,7 +1608,7 @@ static int ccdc_isr_buffer(struct isp_ccdc_device *ccdc)
 	/* Wait for the CCDC to become idle. */
 	if (ccdc_sbl_wait_idle(ccdc, 1000)) {
 		dev_info(isp->dev, "CCDC won't become idle!\n");
-		isp->crashed |= 1U << ccdc->subdev.entity.id;
+		isp->crashed |= 1U << media_entity_id(&ccdc->subdev.entity);
 		omap3isp_pipeline_cancel_stream(pipe);
 		return 0;
 	}
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 3094572f8897..6c89dc40df85 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -235,7 +235,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		struct isp_video *__video;
 
-		pipe->entities |= 1 << entity->id;
+		pipe->entities |= 1 << media_entity_id(entity);
 
 		if (far_end != NULL)
 			continue;
@@ -891,6 +891,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
 	struct v4l2_ext_control ctrl;
 	unsigned int i;
 	int ret;
+	u32 id;
 
 	/* Memory-to-memory pipelines have no external subdev. */
 	if (pipe->input != NULL)
@@ -898,7 +899,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
 
 	for (i = 0; i < ARRAY_SIZE(ents); i++) {
 		/* Is the entity part of the pipeline? */
-		if (!(pipe->entities & (1 << ents[i]->id)))
+		if (!(pipe->entities & (1 << media_entity_id(ents[i]))))
 			continue;
 
 		/* ISP entities have always sink pad == 0. Find source. */
@@ -950,7 +951,8 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
 
 	pipe->external_rate = ctrl.value64;
 
-	if (pipe->entities & (1 << isp->isp_ccdc.subdev.entity.id)) {
+	id = media_entity_id(&isp->isp_ccdc.subdev.entity);
+	if (pipe->entities & (1 << id)) {
 		unsigned int rate = UINT_MAX;
 		/*
 		 * Check that maximum allowed CCDC pixel rate isn't
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 04/55] [media] media: add a common struct to be embed on media graph objects
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (5 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-09-09  7:01   ` Sakari Ailus
  2015-09-10 14:02   ` Javier Martinez Canillas
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Due to the MC API proposed changes, we'll need to have an unique
object ID for all graph objects, and have some shared fields
that will be common on all media graph objects.

Right now, the only common object is the object ID, but other
fields will be added later on.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index cb0ac4e0dfa5..4834172bf6f8 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -27,6 +27,38 @@
 #include <media/media-device.h>
 
 /**
+ *  media_gobj_init - Initialize a graph object
+ *
+ * @mdev:	Pointer to the media_device that contains the object
+ * @type:	Type of the object
+ * @gobj:	Pointer to the object
+ *
+ * This routine initializes the embedded struct media_gobj inside a
+ * media graph object. It is called automatically if media_*_create()
+ * calls are used. However, if the object (entity, link, pad, interface)
+ * is embedded on some other object, this function should be called before
+ * registering the object at the media controller.
+ */
+void media_gobj_init(struct media_device *mdev,
+			   enum media_gobj_type type,
+			   struct media_gobj *gobj)
+{
+	/* For now, nothing to do */
+}
+
+/**
+ *  media_gobj_remove - Stop using a graph object on a media device
+ *
+ * @graph_obj:	Pointer to the object
+ *
+ * This should be called at media_device_unregister_*() routines
+ */
+void media_gobj_remove(struct media_gobj *gobj)
+{
+	/* For now, nothing to do */
+}
+
+/**
  * media_entity_init - Initialize a media entity
  *
  * @num_pads: Total number of sink and source pads.
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 0a66fc225559..b1854239a476 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -28,6 +28,39 @@
 #include <linux/list.h>
 #include <linux/media.h>
 
+/* Enums used internally at the media controller to represent graphs */
+
+/**
+ * enum media_gobj_type - type of a graph object
+ *
+ */
+enum media_gobj_type {
+	 /* FIXME: add the types here, as we embed media_gobj */
+	MEDIA_GRAPH_NONE
+};
+
+#define MEDIA_BITS_PER_TYPE		8
+#define MEDIA_BITS_PER_LOCAL_ID		(32 - MEDIA_BITS_PER_TYPE)
+#define MEDIA_LOCAL_ID_MASK		 GENMASK(MEDIA_BITS_PER_LOCAL_ID - 1, 0)
+
+/* Structs to represent the objects that belong to a media graph */
+
+/**
+ * struct media_gobj - Define a graph object.
+ *
+ * @id:		Non-zero object ID identifier. The ID should be unique
+ *		inside a media_device, as it is composed by
+ *		MEDIA_BITS_PER_TYPE to store the type plus
+ *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
+ *		(called as "local ID").
+ *
+ * All objects on the media graph should have this struct embedded
+ */
+struct media_gobj {
+	u32			id;
+};
+
+
 struct media_pipeline {
 };
 
@@ -118,6 +151,26 @@ static inline u32 media_entity_id(struct media_entity *entity)
 	return entity->id;
 }
 
+static inline enum media_gobj_type media_type(struct media_gobj *gobj)
+{
+	return gobj->id >> MEDIA_BITS_PER_LOCAL_ID;
+}
+
+static inline u32 media_localid(struct media_gobj *gobj)
+{
+	return gobj->id & MEDIA_LOCAL_ID_MASK;
+}
+
+static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
+{
+	u32 id;
+
+	id = type << MEDIA_BITS_PER_LOCAL_ID;
+	id |= local_id & MEDIA_LOCAL_ID_MASK;
+
+	return id;
+}
+
 #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
 #define MEDIA_ENTITY_ENUM_MAX_ID	64
 
@@ -131,6 +184,14 @@ struct media_entity_graph {
 	int top;
 };
 
+#define gobj_to_entity(gobj) \
+		container_of(gobj, struct media_entity, graph_obj)
+
+void media_gobj_init(struct media_device *mdev,
+		    enum media_gobj_type type,
+		    struct media_gobj *gobj);
+void media_gobj_remove(struct media_gobj *gobj);
+
 int media_entity_init(struct media_entity *entity, u16 num_pads,
 		struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 05/55] [media] media: use media_gobj inside entities
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (6 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-09-10 14:04   ` Javier Martinez Canillas
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

As entities are graph objects, let's embed media_gobj
on it. That ensures an unique ID for entities that can be
global along the entire media controller.

For now, we'll keep the already existing entity ID. Such
field need to be dropped at some point, but for now, let's
not do this, to avoid needing to review all drivers and
the userspace apps.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index e429605ca2c3..81d6a130efef 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -379,7 +379,6 @@ int __must_check __media_device_register(struct media_device *mdev,
 	if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0))
 		return -EINVAL;
 
-	mdev->entity_id = 1;
 	INIT_LIST_HEAD(&mdev->entities);
 	spin_lock_init(&mdev->lock);
 	mutex_init(&mdev->graph_mutex);
@@ -433,10 +432,8 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	entity->parent = mdev;
 
 	spin_lock(&mdev->lock);
-	if (entity->id == 0)
-		entity->id = mdev->entity_id++;
-	else
-		mdev->entity_id = max(entity->id + 1, mdev->entity_id);
+	/* Initialize media_gobj embedded at the entity */
+	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
 	list_add_tail(&entity->list, &mdev->entities);
 	spin_unlock(&mdev->lock);
 
@@ -459,6 +456,7 @@ void media_device_unregister_entity(struct media_entity *entity)
 		return;
 
 	spin_lock(&mdev->lock);
+	media_gobj_remove(&entity->graph_obj);
 	list_del(&entity->list);
 	spin_unlock(&mdev->lock);
 	entity->parent = NULL;
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 4834172bf6f8..888cb88e19bf 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -43,7 +43,12 @@ void media_gobj_init(struct media_device *mdev,
 			   enum media_gobj_type type,
 			   struct media_gobj *gobj)
 {
-	/* For now, nothing to do */
+	/* Create a per-type unique object ID */
+	switch (type) {
+	case MEDIA_GRAPH_ENTITY:
+		gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
+		break;
+	}
 }
 
 /**
diff --git a/include/media/media-device.h b/include/media/media-device.h
index a44f18fdf321..f6deef6e5820 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -41,7 +41,7 @@ struct device;
  * @bus_info:	Unique and stable device location identifier
  * @hw_revision: Hardware device revision
  * @driver_version: Device driver version
- * @entity_id:	ID of the next entity to be registered
+ * @entity_id:	Unique ID used on the last entity registered
  * @entities:	List of registered entities
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
@@ -69,6 +69,7 @@ struct media_device {
 	u32 driver_version;
 
 	u32 entity_id;
+
 	struct list_head entities;
 
 	/* Protects the entities list */
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index b1854239a476..bb74b5883cbb 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -33,10 +33,10 @@
 /**
  * enum media_gobj_type - type of a graph object
  *
+ * @MEDIA_GRAPH_ENTITY:		Identify a media entity
  */
 enum media_gobj_type {
-	 /* FIXME: add the types here, as we embed media_gobj */
-	MEDIA_GRAPH_NONE
+	MEDIA_GRAPH_ENTITY,
 };
 
 #define MEDIA_BITS_PER_TYPE		8
@@ -94,10 +94,9 @@ struct media_entity_operations {
 };
 
 struct media_entity {
+	struct media_gobj graph_obj;
 	struct list_head list;
 	struct media_device *parent;	/* Media device this entity belongs to*/
-	u32 id;				/* Entity ID, unique in the parent media
-					 * device context */
 	const char *name;		/* Entity name */
 	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
 	u32 revision;			/* Entity revision, driver specific */
@@ -148,7 +147,7 @@ static inline u32 media_entity_subtype(struct media_entity *entity)
 
 static inline u32 media_entity_id(struct media_entity *entity)
 {
-	return entity->id;
+	return entity->graph_obj.id;
 }
 
 static inline enum media_gobj_type media_type(struct media_gobj *gobj)
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 06/55] [media] media: use media_gobj inside pads
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (7 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-09-09  7:37   ` Sakari Ailus
  2015-09-10 14:09   ` Javier Martinez Canillas
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

PADs also need unique object IDs that won't conflict with
the entity object IDs.

The pad objects are currently created via media_entity_init()
and, once created, never change.

While this will likely change in the future in order to
support dynamic changes, for now we'll keep PADs as arrays
and initialize the media_gobj embedded structs when
registering the entity.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 81d6a130efef..3bdda16584fe 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -427,6 +427,8 @@ EXPORT_SYMBOL_GPL(media_device_unregister);
 int __must_check media_device_register_entity(struct media_device *mdev,
 					      struct media_entity *entity)
 {
+	int i;
+
 	/* Warn if we apparently re-register an entity */
 	WARN_ON(entity->parent != NULL);
 	entity->parent = mdev;
@@ -435,6 +437,12 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	/* Initialize media_gobj embedded at the entity */
 	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
 	list_add_tail(&entity->list, &mdev->entities);
+
+	/* Initialize objects at the pads */
+	for (i = 0; i < entity->num_pads; i++)
+		media_gobj_init(mdev, MEDIA_GRAPH_PAD,
+			       &entity->pads[i].graph_obj);
+
 	spin_unlock(&mdev->lock);
 
 	return 0;
@@ -450,12 +458,15 @@ EXPORT_SYMBOL_GPL(media_device_register_entity);
  */
 void media_device_unregister_entity(struct media_entity *entity)
 {
+	int i;
 	struct media_device *mdev = entity->parent;
 
 	if (mdev == NULL)
 		return;
 
 	spin_lock(&mdev->lock);
+	for (i = 0; i < entity->num_pads; i++)
+		media_gobj_remove(&entity->pads[i].graph_obj);
 	media_gobj_remove(&entity->graph_obj);
 	list_del(&entity->list);
 	spin_unlock(&mdev->lock);
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 888cb88e19bf..377c6655c5d0 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -48,6 +48,9 @@ void media_gobj_init(struct media_device *mdev,
 	case MEDIA_GRAPH_ENTITY:
 		gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
 		break;
+	case MEDIA_GRAPH_PAD:
+		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
+		break;
 	}
 }
 
diff --git a/include/media/media-device.h b/include/media/media-device.h
index f6deef6e5820..9493721f630e 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -42,6 +42,7 @@ struct device;
  * @hw_revision: Hardware device revision
  * @driver_version: Device driver version
  * @entity_id:	Unique ID used on the last entity registered
+ * @pad_id:	Unique ID used on the last pad registered
  * @entities:	List of registered entities
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
@@ -69,6 +70,7 @@ struct media_device {
 	u32 driver_version;
 
 	u32 entity_id;
+	u32 pad_id;
 
 	struct list_head entities;
 
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index bb74b5883cbb..ce4c654486d6 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -34,9 +34,11 @@
  * enum media_gobj_type - type of a graph object
  *
  * @MEDIA_GRAPH_ENTITY:		Identify a media entity
+ * @MEDIA_GRAPH_PAD:		Identify a media pad
  */
 enum media_gobj_type {
 	MEDIA_GRAPH_ENTITY,
+	MEDIA_GRAPH_PAD,
 };
 
 #define MEDIA_BITS_PER_TYPE		8
@@ -72,6 +74,7 @@ struct media_link {
 };
 
 struct media_pad {
+	struct media_gobj graph_obj;
 	struct media_entity *entity;	/* Entity this pad belongs to */
 	u16 index;			/* Pad index in the entity pads array */
 	unsigned long flags;		/* Pad flags (MEDIA_PAD_FL_*) */
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 07/55] [media] media: use media_gobj inside links
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (8 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-09-10 14:10   ` Javier Martinez Canillas
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Just like entities and pads, links also need to have unique
Object IDs along a given media controller.

So, let's add a media_gobj inside it and initialize
the object then a new link is created.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 3bdda16584fe..065f6f08da37 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -438,6 +438,13 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
 	list_add_tail(&entity->list, &mdev->entities);
 
+	/*
+	 * Initialize objects at the links
+	 * in the case where links got created before entity register
+	 */
+	for (i = 0; i < entity->num_links; i++)
+		media_gobj_init(mdev, MEDIA_GRAPH_LINK,
+				&entity->links[i].graph_obj);
 	/* Initialize objects at the pads */
 	for (i = 0; i < entity->num_pads; i++)
 		media_gobj_init(mdev, MEDIA_GRAPH_PAD,
@@ -465,6 +472,8 @@ void media_device_unregister_entity(struct media_entity *entity)
 		return;
 
 	spin_lock(&mdev->lock);
+	for (i = 0; i < entity->num_links; i++)
+		media_gobj_remove(&entity->links[i].graph_obj);
 	for (i = 0; i < entity->num_pads; i++)
 		media_gobj_remove(&entity->pads[i].graph_obj);
 	media_gobj_remove(&entity->graph_obj);
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 377c6655c5d0..36d725ec5f3d 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -51,6 +51,9 @@ void media_gobj_init(struct media_device *mdev,
 	case MEDIA_GRAPH_PAD:
 		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
 		break;
+	case MEDIA_GRAPH_LINK:
+		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
+		break;
 	}
 }
 
@@ -491,6 +494,9 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
 	link->sink = &sink->pads[sink_pad];
 	link->flags = flags;
 
+	/* Initialize graph object embedded at the new link */
+	media_gobj_init(source->parent, MEDIA_GRAPH_LINK, &link->graph_obj);
+
 	/* Create the backlink. Backlinks are used to help graph traversal and
 	 * are not reported to userspace.
 	 */
@@ -504,6 +510,9 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
 	backlink->sink = &sink->pads[sink_pad];
 	backlink->flags = flags;
 
+	/* Initialize graph object embedded at the new link */
+	media_gobj_init(sink->parent, MEDIA_GRAPH_LINK, &backlink->graph_obj);
+
 	link->reverse = backlink;
 	backlink->reverse = link;
 
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 9493721f630e..05414e351f8e 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -43,6 +43,7 @@ struct device;
  * @driver_version: Device driver version
  * @entity_id:	Unique ID used on the last entity registered
  * @pad_id:	Unique ID used on the last pad registered
+ * @link_id:	Unique ID used on the last link registered
  * @entities:	List of registered entities
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
@@ -71,6 +72,7 @@ struct media_device {
 
 	u32 entity_id;
 	u32 pad_id;
+	u32 link_id;
 
 	struct list_head entities;
 
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index ce4c654486d6..cd08a96bfbaa 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -35,10 +35,12 @@
  *
  * @MEDIA_GRAPH_ENTITY:		Identify a media entity
  * @MEDIA_GRAPH_PAD:		Identify a media pad
+ * @MEDIA_GRAPH_LINK:		Identify a media link
  */
 enum media_gobj_type {
 	MEDIA_GRAPH_ENTITY,
 	MEDIA_GRAPH_PAD,
+	MEDIA_GRAPH_LINK,
 };
 
 #define MEDIA_BITS_PER_TYPE		8
@@ -67,6 +69,7 @@ struct media_pipeline {
 };
 
 struct media_link {
+	struct media_gobj graph_obj;
 	struct media_pad *source;	/* Source pad */
 	struct media_pad *sink;		/* Sink pad  */
 	struct media_link *reverse;	/* Link in the reverse direction */
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 08/55] [media] media: add messages when media device gets (un)registered
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (9 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-09-10 14:12   ` Javier Martinez Canillas
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

We can only free the media device after being sure that no
graph object is used.

In order to help tracking it, let's add debug messages
that will print when the media controller gets registered
or unregistered.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 065f6f08da37..0f3844470147 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -359,6 +359,7 @@ static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
 
 static void media_device_release(struct media_devnode *mdev)
 {
+	dev_dbg(mdev->parent, "Media device released\n");
 }
 
 /**
@@ -397,6 +398,8 @@ int __must_check __media_device_register(struct media_device *mdev,
 		return ret;
 	}
 
+	dev_dbg(mdev->dev, "Media device registered\n");
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(__media_device_register);
@@ -416,6 +419,8 @@ void media_device_unregister(struct media_device *mdev)
 
 	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
 	media_devnode_unregister(&mdev->devnode);
+
+	dev_dbg(mdev->dev, "Media device unregistered\n");
 }
 EXPORT_SYMBOL_GPL(media_device_unregister);
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 09/55] [media] media: add a debug message to warn about gobj creation/removal
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (10 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-09-10 14:14   ` Javier Martinez Canillas
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

It helps to check if the media controller is doing the
right thing with the object creation and removal.

No extra code/data will be produced if DEBUG or
CONFIG_DYNAMIC_DEBUG is not enabled.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 36d725ec5f3d..6d515e149d7f 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -27,6 +27,69 @@
 #include <media/media-device.h>
 
 /**
+ *  dev_dbg_obj - Prints in debug mode a change on some object
+ *
+ * @event_name:	Name of the event to report. Could be __func__
+ * @gobj:	Pointer to the object
+ *
+ * Enabled only if DEBUG or CONFIG_DYNAMIC_DEBUG. Otherwise, it
+ * won't produce any code.
+ */
+static inline const char *gobj_type(enum media_gobj_type type)
+{
+	switch (type) {
+	case MEDIA_GRAPH_ENTITY:
+		return "entity";
+	case MEDIA_GRAPH_PAD:
+		return "pad";
+	case MEDIA_GRAPH_LINK:
+		return "link";
+	default:
+		return "unknown";
+	}
+}
+
+static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
+{
+#if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
+	switch (media_type(gobj)) {
+	case MEDIA_GRAPH_ENTITY:
+		dev_dbg(gobj->mdev->dev,
+			"%s: id 0x%08x entity#%d: '%s'\n",
+			event_name, gobj->id, media_localid(gobj),
+			gobj_to_entity(gobj)->name);
+		break;
+	case MEDIA_GRAPH_LINK:
+	{
+		struct media_link *link = gobj_to_link(gobj);
+
+		dev_dbg(gobj->mdev->dev,
+			"%s: id 0x%08x link#%d: '%s' %s#%d ==> '%s' %s#%d\n",
+			event_name, gobj->id, media_localid(gobj),
+
+			link->source->entity->name,
+			gobj_type(media_type(&link->source->graph_obj)),
+			media_localid(&link->source->graph_obj),
+
+			link->sink->entity->name,
+			gobj_type(media_type(&link->sink->graph_obj)),
+			media_localid(&link->sink->graph_obj));
+		break;
+	}
+	case MEDIA_GRAPH_PAD:
+	{
+		struct media_pad *pad = gobj_to_pad(gobj);
+
+		dev_dbg(gobj->mdev->dev,
+			"%s: id 0x%08x pad#%d: '%s':%d\n",
+			event_name, gobj->id, media_localid(gobj),
+			pad->entity->name, pad->index);
+	}
+	}
+#endif
+}
+
+/**
  *  media_gobj_init - Initialize a graph object
  *
  * @mdev:	Pointer to the media_device that contains the object
@@ -43,6 +106,8 @@ void media_gobj_init(struct media_device *mdev,
 			   enum media_gobj_type type,
 			   struct media_gobj *gobj)
 {
+	gobj->mdev = mdev;
+
 	/* Create a per-type unique object ID */
 	switch (type) {
 	case MEDIA_GRAPH_ENTITY:
@@ -55,6 +120,7 @@ void media_gobj_init(struct media_device *mdev,
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
 		break;
 	}
+	dev_dbg_obj(__func__, gobj);
 }
 
 /**
@@ -66,7 +132,7 @@ void media_gobj_init(struct media_device *mdev,
  */
 void media_gobj_remove(struct media_gobj *gobj)
 {
-	/* For now, nothing to do */
+	dev_dbg_obj(__func__, gobj);
 }
 
 /**
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index cd08a96bfbaa..af6646ddf6db 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -61,6 +61,7 @@ enum media_gobj_type {
  * All objects on the media graph should have this struct embedded
  */
 struct media_gobj {
+	struct media_device	*mdev;
 	u32			id;
 };
 
@@ -192,6 +193,12 @@ struct media_entity_graph {
 #define gobj_to_entity(gobj) \
 		container_of(gobj, struct media_entity, graph_obj)
 
+#define gobj_to_pad(gobj) \
+		container_of(gobj, struct media_pad, graph_obj)
+
+#define gobj_to_link(gobj) \
+		container_of(gobj, struct media_link, graph_obj)
+
 void media_gobj_init(struct media_device *mdev,
 		    enum media_gobj_type type,
 		    struct media_gobj *gobj);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 10/55] [media] media: rename the function that create pad links
  2015-08-30  3:06 ` Mauro Carvalho Chehab
  (?)
  (?)
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: linux-arm-kernel

With the new API, a link can be either between two PADs or between an interface
and an entity. So, we need to use a better name for the function that create
links between two pads.

So, rename the such function to media_create_pad_link().

No functional changes.

This patch was created via this shell script:
	for i in $(find drivers/media -name '*.[ch]' -type f) $(find drivers/staging/media -name '*.[ch]' -type f) $(find include/ -name '*.h' -type f) ; do sed s,media_entity_create_link,media_create_pad_link,g <$i >a && mv a $i; done

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/Documentation/media-framework.txt b/Documentation/media-framework.txt
index 6903b2503577..b424de6c3bb3 100644
--- a/Documentation/media-framework.txt
+++ b/Documentation/media-framework.txt
@@ -199,7 +199,7 @@ pre-allocated and grows dynamically as needed.
 
 Drivers create links by calling
 
-	media_entity_create_link(struct media_entity *source, u16 source_pad,
+	media_create_pad_link(struct media_entity *source, u16 source_pad,
 				 struct media_entity *sink,   u16 sink_pad,
 				 u32 flags);
 
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 2fdcbb5f000a..65f59f2124b4 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -412,16 +412,16 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	}
 
 	if (tuner && fe)
-		media_entity_create_link(tuner, 0, fe, 0, 0);
+		media_create_pad_link(tuner, 0, fe, 0, 0);
 
 	if (fe && demux)
-		media_entity_create_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && dvr)
-		media_entity_create_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && ca)
-		media_entity_create_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
 }
 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
 #endif
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 6d167428727d..c81bfbfea32f 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1482,11 +1482,11 @@ static int s5c73m3_oif_registered(struct v4l2_subdev *sd)
 		return ret;
 	}
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_ISP_PAD, &state->oif_sd.entity, OIF_ISP_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_JPEG_PAD, &state->oif_sd.entity, OIF_JPEG_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 30a9ca62e034..d3bff30bcb6f 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -1756,7 +1756,7 @@ static int s5k5baf_registered(struct v4l2_subdev *sd)
 		v4l2_err(sd, "failed to register subdev %s\n",
 			 state->cis_sd.name);
 	else
-		ret = media_entity_create_link(&state->cis_sd.entity, PAD_CIS,
+		ret = media_create_pad_link(&state->cis_sd.entity, PAD_CIS,
 					       &state->sd.entity, PAD_CIS,
 					       MEDIA_LNK_FL_IMMUTABLE |
 					       MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 308613ea0aed..5aa49eb393a9 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2495,7 +2495,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 			return rval;
 		}
 
-		rval = media_entity_create_link(&this->sd.entity,
+		rval = media_create_pad_link(&this->sd.entity,
 						this->source_pad,
 						&last->sd.entity,
 						last->sink_pad,
@@ -2503,7 +2503,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 						MEDIA_LNK_FL_IMMUTABLE);
 		if (rval) {
 			dev_err(&client->dev,
-				"media_entity_create_link failed\n");
+				"media_create_pad_link failed\n");
 			return rval;
 		}
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 6d515e149d7f..35e52cd1fc5a 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -542,7 +542,7 @@ static struct media_link *media_entity_add_link(struct media_entity *entity)
 }
 
 int
-media_entity_create_link(struct media_entity *source, u16 source_pad,
+media_create_pad_link(struct media_entity *source, u16 source_pad,
 			 struct media_entity *sink, u16 sink_pad, u32 flags)
 {
 	struct media_link *link;
@@ -586,7 +586,7 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(media_entity_create_link);
+EXPORT_SYMBOL_GPL(media_create_pad_link);
 
 void __media_entity_remove_links(struct media_entity *entity)
 {
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 4f5586a4cbff..3ba76940eef5 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -729,7 +729,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 		flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0;
 
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					      FIMC_SD_PAD_SINK_CAM, flags);
 		if (ret)
 			return ret;
@@ -749,7 +749,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 			continue;
 
 		sink = &fmd->fimc_lite[i]->subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					       FLITE_SD_PAD_SINK, 0);
 		if (ret)
 			return ret;
@@ -781,13 +781,13 @@ static int __fimc_md_create_flite_source_links(struct fimc_md *fmd)
 		source = &fimc->subdev.entity;
 		sink = &fimc->ve.vdev.entity;
 		/* FIMC-LITE's subdev and video node */
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_DMA,
 					       sink, 0, 0);
 		if (ret)
 			break;
 		/* Link from FIMC-LITE to IS-ISP subdev */
 		sink = &fmd->fimc_is->isp.subdev.entity;
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_ISP,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_ISP,
 					       sink, 0, 0);
 		if (ret)
 			break;
@@ -811,7 +811,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 
 		/* Link from FIMC-IS-ISP subdev to FIMC */
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
+		ret = media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
 					       sink, FIMC_SD_PAD_SINK_FIFO, 0);
 		if (ret)
 			return ret;
@@ -824,7 +824,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 	if (sink->num_pads = 0)
 		return 0;
 
-	return media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
+	return media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
 					sink, 0, 0);
 }
 
@@ -873,7 +873,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 				return -EINVAL;
 
 			pad = sensor->entity.num_pads - 1;
-			ret = media_entity_create_link(&sensor->entity, pad,
+			ret = media_create_pad_link(&sensor->entity, pad,
 					      &csis->entity, CSIS_PAD_SINK,
 					      MEDIA_LNK_FL_IMMUTABLE |
 					      MEDIA_LNK_FL_ENABLED);
@@ -927,7 +927,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 		source = &fmd->fimc[i]->vid_cap.subdev.entity;
 		sink = &fmd->fimc[i]->vid_cap.ve.vdev.entity;
 
-		ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE,
+		ret = media_create_pad_link(source, FIMC_SD_PAD_SOURCE,
 					      sink, 0, flags);
 		if (ret)
 			break;
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index e08183f9d0f7..6351f35b0a65 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -1865,7 +1865,7 @@ static int isp_link_entity(
 		return -EINVAL;
 	}
 
-	return media_entity_create_link(entity, i, input, pad, flags);
+	return media_create_pad_link(entity, i, input, pad, flags);
 }
 
 static int isp_register_entities(struct isp_device *isp)
@@ -2004,51 +2004,51 @@ static int isp_initialize_modules(struct isp_device *isp)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_aewb.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_af.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_hist.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c
index d96e3be5e252..27555e4f4aa8 100644
--- a/drivers/media/platform/omap3isp/ispccdc.c
+++ b/drivers/media/platform/omap3isp/ispccdc.c
@@ -2667,7 +2667,7 @@ static int ccdc_init_entities(struct isp_ccdc_device *ccdc)
 		goto error_video;
 
 	/* Connect the CCDC subdev to the video node. */
-	ret = media_entity_create_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
+	ret = media_create_pad_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
 			&ccdc->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c
index e1b5f5bea541..b215eb5049d6 100644
--- a/drivers/media/platform/omap3isp/ispccp2.c
+++ b/drivers/media/platform/omap3isp/ispccp2.c
@@ -1100,7 +1100,7 @@ static int ccp2_init_entities(struct isp_ccp2_device *ccp2)
 		goto error_video;
 
 	/* Connect the video node to the ccp2 subdev. */
-	ret = media_entity_create_link(&ccp2->video_in.video.entity, 0,
+	ret = media_create_pad_link(&ccp2->video_in.video.entity, 0,
 				       &ccp2->subdev.entity, CCP2_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispcsi2.c b/drivers/media/platform/omap3isp/ispcsi2.c
index 6fff92f0813a..fcefc1e74881 100644
--- a/drivers/media/platform/omap3isp/ispcsi2.c
+++ b/drivers/media/platform/omap3isp/ispcsi2.c
@@ -1265,7 +1265,7 @@ static int csi2_init_entities(struct isp_csi2_device *csi2)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/isppreview.c b/drivers/media/platform/omap3isp/isppreview.c
index b440c6342ca4..ad38d20c7770 100644
--- a/drivers/media/platform/omap3isp/isppreview.c
+++ b/drivers/media/platform/omap3isp/isppreview.c
@@ -2312,12 +2312,12 @@ static int preview_init_entities(struct isp_prev_device *prev)
 		goto error_video_out;
 
 	/* Connect the video nodes to the previewer subdev. */
-	ret = media_entity_create_link(&prev->video_in.video.entity, 0,
+	ret = media_create_pad_link(&prev->video_in.video.entity, 0,
 			&prev->subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&prev->subdev.entity, PREV_PAD_SOURCE,
+	ret = media_create_pad_link(&prev->subdev.entity, PREV_PAD_SOURCE,
 			&prev->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispresizer.c b/drivers/media/platform/omap3isp/ispresizer.c
index 3deb1ec4a973..b48ad4d4b834 100644
--- a/drivers/media/platform/omap3isp/ispresizer.c
+++ b/drivers/media/platform/omap3isp/ispresizer.c
@@ -1756,12 +1756,12 @@ static int resizer_init_entities(struct isp_res_device *res)
 	res->video_out.video.entity.flags |= MEDIA_ENT_FL_DEFAULT;
 
 	/* Connect the video nodes to the resizer subdev. */
-	ret = media_entity_create_link(&res->video_in.video.entity, 0,
+	ret = media_create_pad_link(&res->video_in.video.entity, 0,
 			&res->subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&res->subdev.entity, RESZ_PAD_SOURCE,
+	ret = media_create_pad_link(&res->subdev.entity, RESZ_PAD_SOURCE,
 			&res->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c
index f47b332f0418..3e33c60be004 100644
--- a/drivers/media/platform/s3c-camif/camif-core.c
+++ b/drivers/media/platform/s3c-camif/camif-core.c
@@ -263,7 +263,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 {
 	int i, ret;
 
-	ret = media_entity_create_link(&camif->sensor.sd->entity, 0,
+	ret = media_create_pad_link(&camif->sensor.sd->entity, 0,
 				&camif->subdev.entity, CAMIF_SD_PAD_SINK,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
@@ -271,7 +271,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 		return ret;
 
 	for (i = 1; i < CAMIF_SD_PADS_NUM && !ret; i++) {
-		ret = media_entity_create_link(&camif->subdev.entity, i,
+		ret = media_create_pad_link(&camif->subdev.entity, i,
 				&camif->vp[i - 1].vdev.entity, 0,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
index 4e61886384e3..9cd94a76a9ed 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -101,7 +101,7 @@ static int vsp1_create_links(struct vsp1_device *vsp1, struct vsp1_entity *sink)
 			if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
 				continue;
 
-			ret = media_entity_create_link(&source->subdev.entity,
+			ret = media_create_pad_link(&source->subdev.entity,
 						       source->source_pad,
 						       entity, pad, flags);
 			if (ret < 0)
@@ -262,7 +262,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 	}
 
 	if (vsp1->pdata.features & VSP1_HAS_LIF) {
-		ret = media_entity_create_link(
+		ret = media_create_pad_link(
 			&vsp1->wpf[0]->entity.subdev.entity, RWPF_PAD_SOURCE,
 			&vsp1->lif->entity.subdev.entity, LIF_PAD_SINK, 0);
 		if (ret < 0)
diff --git a/drivers/media/platform/vsp1/vsp1_rpf.c b/drivers/media/platform/vsp1/vsp1_rpf.c
index 3294529a3108..b60a528a8fe8 100644
--- a/drivers/media/platform/vsp1/vsp1_rpf.c
+++ b/drivers/media/platform/vsp1/vsp1_rpf.c
@@ -278,7 +278,7 @@ struct vsp1_rwpf *vsp1_rpf_create(struct vsp1_device *vsp1, unsigned int index)
 	rpf->entity.video = video;
 
 	/* Connect the video device to the RPF. */
-	ret = media_entity_create_link(&rpf->video.video.entity, 0,
+	ret = media_create_pad_link(&rpf->video.video.entity, 0,
 				       &rpf->entity.subdev.entity,
 				       RWPF_PAD_SINK,
 				       MEDIA_LNK_FL_ENABLED |
diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c b/drivers/media/platform/vsp1/vsp1_wpf.c
index 1d2b3a2f1573..d39aa4b8aea1 100644
--- a/drivers/media/platform/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/vsp1/vsp1_wpf.c
@@ -284,7 +284,7 @@ struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index)
 	if (!(vsp1->pdata.features & VSP1_HAS_LIF) || index != 0)
 		flags |= MEDIA_LNK_FL_IMMUTABLE;
 
-	ret = media_entity_create_link(&wpf->entity.subdev.entity,
+	ret = media_create_pad_link(&wpf->entity.subdev.entity,
 				       RWPF_PAD_SOURCE,
 				       &wpf->video.video.entity, 0, flags);
 	if (ret < 0)
diff --git a/drivers/media/platform/xilinx/xilinx-vipp.c b/drivers/media/platform/xilinx/xilinx-vipp.c
index 7b7cb9c28d2c..79d4be7ce9a5 100644
--- a/drivers/media/platform/xilinx/xilinx-vipp.c
+++ b/drivers/media/platform/xilinx/xilinx-vipp.c
@@ -156,7 +156,7 @@ static int xvip_graph_build_one(struct xvip_composite_device *xdev,
 			local->name, local_pad->index,
 			remote->name, remote_pad->index);
 
-		ret = media_entity_create_link(local, local_pad->index,
+		ret = media_create_pad_link(local, local_pad->index,
 					       remote, remote_pad->index,
 					       link_flags);
 		if (ret < 0) {
@@ -270,7 +270,7 @@ static int xvip_graph_build_dma(struct xvip_composite_device *xdev)
 			source->name, source_pad->index,
 			sink->name, sink_pad->index);
 
-		ret = media_entity_create_link(source, source_pad->index,
+		ret = media_create_pad_link(source, source_pad->index,
 					       sink, sink_pad->index,
 					       link_flags);
 		if (ret < 0) {
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 0378a2c99ebb..a55eb524ea21 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -260,13 +260,13 @@ static void au0828_create_media_graph(struct au0828_dev *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
 	if (dev->vdev.entity.links)
-		media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+		media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 	if (dev->vbi_dev.entity.links)
-		media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+		media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 4a117a58c39a..3b5c9ae39ad3 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1264,11 +1264,11 @@ static void cx231xx_create_media_graph(struct cx231xx *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+	media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+	media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
index 245445491516..429e428ccd93 100644
--- a/drivers/media/usb/uvc/uvc_entity.c
+++ b/drivers/media/usb/uvc/uvc_entity.c
@@ -56,7 +56,7 @@ static int uvc_mc_register_entity(struct uvc_video_chain *chain,
 			continue;
 
 		remote_pad = remote->num_pads - 1;
-		ret = media_entity_create_link(source, remote_pad,
+		ret = media_create_pad_link(source, remote_pad,
 					       sink, i, flags);
 		if (ret < 0)
 			return ret;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
index 8fb676186898..d96bdaaae50e 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
@@ -971,7 +971,7 @@ vpfe_ipipeif_register_entities(struct vpfe_ipipeif_device *ipipeif,
 	ipipeif->video_in.vpfe_dev = vpfe_dev;
 
 	flags = 0;
-	ret = media_entity_create_link(&ipipeif->video_in.video_dev.entity, 0,
+	ret = media_create_pad_link(&ipipeif->video_in.video_dev.entity, 0,
 					&ipipeif->subdev.entity, 0, flags);
 	if (ret < 0)
 		goto fail;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index b1f01adfa7c8..df77288b0ec0 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -1817,7 +1817,7 @@ int vpfe_isif_register_entities(struct vpfe_isif_device *isif,
 	isif->video_out.vpfe_dev = vpfe_dev;
 	flags = 0;
 	/* connect isif to video node */
-	ret = media_entity_create_link(&isif->subdev.entity, 1,
+	ret = media_create_pad_link(&isif->subdev.entity, 1,
 				       &isif->video_out.video_dev.entity,
 				       0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index 692789aa22f4..ae942de3a23d 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -1831,27 +1831,27 @@ int vpfe_resizer_register_entities(struct vpfe_resizer_device *resizer,
 	resizer->resizer_b.video_out.vpfe_dev = vpfe_dev;
 
 	/* create link between Resizer Crop----> Resizer A*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 1,
 				&resizer->resizer_a.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer Crop----> Resizer B*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 2,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 2,
 				&resizer->resizer_b.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer A ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_a.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_a.subdev.entity, 1,
 		&resizer->resizer_a.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer B ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_b.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_b.subdev.entity, 1,
 		&resizer->resizer_b.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
index 57426199ad7a..08c8a5f967d3 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
@@ -445,32 +445,32 @@ static int vpfe_register_entities(struct vpfe_device *vpfe_dev)
 		/* if entity has no pads (ex: amplifier),
 		   cant establish link */
 		if (vpfe_dev->sd[i]->entity.num_pads) {
-			ret = media_entity_create_link(&vpfe_dev->sd[i]->entity,
+			ret = media_create_pad_link(&vpfe_dev->sd[i]->entity,
 				0, &vpfe_dev->vpfe_isif.subdev.entity,
 				0, flags);
 			if (ret < 0)
 				goto out_resizer_register;
 		}
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipeif.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipe.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
 			1, &vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 			&vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index e54a7afd31de..7226553ceb2f 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -1259,7 +1259,7 @@ static int iss_register_entities(struct iss_device *iss)
 			goto done;
 		}
 
-		ret = media_entity_create_link(&sensor->entity, 0, input, pad,
+		ret = media_create_pad_link(&sensor->entity, 0, input, pad,
 					       flags);
 		if (ret < 0)
 			goto done;
@@ -1317,31 +1317,31 @@ static int iss_initialize_modules(struct iss_device *iss)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2b.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_csi2.c b/drivers/staging/media/omap4iss/iss_csi2.c
index e936cfc218cb..6b4dcbfa9425 100644
--- a/drivers/staging/media/omap4iss/iss_csi2.c
+++ b/drivers/staging/media/omap4iss/iss_csi2.c
@@ -1291,7 +1291,7 @@ static int csi2_init_entities(struct iss_csi2_device *csi2, const char *subname)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/staging/media/omap4iss/iss_ipipeif.c b/drivers/staging/media/omap4iss/iss_ipipeif.c
index be5f80d7b5dc..44c432ef2ac5 100644
--- a/drivers/staging/media/omap4iss/iss_ipipeif.c
+++ b/drivers/staging/media/omap4iss/iss_ipipeif.c
@@ -762,7 +762,7 @@ static int ipipeif_init_entities(struct iss_ipipeif_device *ipipeif)
 		return ret;
 
 	/* Connect the IPIPEIF subdev to the video node. */
-	ret = media_entity_create_link(&ipipeif->subdev.entity,
+	ret = media_create_pad_link(&ipipeif->subdev.entity,
 				       IPIPEIF_PAD_SOURCE_ISIF_SF,
 				       &ipipeif->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_resizer.c b/drivers/staging/media/omap4iss/iss_resizer.c
index 91e724085dba..b659e465cb56 100644
--- a/drivers/staging/media/omap4iss/iss_resizer.c
+++ b/drivers/staging/media/omap4iss/iss_resizer.c
@@ -806,7 +806,7 @@ static int resizer_init_entities(struct iss_resizer_device *resizer)
 		return ret;
 
 	/* Connect the RESIZER subdev to the video node. */
-	ret = media_entity_create_link(&resizer->subdev.entity,
+	ret = media_create_pad_link(&resizer->subdev.entity,
 				       RESIZER_PAD_SOURCE_MEM,
 				       &resizer->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index af6646ddf6db..e0e4b014ce62 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -208,7 +208,7 @@ int media_entity_init(struct media_entity *entity, u16 num_pads,
 		struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
 
-int media_entity_create_link(struct media_entity *source, u16 source_pad,
+int media_create_pad_link(struct media_entity *source, u16 source_pad,
 		struct media_entity *sink, u16 sink_pad, u32 flags);
 void __media_entity_remove_links(struct media_entity *entity);
 void media_entity_remove_links(struct media_entity *entity);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 10/55] [media] media: rename the function that create pad links
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Jonathan Corbet,
	Kyungmin Park, Andrzej Hajda, Sakari Ailus, Sylwester Nawrocki,
	Kukjin Kim, Krzysztof Kozlowski, Laurent Pinchart, Hyun Kwon,
	Michal Simek, Sören Brinkmann, Greg Kroah-Hartman,
	Hans Verkuil, Rafael Lourenço de Lima Chehab, Shuah Khan,
	Matthias Schwarzott, Antti Palosaari, Olli Salonen,
	Tommi Rantala, Navya Sri Nizamkari, Boris BREZILLON, Aya Mahfouz,
	anuvazhayil, Mahati Chamarthy, Prabhakar Lad, Jiayi Ye,
	Wolfram Sang, Heena Sirwani, linux-doc, linux-arm-kernel,
	linux-samsung-soc, linux-sh, devel

With the new API, a link can be either between two PADs or between an interface
and an entity. So, we need to use a better name for the function that create
links between two pads.

So, rename the such function to media_create_pad_link().

No functional changes.

This patch was created via this shell script:
	for i in $(find drivers/media -name '*.[ch]' -type f) $(find drivers/staging/media -name '*.[ch]' -type f) $(find include/ -name '*.h' -type f) ; do sed s,media_entity_create_link,media_create_pad_link,g <$i >a && mv a $i; done

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/Documentation/media-framework.txt b/Documentation/media-framework.txt
index 6903b2503577..b424de6c3bb3 100644
--- a/Documentation/media-framework.txt
+++ b/Documentation/media-framework.txt
@@ -199,7 +199,7 @@ pre-allocated and grows dynamically as needed.
 
 Drivers create links by calling
 
-	media_entity_create_link(struct media_entity *source, u16 source_pad,
+	media_create_pad_link(struct media_entity *source, u16 source_pad,
 				 struct media_entity *sink,   u16 sink_pad,
 				 u32 flags);
 
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 2fdcbb5f000a..65f59f2124b4 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -412,16 +412,16 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	}
 
 	if (tuner && fe)
-		media_entity_create_link(tuner, 0, fe, 0, 0);
+		media_create_pad_link(tuner, 0, fe, 0, 0);
 
 	if (fe && demux)
-		media_entity_create_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && dvr)
-		media_entity_create_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && ca)
-		media_entity_create_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
 }
 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
 #endif
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 6d167428727d..c81bfbfea32f 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1482,11 +1482,11 @@ static int s5c73m3_oif_registered(struct v4l2_subdev *sd)
 		return ret;
 	}
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_ISP_PAD, &state->oif_sd.entity, OIF_ISP_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_JPEG_PAD, &state->oif_sd.entity, OIF_JPEG_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 30a9ca62e034..d3bff30bcb6f 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -1756,7 +1756,7 @@ static int s5k5baf_registered(struct v4l2_subdev *sd)
 		v4l2_err(sd, "failed to register subdev %s\n",
 			 state->cis_sd.name);
 	else
-		ret = media_entity_create_link(&state->cis_sd.entity, PAD_CIS,
+		ret = media_create_pad_link(&state->cis_sd.entity, PAD_CIS,
 					       &state->sd.entity, PAD_CIS,
 					       MEDIA_LNK_FL_IMMUTABLE |
 					       MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 308613ea0aed..5aa49eb393a9 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2495,7 +2495,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 			return rval;
 		}
 
-		rval = media_entity_create_link(&this->sd.entity,
+		rval = media_create_pad_link(&this->sd.entity,
 						this->source_pad,
 						&last->sd.entity,
 						last->sink_pad,
@@ -2503,7 +2503,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 						MEDIA_LNK_FL_IMMUTABLE);
 		if (rval) {
 			dev_err(&client->dev,
-				"media_entity_create_link failed\n");
+				"media_create_pad_link failed\n");
 			return rval;
 		}
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 6d515e149d7f..35e52cd1fc5a 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -542,7 +542,7 @@ static struct media_link *media_entity_add_link(struct media_entity *entity)
 }
 
 int
-media_entity_create_link(struct media_entity *source, u16 source_pad,
+media_create_pad_link(struct media_entity *source, u16 source_pad,
 			 struct media_entity *sink, u16 sink_pad, u32 flags)
 {
 	struct media_link *link;
@@ -586,7 +586,7 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(media_entity_create_link);
+EXPORT_SYMBOL_GPL(media_create_pad_link);
 
 void __media_entity_remove_links(struct media_entity *entity)
 {
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 4f5586a4cbff..3ba76940eef5 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -729,7 +729,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 		flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0;
 
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					      FIMC_SD_PAD_SINK_CAM, flags);
 		if (ret)
 			return ret;
@@ -749,7 +749,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 			continue;
 
 		sink = &fmd->fimc_lite[i]->subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					       FLITE_SD_PAD_SINK, 0);
 		if (ret)
 			return ret;
@@ -781,13 +781,13 @@ static int __fimc_md_create_flite_source_links(struct fimc_md *fmd)
 		source = &fimc->subdev.entity;
 		sink = &fimc->ve.vdev.entity;
 		/* FIMC-LITE's subdev and video node */
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_DMA,
 					       sink, 0, 0);
 		if (ret)
 			break;
 		/* Link from FIMC-LITE to IS-ISP subdev */
 		sink = &fmd->fimc_is->isp.subdev.entity;
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_ISP,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_ISP,
 					       sink, 0, 0);
 		if (ret)
 			break;
@@ -811,7 +811,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 
 		/* Link from FIMC-IS-ISP subdev to FIMC */
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
+		ret = media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
 					       sink, FIMC_SD_PAD_SINK_FIFO, 0);
 		if (ret)
 			return ret;
@@ -824,7 +824,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 	if (sink->num_pads == 0)
 		return 0;
 
-	return media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
+	return media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
 					sink, 0, 0);
 }
 
@@ -873,7 +873,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 				return -EINVAL;
 
 			pad = sensor->entity.num_pads - 1;
-			ret = media_entity_create_link(&sensor->entity, pad,
+			ret = media_create_pad_link(&sensor->entity, pad,
 					      &csis->entity, CSIS_PAD_SINK,
 					      MEDIA_LNK_FL_IMMUTABLE |
 					      MEDIA_LNK_FL_ENABLED);
@@ -927,7 +927,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 		source = &fmd->fimc[i]->vid_cap.subdev.entity;
 		sink = &fmd->fimc[i]->vid_cap.ve.vdev.entity;
 
-		ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE,
+		ret = media_create_pad_link(source, FIMC_SD_PAD_SOURCE,
 					      sink, 0, flags);
 		if (ret)
 			break;
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index e08183f9d0f7..6351f35b0a65 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -1865,7 +1865,7 @@ static int isp_link_entity(
 		return -EINVAL;
 	}
 
-	return media_entity_create_link(entity, i, input, pad, flags);
+	return media_create_pad_link(entity, i, input, pad, flags);
 }
 
 static int isp_register_entities(struct isp_device *isp)
@@ -2004,51 +2004,51 @@ static int isp_initialize_modules(struct isp_device *isp)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_aewb.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_af.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_hist.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c
index d96e3be5e252..27555e4f4aa8 100644
--- a/drivers/media/platform/omap3isp/ispccdc.c
+++ b/drivers/media/platform/omap3isp/ispccdc.c
@@ -2667,7 +2667,7 @@ static int ccdc_init_entities(struct isp_ccdc_device *ccdc)
 		goto error_video;
 
 	/* Connect the CCDC subdev to the video node. */
-	ret = media_entity_create_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
+	ret = media_create_pad_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
 			&ccdc->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c
index e1b5f5bea541..b215eb5049d6 100644
--- a/drivers/media/platform/omap3isp/ispccp2.c
+++ b/drivers/media/platform/omap3isp/ispccp2.c
@@ -1100,7 +1100,7 @@ static int ccp2_init_entities(struct isp_ccp2_device *ccp2)
 		goto error_video;
 
 	/* Connect the video node to the ccp2 subdev. */
-	ret = media_entity_create_link(&ccp2->video_in.video.entity, 0,
+	ret = media_create_pad_link(&ccp2->video_in.video.entity, 0,
 				       &ccp2->subdev.entity, CCP2_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispcsi2.c b/drivers/media/platform/omap3isp/ispcsi2.c
index 6fff92f0813a..fcefc1e74881 100644
--- a/drivers/media/platform/omap3isp/ispcsi2.c
+++ b/drivers/media/platform/omap3isp/ispcsi2.c
@@ -1265,7 +1265,7 @@ static int csi2_init_entities(struct isp_csi2_device *csi2)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/isppreview.c b/drivers/media/platform/omap3isp/isppreview.c
index b440c6342ca4..ad38d20c7770 100644
--- a/drivers/media/platform/omap3isp/isppreview.c
+++ b/drivers/media/platform/omap3isp/isppreview.c
@@ -2312,12 +2312,12 @@ static int preview_init_entities(struct isp_prev_device *prev)
 		goto error_video_out;
 
 	/* Connect the video nodes to the previewer subdev. */
-	ret = media_entity_create_link(&prev->video_in.video.entity, 0,
+	ret = media_create_pad_link(&prev->video_in.video.entity, 0,
 			&prev->subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&prev->subdev.entity, PREV_PAD_SOURCE,
+	ret = media_create_pad_link(&prev->subdev.entity, PREV_PAD_SOURCE,
 			&prev->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispresizer.c b/drivers/media/platform/omap3isp/ispresizer.c
index 3deb1ec4a973..b48ad4d4b834 100644
--- a/drivers/media/platform/omap3isp/ispresizer.c
+++ b/drivers/media/platform/omap3isp/ispresizer.c
@@ -1756,12 +1756,12 @@ static int resizer_init_entities(struct isp_res_device *res)
 	res->video_out.video.entity.flags |= MEDIA_ENT_FL_DEFAULT;
 
 	/* Connect the video nodes to the resizer subdev. */
-	ret = media_entity_create_link(&res->video_in.video.entity, 0,
+	ret = media_create_pad_link(&res->video_in.video.entity, 0,
 			&res->subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&res->subdev.entity, RESZ_PAD_SOURCE,
+	ret = media_create_pad_link(&res->subdev.entity, RESZ_PAD_SOURCE,
 			&res->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c
index f47b332f0418..3e33c60be004 100644
--- a/drivers/media/platform/s3c-camif/camif-core.c
+++ b/drivers/media/platform/s3c-camif/camif-core.c
@@ -263,7 +263,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 {
 	int i, ret;
 
-	ret = media_entity_create_link(&camif->sensor.sd->entity, 0,
+	ret = media_create_pad_link(&camif->sensor.sd->entity, 0,
 				&camif->subdev.entity, CAMIF_SD_PAD_SINK,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
@@ -271,7 +271,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 		return ret;
 
 	for (i = 1; i < CAMIF_SD_PADS_NUM && !ret; i++) {
-		ret = media_entity_create_link(&camif->subdev.entity, i,
+		ret = media_create_pad_link(&camif->subdev.entity, i,
 				&camif->vp[i - 1].vdev.entity, 0,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
index 4e61886384e3..9cd94a76a9ed 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -101,7 +101,7 @@ static int vsp1_create_links(struct vsp1_device *vsp1, struct vsp1_entity *sink)
 			if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
 				continue;
 
-			ret = media_entity_create_link(&source->subdev.entity,
+			ret = media_create_pad_link(&source->subdev.entity,
 						       source->source_pad,
 						       entity, pad, flags);
 			if (ret < 0)
@@ -262,7 +262,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 	}
 
 	if (vsp1->pdata.features & VSP1_HAS_LIF) {
-		ret = media_entity_create_link(
+		ret = media_create_pad_link(
 			&vsp1->wpf[0]->entity.subdev.entity, RWPF_PAD_SOURCE,
 			&vsp1->lif->entity.subdev.entity, LIF_PAD_SINK, 0);
 		if (ret < 0)
diff --git a/drivers/media/platform/vsp1/vsp1_rpf.c b/drivers/media/platform/vsp1/vsp1_rpf.c
index 3294529a3108..b60a528a8fe8 100644
--- a/drivers/media/platform/vsp1/vsp1_rpf.c
+++ b/drivers/media/platform/vsp1/vsp1_rpf.c
@@ -278,7 +278,7 @@ struct vsp1_rwpf *vsp1_rpf_create(struct vsp1_device *vsp1, unsigned int index)
 	rpf->entity.video = video;
 
 	/* Connect the video device to the RPF. */
-	ret = media_entity_create_link(&rpf->video.video.entity, 0,
+	ret = media_create_pad_link(&rpf->video.video.entity, 0,
 				       &rpf->entity.subdev.entity,
 				       RWPF_PAD_SINK,
 				       MEDIA_LNK_FL_ENABLED |
diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c b/drivers/media/platform/vsp1/vsp1_wpf.c
index 1d2b3a2f1573..d39aa4b8aea1 100644
--- a/drivers/media/platform/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/vsp1/vsp1_wpf.c
@@ -284,7 +284,7 @@ struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index)
 	if (!(vsp1->pdata.features & VSP1_HAS_LIF) || index != 0)
 		flags |= MEDIA_LNK_FL_IMMUTABLE;
 
-	ret = media_entity_create_link(&wpf->entity.subdev.entity,
+	ret = media_create_pad_link(&wpf->entity.subdev.entity,
 				       RWPF_PAD_SOURCE,
 				       &wpf->video.video.entity, 0, flags);
 	if (ret < 0)
diff --git a/drivers/media/platform/xilinx/xilinx-vipp.c b/drivers/media/platform/xilinx/xilinx-vipp.c
index 7b7cb9c28d2c..79d4be7ce9a5 100644
--- a/drivers/media/platform/xilinx/xilinx-vipp.c
+++ b/drivers/media/platform/xilinx/xilinx-vipp.c
@@ -156,7 +156,7 @@ static int xvip_graph_build_one(struct xvip_composite_device *xdev,
 			local->name, local_pad->index,
 			remote->name, remote_pad->index);
 
-		ret = media_entity_create_link(local, local_pad->index,
+		ret = media_create_pad_link(local, local_pad->index,
 					       remote, remote_pad->index,
 					       link_flags);
 		if (ret < 0) {
@@ -270,7 +270,7 @@ static int xvip_graph_build_dma(struct xvip_composite_device *xdev)
 			source->name, source_pad->index,
 			sink->name, sink_pad->index);
 
-		ret = media_entity_create_link(source, source_pad->index,
+		ret = media_create_pad_link(source, source_pad->index,
 					       sink, sink_pad->index,
 					       link_flags);
 		if (ret < 0) {
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 0378a2c99ebb..a55eb524ea21 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -260,13 +260,13 @@ static void au0828_create_media_graph(struct au0828_dev *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
 	if (dev->vdev.entity.links)
-		media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+		media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 	if (dev->vbi_dev.entity.links)
-		media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+		media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 4a117a58c39a..3b5c9ae39ad3 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1264,11 +1264,11 @@ static void cx231xx_create_media_graph(struct cx231xx *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+	media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+	media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
index 245445491516..429e428ccd93 100644
--- a/drivers/media/usb/uvc/uvc_entity.c
+++ b/drivers/media/usb/uvc/uvc_entity.c
@@ -56,7 +56,7 @@ static int uvc_mc_register_entity(struct uvc_video_chain *chain,
 			continue;
 
 		remote_pad = remote->num_pads - 1;
-		ret = media_entity_create_link(source, remote_pad,
+		ret = media_create_pad_link(source, remote_pad,
 					       sink, i, flags);
 		if (ret < 0)
 			return ret;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
index 8fb676186898..d96bdaaae50e 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
@@ -971,7 +971,7 @@ vpfe_ipipeif_register_entities(struct vpfe_ipipeif_device *ipipeif,
 	ipipeif->video_in.vpfe_dev = vpfe_dev;
 
 	flags = 0;
-	ret = media_entity_create_link(&ipipeif->video_in.video_dev.entity, 0,
+	ret = media_create_pad_link(&ipipeif->video_in.video_dev.entity, 0,
 					&ipipeif->subdev.entity, 0, flags);
 	if (ret < 0)
 		goto fail;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index b1f01adfa7c8..df77288b0ec0 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -1817,7 +1817,7 @@ int vpfe_isif_register_entities(struct vpfe_isif_device *isif,
 	isif->video_out.vpfe_dev = vpfe_dev;
 	flags = 0;
 	/* connect isif to video node */
-	ret = media_entity_create_link(&isif->subdev.entity, 1,
+	ret = media_create_pad_link(&isif->subdev.entity, 1,
 				       &isif->video_out.video_dev.entity,
 				       0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index 692789aa22f4..ae942de3a23d 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -1831,27 +1831,27 @@ int vpfe_resizer_register_entities(struct vpfe_resizer_device *resizer,
 	resizer->resizer_b.video_out.vpfe_dev = vpfe_dev;
 
 	/* create link between Resizer Crop----> Resizer A*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 1,
 				&resizer->resizer_a.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer Crop----> Resizer B*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 2,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 2,
 				&resizer->resizer_b.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer A ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_a.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_a.subdev.entity, 1,
 		&resizer->resizer_a.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer B ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_b.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_b.subdev.entity, 1,
 		&resizer->resizer_b.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
index 57426199ad7a..08c8a5f967d3 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
@@ -445,32 +445,32 @@ static int vpfe_register_entities(struct vpfe_device *vpfe_dev)
 		/* if entity has no pads (ex: amplifier),
 		   cant establish link */
 		if (vpfe_dev->sd[i]->entity.num_pads) {
-			ret = media_entity_create_link(&vpfe_dev->sd[i]->entity,
+			ret = media_create_pad_link(&vpfe_dev->sd[i]->entity,
 				0, &vpfe_dev->vpfe_isif.subdev.entity,
 				0, flags);
 			if (ret < 0)
 				goto out_resizer_register;
 		}
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipeif.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipe.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
 			1, &vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 			&vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index e54a7afd31de..7226553ceb2f 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -1259,7 +1259,7 @@ static int iss_register_entities(struct iss_device *iss)
 			goto done;
 		}
 
-		ret = media_entity_create_link(&sensor->entity, 0, input, pad,
+		ret = media_create_pad_link(&sensor->entity, 0, input, pad,
 					       flags);
 		if (ret < 0)
 			goto done;
@@ -1317,31 +1317,31 @@ static int iss_initialize_modules(struct iss_device *iss)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2b.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_csi2.c b/drivers/staging/media/omap4iss/iss_csi2.c
index e936cfc218cb..6b4dcbfa9425 100644
--- a/drivers/staging/media/omap4iss/iss_csi2.c
+++ b/drivers/staging/media/omap4iss/iss_csi2.c
@@ -1291,7 +1291,7 @@ static int csi2_init_entities(struct iss_csi2_device *csi2, const char *subname)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/staging/media/omap4iss/iss_ipipeif.c b/drivers/staging/media/omap4iss/iss_ipipeif.c
index be5f80d7b5dc..44c432ef2ac5 100644
--- a/drivers/staging/media/omap4iss/iss_ipipeif.c
+++ b/drivers/staging/media/omap4iss/iss_ipipeif.c
@@ -762,7 +762,7 @@ static int ipipeif_init_entities(struct iss_ipipeif_device *ipipeif)
 		return ret;
 
 	/* Connect the IPIPEIF subdev to the video node. */
-	ret = media_entity_create_link(&ipipeif->subdev.entity,
+	ret = media_create_pad_link(&ipipeif->subdev.entity,
 				       IPIPEIF_PAD_SOURCE_ISIF_SF,
 				       &ipipeif->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_resizer.c b/drivers/staging/media/omap4iss/iss_resizer.c
index 91e724085dba..b659e465cb56 100644
--- a/drivers/staging/media/omap4iss/iss_resizer.c
+++ b/drivers/staging/media/omap4iss/iss_resizer.c
@@ -806,7 +806,7 @@ static int resizer_init_entities(struct iss_resizer_device *resizer)
 		return ret;
 
 	/* Connect the RESIZER subdev to the video node. */
-	ret = media_entity_create_link(&resizer->subdev.entity,
+	ret = media_create_pad_link(&resizer->subdev.entity,
 				       RESIZER_PAD_SOURCE_MEM,
 				       &resizer->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index af6646ddf6db..e0e4b014ce62 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -208,7 +208,7 @@ int media_entity_init(struct media_entity *entity, u16 num_pads,
 		struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
 
-int media_entity_create_link(struct media_entity *source, u16 source_pad,
+int media_create_pad_link(struct media_entity *source, u16 source_pad,
 		struct media_entity *sink, u16 sink_pad, u32 flags);
 void __media_entity_remove_links(struct media_entity *entity);
 void media_entity_remove_links(struct media_entity *entity);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 10/55] [media] media: rename the function that create pad links
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Krzysztof Kozlowski, Wolfram Sang, Jiayi Ye, Michal Simek,
	Andrzej Hajda, Prabhakar Lad, Laurent Pinchart,
	Sylwester Nawrocki, Matthias Schwarzott, Olli Salonen,
	Heena Sirwani, devel, Antti Palosaari, linux-samsung-soc,
	Jonathan Corbet, linux-sh, Boris BREZILLON, linux-doc,
	Shuah Khan, Kukjin Kim, Hans Verkuil, linux-arm-kernel,
	Navya Sri Nizamkari, anuv

With the new API, a link can be either between two PADs or between an interface
and an entity. So, we need to use a better name for the function that create
links between two pads.

So, rename the such function to media_create_pad_link().

No functional changes.

This patch was created via this shell script:
	for i in $(find drivers/media -name '*.[ch]' -type f) $(find drivers/staging/media -name '*.[ch]' -type f) $(find include/ -name '*.h' -type f) ; do sed s,media_entity_create_link,media_create_pad_link,g <$i >a && mv a $i; done

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/Documentation/media-framework.txt b/Documentation/media-framework.txt
index 6903b2503577..b424de6c3bb3 100644
--- a/Documentation/media-framework.txt
+++ b/Documentation/media-framework.txt
@@ -199,7 +199,7 @@ pre-allocated and grows dynamically as needed.
 
 Drivers create links by calling
 
-	media_entity_create_link(struct media_entity *source, u16 source_pad,
+	media_create_pad_link(struct media_entity *source, u16 source_pad,
 				 struct media_entity *sink,   u16 sink_pad,
 				 u32 flags);
 
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 2fdcbb5f000a..65f59f2124b4 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -412,16 +412,16 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	}
 
 	if (tuner && fe)
-		media_entity_create_link(tuner, 0, fe, 0, 0);
+		media_create_pad_link(tuner, 0, fe, 0, 0);
 
 	if (fe && demux)
-		media_entity_create_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && dvr)
-		media_entity_create_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && ca)
-		media_entity_create_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
 }
 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
 #endif
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 6d167428727d..c81bfbfea32f 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1482,11 +1482,11 @@ static int s5c73m3_oif_registered(struct v4l2_subdev *sd)
 		return ret;
 	}
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_ISP_PAD, &state->oif_sd.entity, OIF_ISP_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_JPEG_PAD, &state->oif_sd.entity, OIF_JPEG_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 30a9ca62e034..d3bff30bcb6f 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -1756,7 +1756,7 @@ static int s5k5baf_registered(struct v4l2_subdev *sd)
 		v4l2_err(sd, "failed to register subdev %s\n",
 			 state->cis_sd.name);
 	else
-		ret = media_entity_create_link(&state->cis_sd.entity, PAD_CIS,
+		ret = media_create_pad_link(&state->cis_sd.entity, PAD_CIS,
 					       &state->sd.entity, PAD_CIS,
 					       MEDIA_LNK_FL_IMMUTABLE |
 					       MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 308613ea0aed..5aa49eb393a9 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2495,7 +2495,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 			return rval;
 		}
 
-		rval = media_entity_create_link(&this->sd.entity,
+		rval = media_create_pad_link(&this->sd.entity,
 						this->source_pad,
 						&last->sd.entity,
 						last->sink_pad,
@@ -2503,7 +2503,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 						MEDIA_LNK_FL_IMMUTABLE);
 		if (rval) {
 			dev_err(&client->dev,
-				"media_entity_create_link failed\n");
+				"media_create_pad_link failed\n");
 			return rval;
 		}
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 6d515e149d7f..35e52cd1fc5a 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -542,7 +542,7 @@ static struct media_link *media_entity_add_link(struct media_entity *entity)
 }
 
 int
-media_entity_create_link(struct media_entity *source, u16 source_pad,
+media_create_pad_link(struct media_entity *source, u16 source_pad,
 			 struct media_entity *sink, u16 sink_pad, u32 flags)
 {
 	struct media_link *link;
@@ -586,7 +586,7 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(media_entity_create_link);
+EXPORT_SYMBOL_GPL(media_create_pad_link);
 
 void __media_entity_remove_links(struct media_entity *entity)
 {
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 4f5586a4cbff..3ba76940eef5 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -729,7 +729,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 		flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0;
 
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					      FIMC_SD_PAD_SINK_CAM, flags);
 		if (ret)
 			return ret;
@@ -749,7 +749,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 			continue;
 
 		sink = &fmd->fimc_lite[i]->subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					       FLITE_SD_PAD_SINK, 0);
 		if (ret)
 			return ret;
@@ -781,13 +781,13 @@ static int __fimc_md_create_flite_source_links(struct fimc_md *fmd)
 		source = &fimc->subdev.entity;
 		sink = &fimc->ve.vdev.entity;
 		/* FIMC-LITE's subdev and video node */
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_DMA,
 					       sink, 0, 0);
 		if (ret)
 			break;
 		/* Link from FIMC-LITE to IS-ISP subdev */
 		sink = &fmd->fimc_is->isp.subdev.entity;
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_ISP,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_ISP,
 					       sink, 0, 0);
 		if (ret)
 			break;
@@ -811,7 +811,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 
 		/* Link from FIMC-IS-ISP subdev to FIMC */
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
+		ret = media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
 					       sink, FIMC_SD_PAD_SINK_FIFO, 0);
 		if (ret)
 			return ret;
@@ -824,7 +824,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 	if (sink->num_pads == 0)
 		return 0;
 
-	return media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
+	return media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
 					sink, 0, 0);
 }
 
@@ -873,7 +873,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 				return -EINVAL;
 
 			pad = sensor->entity.num_pads - 1;
-			ret = media_entity_create_link(&sensor->entity, pad,
+			ret = media_create_pad_link(&sensor->entity, pad,
 					      &csis->entity, CSIS_PAD_SINK,
 					      MEDIA_LNK_FL_IMMUTABLE |
 					      MEDIA_LNK_FL_ENABLED);
@@ -927,7 +927,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 		source = &fmd->fimc[i]->vid_cap.subdev.entity;
 		sink = &fmd->fimc[i]->vid_cap.ve.vdev.entity;
 
-		ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE,
+		ret = media_create_pad_link(source, FIMC_SD_PAD_SOURCE,
 					      sink, 0, flags);
 		if (ret)
 			break;
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index e08183f9d0f7..6351f35b0a65 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -1865,7 +1865,7 @@ static int isp_link_entity(
 		return -EINVAL;
 	}
 
-	return media_entity_create_link(entity, i, input, pad, flags);
+	return media_create_pad_link(entity, i, input, pad, flags);
 }
 
 static int isp_register_entities(struct isp_device *isp)
@@ -2004,51 +2004,51 @@ static int isp_initialize_modules(struct isp_device *isp)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_aewb.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_af.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_hist.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c
index d96e3be5e252..27555e4f4aa8 100644
--- a/drivers/media/platform/omap3isp/ispccdc.c
+++ b/drivers/media/platform/omap3isp/ispccdc.c
@@ -2667,7 +2667,7 @@ static int ccdc_init_entities(struct isp_ccdc_device *ccdc)
 		goto error_video;
 
 	/* Connect the CCDC subdev to the video node. */
-	ret = media_entity_create_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
+	ret = media_create_pad_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
 			&ccdc->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c
index e1b5f5bea541..b215eb5049d6 100644
--- a/drivers/media/platform/omap3isp/ispccp2.c
+++ b/drivers/media/platform/omap3isp/ispccp2.c
@@ -1100,7 +1100,7 @@ static int ccp2_init_entities(struct isp_ccp2_device *ccp2)
 		goto error_video;
 
 	/* Connect the video node to the ccp2 subdev. */
-	ret = media_entity_create_link(&ccp2->video_in.video.entity, 0,
+	ret = media_create_pad_link(&ccp2->video_in.video.entity, 0,
 				       &ccp2->subdev.entity, CCP2_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispcsi2.c b/drivers/media/platform/omap3isp/ispcsi2.c
index 6fff92f0813a..fcefc1e74881 100644
--- a/drivers/media/platform/omap3isp/ispcsi2.c
+++ b/drivers/media/platform/omap3isp/ispcsi2.c
@@ -1265,7 +1265,7 @@ static int csi2_init_entities(struct isp_csi2_device *csi2)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/isppreview.c b/drivers/media/platform/omap3isp/isppreview.c
index b440c6342ca4..ad38d20c7770 100644
--- a/drivers/media/platform/omap3isp/isppreview.c
+++ b/drivers/media/platform/omap3isp/isppreview.c
@@ -2312,12 +2312,12 @@ static int preview_init_entities(struct isp_prev_device *prev)
 		goto error_video_out;
 
 	/* Connect the video nodes to the previewer subdev. */
-	ret = media_entity_create_link(&prev->video_in.video.entity, 0,
+	ret = media_create_pad_link(&prev->video_in.video.entity, 0,
 			&prev->subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&prev->subdev.entity, PREV_PAD_SOURCE,
+	ret = media_create_pad_link(&prev->subdev.entity, PREV_PAD_SOURCE,
 			&prev->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispresizer.c b/drivers/media/platform/omap3isp/ispresizer.c
index 3deb1ec4a973..b48ad4d4b834 100644
--- a/drivers/media/platform/omap3isp/ispresizer.c
+++ b/drivers/media/platform/omap3isp/ispresizer.c
@@ -1756,12 +1756,12 @@ static int resizer_init_entities(struct isp_res_device *res)
 	res->video_out.video.entity.flags |= MEDIA_ENT_FL_DEFAULT;
 
 	/* Connect the video nodes to the resizer subdev. */
-	ret = media_entity_create_link(&res->video_in.video.entity, 0,
+	ret = media_create_pad_link(&res->video_in.video.entity, 0,
 			&res->subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&res->subdev.entity, RESZ_PAD_SOURCE,
+	ret = media_create_pad_link(&res->subdev.entity, RESZ_PAD_SOURCE,
 			&res->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c
index f47b332f0418..3e33c60be004 100644
--- a/drivers/media/platform/s3c-camif/camif-core.c
+++ b/drivers/media/platform/s3c-camif/camif-core.c
@@ -263,7 +263,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 {
 	int i, ret;
 
-	ret = media_entity_create_link(&camif->sensor.sd->entity, 0,
+	ret = media_create_pad_link(&camif->sensor.sd->entity, 0,
 				&camif->subdev.entity, CAMIF_SD_PAD_SINK,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
@@ -271,7 +271,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 		return ret;
 
 	for (i = 1; i < CAMIF_SD_PADS_NUM && !ret; i++) {
-		ret = media_entity_create_link(&camif->subdev.entity, i,
+		ret = media_create_pad_link(&camif->subdev.entity, i,
 				&camif->vp[i - 1].vdev.entity, 0,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
index 4e61886384e3..9cd94a76a9ed 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -101,7 +101,7 @@ static int vsp1_create_links(struct vsp1_device *vsp1, struct vsp1_entity *sink)
 			if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
 				continue;
 
-			ret = media_entity_create_link(&source->subdev.entity,
+			ret = media_create_pad_link(&source->subdev.entity,
 						       source->source_pad,
 						       entity, pad, flags);
 			if (ret < 0)
@@ -262,7 +262,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 	}
 
 	if (vsp1->pdata.features & VSP1_HAS_LIF) {
-		ret = media_entity_create_link(
+		ret = media_create_pad_link(
 			&vsp1->wpf[0]->entity.subdev.entity, RWPF_PAD_SOURCE,
 			&vsp1->lif->entity.subdev.entity, LIF_PAD_SINK, 0);
 		if (ret < 0)
diff --git a/drivers/media/platform/vsp1/vsp1_rpf.c b/drivers/media/platform/vsp1/vsp1_rpf.c
index 3294529a3108..b60a528a8fe8 100644
--- a/drivers/media/platform/vsp1/vsp1_rpf.c
+++ b/drivers/media/platform/vsp1/vsp1_rpf.c
@@ -278,7 +278,7 @@ struct vsp1_rwpf *vsp1_rpf_create(struct vsp1_device *vsp1, unsigned int index)
 	rpf->entity.video = video;
 
 	/* Connect the video device to the RPF. */
-	ret = media_entity_create_link(&rpf->video.video.entity, 0,
+	ret = media_create_pad_link(&rpf->video.video.entity, 0,
 				       &rpf->entity.subdev.entity,
 				       RWPF_PAD_SINK,
 				       MEDIA_LNK_FL_ENABLED |
diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c b/drivers/media/platform/vsp1/vsp1_wpf.c
index 1d2b3a2f1573..d39aa4b8aea1 100644
--- a/drivers/media/platform/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/vsp1/vsp1_wpf.c
@@ -284,7 +284,7 @@ struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index)
 	if (!(vsp1->pdata.features & VSP1_HAS_LIF) || index != 0)
 		flags |= MEDIA_LNK_FL_IMMUTABLE;
 
-	ret = media_entity_create_link(&wpf->entity.subdev.entity,
+	ret = media_create_pad_link(&wpf->entity.subdev.entity,
 				       RWPF_PAD_SOURCE,
 				       &wpf->video.video.entity, 0, flags);
 	if (ret < 0)
diff --git a/drivers/media/platform/xilinx/xilinx-vipp.c b/drivers/media/platform/xilinx/xilinx-vipp.c
index 7b7cb9c28d2c..79d4be7ce9a5 100644
--- a/drivers/media/platform/xilinx/xilinx-vipp.c
+++ b/drivers/media/platform/xilinx/xilinx-vipp.c
@@ -156,7 +156,7 @@ static int xvip_graph_build_one(struct xvip_composite_device *xdev,
 			local->name, local_pad->index,
 			remote->name, remote_pad->index);
 
-		ret = media_entity_create_link(local, local_pad->index,
+		ret = media_create_pad_link(local, local_pad->index,
 					       remote, remote_pad->index,
 					       link_flags);
 		if (ret < 0) {
@@ -270,7 +270,7 @@ static int xvip_graph_build_dma(struct xvip_composite_device *xdev)
 			source->name, source_pad->index,
 			sink->name, sink_pad->index);
 
-		ret = media_entity_create_link(source, source_pad->index,
+		ret = media_create_pad_link(source, source_pad->index,
 					       sink, sink_pad->index,
 					       link_flags);
 		if (ret < 0) {
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 0378a2c99ebb..a55eb524ea21 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -260,13 +260,13 @@ static void au0828_create_media_graph(struct au0828_dev *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
 	if (dev->vdev.entity.links)
-		media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+		media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 	if (dev->vbi_dev.entity.links)
-		media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+		media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 4a117a58c39a..3b5c9ae39ad3 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1264,11 +1264,11 @@ static void cx231xx_create_media_graph(struct cx231xx *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+	media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+	media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
index 245445491516..429e428ccd93 100644
--- a/drivers/media/usb/uvc/uvc_entity.c
+++ b/drivers/media/usb/uvc/uvc_entity.c
@@ -56,7 +56,7 @@ static int uvc_mc_register_entity(struct uvc_video_chain *chain,
 			continue;
 
 		remote_pad = remote->num_pads - 1;
-		ret = media_entity_create_link(source, remote_pad,
+		ret = media_create_pad_link(source, remote_pad,
 					       sink, i, flags);
 		if (ret < 0)
 			return ret;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
index 8fb676186898..d96bdaaae50e 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
@@ -971,7 +971,7 @@ vpfe_ipipeif_register_entities(struct vpfe_ipipeif_device *ipipeif,
 	ipipeif->video_in.vpfe_dev = vpfe_dev;
 
 	flags = 0;
-	ret = media_entity_create_link(&ipipeif->video_in.video_dev.entity, 0,
+	ret = media_create_pad_link(&ipipeif->video_in.video_dev.entity, 0,
 					&ipipeif->subdev.entity, 0, flags);
 	if (ret < 0)
 		goto fail;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index b1f01adfa7c8..df77288b0ec0 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -1817,7 +1817,7 @@ int vpfe_isif_register_entities(struct vpfe_isif_device *isif,
 	isif->video_out.vpfe_dev = vpfe_dev;
 	flags = 0;
 	/* connect isif to video node */
-	ret = media_entity_create_link(&isif->subdev.entity, 1,
+	ret = media_create_pad_link(&isif->subdev.entity, 1,
 				       &isif->video_out.video_dev.entity,
 				       0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index 692789aa22f4..ae942de3a23d 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -1831,27 +1831,27 @@ int vpfe_resizer_register_entities(struct vpfe_resizer_device *resizer,
 	resizer->resizer_b.video_out.vpfe_dev = vpfe_dev;
 
 	/* create link between Resizer Crop----> Resizer A*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 1,
 				&resizer->resizer_a.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer Crop----> Resizer B*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 2,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 2,
 				&resizer->resizer_b.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer A ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_a.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_a.subdev.entity, 1,
 		&resizer->resizer_a.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer B ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_b.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_b.subdev.entity, 1,
 		&resizer->resizer_b.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
index 57426199ad7a..08c8a5f967d3 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
@@ -445,32 +445,32 @@ static int vpfe_register_entities(struct vpfe_device *vpfe_dev)
 		/* if entity has no pads (ex: amplifier),
 		   cant establish link */
 		if (vpfe_dev->sd[i]->entity.num_pads) {
-			ret = media_entity_create_link(&vpfe_dev->sd[i]->entity,
+			ret = media_create_pad_link(&vpfe_dev->sd[i]->entity,
 				0, &vpfe_dev->vpfe_isif.subdev.entity,
 				0, flags);
 			if (ret < 0)
 				goto out_resizer_register;
 		}
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipeif.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipe.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
 			1, &vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 			&vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index e54a7afd31de..7226553ceb2f 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -1259,7 +1259,7 @@ static int iss_register_entities(struct iss_device *iss)
 			goto done;
 		}
 
-		ret = media_entity_create_link(&sensor->entity, 0, input, pad,
+		ret = media_create_pad_link(&sensor->entity, 0, input, pad,
 					       flags);
 		if (ret < 0)
 			goto done;
@@ -1317,31 +1317,31 @@ static int iss_initialize_modules(struct iss_device *iss)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2b.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_csi2.c b/drivers/staging/media/omap4iss/iss_csi2.c
index e936cfc218cb..6b4dcbfa9425 100644
--- a/drivers/staging/media/omap4iss/iss_csi2.c
+++ b/drivers/staging/media/omap4iss/iss_csi2.c
@@ -1291,7 +1291,7 @@ static int csi2_init_entities(struct iss_csi2_device *csi2, const char *subname)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/staging/media/omap4iss/iss_ipipeif.c b/drivers/staging/media/omap4iss/iss_ipipeif.c
index be5f80d7b5dc..44c432ef2ac5 100644
--- a/drivers/staging/media/omap4iss/iss_ipipeif.c
+++ b/drivers/staging/media/omap4iss/iss_ipipeif.c
@@ -762,7 +762,7 @@ static int ipipeif_init_entities(struct iss_ipipeif_device *ipipeif)
 		return ret;
 
 	/* Connect the IPIPEIF subdev to the video node. */
-	ret = media_entity_create_link(&ipipeif->subdev.entity,
+	ret = media_create_pad_link(&ipipeif->subdev.entity,
 				       IPIPEIF_PAD_SOURCE_ISIF_SF,
 				       &ipipeif->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_resizer.c b/drivers/staging/media/omap4iss/iss_resizer.c
index 91e724085dba..b659e465cb56 100644
--- a/drivers/staging/media/omap4iss/iss_resizer.c
+++ b/drivers/staging/media/omap4iss/iss_resizer.c
@@ -806,7 +806,7 @@ static int resizer_init_entities(struct iss_resizer_device *resizer)
 		return ret;
 
 	/* Connect the RESIZER subdev to the video node. */
-	ret = media_entity_create_link(&resizer->subdev.entity,
+	ret = media_create_pad_link(&resizer->subdev.entity,
 				       RESIZER_PAD_SOURCE_MEM,
 				       &resizer->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index af6646ddf6db..e0e4b014ce62 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -208,7 +208,7 @@ int media_entity_init(struct media_entity *entity, u16 num_pads,
 		struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
 
-int media_entity_create_link(struct media_entity *source, u16 source_pad,
+int media_create_pad_link(struct media_entity *source, u16 source_pad,
 		struct media_entity *sink, u16 sink_pad, u32 flags);
 void __media_entity_remove_links(struct media_entity *entity);
 void media_entity_remove_links(struct media_entity *entity);
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 10/55] [media] media: rename the function that create pad links
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: linux-arm-kernel

With the new API, a link can be either between two PADs or between an interface
and an entity. So, we need to use a better name for the function that create
links between two pads.

So, rename the such function to media_create_pad_link().

No functional changes.

This patch was created via this shell script:
	for i in $(find drivers/media -name '*.[ch]' -type f) $(find drivers/staging/media -name '*.[ch]' -type f) $(find include/ -name '*.h' -type f) ; do sed s,media_entity_create_link,media_create_pad_link,g <$i >a && mv a $i; done

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/Documentation/media-framework.txt b/Documentation/media-framework.txt
index 6903b2503577..b424de6c3bb3 100644
--- a/Documentation/media-framework.txt
+++ b/Documentation/media-framework.txt
@@ -199,7 +199,7 @@ pre-allocated and grows dynamically as needed.
 
 Drivers create links by calling
 
-	media_entity_create_link(struct media_entity *source, u16 source_pad,
+	media_create_pad_link(struct media_entity *source, u16 source_pad,
 				 struct media_entity *sink,   u16 sink_pad,
 				 u32 flags);
 
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 2fdcbb5f000a..65f59f2124b4 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -412,16 +412,16 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	}
 
 	if (tuner && fe)
-		media_entity_create_link(tuner, 0, fe, 0, 0);
+		media_create_pad_link(tuner, 0, fe, 0, 0);
 
 	if (fe && demux)
-		media_entity_create_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && dvr)
-		media_entity_create_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && ca)
-		media_entity_create_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
 }
 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
 #endif
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 6d167428727d..c81bfbfea32f 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1482,11 +1482,11 @@ static int s5c73m3_oif_registered(struct v4l2_subdev *sd)
 		return ret;
 	}
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_ISP_PAD, &state->oif_sd.entity, OIF_ISP_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_JPEG_PAD, &state->oif_sd.entity, OIF_JPEG_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 30a9ca62e034..d3bff30bcb6f 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -1756,7 +1756,7 @@ static int s5k5baf_registered(struct v4l2_subdev *sd)
 		v4l2_err(sd, "failed to register subdev %s\n",
 			 state->cis_sd.name);
 	else
-		ret = media_entity_create_link(&state->cis_sd.entity, PAD_CIS,
+		ret = media_create_pad_link(&state->cis_sd.entity, PAD_CIS,
 					       &state->sd.entity, PAD_CIS,
 					       MEDIA_LNK_FL_IMMUTABLE |
 					       MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 308613ea0aed..5aa49eb393a9 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2495,7 +2495,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 			return rval;
 		}
 
-		rval = media_entity_create_link(&this->sd.entity,
+		rval = media_create_pad_link(&this->sd.entity,
 						this->source_pad,
 						&last->sd.entity,
 						last->sink_pad,
@@ -2503,7 +2503,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 						MEDIA_LNK_FL_IMMUTABLE);
 		if (rval) {
 			dev_err(&client->dev,
-				"media_entity_create_link failed\n");
+				"media_create_pad_link failed\n");
 			return rval;
 		}
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 6d515e149d7f..35e52cd1fc5a 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -542,7 +542,7 @@ static struct media_link *media_entity_add_link(struct media_entity *entity)
 }
 
 int
-media_entity_create_link(struct media_entity *source, u16 source_pad,
+media_create_pad_link(struct media_entity *source, u16 source_pad,
 			 struct media_entity *sink, u16 sink_pad, u32 flags)
 {
 	struct media_link *link;
@@ -586,7 +586,7 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(media_entity_create_link);
+EXPORT_SYMBOL_GPL(media_create_pad_link);
 
 void __media_entity_remove_links(struct media_entity *entity)
 {
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 4f5586a4cbff..3ba76940eef5 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -729,7 +729,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 		flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0;
 
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					      FIMC_SD_PAD_SINK_CAM, flags);
 		if (ret)
 			return ret;
@@ -749,7 +749,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 			continue;
 
 		sink = &fmd->fimc_lite[i]->subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					       FLITE_SD_PAD_SINK, 0);
 		if (ret)
 			return ret;
@@ -781,13 +781,13 @@ static int __fimc_md_create_flite_source_links(struct fimc_md *fmd)
 		source = &fimc->subdev.entity;
 		sink = &fimc->ve.vdev.entity;
 		/* FIMC-LITE's subdev and video node */
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_DMA,
 					       sink, 0, 0);
 		if (ret)
 			break;
 		/* Link from FIMC-LITE to IS-ISP subdev */
 		sink = &fmd->fimc_is->isp.subdev.entity;
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_ISP,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_ISP,
 					       sink, 0, 0);
 		if (ret)
 			break;
@@ -811,7 +811,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 
 		/* Link from FIMC-IS-ISP subdev to FIMC */
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
+		ret = media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
 					       sink, FIMC_SD_PAD_SINK_FIFO, 0);
 		if (ret)
 			return ret;
@@ -824,7 +824,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 	if (sink->num_pads == 0)
 		return 0;
 
-	return media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
+	return media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
 					sink, 0, 0);
 }
 
@@ -873,7 +873,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 				return -EINVAL;
 
 			pad = sensor->entity.num_pads - 1;
-			ret = media_entity_create_link(&sensor->entity, pad,
+			ret = media_create_pad_link(&sensor->entity, pad,
 					      &csis->entity, CSIS_PAD_SINK,
 					      MEDIA_LNK_FL_IMMUTABLE |
 					      MEDIA_LNK_FL_ENABLED);
@@ -927,7 +927,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 		source = &fmd->fimc[i]->vid_cap.subdev.entity;
 		sink = &fmd->fimc[i]->vid_cap.ve.vdev.entity;
 
-		ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE,
+		ret = media_create_pad_link(source, FIMC_SD_PAD_SOURCE,
 					      sink, 0, flags);
 		if (ret)
 			break;
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index e08183f9d0f7..6351f35b0a65 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -1865,7 +1865,7 @@ static int isp_link_entity(
 		return -EINVAL;
 	}
 
-	return media_entity_create_link(entity, i, input, pad, flags);
+	return media_create_pad_link(entity, i, input, pad, flags);
 }
 
 static int isp_register_entities(struct isp_device *isp)
@@ -2004,51 +2004,51 @@ static int isp_initialize_modules(struct isp_device *isp)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_aewb.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_af.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_hist.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c
index d96e3be5e252..27555e4f4aa8 100644
--- a/drivers/media/platform/omap3isp/ispccdc.c
+++ b/drivers/media/platform/omap3isp/ispccdc.c
@@ -2667,7 +2667,7 @@ static int ccdc_init_entities(struct isp_ccdc_device *ccdc)
 		goto error_video;
 
 	/* Connect the CCDC subdev to the video node. */
-	ret = media_entity_create_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
+	ret = media_create_pad_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
 			&ccdc->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c
index e1b5f5bea541..b215eb5049d6 100644
--- a/drivers/media/platform/omap3isp/ispccp2.c
+++ b/drivers/media/platform/omap3isp/ispccp2.c
@@ -1100,7 +1100,7 @@ static int ccp2_init_entities(struct isp_ccp2_device *ccp2)
 		goto error_video;
 
 	/* Connect the video node to the ccp2 subdev. */
-	ret = media_entity_create_link(&ccp2->video_in.video.entity, 0,
+	ret = media_create_pad_link(&ccp2->video_in.video.entity, 0,
 				       &ccp2->subdev.entity, CCP2_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispcsi2.c b/drivers/media/platform/omap3isp/ispcsi2.c
index 6fff92f0813a..fcefc1e74881 100644
--- a/drivers/media/platform/omap3isp/ispcsi2.c
+++ b/drivers/media/platform/omap3isp/ispcsi2.c
@@ -1265,7 +1265,7 @@ static int csi2_init_entities(struct isp_csi2_device *csi2)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/isppreview.c b/drivers/media/platform/omap3isp/isppreview.c
index b440c6342ca4..ad38d20c7770 100644
--- a/drivers/media/platform/omap3isp/isppreview.c
+++ b/drivers/media/platform/omap3isp/isppreview.c
@@ -2312,12 +2312,12 @@ static int preview_init_entities(struct isp_prev_device *prev)
 		goto error_video_out;
 
 	/* Connect the video nodes to the previewer subdev. */
-	ret = media_entity_create_link(&prev->video_in.video.entity, 0,
+	ret = media_create_pad_link(&prev->video_in.video.entity, 0,
 			&prev->subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&prev->subdev.entity, PREV_PAD_SOURCE,
+	ret = media_create_pad_link(&prev->subdev.entity, PREV_PAD_SOURCE,
 			&prev->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispresizer.c b/drivers/media/platform/omap3isp/ispresizer.c
index 3deb1ec4a973..b48ad4d4b834 100644
--- a/drivers/media/platform/omap3isp/ispresizer.c
+++ b/drivers/media/platform/omap3isp/ispresizer.c
@@ -1756,12 +1756,12 @@ static int resizer_init_entities(struct isp_res_device *res)
 	res->video_out.video.entity.flags |= MEDIA_ENT_FL_DEFAULT;
 
 	/* Connect the video nodes to the resizer subdev. */
-	ret = media_entity_create_link(&res->video_in.video.entity, 0,
+	ret = media_create_pad_link(&res->video_in.video.entity, 0,
 			&res->subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&res->subdev.entity, RESZ_PAD_SOURCE,
+	ret = media_create_pad_link(&res->subdev.entity, RESZ_PAD_SOURCE,
 			&res->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c
index f47b332f0418..3e33c60be004 100644
--- a/drivers/media/platform/s3c-camif/camif-core.c
+++ b/drivers/media/platform/s3c-camif/camif-core.c
@@ -263,7 +263,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 {
 	int i, ret;
 
-	ret = media_entity_create_link(&camif->sensor.sd->entity, 0,
+	ret = media_create_pad_link(&camif->sensor.sd->entity, 0,
 				&camif->subdev.entity, CAMIF_SD_PAD_SINK,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
@@ -271,7 +271,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 		return ret;
 
 	for (i = 1; i < CAMIF_SD_PADS_NUM && !ret; i++) {
-		ret = media_entity_create_link(&camif->subdev.entity, i,
+		ret = media_create_pad_link(&camif->subdev.entity, i,
 				&camif->vp[i - 1].vdev.entity, 0,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
index 4e61886384e3..9cd94a76a9ed 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -101,7 +101,7 @@ static int vsp1_create_links(struct vsp1_device *vsp1, struct vsp1_entity *sink)
 			if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
 				continue;
 
-			ret = media_entity_create_link(&source->subdev.entity,
+			ret = media_create_pad_link(&source->subdev.entity,
 						       source->source_pad,
 						       entity, pad, flags);
 			if (ret < 0)
@@ -262,7 +262,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 	}
 
 	if (vsp1->pdata.features & VSP1_HAS_LIF) {
-		ret = media_entity_create_link(
+		ret = media_create_pad_link(
 			&vsp1->wpf[0]->entity.subdev.entity, RWPF_PAD_SOURCE,
 			&vsp1->lif->entity.subdev.entity, LIF_PAD_SINK, 0);
 		if (ret < 0)
diff --git a/drivers/media/platform/vsp1/vsp1_rpf.c b/drivers/media/platform/vsp1/vsp1_rpf.c
index 3294529a3108..b60a528a8fe8 100644
--- a/drivers/media/platform/vsp1/vsp1_rpf.c
+++ b/drivers/media/platform/vsp1/vsp1_rpf.c
@@ -278,7 +278,7 @@ struct vsp1_rwpf *vsp1_rpf_create(struct vsp1_device *vsp1, unsigned int index)
 	rpf->entity.video = video;
 
 	/* Connect the video device to the RPF. */
-	ret = media_entity_create_link(&rpf->video.video.entity, 0,
+	ret = media_create_pad_link(&rpf->video.video.entity, 0,
 				       &rpf->entity.subdev.entity,
 				       RWPF_PAD_SINK,
 				       MEDIA_LNK_FL_ENABLED |
diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c b/drivers/media/platform/vsp1/vsp1_wpf.c
index 1d2b3a2f1573..d39aa4b8aea1 100644
--- a/drivers/media/platform/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/vsp1/vsp1_wpf.c
@@ -284,7 +284,7 @@ struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index)
 	if (!(vsp1->pdata.features & VSP1_HAS_LIF) || index != 0)
 		flags |= MEDIA_LNK_FL_IMMUTABLE;
 
-	ret = media_entity_create_link(&wpf->entity.subdev.entity,
+	ret = media_create_pad_link(&wpf->entity.subdev.entity,
 				       RWPF_PAD_SOURCE,
 				       &wpf->video.video.entity, 0, flags);
 	if (ret < 0)
diff --git a/drivers/media/platform/xilinx/xilinx-vipp.c b/drivers/media/platform/xilinx/xilinx-vipp.c
index 7b7cb9c28d2c..79d4be7ce9a5 100644
--- a/drivers/media/platform/xilinx/xilinx-vipp.c
+++ b/drivers/media/platform/xilinx/xilinx-vipp.c
@@ -156,7 +156,7 @@ static int xvip_graph_build_one(struct xvip_composite_device *xdev,
 			local->name, local_pad->index,
 			remote->name, remote_pad->index);
 
-		ret = media_entity_create_link(local, local_pad->index,
+		ret = media_create_pad_link(local, local_pad->index,
 					       remote, remote_pad->index,
 					       link_flags);
 		if (ret < 0) {
@@ -270,7 +270,7 @@ static int xvip_graph_build_dma(struct xvip_composite_device *xdev)
 			source->name, source_pad->index,
 			sink->name, sink_pad->index);
 
-		ret = media_entity_create_link(source, source_pad->index,
+		ret = media_create_pad_link(source, source_pad->index,
 					       sink, sink_pad->index,
 					       link_flags);
 		if (ret < 0) {
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 0378a2c99ebb..a55eb524ea21 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -260,13 +260,13 @@ static void au0828_create_media_graph(struct au0828_dev *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
 	if (dev->vdev.entity.links)
-		media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+		media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 	if (dev->vbi_dev.entity.links)
-		media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+		media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 4a117a58c39a..3b5c9ae39ad3 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1264,11 +1264,11 @@ static void cx231xx_create_media_graph(struct cx231xx *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+	media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+	media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
index 245445491516..429e428ccd93 100644
--- a/drivers/media/usb/uvc/uvc_entity.c
+++ b/drivers/media/usb/uvc/uvc_entity.c
@@ -56,7 +56,7 @@ static int uvc_mc_register_entity(struct uvc_video_chain *chain,
 			continue;
 
 		remote_pad = remote->num_pads - 1;
-		ret = media_entity_create_link(source, remote_pad,
+		ret = media_create_pad_link(source, remote_pad,
 					       sink, i, flags);
 		if (ret < 0)
 			return ret;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
index 8fb676186898..d96bdaaae50e 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
@@ -971,7 +971,7 @@ vpfe_ipipeif_register_entities(struct vpfe_ipipeif_device *ipipeif,
 	ipipeif->video_in.vpfe_dev = vpfe_dev;
 
 	flags = 0;
-	ret = media_entity_create_link(&ipipeif->video_in.video_dev.entity, 0,
+	ret = media_create_pad_link(&ipipeif->video_in.video_dev.entity, 0,
 					&ipipeif->subdev.entity, 0, flags);
 	if (ret < 0)
 		goto fail;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index b1f01adfa7c8..df77288b0ec0 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -1817,7 +1817,7 @@ int vpfe_isif_register_entities(struct vpfe_isif_device *isif,
 	isif->video_out.vpfe_dev = vpfe_dev;
 	flags = 0;
 	/* connect isif to video node */
-	ret = media_entity_create_link(&isif->subdev.entity, 1,
+	ret = media_create_pad_link(&isif->subdev.entity, 1,
 				       &isif->video_out.video_dev.entity,
 				       0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index 692789aa22f4..ae942de3a23d 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -1831,27 +1831,27 @@ int vpfe_resizer_register_entities(struct vpfe_resizer_device *resizer,
 	resizer->resizer_b.video_out.vpfe_dev = vpfe_dev;
 
 	/* create link between Resizer Crop----> Resizer A*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 1,
 				&resizer->resizer_a.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer Crop----> Resizer B*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 2,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 2,
 				&resizer->resizer_b.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer A ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_a.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_a.subdev.entity, 1,
 		&resizer->resizer_a.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer B ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_b.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_b.subdev.entity, 1,
 		&resizer->resizer_b.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
index 57426199ad7a..08c8a5f967d3 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
@@ -445,32 +445,32 @@ static int vpfe_register_entities(struct vpfe_device *vpfe_dev)
 		/* if entity has no pads (ex: amplifier),
 		   cant establish link */
 		if (vpfe_dev->sd[i]->entity.num_pads) {
-			ret = media_entity_create_link(&vpfe_dev->sd[i]->entity,
+			ret = media_create_pad_link(&vpfe_dev->sd[i]->entity,
 				0, &vpfe_dev->vpfe_isif.subdev.entity,
 				0, flags);
 			if (ret < 0)
 				goto out_resizer_register;
 		}
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipeif.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipe.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
 			1, &vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 			&vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index e54a7afd31de..7226553ceb2f 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -1259,7 +1259,7 @@ static int iss_register_entities(struct iss_device *iss)
 			goto done;
 		}
 
-		ret = media_entity_create_link(&sensor->entity, 0, input, pad,
+		ret = media_create_pad_link(&sensor->entity, 0, input, pad,
 					       flags);
 		if (ret < 0)
 			goto done;
@@ -1317,31 +1317,31 @@ static int iss_initialize_modules(struct iss_device *iss)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2b.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_csi2.c b/drivers/staging/media/omap4iss/iss_csi2.c
index e936cfc218cb..6b4dcbfa9425 100644
--- a/drivers/staging/media/omap4iss/iss_csi2.c
+++ b/drivers/staging/media/omap4iss/iss_csi2.c
@@ -1291,7 +1291,7 @@ static int csi2_init_entities(struct iss_csi2_device *csi2, const char *subname)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/staging/media/omap4iss/iss_ipipeif.c b/drivers/staging/media/omap4iss/iss_ipipeif.c
index be5f80d7b5dc..44c432ef2ac5 100644
--- a/drivers/staging/media/omap4iss/iss_ipipeif.c
+++ b/drivers/staging/media/omap4iss/iss_ipipeif.c
@@ -762,7 +762,7 @@ static int ipipeif_init_entities(struct iss_ipipeif_device *ipipeif)
 		return ret;
 
 	/* Connect the IPIPEIF subdev to the video node. */
-	ret = media_entity_create_link(&ipipeif->subdev.entity,
+	ret = media_create_pad_link(&ipipeif->subdev.entity,
 				       IPIPEIF_PAD_SOURCE_ISIF_SF,
 				       &ipipeif->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_resizer.c b/drivers/staging/media/omap4iss/iss_resizer.c
index 91e724085dba..b659e465cb56 100644
--- a/drivers/staging/media/omap4iss/iss_resizer.c
+++ b/drivers/staging/media/omap4iss/iss_resizer.c
@@ -806,7 +806,7 @@ static int resizer_init_entities(struct iss_resizer_device *resizer)
 		return ret;
 
 	/* Connect the RESIZER subdev to the video node. */
-	ret = media_entity_create_link(&resizer->subdev.entity,
+	ret = media_create_pad_link(&resizer->subdev.entity,
 				       RESIZER_PAD_SOURCE_MEM,
 				       &resizer->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index af6646ddf6db..e0e4b014ce62 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -208,7 +208,7 @@ int media_entity_init(struct media_entity *entity, u16 num_pads,
 		struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
 
-int media_entity_create_link(struct media_entity *source, u16 source_pad,
+int media_create_pad_link(struct media_entity *source, u16 source_pad,
 		struct media_entity *sink, u16 sink_pad, u32 flags);
 void __media_entity_remove_links(struct media_entity *entity);
 void media_entity_remove_links(struct media_entity *entity);
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 11/55] [media] media: use entity.graph_obj.mdev instead of .parent
  2015-08-30  3:06 ` Mauro Carvalho Chehab
  (?)
  (?)
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: linux-arm-kernel

From: Javier Martinez Canillas <javier@osg.samsung.com>

The struct media_entity has a .parent field that stores a pointer
to the parent struct media_device. But recently a media_gobj was
embedded into the entities and since struct media_gojb already has
a pointer to a struct media_device in the .mdev field, the .parent
field becomes redundant and can be removed.

This patch replaces all the usage of .parent by .graph_obj.mdev so
that field will become unused and can be removed on a later patch.

No functional changes.

The transformation was made using the following coccinelle spatch:

@@
struct media_entity *me;
@@

- me->parent
+ me->graph_obj.mdev

@@
struct media_entity *link;
@@

- link->source->entity->parent
+ link->source->entity->graph_obj.mdev

@@
struct exynos_video_entity *ve;
@@

- ve->vdev.entity.parent
+ ve->vdev.entity.graph_obj.mdev

Suggested-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 0f3844470147..138b18416460 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -435,8 +435,8 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	int i;
 
 	/* Warn if we apparently re-register an entity */
-	WARN_ON(entity->parent != NULL);
-	entity->parent = mdev;
+	WARN_ON(entity->graph_obj.mdev != NULL);
+	entity->graph_obj.mdev = mdev;
 
 	spin_lock(&mdev->lock);
 	/* Initialize media_gobj embedded at the entity */
@@ -471,7 +471,7 @@ EXPORT_SYMBOL_GPL(media_device_register_entity);
 void media_device_unregister_entity(struct media_entity *entity)
 {
 	int i;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 
 	if (mdev = NULL)
 		return;
@@ -484,7 +484,7 @@ void media_device_unregister_entity(struct media_entity *entity)
 	media_gobj_remove(&entity->graph_obj);
 	list_del(&entity->list);
 	spin_unlock(&mdev->lock);
-	entity->parent = NULL;
+	entity->graph_obj.mdev = NULL;
 }
 EXPORT_SYMBOL_GPL(media_device_unregister_entity);
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 35e52cd1fc5a..a23c93369a04 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -332,7 +332,7 @@ EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
 __must_check int media_entity_pipeline_start(struct media_entity *entity,
 					     struct media_pipeline *pipe)
 {
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph graph;
 	struct media_entity *entity_err = entity;
 	int ret;
@@ -387,7 +387,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 
 			ret = entity->ops->link_validate(link);
 			if (ret < 0 && ret != -ENOIOCTLCMD) {
-				dev_dbg(entity->parent->dev,
+				dev_dbg(entity->graph_obj.mdev->dev,
 					"link validation failed for \"%s\":%u -> \"%s\":%u, error %d\n",
 					link->source->entity->name,
 					link->source->index,
@@ -401,7 +401,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 
 		if (!bitmap_full(active, entity->num_pads)) {
 			ret = -EPIPE;
-			dev_dbg(entity->parent->dev,
+			dev_dbg(entity->graph_obj.mdev->dev,
 				"\"%s\":%u must be connected by an enabled link\n",
 				entity->name,
 				(unsigned)find_first_zero_bit(
@@ -454,7 +454,7 @@ EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
  */
 void media_entity_pipeline_stop(struct media_entity *entity)
 {
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph graph;
 
 	mutex_lock(&mdev->graph_mutex);
@@ -490,8 +490,8 @@ struct media_entity *media_entity_get(struct media_entity *entity)
 	if (entity = NULL)
 		return NULL;
 
-	if (entity->parent->dev &&
-	    !try_module_get(entity->parent->dev->driver->owner))
+	if (entity->graph_obj.mdev->dev &&
+	    !try_module_get(entity->graph_obj.mdev->dev->driver->owner))
 		return NULL;
 
 	return entity;
@@ -511,8 +511,8 @@ void media_entity_put(struct media_entity *entity)
 	if (entity = NULL)
 		return;
 
-	if (entity->parent->dev)
-		module_put(entity->parent->dev->driver->owner);
+	if (entity->graph_obj.mdev->dev)
+		module_put(entity->graph_obj.mdev->dev->driver->owner);
 }
 EXPORT_SYMBOL_GPL(media_entity_put);
 
@@ -561,7 +561,8 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	link->flags = flags;
 
 	/* Initialize graph object embedded at the new link */
-	media_gobj_init(source->parent, MEDIA_GRAPH_LINK, &link->graph_obj);
+	media_gobj_init(source->graph_obj.mdev, MEDIA_GRAPH_LINK,
+			&link->graph_obj);
 
 	/* Create the backlink. Backlinks are used to help graph traversal and
 	 * are not reported to userspace.
@@ -577,7 +578,8 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	backlink->flags = flags;
 
 	/* Initialize graph object embedded at the new link */
-	media_gobj_init(sink->parent, MEDIA_GRAPH_LINK, &backlink->graph_obj);
+	media_gobj_init(sink->graph_obj.mdev, MEDIA_GRAPH_LINK,
+			&backlink->graph_obj);
 
 	link->reverse = backlink;
 	backlink->reverse = link;
@@ -629,12 +631,12 @@ EXPORT_SYMBOL_GPL(__media_entity_remove_links);
 void media_entity_remove_links(struct media_entity *entity)
 {
 	/* Do nothing if the entity is not registered. */
-	if (entity->parent = NULL)
+	if (entity->graph_obj.mdev = NULL)
 		return;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 	__media_entity_remove_links(entity);
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_entity_remove_links);
 
@@ -703,7 +705,7 @@ int __media_entity_setup_link(struct media_link *link, u32 flags)
 	    (source->stream_count || sink->stream_count))
 		return -EBUSY;
 
-	mdev = source->parent;
+	mdev = source->graph_obj.mdev;
 
 	if (mdev->link_notify) {
 		ret = mdev->link_notify(link, flags,
@@ -724,9 +726,9 @@ int media_entity_setup_link(struct media_link *link, u32 flags)
 {
 	int ret;
 
-	mutex_lock(&link->source->entity->parent->graph_mutex);
+	mutex_lock(&link->source->entity->graph_obj.mdev->graph_mutex);
 	ret = __media_entity_setup_link(link, flags);
-	mutex_unlock(&link->source->entity->parent->graph_mutex);
+	mutex_unlock(&link->source->entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index b7dc5ac66e36..3d9ccbf5f10f 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -288,7 +288,7 @@ static int isp_video_open(struct file *file)
 		goto rel_fh;
 
 	if (v4l2_fh_is_singular_file(file)) {
-		mutex_lock(&me->parent->graph_mutex);
+		mutex_lock(&me->graph_obj.mdev->graph_mutex);
 
 		ret = fimc_pipeline_call(ve, open, me, true);
 
@@ -296,7 +296,7 @@ static int isp_video_open(struct file *file)
 		if (ret = 0)
 			me->use_count++;
 
-		mutex_unlock(&me->parent->graph_mutex);
+		mutex_unlock(&me->graph_obj.mdev->graph_mutex);
 	}
 	if (!ret)
 		goto unlock;
@@ -312,7 +312,7 @@ static int isp_video_release(struct file *file)
 	struct fimc_isp *isp = video_drvdata(file);
 	struct fimc_is_video *ivc = &isp->video_capture;
 	struct media_entity *entity = &ivc->ve.vdev.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 
 	mutex_lock(&isp->video_lock);
 
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index e8f707d1729b..b2607da4ad14 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -500,7 +500,7 @@ static int fimc_lite_open(struct file *file)
 	    atomic_read(&fimc->out_path) != FIMC_IO_DMA)
 		goto unlock;
 
-	mutex_lock(&me->parent->graph_mutex);
+	mutex_lock(&me->graph_obj.mdev->graph_mutex);
 
 	ret = fimc_pipeline_call(&fimc->ve, open, me, true);
 
@@ -508,7 +508,7 @@ static int fimc_lite_open(struct file *file)
 	if (ret = 0)
 		me->use_count++;
 
-	mutex_unlock(&me->parent->graph_mutex);
+	mutex_unlock(&me->graph_obj.mdev->graph_mutex);
 
 	if (!ret) {
 		fimc_lite_clear_event_counters(fimc);
@@ -541,9 +541,9 @@ static int fimc_lite_release(struct file *file)
 		fimc_pipeline_call(&fimc->ve, close);
 		clear_bit(ST_FLITE_IN_USE, &fimc->state);
 
-		mutex_lock(&entity->parent->graph_mutex);
+		mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 		entity->use_count--;
-		mutex_unlock(&entity->parent->graph_mutex);
+		mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 	}
 
 	_vb2_fop_release(file, NULL);
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 3ba76940eef5..92dbade2fffc 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -1046,7 +1046,7 @@ static int __fimc_md_modify_pipeline(struct media_entity *entity, bool enable)
 	return ret;
 }
 
-/* Locking: called with entity->parent->graph_mutex mutex held. */
+/* Locking: called with entity->graph_obj.mdev->graph_mutex mutex held. */
 static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
 {
 	struct media_entity *entity_err = entity;
diff --git a/drivers/media/platform/exynos4-is/media-dev.h b/drivers/media/platform/exynos4-is/media-dev.h
index 03214541f149..9a69913b31cb 100644
--- a/drivers/media/platform/exynos4-is/media-dev.h
+++ b/drivers/media/platform/exynos4-is/media-dev.h
@@ -164,8 +164,8 @@ struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si)
 
 static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
 {
-	return me->parent = NULL ? NULL :
-		container_of(me->parent, struct fimc_md, media_dev);
+	return me->graph_obj.mdev = NULL ? NULL :
+		container_of(me->graph_obj.mdev, struct fimc_md, media_dev);
 }
 
 static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n)
@@ -175,12 +175,12 @@ static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n)
 
 static inline void fimc_md_graph_lock(struct exynos_video_entity *ve)
 {
-	mutex_lock(&ve->vdev.entity.parent->graph_mutex);
+	mutex_lock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
 }
 
 static inline void fimc_md_graph_unlock(struct exynos_video_entity *ve)
 {
-	mutex_unlock(&ve->vdev.entity.parent->graph_mutex);
+	mutex_unlock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
 }
 
 int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 6351f35b0a65..aa13b17d19a0 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -787,7 +787,7 @@ int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
 	int change = use ? 1 : -1;
 	int ret;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 
 	/* Apply use count to node. */
 	entity->use_count += change;
@@ -798,7 +798,7 @@ int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
 	if (ret < 0)
 		entity->use_count -= change;
 
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 6c89dc40df85..4c367352b1f7 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -226,7 +226,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct isp_video *far_end = NULL;
 
 	mutex_lock(&mdev->graph_mutex);
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index debe4e539df6..1f94c1a54e00 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -409,7 +409,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	unsigned int i;
 	int ret;
 
diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index f7f9aa353a55..92e8116dc28f 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -181,7 +181,7 @@ static int xvip_pipeline_validate(struct xvip_pipeline *pipe,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &start->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	unsigned int num_inputs = 0;
 	unsigned int num_outputs = 0;
 
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 61a8d5beff58..92573fa852a9 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -130,7 +130,7 @@ __vpfe_video_get_format(struct vpfe_video_device *video,
 static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
 {
 	struct media_entity *entity = &video->video_dev.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct vpfe_pipeline *pipe = &video->pipe;
 	struct vpfe_video_device *far_end = NULL;
 	struct media_entity_graph graph;
@@ -288,7 +288,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
 	else
 		entity = &pipe->inputs[0]->video_dev.entity;
 
-	mdev = entity->parent;
+	mdev = entity->graph_obj.mdev;
 	mutex_lock(&mdev->graph_mutex);
 	media_entity_graph_walk_start(&graph, entity);
 	while ((entity = media_entity_graph_walk_next(&graph))) {
@@ -328,7 +328,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
 	else
 		entity = &pipe->inputs[0]->video_dev.entity;
 
-	mdev = entity->parent;
+	mdev = entity->graph_obj.mdev;
 	mutex_lock(&mdev->graph_mutex);
 	media_entity_graph_walk_start(&graph, entity);
 
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 7226553ceb2f..40591963b42b 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -494,7 +494,7 @@ int omap4iss_pipeline_pm_use(struct media_entity *entity, int use)
 	int change = use ? 1 : -1;
 	int ret;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 
 	/* Apply use count to node. */
 	entity->use_count += change;
@@ -505,7 +505,7 @@ int omap4iss_pipeline_pm_use(struct media_entity *entity, int use)
 	if (ret < 0)
 		entity->use_count -= change;
 
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
index 25e9e7a6b99d..45a3f2d778fc 100644
--- a/drivers/staging/media/omap4iss/iss_video.c
+++ b/drivers/staging/media/omap4iss/iss_video.c
@@ -207,7 +207,7 @@ iss_video_far_end(struct iss_video *video)
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct iss_video *far_end = NULL;
 
 	mutex_lock(&mdev->graph_mutex);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 11/55] [media] media: use entity.graph_obj.mdev instead of .parent
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Javier Martinez Canillas, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Kukjin Kim, Krzysztof Kozlowski,
	Laurent Pinchart, Hyun Kwon, Michal Simek, Sören Brinkmann,
	Greg Kroah-Hartman, Hans Verkuil, Prabhakar Lad, Sakari Ailus,
	linux-arm-kernel, linux-samsung-soc, linux-sh, devel,
	Mauro Carvalho Chehab

From: Javier Martinez Canillas <javier@osg.samsung.com>

The struct media_entity has a .parent field that stores a pointer
to the parent struct media_device. But recently a media_gobj was
embedded into the entities and since struct media_gojb already has
a pointer to a struct media_device in the .mdev field, the .parent
field becomes redundant and can be removed.

This patch replaces all the usage of .parent by .graph_obj.mdev so
that field will become unused and can be removed on a later patch.

No functional changes.

The transformation was made using the following coccinelle spatch:

@@
struct media_entity *me;
@@

- me->parent
+ me->graph_obj.mdev

@@
struct media_entity *link;
@@

- link->source->entity->parent
+ link->source->entity->graph_obj.mdev

@@
struct exynos_video_entity *ve;
@@

- ve->vdev.entity.parent
+ ve->vdev.entity.graph_obj.mdev

Suggested-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 0f3844470147..138b18416460 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -435,8 +435,8 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	int i;
 
 	/* Warn if we apparently re-register an entity */
-	WARN_ON(entity->parent != NULL);
-	entity->parent = mdev;
+	WARN_ON(entity->graph_obj.mdev != NULL);
+	entity->graph_obj.mdev = mdev;
 
 	spin_lock(&mdev->lock);
 	/* Initialize media_gobj embedded at the entity */
@@ -471,7 +471,7 @@ EXPORT_SYMBOL_GPL(media_device_register_entity);
 void media_device_unregister_entity(struct media_entity *entity)
 {
 	int i;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 
 	if (mdev == NULL)
 		return;
@@ -484,7 +484,7 @@ void media_device_unregister_entity(struct media_entity *entity)
 	media_gobj_remove(&entity->graph_obj);
 	list_del(&entity->list);
 	spin_unlock(&mdev->lock);
-	entity->parent = NULL;
+	entity->graph_obj.mdev = NULL;
 }
 EXPORT_SYMBOL_GPL(media_device_unregister_entity);
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 35e52cd1fc5a..a23c93369a04 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -332,7 +332,7 @@ EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
 __must_check int media_entity_pipeline_start(struct media_entity *entity,
 					     struct media_pipeline *pipe)
 {
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph graph;
 	struct media_entity *entity_err = entity;
 	int ret;
@@ -387,7 +387,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 
 			ret = entity->ops->link_validate(link);
 			if (ret < 0 && ret != -ENOIOCTLCMD) {
-				dev_dbg(entity->parent->dev,
+				dev_dbg(entity->graph_obj.mdev->dev,
 					"link validation failed for \"%s\":%u -> \"%s\":%u, error %d\n",
 					link->source->entity->name,
 					link->source->index,
@@ -401,7 +401,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 
 		if (!bitmap_full(active, entity->num_pads)) {
 			ret = -EPIPE;
-			dev_dbg(entity->parent->dev,
+			dev_dbg(entity->graph_obj.mdev->dev,
 				"\"%s\":%u must be connected by an enabled link\n",
 				entity->name,
 				(unsigned)find_first_zero_bit(
@@ -454,7 +454,7 @@ EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
  */
 void media_entity_pipeline_stop(struct media_entity *entity)
 {
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph graph;
 
 	mutex_lock(&mdev->graph_mutex);
@@ -490,8 +490,8 @@ struct media_entity *media_entity_get(struct media_entity *entity)
 	if (entity == NULL)
 		return NULL;
 
-	if (entity->parent->dev &&
-	    !try_module_get(entity->parent->dev->driver->owner))
+	if (entity->graph_obj.mdev->dev &&
+	    !try_module_get(entity->graph_obj.mdev->dev->driver->owner))
 		return NULL;
 
 	return entity;
@@ -511,8 +511,8 @@ void media_entity_put(struct media_entity *entity)
 	if (entity == NULL)
 		return;
 
-	if (entity->parent->dev)
-		module_put(entity->parent->dev->driver->owner);
+	if (entity->graph_obj.mdev->dev)
+		module_put(entity->graph_obj.mdev->dev->driver->owner);
 }
 EXPORT_SYMBOL_GPL(media_entity_put);
 
@@ -561,7 +561,8 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	link->flags = flags;
 
 	/* Initialize graph object embedded at the new link */
-	media_gobj_init(source->parent, MEDIA_GRAPH_LINK, &link->graph_obj);
+	media_gobj_init(source->graph_obj.mdev, MEDIA_GRAPH_LINK,
+			&link->graph_obj);
 
 	/* Create the backlink. Backlinks are used to help graph traversal and
 	 * are not reported to userspace.
@@ -577,7 +578,8 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	backlink->flags = flags;
 
 	/* Initialize graph object embedded at the new link */
-	media_gobj_init(sink->parent, MEDIA_GRAPH_LINK, &backlink->graph_obj);
+	media_gobj_init(sink->graph_obj.mdev, MEDIA_GRAPH_LINK,
+			&backlink->graph_obj);
 
 	link->reverse = backlink;
 	backlink->reverse = link;
@@ -629,12 +631,12 @@ EXPORT_SYMBOL_GPL(__media_entity_remove_links);
 void media_entity_remove_links(struct media_entity *entity)
 {
 	/* Do nothing if the entity is not registered. */
-	if (entity->parent == NULL)
+	if (entity->graph_obj.mdev == NULL)
 		return;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 	__media_entity_remove_links(entity);
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_entity_remove_links);
 
@@ -703,7 +705,7 @@ int __media_entity_setup_link(struct media_link *link, u32 flags)
 	    (source->stream_count || sink->stream_count))
 		return -EBUSY;
 
-	mdev = source->parent;
+	mdev = source->graph_obj.mdev;
 
 	if (mdev->link_notify) {
 		ret = mdev->link_notify(link, flags,
@@ -724,9 +726,9 @@ int media_entity_setup_link(struct media_link *link, u32 flags)
 {
 	int ret;
 
-	mutex_lock(&link->source->entity->parent->graph_mutex);
+	mutex_lock(&link->source->entity->graph_obj.mdev->graph_mutex);
 	ret = __media_entity_setup_link(link, flags);
-	mutex_unlock(&link->source->entity->parent->graph_mutex);
+	mutex_unlock(&link->source->entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index b7dc5ac66e36..3d9ccbf5f10f 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -288,7 +288,7 @@ static int isp_video_open(struct file *file)
 		goto rel_fh;
 
 	if (v4l2_fh_is_singular_file(file)) {
-		mutex_lock(&me->parent->graph_mutex);
+		mutex_lock(&me->graph_obj.mdev->graph_mutex);
 
 		ret = fimc_pipeline_call(ve, open, me, true);
 
@@ -296,7 +296,7 @@ static int isp_video_open(struct file *file)
 		if (ret == 0)
 			me->use_count++;
 
-		mutex_unlock(&me->parent->graph_mutex);
+		mutex_unlock(&me->graph_obj.mdev->graph_mutex);
 	}
 	if (!ret)
 		goto unlock;
@@ -312,7 +312,7 @@ static int isp_video_release(struct file *file)
 	struct fimc_isp *isp = video_drvdata(file);
 	struct fimc_is_video *ivc = &isp->video_capture;
 	struct media_entity *entity = &ivc->ve.vdev.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 
 	mutex_lock(&isp->video_lock);
 
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index e8f707d1729b..b2607da4ad14 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -500,7 +500,7 @@ static int fimc_lite_open(struct file *file)
 	    atomic_read(&fimc->out_path) != FIMC_IO_DMA)
 		goto unlock;
 
-	mutex_lock(&me->parent->graph_mutex);
+	mutex_lock(&me->graph_obj.mdev->graph_mutex);
 
 	ret = fimc_pipeline_call(&fimc->ve, open, me, true);
 
@@ -508,7 +508,7 @@ static int fimc_lite_open(struct file *file)
 	if (ret == 0)
 		me->use_count++;
 
-	mutex_unlock(&me->parent->graph_mutex);
+	mutex_unlock(&me->graph_obj.mdev->graph_mutex);
 
 	if (!ret) {
 		fimc_lite_clear_event_counters(fimc);
@@ -541,9 +541,9 @@ static int fimc_lite_release(struct file *file)
 		fimc_pipeline_call(&fimc->ve, close);
 		clear_bit(ST_FLITE_IN_USE, &fimc->state);
 
-		mutex_lock(&entity->parent->graph_mutex);
+		mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 		entity->use_count--;
-		mutex_unlock(&entity->parent->graph_mutex);
+		mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 	}
 
 	_vb2_fop_release(file, NULL);
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 3ba76940eef5..92dbade2fffc 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -1046,7 +1046,7 @@ static int __fimc_md_modify_pipeline(struct media_entity *entity, bool enable)
 	return ret;
 }
 
-/* Locking: called with entity->parent->graph_mutex mutex held. */
+/* Locking: called with entity->graph_obj.mdev->graph_mutex mutex held. */
 static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
 {
 	struct media_entity *entity_err = entity;
diff --git a/drivers/media/platform/exynos4-is/media-dev.h b/drivers/media/platform/exynos4-is/media-dev.h
index 03214541f149..9a69913b31cb 100644
--- a/drivers/media/platform/exynos4-is/media-dev.h
+++ b/drivers/media/platform/exynos4-is/media-dev.h
@@ -164,8 +164,8 @@ struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si)
 
 static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
 {
-	return me->parent == NULL ? NULL :
-		container_of(me->parent, struct fimc_md, media_dev);
+	return me->graph_obj.mdev == NULL ? NULL :
+		container_of(me->graph_obj.mdev, struct fimc_md, media_dev);
 }
 
 static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n)
@@ -175,12 +175,12 @@ static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n)
 
 static inline void fimc_md_graph_lock(struct exynos_video_entity *ve)
 {
-	mutex_lock(&ve->vdev.entity.parent->graph_mutex);
+	mutex_lock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
 }
 
 static inline void fimc_md_graph_unlock(struct exynos_video_entity *ve)
 {
-	mutex_unlock(&ve->vdev.entity.parent->graph_mutex);
+	mutex_unlock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
 }
 
 int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 6351f35b0a65..aa13b17d19a0 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -787,7 +787,7 @@ int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
 	int change = use ? 1 : -1;
 	int ret;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 
 	/* Apply use count to node. */
 	entity->use_count += change;
@@ -798,7 +798,7 @@ int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
 	if (ret < 0)
 		entity->use_count -= change;
 
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 6c89dc40df85..4c367352b1f7 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -226,7 +226,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct isp_video *far_end = NULL;
 
 	mutex_lock(&mdev->graph_mutex);
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index debe4e539df6..1f94c1a54e00 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -409,7 +409,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	unsigned int i;
 	int ret;
 
diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index f7f9aa353a55..92e8116dc28f 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -181,7 +181,7 @@ static int xvip_pipeline_validate(struct xvip_pipeline *pipe,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &start->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	unsigned int num_inputs = 0;
 	unsigned int num_outputs = 0;
 
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 61a8d5beff58..92573fa852a9 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -130,7 +130,7 @@ __vpfe_video_get_format(struct vpfe_video_device *video,
 static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
 {
 	struct media_entity *entity = &video->video_dev.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct vpfe_pipeline *pipe = &video->pipe;
 	struct vpfe_video_device *far_end = NULL;
 	struct media_entity_graph graph;
@@ -288,7 +288,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
 	else
 		entity = &pipe->inputs[0]->video_dev.entity;
 
-	mdev = entity->parent;
+	mdev = entity->graph_obj.mdev;
 	mutex_lock(&mdev->graph_mutex);
 	media_entity_graph_walk_start(&graph, entity);
 	while ((entity = media_entity_graph_walk_next(&graph))) {
@@ -328,7 +328,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
 	else
 		entity = &pipe->inputs[0]->video_dev.entity;
 
-	mdev = entity->parent;
+	mdev = entity->graph_obj.mdev;
 	mutex_lock(&mdev->graph_mutex);
 	media_entity_graph_walk_start(&graph, entity);
 
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 7226553ceb2f..40591963b42b 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -494,7 +494,7 @@ int omap4iss_pipeline_pm_use(struct media_entity *entity, int use)
 	int change = use ? 1 : -1;
 	int ret;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 
 	/* Apply use count to node. */
 	entity->use_count += change;
@@ -505,7 +505,7 @@ int omap4iss_pipeline_pm_use(struct media_entity *entity, int use)
 	if (ret < 0)
 		entity->use_count -= change;
 
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
index 25e9e7a6b99d..45a3f2d778fc 100644
--- a/drivers/staging/media/omap4iss/iss_video.c
+++ b/drivers/staging/media/omap4iss/iss_video.c
@@ -207,7 +207,7 @@ iss_video_far_end(struct iss_video *video)
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct iss_video *far_end = NULL;
 
 	mutex_lock(&mdev->graph_mutex);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 11/55] [media] media: use entity.graph_obj.mdev instead of .parent
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: linux-arm-kernel, devel, Krzysztof Kozlowski, linux-samsung-soc,
	Sakari Ailus, Hyun Kwon, linux-sh, Greg Kroah-Hartman,
	Mauro Carvalho Chehab, Michal Simek, Mauro Carvalho Chehab,
	Javier Martinez Canillas, Kyungmin Park, Kukjin Kim,
	Hans Verkuil, Laurent Pinchart, Sylwester Nawrocki,
	Prabhakar Lad, Sören Brinkmann

From: Javier Martinez Canillas <javier@osg.samsung.com>

The struct media_entity has a .parent field that stores a pointer
to the parent struct media_device. But recently a media_gobj was
embedded into the entities and since struct media_gojb already has
a pointer to a struct media_device in the .mdev field, the .parent
field becomes redundant and can be removed.

This patch replaces all the usage of .parent by .graph_obj.mdev so
that field will become unused and can be removed on a later patch.

No functional changes.

The transformation was made using the following coccinelle spatch:

@@
struct media_entity *me;
@@

- me->parent
+ me->graph_obj.mdev

@@
struct media_entity *link;
@@

- link->source->entity->parent
+ link->source->entity->graph_obj.mdev

@@
struct exynos_video_entity *ve;
@@

- ve->vdev.entity.parent
+ ve->vdev.entity.graph_obj.mdev

Suggested-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 0f3844470147..138b18416460 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -435,8 +435,8 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	int i;
 
 	/* Warn if we apparently re-register an entity */
-	WARN_ON(entity->parent != NULL);
-	entity->parent = mdev;
+	WARN_ON(entity->graph_obj.mdev != NULL);
+	entity->graph_obj.mdev = mdev;
 
 	spin_lock(&mdev->lock);
 	/* Initialize media_gobj embedded at the entity */
@@ -471,7 +471,7 @@ EXPORT_SYMBOL_GPL(media_device_register_entity);
 void media_device_unregister_entity(struct media_entity *entity)
 {
 	int i;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 
 	if (mdev == NULL)
 		return;
@@ -484,7 +484,7 @@ void media_device_unregister_entity(struct media_entity *entity)
 	media_gobj_remove(&entity->graph_obj);
 	list_del(&entity->list);
 	spin_unlock(&mdev->lock);
-	entity->parent = NULL;
+	entity->graph_obj.mdev = NULL;
 }
 EXPORT_SYMBOL_GPL(media_device_unregister_entity);
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 35e52cd1fc5a..a23c93369a04 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -332,7 +332,7 @@ EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
 __must_check int media_entity_pipeline_start(struct media_entity *entity,
 					     struct media_pipeline *pipe)
 {
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph graph;
 	struct media_entity *entity_err = entity;
 	int ret;
@@ -387,7 +387,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 
 			ret = entity->ops->link_validate(link);
 			if (ret < 0 && ret != -ENOIOCTLCMD) {
-				dev_dbg(entity->parent->dev,
+				dev_dbg(entity->graph_obj.mdev->dev,
 					"link validation failed for \"%s\":%u -> \"%s\":%u, error %d\n",
 					link->source->entity->name,
 					link->source->index,
@@ -401,7 +401,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 
 		if (!bitmap_full(active, entity->num_pads)) {
 			ret = -EPIPE;
-			dev_dbg(entity->parent->dev,
+			dev_dbg(entity->graph_obj.mdev->dev,
 				"\"%s\":%u must be connected by an enabled link\n",
 				entity->name,
 				(unsigned)find_first_zero_bit(
@@ -454,7 +454,7 @@ EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
  */
 void media_entity_pipeline_stop(struct media_entity *entity)
 {
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph graph;
 
 	mutex_lock(&mdev->graph_mutex);
@@ -490,8 +490,8 @@ struct media_entity *media_entity_get(struct media_entity *entity)
 	if (entity == NULL)
 		return NULL;
 
-	if (entity->parent->dev &&
-	    !try_module_get(entity->parent->dev->driver->owner))
+	if (entity->graph_obj.mdev->dev &&
+	    !try_module_get(entity->graph_obj.mdev->dev->driver->owner))
 		return NULL;
 
 	return entity;
@@ -511,8 +511,8 @@ void media_entity_put(struct media_entity *entity)
 	if (entity == NULL)
 		return;
 
-	if (entity->parent->dev)
-		module_put(entity->parent->dev->driver->owner);
+	if (entity->graph_obj.mdev->dev)
+		module_put(entity->graph_obj.mdev->dev->driver->owner);
 }
 EXPORT_SYMBOL_GPL(media_entity_put);
 
@@ -561,7 +561,8 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	link->flags = flags;
 
 	/* Initialize graph object embedded at the new link */
-	media_gobj_init(source->parent, MEDIA_GRAPH_LINK, &link->graph_obj);
+	media_gobj_init(source->graph_obj.mdev, MEDIA_GRAPH_LINK,
+			&link->graph_obj);
 
 	/* Create the backlink. Backlinks are used to help graph traversal and
 	 * are not reported to userspace.
@@ -577,7 +578,8 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	backlink->flags = flags;
 
 	/* Initialize graph object embedded at the new link */
-	media_gobj_init(sink->parent, MEDIA_GRAPH_LINK, &backlink->graph_obj);
+	media_gobj_init(sink->graph_obj.mdev, MEDIA_GRAPH_LINK,
+			&backlink->graph_obj);
 
 	link->reverse = backlink;
 	backlink->reverse = link;
@@ -629,12 +631,12 @@ EXPORT_SYMBOL_GPL(__media_entity_remove_links);
 void media_entity_remove_links(struct media_entity *entity)
 {
 	/* Do nothing if the entity is not registered. */
-	if (entity->parent == NULL)
+	if (entity->graph_obj.mdev == NULL)
 		return;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 	__media_entity_remove_links(entity);
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_entity_remove_links);
 
@@ -703,7 +705,7 @@ int __media_entity_setup_link(struct media_link *link, u32 flags)
 	    (source->stream_count || sink->stream_count))
 		return -EBUSY;
 
-	mdev = source->parent;
+	mdev = source->graph_obj.mdev;
 
 	if (mdev->link_notify) {
 		ret = mdev->link_notify(link, flags,
@@ -724,9 +726,9 @@ int media_entity_setup_link(struct media_link *link, u32 flags)
 {
 	int ret;
 
-	mutex_lock(&link->source->entity->parent->graph_mutex);
+	mutex_lock(&link->source->entity->graph_obj.mdev->graph_mutex);
 	ret = __media_entity_setup_link(link, flags);
-	mutex_unlock(&link->source->entity->parent->graph_mutex);
+	mutex_unlock(&link->source->entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index b7dc5ac66e36..3d9ccbf5f10f 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -288,7 +288,7 @@ static int isp_video_open(struct file *file)
 		goto rel_fh;
 
 	if (v4l2_fh_is_singular_file(file)) {
-		mutex_lock(&me->parent->graph_mutex);
+		mutex_lock(&me->graph_obj.mdev->graph_mutex);
 
 		ret = fimc_pipeline_call(ve, open, me, true);
 
@@ -296,7 +296,7 @@ static int isp_video_open(struct file *file)
 		if (ret == 0)
 			me->use_count++;
 
-		mutex_unlock(&me->parent->graph_mutex);
+		mutex_unlock(&me->graph_obj.mdev->graph_mutex);
 	}
 	if (!ret)
 		goto unlock;
@@ -312,7 +312,7 @@ static int isp_video_release(struct file *file)
 	struct fimc_isp *isp = video_drvdata(file);
 	struct fimc_is_video *ivc = &isp->video_capture;
 	struct media_entity *entity = &ivc->ve.vdev.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 
 	mutex_lock(&isp->video_lock);
 
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index e8f707d1729b..b2607da4ad14 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -500,7 +500,7 @@ static int fimc_lite_open(struct file *file)
 	    atomic_read(&fimc->out_path) != FIMC_IO_DMA)
 		goto unlock;
 
-	mutex_lock(&me->parent->graph_mutex);
+	mutex_lock(&me->graph_obj.mdev->graph_mutex);
 
 	ret = fimc_pipeline_call(&fimc->ve, open, me, true);
 
@@ -508,7 +508,7 @@ static int fimc_lite_open(struct file *file)
 	if (ret == 0)
 		me->use_count++;
 
-	mutex_unlock(&me->parent->graph_mutex);
+	mutex_unlock(&me->graph_obj.mdev->graph_mutex);
 
 	if (!ret) {
 		fimc_lite_clear_event_counters(fimc);
@@ -541,9 +541,9 @@ static int fimc_lite_release(struct file *file)
 		fimc_pipeline_call(&fimc->ve, close);
 		clear_bit(ST_FLITE_IN_USE, &fimc->state);
 
-		mutex_lock(&entity->parent->graph_mutex);
+		mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 		entity->use_count--;
-		mutex_unlock(&entity->parent->graph_mutex);
+		mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 	}
 
 	_vb2_fop_release(file, NULL);
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 3ba76940eef5..92dbade2fffc 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -1046,7 +1046,7 @@ static int __fimc_md_modify_pipeline(struct media_entity *entity, bool enable)
 	return ret;
 }
 
-/* Locking: called with entity->parent->graph_mutex mutex held. */
+/* Locking: called with entity->graph_obj.mdev->graph_mutex mutex held. */
 static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
 {
 	struct media_entity *entity_err = entity;
diff --git a/drivers/media/platform/exynos4-is/media-dev.h b/drivers/media/platform/exynos4-is/media-dev.h
index 03214541f149..9a69913b31cb 100644
--- a/drivers/media/platform/exynos4-is/media-dev.h
+++ b/drivers/media/platform/exynos4-is/media-dev.h
@@ -164,8 +164,8 @@ struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si)
 
 static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
 {
-	return me->parent == NULL ? NULL :
-		container_of(me->parent, struct fimc_md, media_dev);
+	return me->graph_obj.mdev == NULL ? NULL :
+		container_of(me->graph_obj.mdev, struct fimc_md, media_dev);
 }
 
 static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n)
@@ -175,12 +175,12 @@ static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n)
 
 static inline void fimc_md_graph_lock(struct exynos_video_entity *ve)
 {
-	mutex_lock(&ve->vdev.entity.parent->graph_mutex);
+	mutex_lock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
 }
 
 static inline void fimc_md_graph_unlock(struct exynos_video_entity *ve)
 {
-	mutex_unlock(&ve->vdev.entity.parent->graph_mutex);
+	mutex_unlock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
 }
 
 int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 6351f35b0a65..aa13b17d19a0 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -787,7 +787,7 @@ int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
 	int change = use ? 1 : -1;
 	int ret;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 
 	/* Apply use count to node. */
 	entity->use_count += change;
@@ -798,7 +798,7 @@ int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
 	if (ret < 0)
 		entity->use_count -= change;
 
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 6c89dc40df85..4c367352b1f7 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -226,7 +226,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct isp_video *far_end = NULL;
 
 	mutex_lock(&mdev->graph_mutex);
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index debe4e539df6..1f94c1a54e00 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -409,7 +409,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	unsigned int i;
 	int ret;
 
diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index f7f9aa353a55..92e8116dc28f 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -181,7 +181,7 @@ static int xvip_pipeline_validate(struct xvip_pipeline *pipe,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &start->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	unsigned int num_inputs = 0;
 	unsigned int num_outputs = 0;
 
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 61a8d5beff58..92573fa852a9 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -130,7 +130,7 @@ __vpfe_video_get_format(struct vpfe_video_device *video,
 static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
 {
 	struct media_entity *entity = &video->video_dev.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct vpfe_pipeline *pipe = &video->pipe;
 	struct vpfe_video_device *far_end = NULL;
 	struct media_entity_graph graph;
@@ -288,7 +288,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
 	else
 		entity = &pipe->inputs[0]->video_dev.entity;
 
-	mdev = entity->parent;
+	mdev = entity->graph_obj.mdev;
 	mutex_lock(&mdev->graph_mutex);
 	media_entity_graph_walk_start(&graph, entity);
 	while ((entity = media_entity_graph_walk_next(&graph))) {
@@ -328,7 +328,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
 	else
 		entity = &pipe->inputs[0]->video_dev.entity;
 
-	mdev = entity->parent;
+	mdev = entity->graph_obj.mdev;
 	mutex_lock(&mdev->graph_mutex);
 	media_entity_graph_walk_start(&graph, entity);
 
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 7226553ceb2f..40591963b42b 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -494,7 +494,7 @@ int omap4iss_pipeline_pm_use(struct media_entity *entity, int use)
 	int change = use ? 1 : -1;
 	int ret;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 
 	/* Apply use count to node. */
 	entity->use_count += change;
@@ -505,7 +505,7 @@ int omap4iss_pipeline_pm_use(struct media_entity *entity, int use)
 	if (ret < 0)
 		entity->use_count -= change;
 
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
index 25e9e7a6b99d..45a3f2d778fc 100644
--- a/drivers/staging/media/omap4iss/iss_video.c
+++ b/drivers/staging/media/omap4iss/iss_video.c
@@ -207,7 +207,7 @@ iss_video_far_end(struct iss_video *video)
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct iss_video *far_end = NULL;
 
 	mutex_lock(&mdev->graph_mutex);
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 11/55] [media] media: use entity.graph_obj.mdev instead of .parent
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: linux-arm-kernel

From: Javier Martinez Canillas <javier@osg.samsung.com>

The struct media_entity has a .parent field that stores a pointer
to the parent struct media_device. But recently a media_gobj was
embedded into the entities and since struct media_gojb already has
a pointer to a struct media_device in the .mdev field, the .parent
field becomes redundant and can be removed.

This patch replaces all the usage of .parent by .graph_obj.mdev so
that field will become unused and can be removed on a later patch.

No functional changes.

The transformation was made using the following coccinelle spatch:

@@
struct media_entity *me;
@@

- me->parent
+ me->graph_obj.mdev

@@
struct media_entity *link;
@@

- link->source->entity->parent
+ link->source->entity->graph_obj.mdev

@@
struct exynos_video_entity *ve;
@@

- ve->vdev.entity.parent
+ ve->vdev.entity.graph_obj.mdev

Suggested-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 0f3844470147..138b18416460 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -435,8 +435,8 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	int i;
 
 	/* Warn if we apparently re-register an entity */
-	WARN_ON(entity->parent != NULL);
-	entity->parent = mdev;
+	WARN_ON(entity->graph_obj.mdev != NULL);
+	entity->graph_obj.mdev = mdev;
 
 	spin_lock(&mdev->lock);
 	/* Initialize media_gobj embedded at the entity */
@@ -471,7 +471,7 @@ EXPORT_SYMBOL_GPL(media_device_register_entity);
 void media_device_unregister_entity(struct media_entity *entity)
 {
 	int i;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 
 	if (mdev == NULL)
 		return;
@@ -484,7 +484,7 @@ void media_device_unregister_entity(struct media_entity *entity)
 	media_gobj_remove(&entity->graph_obj);
 	list_del(&entity->list);
 	spin_unlock(&mdev->lock);
-	entity->parent = NULL;
+	entity->graph_obj.mdev = NULL;
 }
 EXPORT_SYMBOL_GPL(media_device_unregister_entity);
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 35e52cd1fc5a..a23c93369a04 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -332,7 +332,7 @@ EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
 __must_check int media_entity_pipeline_start(struct media_entity *entity,
 					     struct media_pipeline *pipe)
 {
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph graph;
 	struct media_entity *entity_err = entity;
 	int ret;
@@ -387,7 +387,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 
 			ret = entity->ops->link_validate(link);
 			if (ret < 0 && ret != -ENOIOCTLCMD) {
-				dev_dbg(entity->parent->dev,
+				dev_dbg(entity->graph_obj.mdev->dev,
 					"link validation failed for \"%s\":%u -> \"%s\":%u, error %d\n",
 					link->source->entity->name,
 					link->source->index,
@@ -401,7 +401,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 
 		if (!bitmap_full(active, entity->num_pads)) {
 			ret = -EPIPE;
-			dev_dbg(entity->parent->dev,
+			dev_dbg(entity->graph_obj.mdev->dev,
 				"\"%s\":%u must be connected by an enabled link\n",
 				entity->name,
 				(unsigned)find_first_zero_bit(
@@ -454,7 +454,7 @@ EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
  */
 void media_entity_pipeline_stop(struct media_entity *entity)
 {
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph graph;
 
 	mutex_lock(&mdev->graph_mutex);
@@ -490,8 +490,8 @@ struct media_entity *media_entity_get(struct media_entity *entity)
 	if (entity == NULL)
 		return NULL;
 
-	if (entity->parent->dev &&
-	    !try_module_get(entity->parent->dev->driver->owner))
+	if (entity->graph_obj.mdev->dev &&
+	    !try_module_get(entity->graph_obj.mdev->dev->driver->owner))
 		return NULL;
 
 	return entity;
@@ -511,8 +511,8 @@ void media_entity_put(struct media_entity *entity)
 	if (entity == NULL)
 		return;
 
-	if (entity->parent->dev)
-		module_put(entity->parent->dev->driver->owner);
+	if (entity->graph_obj.mdev->dev)
+		module_put(entity->graph_obj.mdev->dev->driver->owner);
 }
 EXPORT_SYMBOL_GPL(media_entity_put);
 
@@ -561,7 +561,8 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	link->flags = flags;
 
 	/* Initialize graph object embedded at the new link */
-	media_gobj_init(source->parent, MEDIA_GRAPH_LINK, &link->graph_obj);
+	media_gobj_init(source->graph_obj.mdev, MEDIA_GRAPH_LINK,
+			&link->graph_obj);
 
 	/* Create the backlink. Backlinks are used to help graph traversal and
 	 * are not reported to userspace.
@@ -577,7 +578,8 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	backlink->flags = flags;
 
 	/* Initialize graph object embedded at the new link */
-	media_gobj_init(sink->parent, MEDIA_GRAPH_LINK, &backlink->graph_obj);
+	media_gobj_init(sink->graph_obj.mdev, MEDIA_GRAPH_LINK,
+			&backlink->graph_obj);
 
 	link->reverse = backlink;
 	backlink->reverse = link;
@@ -629,12 +631,12 @@ EXPORT_SYMBOL_GPL(__media_entity_remove_links);
 void media_entity_remove_links(struct media_entity *entity)
 {
 	/* Do nothing if the entity is not registered. */
-	if (entity->parent == NULL)
+	if (entity->graph_obj.mdev == NULL)
 		return;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 	__media_entity_remove_links(entity);
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_entity_remove_links);
 
@@ -703,7 +705,7 @@ int __media_entity_setup_link(struct media_link *link, u32 flags)
 	    (source->stream_count || sink->stream_count))
 		return -EBUSY;
 
-	mdev = source->parent;
+	mdev = source->graph_obj.mdev;
 
 	if (mdev->link_notify) {
 		ret = mdev->link_notify(link, flags,
@@ -724,9 +726,9 @@ int media_entity_setup_link(struct media_link *link, u32 flags)
 {
 	int ret;
 
-	mutex_lock(&link->source->entity->parent->graph_mutex);
+	mutex_lock(&link->source->entity->graph_obj.mdev->graph_mutex);
 	ret = __media_entity_setup_link(link, flags);
-	mutex_unlock(&link->source->entity->parent->graph_mutex);
+	mutex_unlock(&link->source->entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index b7dc5ac66e36..3d9ccbf5f10f 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -288,7 +288,7 @@ static int isp_video_open(struct file *file)
 		goto rel_fh;
 
 	if (v4l2_fh_is_singular_file(file)) {
-		mutex_lock(&me->parent->graph_mutex);
+		mutex_lock(&me->graph_obj.mdev->graph_mutex);
 
 		ret = fimc_pipeline_call(ve, open, me, true);
 
@@ -296,7 +296,7 @@ static int isp_video_open(struct file *file)
 		if (ret == 0)
 			me->use_count++;
 
-		mutex_unlock(&me->parent->graph_mutex);
+		mutex_unlock(&me->graph_obj.mdev->graph_mutex);
 	}
 	if (!ret)
 		goto unlock;
@@ -312,7 +312,7 @@ static int isp_video_release(struct file *file)
 	struct fimc_isp *isp = video_drvdata(file);
 	struct fimc_is_video *ivc = &isp->video_capture;
 	struct media_entity *entity = &ivc->ve.vdev.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 
 	mutex_lock(&isp->video_lock);
 
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index e8f707d1729b..b2607da4ad14 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -500,7 +500,7 @@ static int fimc_lite_open(struct file *file)
 	    atomic_read(&fimc->out_path) != FIMC_IO_DMA)
 		goto unlock;
 
-	mutex_lock(&me->parent->graph_mutex);
+	mutex_lock(&me->graph_obj.mdev->graph_mutex);
 
 	ret = fimc_pipeline_call(&fimc->ve, open, me, true);
 
@@ -508,7 +508,7 @@ static int fimc_lite_open(struct file *file)
 	if (ret == 0)
 		me->use_count++;
 
-	mutex_unlock(&me->parent->graph_mutex);
+	mutex_unlock(&me->graph_obj.mdev->graph_mutex);
 
 	if (!ret) {
 		fimc_lite_clear_event_counters(fimc);
@@ -541,9 +541,9 @@ static int fimc_lite_release(struct file *file)
 		fimc_pipeline_call(&fimc->ve, close);
 		clear_bit(ST_FLITE_IN_USE, &fimc->state);
 
-		mutex_lock(&entity->parent->graph_mutex);
+		mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 		entity->use_count--;
-		mutex_unlock(&entity->parent->graph_mutex);
+		mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 	}
 
 	_vb2_fop_release(file, NULL);
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 3ba76940eef5..92dbade2fffc 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -1046,7 +1046,7 @@ static int __fimc_md_modify_pipeline(struct media_entity *entity, bool enable)
 	return ret;
 }
 
-/* Locking: called with entity->parent->graph_mutex mutex held. */
+/* Locking: called with entity->graph_obj.mdev->graph_mutex mutex held. */
 static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
 {
 	struct media_entity *entity_err = entity;
diff --git a/drivers/media/platform/exynos4-is/media-dev.h b/drivers/media/platform/exynos4-is/media-dev.h
index 03214541f149..9a69913b31cb 100644
--- a/drivers/media/platform/exynos4-is/media-dev.h
+++ b/drivers/media/platform/exynos4-is/media-dev.h
@@ -164,8 +164,8 @@ struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si)
 
 static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
 {
-	return me->parent == NULL ? NULL :
-		container_of(me->parent, struct fimc_md, media_dev);
+	return me->graph_obj.mdev == NULL ? NULL :
+		container_of(me->graph_obj.mdev, struct fimc_md, media_dev);
 }
 
 static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n)
@@ -175,12 +175,12 @@ static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n)
 
 static inline void fimc_md_graph_lock(struct exynos_video_entity *ve)
 {
-	mutex_lock(&ve->vdev.entity.parent->graph_mutex);
+	mutex_lock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
 }
 
 static inline void fimc_md_graph_unlock(struct exynos_video_entity *ve)
 {
-	mutex_unlock(&ve->vdev.entity.parent->graph_mutex);
+	mutex_unlock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
 }
 
 int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 6351f35b0a65..aa13b17d19a0 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -787,7 +787,7 @@ int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
 	int change = use ? 1 : -1;
 	int ret;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 
 	/* Apply use count to node. */
 	entity->use_count += change;
@@ -798,7 +798,7 @@ int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
 	if (ret < 0)
 		entity->use_count -= change;
 
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 6c89dc40df85..4c367352b1f7 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -226,7 +226,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct isp_video *far_end = NULL;
 
 	mutex_lock(&mdev->graph_mutex);
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index debe4e539df6..1f94c1a54e00 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -409,7 +409,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	unsigned int i;
 	int ret;
 
diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index f7f9aa353a55..92e8116dc28f 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -181,7 +181,7 @@ static int xvip_pipeline_validate(struct xvip_pipeline *pipe,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &start->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	unsigned int num_inputs = 0;
 	unsigned int num_outputs = 0;
 
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 61a8d5beff58..92573fa852a9 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -130,7 +130,7 @@ __vpfe_video_get_format(struct vpfe_video_device *video,
 static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
 {
 	struct media_entity *entity = &video->video_dev.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct vpfe_pipeline *pipe = &video->pipe;
 	struct vpfe_video_device *far_end = NULL;
 	struct media_entity_graph graph;
@@ -288,7 +288,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
 	else
 		entity = &pipe->inputs[0]->video_dev.entity;
 
-	mdev = entity->parent;
+	mdev = entity->graph_obj.mdev;
 	mutex_lock(&mdev->graph_mutex);
 	media_entity_graph_walk_start(&graph, entity);
 	while ((entity = media_entity_graph_walk_next(&graph))) {
@@ -328,7 +328,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
 	else
 		entity = &pipe->inputs[0]->video_dev.entity;
 
-	mdev = entity->parent;
+	mdev = entity->graph_obj.mdev;
 	mutex_lock(&mdev->graph_mutex);
 	media_entity_graph_walk_start(&graph, entity);
 
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 7226553ceb2f..40591963b42b 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -494,7 +494,7 @@ int omap4iss_pipeline_pm_use(struct media_entity *entity, int use)
 	int change = use ? 1 : -1;
 	int ret;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 
 	/* Apply use count to node. */
 	entity->use_count += change;
@@ -505,7 +505,7 @@ int omap4iss_pipeline_pm_use(struct media_entity *entity, int use)
 	if (ret < 0)
 		entity->use_count -= change;
 
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
index 25e9e7a6b99d..45a3f2d778fc 100644
--- a/drivers/staging/media/omap4iss/iss_video.c
+++ b/drivers/staging/media/omap4iss/iss_video.c
@@ -207,7 +207,7 @@ iss_video_far_end(struct iss_video *video)
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct iss_video *far_end = NULL;
 
 	mutex_lock(&mdev->graph_mutex);
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 12/55] [media] media: remove media entity .parent field
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (13 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Javier Martinez Canillas, Mauro Carvalho Chehab, Mauro Carvalho Chehab

From: Javier Martinez Canillas <javier@osg.samsung.com>

Now that the struct media_entity .parent field is unused, it can be
safely removed. Since all the previous users were converted to use
the .mdev field from the embedded struct media_gobj instead.

Suggested-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index e0e4b014ce62..239c4ec30ef6 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -103,7 +103,6 @@ struct media_entity_operations {
 struct media_entity {
 	struct media_gobj graph_obj;
 	struct list_head list;
-	struct media_device *parent;	/* Media device this entity belongs to*/
 	const char *name;		/* Entity name */
 	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
 	u32 revision;			/* Entity revision, driver specific */
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 13/55] [media] uapi/media.h: Declare interface types for V4L2 and DVB
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (14 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-09-10 14:19     ` Javier Martinez Canillas
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, linux-api

Declare the interface types that will be used by the new
G_TOPOLOGY ioctl that will be defined latter on.

For now, we need those types, as they'll be used on the
internal structs associated with the new media_interface
graph object defined on the next patch.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 4e816be3de39..3ad3d6be293f 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -167,6 +167,27 @@ struct media_links_enum {
 	__u32 reserved[4];
 };
 
+/* Interface type ranges */
+
+#define MEDIA_INTF_T_DVB_BASE	0x00000100
+#define MEDIA_INTF_T_V4L_BASE	0x00000200
+
+/* Interface types */
+
+#define MEDIA_INTF_T_DVB_FE    	(MEDIA_INTF_T_DVB_BASE)
+#define MEDIA_INTF_T_DVB_DEMUX  (MEDIA_INTF_T_DVB_BASE + 1)
+#define MEDIA_INTF_T_DVB_DVR    (MEDIA_INTF_T_DVB_BASE + 2)
+#define MEDIA_INTF_T_DVB_CA     (MEDIA_INTF_T_DVB_BASE + 3)
+#define MEDIA_INTF_T_DVB_NET    (MEDIA_INTF_T_DVB_BASE + 4)
+
+#define MEDIA_INTF_T_V4L_VIDEO  (MEDIA_INTF_T_V4L_BASE)
+#define MEDIA_INTF_T_V4L_VBI    (MEDIA_INTF_T_V4L_BASE + 1)
+#define MEDIA_INTF_T_V4L_RADIO  (MEDIA_INTF_T_V4L_BASE + 2)
+#define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
+#define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
+
+/* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
+
 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
 #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct media_entity_desc)
 #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 14/55] [media] media: add functions to allow creating interfaces
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (15 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 10:20   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Interfaces are different than entities: they represent a
Kernel<->userspace interaction, while entities represent a
piece of hardware/firmware/software that executes a function.

Let's distinguish them by creating a separate structure to
store the interfaces.

Latter patches should change the existing drivers and logic
to split the current interface embedded inside the entity
structure (device nodes) into a separate object of the graph.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index a23c93369a04..583666e2cc25 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -44,11 +44,41 @@ static inline const char *gobj_type(enum media_gobj_type type)
 		return "pad";
 	case MEDIA_GRAPH_LINK:
 		return "link";
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		return "intf_devnode";
 	default:
 		return "unknown";
 	}
 }
 
+static inline const char *intf_type(struct media_interface *intf)
+{
+	switch (intf->type) {
+	case MEDIA_INTF_T_DVB_FE:
+		return "frontend";
+	case MEDIA_INTF_T_DVB_DEMUX:
+		return "demux";
+	case MEDIA_INTF_T_DVB_DVR:
+		return "DVR";
+	case MEDIA_INTF_T_DVB_CA:
+		return  "CA";
+	case MEDIA_INTF_T_DVB_NET:
+		return "dvbnet";
+	case MEDIA_INTF_T_V4L_VIDEO:
+		return "video";
+	case MEDIA_INTF_T_V4L_VBI:
+		return "vbi";
+	case MEDIA_INTF_T_V4L_RADIO:
+		return "radio";
+	case MEDIA_INTF_T_V4L_SUBDEV:
+		return "v4l2-subdev";
+	case MEDIA_INTF_T_V4L_SWRADIO:
+		return "swradio";
+	default:
+		return "unknown-intf";
+	}
+};
+
 static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 {
 #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
@@ -84,6 +114,19 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 			"%s: id 0x%08x pad#%d: '%s':%d\n",
 			event_name, gobj->id, media_localid(gobj),
 			pad->entity->name, pad->index);
+		break;
+	}
+	case MEDIA_GRAPH_INTF_DEVNODE:
+	{
+		struct media_interface *intf = gobj_to_intf(gobj);
+		struct media_intf_devnode *devnode = intf_to_devnode(intf);
+
+		dev_dbg(gobj->mdev->dev,
+			"%s: id 0x%08x intf_devnode#%d: %s - major: %d, minor: %d\n",
+			event_name, gobj->id, media_localid(gobj),
+			intf_type(intf),
+			devnode->major, devnode->minor);
+		break;
 	}
 	}
 #endif
@@ -119,6 +162,9 @@ void media_gobj_init(struct media_device *mdev,
 	case MEDIA_GRAPH_LINK:
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
 		break;
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
+		break;
 	}
 	dev_dbg_obj(__func__, gobj);
 }
@@ -793,3 +839,40 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
 
 }
 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
+
+
+/* Functions related to the media interface via device nodes */
+
+struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
+						u32 type, u32 flags,
+						u32 major, u32 minor,
+						gfp_t gfp_flags)
+{
+	struct media_intf_devnode *devnode;
+	struct media_interface *intf;
+
+	devnode = kzalloc(sizeof(*devnode), gfp_flags);
+	if (!devnode)
+		return NULL;
+
+	intf = &devnode->intf;
+
+	intf->type = type;
+	intf->flags = flags;
+
+	devnode->major = major;
+	devnode->minor = minor;
+
+	media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
+		       &devnode->intf.graph_obj);
+
+	return devnode;
+}
+EXPORT_SYMBOL_GPL(media_devnode_create);
+
+void media_devnode_remove(struct media_intf_devnode *devnode)
+{
+	media_gobj_remove(&devnode->intf.graph_obj);
+	kfree(devnode);
+}
+EXPORT_SYMBOL_GPL(media_devnode_remove);
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 05414e351f8e..3b14394d5701 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -44,6 +44,7 @@ struct device;
  * @entity_id:	Unique ID used on the last entity registered
  * @pad_id:	Unique ID used on the last pad registered
  * @link_id:	Unique ID used on the last link registered
+ * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:	List of registered entities
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
@@ -73,6 +74,7 @@ struct media_device {
 	u32 entity_id;
 	u32 pad_id;
 	u32 link_id;
+	u32 intf_devnode_id;
 
 	struct list_head entities;
 
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 239c4ec30ef6..7df8836f4eef 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -36,11 +36,14 @@
  * @MEDIA_GRAPH_ENTITY:		Identify a media entity
  * @MEDIA_GRAPH_PAD:		Identify a media pad
  * @MEDIA_GRAPH_LINK:		Identify a media link
+ * @MEDIA_GRAPH_INTF_DEVNODE:	Identify a media Kernel API interface via
+ *				a device node
  */
 enum media_gobj_type {
 	MEDIA_GRAPH_ENTITY,
 	MEDIA_GRAPH_PAD,
 	MEDIA_GRAPH_LINK,
+	MEDIA_GRAPH_INTF_DEVNODE,
 };
 
 #define MEDIA_BITS_PER_TYPE		8
@@ -141,6 +144,34 @@ struct media_entity {
 	} info;
 };
 
+/**
+ * struct media_intf_devnode - Define a Kernel API interface
+ *
+ * @graph_obj:		embedded graph object
+ * @type:		Type of the interface as defined at the
+ *			uapi/media/media.h header, e. g.
+ *			MEDIA_INTF_T_*
+ * @flags:		Interface flags as defined at uapi/media/media.h
+ */
+struct media_interface {
+	struct media_gobj		graph_obj;
+	u32				type;
+	u32				flags;
+};
+
+/**
+ * struct media_intf_devnode - Define a Kernel API interface via a device node
+ *
+ * @intf:	embedded interface object
+ * @major:	Major number of a device node
+ * @minor:	Minor number of a device node
+ */
+struct media_intf_devnode {
+	struct media_interface		intf;
+	u32				major;
+	u32				minor;
+};
+
 static inline u32 media_entity_type(struct media_entity *entity)
 {
 	return entity->type & MEDIA_ENT_TYPE_MASK;
@@ -198,6 +229,18 @@ struct media_entity_graph {
 #define gobj_to_link(gobj) \
 		container_of(gobj, struct media_link, graph_obj)
 
+#define gobj_to_link(gobj) \
+		container_of(gobj, struct media_link, graph_obj)
+
+#define gobj_to_pad(gobj) \
+		container_of(gobj, struct media_pad, graph_obj)
+
+#define gobj_to_intf(gobj) \
+		container_of(gobj, struct media_interface, graph_obj)
+
+#define intf_to_devnode(intf) \
+		container_of(intf, struct media_intf_devnode, intf)
+
 void media_gobj_init(struct media_device *mdev,
 		    enum media_gobj_type type,
 		    struct media_gobj *gobj);
@@ -229,6 +272,11 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 					     struct media_pipeline *pipe);
 void media_entity_pipeline_stop(struct media_entity *entity);
 
+struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
+						u32 type, u32 flags,
+						u32 major, u32 minor,
+						gfp_t gfp_flags);
+void media_devnode_remove(struct media_intf_devnode *devnode);
 #define media_entity_call(entity, operation, args...)			\
 	(((entity)->ops && (entity)->ops->operation) ?			\
 	 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 15/55] [media] uapi/media.h: Declare interface types for ALSA
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (16 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-09-06 12:02     ` Mauro Carvalho Chehab
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, linux-api

Declare the interface types to be used on alsa for the new
G_TOPOLOGY ioctl.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 583666e2cc25..01946baa32d5 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -74,6 +74,18 @@ static inline const char *intf_type(struct media_interface *intf)
 		return "v4l2-subdev";
 	case MEDIA_INTF_T_V4L_SWRADIO:
 		return "swradio";
+	case MEDIA_INTF_T_ALSA_PCM_CAPTURE:
+		return "pcm-capture";
+	case MEDIA_INTF_T_ALSA_PCM_PLAYBACK:
+		return "pcm-playback";
+	case MEDIA_INTF_T_ALSA_CONTROL:
+		return "alsa-control";
+	case MEDIA_INTF_T_ALSA_COMPRESS:
+		return "compress";
+	case MEDIA_INTF_T_ALSA_RAWMIDI:
+		return "rawmidi";
+	case MEDIA_INTF_T_ALSA_HWDEP:
+		return "hwdep";
 	default:
 		return "unknown-intf";
 	}
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 3ad3d6be293f..aca828709bad 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -171,6 +171,7 @@ struct media_links_enum {
 
 #define MEDIA_INTF_T_DVB_BASE	0x00000100
 #define MEDIA_INTF_T_V4L_BASE	0x00000200
+#define MEDIA_INTF_T_ALSA_BASE	0x00000300
 
 /* Interface types */
 
@@ -186,6 +187,13 @@ struct media_links_enum {
 #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
 #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
 
+#define MEDIA_INTF_T_ALSA_PCM_CAPTURE   (MEDIA_INTF_T_ALSA_BASE)
+#define MEDIA_INTF_T_ALSA_PCM_PLAYBACK  (MEDIA_INTF_T_ALSA_BASE + 1)
+#define MEDIA_INTF_T_ALSA_CONTROL       (MEDIA_INTF_T_ALSA_BASE + 2)
+#define MEDIA_INTF_T_ALSA_COMPRESS      (MEDIA_INTF_T_ALSA_BASE + 3)
+#define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
+#define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
+
 /* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
 
 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 16/55] [media] media: Don't accept early-created links
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (17 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 10:30   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Links are graph objects that represent the links of two already
existing objects in the graph.

While with the current implementation, it is possible to create
the links earlier, It doesn't make any sense to allow linking
two objects when they are not both created.

So, remove the code that would be handling those early-created
links and add a BUG_ON() to ensure that.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 138b18416460..0d85c6c28004 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -443,13 +443,6 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
 	list_add_tail(&entity->list, &mdev->entities);
 
-	/*
-	 * Initialize objects at the links
-	 * in the case where links got created before entity register
-	 */
-	for (i = 0; i < entity->num_links; i++)
-		media_gobj_init(mdev, MEDIA_GRAPH_LINK,
-				&entity->links[i].graph_obj);
 	/* Initialize objects at the pads */
 	for (i = 0; i < entity->num_pads; i++)
 		media_gobj_init(mdev, MEDIA_GRAPH_PAD,
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 01946baa32d5..9f8e0145db7a 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -161,6 +161,8 @@ void media_gobj_init(struct media_device *mdev,
 			   enum media_gobj_type type,
 			   struct media_gobj *gobj)
 {
+	BUG_ON(!mdev);
+
 	gobj->mdev = mdev;
 
 	/* Create a per-type unique object ID */
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 17/55] [media] omap3isp: separate links creation from entities init
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (18 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-11-23 15:55   ` Laurent Pinchart
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Javier Martinez Canillas, Mauro Carvalho Chehab,
	Laurent Pinchart, Mauro Carvalho Chehab

From: Javier Martinez Canillas <javier@osg.samsung.com>

The omap3isp driver initializes the entities and creates the pads links
before the entities are registered with the media device. This does not
work now that object IDs are used to create links so the media_device
has to be set.

Split out the pads links creation from the entity initialization so are
made after the entities registration.

Suggested-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>

Series-to: linux-kernel@vger.kernel.org
Series-cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Series-cc: linux-media@vger.kernel.org
Series-cc: Shuah Khan <shuahkh@osg.samsung.com>
Series-cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Cover-letter:
Patches to test MC next gen patches in OMAP3 ISP
Hello,

This series contains two patches that are needed to test the
"[PATCH v7 00/44] MC next generation patches" [0] in a OMAP3
board by using the omap3isp driver.

I found two issues during testing, the first one is that the
media_entity_cleanup() function tries to empty the pad links
list but the list is initialized when a entity is registered
causing a NULL pointer deference error.

The second issue is that the omap3isp driver creates links
when the entities are initialized but before the media device
is registered causing a NULL pointer deference as well.

Patch 1/1 fixes the first issue by removing the links list
empty logic from media_entity_cleanup() since that is made
in media_device_unregister_entity() and 2/2 fixes the second
issue by separating the entities initialization from the pads
links creation after the entities have been registered.

Patch 1/1 was posted before [1] but forgot to add the [media]
prefix in the subject line so I'm including in this set again.
Sorry about that.

The testing was made on an OMAP3 DM3735 IGEPv2 board and test
that the media-ctl -p prints out the topology. More extensive
testing will be made but I wanted to share these patches in
order to make easier for other people that were looking at it.

[0]: https://www.mail-archive.com/linux-media@vger.kernel.org/msg91528.html
[1]: https://lkml.org/lkml/2015/8/24/649

Best regards,
Javier
END

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index aa13b17d19a0..b8f6f81d2db2 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -1933,6 +1933,100 @@ done:
 	return ret;
 }
 
+/*
+ * isp_create_pads_links - Pads links creation for the subdevices
+ * @isp : Pointer to ISP device
+ * return negative error code or zero on success
+ */
+static int isp_create_pads_links(struct isp_device *isp)
+{
+	int ret;
+
+	ret = omap3isp_csi2_create_pads_links(isp);
+	if (ret < 0) {
+		dev_err(isp->dev, "CSI2 pads links creation failed\n");
+		return ret;
+	}
+
+	ret = omap3isp_ccp2_create_pads_links(isp);
+	if (ret < 0) {
+		dev_err(isp->dev, "CCP2 pads links creation failed\n");
+		return ret;
+	}
+
+	ret = omap3isp_ccdc_create_pads_links(isp);
+	if (ret < 0) {
+		dev_err(isp->dev, "CCDC pads links creation failed\n");
+		return ret;
+	}
+
+	ret = omap3isp_preview_create_pads_links(isp);
+	if (ret < 0) {
+		dev_err(isp->dev, "Preview pads links creation failed\n");
+		return ret;
+	}
+
+	ret = omap3isp_resizer_create_pads_links(isp);
+	if (ret < 0) {
+		dev_err(isp->dev, "Resizer pads links creation failed\n");
+		return ret;
+	}
+
+	/* Connect the submodules. */
+	ret = media_create_pad_link(
+			&isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
+			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
+	if (ret < 0)
+		return ret;
+
+	ret = media_create_pad_link(
+			&isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
+			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
+	if (ret < 0)
+		return ret;
+
+	ret = media_create_pad_link(
+			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
+			&isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
+	if (ret < 0)
+		return ret;
+
+	ret = media_create_pad_link(
+			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
+			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
+	if (ret < 0)
+		return ret;
+
+	ret = media_create_pad_link(
+			&isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
+			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
+	if (ret < 0)
+		return ret;
+
+	ret = media_create_pad_link(
+			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
+			&isp->isp_aewb.subdev.entity, 0,
+			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
+	if (ret < 0)
+		return ret;
+
+	ret = media_create_pad_link(
+			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
+			&isp->isp_af.subdev.entity, 0,
+			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
+	if (ret < 0)
+		return ret;
+
+	ret = media_create_pad_link(
+			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
+			&isp->isp_hist.subdev.entity, 0,
+			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 static void isp_cleanup_modules(struct isp_device *isp)
 {
 	omap3isp_h3a_aewb_cleanup(isp);
@@ -2003,62 +2097,8 @@ static int isp_initialize_modules(struct isp_device *isp)
 		goto error_h3a_af;
 	}
 
-	/* Connect the submodules. */
-	ret = media_create_pad_link(
-			&isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
-			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
-	if (ret < 0)
-		goto error_link;
-
-	ret = media_create_pad_link(
-			&isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
-			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
-	if (ret < 0)
-		goto error_link;
-
-	ret = media_create_pad_link(
-			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
-			&isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
-	if (ret < 0)
-		goto error_link;
-
-	ret = media_create_pad_link(
-			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
-			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
-	if (ret < 0)
-		goto error_link;
-
-	ret = media_create_pad_link(
-			&isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
-			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
-	if (ret < 0)
-		goto error_link;
-
-	ret = media_create_pad_link(
-			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
-			&isp->isp_aewb.subdev.entity, 0,
-			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
-	if (ret < 0)
-		goto error_link;
-
-	ret = media_create_pad_link(
-			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
-			&isp->isp_af.subdev.entity, 0,
-			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
-	if (ret < 0)
-		goto error_link;
-
-	ret = media_create_pad_link(
-			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
-			&isp->isp_hist.subdev.entity, 0,
-			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
-	if (ret < 0)
-		goto error_link;
-
 	return 0;
 
-error_link:
-	omap3isp_h3a_af_cleanup(isp);
 error_h3a_af:
 	omap3isp_h3a_aewb_cleanup(isp);
 error_h3a_aewb:
@@ -2468,6 +2508,10 @@ static int isp_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto error_modules;
 
+	ret = isp_create_pads_links(isp);
+	if (ret < 0)
+		goto error_register_entities;
+
 	isp->notifier.bound = isp_subdev_notifier_bound;
 	isp->notifier.complete = isp_subdev_notifier_complete;
 
diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c
index 27555e4f4aa8..9a811f5741fa 100644
--- a/drivers/media/platform/omap3isp/ispccdc.c
+++ b/drivers/media/platform/omap3isp/ispccdc.c
@@ -2666,16 +2666,8 @@ static int ccdc_init_entities(struct isp_ccdc_device *ccdc)
 	if (ret < 0)
 		goto error_video;
 
-	/* Connect the CCDC subdev to the video node. */
-	ret = media_create_pad_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
-			&ccdc->video_out.video.entity, 0, 0);
-	if (ret < 0)
-		goto error_link;
-
 	return 0;
 
-error_link:
-	omap3isp_video_cleanup(&ccdc->video_out);
 error_video:
 	media_entity_cleanup(me);
 	return ret;
@@ -2721,6 +2713,20 @@ int omap3isp_ccdc_init(struct isp_device *isp)
 }
 
 /*
+ * omap3isp_ccdc_create_pads_links - CCDC pads links creation
+ * @isp : Pointer to ISP device
+ * return negative error code or zero on success
+ */
+int omap3isp_ccdc_create_pads_links(struct isp_device *isp)
+{
+	struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
+
+	/* Connect the CCDC subdev to the video node. */
+	return media_create_pad_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
+				     &ccdc->video_out.video.entity, 0, 0);
+}
+
+/*
  * omap3isp_ccdc_cleanup - CCDC module cleanup.
  * @isp: Device pointer specific to the OMAP3 ISP.
  */
diff --git a/drivers/media/platform/omap3isp/ispccdc.h b/drivers/media/platform/omap3isp/ispccdc.h
index 3440a7097940..2128203ef6fb 100644
--- a/drivers/media/platform/omap3isp/ispccdc.h
+++ b/drivers/media/platform/omap3isp/ispccdc.h
@@ -163,6 +163,7 @@ struct isp_ccdc_device {
 struct isp_device;
 
 int omap3isp_ccdc_init(struct isp_device *isp);
+int omap3isp_ccdc_create_pads_links(struct isp_device *isp);
 void omap3isp_ccdc_cleanup(struct isp_device *isp);
 int omap3isp_ccdc_register_entities(struct isp_ccdc_device *ccdc,
 	struct v4l2_device *vdev);
diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c
index b215eb5049d6..6ec7d104ab75 100644
--- a/drivers/media/platform/omap3isp/ispccp2.c
+++ b/drivers/media/platform/omap3isp/ispccp2.c
@@ -1099,16 +1099,8 @@ static int ccp2_init_entities(struct isp_ccp2_device *ccp2)
 	if (ret < 0)
 		goto error_video;
 
-	/* Connect the video node to the ccp2 subdev. */
-	ret = media_create_pad_link(&ccp2->video_in.video.entity, 0,
-				       &ccp2->subdev.entity, CCP2_PAD_SINK, 0);
-	if (ret < 0)
-		goto error_link;
-
 	return 0;
 
-error_link:
-	omap3isp_video_cleanup(&ccp2->video_in);
 error_video:
 	media_entity_cleanup(&ccp2->subdev.entity);
 	return ret;
@@ -1157,6 +1149,20 @@ int omap3isp_ccp2_init(struct isp_device *isp)
 }
 
 /*
+ * omap3isp_ccp2_create_pads_links - CCP2 pads links creation
+ * @isp : Pointer to ISP device
+ * return negative error code or zero on success
+ */
+int omap3isp_ccp2_create_pads_links(struct isp_device *isp)
+{
+	struct isp_ccp2_device *ccp2 = &isp->isp_ccp2;
+
+	/* Connect the video node to the ccp2 subdev. */
+	return media_create_pad_link(&ccp2->video_in.video.entity, 0,
+				     &ccp2->subdev.entity, CCP2_PAD_SINK, 0);
+}
+
+/*
  * omap3isp_ccp2_cleanup - CCP2 un-initialization
  * @isp : Pointer to ISP device
  */
diff --git a/drivers/media/platform/omap3isp/ispccp2.h b/drivers/media/platform/omap3isp/ispccp2.h
index 4662bffa79e3..fb74bc67878b 100644
--- a/drivers/media/platform/omap3isp/ispccp2.h
+++ b/drivers/media/platform/omap3isp/ispccp2.h
@@ -79,6 +79,7 @@ struct isp_ccp2_device {
 
 /* Function declarations */
 int omap3isp_ccp2_init(struct isp_device *isp);
+int omap3isp_ccp2_create_pads_links(struct isp_device *isp);
 void omap3isp_ccp2_cleanup(struct isp_device *isp);
 int omap3isp_ccp2_register_entities(struct isp_ccp2_device *ccp2,
 			struct v4l2_device *vdev);
diff --git a/drivers/media/platform/omap3isp/ispcsi2.c b/drivers/media/platform/omap3isp/ispcsi2.c
index fcefc1e74881..0fb057a74f69 100644
--- a/drivers/media/platform/omap3isp/ispcsi2.c
+++ b/drivers/media/platform/omap3isp/ispcsi2.c
@@ -1264,16 +1264,8 @@ static int csi2_init_entities(struct isp_csi2_device *csi2)
 	if (ret < 0)
 		goto error_video;
 
-	/* Connect the CSI2 subdev to the video node. */
-	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
-				       &csi2->video_out.video.entity, 0, 0);
-	if (ret < 0)
-		goto error_link;
-
 	return 0;
 
-error_link:
-	omap3isp_video_cleanup(&csi2->video_out);
 error_video:
 	media_entity_cleanup(&csi2->subdev.entity);
 	return ret;
@@ -1314,6 +1306,20 @@ int omap3isp_csi2_init(struct isp_device *isp)
 }
 
 /*
+ * omap3isp_csi2_create_pads_links - CSI2 pads links creation
+ * @isp : Pointer to ISP device
+ * return negative error code or zero on success
+ */
+int omap3isp_csi2_create_pads_links(struct isp_device *isp)
+{
+	struct isp_csi2_device *csi2a = &isp->isp_csi2a;
+
+	/* Connect the CSI2 subdev to the video node. */
+	return media_create_pad_link(&csi2a->subdev.entity, CSI2_PAD_SOURCE,
+				     &csi2a->video_out.video.entity, 0, 0);
+}
+
+/*
  * omap3isp_csi2_cleanup - Routine for module driver cleanup
  */
 void omap3isp_csi2_cleanup(struct isp_device *isp)
diff --git a/drivers/media/platform/omap3isp/ispcsi2.h b/drivers/media/platform/omap3isp/ispcsi2.h
index 453ed62fe394..452ee239c7d7 100644
--- a/drivers/media/platform/omap3isp/ispcsi2.h
+++ b/drivers/media/platform/omap3isp/ispcsi2.h
@@ -148,6 +148,7 @@ struct isp_csi2_device {
 void omap3isp_csi2_isr(struct isp_csi2_device *csi2);
 int omap3isp_csi2_reset(struct isp_csi2_device *csi2);
 int omap3isp_csi2_init(struct isp_device *isp);
+int omap3isp_csi2_create_pads_links(struct isp_device *isp);
 void omap3isp_csi2_cleanup(struct isp_device *isp);
 void omap3isp_csi2_unregister_entities(struct isp_csi2_device *csi2);
 int omap3isp_csi2_register_entities(struct isp_csi2_device *csi2,
diff --git a/drivers/media/platform/omap3isp/isppreview.c b/drivers/media/platform/omap3isp/isppreview.c
index ad38d20c7770..6986d2f65c19 100644
--- a/drivers/media/platform/omap3isp/isppreview.c
+++ b/drivers/media/platform/omap3isp/isppreview.c
@@ -2311,21 +2311,8 @@ static int preview_init_entities(struct isp_prev_device *prev)
 	if (ret < 0)
 		goto error_video_out;
 
-	/* Connect the video nodes to the previewer subdev. */
-	ret = media_create_pad_link(&prev->video_in.video.entity, 0,
-			&prev->subdev.entity, PREV_PAD_SINK, 0);
-	if (ret < 0)
-		goto error_link;
-
-	ret = media_create_pad_link(&prev->subdev.entity, PREV_PAD_SOURCE,
-			&prev->video_out.video.entity, 0, 0);
-	if (ret < 0)
-		goto error_link;
-
 	return 0;
 
-error_link:
-	omap3isp_video_cleanup(&prev->video_out);
 error_video_out:
 	omap3isp_video_cleanup(&prev->video_in);
 error_video_in:
@@ -2349,6 +2336,26 @@ int omap3isp_preview_init(struct isp_device *isp)
 	return preview_init_entities(prev);
 }
 
+/*
+ * omap3isp_preview_create_pads_links - Previewer pads links creation
+ * @isp : Pointer to ISP device
+ * return negative error code or zero on success
+ */
+int omap3isp_preview_create_pads_links(struct isp_device *isp)
+{
+	struct isp_prev_device *prev = &isp->isp_prev;
+	int ret;
+
+	/* Connect the video nodes to the previewer subdev. */
+	ret = media_create_pad_link(&prev->video_in.video.entity, 0,
+			&prev->subdev.entity, PREV_PAD_SINK, 0);
+	if (ret < 0)
+		return ret;
+
+	return media_create_pad_link(&prev->subdev.entity, PREV_PAD_SOURCE,
+				     &prev->video_out.video.entity, 0, 0);
+}
+
 void omap3isp_preview_cleanup(struct isp_device *isp)
 {
 	struct isp_prev_device *prev = &isp->isp_prev;
diff --git a/drivers/media/platform/omap3isp/isppreview.h b/drivers/media/platform/omap3isp/isppreview.h
index 16fdc03a3d43..f3593b7cecc7 100644
--- a/drivers/media/platform/omap3isp/isppreview.h
+++ b/drivers/media/platform/omap3isp/isppreview.h
@@ -148,6 +148,7 @@ struct isp_prev_device {
 struct isp_device;
 
 int omap3isp_preview_init(struct isp_device *isp);
+int omap3isp_preview_create_pads_links(struct isp_device *isp);
 void omap3isp_preview_cleanup(struct isp_device *isp);
 
 int omap3isp_preview_register_entities(struct isp_prev_device *prv,
diff --git a/drivers/media/platform/omap3isp/ispresizer.c b/drivers/media/platform/omap3isp/ispresizer.c
index b48ad4d4b834..249af7f524f9 100644
--- a/drivers/media/platform/omap3isp/ispresizer.c
+++ b/drivers/media/platform/omap3isp/ispresizer.c
@@ -1755,21 +1755,8 @@ static int resizer_init_entities(struct isp_res_device *res)
 
 	res->video_out.video.entity.flags |= MEDIA_ENT_FL_DEFAULT;
 
-	/* Connect the video nodes to the resizer subdev. */
-	ret = media_create_pad_link(&res->video_in.video.entity, 0,
-			&res->subdev.entity, RESZ_PAD_SINK, 0);
-	if (ret < 0)
-		goto error_link;
-
-	ret = media_create_pad_link(&res->subdev.entity, RESZ_PAD_SOURCE,
-			&res->video_out.video.entity, 0, 0);
-	if (ret < 0)
-		goto error_link;
-
 	return 0;
 
-error_link:
-	omap3isp_video_cleanup(&res->video_out);
 error_video_out:
 	omap3isp_video_cleanup(&res->video_in);
 error_video_in:
@@ -1793,6 +1780,26 @@ int omap3isp_resizer_init(struct isp_device *isp)
 	return resizer_init_entities(res);
 }
 
+/*
+ * omap3isp_resizer_create_pads_links - Resizer pads links creation
+ * @isp : Pointer to ISP device
+ * return negative error code or zero on success
+ */
+int omap3isp_resizer_create_pads_links(struct isp_device *isp)
+{
+	struct isp_res_device *res = &isp->isp_res;
+	int ret;
+
+	/* Connect the video nodes to the resizer subdev. */
+	ret = media_create_pad_link(&res->video_in.video.entity, 0,
+				    &res->subdev.entity, RESZ_PAD_SINK, 0);
+	if (ret < 0)
+		return ret;
+
+	return media_create_pad_link(&res->subdev.entity, RESZ_PAD_SOURCE,
+				     &res->video_out.video.entity, 0, 0);
+}
+
 void omap3isp_resizer_cleanup(struct isp_device *isp)
 {
 	struct isp_res_device *res = &isp->isp_res;
diff --git a/drivers/media/platform/omap3isp/ispresizer.h b/drivers/media/platform/omap3isp/ispresizer.h
index 5414542912e2..8b9fdcdab73d 100644
--- a/drivers/media/platform/omap3isp/ispresizer.h
+++ b/drivers/media/platform/omap3isp/ispresizer.h
@@ -119,6 +119,7 @@ struct isp_res_device {
 struct isp_device;
 
 int omap3isp_resizer_init(struct isp_device *isp);
+int omap3isp_resizer_create_pads_links(struct isp_device *isp);
 void omap3isp_resizer_cleanup(struct isp_device *isp);
 
 int omap3isp_resizer_register_entities(struct isp_res_device *res,
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 18/55] [media] omap3isp: create links after all subdevs have been bound
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (19 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-09-09  8:03   ` Sakari Ailus
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Javier Martinez Canillas, Mauro Carvalho Chehab,
	Laurent Pinchart, Mauro Carvalho Chehab

From: Javier Martinez Canillas <javier@osg.samsung.com>

The omap3isp driver parses the graph endpoints to know how many subdevices
needs to be registered async and register notifiers callbacks for to know
when these are bound and when the async registrations are completed.

Currently the entities pad are linked with the correct ISP input interface
when the subdevs are bound but it happens before entitities are registered
with the media device so that won't work now that the entity links list is
initialized on device registration.

So instead creating the pad links when the subdevice is bound, create them
on the complete callback once all the subdevices have been bound but only
try to create for the ones that have a bus configuration set during bound.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index b8f6f81d2db2..69e7733d36cd 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -2321,26 +2321,33 @@ static int isp_subdev_notifier_bound(struct v4l2_async_notifier *async,
 				     struct v4l2_subdev *subdev,
 				     struct v4l2_async_subdev *asd)
 {
-	struct isp_device *isp = container_of(async, struct isp_device,
-					      notifier);
 	struct isp_async_subdev *isd =
 		container_of(asd, struct isp_async_subdev, asd);
-	int ret;
-
-	ret = isp_link_entity(isp, &subdev->entity, isd->bus.interface);
-	if (ret < 0)
-		return ret;
 
 	isd->sd = subdev;
 	isd->sd->host_priv = &isd->bus;
 
-	return ret;
+	return 0;
 }
 
 static int isp_subdev_notifier_complete(struct v4l2_async_notifier *async)
 {
 	struct isp_device *isp = container_of(async, struct isp_device,
 					      notifier);
+	struct v4l2_device *v4l2_dev = &isp->v4l2_dev;
+	struct v4l2_subdev *sd;
+	struct isp_bus_cfg *bus;
+	int ret;
+
+	list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
+		/* Only try to link entities whose interface was set on bound */
+		if (sd->host_priv) {
+			bus = (struct isp_bus_cfg *)sd->host_priv;
+			ret = isp_link_entity(isp, &sd->entity, bus->interface);
+			if (ret < 0)
+				return ret;
+		}
+	}
 
 	return v4l2_device_register_subdev_nodes(&isp->v4l2_dev);
 }
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 19/55] [media] media: convert links from array to list
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (20 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-09-04  8:41   ` Sakari Ailus
  2015-09-04 11:28   ` [PATCH v8.1 " Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Akihiro Tsukada,
	Stefan Richter, Jonathan Corbet, Tina Ruchandani,
	Antti Palosaari, Dan Carpenter,
	Rafael Lourenço de Lima Chehab, Hans Verkuil, Shuah Khan,
	Prabhakar Lad, Julia Lawall, Markus Elfring, Sakari Ailus,
	Scott Jiang, Boris BREZILLON

The entire logic that represent graph links were developed on a
time where there were no needs to dynamic remove links. So,
although links are created/removed one by one via some
functions, they're stored as an array inside the entity struct.

As the array may grow, there's a logic inside the code that
checks if the amount of space is not enough to store
the needed links. If it isn't the core uses krealloc()
to change the size of the link, with is bad, as it
leaves the memory fragmented.

So, convert links into a list.

Also, currently,  both source and sink entities need the link
at the graph traversal logic inside media_entity. So there's
a logic duplicating all links. That makes it to spend
twice the memory needed. This is not a big deal for today's
usage, where the number of links are not big.

Yet, if during the MC workshop discussions, it was said that
IIO graphs could have up to 4,000 entities. So, we may
want to remove the duplication on some future. The problem
is that it would require a separate linked list to store
the backlinks inside the entity, or to use a more complex
algorithm to do graph backlink traversal, with is something
that the current graph traversal inside the core can't cope
with. So, let's postpone a such change if/when it is actually
needed.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index c38ef1a72b4a..2d06bcff0946 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -622,7 +622,7 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
 	struct media_device *mdev = adapter->mdev;
 	struct media_entity  *entity, *source;
 	struct media_link *link, *found_link = NULL;
-	int i, ret, n_links = 0, active_links = 0;
+	int ret, n_links = 0, active_links = 0;
 
 	fepriv->pipe_start_entity = NULL;
 
@@ -632,8 +632,7 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
 	entity = fepriv->dvbdev->entity;
 	fepriv->pipe_start_entity = entity;
 
-	for (i = 0; i < entity->num_links; i++) {
-		link = &entity->links[i];
+	list_for_each_entry(link, &entity->links, list) {
 		if (link->sink->entity == entity) {
 			found_link = link;
 			n_links++;
@@ -659,13 +658,11 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
 
 	source = found_link->source->entity;
 	fepriv->pipe_start_entity = source;
-	for (i = 0; i < source->num_links; i++) {
+	list_for_each_entry(link, &source->links, list) {
 		struct media_entity *sink;
 		int flags = 0;
 
-		link = &source->links[i];
 		sink = link->sink->entity;
-
 		if (sink == entity)
 			flags = MEDIA_LNK_FL_ENABLED;
 
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 0d85c6c28004..3e649cacfc07 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -25,6 +25,7 @@
 #include <linux/ioctl.h>
 #include <linux/media.h>
 #include <linux/types.h>
+#include <linux/slab.h>
 
 #include <media/media-device.h>
 #include <media/media-devnode.h>
@@ -150,22 +151,21 @@ static long __media_device_enum_links(struct media_device *mdev,
 	}
 
 	if (links->links) {
-		struct media_link_desc __user *ulink;
-		unsigned int l;
+		struct media_link *ent_link;
+		struct media_link_desc __user *ulink = links->links;
 
-		for (l = 0, ulink = links->links; l < entity->num_links; l++) {
+		list_for_each_entry(ent_link, &entity->links, list) {
 			struct media_link_desc link;
 
 			/* Ignore backlinks. */
-			if (entity->links[l].source->entity != entity)
+			if (ent_link->source->entity != entity)
 				continue;
-
 			memset(&link, 0, sizeof(link));
-			media_device_kpad_to_upad(entity->links[l].source,
+			media_device_kpad_to_upad(ent_link->source,
 						  &link.source);
-			media_device_kpad_to_upad(entity->links[l].sink,
+			media_device_kpad_to_upad(ent_link->sink,
 						  &link.sink);
-			link.flags = entity->links[l].flags;
+			link.flags = ent_link->flags;
 			if (copy_to_user(ulink, &link, sizeof(*ulink)))
 				return -EFAULT;
 			ulink++;
@@ -437,6 +437,7 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	/* Warn if we apparently re-register an entity */
 	WARN_ON(entity->graph_obj.mdev != NULL);
 	entity->graph_obj.mdev = mdev;
+	INIT_LIST_HEAD(&entity->links);
 
 	spin_lock(&mdev->lock);
 	/* Initialize media_gobj embedded at the entity */
@@ -465,13 +466,17 @@ void media_device_unregister_entity(struct media_entity *entity)
 {
 	int i;
 	struct media_device *mdev = entity->graph_obj.mdev;
+	struct media_link *link, *tmp;
 
 	if (mdev == NULL)
 		return;
 
 	spin_lock(&mdev->lock);
-	for (i = 0; i < entity->num_links; i++)
-		media_gobj_remove(&entity->links[i].graph_obj);
+	list_for_each_entry_safe(link, tmp, &entity->links, list) {
+		media_gobj_remove(&link->graph_obj);
+		list_del(&link->list);
+		kfree(link);
+	}
 	for (i = 0; i < entity->num_pads; i++)
 		media_gobj_remove(&entity->pads[i].graph_obj);
 	media_gobj_remove(&entity->graph_obj);
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 9f8e0145db7a..ff63201443d7 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -221,21 +221,13 @@ int
 media_entity_init(struct media_entity *entity, u16 num_pads,
 		  struct media_pad *pads)
 {
-	struct media_link *links;
-	unsigned int max_links = num_pads;
 	unsigned int i;
 
-	links = kzalloc(max_links * sizeof(links[0]), GFP_KERNEL);
-	if (links == NULL)
-		return -ENOMEM;
-
 	entity->group_id = 0;
-	entity->max_links = max_links;
 	entity->num_links = 0;
 	entity->num_backlinks = 0;
 	entity->num_pads = num_pads;
 	entity->pads = pads;
-	entity->links = links;
 
 	for (i = 0; i < num_pads; i++) {
 		pads[i].entity = entity;
@@ -249,7 +241,13 @@ EXPORT_SYMBOL_GPL(media_entity_init);
 void
 media_entity_cleanup(struct media_entity *entity)
 {
-	kfree(entity->links);
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &entity->links, list) {
+		media_gobj_remove(&link->graph_obj);
+		list_del(&link->list);
+		kfree(link);
+	}
 }
 EXPORT_SYMBOL_GPL(media_entity_cleanup);
 
@@ -275,7 +273,7 @@ static void stack_push(struct media_entity_graph *graph,
 		return;
 	}
 	graph->top++;
-	graph->stack[graph->top].link = 0;
+	graph->stack[graph->top].link = entity->links;
 	graph->stack[graph->top].entity = entity;
 }
 
@@ -317,6 +315,7 @@ void media_entity_graph_walk_start(struct media_entity_graph *graph,
 }
 EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
 
+
 /**
  * media_entity_graph_walk_next - Get the next entity in the graph
  * @graph: Media graph structure
@@ -340,14 +339,16 @@ media_entity_graph_walk_next(struct media_entity_graph *graph)
 	 * top of the stack until no more entities on the level can be
 	 * found.
 	 */
-	while (link_top(graph) < stack_top(graph)->num_links) {
+	while (list_is_last(&link_top(graph), &(stack_top(graph)->links))) {
 		struct media_entity *entity = stack_top(graph);
-		struct media_link *link = &entity->links[link_top(graph)];
+		struct media_link *link;
 		struct media_entity *next;
 
+		link = list_last_entry(&link_top(graph), typeof(*link), list);
+
 		/* The link is not enabled so we do not follow. */
 		if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {
-			link_top(graph)++;
+			list_rotate_left(&link_top(graph));
 			continue;
 		}
 
@@ -358,12 +359,12 @@ media_entity_graph_walk_next(struct media_entity_graph *graph)
 
 		/* Has the entity already been visited? */
 		if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
-			link_top(graph)++;
+			list_rotate_left(&link_top(graph));
 			continue;
 		}
 
 		/* Push the new entity to stack and start over. */
-		link_top(graph)++;
+		list_rotate_left(&link_top(graph));
 		stack_push(graph, next);
 	}
 
@@ -395,6 +396,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph graph;
 	struct media_entity *entity_err = entity;
+	struct media_link *link;
 	int ret;
 
 	mutex_lock(&mdev->graph_mutex);
@@ -404,7 +406,6 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		DECLARE_BITMAP(active, entity->num_pads);
 		DECLARE_BITMAP(has_no_links, entity->num_pads);
-		unsigned int i;
 
 		entity->stream_count++;
 		WARN_ON(entity->pipe && entity->pipe != pipe);
@@ -420,8 +421,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 		bitmap_zero(active, entity->num_pads);
 		bitmap_fill(has_no_links, entity->num_pads);
 
-		for (i = 0; i < entity->num_links; i++) {
-			struct media_link *link = &entity->links[i];
+		list_for_each_entry(link, &entity->links, list) {
 			struct media_pad *pad = link->sink->entity == entity
 						? link->sink : link->source;
 
@@ -582,25 +582,20 @@ EXPORT_SYMBOL_GPL(media_entity_put);
 
 static struct media_link *media_entity_add_link(struct media_entity *entity)
 {
-	if (entity->num_links >= entity->max_links) {
-		struct media_link *links = entity->links;
-		unsigned int max_links = entity->max_links + 2;
-		unsigned int i;
+	struct media_link *link;
 
-		links = krealloc(links, max_links * sizeof(*links), GFP_KERNEL);
-		if (links == NULL)
-			return NULL;
+	link = kzalloc(sizeof(*link), GFP_KERNEL);
+	if (link == NULL)
+		return NULL;
 
-		for (i = 0; i < entity->num_links; i++)
-			links[i].reverse->reverse = &links[i];
+	list_add_tail(&link->list, &entity->links);
 
-		entity->max_links = max_links;
-		entity->links = links;
-	}
-
-	return &entity->links[entity->num_links++];
+	return link;
 }
 
+static void __media_entity_remove_link(struct media_entity *entity,
+				       struct media_link *link);
+
 int
 media_create_pad_link(struct media_entity *source, u16 source_pad,
 			 struct media_entity *sink, u16 sink_pad, u32 flags)
@@ -629,7 +624,7 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	 */
 	backlink = media_entity_add_link(sink);
 	if (backlink == NULL) {
-		source->num_links--;
+		__media_entity_remove_link(source, link);
 		return -ENOMEM;
 	}
 
@@ -645,43 +640,51 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	backlink->reverse = link;
 
 	sink->num_backlinks++;
+	sink->num_links++;
+	source->num_links++;
 
 	return 0;
 }
 EXPORT_SYMBOL_GPL(media_create_pad_link);
 
-void __media_entity_remove_links(struct media_entity *entity)
+static void __media_entity_remove_link(struct media_entity *entity,
+				       struct media_link *link)
 {
-	unsigned int i;
+	struct media_link *rlink, *tmp;
+	struct media_entity *remote;
+	unsigned int r = 0;
 
-	for (i = 0; i < entity->num_links; i++) {
-		struct media_link *link = &entity->links[i];
-		struct media_entity *remote;
-		unsigned int r = 0;
+	if (link->source->entity == entity)
+		remote = link->sink->entity;
+	else
+		remote = link->source->entity;
+
+	list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
+		if (rlink != link->reverse) {
+			r++;
+			continue;
+		}
 
 		if (link->source->entity == entity)
-			remote = link->sink->entity;
-		else
-			remote = link->source->entity;
+			remote->num_backlinks--;
 
-		while (r < remote->num_links) {
-			struct media_link *rlink = &remote->links[r];
+		if (--remote->num_links == 0)
+			break;
 
-			if (rlink != link->reverse) {
-				r++;
-				continue;
-			}
-
-			if (link->source->entity == entity)
-				remote->num_backlinks--;
-
-			if (--remote->num_links == 0)
-				break;
-
-			/* Insert last entry in place of the dropped link. */
-			*rlink = remote->links[remote->num_links];
-		}
+		/* Remove the remote link */
+		list_del(&rlink->list);
+		kfree(rlink);
 	}
+	list_del(&link->list);
+	kfree(link);
+}
+
+void __media_entity_remove_links(struct media_entity *entity)
+{
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &entity->links, list)
+		__media_entity_remove_link(entity, link);
 
 	entity->num_links = 0;
 	entity->num_backlinks = 0;
@@ -806,11 +809,8 @@ struct media_link *
 media_entity_find_link(struct media_pad *source, struct media_pad *sink)
 {
 	struct media_link *link;
-	unsigned int i;
-
-	for (i = 0; i < source->entity->num_links; ++i) {
-		link = &source->entity->links[i];
 
+	list_for_each_entry(link, &source->entity->links, list) {
 		if (link->source->entity == source->entity &&
 		    link->source->index == source->index &&
 		    link->sink->entity == sink->entity &&
@@ -834,11 +834,9 @@ EXPORT_SYMBOL_GPL(media_entity_find_link);
  */
 struct media_pad *media_entity_remote_pad(struct media_pad *pad)
 {
-	unsigned int i;
-
-	for (i = 0; i < pad->entity->num_links; i++) {
-		struct media_link *link = &pad->entity->links[i];
+	struct media_link *link;
 
+	list_for_each_entry(link, &pad->entity->links, list) {
 		if (!(link->flags & MEDIA_LNK_FL_ENABLED))
 			continue;
 
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index a55eb524ea21..7f645bcb7463 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -261,13 +261,11 @@ static void au0828_create_media_graph(struct au0828_dev *dev)
 
 	if (tuner)
 		media_create_pad_link(tuner, 0, decoder, 0,
-					 MEDIA_LNK_FL_ENABLED);
-	if (dev->vdev.entity.links)
-		media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
-				 MEDIA_LNK_FL_ENABLED);
-	if (dev->vbi_dev.entity.links)
-		media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
-				 MEDIA_LNK_FL_ENABLED);
+				      MEDIA_LNK_FL_ENABLED);
+	media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
+			      MEDIA_LNK_FL_ENABLED);
+	media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
+			      MEDIA_LNK_FL_ENABLED);
 #endif
 }
 
diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 2c040056d4eb..4511e2893282 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -643,7 +643,7 @@ static int au0828_enable_analog_tuner(struct au0828_dev *dev)
 	struct media_device *mdev = dev->media_dev;
 	struct media_entity *source;
 	struct media_link *link, *found_link = NULL;
-	int i, ret, active_links = 0;
+	int ret, active_links = 0;
 
 	if (!mdev || !dev->decoder)
 		return 0;
@@ -655,8 +655,7 @@ static int au0828_enable_analog_tuner(struct au0828_dev *dev)
 	 * do DVB streaming while the DMA engine is being used for V4L2,
 	 * this should be enough for the actual needs.
 	 */
-	for (i = 0; i < dev->decoder->num_links; i++) {
-		link = &dev->decoder->links[i];
+	list_for_each_entry(link, &dev->decoder->links, list) {
 		if (link->sink->entity == dev->decoder) {
 			found_link = link;
 			if (link->flags & MEDIA_LNK_FL_ENABLED)
@@ -669,11 +668,10 @@ static int au0828_enable_analog_tuner(struct au0828_dev *dev)
 		return 0;
 
 	source = found_link->source->entity;
-	for (i = 0; i < source->num_links; i++) {
+	list_for_each_entry(link, &source->links, list) {
 		struct media_entity *sink;
 		int flags = 0;
 
-		link = &source->links[i];
 		sink = link->sink->entity;
 
 		if (sink == dev->decoder)
diff --git a/drivers/media/usb/cx231xx/cx231xx-video.c b/drivers/media/usb/cx231xx/cx231xx-video.c
index 8f04b125486f..e8baff4d6290 100644
--- a/drivers/media/usb/cx231xx/cx231xx-video.c
+++ b/drivers/media/usb/cx231xx/cx231xx-video.c
@@ -106,7 +106,7 @@ static int cx231xx_enable_analog_tuner(struct cx231xx *dev)
 	struct media_device *mdev = dev->media_dev;
 	struct media_entity  *entity, *decoder = NULL, *source;
 	struct media_link *link, *found_link = NULL;
-	int i, ret, active_links = 0;
+	int ret, active_links = 0;
 
 	if (!mdev)
 		return 0;
@@ -127,8 +127,7 @@ static int cx231xx_enable_analog_tuner(struct cx231xx *dev)
 	if (!decoder)
 		return 0;
 
-	for (i = 0; i < decoder->num_links; i++) {
-		link = &decoder->links[i];
+	list_for_each_entry(link, &decoder->links, list) {
 		if (link->sink->entity == decoder) {
 			found_link = link;
 			if (link->flags & MEDIA_LNK_FL_ENABLED)
@@ -141,11 +140,10 @@ static int cx231xx_enable_analog_tuner(struct cx231xx *dev)
 		return 0;
 
 	source = found_link->source->entity;
-	for (i = 0; i < source->num_links; i++) {
+	list_for_each_entry(link, &source->links, list) {
 		struct media_entity *sink;
 		int flags = 0;
 
-		link = &source->links[i];
 		sink = link->sink->entity;
 
 		if (sink == entity)
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 7df8836f4eef..bb89cedb0c40 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -74,6 +74,7 @@ struct media_pipeline {
 
 struct media_link {
 	struct media_gobj graph_obj;
+	struct list_head list;
 	struct media_pad *source;	/* Source pad */
 	struct media_pad *sink;		/* Sink pad  */
 	struct media_link *reverse;	/* Link in the reverse direction */
@@ -116,10 +117,9 @@ struct media_entity {
 	u16 num_links;			/* Number of existing links, both
 					 * enabled and disabled */
 	u16 num_backlinks;		/* Number of backlinks */
-	u16 max_links;			/* Maximum number of links */
 
-	struct media_pad *pads;		/* Pads array (num_pads elements) */
-	struct media_link *links;	/* Links array (max_links elements)*/
+	struct media_pad *pads;		/* Pads array (num_pads objects) */
+	struct list_head links;		/* Links list */
 
 	const struct media_entity_operations *ops;	/* Entity operations */
 
@@ -213,7 +213,7 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
 struct media_entity_graph {
 	struct {
 		struct media_entity *entity;
-		int link;
+		struct list_head link;
 	} stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
 
 	DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID);
@@ -247,7 +247,7 @@ void media_gobj_init(struct media_device *mdev,
 void media_gobj_remove(struct media_gobj *gobj);
 
 int media_entity_init(struct media_entity *entity, u16 num_pads,
-		struct media_pad *pads);
+		      struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
 
 int media_create_pad_link(struct media_entity *source, u16 source_pad,
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 20/55] [media] media: make add link more generic
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (21 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 10:44   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

The media_entity_add_link() function takes an entity
as an argument just to get the list head.

Make it more generic by changing the function argument
to list_head.

No functional changes.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index ff63201443d7..6d06be6c9ef3 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -580,7 +580,7 @@ EXPORT_SYMBOL_GPL(media_entity_put);
  * Links management
  */
 
-static struct media_link *media_entity_add_link(struct media_entity *entity)
+static struct media_link *media_add_link(struct list_head *head)
 {
 	struct media_link *link;
 
@@ -588,7 +588,7 @@ static struct media_link *media_entity_add_link(struct media_entity *entity)
 	if (link == NULL)
 		return NULL;
 
-	list_add_tail(&link->list, &entity->links);
+	list_add_tail(&link->list, head);
 
 	return link;
 }
@@ -607,7 +607,7 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	BUG_ON(source_pad >= source->num_pads);
 	BUG_ON(sink_pad >= sink->num_pads);
 
-	link = media_entity_add_link(source);
+	link = media_add_link(&source->links);
 	if (link == NULL)
 		return -ENOMEM;
 
@@ -622,7 +622,7 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	/* Create the backlink. Backlinks are used to help graph traversal and
 	 * are not reported to userspace.
 	 */
-	backlink = media_entity_add_link(sink);
+	backlink = media_add_link(&sink->links);
 	if (backlink == NULL) {
 		__media_entity_remove_link(source, link);
 		return -ENOMEM;
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 21/55] [media] media: make media_link more generic to handle interace links
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (22 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 10:44   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

By adding an union at media_link, we get for free a way to
represent interface->entity links.

No need to change anything at the code, just at the internal
header file.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index bb89cedb0c40..b4923a24efd5 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -75,14 +75,20 @@ struct media_pipeline {
 struct media_link {
 	struct media_gobj graph_obj;
 	struct list_head list;
-	struct media_pad *source;	/* Source pad */
-	struct media_pad *sink;		/* Sink pad  */
+	union {
+		struct media_gobj *gobj0;
+		struct media_pad *source;
+	};
+	union {
+		struct media_gobj *gobj1;
+		struct media_pad *sink;
+	};
 	struct media_link *reverse;	/* Link in the reverse direction */
 	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
 };
 
 struct media_pad {
-	struct media_gobj graph_obj;
+	struct media_gobj graph_obj;	/* must be first field in struct */
 	struct media_entity *entity;	/* Entity this pad belongs to */
 	u16 index;			/* Pad index in the entity pads array */
 	unsigned long flags;		/* Pad flags (MEDIA_PAD_FL_*) */
@@ -105,7 +111,7 @@ struct media_entity_operations {
 };
 
 struct media_entity {
-	struct media_gobj graph_obj;
+	struct media_gobj graph_obj;	/* must be first field in struct */
 	struct list_head list;
 	const char *name;		/* Entity name */
 	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
@@ -119,7 +125,7 @@ struct media_entity {
 	u16 num_backlinks;		/* Number of backlinks */
 
 	struct media_pad *pads;		/* Pads array (num_pads objects) */
-	struct list_head links;		/* Links list */
+	struct list_head links;		/* Pad-to-pad links list */
 
 	const struct media_entity_operations *ops;	/* Entity operations */
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 22/55] [media] media: make link debug printk more generic
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (23 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Remove entity name from the link as this exists only if the object
type is PAD on both link ends.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 6d06be6c9ef3..973d1be427c5 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -106,16 +106,14 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 		struct media_link *link = gobj_to_link(gobj);
 
 		dev_dbg(gobj->mdev->dev,
-			"%s: id 0x%08x link#%d: '%s' %s#%d ==> '%s' %s#%d\n",
+			"%s: id 0x%08x link#%d: %s#%d ==> %s#%d\n",
 			event_name, gobj->id, media_localid(gobj),
 
-			link->source->entity->name,
-			gobj_type(media_type(&link->source->graph_obj)),
-			media_localid(&link->source->graph_obj),
+			gobj_type(media_type(link->gobj0)),
+			media_localid(link->gobj0),
 
-			link->sink->entity->name,
-			gobj_type(media_type(&link->sink->graph_obj)),
-			media_localid(&link->sink->graph_obj));
+			gobj_type(media_type(link->gobj1)),
+			media_localid(link->gobj1));
 		break;
 	}
 	case MEDIA_GRAPH_PAD:
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 23/55] [media] media: add support to link interfaces and entities
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (24 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 10:48   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Now that we have a new graph object called "interfaces", we
need to be able to link them to the entities.

Add a linked list to the interfaces to allow them to be
linked to the entities.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 973d1be427c5..08239128fbc4 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -869,6 +869,7 @@ struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
 
 	intf->type = type;
 	intf->flags = flags;
+	INIT_LIST_HEAD(&intf->links);
 
 	devnode->major = major;
 	devnode->minor = minor;
@@ -886,3 +887,40 @@ void media_devnode_remove(struct media_intf_devnode *devnode)
 	kfree(devnode);
 }
 EXPORT_SYMBOL_GPL(media_devnode_remove);
+
+struct media_link *media_create_intf_link(struct media_entity *entity,
+					    struct media_interface *intf,
+					    u32 flags)
+{
+	struct media_link *link;
+
+	link = media_add_link(&intf->links);
+	if (link == NULL)
+		return NULL;
+
+	link->intf = intf;
+	link->entity = entity;
+	link->flags = flags;
+
+	/* Initialize graph object embedded at the new link */
+	media_gobj_init(intf->graph_obj.mdev, MEDIA_GRAPH_LINK,
+			&link->graph_obj);
+
+	return link;
+}
+EXPORT_SYMBOL_GPL(media_create_intf_link);
+
+
+static void __media_remove_intf_link(struct media_link *link)
+{
+	media_gobj_remove(&link->graph_obj);
+	kfree(link);
+}
+
+void media_remove_intf_link(struct media_link *link)
+{
+	mutex_lock(&link->graph_obj.mdev->graph_mutex);
+	__media_remove_intf_link(link);
+	mutex_unlock(&link->graph_obj.mdev->graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_remove_intf_link);
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index b4923a24efd5..423ff804e686 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -78,10 +78,12 @@ struct media_link {
 	union {
 		struct media_gobj *gobj0;
 		struct media_pad *source;
+		struct media_interface *intf;
 	};
 	union {
 		struct media_gobj *gobj1;
 		struct media_pad *sink;
+		struct media_entity *entity;
 	};
 	struct media_link *reverse;	/* Link in the reverse direction */
 	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
@@ -154,6 +156,7 @@ struct media_entity {
  * struct media_intf_devnode - Define a Kernel API interface
  *
  * @graph_obj:		embedded graph object
+ * @links:		List of links pointing to graph entities
  * @type:		Type of the interface as defined at the
  *			uapi/media/media.h header, e. g.
  *			MEDIA_INTF_T_*
@@ -161,6 +164,7 @@ struct media_entity {
  */
 struct media_interface {
 	struct media_gobj		graph_obj;
+	struct list_head		links;
 	u32				type;
 	u32				flags;
 };
@@ -283,6 +287,11 @@ struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
 						u32 major, u32 minor,
 						gfp_t gfp_flags);
 void media_devnode_remove(struct media_intf_devnode *devnode);
+struct media_link *media_create_intf_link(struct media_entity *entity,
+					    struct media_interface *intf,
+					    u32 flags);
+void media_remove_intf_link(struct media_link *link);
+
 #define media_entity_call(entity, operation, args...)			\
 	(((entity)->ops && (entity)->ops->operation) ?			\
 	 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 24/55] [media] media-entity: add a helper function to create interface
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (25 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 10:49   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

As we'll be adding other interface types in the future, put the
common interface create code on a separate function.

Suggested-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 08239128fbc4..417673a32c21 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -851,6 +851,18 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
 
 
+static void media_interface_init(struct media_device *mdev,
+				 struct media_interface *intf,
+				 u32 gobj_type,
+				 u32 intf_type, u32 flags)
+{
+	intf->type = intf_type;
+	intf->flags = flags;
+	INIT_LIST_HEAD(&intf->links);
+
+	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
+}
+
 /* Functions related to the media interface via device nodes */
 
 struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
@@ -859,23 +871,16 @@ struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
 						gfp_t gfp_flags)
 {
 	struct media_intf_devnode *devnode;
-	struct media_interface *intf;
 
 	devnode = kzalloc(sizeof(*devnode), gfp_flags);
 	if (!devnode)
 		return NULL;
 
-	intf = &devnode->intf;
-
-	intf->type = type;
-	intf->flags = flags;
-	INIT_LIST_HEAD(&intf->links);
-
 	devnode->major = major;
 	devnode->minor = minor;
 
-	media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
-		       &devnode->intf.graph_obj);
+	media_interface_init(mdev, &devnode->intf, MEDIA_GRAPH_INTF_DEVNODE,
+			     type, flags);
 
 	return devnode;
 }
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 25/55] [media] dvbdev: add support for interfaces
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (26 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 10:51   ` Hans Verkuil
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Laurent Pinchart,
	Hans Verkuil, Sakari Ailus, Jonathan Corbet

Now that the infrastruct for that is set, add support for
interfaces.

Please notice that we're missing two links:
	DVB FE intf    -> tuner
	DVB demux intf -> dvr

Those should be added latter, after having the entire graph
set. With the current infrastructure, those should be added
at dvb_create_media_graph(), but it would also require some
extra core changes, to allow the function to enumerate the
interfaces.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 65f59f2124b4..6bf61d42c017 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -180,14 +180,36 @@ skip:
 	return -ENFILE;
 }
 
-static void dvb_register_media_device(struct dvb_device *dvbdev,
-				      int type, int minor)
+static void dvb_create_media_entity(struct dvb_device *dvbdev,
+				       int type, int minor)
 {
 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
 	int ret = 0, npads;
 
-	if (!dvbdev->adapter->mdev)
+	switch (type) {
+	case DVB_DEVICE_FRONTEND:
+		npads = 2;
+		break;
+	case DVB_DEVICE_DEMUX:
+		npads = 2;
+		break;
+	case DVB_DEVICE_CA:
+		npads = 2;
+		break;
+	case DVB_DEVICE_NET:
+		/*
+		 * We should be creating entities for the MPE/ULE
+		 * decapsulation hardware (or software implementation).
+		 *
+		 * However, the number of for the MPE/ULE decaps may not be
+		 * fixed. As we don't have yet dynamic support for PADs at
+		 * the Media Controller, let's not create the decap
+		 * entities yet.
+		 */
 		return;
+	default:
+		return;
+	}
 
 	dvbdev->entity = kzalloc(sizeof(*dvbdev->entity), GFP_KERNEL);
 	if (!dvbdev->entity)
@@ -197,19 +219,6 @@ static void dvb_register_media_device(struct dvb_device *dvbdev,
 	dvbdev->entity->info.dev.minor = minor;
 	dvbdev->entity->name = dvbdev->name;
 
-	switch (type) {
-	case DVB_DEVICE_CA:
-	case DVB_DEVICE_DEMUX:
-	case DVB_DEVICE_FRONTEND:
-		npads = 2;
-		break;
-	case DVB_DEVICE_NET:
-		npads = 0;
-		break;
-	default:
-		npads = 1;
-	}
-
 	if (npads) {
 		dvbdev->pads = kcalloc(npads, sizeof(*dvbdev->pads),
 				       GFP_KERNEL);
@@ -230,18 +239,11 @@ static void dvb_register_media_device(struct dvb_device *dvbdev,
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
-	case DVB_DEVICE_DVR:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_DVR;
-		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
-		break;
 	case DVB_DEVICE_CA:
 		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_CA;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
-	case DVB_DEVICE_NET:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_NET;
-		break;
 	default:
 		kfree(dvbdev->entity);
 		dvbdev->entity = NULL;
@@ -263,11 +265,63 @@ static void dvb_register_media_device(struct dvb_device *dvbdev,
 		return;
 	}
 
-	printk(KERN_DEBUG "%s: media device '%s' registered.\n",
+	printk(KERN_DEBUG "%s: media entity '%s' registered.\n",
 		__func__, dvbdev->entity->name);
 #endif
 }
 
+static void dvb_register_media_device(struct dvb_device *dvbdev,
+				      int type, int minor)
+{
+#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
+	u32 intf_type;
+
+	if (!dvbdev->adapter->mdev)
+		return;
+
+	dvb_create_media_entity(dvbdev, type, minor);
+
+	switch (type) {
+	case DVB_DEVICE_FRONTEND:
+		intf_type = MEDIA_INTF_T_DVB_FE;
+		break;
+	case DVB_DEVICE_DEMUX:
+		intf_type = MEDIA_INTF_T_DVB_DEMUX;
+		break;
+	case DVB_DEVICE_DVR:
+		intf_type = MEDIA_INTF_T_DVB_DVR;
+		break;
+	case DVB_DEVICE_CA:
+		intf_type = MEDIA_INTF_T_DVB_CA;
+		break;
+	case DVB_DEVICE_NET:
+		intf_type = MEDIA_INTF_T_DVB_NET;
+		break;
+	default:
+		return;
+	}
+
+	dvbdev->intf_devnode = media_devnode_create(dvbdev->adapter->mdev,
+						 intf_type, 0,
+						 DVB_MAJOR, minor,
+						 GFP_KERNEL);
+
+	/*
+	 * Create the "obvious" link, e. g. the ones that represent
+	 * a direct association between an interface and an entity.
+	 * Other links should be created elsewhere, like:
+	 *		DVB FE intf    -> tuner
+	 *		DVB demux intf -> dvr
+	 */
+
+	if (!dvbdev->entity || !dvbdev->intf_devnode)
+		return;
+
+	media_create_intf_link(dvbdev->entity, &dvbdev->intf_devnode->intf, 0);
+
+#endif
+}
+
 int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
 			const struct dvb_device *template, void *priv, int type)
 {
diff --git a/drivers/media/dvb-core/dvbdev.h b/drivers/media/dvb-core/dvbdev.h
index c61a4f03a66f..5f37b4dd1e69 100644
--- a/drivers/media/dvb-core/dvbdev.h
+++ b/drivers/media/dvb-core/dvbdev.h
@@ -149,6 +149,7 @@ struct dvb_device {
 
 	/* Allocated and filled inside dvbdev.c */
 	struct media_entity *entity;
+	struct media_intf_devnode *intf_devnode;
 	struct media_pad *pads;
 #endif
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 26/55] [media] media: add a linked list to track interfaces by mdev
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (27 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 10:52   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

The media device should list the interface objects, so add a linked list
for those interfaces in struct media_device.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 3e649cacfc07..659507bce63f 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -381,6 +381,7 @@ int __must_check __media_device_register(struct media_device *mdev,
 		return -EINVAL;
 
 	INIT_LIST_HEAD(&mdev->entities);
+	INIT_LIST_HEAD(&mdev->interfaces);
 	spin_lock_init(&mdev->lock);
 	mutex_init(&mdev->graph_mutex);
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 417673a32c21..15bc92d3a648 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -861,6 +861,8 @@ static void media_interface_init(struct media_device *mdev,
 	INIT_LIST_HEAD(&intf->links);
 
 	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
+
+	list_add_tail(&intf->list, &mdev->interfaces);
 }
 
 /* Functions related to the media interface via device nodes */
@@ -889,6 +891,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
 	media_gobj_remove(&devnode->intf.graph_obj);
+	list_del(&devnode->intf.list);
 	kfree(devnode);
 }
 EXPORT_SYMBOL_GPL(media_devnode_remove);
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 3b14394d5701..51807efa505b 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -46,6 +46,7 @@ struct device;
  * @link_id:	Unique ID used on the last link registered
  * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:	List of registered entities
+ * @interfaces:	List of registered interfaces
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
  * @link_notify: Link state change notification callback
@@ -77,6 +78,7 @@ struct media_device {
 	u32 intf_devnode_id;
 
 	struct list_head entities;
+	struct list_head interfaces;
 
 	/* Protects the entities list */
 	spinlock_t lock;
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 423ff804e686..e7b20bdc735d 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -156,6 +156,8 @@ struct media_entity {
  * struct media_intf_devnode - Define a Kernel API interface
  *
  * @graph_obj:		embedded graph object
+ * @list:		Linked list used to find other interfaces that belong
+ *			to the same media controller
  * @links:		List of links pointing to graph entities
  * @type:		Type of the interface as defined at the
  *			uapi/media/media.h header, e. g.
@@ -164,6 +166,7 @@ struct media_entity {
  */
 struct media_interface {
 	struct media_gobj		graph_obj;
+	struct list_head		list;
 	struct list_head		links;
 	u32				type;
 	u32				flags;
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 27/55] [media] dvbdev: add support for indirect interface links
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (28 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 10:54   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Sakari Ailus,
	Laurent Pinchart, Hans Verkuil

Some interfaces indirectly control multiple entities.
Add support for those.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 6bf61d42c017..14d32cdcdd47 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -441,6 +441,7 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	struct media_device *mdev = adap->mdev;
 	struct media_entity *entity, *tuner = NULL, *fe = NULL;
 	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
+	struct media_interface *intf;
 
 	if (!mdev)
 		return;
@@ -476,6 +477,18 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 
 	if (demux && ca)
 		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
+
+	/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca */
+	list_for_each_entry(intf, &mdev->interfaces, list) {
+		if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
+			media_create_intf_link(ca, intf, 0);
+		if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
+			media_create_intf_link(tuner, intf, 0);
+		if (intf->type == MEDIA_INTF_T_DVB_DVR && demux)
+			media_create_intf_link(demux, intf, 0);
+	}
+
+
 }
 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
 #endif
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 28/55] [media] uapi/media.h: Fix entity namespace
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (29 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 11:17   ` Hans Verkuil
  2015-09-06 12:02     ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Laurent Pinchart,
	Sakari Ailus, Hans Verkuil, linux-api

Now that interfaces got created, we need to fix the entity
namespace.

So, let's create a consistent new namespace and add backward
compatibility macros to keep the old namespace preserved.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 14d32cdcdd47..88013d1a2c39 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -230,17 +230,17 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
 
 	switch (type) {
 	case DVB_DEVICE_FRONTEND:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_FE;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMOD;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
 	case DVB_DEVICE_DEMUX:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_DEMUX;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMUX;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
 	case DVB_DEVICE_CA:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_CA;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_CA;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
@@ -439,7 +439,7 @@ EXPORT_SYMBOL(dvb_unregister_device);
 void dvb_create_media_graph(struct dvb_adapter *adap)
 {
 	struct media_device *mdev = adap->mdev;
-	struct media_entity *entity, *tuner = NULL, *fe = NULL;
+	struct media_entity *entity, *tuner = NULL, *demod = NULL;
 	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
 	struct media_interface *intf;
 
@@ -451,26 +451,26 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 		case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
 			tuner = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_FE:
-			fe = entity;
+		case MEDIA_ENT_T_DVB_DEMOD:
+			demod = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_DEMUX:
+		case MEDIA_ENT_T_DVB_DEMUX:
 			demux = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_DVR:
+		case MEDIA_ENT_T_DVB_TSOUT:
 			dvr = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_CA:
+		case MEDIA_ENT_T_DVB_CA:
 			ca = entity;
 			break;
 		}
 	}
 
-	if (tuner && fe)
-		media_create_pad_link(tuner, 0, fe, 0, 0);
+	if (tuner && demod)
+		media_create_pad_link(tuner, 0, demod, 0, 0);
 
-	if (fe && demux)
-		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
+	if (demod && demux)
+		media_create_pad_link(demod, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && dvr)
 		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index aca828709bad..3bbda409353f 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -42,31 +42,71 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
+/*
+ * Base numbers for entity types
+ *
+ * Please notice that the huge gap of 16 bits for each base is overkill!
+ * 8 bits is more than enough to avoid starving entity types for each
+ * subsystem.
+ *
+ * However, It is kept this way just to avoid binary breakages with the
+ * namespace provided on legacy versions of this header.
+ */
+#define MEDIA_ENT_T_DVB_BASE		0x00000001
+#define MEDIA_ENT_T_V4L2_BASE		0x00010000
+#define MEDIA_ENT_T_V4L2_SUBDEV_BASE	0x00020000
+
+/*
+ * V4L2 entities - Those are used for DMA (mmap/DMABUF) and
+ *	read()/write() data I/O associated with the V4L2 devnodes.
+ */
+#define MEDIA_ENT_T_V4L2_VIDEO		(MEDIA_ENT_T_V4L2_BASE + 1)
+	/*
+	 * Please notice that numbers between MEDIA_ENT_T_V4L2_BASE + 2 and
+	 * MEDIA_ENT_T_V4L2_BASE + 4 can't be used, as those values used
+	 * to be declared for FB, ALSA and DVB entities.
+	 * As those values were never actually used in practice, we're just
+	 * adding them as backward compatibility macros and keeping the
+	 * numberspace clean here. This way, we avoid breaking compilation,
+	 * in the case of having some userspace application using the old
+	 * symbols.
+	 */
+#define MEDIA_ENT_T_V4L2_VBI		(MEDIA_ENT_T_V4L2_BASE + 5)
+	/* for TX radio, as RX is done via either ALSA or wire */
+#define MEDIA_ENT_T_V4L2_RADIO		(MEDIA_ENT_T_V4L2_BASE + 6)
+#define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 7)
+
+/* V4L2 Sub-device entities */
+#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
+#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
+#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
+	/* A converter of analogue video to its digital representation. */
+#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 4)
+	/* Tuner entity is actually both V4L2 and DVB subdev */
+#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 5)
+
+/* DVB entities */
+#define MEDIA_ENT_T_DVB_DEMOD		(MEDIA_ENT_T_DVB_BASE)
+#define MEDIA_ENT_T_DVB_DEMUX		(MEDIA_ENT_T_DVB_BASE + 1)
+#define MEDIA_ENT_T_DVB_TSOUT		(MEDIA_ENT_T_DVB_BASE + 2)
+#define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 3)
+#define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 4)
+
+/* Legacy symbols used to avoid userspace compilation breakages */
 #define MEDIA_ENT_TYPE_SHIFT		16
 #define MEDIA_ENT_TYPE_MASK		0x00ff0000
 #define MEDIA_ENT_SUBTYPE_MASK		0x0000ffff
 
-#define MEDIA_ENT_T_DEVNODE		(1 << MEDIA_ENT_TYPE_SHIFT)
-#define MEDIA_ENT_T_DEVNODE_V4L		(MEDIA_ENT_T_DEVNODE + 1)
+#define MEDIA_ENT_T_DEVNODE		MEDIA_ENT_T_V4L2_BASE
+#define MEDIA_ENT_T_V4L2_SUBDEV		MEDIA_ENT_T_V4L2_SUBDEV_BASE
+
+#define MEDIA_ENT_T_DEVNODE_V4L		MEDIA_ENT_T_V4L2_VIDEO
+
 #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
 #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
-#define MEDIA_ENT_T_DEVNODE_DVB_FE	(MEDIA_ENT_T_DEVNODE + 4)
-#define MEDIA_ENT_T_DEVNODE_DVB_DEMUX	(MEDIA_ENT_T_DEVNODE + 5)
-#define MEDIA_ENT_T_DEVNODE_DVB_DVR	(MEDIA_ENT_T_DEVNODE + 6)
-#define MEDIA_ENT_T_DEVNODE_DVB_CA	(MEDIA_ENT_T_DEVNODE + 7)
-#define MEDIA_ENT_T_DEVNODE_DVB_NET	(MEDIA_ENT_T_DEVNODE + 8)
+#define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
 
-/* Legacy symbol. Use it to avoid userspace compilation breakages */
-#define MEDIA_ENT_T_DEVNODE_DVB		MEDIA_ENT_T_DEVNODE_DVB_FE
-
-#define MEDIA_ENT_T_V4L2_SUBDEV		(2 << MEDIA_ENT_TYPE_SHIFT)
-#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV + 1)
-#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV + 2)
-#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV + 3)
-/* A converter of analogue video to its digital representation. */
-#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV + 4)
-
-#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV + 5)
+/* Entity types */
 
 #define MEDIA_ENT_FL_DEFAULT		(1 << 0)
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 29/55] [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_V4L
  2015-08-30  3:06 ` Mauro Carvalho Chehab
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Jonathan Corbet,
	Hyun Kwon, Laurent Pinchart, Michal Simek, Sören Brinkmann,
	Hans Verkuil, Sakari Ailus, Prabhakar Lad, Sylwester Nawrocki,
	Lars-Peter Clausen, Markus Elfring, linux-doc, linux-arm-kernel

Now that interfaces and entities are distinct, it makes no sense
of keeping something named as MEDIA_ENT_T_DEVNODE.

This change was done with this script:

	for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DEVNODE_V4L,MEDIA_ENT_T_V4L2_VIDEO, <$i >a && mv a $i; done

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
index 5872f8bbf774..910243d4edb8 100644
--- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
+++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
@@ -183,7 +183,7 @@
 	    <entry>Unknown device node</entry>
 	  </row>
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_V4L</constant></entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
 	    <entry>V4L video, radio or vbi device node</entry>
 	  </row>
 	  <row>
diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index 92e8116dc28f..88cd789cdaf7 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -193,7 +193,7 @@ static int xvip_pipeline_validate(struct xvip_pipeline *pipe,
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		struct xvip_dma *dma;
 
-		if (entity->type != MEDIA_ENT_T_DEVNODE_V4L)
+		if (entity->type != MEDIA_ENT_T_V4L2_VIDEO)
 			continue;
 
 		dma = to_xvip_dma(media_entity_to_video_device(entity));
diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 71a1b93b0790..44b330589787 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -912,7 +912,7 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
 	/* Part 5: Register the entity. */
 	if (vdev->v4l2_dev->mdev &&
 	    vdev->vfl_type != VFL_TYPE_SUBDEV) {
-		vdev->entity.type = MEDIA_ENT_T_DEVNODE_V4L;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
 		vdev->entity.name = vdev->name;
 		vdev->entity.info.dev.major = VIDEO_MAJOR;
 		vdev->entity.info.dev.minor = vdev->minor;
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index 83615b8fb46a..e6e1115d8215 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -535,7 +535,7 @@ v4l2_subdev_link_validate_get_format(struct media_pad *pad,
 		return v4l2_subdev_call(sd, pad, get_fmt, NULL, fmt);
 	}
 
-	WARN(pad->entity->type != MEDIA_ENT_T_DEVNODE_V4L,
+	WARN(pad->entity->type != MEDIA_ENT_T_V4L2_VIDEO,
 	     "Driver bug! Wrong media entity type 0x%08x, entity %s\n",
 	     pad->entity->type, pad->entity->name);
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 29/55] [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_V4L
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: linux-arm-kernel

Now that interfaces and entities are distinct, it makes no sense
of keeping something named as MEDIA_ENT_T_DEVNODE.

This change was done with this script:

	for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DEVNODE_V4L,MEDIA_ENT_T_V4L2_VIDEO, <$i >a && mv a $i; done

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
index 5872f8bbf774..910243d4edb8 100644
--- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
+++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
@@ -183,7 +183,7 @@
 	    <entry>Unknown device node</entry>
 	  </row>
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_V4L</constant></entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
 	    <entry>V4L video, radio or vbi device node</entry>
 	  </row>
 	  <row>
diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index 92e8116dc28f..88cd789cdaf7 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -193,7 +193,7 @@ static int xvip_pipeline_validate(struct xvip_pipeline *pipe,
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		struct xvip_dma *dma;
 
-		if (entity->type != MEDIA_ENT_T_DEVNODE_V4L)
+		if (entity->type != MEDIA_ENT_T_V4L2_VIDEO)
 			continue;
 
 		dma = to_xvip_dma(media_entity_to_video_device(entity));
diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 71a1b93b0790..44b330589787 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -912,7 +912,7 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
 	/* Part 5: Register the entity. */
 	if (vdev->v4l2_dev->mdev &&
 	    vdev->vfl_type != VFL_TYPE_SUBDEV) {
-		vdev->entity.type = MEDIA_ENT_T_DEVNODE_V4L;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
 		vdev->entity.name = vdev->name;
 		vdev->entity.info.dev.major = VIDEO_MAJOR;
 		vdev->entity.info.dev.minor = vdev->minor;
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index 83615b8fb46a..e6e1115d8215 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -535,7 +535,7 @@ v4l2_subdev_link_validate_get_format(struct media_pad *pad,
 		return v4l2_subdev_call(sd, pad, get_fmt, NULL, fmt);
 	}
 
-	WARN(pad->entity->type != MEDIA_ENT_T_DEVNODE_V4L,
+	WARN(pad->entity->type != MEDIA_ENT_T_V4L2_VIDEO,
 	     "Driver bug! Wrong media entity type 0x%08x, entity %s\n",
 	     pad->entity->type, pad->entity->name);
 
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 30/55] [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_DVB
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (31 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 11:21   ` Hans Verkuil
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Jonathan Corbet,
	Hans Verkuil, linux-doc

Now that interfaces and entities are distinct, it makes no sense
of keeping something named as MEDIA_ENT_T_DEVNODE_DVB_foo.

Made via this script:
	for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DEVNODE_DVB_,MEDIA_ENT_T_DVB_, <$i >a && mv a $i; done
	for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DVB_DVR,MEDIA_ENT_T_DVB_TSOUT, <$i >a && mv a $i; done
	for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DVB_FE,MEDIA_ENT_T_DVB_DEMOD, <$i >a && mv a $i; done
	for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DVB_NET,MEDIA_ENT_T_DVB_DEMOD_NET_DECAP, <$i >a && mv a $i; done

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
index 910243d4edb8..32a783635649 100644
--- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
+++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
@@ -195,23 +195,23 @@
 	    <entry>ALSA card</entry>
 	  </row>
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_DVB_FE</constant></entry>
+	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD</constant></entry>
 	    <entry>DVB frontend devnode</entry>
 	  </row>
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_DVB_DEMUX</constant></entry>
+	    <entry><constant>MEDIA_ENT_T_DVB_DEMUX</constant></entry>
 	    <entry>DVB demux devnode</entry>
 	  </row>
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_DVB_DVR</constant></entry>
+	    <entry><constant>MEDIA_ENT_T_DVB_TSOUT</constant></entry>
 	    <entry>DVB DVR devnode</entry>
 	  </row>
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_DVB_CA</constant></entry>
+	    <entry><constant>MEDIA_ENT_T_DVB_CA</constant></entry>
 	    <entry>DVB CAM devnode</entry>
 	  </row>
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_DVB_NET</constant></entry>
+	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD_NET_DECAP</constant></entry>
 	    <entry>DVB network devnode</entry>
 	  </row>
 	  <row>
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (32 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 11:31   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

As we'll be removing entity subtypes from the Kernel, we need
to provide a way for drivers and core to check if a given
entity is represented by a V4L2 subdev or if it is an V4L2
I/O entity (typically with DMA).

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index e7b20bdc735d..b0cfbc0dffc7 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -220,6 +220,39 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
 	return id;
 }
 
+static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_VIDEO:
+	case MEDIA_ENT_T_V4L2_VBI:
+	case MEDIA_ENT_T_V4L2_SWRADIO:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
+	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
+	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
+	case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
+	case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
+		return true;
+
+	default:
+		return false;
+	}
+}
+
 #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
 #define MEDIA_ENTITY_ENUM_MAX_ID	64
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
  2015-08-30  3:06 ` Mauro Carvalho Chehab
  (?)
  (?)
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: linux-arm-kernel

Instead of relying on media subtype, use the new macros to detect
if an entity is a subdev or an A/V DMA entity.

Please note that most drivers assume that there's just AV_DMA or
V4L2 subdevs. This is not true anymore, as we've added MC support
for DVB, and there are plans to add support for ALSA and FB/DRM
too.

Ok, on the current pipelines supported by those drivers, just V4L
stuff are there, but, assuming that some day a pipeline that also
works with other subsystems will ever added, it is better to add
explicit checks for the AV_DMA stuff.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
index 0eb34ecb8ee4..8c9a29e0e294 100644
--- a/drivers/media/platform/exynos4-is/common.c
+++ b/drivers/media/platform/exynos4-is/common.c
@@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
 	while (pad->flags & MEDIA_PAD_FL_SINK) {
 		/* source pad */
 		pad = media_entity_remote_pad(pad);
-		if (pad = NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		sd = media_entity_to_v4l2_subdev(pad->entity);
diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
index 0627a93b2f3b..e9810fee4c30 100644
--- a/drivers/media/platform/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
 			}
 		}
 
-		if (src_pad = NULL ||
-		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
 			break;
 
 		/* Don't call FIMC subdev operation to avoid nested locking */
@@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
 	struct fimc_vid_cap *vc = &fimc->vid_cap;
 	struct v4l2_subdev *sensor;
 
-	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!is_media_entity_v4l2_subdev(remote->entity))
 		return -EINVAL;
 
 	if (WARN_ON(fimc = NULL))
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 3d9ccbf5f10f..5fbaf5e39903 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
 
 		/* Retrieve format at the source pad */
 		pad = media_entity_remote_pad(pad);
-		if (pad = NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		sd = media_entity_to_v4l2_subdev(pad->entity);
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index b2607da4ad14..c2327147b360 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
 		}
 		/* Retrieve format at the source pad */
 		pad = media_entity_remote_pad(pad);
-		if (pad = NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		sd = media_entity_to_v4l2_subdev(pad->entity);
@@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 {
 	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
 	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
-	unsigned int remote_ent_type = media_entity_type(remote->entity);
 	int ret = 0;
 
 	if (WARN_ON(fimc = NULL))
@@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 
 	switch (local->index) {
 	case FLITE_SD_PAD_SINK:
-		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
+		if (!is_media_entity_v4l2_subdev(remote->entity)) {
 			ret = -EINVAL;
 			break;
 		}
@@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 	case FLITE_SD_PAD_SOURCE_DMA:
 		if (!(flags & MEDIA_LNK_FL_ENABLED))
 			atomic_set(&fimc->out_path, FIMC_IO_NONE);
-		else if (remote_ent_type = MEDIA_ENT_T_DEVNODE)
+		else if (is_media_entity_v4l2_io(remote->entity))
 			atomic_set(&fimc->out_path, FIMC_IO_DMA);
 		else
 			ret = -EINVAL;
@@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 	case FLITE_SD_PAD_SOURCE_ISP:
 		if (!(flags & MEDIA_LNK_FL_ENABLED))
 			atomic_set(&fimc->out_path, FIMC_IO_NONE);
-		else if (remote_ent_type = MEDIA_ENT_T_V4L2_SUBDEV)
+		else if (is_media_entity_v4l2_subdev(remote->entity))
 			atomic_set(&fimc->out_path, FIMC_IO_ISP);
 		else
 			ret = -EINVAL;
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 92dbade2fffc..4a25df9dd869 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
 				break;
 		}
 
-		if (pad = NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 		sd = media_entity_to_v4l2_subdev(pad->entity);
 
@@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity))
 			continue;
 
 		ret  = __fimc_md_modify_pipeline(entity, enable);
@@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
 	media_entity_graph_walk_start(&graph, entity_err);
 
 	while ((entity_err = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity_err))
 			continue;
 
 		__fimc_md_modify_pipeline(entity_err, !enable);
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 69e7733d36cd..cb8ac90086c1 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_io(entity))
 			use += entity->use_count;
 	}
 
@@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
 	struct v4l2_subdev *subdev;
 	int ret;
 
-	subdev = media_entity_type(entity) = MEDIA_ENT_T_V4L2_SUBDEV
+	subdev = is_media_entity_v4l2_subdev(entity)
 	       ? media_entity_to_v4l2_subdev(entity) : NULL;
 
 	if (entity->use_count = 0 && change > 0 && subdev != NULL) {
@@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(entity))
 			ret = isp_pipeline_pm_power_one(entity, change);
 
 	if (!ret)
@@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
 
 	while ((first = media_entity_graph_walk_next(&graph))
 	       && first != entity)
-		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(first))
 			isp_pipeline_pm_power_one(first, -change);
 
 	return ret;
@@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad = NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
@@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad = NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 4c367352b1f7..52843ac2a9ca 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
 
 	remote = media_entity_remote_pad(&video->pad);
 
-	if (remote = NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
 		if (entity = &video->video.entity)
 			continue;
 
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity))
 			continue;
 
 		__video = to_isp_video(media_entity_to_video_device(entity));
@@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
 		return -EINVAL;
 	}
 
-	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!is_media_entity_v4l2_subdev(source))
 		return 0;
 
 	pipe->external = media_entity_to_v4l2_subdev(source);
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index eae667eab1b9..fb5b016cc0a1 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
 
 	/* Retrieve format at the sensor subdev source pad */
 	pad = media_entity_remote_pad(&camif->pads[0]);
-	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 		return -EPIPE;
 
 	src_fmt.pad = pad->index;
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index 1f94c1a54e00..f74158224b93 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
 	struct media_pad *remote;
 
 	remote = media_entity_remote_pad(local);
-	if (remote = NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
 			return -EPIPE;
 
 		/* We've reached a video node, that shouldn't have happened. */
-		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!is_media_entity_v4l2_subdev(pad->entity))
 			return -EPIPE;
 
 		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
@@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
 		struct vsp1_rwpf *rwpf;
 		struct vsp1_entity *e;
 
-		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
+		if (is_media_entity_v4l2_io(entity)) {
 			pipe->num_video++;
 			continue;
 		}
@@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
 	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
 
 	while (pad) {
-		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index 88cd789cdaf7..8e14841bf445 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
 	struct media_pad *remote;
 
 	remote = media_entity_remote_pad(local);
-	if (remote = NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad = NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index e6e1115d8215..60da43772de9 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -526,7 +526,7 @@ static int
 v4l2_subdev_link_validate_get_format(struct media_pad *pad,
 				     struct v4l2_subdev_format *fmt)
 {
-	if (media_entity_type(pad->entity) = MEDIA_ENT_T_V4L2_SUBDEV) {
+	if (is_media_entity_v4l2_subdev(pad->entity)) {
 		struct v4l2_subdev *sd  			media_entity_to_v4l2_subdev(pad->entity);
 
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 92573fa852a9..16763e0831f2 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		if (entity = &video->video_dev.entity)
 			continue;
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if ((!is_media_entity_v4l2_io(remote->entity))
 			continue;
 		far_end = to_vpfe_video(media_entity_to_video_device(entity));
 		if (far_end->type = V4L2_BUF_TYPE_VIDEO_OUTPUT)
@@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
 	media_entity_graph_walk_start(&graph, entity);
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 
-		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
+		if !is_media_entity_v4l2_subdev(entity))
 			continue;
 		subdev = media_entity_to_v4l2_subdev(entity);
 		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
@@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 
-		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_subdev(entity))
 			continue;
 		subdev = media_entity_to_v4l2_subdev(entity);
 		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 40591963b42b..44b88ff3ba83 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_io(entity))
 			use += entity->use_count;
 	}
 
@@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
 {
 	struct v4l2_subdev *subdev;
 
-	subdev = media_entity_type(entity) = MEDIA_ENT_T_V4L2_SUBDEV
+	subdev = is_media_entity_v4l2_subdev(entity)
 	       ? media_entity_to_v4l2_subdev(entity) : NULL;
 
 	if (entity->use_count = 0 && change > 0 && subdev != NULL) {
@@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(entity))
 			ret = iss_pipeline_pm_power_one(entity, change);
 
 	if (!ret)
@@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
 
 	while ((first = media_entity_graph_walk_next(&graph))
 	       && first != entity)
-		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(first))
 			iss_pipeline_pm_power_one(first, -change);
 
 	return ret;
@@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad = NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
@@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad = NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
index 45a3f2d778fc..cbe5783735dc 100644
--- a/drivers/staging/media/omap4iss/iss_video.c
+++ b/drivers/staging/media/omap4iss/iss_video.c
@@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
 
 	remote = media_entity_remote_pad(&video->pad);
 
-	if (remote = NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
 		if (entity = &video->video.entity)
 			continue;
 
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity))
 			continue;
 
 		far_end = to_iss_video(media_entity_to_video_device(entity));
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Kukjin Kim, Krzysztof Kozlowski,
	Laurent Pinchart, Hyun Kwon, Michal Simek, Sören Brinkmann,
	Greg Kroah-Hartman, Hans Verkuil, Prabhakar Lad,
	Lars-Peter Clausen, Markus Elfring, Sakari Ailus,
	Javier Martinez Canillas, linux-arm-kernel, linux-samsung-soc,
	linux-sh, devel

Instead of relying on media subtype, use the new macros to detect
if an entity is a subdev or an A/V DMA entity.

Please note that most drivers assume that there's just AV_DMA or
V4L2 subdevs. This is not true anymore, as we've added MC support
for DVB, and there are plans to add support for ALSA and FB/DRM
too.

Ok, on the current pipelines supported by those drivers, just V4L
stuff are there, but, assuming that some day a pipeline that also
works with other subsystems will ever added, it is better to add
explicit checks for the AV_DMA stuff.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
index 0eb34ecb8ee4..8c9a29e0e294 100644
--- a/drivers/media/platform/exynos4-is/common.c
+++ b/drivers/media/platform/exynos4-is/common.c
@@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
 	while (pad->flags & MEDIA_PAD_FL_SINK) {
 		/* source pad */
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		sd = media_entity_to_v4l2_subdev(pad->entity);
diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
index 0627a93b2f3b..e9810fee4c30 100644
--- a/drivers/media/platform/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
 			}
 		}
 
-		if (src_pad == NULL ||
-		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
 			break;
 
 		/* Don't call FIMC subdev operation to avoid nested locking */
@@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
 	struct fimc_vid_cap *vc = &fimc->vid_cap;
 	struct v4l2_subdev *sensor;
 
-	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!is_media_entity_v4l2_subdev(remote->entity))
 		return -EINVAL;
 
 	if (WARN_ON(fimc == NULL))
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 3d9ccbf5f10f..5fbaf5e39903 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
 
 		/* Retrieve format at the source pad */
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		sd = media_entity_to_v4l2_subdev(pad->entity);
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index b2607da4ad14..c2327147b360 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
 		}
 		/* Retrieve format at the source pad */
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		sd = media_entity_to_v4l2_subdev(pad->entity);
@@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 {
 	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
 	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
-	unsigned int remote_ent_type = media_entity_type(remote->entity);
 	int ret = 0;
 
 	if (WARN_ON(fimc == NULL))
@@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 
 	switch (local->index) {
 	case FLITE_SD_PAD_SINK:
-		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
+		if (!is_media_entity_v4l2_subdev(remote->entity)) {
 			ret = -EINVAL;
 			break;
 		}
@@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 	case FLITE_SD_PAD_SOURCE_DMA:
 		if (!(flags & MEDIA_LNK_FL_ENABLED))
 			atomic_set(&fimc->out_path, FIMC_IO_NONE);
-		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
+		else if (is_media_entity_v4l2_io(remote->entity))
 			atomic_set(&fimc->out_path, FIMC_IO_DMA);
 		else
 			ret = -EINVAL;
@@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 	case FLITE_SD_PAD_SOURCE_ISP:
 		if (!(flags & MEDIA_LNK_FL_ENABLED))
 			atomic_set(&fimc->out_path, FIMC_IO_NONE);
-		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
+		else if (is_media_entity_v4l2_subdev(remote->entity))
 			atomic_set(&fimc->out_path, FIMC_IO_ISP);
 		else
 			ret = -EINVAL;
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 92dbade2fffc..4a25df9dd869 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
 				break;
 		}
 
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 		sd = media_entity_to_v4l2_subdev(pad->entity);
 
@@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity))
 			continue;
 
 		ret  = __fimc_md_modify_pipeline(entity, enable);
@@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
 	media_entity_graph_walk_start(&graph, entity_err);
 
 	while ((entity_err = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity_err))
 			continue;
 
 		__fimc_md_modify_pipeline(entity_err, !enable);
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 69e7733d36cd..cb8ac90086c1 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_io(entity))
 			use += entity->use_count;
 	}
 
@@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
 	struct v4l2_subdev *subdev;
 	int ret;
 
-	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
+	subdev = is_media_entity_v4l2_subdev(entity)
 	       ? media_entity_to_v4l2_subdev(entity) : NULL;
 
 	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
@@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(entity))
 			ret = isp_pipeline_pm_power_one(entity, change);
 
 	if (!ret)
@@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
 
 	while ((first = media_entity_graph_walk_next(&graph))
 	       && first != entity)
-		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(first))
 			isp_pipeline_pm_power_one(first, -change);
 
 	return ret;
@@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
@@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 4c367352b1f7..52843ac2a9ca 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
 
 	remote = media_entity_remote_pad(&video->pad);
 
-	if (remote == NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
 		if (entity == &video->video.entity)
 			continue;
 
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity))
 			continue;
 
 		__video = to_isp_video(media_entity_to_video_device(entity));
@@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
 		return -EINVAL;
 	}
 
-	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!is_media_entity_v4l2_subdev(source))
 		return 0;
 
 	pipe->external = media_entity_to_v4l2_subdev(source);
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index eae667eab1b9..fb5b016cc0a1 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
 
 	/* Retrieve format at the sensor subdev source pad */
 	pad = media_entity_remote_pad(&camif->pads[0]);
-	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 		return -EPIPE;
 
 	src_fmt.pad = pad->index;
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index 1f94c1a54e00..f74158224b93 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
 	struct media_pad *remote;
 
 	remote = media_entity_remote_pad(local);
-	if (remote == NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
 			return -EPIPE;
 
 		/* We've reached a video node, that shouldn't have happened. */
-		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!is_media_entity_v4l2_subdev(pad->entity))
 			return -EPIPE;
 
 		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
@@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
 		struct vsp1_rwpf *rwpf;
 		struct vsp1_entity *e;
 
-		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
+		if (is_media_entity_v4l2_io(entity)) {
 			pipe->num_video++;
 			continue;
 		}
@@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
 	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
 
 	while (pad) {
-		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index 88cd789cdaf7..8e14841bf445 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
 	struct media_pad *remote;
 
 	remote = media_entity_remote_pad(local);
-	if (remote == NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index e6e1115d8215..60da43772de9 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -526,7 +526,7 @@ static int
 v4l2_subdev_link_validate_get_format(struct media_pad *pad,
 				     struct v4l2_subdev_format *fmt)
 {
-	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
+	if (is_media_entity_v4l2_subdev(pad->entity)) {
 		struct v4l2_subdev *sd =
 			media_entity_to_v4l2_subdev(pad->entity);
 
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 92573fa852a9..16763e0831f2 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		if (entity == &video->video_dev.entity)
 			continue;
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if ((!is_media_entity_v4l2_io(remote->entity))
 			continue;
 		far_end = to_vpfe_video(media_entity_to_video_device(entity));
 		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
@@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
 	media_entity_graph_walk_start(&graph, entity);
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 
-		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
+		if !is_media_entity_v4l2_subdev(entity))
 			continue;
 		subdev = media_entity_to_v4l2_subdev(entity);
 		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
@@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 
-		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_subdev(entity))
 			continue;
 		subdev = media_entity_to_v4l2_subdev(entity);
 		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 40591963b42b..44b88ff3ba83 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_io(entity))
 			use += entity->use_count;
 	}
 
@@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
 {
 	struct v4l2_subdev *subdev;
 
-	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
+	subdev = is_media_entity_v4l2_subdev(entity)
 	       ? media_entity_to_v4l2_subdev(entity) : NULL;
 
 	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
@@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(entity))
 			ret = iss_pipeline_pm_power_one(entity, change);
 
 	if (!ret)
@@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
 
 	while ((first = media_entity_graph_walk_next(&graph))
 	       && first != entity)
-		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(first))
 			iss_pipeline_pm_power_one(first, -change);
 
 	return ret;
@@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
@@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
index 45a3f2d778fc..cbe5783735dc 100644
--- a/drivers/staging/media/omap4iss/iss_video.c
+++ b/drivers/staging/media/omap4iss/iss_video.c
@@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
 
 	remote = media_entity_remote_pad(&video->pad);
 
-	if (remote == NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
 		if (entity == &video->video.entity)
 			continue;
 
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity))
 			continue;
 
 		far_end = to_iss_video(media_entity_to_video_device(entity));
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Kukjin Kim, Krzysztof Kozlowski,
	Laurent Pinchart, Hyun Kwon, Michal Simek, Sören Brinkmann,
	Greg Kroah-Hartman, Hans Verkuil, Prabhakar Lad,
	Lars-Peter Clausen, Markus Elfring, Sakari Ailus,
	Javier Martinez Canillas, linux-arm-kernel, linux-samsung-soc,
	linux-sh, devel

Instead of relying on media subtype, use the new macros to detect
if an entity is a subdev or an A/V DMA entity.

Please note that most drivers assume that there's just AV_DMA or
V4L2 subdevs. This is not true anymore, as we've added MC support
for DVB, and there are plans to add support for ALSA and FB/DRM
too.

Ok, on the current pipelines supported by those drivers, just V4L
stuff are there, but, assuming that some day a pipeline that also
works with other subsystems will ever added, it is better to add
explicit checks for the AV_DMA stuff.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
index 0eb34ecb8ee4..8c9a29e0e294 100644
--- a/drivers/media/platform/exynos4-is/common.c
+++ b/drivers/media/platform/exynos4-is/common.c
@@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
 	while (pad->flags & MEDIA_PAD_FL_SINK) {
 		/* source pad */
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		sd = media_entity_to_v4l2_subdev(pad->entity);
diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
index 0627a93b2f3b..e9810fee4c30 100644
--- a/drivers/media/platform/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
 			}
 		}
 
-		if (src_pad == NULL ||
-		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
 			break;
 
 		/* Don't call FIMC subdev operation to avoid nested locking */
@@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
 	struct fimc_vid_cap *vc = &fimc->vid_cap;
 	struct v4l2_subdev *sensor;
 
-	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!is_media_entity_v4l2_subdev(remote->entity))
 		return -EINVAL;
 
 	if (WARN_ON(fimc == NULL))
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 3d9ccbf5f10f..5fbaf5e39903 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
 
 		/* Retrieve format at the source pad */
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		sd = media_entity_to_v4l2_subdev(pad->entity);
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index b2607da4ad14..c2327147b360 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
 		}
 		/* Retrieve format at the source pad */
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		sd = media_entity_to_v4l2_subdev(pad->entity);
@@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 {
 	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
 	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
-	unsigned int remote_ent_type = media_entity_type(remote->entity);
 	int ret = 0;
 
 	if (WARN_ON(fimc == NULL))
@@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 
 	switch (local->index) {
 	case FLITE_SD_PAD_SINK:
-		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
+		if (!is_media_entity_v4l2_subdev(remote->entity)) {
 			ret = -EINVAL;
 			break;
 		}
@@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 	case FLITE_SD_PAD_SOURCE_DMA:
 		if (!(flags & MEDIA_LNK_FL_ENABLED))
 			atomic_set(&fimc->out_path, FIMC_IO_NONE);
-		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
+		else if (is_media_entity_v4l2_io(remote->entity))
 			atomic_set(&fimc->out_path, FIMC_IO_DMA);
 		else
 			ret = -EINVAL;
@@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 	case FLITE_SD_PAD_SOURCE_ISP:
 		if (!(flags & MEDIA_LNK_FL_ENABLED))
 			atomic_set(&fimc->out_path, FIMC_IO_NONE);
-		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
+		else if (is_media_entity_v4l2_subdev(remote->entity))
 			atomic_set(&fimc->out_path, FIMC_IO_ISP);
 		else
 			ret = -EINVAL;
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 92dbade2fffc..4a25df9dd869 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
 				break;
 		}
 
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 		sd = media_entity_to_v4l2_subdev(pad->entity);
 
@@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity))
 			continue;
 
 		ret  = __fimc_md_modify_pipeline(entity, enable);
@@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
 	media_entity_graph_walk_start(&graph, entity_err);
 
 	while ((entity_err = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity_err))
 			continue;
 
 		__fimc_md_modify_pipeline(entity_err, !enable);
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 69e7733d36cd..cb8ac90086c1 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_io(entity))
 			use += entity->use_count;
 	}
 
@@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
 	struct v4l2_subdev *subdev;
 	int ret;
 
-	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
+	subdev = is_media_entity_v4l2_subdev(entity)
 	       ? media_entity_to_v4l2_subdev(entity) : NULL;
 
 	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
@@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(entity))
 			ret = isp_pipeline_pm_power_one(entity, change);
 
 	if (!ret)
@@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
 
 	while ((first = media_entity_graph_walk_next(&graph))
 	       && first != entity)
-		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(first))
 			isp_pipeline_pm_power_one(first, -change);
 
 	return ret;
@@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
@@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 4c367352b1f7..52843ac2a9ca 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
 
 	remote = media_entity_remote_pad(&video->pad);
 
-	if (remote == NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
 		if (entity == &video->video.entity)
 			continue;
 
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity))
 			continue;
 
 		__video = to_isp_video(media_entity_to_video_device(entity));
@@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
 		return -EINVAL;
 	}
 
-	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!is_media_entity_v4l2_subdev(source))
 		return 0;
 
 	pipe->external = media_entity_to_v4l2_subdev(source);
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index eae667eab1b9..fb5b016cc0a1 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
 
 	/* Retrieve format at the sensor subdev source pad */
 	pad = media_entity_remote_pad(&camif->pads[0]);
-	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 		return -EPIPE;
 
 	src_fmt.pad = pad->index;
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index 1f94c1a54e00..f74158224b93 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
 	struct media_pad *remote;
 
 	remote = media_entity_remote_pad(local);
-	if (remote == NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
 			return -EPIPE;
 
 		/* We've reached a video node, that shouldn't have happened. */
-		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!is_media_entity_v4l2_subdev(pad->entity))
 			return -EPIPE;
 
 		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
@@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
 		struct vsp1_rwpf *rwpf;
 		struct vsp1_entity *e;
 
-		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
+		if (is_media_entity_v4l2_io(entity)) {
 			pipe->num_video++;
 			continue;
 		}
@@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
 	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
 
 	while (pad) {
-		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index 88cd789cdaf7..8e14841bf445 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
 	struct media_pad *remote;
 
 	remote = media_entity_remote_pad(local);
-	if (remote == NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index e6e1115d8215..60da43772de9 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -526,7 +526,7 @@ static int
 v4l2_subdev_link_validate_get_format(struct media_pad *pad,
 				     struct v4l2_subdev_format *fmt)
 {
-	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
+	if (is_media_entity_v4l2_subdev(pad->entity)) {
 		struct v4l2_subdev *sd =
 			media_entity_to_v4l2_subdev(pad->entity);
 
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 92573fa852a9..16763e0831f2 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		if (entity == &video->video_dev.entity)
 			continue;
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if ((!is_media_entity_v4l2_io(remote->entity))
 			continue;
 		far_end = to_vpfe_video(media_entity_to_video_device(entity));
 		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
@@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
 	media_entity_graph_walk_start(&graph, entity);
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 
-		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
+		if !is_media_entity_v4l2_subdev(entity))
 			continue;
 		subdev = media_entity_to_v4l2_subdev(entity);
 		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
@@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 
-		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_subdev(entity))
 			continue;
 		subdev = media_entity_to_v4l2_subdev(entity);
 		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 40591963b42b..44b88ff3ba83 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_io(entity))
 			use += entity->use_count;
 	}
 
@@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
 {
 	struct v4l2_subdev *subdev;
 
-	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
+	subdev = is_media_entity_v4l2_subdev(entity)
 	       ? media_entity_to_v4l2_subdev(entity) : NULL;
 
 	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
@@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(entity))
 			ret = iss_pipeline_pm_power_one(entity, change);
 
 	if (!ret)
@@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
 
 	while ((first = media_entity_graph_walk_next(&graph))
 	       && first != entity)
-		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(first))
 			iss_pipeline_pm_power_one(first, -change);
 
 	return ret;
@@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
@@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
index 45a3f2d778fc..cbe5783735dc 100644
--- a/drivers/staging/media/omap4iss/iss_video.c
+++ b/drivers/staging/media/omap4iss/iss_video.c
@@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
 
 	remote = media_entity_remote_pad(&video->pad);
 
-	if (remote == NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
 		if (entity == &video->video.entity)
 			continue;
 
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity))
 			continue;
 
 		far_end = to_iss_video(media_entity_to_video_device(entity));
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: linux-arm-kernel

Instead of relying on media subtype, use the new macros to detect
if an entity is a subdev or an A/V DMA entity.

Please note that most drivers assume that there's just AV_DMA or
V4L2 subdevs. This is not true anymore, as we've added MC support
for DVB, and there are plans to add support for ALSA and FB/DRM
too.

Ok, on the current pipelines supported by those drivers, just V4L
stuff are there, but, assuming that some day a pipeline that also
works with other subsystems will ever added, it is better to add
explicit checks for the AV_DMA stuff.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
index 0eb34ecb8ee4..8c9a29e0e294 100644
--- a/drivers/media/platform/exynos4-is/common.c
+++ b/drivers/media/platform/exynos4-is/common.c
@@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
 	while (pad->flags & MEDIA_PAD_FL_SINK) {
 		/* source pad */
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		sd = media_entity_to_v4l2_subdev(pad->entity);
diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
index 0627a93b2f3b..e9810fee4c30 100644
--- a/drivers/media/platform/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
 			}
 		}
 
-		if (src_pad == NULL ||
-		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
 			break;
 
 		/* Don't call FIMC subdev operation to avoid nested locking */
@@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
 	struct fimc_vid_cap *vc = &fimc->vid_cap;
 	struct v4l2_subdev *sensor;
 
-	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!is_media_entity_v4l2_subdev(remote->entity))
 		return -EINVAL;
 
 	if (WARN_ON(fimc == NULL))
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 3d9ccbf5f10f..5fbaf5e39903 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
 
 		/* Retrieve format at the source pad */
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		sd = media_entity_to_v4l2_subdev(pad->entity);
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index b2607da4ad14..c2327147b360 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
 		}
 		/* Retrieve format at the source pad */
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		sd = media_entity_to_v4l2_subdev(pad->entity);
@@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 {
 	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
 	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
-	unsigned int remote_ent_type = media_entity_type(remote->entity);
 	int ret = 0;
 
 	if (WARN_ON(fimc == NULL))
@@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 
 	switch (local->index) {
 	case FLITE_SD_PAD_SINK:
-		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
+		if (!is_media_entity_v4l2_subdev(remote->entity)) {
 			ret = -EINVAL;
 			break;
 		}
@@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 	case FLITE_SD_PAD_SOURCE_DMA:
 		if (!(flags & MEDIA_LNK_FL_ENABLED))
 			atomic_set(&fimc->out_path, FIMC_IO_NONE);
-		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
+		else if (is_media_entity_v4l2_io(remote->entity))
 			atomic_set(&fimc->out_path, FIMC_IO_DMA);
 		else
 			ret = -EINVAL;
@@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 	case FLITE_SD_PAD_SOURCE_ISP:
 		if (!(flags & MEDIA_LNK_FL_ENABLED))
 			atomic_set(&fimc->out_path, FIMC_IO_NONE);
-		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
+		else if (is_media_entity_v4l2_subdev(remote->entity))
 			atomic_set(&fimc->out_path, FIMC_IO_ISP);
 		else
 			ret = -EINVAL;
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 92dbade2fffc..4a25df9dd869 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
 				break;
 		}
 
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 		sd = media_entity_to_v4l2_subdev(pad->entity);
 
@@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity))
 			continue;
 
 		ret  = __fimc_md_modify_pipeline(entity, enable);
@@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
 	media_entity_graph_walk_start(&graph, entity_err);
 
 	while ((entity_err = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity_err))
 			continue;
 
 		__fimc_md_modify_pipeline(entity_err, !enable);
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 69e7733d36cd..cb8ac90086c1 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_io(entity))
 			use += entity->use_count;
 	}
 
@@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
 	struct v4l2_subdev *subdev;
 	int ret;
 
-	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
+	subdev = is_media_entity_v4l2_subdev(entity)
 	       ? media_entity_to_v4l2_subdev(entity) : NULL;
 
 	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
@@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(entity))
 			ret = isp_pipeline_pm_power_one(entity, change);
 
 	if (!ret)
@@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
 
 	while ((first = media_entity_graph_walk_next(&graph))
 	       && first != entity)
-		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(first))
 			isp_pipeline_pm_power_one(first, -change);
 
 	return ret;
@@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
@@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 4c367352b1f7..52843ac2a9ca 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
 
 	remote = media_entity_remote_pad(&video->pad);
 
-	if (remote == NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
 		if (entity == &video->video.entity)
 			continue;
 
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity))
 			continue;
 
 		__video = to_isp_video(media_entity_to_video_device(entity));
@@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
 		return -EINVAL;
 	}
 
-	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!is_media_entity_v4l2_subdev(source))
 		return 0;
 
 	pipe->external = media_entity_to_v4l2_subdev(source);
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index eae667eab1b9..fb5b016cc0a1 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
 
 	/* Retrieve format at the sensor subdev source pad */
 	pad = media_entity_remote_pad(&camif->pads[0]);
-	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 		return -EPIPE;
 
 	src_fmt.pad = pad->index;
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index 1f94c1a54e00..f74158224b93 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
 	struct media_pad *remote;
 
 	remote = media_entity_remote_pad(local);
-	if (remote == NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
 			return -EPIPE;
 
 		/* We've reached a video node, that shouldn't have happened. */
-		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!is_media_entity_v4l2_subdev(pad->entity))
 			return -EPIPE;
 
 		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
@@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
 		struct vsp1_rwpf *rwpf;
 		struct vsp1_entity *e;
 
-		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
+		if (is_media_entity_v4l2_io(entity)) {
 			pipe->num_video++;
 			continue;
 		}
@@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
 	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
 
 	while (pad) {
-		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index 88cd789cdaf7..8e14841bf445 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
 	struct media_pad *remote;
 
 	remote = media_entity_remote_pad(local);
-	if (remote == NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index e6e1115d8215..60da43772de9 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -526,7 +526,7 @@ static int
 v4l2_subdev_link_validate_get_format(struct media_pad *pad,
 				     struct v4l2_subdev_format *fmt)
 {
-	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
+	if (is_media_entity_v4l2_subdev(pad->entity)) {
 		struct v4l2_subdev *sd =
 			media_entity_to_v4l2_subdev(pad->entity);
 
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 92573fa852a9..16763e0831f2 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		if (entity == &video->video_dev.entity)
 			continue;
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if ((!is_media_entity_v4l2_io(remote->entity))
 			continue;
 		far_end = to_vpfe_video(media_entity_to_video_device(entity));
 		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
@@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
 	media_entity_graph_walk_start(&graph, entity);
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 
-		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
+		if !is_media_entity_v4l2_subdev(entity))
 			continue;
 		subdev = media_entity_to_v4l2_subdev(entity);
 		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
@@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 
-		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_subdev(entity))
 			continue;
 		subdev = media_entity_to_v4l2_subdev(entity);
 		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 40591963b42b..44b88ff3ba83 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
-		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_io(entity))
 			use += entity->use_count;
 	}
 
@@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
 {
 	struct v4l2_subdev *subdev;
 
-	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
+	subdev = is_media_entity_v4l2_subdev(entity)
 	       ? media_entity_to_v4l2_subdev(entity) : NULL;
 
 	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
@@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
 	media_entity_graph_walk_start(&graph, entity);
 
 	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(entity))
 			ret = iss_pipeline_pm_power_one(entity, change);
 
 	if (!ret)
@@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
 
 	while ((first = media_entity_graph_walk_next(&graph))
 	       && first != entity)
-		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
+		if (is_media_entity_v4l2_subdev(first))
 			iss_pipeline_pm_power_one(first, -change);
 
 	return ret;
@@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
@@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
 			break;
 
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		entity = pad->entity;
diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
index 45a3f2d778fc..cbe5783735dc 100644
--- a/drivers/staging/media/omap4iss/iss_video.c
+++ b/drivers/staging/media/omap4iss/iss_video.c
@@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
 
 	remote = media_entity_remote_pad(&video->pad);
 
-	if (remote == NULL ||
-	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 
 	if (pad)
@@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
 		if (entity == &video->video.entity)
 			continue;
 
-		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
+		if (!is_media_entity_v4l2_io(entity))
 			continue;
 
 		far_end = to_iss_video(media_entity_to_video_device(entity));
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 33/55] [media] omap3/omap4/davinci: get rid of MEDIA_ENT_T_V4L2_SUBDEV abuse
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (34 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-12-06  2:08   ` Laurent Pinchart
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Laurent Pinchart,
	Greg Kroah-Hartman, Hans Verkuil, Sakari Ailus, Prabhakar Lad,
	Haneen Mohammed, Tapasweni Pathak, Boris BREZILLON,
	Mahati Chamarthy, Javier Martinez Canillas, devel

On omap3/omap4/davinci drivers, MEDIA_ENT_T_V4L2_SUBDEV macro is
abused in order to "simplify" the pad checks.

Basically, it does a logical or of this macro, in order to check
for a local index and if the entity is either a subdev or not.

As we'll get rid of MEDIA_ENT_T_V4L2_SUBDEV macro, replace it by
2 << 16 where it occurs, and add a note saying that the code
there is actually a hack.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c
index 9a811f5741fa..f0e530c98188 100644
--- a/drivers/media/platform/omap3isp/ispccdc.c
+++ b/drivers/media/platform/omap3isp/ispccdc.c
@@ -2513,9 +2513,14 @@ static int ccdc_link_setup(struct media_entity *entity,
 	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
 	struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
 	struct isp_device *isp = to_isp_device(ccdc);
+	int index = local->index;
 
-	switch (local->index | media_entity_type(remote->entity)) {
-	case CCDC_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
+	/* FIXME: this is actually a hack! */
+	if (is_media_entity_v4l2_subdev(remote->entity))
+		index |= 2 << 16;
+
+	switch (index) {
+	case CCDC_PAD_SINK | 2 << 16:
 		/* Read from the sensor (parallel interface), CCP2, CSI2a or
 		 * CSI2c.
 		 */
@@ -2543,7 +2548,7 @@ static int ccdc_link_setup(struct media_entity *entity,
 	 * Revisit this when it will be implemented, and return -EBUSY for now.
 	 */
 
-	case CCDC_PAD_SOURCE_VP | MEDIA_ENT_T_V4L2_SUBDEV:
+	case CCDC_PAD_SOURCE_VP | 2 << 16:
 		/* Write to preview engine, histogram and H3A. When none of
 		 * those links are active, the video port can be disabled.
 		 */
@@ -2556,7 +2561,7 @@ static int ccdc_link_setup(struct media_entity *entity,
 		}
 		break;
 
-	case CCDC_PAD_SOURCE_OF | MEDIA_ENT_T_DEVNODE:
+	case CCDC_PAD_SOURCE_OF:
 		/* Write to memory */
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (ccdc->output & ~CCDC_OUTPUT_MEMORY)
@@ -2567,7 +2572,7 @@ static int ccdc_link_setup(struct media_entity *entity,
 		}
 		break;
 
-	case CCDC_PAD_SOURCE_OF | MEDIA_ENT_T_V4L2_SUBDEV:
+	case CCDC_PAD_SOURCE_OF | 2 << 16:
 		/* Write to resizer */
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (ccdc->output & ~CCDC_OUTPUT_RESIZER)
diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c
index 6ec7d104ab75..ae3038e643cc 100644
--- a/drivers/media/platform/omap3isp/ispccp2.c
+++ b/drivers/media/platform/omap3isp/ispccp2.c
@@ -956,9 +956,14 @@ static int ccp2_link_setup(struct media_entity *entity,
 {
 	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
 	struct isp_ccp2_device *ccp2 = v4l2_get_subdevdata(sd);
+	int index = local->index;
 
-	switch (local->index | media_entity_type(remote->entity)) {
-	case CCP2_PAD_SINK | MEDIA_ENT_T_DEVNODE:
+	/* FIXME: this is actually a hack! */
+	if (is_media_entity_v4l2_subdev(remote->entity))
+		index |= 2 << 16;
+
+	switch (index) {
+	case CCP2_PAD_SINK:
 		/* read from memory */
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (ccp2->input == CCP2_INPUT_SENSOR)
@@ -970,7 +975,7 @@ static int ccp2_link_setup(struct media_entity *entity,
 		}
 		break;
 
-	case CCP2_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
+	case CCP2_PAD_SINK | 2 << 16:
 		/* read from sensor/phy */
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (ccp2->input == CCP2_INPUT_MEMORY)
@@ -981,7 +986,7 @@ static int ccp2_link_setup(struct media_entity *entity,
 				ccp2->input = CCP2_INPUT_NONE;
 		} break;
 
-	case CCP2_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
+	case CCP2_PAD_SOURCE | 2 << 16:
 		/* write to video port/ccdc */
 		if (flags & MEDIA_LNK_FL_ENABLED)
 			ccp2->output = CCP2_OUTPUT_CCDC;
diff --git a/drivers/media/platform/omap3isp/ispcsi2.c b/drivers/media/platform/omap3isp/ispcsi2.c
index 0fb057a74f69..b1617f7efdee 100644
--- a/drivers/media/platform/omap3isp/ispcsi2.c
+++ b/drivers/media/platform/omap3isp/ispcsi2.c
@@ -1144,14 +1144,19 @@ static int csi2_link_setup(struct media_entity *entity,
 	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
 	struct isp_csi2_device *csi2 = v4l2_get_subdevdata(sd);
 	struct isp_csi2_ctrl_cfg *ctrl = &csi2->ctrl;
+	int index = local->index;
 
 	/*
 	 * The ISP core doesn't support pipelines with multiple video outputs.
 	 * Revisit this when it will be implemented, and return -EBUSY for now.
 	 */
 
-	switch (local->index | media_entity_type(remote->entity)) {
-	case CSI2_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
+	/* FIXME: this is actually a hack! */
+	if (is_media_entity_v4l2_subdev(remote->entity))
+		index |= 2 << 16;
+
+	switch (index) {
+	case CSI2_PAD_SOURCE:
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (csi2->output & ~CSI2_OUTPUT_MEMORY)
 				return -EBUSY;
@@ -1161,7 +1166,7 @@ static int csi2_link_setup(struct media_entity *entity,
 		}
 		break;
 
-	case CSI2_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
+	case CSI2_PAD_SOURCE | 2 << 16:
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (csi2->output & ~CSI2_OUTPUT_CCDC)
 				return -EBUSY;
diff --git a/drivers/media/platform/omap3isp/isppreview.c b/drivers/media/platform/omap3isp/isppreview.c
index 6986d2f65c19..cfb2debb02bf 100644
--- a/drivers/media/platform/omap3isp/isppreview.c
+++ b/drivers/media/platform/omap3isp/isppreview.c
@@ -2144,9 +2144,14 @@ static int preview_link_setup(struct media_entity *entity,
 {
 	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
 	struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
+	int index = local->index;
 
-	switch (local->index | media_entity_type(remote->entity)) {
-	case PREV_PAD_SINK | MEDIA_ENT_T_DEVNODE:
+	/* FIXME: this is actually a hack! */
+	if (is_media_entity_v4l2_subdev(remote->entity))
+		index |= 2 << 16;
+
+	switch (index) {
+	case PREV_PAD_SINK:
 		/* read from memory */
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (prev->input == PREVIEW_INPUT_CCDC)
@@ -2158,7 +2163,7 @@ static int preview_link_setup(struct media_entity *entity,
 		}
 		break;
 
-	case PREV_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
+	case PREV_PAD_SINK | 2 << 16:
 		/* read from ccdc */
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (prev->input == PREVIEW_INPUT_MEMORY)
@@ -2175,7 +2180,7 @@ static int preview_link_setup(struct media_entity *entity,
 	 * Revisit this when it will be implemented, and return -EBUSY for now.
 	 */
 
-	case PREV_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
+	case PREV_PAD_SOURCE:
 		/* write to memory */
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (prev->output & ~PREVIEW_OUTPUT_MEMORY)
@@ -2186,7 +2191,7 @@ static int preview_link_setup(struct media_entity *entity,
 		}
 		break;
 
-	case PREV_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
+	case PREV_PAD_SOURCE | 2 << 16:
 		/* write to resizer */
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (prev->output & ~PREVIEW_OUTPUT_RESIZER)
diff --git a/drivers/media/platform/omap3isp/ispresizer.c b/drivers/media/platform/omap3isp/ispresizer.c
index 249af7f524f9..e3ecf1787fc4 100644
--- a/drivers/media/platform/omap3isp/ispresizer.c
+++ b/drivers/media/platform/omap3isp/ispresizer.c
@@ -1623,9 +1623,14 @@ static int resizer_link_setup(struct media_entity *entity,
 {
 	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
 	struct isp_res_device *res = v4l2_get_subdevdata(sd);
+	int index = local->index;
 
-	switch (local->index | media_entity_type(remote->entity)) {
-	case RESZ_PAD_SINK | MEDIA_ENT_T_DEVNODE:
+	/* FIXME: this is actually a hack! */
+	if (is_media_entity_v4l2_subdev(remote->entity))
+		index |= 2 << 16;
+
+	switch (index) {
+	case RESZ_PAD_SINK:
 		/* read from memory */
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (res->input == RESIZER_INPUT_VP)
@@ -1637,7 +1642,7 @@ static int resizer_link_setup(struct media_entity *entity,
 		}
 		break;
 
-	case RESZ_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
+	case RESZ_PAD_SINK | 2 << 16:
 		/* read from ccdc or previewer */
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (res->input == RESIZER_INPUT_MEMORY)
@@ -1649,7 +1654,7 @@ static int resizer_link_setup(struct media_entity *entity,
 		}
 		break;
 
-	case RESZ_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
+	case RESZ_PAD_SOURCE:
 		/* resizer always write to memory */
 		break;
 
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
index d96bdaaae50e..b66584ecb693 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
@@ -885,9 +885,14 @@ ipipeif_link_setup(struct media_entity *entity, const struct media_pad *local,
 	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
 	struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
 	struct vpfe_device *vpfe = to_vpfe_device(ipipeif);
+	int index = local->index;
 
-	switch (local->index | media_entity_type(remote->entity)) {
-	case IPIPEIF_PAD_SINK | MEDIA_ENT_T_DEVNODE:
+	/* FIXME: this is actually a hack! */
+	if (is_media_entity_v4l2_subdev(remote->entity))
+		index |= 2 << 16;
+
+	switch (index) {
+	case IPIPEIF_PAD_SINK:
 		/* Single shot mode */
 		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 			ipipeif->input = IPIPEIF_INPUT_NONE;
@@ -896,7 +901,7 @@ ipipeif_link_setup(struct media_entity *entity, const struct media_pad *local,
 		ipipeif->input = IPIPEIF_INPUT_MEMORY;
 		break;
 
-	case IPIPEIF_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
+	case IPIPEIF_PAD_SINK | 2 << 16:
 		/* read from isif */
 		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 			ipipeif->input = IPIPEIF_INPUT_NONE;
@@ -908,7 +913,7 @@ ipipeif_link_setup(struct media_entity *entity, const struct media_pad *local,
 		ipipeif->input = IPIPEIF_INPUT_ISIF;
 		break;
 
-	case IPIPEIF_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
+	case IPIPEIF_PAD_SOURCE | 2 << 16:
 		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 			ipipeif->output = IPIPEIF_OUTPUT_NONE;
 			break;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index df77288b0ec0..8ca0c1297ec8 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -1707,9 +1707,14 @@ isif_link_setup(struct media_entity *entity, const struct media_pad *local,
 {
 	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
 	struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
+	int index = local->index;
 
-	switch (local->index | media_entity_type(remote->entity)) {
-	case ISIF_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
+	/* FIXME: this is actually a hack! */
+	if (is_media_entity_v4l2_subdev(remote->entity))
+		index |= 2 << 16;
+
+	switch (index) {
+	case ISIF_PAD_SINK | 2 << 16:
 		/* read from decoder/sensor */
 		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 			isif->input = ISIF_INPUT_NONE;
@@ -1720,7 +1725,7 @@ isif_link_setup(struct media_entity *entity, const struct media_pad *local,
 		isif->input = ISIF_INPUT_PARALLEL;
 		break;
 
-	case ISIF_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
+	case ISIF_PAD_SOURCE:
 		/* write to memory */
 		if (flags & MEDIA_LNK_FL_ENABLED)
 			isif->output = ISIF_OUTPUT_MEMORY;
@@ -1728,7 +1733,7 @@ isif_link_setup(struct media_entity *entity, const struct media_pad *local,
 			isif->output = ISIF_OUTPUT_NONE;
 		break;
 
-	case ISIF_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
+	case ISIF_PAD_SOURCE | 2 << 16:
 		if (flags & MEDIA_LNK_FL_ENABLED)
 			isif->output = ISIF_OUTPUT_IPIPEIF;
 		else
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index ae942de3a23d..8eb6f5fda21c 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -1653,10 +1653,15 @@ static int resizer_link_setup(struct media_entity *entity,
 	struct vpfe_device *vpfe_dev = to_vpfe_device(resizer);
 	u16 ipipeif_source = vpfe_dev->vpfe_ipipeif.output;
 	u16 ipipe_source = vpfe_dev->vpfe_ipipe.output;
+	int index = local->index;
+
+	/* FIXME: this is actually a hack! */
+	if (is_media_entity_v4l2_subdev(remote->entity))
+		index |= 2 << 16;
 
 	if (&resizer->crop_resizer.subdev == sd) {
-		switch (local->index | media_entity_type(remote->entity)) {
-		case RESIZER_CROP_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
+		switch (index) {
+		case RESIZER_CROP_PAD_SINK | 2 << 16:
 			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 				resizer->crop_resizer.input =
 					RESIZER_CROP_INPUT_NONE;
@@ -1676,7 +1681,7 @@ static int resizer_link_setup(struct media_entity *entity,
 				return -EINVAL;
 			break;
 
-		case RESIZER_CROP_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
+		case RESIZER_CROP_PAD_SOURCE | 2 << 16:
 			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 				resizer->crop_resizer.output =
 				RESIZER_CROP_OUTPUT_NONE;
@@ -1688,7 +1693,7 @@ static int resizer_link_setup(struct media_entity *entity,
 			resizer->crop_resizer.output = RESIZER_A;
 			break;
 
-		case RESIZER_CROP_PAD_SOURCE2 | MEDIA_ENT_T_V4L2_SUBDEV:
+		case RESIZER_CROP_PAD_SOURCE2 | 2 << 16:
 			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 				resizer->crop_resizer.output2 =
 					RESIZER_CROP_OUTPUT_NONE;
@@ -1704,8 +1709,8 @@ static int resizer_link_setup(struct media_entity *entity,
 			return -EINVAL;
 		}
 	} else if (&resizer->resizer_a.subdev == sd) {
-		switch (local->index | media_entity_type(remote->entity)) {
-		case RESIZER_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
+		switch (index) {
+		case RESIZER_PAD_SINK | 2 << 16:
 			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 				resizer->resizer_a.input = RESIZER_INPUT_NONE;
 				break;
@@ -1715,7 +1720,7 @@ static int resizer_link_setup(struct media_entity *entity,
 			resizer->resizer_a.input = RESIZER_INPUT_CROP_RESIZER;
 			break;
 
-		case RESIZER_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
+		case RESIZER_PAD_SOURCE:
 			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 				resizer->resizer_a.output = RESIZER_OUTPUT_NONE;
 				break;
@@ -1729,8 +1734,8 @@ static int resizer_link_setup(struct media_entity *entity,
 			return -EINVAL;
 		}
 	} else if (&resizer->resizer_b.subdev == sd) {
-		switch (local->index | media_entity_type(remote->entity)) {
-		case RESIZER_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
+		switch (index) {
+		case RESIZER_PAD_SINK | 2 << 16:
 			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 				resizer->resizer_b.input = RESIZER_INPUT_NONE;
 				break;
@@ -1740,7 +1745,7 @@ static int resizer_link_setup(struct media_entity *entity,
 			resizer->resizer_b.input = RESIZER_INPUT_CROP_RESIZER;
 			break;
 
-		case RESIZER_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
+		case RESIZER_PAD_SOURCE:
 			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 				resizer->resizer_b.output = RESIZER_OUTPUT_NONE;
 				break;
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 16763e0831f2..9eef64e0f0ab 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		if (entity == &video->video_dev.entity)
 			continue;
-		if ((!is_media_entity_v4l2_io(remote->entity))
+		if (!is_media_entity_v4l2_io(entity))
 			continue;
 		far_end = to_vpfe_video(media_entity_to_video_device(entity));
 		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
@@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
 	media_entity_graph_walk_start(&graph, entity);
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 
-		if !is_media_entity_v4l2_subdev(entity))
+		if (!is_media_entity_v4l2_subdev(entity))
 			continue;
 		subdev = media_entity_to_v4l2_subdev(entity);
 		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
diff --git a/drivers/staging/media/omap4iss/iss_csi2.c b/drivers/staging/media/omap4iss/iss_csi2.c
index 6b4dcbfa9425..50a24e8e8129 100644
--- a/drivers/staging/media/omap4iss/iss_csi2.c
+++ b/drivers/staging/media/omap4iss/iss_csi2.c
@@ -1170,14 +1170,19 @@ static int csi2_link_setup(struct media_entity *entity,
 	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
 	struct iss_csi2_device *csi2 = v4l2_get_subdevdata(sd);
 	struct iss_csi2_ctrl_cfg *ctrl = &csi2->ctrl;
+	int index = local->index;
+
+	/* FIXME: this is actually a hack! */
+	if (is_media_entity_v4l2_subdev(remote->entity))
+		index |= 2 << 16;
 
 	/*
 	 * The ISS core doesn't support pipelines with multiple video outputs.
 	 * Revisit this when it will be implemented, and return -EBUSY for now.
 	 */
 
-	switch (local->index | media_entity_type(remote->entity)) {
-	case CSI2_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
+	switch (index) {
+	case CSI2_PAD_SOURCE:
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (csi2->output & ~CSI2_OUTPUT_MEMORY)
 				return -EBUSY;
@@ -1187,7 +1192,7 @@ static int csi2_link_setup(struct media_entity *entity,
 		}
 		break;
 
-	case CSI2_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
+	case CSI2_PAD_SOURCE | 2 << 16:
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (csi2->output & ~CSI2_OUTPUT_IPIPEIF)
 				return -EBUSY;
diff --git a/drivers/staging/media/omap4iss/iss_ipipeif.c b/drivers/staging/media/omap4iss/iss_ipipeif.c
index 44c432ef2ac5..e46b2c07bd5d 100644
--- a/drivers/staging/media/omap4iss/iss_ipipeif.c
+++ b/drivers/staging/media/omap4iss/iss_ipipeif.c
@@ -662,9 +662,14 @@ static int ipipeif_link_setup(struct media_entity *entity,
 	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
 	struct iss_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
 	struct iss_device *iss = to_iss_device(ipipeif);
+	int index = local->index;
 
-	switch (local->index | media_entity_type(remote->entity)) {
-	case IPIPEIF_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
+	/* FIXME: this is actually a hack! */
+	if (is_media_entity_v4l2_subdev(remote->entity))
+		index |= 2 << 16;
+
+	switch (index) {
+	case IPIPEIF_PAD_SINK | 2 << 16:
 		/* Read from the sensor CSI2a or CSI2b. */
 		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 			ipipeif->input = IPIPEIF_INPUT_NONE;
@@ -681,7 +686,7 @@ static int ipipeif_link_setup(struct media_entity *entity,
 
 		break;
 
-	case IPIPEIF_PAD_SOURCE_ISIF_SF | MEDIA_ENT_T_DEVNODE:
+	case IPIPEIF_PAD_SOURCE_ISIF_SF:
 		/* Write to memory */
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (ipipeif->output & ~IPIPEIF_OUTPUT_MEMORY)
@@ -692,7 +697,7 @@ static int ipipeif_link_setup(struct media_entity *entity,
 		}
 		break;
 
-	case IPIPEIF_PAD_SOURCE_VP | MEDIA_ENT_T_V4L2_SUBDEV:
+	case IPIPEIF_PAD_SOURCE_VP | 2 << 16:
 		/* Send to IPIPE/RESIZER */
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (ipipeif->output & ~IPIPEIF_OUTPUT_VP)
diff --git a/drivers/staging/media/omap4iss/iss_resizer.c b/drivers/staging/media/omap4iss/iss_resizer.c
index b659e465cb56..bc5001002cc5 100644
--- a/drivers/staging/media/omap4iss/iss_resizer.c
+++ b/drivers/staging/media/omap4iss/iss_resizer.c
@@ -717,9 +717,14 @@ static int resizer_link_setup(struct media_entity *entity,
 	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
 	struct iss_resizer_device *resizer = v4l2_get_subdevdata(sd);
 	struct iss_device *iss = to_iss_device(resizer);
+	int index = local->index;
 
-	switch (local->index | media_entity_type(remote->entity)) {
-	case RESIZER_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
+	/* FIXME: this is actually a hack! */
+	if (is_media_entity_v4l2_subdev(remote->entity))
+		index |= 2 << 16;
+
+	switch (index) {
+	case RESIZER_PAD_SINK | 2 << 16:
 		/* Read from IPIPE or IPIPEIF. */
 		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 			resizer->input = RESIZER_INPUT_NONE;
@@ -737,7 +742,7 @@ static int resizer_link_setup(struct media_entity *entity,
 
 		break;
 
-	case RESIZER_PAD_SOURCE_MEM | MEDIA_ENT_T_DEVNODE:
+	case RESIZER_PAD_SOURCE_MEM :
 		/* Write to memory */
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (resizer->output & ~RESIZER_OUTPUT_MEMORY)
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 34/55] [media] s5c73m3: fix subdev type
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (35 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-12-06  1:57   ` Laurent Pinchart
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Kyungmin Park,
	Andrzej Hajda

This sensor driver is abusing MEDIA_ENT_T_V4L2_SUBDEV, creating
some subdevs with a non-existing type.

As this is a sensor driver, the proper type is likely
MEDIA_ENT_T_CAM_SENSOR.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index c81bfbfea32f..abae37321c0c 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1688,7 +1688,7 @@ static int s5c73m3_probe(struct i2c_client *client,
 
 	state->sensor_pads[S5C73M3_JPEG_PAD].flags = MEDIA_PAD_FL_SOURCE;
 	state->sensor_pads[S5C73M3_ISP_PAD].flags = MEDIA_PAD_FL_SOURCE;
-	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
+	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
 
 	ret = media_entity_init(&sd->entity, S5C73M3_NUM_PADS,
 							state->sensor_pads);
@@ -1704,7 +1704,7 @@ static int s5c73m3_probe(struct i2c_client *client,
 	state->oif_pads[OIF_ISP_PAD].flags = MEDIA_PAD_FL_SINK;
 	state->oif_pads[OIF_JPEG_PAD].flags = MEDIA_PAD_FL_SINK;
 	state->oif_pads[OIF_SOURCE_PAD].flags = MEDIA_PAD_FL_SOURCE;
-	oif_sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
+	oif_sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
 
 	ret = media_entity_init(&oif_sd->entity, OIF_NUM_PADS,
 							state->oif_pads);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 35/55] [media] s5k5baf: fix subdev type
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (36 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-12-06  1:55   ` Laurent Pinchart
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Kyungmin Park,
	Andrzej Hajda

X-Patchwork-Delegate: m.chehab@samsung.com
This sensor driver is abusing MEDIA_ENT_T_V4L2_SUBDEV, creating
some subdevs with a non-existing type.

As this is a sensor driver, the proper type is likely
MEDIA_ENT_T_V4L2_SUBDEV_SENSOR.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index d3bff30bcb6f..0513196bd48c 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -1919,7 +1919,7 @@ static int s5k5baf_configure_subdevs(struct s5k5baf *state,
 
 	state->pads[PAD_CIS].flags = MEDIA_PAD_FL_SINK;
 	state->pads[PAD_OUT].flags = MEDIA_PAD_FL_SOURCE;
-	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
+	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
 	ret = media_entity_init(&sd->entity, NUM_ISP_PADS, state->pads);
 
 	if (!ret)
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 36/55] [media] davinci_vbpe: stop MEDIA_ENT_T_V4L2_SUBDEV abuse
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (37 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-12-06  1:52   ` Laurent Pinchart
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Greg Kroah-Hartman,
	Hans Verkuil, Prabhakar Lad, Sakari Ailus, Laurent Pinchart,
	Aya Mahfouz, Boris BREZILLON, Javier Martinez Canillas, devel

This driver is abusing MEDIA_ENT_T_V4L2_SUBDEV:

- it uses a hack to check if the remote entity is a subdev;
- it still uses the legacy entity subtype check macro, that
  will be removed soon.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
index b89a057b8b7e..7fd78329e3e1 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
@@ -1711,8 +1711,11 @@ ipipe_link_setup(struct media_entity *entity, const struct media_pad *local,
 	struct vpfe_device *vpfe_dev = to_vpfe_device(ipipe);
 	u16 ipipeif_sink = vpfe_dev->vpfe_ipipeif.input;
 
-	switch (local->index | media_entity_type(remote->entity)) {
-	case IPIPE_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
+	if (!is_media_entity_v4l2_subdev(remote->entity))
+		return -EINVAL;
+
+	switch (local->index) {
+	case IPIPE_PAD_SINK:
 		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 			ipipe->input = IPIPE_INPUT_NONE;
 			break;
@@ -1725,7 +1728,7 @@ ipipe_link_setup(struct media_entity *entity, const struct media_pad *local,
 			ipipe->input = IPIPE_INPUT_CCDC;
 		break;
 
-	case IPIPE_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
+	case IPIPE_PAD_SOURCE:
 		/* out to RESIZER */
 		if (flags & MEDIA_LNK_FL_ENABLED)
 			ipipe->output = IPIPE_OUTPUT_RESIZER;
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 9eef64e0f0ab..2dbf14b9bb5f 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -88,7 +88,7 @@ vpfe_video_remote_subdev(struct vpfe_video_device *video, u32 *pad)
 {
 	struct media_pad *remote = media_entity_remote_pad(&video->pad);
 
-	if (remote == NULL || remote->entity->type != MEDIA_ENT_T_V4L2_SUBDEV)
+	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
 		return NULL;
 	if (pad)
 		*pad = remote->index;
@@ -243,8 +243,7 @@ static int vpfe_video_validate_pipeline(struct vpfe_pipeline *pipe)
 
 		/* Retrieve the source format */
 		pad = media_entity_remote_pad(pad);
-		if (pad == NULL ||
-			pad->entity->type != MEDIA_ENT_T_V4L2_SUBDEV)
+		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
 			break;
 
 		subdev = media_entity_to_v4l2_subdev(pad->entity);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 37/55] [media] omap4iss: stop MEDIA_ENT_T_V4L2_SUBDEV abuse
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (38 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-12-06  1:46   ` Laurent Pinchart
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Laurent Pinchart,
	Greg Kroah-Hartman, devel

This driver is abusing MEDIA_ENT_T_V4L2_SUBDEV, as it uses a
hack to check if the remote entity is a subdev. Get rid of it.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/staging/media/omap4iss/iss_ipipe.c b/drivers/staging/media/omap4iss/iss_ipipe.c
index e1a7b7ba7362..eb91ec48a21e 100644
--- a/drivers/staging/media/omap4iss/iss_ipipe.c
+++ b/drivers/staging/media/omap4iss/iss_ipipe.c
@@ -447,8 +447,11 @@ static int ipipe_link_setup(struct media_entity *entity,
 	struct iss_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
 	struct iss_device *iss = to_iss_device(ipipe);
 
-	switch (local->index | media_entity_type(remote->entity)) {
-	case IPIPE_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
+	if (!is_media_entity_v4l2_subdev(remote->entity))
+		return -EINVAL;
+
+	switch (local->index) {
+	case IPIPE_PAD_SINK:
 		/* Read from IPIPEIF. */
 		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
 			ipipe->input = IPIPE_INPUT_NONE;
@@ -463,7 +466,7 @@ static int ipipe_link_setup(struct media_entity *entity,
 
 		break;
 
-	case IPIPE_PAD_SOURCE_VP | MEDIA_ENT_T_V4L2_SUBDEV:
+	case IPIPE_PAD_SOURCE_VP:
 		/* Send to RESIZER */
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (ipipe->output & ~IPIPE_OUTPUT_VP)
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 38/55] [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (39 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 11:43     ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Hans Verkuil,
	Laurent Pinchart, Sylwester Nawrocki, Prabhakar Lad,
	Lars-Peter Clausen, Markus Elfring, linux-api

Instead of abusing MEDIA_ENT_T_V4L2_SUBDEV, initialize
new subdev entities as MEDIA_ENT_T_UNKNOWN.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 659507bce63f..134fe7510195 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -435,6 +435,12 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 {
 	int i;
 
+	if (entity->type == MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN ||
+	    entity->type == MEDIA_ENT_T_UNKNOWN)
+		dev_warn(mdev->dev,
+			 "Entity type for entity %s was not initialized!\n",
+			 entity->name);
+
 	/* Warn if we apparently re-register an entity */
 	WARN_ON(entity->graph_obj.mdev != NULL);
 	entity->graph_obj.mdev = mdev;
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index 60da43772de9..b3bcc8253182 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -584,7 +584,7 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops)
 	sd->host_priv = NULL;
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	sd->entity.name = sd->name;
-	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
+	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN;
 #endif
 }
 EXPORT_SYMBOL(v4l2_subdev_init);
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 3bbda409353f..44b84aae8b02 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -42,6 +42,14 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
+/* Used values for media_entity_desc::type */
+
+/*
+ * Initial value when an entity is created
+ * Drivers should change it to something useful
+ */
+#define MEDIA_ENT_T_UNKNOWN	0x00000000
+
 /*
  * Base numbers for entity types
  *
@@ -77,6 +85,15 @@ struct media_device_info {
 #define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 7)
 
 /* V4L2 Sub-device entities */
+
+	/*
+	 * Subdevs are initialized with MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN,
+	 * in order to preserve backward compatibility.
+	 * Drivers should change to the proper subdev type before
+	 * registering the entity.
+	 */
+#define MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN	MEDIA_ENT_T_V4L2_SUBDEV_BASE
+
 #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
 #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
 #define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 39/55] [media] media controller: get rid of entity subtype on Kernel
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (40 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 11:44     ` Hans Verkuil
  2015-09-06 12:02     ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, linux-api

Don't use anymore the type/subtype entity data/macros
inside the Kernel.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index b0cfbc0dffc7..756e1960fd7f 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -185,16 +185,6 @@ struct media_intf_devnode {
 	u32				minor;
 };
 
-static inline u32 media_entity_type(struct media_entity *entity)
-{
-	return entity->type & MEDIA_ENT_TYPE_MASK;
-}
-
-static inline u32 media_entity_subtype(struct media_entity *entity)
-{
-	return entity->type & MEDIA_ENT_SUBTYPE_MASK;
-}
-
 static inline u32 media_entity_id(struct media_entity *entity)
 {
 	return entity->graph_obj.id;
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 44b84aae8b02..cd486fc25f1e 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -42,10 +42,8 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
-/* Used values for media_entity_desc::type */
-
 /*
- * Initial value when an entity is created
+ * Initial value to be used when a new entity is created
  * Drivers should change it to something useful
  */
 #define MEDIA_ENT_T_UNKNOWN	0x00000000
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 40/55] [media] media.h: don't use legacy entity macros at Kernel
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, linux-api

Put the legacy MEDIA_ENT_* macros under a #ifndef __KERNEL__,
in order to be sure that none of those old symbols are used
inside the Kernel.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index cd486fc25f1e..4186891e5e81 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -107,6 +107,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 3)
 #define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 4)
 
+#ifndef __KERNEL__
 /* Legacy symbols used to avoid userspace compilation breakages */
 #define MEDIA_ENT_TYPE_SHIFT		16
 #define MEDIA_ENT_TYPE_MASK		0x00ff0000
@@ -120,6 +121,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
 #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
 #define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
+#endif
 
 /* Entity types */
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 40/55] [media] media.h: don't use legacy entity macros at Kernel
@ 2015-08-30  3:06   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab,
	linux-api-u79uwXL29TY76Z2rM5mHXA

Put the legacy MEDIA_ENT_* macros under a #ifndef __KERNEL__,
in order to be sure that none of those old symbols are used
inside the Kernel.

Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>

diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index cd486fc25f1e..4186891e5e81 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -107,6 +107,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 3)
 #define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 4)
 
+#ifndef __KERNEL__
 /* Legacy symbols used to avoid userspace compilation breakages */
 #define MEDIA_ENT_TYPE_SHIFT		16
 #define MEDIA_ENT_TYPE_MASK		0x00ff0000
@@ -120,6 +121,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
 #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
 #define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
+#endif
 
 /* Entity types */
 
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 41/55] [media] DocBook: update descriptions for the media controller entities
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (42 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 11:22   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Jonathan Corbet,
	Hans Verkuil, linux-doc

Cleanup the media controller entities description:
- remove MEDIA_ENT_T_DEVNODE and MEDIA_ENT_T_V4L2_SUBDEV entity
  types, as they don't mean anything;
- add MEDIA_ENT_T_UNKNOWN with a proper description;
- remove ALSA and FB entity types. Those should not be used, as
  the types are deprecated. We'll soon be adidng ALSA, but with
  a different entity namespace;
- improve the description of some entities.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
index 32a783635649..bd90dde54416 100644
--- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
+++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
@@ -179,70 +179,59 @@
         <colspec colname="c2"/>
 	<tbody valign="top">
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE</constant></entry>
-	    <entry>Unknown device node</entry>
+	    <entry><constant>MEDIA_ENT_T_UNKNOWN</constant> and <constant>MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN</constant></entry>
+	    <entry>Unknown entity. That generally indicates that
+	    a driver didn't initialize properly the entity, with is a Kernel bug</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
-	    <entry>V4L video, radio or vbi device node</entry>
-	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_FB</constant></entry>
-	    <entry>Frame buffer device node</entry>
-	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_ALSA</constant></entry>
-	    <entry>ALSA card</entry>
+	    <entry>V4L video streaming input or output entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD</constant></entry>
-	    <entry>DVB frontend devnode</entry>
+	    <entry>DVB demodulator entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMUX</constant></entry>
-	    <entry>DVB demux devnode</entry>
+	    <entry>DVB demux entity. Could be implemented on hardware or in Kernelspace</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_TSOUT</constant></entry>
-	    <entry>DVB DVR devnode</entry>
+	    <entry>DVB Transport Stream output entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_CA</constant></entry>
-	    <entry>DVB CAM devnode</entry>
+	    <entry>DVB Conditional Access module (CAM) entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD_NET_DECAP</constant></entry>
-	    <entry>DVB network devnode</entry>
-	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV</constant></entry>
-	    <entry>Unknown V4L sub-device</entry>
+	    <entry>DVB network ULE/MLE desencapsulation entity. Could be implemented on hardware or in Kernelspace</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_SENSOR</constant></entry>
-	    <entry>Video sensor</entry>
+	    <entry>Camera video sensor entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_FLASH</constant></entry>
-	    <entry>Flash controller</entry>
+	    <entry>Flash controller entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_LENS</constant></entry>
-	    <entry>Lens controller</entry>
+	    <entry>Lens controller entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_DECODER</constant></entry>
-	    <entry>Video decoder, the basic function of the video decoder is to
-	    accept analogue video from a wide variety of sources such as
+	    <entry>Analog video decoder, the basic function of the video decoder
+	    is to accept analogue video from a wide variety of sources such as
 	    broadcast, DVD players, cameras and video cassette recorders, in
-	    either NTSC, PAL or HD format and still occasionally SECAM, separate
-	    it into its component parts, luminance and chrominance, and output
+	    either NTSC, PAL, SECAM or HD format, separating the stream
+	    into its component parts, luminance and chrominance, and output
 	    it in some digital video standard, with appropriate embedded timing
 	    signals.</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_TUNER</constant></entry>
-	    <entry>TV and/or radio tuner</entry>
+	    <entry>Digital TV, analog TV, radio and/or software radio tuner</entry>
 	  </row>
 	</tbody>
       </tgroup>
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 42/55] [media] dvb: modify core to implement interfaces/entities at MC new gen
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (43 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 11:49   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Stefan Richter,
	Changbing Xiong, Hans Verkuil, Markus Elfring, Jonathan Corbet,
	Akihiro Tsukada, Dan Carpenter, Tina Ruchandani, Antti Palosaari,
	Joe Perches, Eric W. Biederman, Vaishali Thakkar, Sakari Ailus,
	Laurent Pinchart, Takeshi Yoshimura, linux1394-devel

The Media Controller New Generation redefines the types for both
interfaces and entities to be used on DVB. Make the needed
changes at the DVB core for all interfaces, entities and
data and interface links to appear in the graph.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c
index d0e3f9d85f34..baaed28ee975 100644
--- a/drivers/media/dvb-core/dmxdev.c
+++ b/drivers/media/dvb-core/dmxdev.c
@@ -1242,9 +1242,9 @@ int dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *dvb_adapter)
 	}
 
 	dvb_register_device(dvb_adapter, &dmxdev->dvbdev, &dvbdev_demux, dmxdev,
-			    DVB_DEVICE_DEMUX);
+			    DVB_DEVICE_DEMUX, dmxdev->filternum);
 	dvb_register_device(dvb_adapter, &dmxdev->dvr_dvbdev, &dvbdev_dvr,
-			    dmxdev, DVB_DEVICE_DVR);
+			    dmxdev, DVB_DEVICE_DVR, dmxdev->filternum);
 
 	dvb_ringbuffer_init(&dmxdev->dvr_buffer, NULL, 8192);
 
diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb-core/dvb_ca_en50221.c
index fb66184dc9b6..f82cd1ff4f3a 100644
--- a/drivers/media/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb-core/dvb_ca_en50221.c
@@ -1695,7 +1695,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 	pubca->private = ca;
 
 	/* register the DVB device */
-	ret = dvb_register_device(dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, DVB_DEVICE_CA);
+	ret = dvb_register_device(dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, DVB_DEVICE_CA, 0);
 	if (ret)
 		goto free_slot_info;
 
diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index 2d06bcff0946..58601bfe0b8d 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -2754,7 +2754,7 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
 			fe->dvb->num, fe->id, fe->ops.info.name);
 
 	dvb_register_device (fe->dvb, &fepriv->dvbdev, &dvbdev_template,
-			     fe, DVB_DEVICE_FRONTEND);
+			     fe, DVB_DEVICE_FRONTEND, 0);
 
 	/*
 	 * Initialize the cache to the proper values according with the
diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c
index b81e026edab3..14f51b68f4fe 100644
--- a/drivers/media/dvb-core/dvb_net.c
+++ b/drivers/media/dvb-core/dvb_net.c
@@ -1503,6 +1503,6 @@ int dvb_net_init (struct dvb_adapter *adap, struct dvb_net *dvbnet,
 		dvbnet->state[i] = 0;
 
 	return dvb_register_device(adap, &dvbnet->dvbdev, &dvbdev_net,
-			     dvbnet, DVB_DEVICE_NET);
+			     dvbnet, DVB_DEVICE_NET, 0);
 }
 EXPORT_SYMBOL(dvb_net_init);
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 88013d1a2c39..f638c67defbe 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -180,18 +180,86 @@ skip:
 	return -ENFILE;
 }
 
+static void dvb_create_tsout_entity(struct dvb_device *dvbdev,
+				    const char *name, int npads)
+{
+#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
+	int i, ret = 0;
+
+	dvbdev->tsout_pads = kcalloc(npads, sizeof(*dvbdev->tsout_pads),
+				     GFP_KERNEL);
+	if (!dvbdev->tsout_pads)
+		return;
+	dvbdev->tsout_entity = kcalloc(npads, sizeof(*dvbdev->tsout_entity),
+				       GFP_KERNEL);
+	if (!dvbdev->tsout_entity) {
+		kfree(dvbdev->tsout_pads);
+		dvbdev->tsout_pads = NULL;
+		return;
+	}
+	for (i = 0; i < npads; i++) {
+		struct media_pad *pads = &dvbdev->tsout_pads[i];
+		struct media_entity *entity = &dvbdev->tsout_entity[i];
+
+		entity->name = kasprintf(GFP_KERNEL, "%s #%d", name, i);
+		if (!entity->name) {
+			ret = -ENOMEM;
+			break;
+		}
+
+		entity->type = MEDIA_ENT_T_DVB_TSOUT;
+		pads->flags = MEDIA_PAD_FL_SINK;
+
+		ret = media_entity_init(entity, 1, pads);
+		if (ret < 0)
+			break;
+
+		ret = media_device_register_entity(dvbdev->adapter->mdev,
+						   entity);
+		if (ret < 0)
+			break;
+	}
+
+	if (!ret) {
+		dvbdev->tsout_num_entities = npads;
+		return;
+	}
+
+	for (i--; i >= 0; i--) {
+		media_device_unregister_entity(&dvbdev->tsout_entity[i]);
+		kfree(dvbdev->tsout_entity[i].name);
+	}
+
+	printk(KERN_ERR
+		"%s: media_device_register_entity failed for %s\n",
+		__func__, name);
+
+	kfree(dvbdev->tsout_entity);
+	kfree(dvbdev->tsout_pads);
+	dvbdev->tsout_entity = NULL;
+	dvbdev->tsout_pads = NULL;
+#endif
+}
+
+#define DEMUX_TSOUT	"demux_tsout"
+#define DVR_TSOUT	"dvr_tsout"
+
 static void dvb_create_media_entity(struct dvb_device *dvbdev,
-				       int type, int minor)
+				    int type, int demux_sink_pads)
 {
 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
-	int ret = 0, npads;
+	int i, ret = 0, npads;
 
 	switch (type) {
 	case DVB_DEVICE_FRONTEND:
 		npads = 2;
 		break;
+	case DVB_DEVICE_DVR:
+		dvb_create_tsout_entity(dvbdev, DVR_TSOUT, demux_sink_pads);
+		return;
 	case DVB_DEVICE_DEMUX:
-		npads = 2;
+		npads = 1 + demux_sink_pads;
+		dvb_create_tsout_entity(dvbdev, DEMUX_TSOUT, demux_sink_pads);
 		break;
 	case DVB_DEVICE_CA:
 		npads = 2;
@@ -215,8 +283,6 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
 	if (!dvbdev->entity)
 		return;
 
-	dvbdev->entity->info.dev.major = DVB_MAJOR;
-	dvbdev->entity->info.dev.minor = minor;
 	dvbdev->entity->name = dvbdev->name;
 
 	if (npads) {
@@ -237,7 +303,8 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
 	case DVB_DEVICE_DEMUX:
 		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMUX;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
-		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
+		for (i = 1; i < npads; i++)
+			dvbdev->pads[i].flags = MEDIA_PAD_FL_SOURCE;
 		break;
 	case DVB_DEVICE_CA:
 		dvbdev->entity->type = MEDIA_ENT_T_DVB_CA;
@@ -259,8 +326,16 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
 		printk(KERN_ERR
 			"%s: media_device_register_entity failed for %s\n",
 			__func__, dvbdev->entity->name);
+
+		media_device_unregister_entity(dvbdev->entity);
+		for (i = 0; i < dvbdev->tsout_num_entities; i++) {
+			media_device_unregister_entity(&dvbdev->tsout_entity[i]);
+			kfree(dvbdev->tsout_entity[i].name);
+		}
 		kfree(dvbdev->pads);
 		kfree(dvbdev->entity);
+		kfree(dvbdev->tsout_pads);
+		kfree(dvbdev->tsout_entity);
 		dvbdev->entity = NULL;
 		return;
 	}
@@ -271,7 +346,8 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
 }
 
 static void dvb_register_media_device(struct dvb_device *dvbdev,
-				      int type, int minor)
+				      int type, int minor,
+				      unsigned demux_sink_pads)
 {
 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
 	u32 intf_type;
@@ -279,7 +355,7 @@ static void dvb_register_media_device(struct dvb_device *dvbdev,
 	if (!dvbdev->adapter->mdev)
 		return;
 
-	dvb_create_media_entity(dvbdev, type, minor);
+	dvb_create_media_entity(dvbdev, type, demux_sink_pads);
 
 	switch (type) {
 	case DVB_DEVICE_FRONTEND:
@@ -323,7 +399,8 @@ static void dvb_register_media_device(struct dvb_device *dvbdev,
 }
 
 int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
-			const struct dvb_device *template, void *priv, int type)
+			const struct dvb_device *template, void *priv, int type,
+			int demux_sink_pads)
 {
 	struct dvb_device *dvbdev;
 	struct file_operations *dvbdevfops;
@@ -402,7 +479,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
 	dprintk(KERN_DEBUG "DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n",
 		adap->num, dnames[type], id, minor, minor);
 
-	dvb_register_media_device(dvbdev, type, minor);
+	dvb_register_media_device(dvbdev, type, minor, demux_sink_pads);
 
 	return 0;
 }
@@ -422,9 +499,18 @@ void dvb_unregister_device(struct dvb_device *dvbdev)
 
 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
 	if (dvbdev->entity) {
+		int i;
+
 		media_device_unregister_entity(dvbdev->entity);
+		for (i = 0; i < dvbdev->tsout_num_entities; i++) {
+			media_device_unregister_entity(&dvbdev->tsout_entity[i]);
+			kfree(dvbdev->tsout_entity[i].name);
+		}
+
 		kfree(dvbdev->entity);
 		kfree(dvbdev->pads);
+		kfree(dvbdev->tsout_entity);
+		kfree(dvbdev->tsout_pads);
 	}
 #endif
 
@@ -440,8 +526,10 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 {
 	struct media_device *mdev = adap->mdev;
 	struct media_entity *entity, *tuner = NULL, *demod = NULL;
-	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
+	struct media_entity *demux = NULL, *ca = NULL;
 	struct media_interface *intf;
+	unsigned demux_pad = 1;
+	unsigned dvr_pad = 1;
 
 	if (!mdev)
 		return;
@@ -457,9 +545,6 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 		case MEDIA_ENT_T_DVB_DEMUX:
 			demux = entity;
 			break;
-		case MEDIA_ENT_T_DVB_TSOUT:
-			dvr = entity;
-			break;
 		case MEDIA_ENT_T_DVB_CA:
 			ca = entity;
 			break;
@@ -471,24 +556,43 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 
 	if (demod && demux)
 		media_create_pad_link(demod, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
-
-	if (demux && dvr)
-		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
-
 	if (demux && ca)
 		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
 
+	/* Create demux links for each ringbuffer/pad */
+	if (demux) {
+		if (entity->type == MEDIA_ENT_T_DVB_TSOUT) {
+			if (!strncmp(entity->name, DVR_TSOUT,
+				     sizeof(DVR_TSOUT)))
+				media_create_pad_link(demux, ++dvr_pad,
+						      entity, 0, 0);
+			if (!strncmp(entity->name, DEMUX_TSOUT,
+				     sizeof(DEMUX_TSOUT)))
+				media_create_pad_link(demux, ++demux_pad,
+						      entity, 0, 0);
+		}
+	}
+
 	/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca */
 	list_for_each_entry(intf, &mdev->interfaces, list) {
 		if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
 			media_create_intf_link(ca, intf, 0);
 		if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
 			media_create_intf_link(tuner, intf, 0);
+
 		if (intf->type == MEDIA_INTF_T_DVB_DVR && demux)
 			media_create_intf_link(demux, intf, 0);
+
+		media_device_for_each_entity(entity, mdev) {
+			if (entity->type == MEDIA_ENT_T_DVB_TSOUT) {
+				if (!strcmp(entity->name, DVR_TSOUT))
+					media_create_intf_link(entity, intf, 0);
+				if (!strcmp(entity->name, DEMUX_TSOUT))
+					media_create_intf_link(entity, intf, 0);
+				break;
+			}
+		}
 	}
-
-
 }
 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
 #endif
diff --git a/drivers/media/dvb-core/dvbdev.h b/drivers/media/dvb-core/dvbdev.h
index 5f37b4dd1e69..0b140e8595de 100644
--- a/drivers/media/dvb-core/dvbdev.h
+++ b/drivers/media/dvb-core/dvbdev.h
@@ -148,9 +148,11 @@ struct dvb_device {
 	const char *name;
 
 	/* Allocated and filled inside dvbdev.c */
-	struct media_entity *entity;
 	struct media_intf_devnode *intf_devnode;
-	struct media_pad *pads;
+
+	unsigned tsout_num_entities;
+	struct media_entity *entity, *tsout_entity;
+	struct media_pad *pads, *tsout_pads;
 #endif
 
 	void *priv;
@@ -197,7 +199,8 @@ int dvb_register_device(struct dvb_adapter *adap,
 			struct dvb_device **pdvbdev,
 			const struct dvb_device *template,
 			void *priv,
-			int type);
+			int type,
+			int demux_sink_pads);
 
 /**
  * dvb_unregister_device - Unregisters a DVB device
diff --git a/drivers/media/firewire/firedtv-ci.c b/drivers/media/firewire/firedtv-ci.c
index e63f582378bf..edbb30fdd9d9 100644
--- a/drivers/media/firewire/firedtv-ci.c
+++ b/drivers/media/firewire/firedtv-ci.c
@@ -241,7 +241,7 @@ int fdtv_ca_register(struct firedtv *fdtv)
 		return -EFAULT;
 
 	err = dvb_register_device(&fdtv->adapter, &fdtv->cadev,
-				  &fdtv_ca, fdtv, DVB_DEVICE_CA);
+				  &fdtv_ca, fdtv, DVB_DEVICE_CA, 0);
 
 	if (stat.ca_application_info == 0)
 		dev_err(fdtv->device, "CaApplicationInfo is not set\n");
diff --git a/drivers/media/pci/bt8xx/dst_ca.c b/drivers/media/pci/bt8xx/dst_ca.c
index c5cc14ef8347..0149a9ed6e58 100644
--- a/drivers/media/pci/bt8xx/dst_ca.c
+++ b/drivers/media/pci/bt8xx/dst_ca.c
@@ -705,7 +705,8 @@ struct dvb_device *dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_
 	struct dvb_device *dvbdev;
 
 	dprintk(verbose, DST_CA_ERROR, 1, "registering DST-CA device");
-	if (dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA) == 0) {
+	if (dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst,
+			        DVB_DEVICE_CA, 0) == 0) {
 		dst->dst_ca = dvbdev;
 		return dst->dst_ca;
 	}
diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
index 0ac2dd35fe50..4caca5df2931 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1065,7 +1065,7 @@ static int ddb_ci_attach(struct ddb_port *port)
 			    port->en, 0, 1);
 	ret = dvb_register_device(&port->output->adap, &port->output->dev,
 				  &dvbdev_ci, (void *) port->output,
-				  DVB_DEVICE_SEC);
+				  DVB_DEVICE_SEC, 0);
 	return ret;
 }
 
diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c
index 1b92d836a564..4e924e2d1638 100644
--- a/drivers/media/pci/ngene/ngene-core.c
+++ b/drivers/media/pci/ngene/ngene-core.c
@@ -1513,7 +1513,7 @@ static int init_channel(struct ngene_channel *chan)
 		set_transfer(&chan->dev->channel[2], 1);
 		dvb_register_device(adapter, &chan->ci_dev,
 				    &ngene_dvbdev_ci, (void *) chan,
-				    DVB_DEVICE_SEC);
+				    DVB_DEVICE_SEC, 0);
 		if (!chan->ci_dev)
 			goto err;
 	}
diff --git a/drivers/media/pci/ttpci/av7110.c b/drivers/media/pci/ttpci/av7110.c
index 3f24fce74fc1..63f1d56bdfb2 100644
--- a/drivers/media/pci/ttpci/av7110.c
+++ b/drivers/media/pci/ttpci/av7110.c
@@ -1361,7 +1361,7 @@ static int av7110_register(struct av7110 *av7110)
 
 #ifdef CONFIG_DVB_AV7110_OSD
 	dvb_register_device(&av7110->dvb_adapter, &av7110->osd_dev,
-			    &dvbdev_osd, av7110, DVB_DEVICE_OSD);
+			    &dvbdev_osd, av7110, DVB_DEVICE_OSD, 0);
 #endif
 
 	dvb_net_init(&av7110->dvb_adapter, &av7110->dvb_net, &dvbdemux->dmx);
diff --git a/drivers/media/pci/ttpci/av7110_av.c b/drivers/media/pci/ttpci/av7110_av.c
index 9544cfc06601..da11501fe5d2 100644
--- a/drivers/media/pci/ttpci/av7110_av.c
+++ b/drivers/media/pci/ttpci/av7110_av.c
@@ -1589,10 +1589,10 @@ int av7110_av_register(struct av7110 *av7110)
 	memset(&av7110->video_size, 0, sizeof (video_size_t));
 
 	dvb_register_device(&av7110->dvb_adapter, &av7110->video_dev,
-			    &dvbdev_video, av7110, DVB_DEVICE_VIDEO);
+			    &dvbdev_video, av7110, DVB_DEVICE_VIDEO, 0);
 
 	dvb_register_device(&av7110->dvb_adapter, &av7110->audio_dev,
-			    &dvbdev_audio, av7110, DVB_DEVICE_AUDIO);
+			    &dvbdev_audio, av7110, DVB_DEVICE_AUDIO, 0);
 
 	return 0;
 }
diff --git a/drivers/media/pci/ttpci/av7110_ca.c b/drivers/media/pci/ttpci/av7110_ca.c
index a6079b90252a..235f0202dc7e 100644
--- a/drivers/media/pci/ttpci/av7110_ca.c
+++ b/drivers/media/pci/ttpci/av7110_ca.c
@@ -378,7 +378,7 @@ static struct dvb_device dvbdev_ca = {
 int av7110_ca_register(struct av7110 *av7110)
 {
 	return dvb_register_device(&av7110->dvb_adapter, &av7110->ca_dev,
-				   &dvbdev_ca, av7110, DVB_DEVICE_CA);
+				   &dvbdev_ca, av7110, DVB_DEVICE_CA, 0);
 }
 
 void av7110_ca_unregister(struct av7110 *av7110)
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 43/55] [media] media: report if a pad is sink or source at debug msg
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (44 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 11:51   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Sakari Ailus,
	Laurent Pinchart, Hans Verkuil

Sometimes, it is important to see if the created pad is
sink or source. Add info to track that.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index f638c67defbe..610d2bab1368 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -528,8 +528,8 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	struct media_entity *entity, *tuner = NULL, *demod = NULL;
 	struct media_entity *demux = NULL, *ca = NULL;
 	struct media_interface *intf;
-	unsigned demux_pad = 1;
-	unsigned dvr_pad = 1;
+	unsigned demux_pad = 0;
+	unsigned dvr_pad = 0;
 
 	if (!mdev)
 		return;
@@ -561,15 +561,19 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 
 	/* Create demux links for each ringbuffer/pad */
 	if (demux) {
-		if (entity->type == MEDIA_ENT_T_DVB_TSOUT) {
-			if (!strncmp(entity->name, DVR_TSOUT,
-				     sizeof(DVR_TSOUT)))
-				media_create_pad_link(demux, ++dvr_pad,
-						      entity, 0, 0);
-			if (!strncmp(entity->name, DEMUX_TSOUT,
-				     sizeof(DEMUX_TSOUT)))
-				media_create_pad_link(demux, ++demux_pad,
-						      entity, 0, 0);
+		media_device_for_each_entity(entity, mdev) {
+			if (entity->type == MEDIA_ENT_T_DVB_TSOUT) {
+				if (!strncmp(entity->name, DVR_TSOUT,
+					strlen(DVR_TSOUT)))
+					media_create_pad_link(demux,
+							      ++dvr_pad,
+							entity, 0, 0);
+				if (!strncmp(entity->name, DEMUX_TSOUT,
+					strlen(DEMUX_TSOUT)))
+					media_create_pad_link(demux,
+							      ++demux_pad,
+							entity, 0, 0);
+			}
 		}
 	}
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 15bc92d3a648..d62a6ffbc929 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -121,8 +121,11 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 		struct media_pad *pad = gobj_to_pad(gobj);
 
 		dev_dbg(gobj->mdev->dev,
-			"%s: id 0x%08x pad#%d: '%s':%d\n",
-			event_name, gobj->id, media_localid(gobj),
+			"%s: id 0x%08x %s%spad#%d: '%s':%d\n",
+			event_name, gobj->id,
+			pad->flags & MEDIA_PAD_FL_SINK   ? "  sink " : "",
+			pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
+			media_localid(gobj),
 			pad->entity->name, pad->index);
 		break;
 	}
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (45 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 12:00   ` Hans Verkuil
  2015-09-06 12:03     ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, linux-api

Add a new ioctl that will report the entire topology on
one go.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 756e1960fd7f..358a0c6b1f86 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -181,6 +181,8 @@ struct media_interface {
  */
 struct media_intf_devnode {
 	struct media_interface		intf;
+
+	/* Should match the fields at media_v2_intf_devnode */
 	u32				major;
 	u32				minor;
 };
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 4186891e5e81..fa0b68e670b0 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -251,11 +251,94 @@ struct media_links_enum {
 #define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
 #define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
 
-/* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
+/*
+ * MC next gen API definitions
+ *
+ * NOTE: The declarations below are close to the MC RFC for the Media
+ *	 Controller, the next generation. Yet, there are a few adjustments
+ *	 to do, as we want to be able to have a functional API before
+ *	 the MC properties change. Those will be properly marked below.
+ *	 Please also notice that I removed "num_pads", "num_links",
+ *	 from the proposal, as a proper userspace application will likely
+ *	 use lists for pads/links, just as we intend todo in Kernelspace.
+ *	 The API definition should be freed from fields that are bound to
+ *	 some specific data structure.
+ *
+ * FIXME: Currently, I opted to name the new types as "media_v2", as this
+ *	  won't cause any conflict with the Kernelspace namespace, nor with
+ *	  the previous kAPI media_*_desc namespace. This can be changed
+ *	  latter, before the adding this API upstream.
+ */
+
+
+#define MEDIA_NEW_LNK_FL_ENABLED		MEDIA_LNK_FL_ENABLED
+#define MEDIA_NEW_LNK_FL_IMMUTABLE		MEDIA_LNK_FL_IMMUTABLE
+#define MEDIA_NEW_LNK_FL_DYNAMIC		MEDIA_NEW_FL_DYNAMIC
+#define MEDIA_NEW_LNK_FL_INTERFACE_LINK		(1 << 3)
+
+struct media_v2_entity {
+	__u32 id;
+	char name[64];		/* FIXME: move to a property? (RFC says so) */
+	__u16 reserved[14];
+};
+
+/* Should match the specific fields at media_intf_devnode */
+struct media_v2_intf_devnode {
+	__u32 major;
+	__u32 minor;
+};
+
+struct media_v2_interface {
+	__u32 id;
+	__u32 intf_type;
+	__u32 flags;
+	__u32 reserved[9];
+
+	union {
+		struct media_v2_intf_devnode devnode;
+		__u32 raw[16];
+	};
+};
+
+struct media_v2_pad {
+	__u32 id;
+	__u32 entity_id;
+	__u32 flags;
+	__u16 reserved[9];
+};
+
+struct media_v2_link {
+    __u32 id;
+    __u32 source_id;
+    __u32 sink_id;
+    __u32 flags;
+    __u32 reserved[5];
+};
+
+struct media_v2_topology {
+	__u32 topology_version;
+
+	__u32 num_entities;
+	struct media_v2_entity *entities;
+
+	__u32 num_interfaces;
+	struct media_v2_interface *interfaces;
+
+	__u32 num_pads;
+	struct media_v2_pad *pads;
+
+	__u32 num_links;
+	struct media_v2_link *links;
+
+	__u32 reserved[64];
+};
+
+/* ioctls */
 
 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
 #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct media_entity_desc)
 #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
 #define MEDIA_IOC_SETUP_LINK		_IOWR('|', 0x03, struct media_link_desc)
+#define MEDIA_IOC_G_TOPOLOGY		_IOWR('|', 0x04, struct media_v2_topology)
 
 #endif /* __LINUX_MEDIA_H */
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 45/55] [media] media: Use a macro to interate between all interfaces
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (46 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 12:01   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Laurent Pinchart,
	Hans Verkuil, Sakari Ailus

Just like we do with entities, use a similar macro for the
interfaces loop.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 610d2bab1368..95b5b4b11230 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -578,9 +578,10 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	}
 
 	/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca */
-	list_for_each_entry(intf, &mdev->interfaces, list) {
+	media_device_for_each_intf(intf, mdev) {
 		if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
 			media_create_intf_link(ca, intf, 0);
+
 		if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
 			media_create_intf_link(tuner, intf, 0);
 
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 51807efa505b..f23d686aaac6 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -113,6 +113,11 @@ struct media_device *media_device_find_devres(struct device *dev);
 #define media_device_for_each_entity(entity, mdev)			\
 	list_for_each_entry(entity, &(mdev)->entities, list)
 
+/* Iterate over all interfaces. */
+#define media_device_for_each_intf(intf, mdev)			\
+	list_for_each_entry(intf, &(mdev)->interfaces, list)
+
+
 #else
 static inline int media_device_register(struct media_device *mdev)
 {
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 46/55] [media] media: move mdev list init to gobj
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (47 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 12:03   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Let's control the topology changes inside the graph_object.
So, move the removal of interfaces/entities from the mdev
lists to media_gobj_init() and media_gobj_remove().

The main reason is that mdev should have lists for all
object types, as the new MC api will require to store
objects in separate places.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 134fe7510195..ec98595b8a7a 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -415,7 +415,7 @@ void media_device_unregister(struct media_device *mdev)
 	struct media_entity *entity;
 	struct media_entity *next;
 
-	list_for_each_entry_safe(entity, next, &mdev->entities, list)
+	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
 		media_device_unregister_entity(entity);
 
 	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
@@ -449,7 +449,6 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	spin_lock(&mdev->lock);
 	/* Initialize media_gobj embedded at the entity */
 	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
-	list_add_tail(&entity->list, &mdev->entities);
 
 	/* Initialize objects at the pads */
 	for (i = 0; i < entity->num_pads; i++)
@@ -487,7 +486,6 @@ void media_device_unregister_entity(struct media_entity *entity)
 	for (i = 0; i < entity->num_pads; i++)
 		media_gobj_remove(&entity->pads[i].graph_obj);
 	media_gobj_remove(&entity->graph_obj);
-	list_del(&entity->list);
 	spin_unlock(&mdev->lock);
 	entity->graph_obj.mdev = NULL;
 }
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index d62a6ffbc929..192af193a394 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -170,6 +170,7 @@ void media_gobj_init(struct media_device *mdev,
 	switch (type) {
 	case MEDIA_GRAPH_ENTITY:
 		gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
+		list_add_tail(&gobj->list, &mdev->entities);
 		break;
 	case MEDIA_GRAPH_PAD:
 		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
@@ -178,6 +179,7 @@ void media_gobj_init(struct media_device *mdev,
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
 		break;
 	case MEDIA_GRAPH_INTF_DEVNODE:
+		list_add_tail(&gobj->list, &mdev->interfaces);
 		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
 		break;
 	}
@@ -193,6 +195,15 @@ void media_gobj_init(struct media_device *mdev,
  */
 void media_gobj_remove(struct media_gobj *gobj)
 {
+	/* Remove the object from mdev list */
+	switch (media_type(gobj)) {
+	case MEDIA_GRAPH_ENTITY:
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		list_del(&gobj->list);
+	default:
+		break;
+	}
+
 	dev_dbg_obj(__func__, gobj);
 }
 
@@ -864,8 +875,6 @@ static void media_interface_init(struct media_device *mdev,
 	INIT_LIST_HEAD(&intf->links);
 
 	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
-
-	list_add_tail(&intf->list, &mdev->interfaces);
 }
 
 /* Functions related to the media interface via device nodes */
@@ -894,7 +903,6 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
 	media_gobj_remove(&devnode->intf.graph_obj);
-	list_del(&devnode->intf.list);
 	kfree(devnode);
 }
 EXPORT_SYMBOL_GPL(media_devnode_remove);
diff --git a/include/media/media-device.h b/include/media/media-device.h
index f23d686aaac6..85fa302047bd 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -111,11 +111,11 @@ struct media_device *media_device_find_devres(struct device *dev);
 
 /* Iterate over all entities. */
 #define media_device_for_each_entity(entity, mdev)			\
-	list_for_each_entry(entity, &(mdev)->entities, list)
+	list_for_each_entry(entity, &(mdev)->entities, graph_obj.list)
 
 /* Iterate over all interfaces. */
 #define media_device_for_each_intf(intf, mdev)			\
-	list_for_each_entry(intf, &(mdev)->interfaces, list)
+	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
 
 
 #else
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 358a0c6b1f86..8c344a07636c 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -66,6 +66,7 @@ enum media_gobj_type {
 struct media_gobj {
 	struct media_device	*mdev;
 	u32			id;
+	struct list_head	list;
 };
 
 
@@ -114,7 +115,6 @@ struct media_entity_operations {
 
 struct media_entity {
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	struct list_head list;
 	const char *name;		/* Entity name */
 	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
 	u32 revision;			/* Entity revision, driver specific */
@@ -166,7 +166,6 @@ struct media_entity {
  */
 struct media_interface {
 	struct media_gobj		graph_obj;
-	struct list_head		list;
 	struct list_head		links;
 	u32				type;
 	u32				flags;
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 47/55] [media] media-device: add pads and links to media_device
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (48 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 12:25   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

The MC next gen API sends objects to userspace grouped by
their types.

In the case of pads and links, in order to improve performance
and have a simpler code, the best is to store them also on
separate linked lists at MC.

If we don't do that, we would need this kind of interaction
to send data to userspace (code is in structured english):

	for each entity:
		for each pad:
			store pads

	for each entity:
		for each link:
			store link

	for each interface:
		for each link:
			store link

With would require one nexted loop for pads and two nested
loops for links. By using  separate linked lists for them,
just one loop would be enough.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index ec98595b8a7a..5b2c9f7fcd45 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -382,6 +382,8 @@ int __must_check __media_device_register(struct media_device *mdev,
 
 	INIT_LIST_HEAD(&mdev->entities);
 	INIT_LIST_HEAD(&mdev->interfaces);
+	INIT_LIST_HEAD(&mdev->pads);
+	INIT_LIST_HEAD(&mdev->links);
 	spin_lock_init(&mdev->lock);
 	mutex_init(&mdev->graph_mutex);
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 192af193a394..c89f51bc688d 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -174,13 +174,15 @@ void media_gobj_init(struct media_device *mdev,
 		break;
 	case MEDIA_GRAPH_PAD:
 		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
+		list_add_tail(&gobj->list, &mdev->pads);
 		break;
 	case MEDIA_GRAPH_LINK:
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
+		list_add_tail(&gobj->list, &mdev->links);
 		break;
 	case MEDIA_GRAPH_INTF_DEVNODE:
-		list_add_tail(&gobj->list, &mdev->interfaces);
 		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
+		list_add_tail(&gobj->list, &mdev->interfaces);
 		break;
 	}
 	dev_dbg_obj(__func__, gobj);
@@ -195,16 +197,10 @@ void media_gobj_init(struct media_device *mdev,
  */
 void media_gobj_remove(struct media_gobj *gobj)
 {
+	dev_dbg_obj(__func__, gobj);
+
 	/* Remove the object from mdev list */
-	switch (media_type(gobj)) {
-	case MEDIA_GRAPH_ENTITY:
-	case MEDIA_GRAPH_INTF_DEVNODE:
-		list_del(&gobj->list);
-	default:
-		break;
-	}
-
-	dev_dbg_obj(__func__, gobj);
+	list_del(&gobj->list);
 }
 
 /**
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 85fa302047bd..0d1b9c687454 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -47,6 +47,8 @@ struct device;
  * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:	List of registered entities
  * @interfaces:	List of registered interfaces
+ * @pads:	List of registered pads
+ * @links:	List of registered links
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
  * @link_notify: Link state change notification callback
@@ -79,6 +81,8 @@ struct media_device {
 
 	struct list_head entities;
 	struct list_head interfaces;
+	struct list_head pads;
+	struct list_head links;
 
 	/* Protects the entities list */
 	spinlock_t lock;
@@ -117,6 +121,14 @@ struct media_device *media_device_find_devres(struct device *dev);
 #define media_device_for_each_intf(intf, mdev)			\
 	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
 
+/* Iterate over all pads. */
+#define media_device_for_each_pad(pad, mdev)			\
+	list_for_each_entry(pad, &(mdev)->pads, graph_obj.list)
+
+/* Iterate over all links. */
+#define media_device_for_each_link(link, mdev)			\
+	list_for_each_entry(link, &(mdev)->links, graph_obj.list)
+
 
 #else
 static inline int media_device_register(struct media_device *mdev)
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 48/55] [media] media_device: add a topology version field
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (49 preceding siblings ...)
  (?)
@ 2015-08-30  3:06 ` Mauro Carvalho Chehab
  2015-08-31 12:29   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:06 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Every time a graph object is added or removed, the version
of the topology changes. That's a requirement for the new
MEDIA_IOC_G_TOPOLOGY, in order to allow userspace to know
that the topology has changed after a previous call to it.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index c89f51bc688d..c18f4af52771 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -185,6 +185,9 @@ void media_gobj_init(struct media_device *mdev,
 		list_add_tail(&gobj->list, &mdev->interfaces);
 		break;
 	}
+
+	mdev->topology_version++;
+
 	dev_dbg_obj(__func__, gobj);
 }
 
@@ -199,6 +202,8 @@ void media_gobj_remove(struct media_gobj *gobj)
 {
 	dev_dbg_obj(__func__, gobj);
 
+	gobj->mdev->topology_version++;
+
 	/* Remove the object from mdev list */
 	list_del(&gobj->list);
 }
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 0d1b9c687454..1b12774a9ab4 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -41,6 +41,8 @@ struct device;
  * @bus_info:	Unique and stable device location identifier
  * @hw_revision: Hardware device revision
  * @driver_version: Device driver version
+ * @topology_version: Monotonic counter for storing the version of the graph
+ *		topology. Should be incremented each time the topology changes.
  * @entity_id:	Unique ID used on the last entity registered
  * @pad_id:	Unique ID used on the last pad registered
  * @link_id:	Unique ID used on the last link registered
@@ -74,6 +76,8 @@ struct media_device {
 	u32 hw_revision;
 	u32 driver_version;
 
+	u32 topology_version;
+
 	u32 entity_id;
 	u32 pad_id;
 	u32 link_id;
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (50 preceding siblings ...)
  (?)
@ 2015-08-30  3:07 ` Mauro Carvalho Chehab
  2015-08-31 12:47   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:07 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
with the RFC for the MC next generation.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 5b2c9f7fcd45..a91e1ec076a6 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -232,6 +232,136 @@ static long media_device_setup_link(struct media_device *mdev,
 	return ret;
 }
 
+static long __media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology *topo)
+{
+	struct media_entity *entity;
+	struct media_interface *intf;
+	struct media_pad *pad;
+	struct media_link *link;
+	struct media_v2_entity uentity;
+	struct media_v2_interface uintf;
+	struct media_v2_pad upad;
+	struct media_v2_link ulink;
+	int ret = 0, i;
+
+	topo->topology_version = mdev->topology_version;
+
+	/* Get entities and number of entities */
+	i = 0;
+	media_device_for_each_entity(entity, mdev) {
+		i++;
+
+		if (ret || !topo->entities)
+			continue;
+
+		/* Copy fields to userspace struct if not error */
+		memset(&uentity, 0, sizeof(uentity));
+		uentity.id = entity->graph_obj.id;
+		strncpy(uentity.name, entity->name,
+			sizeof(uentity.name));
+
+		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
+			ret = -EFAULT;
+	}
+	topo->num_entities = i;
+
+	/* Get interfaces and number of interfaces */
+	i = 0;
+	media_device_for_each_intf(intf, mdev) {
+		i++;
+
+		if (ret || !topo->interfaces)
+			continue;
+
+		memset(&uintf, 0, sizeof(uintf));
+
+		/* Copy intf fields to userspace struct */
+		uintf.id = intf->graph_obj.id;
+		uintf.intf_type = intf->type;
+		uintf.flags = intf->flags;
+
+		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
+			struct media_intf_devnode *devnode;
+
+			devnode = intf_to_devnode(intf);
+
+			uintf.devnode.major = devnode->major;
+			uintf.devnode.minor = devnode->minor;
+		}
+
+		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
+			ret = -EFAULT;
+	}
+	topo->num_interfaces = i;
+
+	/* Get pads and number of pads */
+	i = 0;
+	media_device_for_each_pad(pad, mdev) {
+		i++;
+
+		if (ret || !topo->pads)
+			continue;
+
+		memset(&upad, 0, sizeof(upad));
+
+		/* Copy pad fields to userspace struct */
+		upad.id = pad->graph_obj.id;
+		upad.entity_id = pad->entity->graph_obj.id;
+		upad.flags = pad->flags;
+
+		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
+			ret = -EFAULT;
+	}
+	topo->num_pads = i;
+
+	/* Get links and number of links */
+	i = 0;
+	media_device_for_each_link(link, mdev) {
+		i++;
+
+		if (ret || !topo->links)
+			continue;
+
+		memset(&ulink, 0, sizeof(ulink));
+
+		/* Copy link fields to userspace struct */
+		ulink.id = link->graph_obj.id;
+		ulink.source_id = link->gobj0->id;
+		ulink.sink_id = link->gobj1->id;
+		ulink.flags = link->flags;
+
+		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
+			ulink.flags |= MEDIA_NEW_LNK_FL_INTERFACE_LINK;
+
+		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
+			ret = -EFAULT;
+	}
+	topo->num_links = i;
+
+	return ret;
+}
+
+static long media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology __user *utopo)
+{
+	struct media_v2_topology ktopo;
+	int ret;
+
+	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
+
+	if (ret < 0)
+		return ret;
+
+	ret = __media_device_get_topology(mdev, &ktopo);
+	if (ret < 0)
+		return ret;
+
+	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));
+
+	return ret;
+}
+
 static long media_device_ioctl(struct file *filp, unsigned int cmd,
 			       unsigned long arg)
 {
@@ -264,6 +394,13 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
 		mutex_unlock(&dev->graph_mutex);
 		break;
 
+	case MEDIA_IOC_G_TOPOLOGY:
+		mutex_lock(&dev->graph_mutex);
+		ret = media_device_get_topology(dev,
+				(struct media_v2_topology __user *)arg);
+		mutex_unlock(&dev->graph_mutex);
+		break;
+
 	default:
 		ret = -ENOIOCTLCMD;
 	}
@@ -312,6 +449,7 @@ static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
 	case MEDIA_IOC_DEVICE_INFO:
 	case MEDIA_IOC_ENUM_ENTITIES:
 	case MEDIA_IOC_SETUP_LINK:
+	case MEDIA_IOC_G_TOPOLOGY:
 		return media_device_ioctl(filp, cmd, arg);
 
 	case MEDIA_IOC_ENUM_LINKS32:
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 50/55] [media] media-entity: unregister entity links
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (51 preceding siblings ...)
  (?)
@ 2015-08-30  3:07 ` Mauro Carvalho Chehab
  2015-08-31 12:48   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:07 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Add functions to explicitly unregister all entity links.
This function is called automatically when an entity
link is destroyed.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index c18f4af52771..96303a0ade59 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -903,6 +903,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
+	media_remove_intf_links(&devnode->intf);
 	media_gobj_remove(&devnode->intf.graph_obj);
 	kfree(devnode);
 }
@@ -944,3 +945,25 @@ void media_remove_intf_link(struct media_link *link)
 	mutex_unlock(&link->graph_obj.mdev->graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_remove_intf_link);
+
+void __media_remove_intf_links(struct media_interface *intf)
+{
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &intf->links, list)
+		__media_remove_intf_link(link);
+
+}
+EXPORT_SYMBOL_GPL(__media_remove_intf_links);
+
+void media_remove_intf_links(struct media_interface *intf)
+{
+	/* Do nothing if the intf is not registered. */
+	if (intf->graph_obj.mdev == NULL)
+		return;
+
+	mutex_lock(&intf->graph_obj.mdev->graph_mutex);
+	__media_remove_intf_links(intf);
+	mutex_unlock(&intf->graph_obj.mdev->graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_remove_intf_links);
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 8c344a07636c..0e7e193a6736 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -318,6 +318,9 @@ struct media_link *media_create_intf_link(struct media_entity *entity,
 					    struct media_interface *intf,
 					    u32 flags);
 void media_remove_intf_link(struct media_link *link);
+void __media_remove_intf_links(struct media_interface *intf);
+void media_remove_intf_links(struct media_interface *intf);
+
 
 #define media_entity_call(entity, operation, args...)			\
 	(((entity)->ops && (entity)->ops->operation) ?			\
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 51/55] [media] remove interface links at media_entity_unregister()
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (52 preceding siblings ...)
  (?)
@ 2015-08-30  3:07 ` Mauro Carvalho Chehab
  2015-08-31 12:53   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:07 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Interface links connected to an entity should be removed
before being able of removing the entity.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index a91e1ec076a6..638c682b79c4 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -618,14 +618,30 @@ void media_device_unregister_entity(struct media_entity *entity)
 		return;
 
 	spin_lock(&mdev->lock);
+
+	/* Remove interface links with this entity on it */
+	list_for_each_entry_safe(link, tmp, &mdev->links, graph_obj.list) {
+		if (media_type(link->gobj1) == MEDIA_GRAPH_ENTITY
+		    && link->entity == entity) {
+			media_gobj_remove(&link->graph_obj);
+			kfree(link);
+		}
+	}
+
+	/* Remove all data links that belong to this entity */
 	list_for_each_entry_safe(link, tmp, &entity->links, list) {
 		media_gobj_remove(&link->graph_obj);
 		list_del(&link->list);
 		kfree(link);
 	}
+
+	/* Remove all pads that belong to this entity */
 	for (i = 0; i < entity->num_pads; i++)
 		media_gobj_remove(&entity->pads[i].graph_obj);
+
+	/* Remove the entity */
 	media_gobj_remove(&entity->graph_obj);
+
 	spin_unlock(&mdev->lock);
 	entity->graph_obj.mdev = NULL;
 }
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 52/55] [media] media-device: remove interfaces and interface links
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (53 preceding siblings ...)
  (?)
@ 2015-08-30  3:07 ` Mauro Carvalho Chehab
  2015-08-31 12:57   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:07 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Just like what's done with entities, when the media controller is
unregistered, release and interface and interface links that
might still be there.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 638c682b79c4..2c16a46ea530 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -554,6 +554,22 @@ void media_device_unregister(struct media_device *mdev)
 {
 	struct media_entity *entity;
 	struct media_entity *next;
+	struct media_link *link, *tmp_link;
+	struct media_interface *intf, *tmp_intf;
+
+	/* Remove interface links from the media device */
+	list_for_each_entry_safe(link, tmp_link, &mdev->links,
+				 graph_obj.list) {
+		media_gobj_remove(&link->graph_obj);
+		kfree(link);
+	}
+
+	/* Remove all interfaces from the media device */
+	list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces,
+				 graph_obj.list) {
+		media_gobj_remove(&intf->graph_obj);
+		kfree(intf);
+	}
 
 	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
 		media_device_unregister_entity(entity);
@@ -631,7 +647,6 @@ void media_device_unregister_entity(struct media_entity *entity)
 	/* Remove all data links that belong to this entity */
 	list_for_each_entry_safe(link, tmp, &entity->links, list) {
 		media_gobj_remove(&link->graph_obj);
-		list_del(&link->list);
 		kfree(link);
 	}
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 96303a0ade59..1cdda9cb0512 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -206,6 +206,10 @@ void media_gobj_remove(struct media_gobj *gobj)
 
 	/* Remove the object from mdev list */
 	list_del(&gobj->list);
+
+	/* Links have their own list - we need to drop them there too */
+	if (media_type(gobj) == MEDIA_GRAPH_LINK)
+		list_del(&gobj_to_link(gobj)->list);
 }
 
 /**
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 0e7e193a6736..7fd6265f0bcb 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -153,7 +153,7 @@ struct media_entity {
 };
 
 /**
- * struct media_intf_devnode - Define a Kernel API interface
+ * struct media_interface - Define a Kernel API interface
  *
  * @graph_obj:		embedded graph object
  * @list:		Linked list used to find other interfaces that belong
@@ -163,6 +163,11 @@ struct media_entity {
  *			uapi/media/media.h header, e. g.
  *			MEDIA_INTF_T_*
  * @flags:		Interface flags as defined at uapi/media/media.h
+ *
+ * NOTE: As media_device_unregister() will free the address of the
+ *	 media_interface, this structure should be embedded as the first
+ *	 element of the derivated functions, in order for the address to be
+ *	 the same.
  */
 struct media_interface {
 	struct media_gobj		graph_obj;
@@ -179,11 +184,11 @@ struct media_interface {
  * @minor:	Minor number of a device node
  */
 struct media_intf_devnode {
-	struct media_interface		intf;
+	struct media_interface	intf; /* must be first field in struct */
 
 	/* Should match the fields at media_v2_intf_devnode */
-	u32				major;
-	u32				minor;
+	u32			major;
+	u32			minor;
 };
 
 static inline u32 media_entity_id(struct media_entity *entity)
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (54 preceding siblings ...)
  (?)
@ 2015-08-30  3:07 ` Mauro Carvalho Chehab
  2015-08-31 13:23   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  -1 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:07 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Hans Verkuil, Sakari Ailus

V4L2 device (and subdevice) nodes should create an
interface, if the Media Controller support is enabled.

Please notice that radio devices should not create an
entity, as radio input/output is either via wires or
via ALSA.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 44b330589787..427a5a32b3de 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -194,9 +194,12 @@ static void v4l2_device_release(struct device *cd)
 	mutex_unlock(&videodev_lock);
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
-	if (v4l2_dev->mdev &&
-	    vdev->vfl_type != VFL_TYPE_SUBDEV)
-		media_device_unregister_entity(&vdev->entity);
+	if (v4l2_dev->mdev) {
+		/* Remove interfaces and interface links */
+		media_devnode_remove(vdev->intf_devnode);
+		if (vdev->vfl_type != VFL_TYPE_SUBDEV)
+			media_device_unregister_entity(&vdev->entity);
+	}
 #endif
 
 	/* Do not call v4l2_device_put if there is no release callback set.
@@ -713,6 +716,85 @@ static void determine_valid_ioctls(struct video_device *vdev)
 			BASE_VIDIOC_PRIVATE);
 }
 
+
+static int video_register_media_controller(struct video_device *vdev, int type)
+{
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	u32 entity_type = MEDIA_ENT_T_UNKNOWN;
+	u32 intf_type;
+	int ret;
+	bool create_entity = true;
+
+	if (!vdev->v4l2_dev->mdev)
+		return 0;
+
+	switch (type) {
+	case VFL_TYPE_GRABBER:
+		intf_type = MEDIA_INTF_T_V4L_VIDEO;
+		entity_type = MEDIA_ENT_T_V4L2_VIDEO;
+		break;
+	case VFL_TYPE_VBI:
+		intf_type = MEDIA_INTF_T_V4L_VBI;
+		entity_type = MEDIA_ENT_T_V4L2_VBI;
+		break;
+	case VFL_TYPE_SDR:
+		intf_type = MEDIA_INTF_T_V4L_SWRADIO;
+		entity_type = MEDIA_ENT_T_V4L2_SWRADIO;
+		break;
+	case VFL_TYPE_RADIO:
+		intf_type = MEDIA_INTF_T_V4L_RADIO;
+		/*
+		 * Radio doesn't have an entity at the V4L2 side to represent
+		 * radio input or output. Instead, the audio input/output goes
+		 * via either physical wires or ALSA.
+		 */
+		create_entity = false;
+		break;
+	case VFL_TYPE_SUBDEV:
+		intf_type = MEDIA_INTF_T_V4L_SUBDEV;
+		/* Entity will be created via v4l2_device_register_subdev() */
+		create_entity = false;
+		break;
+	default:
+		return 0;
+	}
+
+	if (create_entity) {
+		vdev->entity.type = entity_type;
+		vdev->entity.name = vdev->name;
+
+		/* Needed just for backward compatibility with legacy MC API */
+		vdev->entity.info.dev.major = VIDEO_MAJOR;
+		vdev->entity.info.dev.minor = vdev->minor;
+
+		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
+						   &vdev->entity);
+		if (ret < 0) {
+			printk(KERN_WARNING
+				"%s: media_device_register_entity failed\n",
+				__func__);
+			return ret;
+		}
+	}
+
+	vdev->intf_devnode = media_devnode_create(vdev->v4l2_dev->mdev,
+						  intf_type,
+						  0, VIDEO_MAJOR,
+						  vdev->minor,
+						  GFP_KERNEL);
+	if (!vdev->intf_devnode)
+		return -ENOMEM;
+
+	if (create_entity)
+		media_create_intf_link(&vdev->entity,
+				       &vdev->intf_devnode->intf, 0);
+
+	/* FIXME: how to create the other interface links? */
+
+#endif
+	return 0;
+}
+
 /**
  *	__video_register_device - register video4linux devices
  *	@vdev: video device structure we want to register
@@ -908,22 +990,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
 	/* Increase v4l2_device refcount */
 	v4l2_device_get(vdev->v4l2_dev);
 
-#if defined(CONFIG_MEDIA_CONTROLLER)
 	/* Part 5: Register the entity. */
-	if (vdev->v4l2_dev->mdev &&
-	    vdev->vfl_type != VFL_TYPE_SUBDEV) {
-		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
-		vdev->entity.name = vdev->name;
-		vdev->entity.info.dev.major = VIDEO_MAJOR;
-		vdev->entity.info.dev.minor = vdev->minor;
-		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
-			&vdev->entity);
-		if (ret < 0)
-			printk(KERN_WARNING
-			       "%s: media_device_register_entity failed\n",
-			       __func__);
-	}
-#endif
+	ret = video_register_media_controller(vdev, type);
+
 	/* Part 6: Activate this minor. The char device can now be used. */
 	set_bit(V4L2_FL_REGISTERED, &vdev->flags);
 
diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
index 5b0a30b9252b..17ec73b1796e 100644
--- a/drivers/media/v4l2-core/v4l2-device.c
+++ b/drivers/media/v4l2-core/v4l2-device.c
@@ -249,6 +249,11 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
 #if defined(CONFIG_MEDIA_CONTROLLER)
 		sd->entity.info.dev.major = VIDEO_MAJOR;
 		sd->entity.info.dev.minor = vdev->minor;
+
+		/* Interface is created by __video_register_device() */
+		if (vdev->v4l2_dev->mdev)
+			media_create_intf_link(&sd->entity,
+					       &vdev->intf_devnode->intf, 0);
 #endif
 		sd->devnode = vdev;
 	}
@@ -285,7 +290,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	if (v4l2_dev->mdev) {
-		media_entity_remove_links(&sd->entity);
+		/*
+		 * No need to explicitly remove links, as both pads and
+		 * links are removed by the function below, at the right order
+		 */
 		media_device_unregister_entity(&sd->entity);
 	}
 #endif
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index acbcd2f5fe7f..eeabf20e87a6 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -86,6 +86,7 @@ struct video_device
 {
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	struct media_entity entity;
+	struct media_intf_devnode *intf_devnode;
 #endif
 	/* device ops */
 	const struct v4l2_file_operations *fops;
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 54/55] [media] au0828: unregister MC at the end
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (55 preceding siblings ...)
  (?)
@ 2015-08-30  3:07 ` Mauro Carvalho Chehab
  2015-08-31 13:25   ` Hans Verkuil
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:07 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab,
	Rafael Lourenço de Lima Chehab, Hans Verkuil, Shuah Khan

au0828_analog_unregister() calls video_unregister_device(),
with, in turn, calls media_devnode_remove() in order to drop
the media interfaces.

We can't release the media controller before that, or an
OOPS will occur:

[  176.938752] usb 1-4.4: Media device released
[  176.938753] usb 1-4.4: Media device unregistered
[  177.091235] general protection fault: 0000 [#1] SMP
[  177.091253] Modules linked in: ir_lirc_codec ir_xmp_decoder lirc_dev ir_mce_kbd_decoder ir_sharp_decoder ir_sanyo_decoder ir_sony_decoder ir_jvc_decoder ir_rc6_decoder ir_nec_decoder ir_rc5_decoder au8522_dig xc5000 tuner au8522_decoder au8522_common au0828(-) videobuf2_vmalloc videobuf2_memops tveeprom videobuf2_core dvb_core rc_core v4l2_common videodev media cpufreq_powersave cpufreq_conservative cpufreq_userspace cpufreq_stats parport_pc ppdev lp parport snd_hda_codec_hdmi i915 x86_pkg_temp_thermal intel_powerclamp intel_rapl iosf_mbi coretemp kvm_intel kvm btusb crct10dif_pclmul snd_hda_codec_realtek crc32_pclmul btrtl crc32c_intel btbcm snd_hda_codec_generic ghash_clmulni_intel btintel i2c_algo_bit drm_kms_helper bluetooth iTCO_wdt snd_usb_audio snd_hda_intel iTCO_vendor_support jitterentropy_rng
[  177.091455]  snd_hda_codec evdev sha256_ssse3 drm sha256_generic hmac snd_usbmidi_lib snd_hwdep snd_hda_core snd_rawmidi drbg snd_seq_device snd_pcm aesni_intel aes_x86_64 lrw gf128mul mei_me glue_helper snd_timer ablk_helper cryptd mei rfkill snd psmouse sg shpchp soundcore lpc_ich serio_raw i2c_i801 pcspkr mfd_core tpm_tis tpm battery dw_dmac video i2c_designware_platform dw_dmac_core i2c_designware_core acpi_pad processor button ext4 crc16 mbcache jbd2 dm_mod sd_mod ahci libahci libata e1000e scsi_mod ptp pps_core ehci_pci xhci_pci ehci_hcd xhci_hcd thermal fan thermal_sys sdhci_acpi sdhci mmc_core i2c_hid hid [last unloaded: rc_core]
[  177.091632] CPU: 1 PID: 18040 Comm: rmmod Tainted: G        W       4.2.0-rc2+ #9
[  177.091648] Hardware name: \xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff \xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff/NUC5i7RYB, BIOS RYBDWi35.86A.0246.2015.0309.1355 03/09/2015
[  177.091677] task: ffff88040811b080 ti: ffff880036b88000 task.ti: ffff880036b88000
[  177.091693] RIP: 0010:[<ffffffff810aecc3>]  [<ffffffff810aecc3>] native_queued_spin_lock_slowpath+0x103/0x180
[  177.091718] RSP: 0018:ffff880036b8bcd8  EFLAGS: 00010202
[  177.091730] RAX: 0000000000003ffe RBX: ffff880407e11b70 RCX: ffff88041ec962c0
[  177.091745] RDX: 7463656a62506357 RSI: 0000000000080000 RDI: ffff880407e11b74
[  177.091760] RBP: ffff880407e11b74 R08: 0000000000000001 R09: ffffffff812bf4e0
[  177.091776] R10: 0000000000000000 R11: 0000000000000000 R12: ffff88040811b080
[  177.091791] R13: ffff88003601cec8 R14: ffff8804084b8890 R15: ffff8804084b8800
[  177.091807] FS:  00007f2f9bab1700(0000) GS:ffff88041ec80000(0000) knlGS:0000000000000000
[  177.091824] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  177.091837] CR2: 00007fe8c0f900e0 CR3: 0000000035c47000 CR4: 00000000003407e0
[  177.091852] Stack:
[  177.091857]  ffffffff81562e3d ffffffff815613b3 0000000000000000 0000000000000000
[  177.091876]  ffff88040b6d3240 ffff8804084b8890 ffff880407e11b70 ffff88003601cd30
[  177.091895]  ffff88003601ce28 ffff88003601cec8 ffff8804084b8890 ffffffff8156148b
[  177.091914] Call Trace:
[  177.091923]  [<ffffffff81562e3d>] ? _raw_spin_lock+0x1d/0x20
[  177.091936]  [<ffffffff815613b3>] ? __mutex_lock_slowpath+0x43/0x100
[  177.091951]  [<ffffffff8156148b>] ? mutex_lock+0x1b/0x30
[  177.091965]  [<ffffffffa028480d>] ? media_remove_intf_links+0x1d/0x40 [media]
[  177.091981]  [<ffffffffa028483e>] ? media_devnode_remove+0xe/0x20 [media]
[  177.091997]  [<ffffffffa063d875>] ? v4l2_device_release+0x95/0x100 [videodev]
[  177.092014]  [<ffffffff813ca19d>] ? device_release+0x2d/0x90
[  177.092028]  [<ffffffff812be5e9>] ? kobject_release+0x79/0x1b0
[  177.092042]  [<ffffffffa07b19ea>] ? au0828_analog_unregister+0x2a/0x60 [au0828]
[  177.092059]  [<ffffffffa07ac10e>] ? au0828_usb_disconnect+0x9e/0xd0 [au0828]
[  177.092075]  [<ffffffff8140e609>] ? usb_unbind_interface+0x79/0x270
[  177.092090]  [<ffffffff813cf285>] ? __device_release_driver+0x95/0x130
[  177.092105]  [<ffffffff813cf41b>] ? driver_detach+0xab/0xb0
[  177.092120]  [<ffffffff813ce4c5>] ? bus_remove_driver+0x55/0xd0
[  177.092134]  [<ffffffff8140d951>] ? usb_deregister+0x71/0xc0
[  177.092148]  [<ffffffff810e438a>] ? SyS_delete_module+0x1aa/0x250
[  177.092163]  [<ffffffff81088ee9>] ? task_work_run+0x89/0xc0
[  177.092176]  [<ffffffff815631f2>] ? entry_SYSCALL_64_fastpath+0x16/0x75
[  177.092191] Code: 87 47 02 c1 e0 10 85 c0 74 38 48 89 c2 c1 e8 12 48 c1 ea 0c 83 e8 01 83 e2 30 48 98 48 81 c2 c0 62 01 00 48 03 14 c5 c0 62 90 81 <48> 89 0a 8b 41 08 85 c0 75 0d f3 90 8b 41 08 85 c0 74 f7 eb 02
[  177.092281] RIP  [<ffffffff810aecc3>] native_queued_spin_lock_slowpath+0x103/0x180
[  177.092299]  RSP <ffff880036b8bcd8>
[  177.097721] ---[ end trace b12d5a66f4c6f1c1 ]---
[  177.243899] lirc_dev: module unloaded

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 7f645bcb7463..e28cabe65934 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -175,8 +175,6 @@ static void au0828_usb_disconnect(struct usb_interface *interface)
 	*/
 	dev->dev_state = DEV_DISCONNECTED;
 
-	au0828_unregister_media_device(dev);
-
 	au0828_rc_unregister(dev);
 	/* Digital TV */
 	au0828_dvb_unregister(dev);
@@ -193,6 +191,8 @@ static void au0828_usb_disconnect(struct usb_interface *interface)
 		return;
 	}
 #endif
+	au0828_unregister_media_device(dev);
+
 	au0828_usb_release(dev);
 }
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8 55/55] [media] media-entity.h: document all the structs
  2015-08-30  3:06 ` Mauro Carvalho Chehab
                   ` (56 preceding siblings ...)
  (?)
@ 2015-08-30  3:07 ` Mauro Carvalho Chehab
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30  3:07 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Only a few structs are documented on kernel-doc-nano format
(the ones added by the MC next gen patches).

Add a documentation for all structs, and ensure that they'll
be producing the documentation at the Kernel's device driver
DocBook.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 7fd6265f0bcb..c42d191fa5a8 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -55,11 +55,13 @@ enum media_gobj_type {
 /**
  * struct media_gobj - Define a graph object.
  *
+ * @mdev:	Pointer to the struct media_device that owns the object
  * @id:		Non-zero object ID identifier. The ID should be unique
  *		inside a media_device, as it is composed by
  *		MEDIA_BITS_PER_TYPE to store the type plus
  *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
  *		(called as "local ID").
+ * @list:	Linked list associated to one of the per-type mdev object lists
  *
  * All objects on the media graph should have this struct embedded
  */
@@ -73,6 +75,28 @@ struct media_gobj {
 struct media_pipeline {
 };
 
+/**
+ * struct media_link - Define a media link graph object.
+ *
+ * @graph_obj:	Embedded structure containing the media object common data
+ * @list:	Linked list associated with an entity or an interface that
+ *		owns the link.
+ * @gobj0:	Part of an union. Used to get the pointer for the first
+ *		graph_object of the link.
+ * @source:	Part of an union. Used only if the first object (gobj0) is
+ *		a pad. On such case, it represents the source pad.
+ * @intf:	Part of an union. Used only if the first object (gobj0) is
+ *		an interface.
+ * @gobj1:	Part of an union. Used to get the pointer for the second
+ *		graph_object of the link.
+ * @source:	Part of an union. Used only if the second object (gobj0) is
+ *		a pad. On such case, it represents the sink pad.
+ * @entity:	Part of an union. Used only if the second object (gobj0) is
+ *		an entity.
+ * @reverse:	Pointer to the link for the reverse direction of a pad to pad
+ *		link.
+ * @flags:	Link flags, as defined at uapi/media.h (MEDIA_LNK_FL_*)
+ */
 struct media_link {
 	struct media_gobj graph_obj;
 	struct list_head list;
@@ -86,15 +110,23 @@ struct media_link {
 		struct media_pad *sink;
 		struct media_entity *entity;
 	};
-	struct media_link *reverse;	/* Link in the reverse direction */
-	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
+	struct media_link *reverse;
+	unsigned long flags;
 };
 
+/**
+ * struct media_pad - Define a media pad graph object.
+ *
+ * @graph_obj:	Embedded structure containing the media object common data
+ * @entity:	Entity where this object belongs
+ * @index:	Pad index in the entity pads array, numbered from 0 to n
+ * @flags:	Pad flags, as defined at uapi/media.h (MEDIA_PAD_FL_*)
+ */
 struct media_pad {
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	struct media_entity *entity;	/* Entity this pad belongs to */
-	u16 index;			/* Pad index in the entity pads array */
-	unsigned long flags;		/* Pad flags (MEDIA_PAD_FL_*) */
+	struct media_entity *entity;
+	u16 index;
+	unsigned long flags;
 };
 
 /**
@@ -113,51 +145,73 @@ struct media_entity_operations {
 	int (*link_validate)(struct media_link *link);
 };
 
+/**
+ * struct media_entity - Define a media entity graph object.
+ *
+ * @graph_obj:	Embedded structure containing the media object common data.
+ * @name:	Entity name.
+ * @type:	Entity type, as defined at uapi/media.h (MEDIA_ENT_T_*)
+ * @revision:	Entity revision - OBSOLETE - should be removed soon.
+ * @flags:	Entity flags, as defined at uapi/media.h (MEDIA_ENT_FL_*)
+ * @group_id:	Entity group ID - OBSOLETE - should be removed soon.
+ * @num_pads:	Number of sink and source pads.
+ * @num_links:	Number of existing links, both enabled and disabled.
+ * @num_backlinks: Number of backlinks
+ * @pads:	Pads array with the size defined by @num_pads.
+ * @links:	Linked list for the data links.
+ * @ops:	Entity operations.
+ * @stream_count: Stream count for the entity.
+ * @use_count:	Use count for the entity.
+ * @pipe:	Pipeline this entity belongs to.
+ * @info:	Union with devnode information.  Kept just for backward
+ * 		compatibility.
+ * @major:	Devnode major number (zero if not applicable). Kept just
+ * 		for backward compatibility.
+ * @minor:	Devnode minor number (zero if not applicable). Kept just
+ * 		for backward compatibility.
+ *
+ * NOTE: @stream_count and @use_count reference counts must never be
+ * negative, but are signed integers on purpose: a simple WARN_ON(<0) check
+ * can be used to detect reference count bugs that would make them negative.
+ */
 struct media_entity {
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	const char *name;		/* Entity name */
-	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
-	u32 revision;			/* Entity revision, driver specific */
-	unsigned long flags;		/* Entity flags (MEDIA_ENT_FL_*) */
-	u32 group_id;			/* Entity group ID */
+	const char *name;
+	u32 type;
+	u32 revision;
+	unsigned long flags;
+	u32 group_id;
 
-	u16 num_pads;			/* Number of sink and source pads */
-	u16 num_links;			/* Number of existing links, both
-					 * enabled and disabled */
-	u16 num_backlinks;		/* Number of backlinks */
+	u16 num_pads;
+	u16 num_links;
+	u16 num_backlinks;
 
-	struct media_pad *pads;		/* Pads array (num_pads objects) */
-	struct list_head links;		/* Pad-to-pad links list */
+	struct media_pad *pads;
+	struct list_head links;
 
-	const struct media_entity_operations *ops;	/* Entity operations */
+	const struct media_entity_operations *ops;
 
 	/* Reference counts must never be negative, but are signed integers on
 	 * purpose: a simple WARN_ON(<0) check can be used to detect reference
 	 * count bugs that would make them negative.
 	 */
-	int stream_count;		/* Stream count for the entity. */
-	int use_count;			/* Use count for the entity. */
+	int stream_count;
+	int use_count;
 
-	struct media_pipeline *pipe;	/* Pipeline this entity belongs to. */
+	struct media_pipeline *pipe;
 
 	union {
-		/* Node specifications */
 		struct {
 			u32 major;
 			u32 minor;
 		} dev;
-
-		/* Sub-device specifications */
-		/* Nothing needed yet */
 	} info;
 };
 
 /**
- * struct media_interface - Define a Kernel API interface
+ * struct media_interface - Define a media interface graph object
  *
  * @graph_obj:		embedded graph object
- * @list:		Linked list used to find other interfaces that belong
- *			to the same media controller
  * @links:		List of links pointing to graph entities
  * @type:		Type of the interface as defined at the
  *			uapi/media/media.h header, e. g.
@@ -177,7 +231,7 @@ struct media_interface {
 };
 
 /**
- * struct media_intf_devnode - Define a Kernel API interface via a device node
+ * struct media_intf_devnode - Define a media interface via a device node
  *
  * @intf:	embedded interface object
  * @major:	Major number of a device node
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 00/55] MC next generation patches
  2015-08-30  3:06 ` Mauro Carvalho Chehab
  (?)
  (?)
@ 2015-08-30 14:27   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30 14:27 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: devel, Lars-Peter Clausen, Sylwester Nawrocki, linux-sh,
	Greg Kroah-Hartman, Shuah Khan, Mauro Carvalho Chehab,
	Hans Verkuil, Javier Martinez Canillas, linux-samsung-soc,
	Laurent Pinchart, Sakari Ailus, linux-api, linux-arm-kernel

Em Sun, 30 Aug 2015 00:06:11 -0300
Mauro Carvalho Chehab <mchehab@osg.samsung.com> escreveu:

> That's the 8th version of the MC next generation patches.
> 
> Differences from version 7:
> 
> - Patches reworked to make the reviewers happy;
> - Bug fixes;
> - ALSA changes got their own separate patches;
> - Javier patches got integrated into this series;
> - media-entity.h structs are now properly documented;
> - Tested on both au0828 and omap3isp.
> 
> Due to the complexity of this change, other platform drivers may
> require some fixes. 
> 
> As the patch series sent before, this is not meant to be sent
> upstream yet. Its goal is to merge it for Kernel 4.4, in order to
> give people enough time to review and fix pending issues.

As on the previous series, the patches are available on my experimental
tree:
	http://git.linuxtv.org/cgit.cgi/mchehab/experimental.git/log/?h=mc_next_gen

There's one additional patch there that removes the backlinks from G_TOPOLOGY
ioctl. I'll be posting it in separate at the ML.

I also added a new branch:
	http://git.linuxtv.org/cgit.cgi/mchehab/experimental.git/log/?h=mc_next_gen_test

Based on the first one. It contains a hack for au0828 that exposes the tuner
also via subdev devnode, and reduces the number of output pads of the DVB
demux to just 5, as the default is too high to produce a .dot file that
would be useful. Of course, this patch should never leave my experimental
tree ;) 

There are a few other from Javier there meant to allow testing the omap3isp
on my Beaglebone (that doesn't have any sensor on it) and on his omap3
devices.

I added support at the mc_nextgen_test tool to produce Graphviz .dot
files. It is still experimental, but it is good enough to already produce
some useful graphs. The newest version is at:

	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/log/?h=mc-next-gen

I added some graphs produced by it at:
	https://mchehab.fedorapeople.org/mc-next-gen/

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 00/55] MC next generation patches
@ 2015-08-30 14:27   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30 14:27 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, devel, Greg Kroah-Hartman, Hans Verkuil,
	Javier Martinez Canillas, Lars-Peter Clausen, Laurent Pinchart,
	linux-api, linux-arm-kernel, linux-samsung-soc, linux-sh,
	Sakari Ailus, Shuah Khan, Sylwester Nawrocki

Em Sun, 30 Aug 2015 00:06:11 -0300
Mauro Carvalho Chehab <mchehab@osg.samsung.com> escreveu:

> That's the 8th version of the MC next generation patches.
> 
> Differences from version 7:
> 
> - Patches reworked to make the reviewers happy;
> - Bug fixes;
> - ALSA changes got their own separate patches;
> - Javier patches got integrated into this series;
> - media-entity.h structs are now properly documented;
> - Tested on both au0828 and omap3isp.
> 
> Due to the complexity of this change, other platform drivers may
> require some fixes. 
> 
> As the patch series sent before, this is not meant to be sent
> upstream yet. Its goal is to merge it for Kernel 4.4, in order to
> give people enough time to review and fix pending issues.

As on the previous series, the patches are available on my experimental
tree:
	http://git.linuxtv.org/cgit.cgi/mchehab/experimental.git/log/?h=mc_next_gen

There's one additional patch there that removes the backlinks from G_TOPOLOGY
ioctl. I'll be posting it in separate at the ML.

I also added a new branch:
	http://git.linuxtv.org/cgit.cgi/mchehab/experimental.git/log/?h=mc_next_gen_test

Based on the first one. It contains a hack for au0828 that exposes the tuner
also via subdev devnode, and reduces the number of output pads of the DVB
demux to just 5, as the default is too high to produce a .dot file that
would be useful. Of course, this patch should never leave my experimental
tree ;) 

There are a few other from Javier there meant to allow testing the omap3isp
on my Beaglebone (that doesn't have any sensor on it) and on his omap3
devices.

I added support at the mc_nextgen_test tool to produce Graphviz .dot
files. It is still experimental, but it is good enough to already produce
some useful graphs. The newest version is at:

	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/log/?h=mc-next-gen

I added some graphs produced by it at:
	https://mchehab.fedorapeople.org/mc-next-gen/

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 00/55] MC next generation patches
@ 2015-08-30 14:27   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30 14:27 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: devel, Lars-Peter Clausen, Sylwester Nawrocki, linux-sh,
	Greg Kroah-Hartman, Shuah Khan, Mauro Carvalho Chehab,
	Hans Verkuil, Javier Martinez Canillas, linux-samsung-soc,
	Laurent Pinchart, Sakari Ailus, linux-api, linux-arm-kernel

Em Sun, 30 Aug 2015 00:06:11 -0300
Mauro Carvalho Chehab <mchehab@osg.samsung.com> escreveu:

> That's the 8th version of the MC next generation patches.
> 
> Differences from version 7:
> 
> - Patches reworked to make the reviewers happy;
> - Bug fixes;
> - ALSA changes got their own separate patches;
> - Javier patches got integrated into this series;
> - media-entity.h structs are now properly documented;
> - Tested on both au0828 and omap3isp.
> 
> Due to the complexity of this change, other platform drivers may
> require some fixes. 
> 
> As the patch series sent before, this is not meant to be sent
> upstream yet. Its goal is to merge it for Kernel 4.4, in order to
> give people enough time to review and fix pending issues.

As on the previous series, the patches are available on my experimental
tree:
	http://git.linuxtv.org/cgit.cgi/mchehab/experimental.git/log/?h=mc_next_gen

There's one additional patch there that removes the backlinks from G_TOPOLOGY
ioctl. I'll be posting it in separate at the ML.

I also added a new branch:
	http://git.linuxtv.org/cgit.cgi/mchehab/experimental.git/log/?h=mc_next_gen_test

Based on the first one. It contains a hack for au0828 that exposes the tuner
also via subdev devnode, and reduces the number of output pads of the DVB
demux to just 5, as the default is too high to produce a .dot file that
would be useful. Of course, this patch should never leave my experimental
tree ;) 

There are a few other from Javier there meant to allow testing the omap3isp
on my Beaglebone (that doesn't have any sensor on it) and on his omap3
devices.

I added support at the mc_nextgen_test tool to produce Graphviz .dot
files. It is still experimental, but it is good enough to already produce
some useful graphs. The newest version is at:

	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/log/?h=mc-next-gen

I added some graphs produced by it at:
	https://mchehab.fedorapeople.org/mc-next-gen/

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH v8 00/55] MC next generation patches
@ 2015-08-30 14:27   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-30 14:27 UTC (permalink / raw)
  To: linux-arm-kernel

Em Sun, 30 Aug 2015 00:06:11 -0300
Mauro Carvalho Chehab <mchehab@osg.samsung.com> escreveu:

> That's the 8th version of the MC next generation patches.
> 
> Differences from version 7:
> 
> - Patches reworked to make the reviewers happy;
> - Bug fixes;
> - ALSA changes got their own separate patches;
> - Javier patches got integrated into this series;
> - media-entity.h structs are now properly documented;
> - Tested on both au0828 and omap3isp.
> 
> Due to the complexity of this change, other platform drivers may
> require some fixes. 
> 
> As the patch series sent before, this is not meant to be sent
> upstream yet. Its goal is to merge it for Kernel 4.4, in order to
> give people enough time to review and fix pending issues.

As on the previous series, the patches are available on my experimental
tree:
	http://git.linuxtv.org/cgit.cgi/mchehab/experimental.git/log/?h=mc_next_gen

There's one additional patch there that removes the backlinks from G_TOPOLOGY
ioctl. I'll be posting it in separate at the ML.

I also added a new branch:
	http://git.linuxtv.org/cgit.cgi/mchehab/experimental.git/log/?h=mc_next_gen_test

Based on the first one. It contains a hack for au0828 that exposes the tuner
also via subdev devnode, and reduces the number of output pads of the DVB
demux to just 5, as the default is too high to produce a .dot file that
would be useful. Of course, this patch should never leave my experimental
tree ;) 

There are a few other from Javier there meant to allow testing the omap3isp
on my Beaglebone (that doesn't have any sensor on it) and on his omap3
devices.

I added support at the mc_nextgen_test tool to produce Graphviz .dot
files. It is still experimental, but it is good enough to already produce
some useful graphs. The newest version is at:

	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/log/?h=mc-next-gen

I added some graphs produced by it at:
	https://mchehab.fedorapeople.org/mc-next-gen/

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 03/55] [media] omap3isp: get entity ID using media_entity_id()
  2015-08-30  3:06 ` [PATCH v8 03/55] [media] omap3isp: " Mauro Carvalho Chehab
@ 2015-08-31 10:10   ` Hans Verkuil
  2015-12-06  3:16   ` Laurent Pinchart
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 10:10 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Javier Martinez Canillas, Mauro Carvalho Chehab, Laurent Pinchart

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> From: Javier Martinez Canillas <javier@osg.samsung.com>
> 
> Assessing media_entity ID should now use media_entity_id() macro to
> obtain the entity ID, as a next patch will remove the .id field from
> struct media_entity .
> 
> So, get rid of it, otherwise the omap3isp driver will fail to build.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Regards,

	Hans

> 
> diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> index 56e683b19a73..e08183f9d0f7 100644
> --- a/drivers/media/platform/omap3isp/isp.c
> +++ b/drivers/media/platform/omap3isp/isp.c
> @@ -975,6 +975,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
>  	struct v4l2_subdev *subdev;
>  	int failure = 0;
>  	int ret;
> +	u32 id;
>  
>  	/*
>  	 * We need to stop all the modules after CCDC first or they'll
> @@ -1027,8 +1028,10 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
>  		if (ret) {
>  			dev_info(isp->dev, "Unable to stop %s\n", subdev->name);
>  			isp->stop_failure = true;
> -			if (subdev == &isp->isp_prev.subdev)
> -				isp->crashed |= 1U << subdev->entity.id;
> +			if (subdev == &isp->isp_prev.subdev) {
> +				id = media_entity_id(&subdev->entity);
> +				isp->crashed |= 1U << id;
> +			}
>  			failure = -ETIMEDOUT;
>  		}
>  	}
> diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c
> index 3b10304b580b..d96e3be5e252 100644
> --- a/drivers/media/platform/omap3isp/ispccdc.c
> +++ b/drivers/media/platform/omap3isp/ispccdc.c
> @@ -1608,7 +1608,7 @@ static int ccdc_isr_buffer(struct isp_ccdc_device *ccdc)
>  	/* Wait for the CCDC to become idle. */
>  	if (ccdc_sbl_wait_idle(ccdc, 1000)) {
>  		dev_info(isp->dev, "CCDC won't become idle!\n");
> -		isp->crashed |= 1U << ccdc->subdev.entity.id;
> +		isp->crashed |= 1U << media_entity_id(&ccdc->subdev.entity);
>  		omap3isp_pipeline_cancel_stream(pipe);
>  		return 0;
>  	}
> diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> index 3094572f8897..6c89dc40df85 100644
> --- a/drivers/media/platform/omap3isp/ispvideo.c
> +++ b/drivers/media/platform/omap3isp/ispvideo.c
> @@ -235,7 +235,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  		struct isp_video *__video;
>  
> -		pipe->entities |= 1 << entity->id;
> +		pipe->entities |= 1 << media_entity_id(entity);
>  
>  		if (far_end != NULL)
>  			continue;
> @@ -891,6 +891,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
>  	struct v4l2_ext_control ctrl;
>  	unsigned int i;
>  	int ret;
> +	u32 id;
>  
>  	/* Memory-to-memory pipelines have no external subdev. */
>  	if (pipe->input != NULL)
> @@ -898,7 +899,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
>  
>  	for (i = 0; i < ARRAY_SIZE(ents); i++) {
>  		/* Is the entity part of the pipeline? */
> -		if (!(pipe->entities & (1 << ents[i]->id)))
> +		if (!(pipe->entities & (1 << media_entity_id(ents[i]))))
>  			continue;
>  
>  		/* ISP entities have always sink pad == 0. Find source. */
> @@ -950,7 +951,8 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
>  
>  	pipe->external_rate = ctrl.value64;
>  
> -	if (pipe->entities & (1 << isp->isp_ccdc.subdev.entity.id)) {
> +	id = media_entity_id(&isp->isp_ccdc.subdev.entity);
> +	if (pipe->entities & (1 << id)) {
>  		unsigned int rate = UINT_MAX;
>  		/*
>  		 * Check that maximum allowed CCDC pixel rate isn't
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 14/55] [media] media: add functions to allow creating interfaces
  2015-08-30  3:06 ` [PATCH v8 14/55] [media] media: add functions to allow creating interfaces Mauro Carvalho Chehab
@ 2015-08-31 10:20   ` Hans Verkuil
  2015-08-31 10:49     ` Mauro Carvalho Chehab
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 10:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Interfaces are different than entities: they represent a
> Kernel<->userspace interaction, while entities represent a
> piece of hardware/firmware/software that executes a function.
> 
> Let's distinguish them by creating a separate structure to
> store the interfaces.
> 
> Latter patches should change the existing drivers and logic

s/Latter/Later/

FYI: you almost never use 'latter' in English texts. The only common use
of 'latter' is in the phrase "the latter of two options" where 'latter' means
'second'.

> to split the current interface embedded inside the entity
> structure (device nodes) into a separate object of the graph.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index a23c93369a04..583666e2cc25 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -44,11 +44,41 @@ static inline const char *gobj_type(enum media_gobj_type type)
>  		return "pad";
>  	case MEDIA_GRAPH_LINK:
>  		return "link";
> +	case MEDIA_GRAPH_INTF_DEVNODE:
> +		return "intf_devnode";

You use '-' below for 'v4l-subdev' and 'unknown-intf', so I think this too should
use '-'. My opinion though.

It's a nitpick, so I give my Ack anyway:

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Regards,

	Hans

>  	default:
>  		return "unknown";
>  	}
>  }
>  
> +static inline const char *intf_type(struct media_interface *intf)
> +{
> +	switch (intf->type) {
> +	case MEDIA_INTF_T_DVB_FE:
> +		return "frontend";
> +	case MEDIA_INTF_T_DVB_DEMUX:
> +		return "demux";
> +	case MEDIA_INTF_T_DVB_DVR:
> +		return "DVR";
> +	case MEDIA_INTF_T_DVB_CA:
> +		return  "CA";
> +	case MEDIA_INTF_T_DVB_NET:
> +		return "dvbnet";
> +	case MEDIA_INTF_T_V4L_VIDEO:
> +		return "video";
> +	case MEDIA_INTF_T_V4L_VBI:
> +		return "vbi";
> +	case MEDIA_INTF_T_V4L_RADIO:
> +		return "radio";
> +	case MEDIA_INTF_T_V4L_SUBDEV:
> +		return "v4l2-subdev";
> +	case MEDIA_INTF_T_V4L_SWRADIO:
> +		return "swradio";
> +	default:
> +		return "unknown-intf";
> +	}
> +};
> +
>  static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
>  {
>  #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
> @@ -84,6 +114,19 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
>  			"%s: id 0x%08x pad#%d: '%s':%d\n",
>  			event_name, gobj->id, media_localid(gobj),
>  			pad->entity->name, pad->index);
> +		break;
> +	}
> +	case MEDIA_GRAPH_INTF_DEVNODE:
> +	{
> +		struct media_interface *intf = gobj_to_intf(gobj);
> +		struct media_intf_devnode *devnode = intf_to_devnode(intf);
> +
> +		dev_dbg(gobj->mdev->dev,
> +			"%s: id 0x%08x intf_devnode#%d: %s - major: %d, minor: %d\n",
> +			event_name, gobj->id, media_localid(gobj),
> +			intf_type(intf),
> +			devnode->major, devnode->minor);
> +		break;
>  	}
>  	}
>  #endif
> @@ -119,6 +162,9 @@ void media_gobj_init(struct media_device *mdev,
>  	case MEDIA_GRAPH_LINK:
>  		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
>  		break;
> +	case MEDIA_GRAPH_INTF_DEVNODE:
> +		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
> +		break;
>  	}
>  	dev_dbg_obj(__func__, gobj);
>  }
> @@ -793,3 +839,40 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
>  
>  }
>  EXPORT_SYMBOL_GPL(media_entity_remote_pad);
> +
> +
> +/* Functions related to the media interface via device nodes */
> +
> +struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
> +						u32 type, u32 flags,
> +						u32 major, u32 minor,
> +						gfp_t gfp_flags)
> +{
> +	struct media_intf_devnode *devnode;
> +	struct media_interface *intf;
> +
> +	devnode = kzalloc(sizeof(*devnode), gfp_flags);
> +	if (!devnode)
> +		return NULL;
> +
> +	intf = &devnode->intf;
> +
> +	intf->type = type;
> +	intf->flags = flags;
> +
> +	devnode->major = major;
> +	devnode->minor = minor;
> +
> +	media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
> +		       &devnode->intf.graph_obj);
> +
> +	return devnode;
> +}
> +EXPORT_SYMBOL_GPL(media_devnode_create);
> +
> +void media_devnode_remove(struct media_intf_devnode *devnode)
> +{
> +	media_gobj_remove(&devnode->intf.graph_obj);
> +	kfree(devnode);
> +}
> +EXPORT_SYMBOL_GPL(media_devnode_remove);
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index 05414e351f8e..3b14394d5701 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -44,6 +44,7 @@ struct device;
>   * @entity_id:	Unique ID used on the last entity registered
>   * @pad_id:	Unique ID used on the last pad registered
>   * @link_id:	Unique ID used on the last link registered
> + * @intf_devnode_id: Unique ID used on the last interface devnode registered
>   * @entities:	List of registered entities
>   * @lock:	Entities list lock
>   * @graph_mutex: Entities graph operation lock
> @@ -73,6 +74,7 @@ struct media_device {
>  	u32 entity_id;
>  	u32 pad_id;
>  	u32 link_id;
> +	u32 intf_devnode_id;
>  
>  	struct list_head entities;
>  
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 239c4ec30ef6..7df8836f4eef 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -36,11 +36,14 @@
>   * @MEDIA_GRAPH_ENTITY:		Identify a media entity
>   * @MEDIA_GRAPH_PAD:		Identify a media pad
>   * @MEDIA_GRAPH_LINK:		Identify a media link
> + * @MEDIA_GRAPH_INTF_DEVNODE:	Identify a media Kernel API interface via
> + *				a device node
>   */
>  enum media_gobj_type {
>  	MEDIA_GRAPH_ENTITY,
>  	MEDIA_GRAPH_PAD,
>  	MEDIA_GRAPH_LINK,
> +	MEDIA_GRAPH_INTF_DEVNODE,
>  };
>  
>  #define MEDIA_BITS_PER_TYPE		8
> @@ -141,6 +144,34 @@ struct media_entity {
>  	} info;
>  };
>  
> +/**
> + * struct media_intf_devnode - Define a Kernel API interface
> + *
> + * @graph_obj:		embedded graph object
> + * @type:		Type of the interface as defined at the
> + *			uapi/media/media.h header, e. g.
> + *			MEDIA_INTF_T_*
> + * @flags:		Interface flags as defined at uapi/media/media.h
> + */
> +struct media_interface {
> +	struct media_gobj		graph_obj;
> +	u32				type;
> +	u32				flags;
> +};
> +
> +/**
> + * struct media_intf_devnode - Define a Kernel API interface via a device node
> + *
> + * @intf:	embedded interface object
> + * @major:	Major number of a device node
> + * @minor:	Minor number of a device node
> + */
> +struct media_intf_devnode {
> +	struct media_interface		intf;
> +	u32				major;
> +	u32				minor;
> +};
> +
>  static inline u32 media_entity_type(struct media_entity *entity)
>  {
>  	return entity->type & MEDIA_ENT_TYPE_MASK;
> @@ -198,6 +229,18 @@ struct media_entity_graph {
>  #define gobj_to_link(gobj) \
>  		container_of(gobj, struct media_link, graph_obj)
>  
> +#define gobj_to_link(gobj) \
> +		container_of(gobj, struct media_link, graph_obj)
> +
> +#define gobj_to_pad(gobj) \
> +		container_of(gobj, struct media_pad, graph_obj)
> +
> +#define gobj_to_intf(gobj) \
> +		container_of(gobj, struct media_interface, graph_obj)
> +
> +#define intf_to_devnode(intf) \
> +		container_of(intf, struct media_intf_devnode, intf)
> +
>  void media_gobj_init(struct media_device *mdev,
>  		    enum media_gobj_type type,
>  		    struct media_gobj *gobj);
> @@ -229,6 +272,11 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
>  					     struct media_pipeline *pipe);
>  void media_entity_pipeline_stop(struct media_entity *entity);
>  
> +struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
> +						u32 type, u32 flags,
> +						u32 major, u32 minor,
> +						gfp_t gfp_flags);
> +void media_devnode_remove(struct media_intf_devnode *devnode);
>  #define media_entity_call(entity, operation, args...)			\
>  	(((entity)->ops && (entity)->ops->operation) ?			\
>  	 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 16/55] [media] media: Don't accept early-created links
  2015-08-30  3:06 ` [PATCH v8 16/55] [media] media: Don't accept early-created links Mauro Carvalho Chehab
@ 2015-08-31 10:30   ` Hans Verkuil
  2015-08-31 10:54     ` Mauro Carvalho Chehab
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 10:30 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Links are graph objects that represent the links of two already
> existing objects in the graph.
> 
> While with the current implementation, it is possible to create
> the links earlier, It doesn't make any sense to allow linking
> two objects when they are not both created.
> 
> So, remove the code that would be handling those early-created
> links and add a BUG_ON() to ensure that.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

The code is OK, so:

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

But shouldn't this go *after* the omap3isp fixes? After this patch the
omap3isp will call BUG_ON, and that's not what you want.

It is also not clear if the omap3isp driver is the only one that has this
'create link before objects' problem. I would expect that the omap4 staging
driver has the same issue and possibly others as well.

Did someone look at that?

Regards,

	Hans

> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 138b18416460..0d85c6c28004 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -443,13 +443,6 @@ int __must_check media_device_register_entity(struct media_device *mdev,
>  	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
>  	list_add_tail(&entity->list, &mdev->entities);
>  
> -	/*
> -	 * Initialize objects at the links
> -	 * in the case where links got created before entity register
> -	 */
> -	for (i = 0; i < entity->num_links; i++)
> -		media_gobj_init(mdev, MEDIA_GRAPH_LINK,
> -				&entity->links[i].graph_obj);
>  	/* Initialize objects at the pads */
>  	for (i = 0; i < entity->num_pads; i++)
>  		media_gobj_init(mdev, MEDIA_GRAPH_PAD,
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 01946baa32d5..9f8e0145db7a 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -161,6 +161,8 @@ void media_gobj_init(struct media_device *mdev,
>  			   enum media_gobj_type type,
>  			   struct media_gobj *gobj)
>  {
> +	BUG_ON(!mdev);
> +
>  	gobj->mdev = mdev;
>  
>  	/* Create a per-type unique object ID */
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 20/55] [media] media: make add link more generic
  2015-08-30  3:06 ` [PATCH v8 20/55] [media] media: make add link more generic Mauro Carvalho Chehab
@ 2015-08-31 10:44   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 10:44 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> The media_entity_add_link() function takes an entity
> as an argument just to get the list head.
> 
> Make it more generic by changing the function argument
> to list_head.
> 
> No functional changes.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index ff63201443d7..6d06be6c9ef3 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -580,7 +580,7 @@ EXPORT_SYMBOL_GPL(media_entity_put);
>   * Links management
>   */
>  
> -static struct media_link *media_entity_add_link(struct media_entity *entity)
> +static struct media_link *media_add_link(struct list_head *head)
>  {
>  	struct media_link *link;
>  
> @@ -588,7 +588,7 @@ static struct media_link *media_entity_add_link(struct media_entity *entity)
>  	if (link == NULL)
>  		return NULL;
>  
> -	list_add_tail(&link->list, &entity->links);
> +	list_add_tail(&link->list, head);
>  
>  	return link;
>  }
> @@ -607,7 +607,7 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
>  	BUG_ON(source_pad >= source->num_pads);
>  	BUG_ON(sink_pad >= sink->num_pads);
>  
> -	link = media_entity_add_link(source);
> +	link = media_add_link(&source->links);
>  	if (link == NULL)
>  		return -ENOMEM;
>  
> @@ -622,7 +622,7 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
>  	/* Create the backlink. Backlinks are used to help graph traversal and
>  	 * are not reported to userspace.
>  	 */
> -	backlink = media_entity_add_link(sink);
> +	backlink = media_add_link(&sink->links);
>  	if (backlink == NULL) {
>  		__media_entity_remove_link(source, link);
>  		return -ENOMEM;
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 21/55] [media] media: make media_link more generic to handle interace links
  2015-08-30  3:06 ` [PATCH v8 21/55] [media] media: make media_link more generic to handle interace links Mauro Carvalho Chehab
@ 2015-08-31 10:44   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 10:44 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> By adding an union at media_link, we get for free a way to
> represent interface->entity links.
> 
> No need to change anything at the code, just at the internal
> header file.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index bb89cedb0c40..b4923a24efd5 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -75,14 +75,20 @@ struct media_pipeline {
>  struct media_link {
>  	struct media_gobj graph_obj;
>  	struct list_head list;
> -	struct media_pad *source;	/* Source pad */
> -	struct media_pad *sink;		/* Sink pad  */
> +	union {
> +		struct media_gobj *gobj0;
> +		struct media_pad *source;
> +	};
> +	union {
> +		struct media_gobj *gobj1;
> +		struct media_pad *sink;
> +	};
>  	struct media_link *reverse;	/* Link in the reverse direction */
>  	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
>  };
>  
>  struct media_pad {
> -	struct media_gobj graph_obj;
> +	struct media_gobj graph_obj;	/* must be first field in struct */
>  	struct media_entity *entity;	/* Entity this pad belongs to */
>  	u16 index;			/* Pad index in the entity pads array */
>  	unsigned long flags;		/* Pad flags (MEDIA_PAD_FL_*) */
> @@ -105,7 +111,7 @@ struct media_entity_operations {
>  };
>  
>  struct media_entity {
> -	struct media_gobj graph_obj;
> +	struct media_gobj graph_obj;	/* must be first field in struct */
>  	struct list_head list;
>  	const char *name;		/* Entity name */
>  	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
> @@ -119,7 +125,7 @@ struct media_entity {
>  	u16 num_backlinks;		/* Number of backlinks */
>  
>  	struct media_pad *pads;		/* Pads array (num_pads objects) */
> -	struct list_head links;		/* Links list */
> +	struct list_head links;		/* Pad-to-pad links list */
>  
>  	const struct media_entity_operations *ops;	/* Entity operations */
>  
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 23/55] [media] media: add support to link interfaces and entities
  2015-08-30  3:06 ` [PATCH v8 23/55] [media] media: add support to link interfaces and entities Mauro Carvalho Chehab
@ 2015-08-31 10:48   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 10:48 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Now that we have a new graph object called "interfaces", we
> need to be able to link them to the entities.
> 
> Add a linked list to the interfaces to allow them to be
> linked to the entities.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 973d1be427c5..08239128fbc4 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -869,6 +869,7 @@ struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
>  
>  	intf->type = type;
>  	intf->flags = flags;
> +	INIT_LIST_HEAD(&intf->links);
>  
>  	devnode->major = major;
>  	devnode->minor = minor;
> @@ -886,3 +887,40 @@ void media_devnode_remove(struct media_intf_devnode *devnode)
>  	kfree(devnode);
>  }
>  EXPORT_SYMBOL_GPL(media_devnode_remove);
> +
> +struct media_link *media_create_intf_link(struct media_entity *entity,
> +					    struct media_interface *intf,
> +					    u32 flags)
> +{
> +	struct media_link *link;
> +
> +	link = media_add_link(&intf->links);
> +	if (link == NULL)
> +		return NULL;
> +
> +	link->intf = intf;
> +	link->entity = entity;
> +	link->flags = flags;
> +
> +	/* Initialize graph object embedded at the new link */
> +	media_gobj_init(intf->graph_obj.mdev, MEDIA_GRAPH_LINK,
> +			&link->graph_obj);
> +
> +	return link;
> +}
> +EXPORT_SYMBOL_GPL(media_create_intf_link);
> +
> +
> +static void __media_remove_intf_link(struct media_link *link)
> +{
> +	media_gobj_remove(&link->graph_obj);
> +	kfree(link);
> +}
> +
> +void media_remove_intf_link(struct media_link *link)
> +{
> +	mutex_lock(&link->graph_obj.mdev->graph_mutex);
> +	__media_remove_intf_link(link);
> +	mutex_unlock(&link->graph_obj.mdev->graph_mutex);

link was just freed, so you can't dereference link anymore.

Instead use a temp 'mdev' pointer to access the mutex.

Regards,

	Hans

> +}
> +EXPORT_SYMBOL_GPL(media_remove_intf_link);
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index b4923a24efd5..423ff804e686 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -78,10 +78,12 @@ struct media_link {
>  	union {
>  		struct media_gobj *gobj0;
>  		struct media_pad *source;
> +		struct media_interface *intf;
>  	};
>  	union {
>  		struct media_gobj *gobj1;
>  		struct media_pad *sink;
> +		struct media_entity *entity;
>  	};
>  	struct media_link *reverse;	/* Link in the reverse direction */
>  	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
> @@ -154,6 +156,7 @@ struct media_entity {
>   * struct media_intf_devnode - Define a Kernel API interface
>   *
>   * @graph_obj:		embedded graph object
> + * @links:		List of links pointing to graph entities
>   * @type:		Type of the interface as defined at the
>   *			uapi/media/media.h header, e. g.
>   *			MEDIA_INTF_T_*
> @@ -161,6 +164,7 @@ struct media_entity {
>   */
>  struct media_interface {
>  	struct media_gobj		graph_obj;
> +	struct list_head		links;
>  	u32				type;
>  	u32				flags;
>  };
> @@ -283,6 +287,11 @@ struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
>  						u32 major, u32 minor,
>  						gfp_t gfp_flags);
>  void media_devnode_remove(struct media_intf_devnode *devnode);
> +struct media_link *media_create_intf_link(struct media_entity *entity,
> +					    struct media_interface *intf,
> +					    u32 flags);
> +void media_remove_intf_link(struct media_link *link);
> +
>  #define media_entity_call(entity, operation, args...)			\
>  	(((entity)->ops && (entity)->ops->operation) ?			\
>  	 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 14/55] [media] media: add functions to allow creating interfaces
  2015-08-31 10:20   ` Hans Verkuil
@ 2015-08-31 10:49     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-31 10:49 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Em Mon, 31 Aug 2015 12:20:43 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> > Interfaces are different than entities: they represent a
> > Kernel<->userspace interaction, while entities represent a
> > piece of hardware/firmware/software that executes a function.
> > 
> > Let's distinguish them by creating a separate structure to
> > store the interfaces.
> > 
> > Latter patches should change the existing drivers and logic
> 
> s/Latter/Later/
> 
> FYI: you almost never use 'latter' in English texts. The only common use
> of 'latter' is in the phrase "the latter of two options" where 'latter' means
> 'second'.

I did a global replace on the patches, but perhaps the regex
expression I used didn't got this one.

> 
> > to split the current interface embedded inside the entity
> > structure (device nodes) into a separate object of the graph.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index a23c93369a04..583666e2cc25 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -44,11 +44,41 @@ static inline const char *gobj_type(enum media_gobj_type type)
> >  		return "pad";
> >  	case MEDIA_GRAPH_LINK:
> >  		return "link";
> > +	case MEDIA_GRAPH_INTF_DEVNODE:
> > +		return "intf_devnode";
> 
> You use '-' below for 'v4l-subdev' and 'unknown-intf', so I think this too should
> use '-'. My opinion though.

Gah, forgot this one ;)

> 
> It's a nitpick, so I give my Ack anyway:
> 
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Regards,
> 
> 	Hans
> 
> >  	default:
> >  		return "unknown";
> >  	}
> >  }
> >  
> > +static inline const char *intf_type(struct media_interface *intf)
> > +{
> > +	switch (intf->type) {
> > +	case MEDIA_INTF_T_DVB_FE:
> > +		return "frontend";
> > +	case MEDIA_INTF_T_DVB_DEMUX:
> > +		return "demux";
> > +	case MEDIA_INTF_T_DVB_DVR:
> > +		return "DVR";
> > +	case MEDIA_INTF_T_DVB_CA:
> > +		return  "CA";
> > +	case MEDIA_INTF_T_DVB_NET:
> > +		return "dvbnet";
> > +	case MEDIA_INTF_T_V4L_VIDEO:
> > +		return "video";
> > +	case MEDIA_INTF_T_V4L_VBI:
> > +		return "vbi";
> > +	case MEDIA_INTF_T_V4L_RADIO:
> > +		return "radio";
> > +	case MEDIA_INTF_T_V4L_SUBDEV:
> > +		return "v4l2-subdev";
> > +	case MEDIA_INTF_T_V4L_SWRADIO:
> > +		return "swradio";
> > +	default:
> > +		return "unknown-intf";
> > +	}
> > +};
> > +
> >  static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
> >  {
> >  #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
> > @@ -84,6 +114,19 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
> >  			"%s: id 0x%08x pad#%d: '%s':%d\n",
> >  			event_name, gobj->id, media_localid(gobj),
> >  			pad->entity->name, pad->index);
> > +		break;
> > +	}
> > +	case MEDIA_GRAPH_INTF_DEVNODE:
> > +	{
> > +		struct media_interface *intf = gobj_to_intf(gobj);
> > +		struct media_intf_devnode *devnode = intf_to_devnode(intf);
> > +
> > +		dev_dbg(gobj->mdev->dev,
> > +			"%s: id 0x%08x intf_devnode#%d: %s - major: %d, minor: %d\n",
> > +			event_name, gobj->id, media_localid(gobj),
> > +			intf_type(intf),
> > +			devnode->major, devnode->minor);
> > +		break;
> >  	}
> >  	}
> >  #endif
> > @@ -119,6 +162,9 @@ void media_gobj_init(struct media_device *mdev,
> >  	case MEDIA_GRAPH_LINK:
> >  		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
> >  		break;
> > +	case MEDIA_GRAPH_INTF_DEVNODE:
> > +		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
> > +		break;
> >  	}
> >  	dev_dbg_obj(__func__, gobj);
> >  }
> > @@ -793,3 +839,40 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
> >  
> >  }
> >  EXPORT_SYMBOL_GPL(media_entity_remote_pad);
> > +
> > +
> > +/* Functions related to the media interface via device nodes */
> > +
> > +struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
> > +						u32 type, u32 flags,
> > +						u32 major, u32 minor,
> > +						gfp_t gfp_flags)
> > +{
> > +	struct media_intf_devnode *devnode;
> > +	struct media_interface *intf;
> > +
> > +	devnode = kzalloc(sizeof(*devnode), gfp_flags);
> > +	if (!devnode)
> > +		return NULL;
> > +
> > +	intf = &devnode->intf;
> > +
> > +	intf->type = type;
> > +	intf->flags = flags;
> > +
> > +	devnode->major = major;
> > +	devnode->minor = minor;
> > +
> > +	media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
> > +		       &devnode->intf.graph_obj);
> > +
> > +	return devnode;
> > +}
> > +EXPORT_SYMBOL_GPL(media_devnode_create);
> > +
> > +void media_devnode_remove(struct media_intf_devnode *devnode)
> > +{
> > +	media_gobj_remove(&devnode->intf.graph_obj);
> > +	kfree(devnode);
> > +}
> > +EXPORT_SYMBOL_GPL(media_devnode_remove);
> > diff --git a/include/media/media-device.h b/include/media/media-device.h
> > index 05414e351f8e..3b14394d5701 100644
> > --- a/include/media/media-device.h
> > +++ b/include/media/media-device.h
> > @@ -44,6 +44,7 @@ struct device;
> >   * @entity_id:	Unique ID used on the last entity registered
> >   * @pad_id:	Unique ID used on the last pad registered
> >   * @link_id:	Unique ID used on the last link registered
> > + * @intf_devnode_id: Unique ID used on the last interface devnode registered
> >   * @entities:	List of registered entities
> >   * @lock:	Entities list lock
> >   * @graph_mutex: Entities graph operation lock
> > @@ -73,6 +74,7 @@ struct media_device {
> >  	u32 entity_id;
> >  	u32 pad_id;
> >  	u32 link_id;
> > +	u32 intf_devnode_id;
> >  
> >  	struct list_head entities;
> >  
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index 239c4ec30ef6..7df8836f4eef 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -36,11 +36,14 @@
> >   * @MEDIA_GRAPH_ENTITY:		Identify a media entity
> >   * @MEDIA_GRAPH_PAD:		Identify a media pad
> >   * @MEDIA_GRAPH_LINK:		Identify a media link
> > + * @MEDIA_GRAPH_INTF_DEVNODE:	Identify a media Kernel API interface via
> > + *				a device node
> >   */
> >  enum media_gobj_type {
> >  	MEDIA_GRAPH_ENTITY,
> >  	MEDIA_GRAPH_PAD,
> >  	MEDIA_GRAPH_LINK,
> > +	MEDIA_GRAPH_INTF_DEVNODE,
> >  };
> >  
> >  #define MEDIA_BITS_PER_TYPE		8
> > @@ -141,6 +144,34 @@ struct media_entity {
> >  	} info;
> >  };
> >  
> > +/**
> > + * struct media_intf_devnode - Define a Kernel API interface
> > + *
> > + * @graph_obj:		embedded graph object
> > + * @type:		Type of the interface as defined at the
> > + *			uapi/media/media.h header, e. g.
> > + *			MEDIA_INTF_T_*
> > + * @flags:		Interface flags as defined at uapi/media/media.h
> > + */
> > +struct media_interface {
> > +	struct media_gobj		graph_obj;
> > +	u32				type;
> > +	u32				flags;
> > +};
> > +
> > +/**
> > + * struct media_intf_devnode - Define a Kernel API interface via a device node
> > + *
> > + * @intf:	embedded interface object
> > + * @major:	Major number of a device node
> > + * @minor:	Minor number of a device node
> > + */
> > +struct media_intf_devnode {
> > +	struct media_interface		intf;
> > +	u32				major;
> > +	u32				minor;
> > +};
> > +
> >  static inline u32 media_entity_type(struct media_entity *entity)
> >  {
> >  	return entity->type & MEDIA_ENT_TYPE_MASK;
> > @@ -198,6 +229,18 @@ struct media_entity_graph {
> >  #define gobj_to_link(gobj) \
> >  		container_of(gobj, struct media_link, graph_obj)
> >  
> > +#define gobj_to_link(gobj) \
> > +		container_of(gobj, struct media_link, graph_obj)
> > +
> > +#define gobj_to_pad(gobj) \
> > +		container_of(gobj, struct media_pad, graph_obj)
> > +
> > +#define gobj_to_intf(gobj) \
> > +		container_of(gobj, struct media_interface, graph_obj)
> > +
> > +#define intf_to_devnode(intf) \
> > +		container_of(intf, struct media_intf_devnode, intf)
> > +
> >  void media_gobj_init(struct media_device *mdev,
> >  		    enum media_gobj_type type,
> >  		    struct media_gobj *gobj);
> > @@ -229,6 +272,11 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
> >  					     struct media_pipeline *pipe);
> >  void media_entity_pipeline_stop(struct media_entity *entity);
> >  
> > +struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
> > +						u32 type, u32 flags,
> > +						u32 major, u32 minor,
> > +						gfp_t gfp_flags);
> > +void media_devnode_remove(struct media_intf_devnode *devnode);
> >  #define media_entity_call(entity, operation, args...)			\
> >  	(((entity)->ops && (entity)->ops->operation) ?			\
> >  	 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
> > 
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 24/55] [media] media-entity: add a helper function to create interface
  2015-08-30  3:06 ` [PATCH v8 24/55] [media] media-entity: add a helper function to create interface Mauro Carvalho Chehab
@ 2015-08-31 10:49   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 10:49 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> As we'll be adding other interface types in the future, put the
> common interface create code on a separate function.
> 
> Suggested-by: Hans Verkuil <hans.verkuil@cisco.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 08239128fbc4..417673a32c21 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -851,6 +851,18 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
>  EXPORT_SYMBOL_GPL(media_entity_remote_pad);
>  
>  
> +static void media_interface_init(struct media_device *mdev,
> +				 struct media_interface *intf,
> +				 u32 gobj_type,
> +				 u32 intf_type, u32 flags)
> +{
> +	intf->type = intf_type;
> +	intf->flags = flags;
> +	INIT_LIST_HEAD(&intf->links);
> +
> +	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
> +}
> +
>  /* Functions related to the media interface via device nodes */
>  
>  struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
> @@ -859,23 +871,16 @@ struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
>  						gfp_t gfp_flags)
>  {
>  	struct media_intf_devnode *devnode;
> -	struct media_interface *intf;
>  
>  	devnode = kzalloc(sizeof(*devnode), gfp_flags);
>  	if (!devnode)
>  		return NULL;
>  
> -	intf = &devnode->intf;
> -
> -	intf->type = type;
> -	intf->flags = flags;
> -	INIT_LIST_HEAD(&intf->links);
> -
>  	devnode->major = major;
>  	devnode->minor = minor;
>  
> -	media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
> -		       &devnode->intf.graph_obj);
> +	media_interface_init(mdev, &devnode->intf, MEDIA_GRAPH_INTF_DEVNODE,
> +			     type, flags);
>  
>  	return devnode;
>  }
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 25/55] [media] dvbdev: add support for interfaces
  2015-08-30  3:06 ` [PATCH v8 25/55] [media] dvbdev: add support for interfaces Mauro Carvalho Chehab
@ 2015-08-31 10:51   ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 10:51 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Laurent Pinchart, Hans Verkuil,
	Sakari Ailus, Jonathan Corbet

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Now that the infrastruct for that is set, add support for
> interfaces.
> 
> Please notice that we're missing two links:
> 	DVB FE intf    -> tuner
> 	DVB demux intf -> dvr
> 
> Those should be added latter, after having the entire graph
> set. With the current infrastructure, those should be added
> at dvb_create_media_graph(), but it would also require some
> extra core changes, to allow the function to enumerate the
> interfaces.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
> index 65f59f2124b4..6bf61d42c017 100644
> --- a/drivers/media/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb-core/dvbdev.c
> @@ -180,14 +180,36 @@ skip:
>  	return -ENFILE;
>  }
>  
> -static void dvb_register_media_device(struct dvb_device *dvbdev,
> -				      int type, int minor)
> +static void dvb_create_media_entity(struct dvb_device *dvbdev,
> +				       int type, int minor)
>  {
>  #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
>  	int ret = 0, npads;
>  
> -	if (!dvbdev->adapter->mdev)
> +	switch (type) {
> +	case DVB_DEVICE_FRONTEND:
> +		npads = 2;
> +		break;
> +	case DVB_DEVICE_DEMUX:
> +		npads = 2;
> +		break;
> +	case DVB_DEVICE_CA:
> +		npads = 2;
> +		break;
> +	case DVB_DEVICE_NET:
> +		/*
> +		 * We should be creating entities for the MPE/ULE
> +		 * decapsulation hardware (or software implementation).
> +		 *
> +		 * However, the number of for the MPE/ULE decaps may not be
> +		 * fixed. As we don't have yet dynamic support for PADs at
> +		 * the Media Controller, let's not create the decap
> +		 * entities yet.
> +		 */
>  		return;
> +	default:
> +		return;
> +	}
>  
>  	dvbdev->entity = kzalloc(sizeof(*dvbdev->entity), GFP_KERNEL);
>  	if (!dvbdev->entity)
> @@ -197,19 +219,6 @@ static void dvb_register_media_device(struct dvb_device *dvbdev,
>  	dvbdev->entity->info.dev.minor = minor;
>  	dvbdev->entity->name = dvbdev->name;
>  
> -	switch (type) {
> -	case DVB_DEVICE_CA:
> -	case DVB_DEVICE_DEMUX:
> -	case DVB_DEVICE_FRONTEND:
> -		npads = 2;
> -		break;
> -	case DVB_DEVICE_NET:
> -		npads = 0;
> -		break;
> -	default:
> -		npads = 1;
> -	}
> -
>  	if (npads) {
>  		dvbdev->pads = kcalloc(npads, sizeof(*dvbdev->pads),
>  				       GFP_KERNEL);
> @@ -230,18 +239,11 @@ static void dvb_register_media_device(struct dvb_device *dvbdev,
>  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
>  		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
>  		break;
> -	case DVB_DEVICE_DVR:
> -		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_DVR;
> -		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
> -		break;
>  	case DVB_DEVICE_CA:
>  		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_CA;
>  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
>  		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
>  		break;
> -	case DVB_DEVICE_NET:
> -		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_NET;
> -		break;
>  	default:
>  		kfree(dvbdev->entity);
>  		dvbdev->entity = NULL;
> @@ -263,11 +265,63 @@ static void dvb_register_media_device(struct dvb_device *dvbdev,
>  		return;
>  	}
>  
> -	printk(KERN_DEBUG "%s: media device '%s' registered.\n",
> +	printk(KERN_DEBUG "%s: media entity '%s' registered.\n",
>  		__func__, dvbdev->entity->name);
>  #endif
>  }
>  
> +static void dvb_register_media_device(struct dvb_device *dvbdev,
> +				      int type, int minor)
> +{
> +#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
> +	u32 intf_type;
> +
> +	if (!dvbdev->adapter->mdev)
> +		return;
> +
> +	dvb_create_media_entity(dvbdev, type, minor);
> +
> +	switch (type) {
> +	case DVB_DEVICE_FRONTEND:
> +		intf_type = MEDIA_INTF_T_DVB_FE;
> +		break;
> +	case DVB_DEVICE_DEMUX:
> +		intf_type = MEDIA_INTF_T_DVB_DEMUX;
> +		break;
> +	case DVB_DEVICE_DVR:
> +		intf_type = MEDIA_INTF_T_DVB_DVR;
> +		break;
> +	case DVB_DEVICE_CA:
> +		intf_type = MEDIA_INTF_T_DVB_CA;
> +		break;
> +	case DVB_DEVICE_NET:
> +		intf_type = MEDIA_INTF_T_DVB_NET;
> +		break;
> +	default:
> +		return;
> +	}
> +
> +	dvbdev->intf_devnode = media_devnode_create(dvbdev->adapter->mdev,
> +						 intf_type, 0,
> +						 DVB_MAJOR, minor,
> +						 GFP_KERNEL);
> +
> +	/*
> +	 * Create the "obvious" link, e. g. the ones that represent
> +	 * a direct association between an interface and an entity.
> +	 * Other links should be created elsewhere, like:
> +	 *		DVB FE intf    -> tuner
> +	 *		DVB demux intf -> dvr
> +	 */
> +
> +	if (!dvbdev->entity || !dvbdev->intf_devnode)
> +		return;
> +
> +	media_create_intf_link(dvbdev->entity, &dvbdev->intf_devnode->intf, 0);
> +
> +#endif
> +}
> +
>  int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
>  			const struct dvb_device *template, void *priv, int type)
>  {
> diff --git a/drivers/media/dvb-core/dvbdev.h b/drivers/media/dvb-core/dvbdev.h
> index c61a4f03a66f..5f37b4dd1e69 100644
> --- a/drivers/media/dvb-core/dvbdev.h
> +++ b/drivers/media/dvb-core/dvbdev.h
> @@ -149,6 +149,7 @@ struct dvb_device {
>  
>  	/* Allocated and filled inside dvbdev.c */
>  	struct media_entity *entity;
> +	struct media_intf_devnode *intf_devnode;
>  	struct media_pad *pads;
>  #endif
>  
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 26/55] [media] media: add a linked list to track interfaces by mdev
  2015-08-30  3:06 ` [PATCH v8 26/55] [media] media: add a linked list to track interfaces by mdev Mauro Carvalho Chehab
@ 2015-08-31 10:52   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 10:52 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> The media device should list the interface objects, so add a linked list
> for those interfaces in struct media_device.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 3e649cacfc07..659507bce63f 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -381,6 +381,7 @@ int __must_check __media_device_register(struct media_device *mdev,
>  		return -EINVAL;
>  
>  	INIT_LIST_HEAD(&mdev->entities);
> +	INIT_LIST_HEAD(&mdev->interfaces);
>  	spin_lock_init(&mdev->lock);
>  	mutex_init(&mdev->graph_mutex);
>  
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 417673a32c21..15bc92d3a648 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -861,6 +861,8 @@ static void media_interface_init(struct media_device *mdev,
>  	INIT_LIST_HEAD(&intf->links);
>  
>  	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
> +
> +	list_add_tail(&intf->list, &mdev->interfaces);
>  }
>  
>  /* Functions related to the media interface via device nodes */
> @@ -889,6 +891,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
>  void media_devnode_remove(struct media_intf_devnode *devnode)
>  {
>  	media_gobj_remove(&devnode->intf.graph_obj);
> +	list_del(&devnode->intf.list);
>  	kfree(devnode);
>  }
>  EXPORT_SYMBOL_GPL(media_devnode_remove);
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index 3b14394d5701..51807efa505b 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -46,6 +46,7 @@ struct device;
>   * @link_id:	Unique ID used on the last link registered
>   * @intf_devnode_id: Unique ID used on the last interface devnode registered
>   * @entities:	List of registered entities
> + * @interfaces:	List of registered interfaces
>   * @lock:	Entities list lock
>   * @graph_mutex: Entities graph operation lock
>   * @link_notify: Link state change notification callback
> @@ -77,6 +78,7 @@ struct media_device {
>  	u32 intf_devnode_id;
>  
>  	struct list_head entities;
> +	struct list_head interfaces;
>  
>  	/* Protects the entities list */
>  	spinlock_t lock;
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 423ff804e686..e7b20bdc735d 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -156,6 +156,8 @@ struct media_entity {
>   * struct media_intf_devnode - Define a Kernel API interface
>   *
>   * @graph_obj:		embedded graph object
> + * @list:		Linked list used to find other interfaces that belong
> + *			to the same media controller
>   * @links:		List of links pointing to graph entities
>   * @type:		Type of the interface as defined at the
>   *			uapi/media/media.h header, e. g.
> @@ -164,6 +166,7 @@ struct media_entity {
>   */
>  struct media_interface {
>  	struct media_gobj		graph_obj;
> +	struct list_head		list;
>  	struct list_head		links;
>  	u32				type;
>  	u32				flags;
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 27/55] [media] dvbdev: add support for indirect interface links
  2015-08-30  3:06 ` [PATCH v8 27/55] [media] dvbdev: add support for indirect interface links Mauro Carvalho Chehab
@ 2015-08-31 10:54   ` Hans Verkuil
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 10:54 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Sakari Ailus, Laurent Pinchart, Hans Verkuil

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Some interfaces indirectly control multiple entities.
> Add support for those.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
> index 6bf61d42c017..14d32cdcdd47 100644
> --- a/drivers/media/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb-core/dvbdev.c
> @@ -441,6 +441,7 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
>  	struct media_device *mdev = adap->mdev;
>  	struct media_entity *entity, *tuner = NULL, *fe = NULL;
>  	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
> +	struct media_interface *intf;
>  
>  	if (!mdev)
>  		return;
> @@ -476,6 +477,18 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
>  
>  	if (demux && ca)
>  		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
> +
> +	/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca */
> +	list_for_each_entry(intf, &mdev->interfaces, list) {
> +		if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
> +			media_create_intf_link(ca, intf, 0);
> +		if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
> +			media_create_intf_link(tuner, intf, 0);
> +		if (intf->type == MEDIA_INTF_T_DVB_DVR && demux)
> +			media_create_intf_link(demux, intf, 0);
> +	}
> +
> +

Spurious newlines.

After removing you can add my:

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

>  }
>  EXPORT_SYMBOL_GPL(dvb_create_media_graph);
>  #endif
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 16/55] [media] media: Don't accept early-created links
  2015-08-31 10:30   ` Hans Verkuil
@ 2015-08-31 10:54     ` Mauro Carvalho Chehab
  2015-08-31 11:01       ` Hans Verkuil
  0 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-31 10:54 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	Javier Martinez Canillas

Em Mon, 31 Aug 2015 12:30:16 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> > Links are graph objects that represent the links of two already
> > existing objects in the graph.
> > 
> > While with the current implementation, it is possible to create
> > the links earlier, It doesn't make any sense to allow linking
> > two objects when they are not both created.
> > 
> > So, remove the code that would be handling those early-created
> > links and add a BUG_ON() to ensure that.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> The code is OK, so:
> 
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> But shouldn't this go *after* the omap3isp fixes? After this patch the
> omap3isp will call BUG_ON, and that's not what you want.

Yes. I'll change the order on my git tree.

> It is also not clear if the omap3isp driver is the only one that has this
> 'create link before objects' problem. I would expect that the omap4 staging
> driver has the same issue and possibly others as well.
> 
> Did someone look at that?

I guess other drivers are doing the same.

Javier's planning to review the other platform drivers in order to add the 
needed fixes there too, and to do more tests with some other platform
drivers that he has hardware for testing.

> 
> Regards,
> 
> 	Hans
> 
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index 138b18416460..0d85c6c28004 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -443,13 +443,6 @@ int __must_check media_device_register_entity(struct media_device *mdev,
> >  	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
> >  	list_add_tail(&entity->list, &mdev->entities);
> >  
> > -	/*
> > -	 * Initialize objects at the links
> > -	 * in the case where links got created before entity register
> > -	 */
> > -	for (i = 0; i < entity->num_links; i++)
> > -		media_gobj_init(mdev, MEDIA_GRAPH_LINK,
> > -				&entity->links[i].graph_obj);
> >  	/* Initialize objects at the pads */
> >  	for (i = 0; i < entity->num_pads; i++)
> >  		media_gobj_init(mdev, MEDIA_GRAPH_PAD,
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index 01946baa32d5..9f8e0145db7a 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -161,6 +161,8 @@ void media_gobj_init(struct media_device *mdev,
> >  			   enum media_gobj_type type,
> >  			   struct media_gobj *gobj)
> >  {
> > +	BUG_ON(!mdev);
> > +
> >  	gobj->mdev = mdev;
> >  
> >  	/* Create a per-type unique object ID */
> > 
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 16/55] [media] media: Don't accept early-created links
  2015-08-31 10:54     ` Mauro Carvalho Chehab
@ 2015-08-31 11:01       ` Hans Verkuil
  2015-08-31 14:39         ` Javier Martinez Canillas
  0 siblings, 1 reply; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:01 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	Javier Martinez Canillas

On 08/31/2015 12:54 PM, Mauro Carvalho Chehab wrote:
> Em Mon, 31 Aug 2015 12:30:16 +0200
> Hans Verkuil <hverkuil@xs4all.nl> escreveu:
> 
>> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
>>> Links are graph objects that represent the links of two already
>>> existing objects in the graph.
>>>
>>> While with the current implementation, it is possible to create
>>> the links earlier, It doesn't make any sense to allow linking
>>> two objects when they are not both created.
>>>
>>> So, remove the code that would be handling those early-created
>>> links and add a BUG_ON() to ensure that.
>>>
>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>>
>> The code is OK, so:
>>
>> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
>>
>> But shouldn't this go *after* the omap3isp fixes? After this patch the
>> omap3isp will call BUG_ON, and that's not what you want.
> 
> Yes. I'll change the order on my git tree.
> 
>> It is also not clear if the omap3isp driver is the only one that has this
>> 'create link before objects' problem. I would expect that the omap4 staging
>> driver has the same issue and possibly others as well.
>>
>> Did someone look at that?
> 
> I guess other drivers are doing the same.
> 
> Javier's planning to review the other platform drivers in order to add the 
> needed fixes there too, and to do more tests with some other platform
> drivers that he has hardware for testing.

OK, good. Just wanted to know that.

Perhaps it is a good idea to add a TODO list to the cover letter. This would
be one item on that list.

Regards,

	Hans

> 
>>
>> Regards,
>>
>> 	Hans
>>
>>>
>>> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
>>> index 138b18416460..0d85c6c28004 100644
>>> --- a/drivers/media/media-device.c
>>> +++ b/drivers/media/media-device.c
>>> @@ -443,13 +443,6 @@ int __must_check media_device_register_entity(struct media_device *mdev,
>>>  	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
>>>  	list_add_tail(&entity->list, &mdev->entities);
>>>  
>>> -	/*
>>> -	 * Initialize objects at the links
>>> -	 * in the case where links got created before entity register
>>> -	 */
>>> -	for (i = 0; i < entity->num_links; i++)
>>> -		media_gobj_init(mdev, MEDIA_GRAPH_LINK,
>>> -				&entity->links[i].graph_obj);
>>>  	/* Initialize objects at the pads */
>>>  	for (i = 0; i < entity->num_pads; i++)
>>>  		media_gobj_init(mdev, MEDIA_GRAPH_PAD,
>>> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
>>> index 01946baa32d5..9f8e0145db7a 100644
>>> --- a/drivers/media/media-entity.c
>>> +++ b/drivers/media/media-entity.c
>>> @@ -161,6 +161,8 @@ void media_gobj_init(struct media_device *mdev,
>>>  			   enum media_gobj_type type,
>>>  			   struct media_gobj *gobj)
>>>  {
>>> +	BUG_ON(!mdev);
>>> +
>>>  	gobj->mdev = mdev;
>>>  
>>>  	/* Create a per-type unique object ID */
>>>
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 28/55] [media] uapi/media.h: Fix entity namespace
  2015-08-30  3:06 ` [PATCH v8 28/55] [media] uapi/media.h: Fix entity namespace Mauro Carvalho Chehab
@ 2015-08-31 11:17   ` Hans Verkuil
  2015-08-31 12:12     ` Mauro Carvalho Chehab
  2015-09-06 12:02     ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:17 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Laurent Pinchart, Sakari Ailus,
	Hans Verkuil, linux-api

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Now that interfaces got created, we need to fix the entity
> namespace.
> 
> So, let's create a consistent new namespace and add backward
> compatibility macros to keep the old namespace preserved.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
> index 14d32cdcdd47..88013d1a2c39 100644
> --- a/drivers/media/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb-core/dvbdev.c
> @@ -230,17 +230,17 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
>  
>  	switch (type) {
>  	case DVB_DEVICE_FRONTEND:
> -		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_FE;
> +		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMOD;
>  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
>  		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
>  		break;
>  	case DVB_DEVICE_DEMUX:
> -		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_DEMUX;
> +		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMUX;
>  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
>  		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
>  		break;
>  	case DVB_DEVICE_CA:
> -		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_CA;
> +		dvbdev->entity->type = MEDIA_ENT_T_DVB_CA;
>  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
>  		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
>  		break;
> @@ -439,7 +439,7 @@ EXPORT_SYMBOL(dvb_unregister_device);
>  void dvb_create_media_graph(struct dvb_adapter *adap)
>  {
>  	struct media_device *mdev = adap->mdev;
> -	struct media_entity *entity, *tuner = NULL, *fe = NULL;
> +	struct media_entity *entity, *tuner = NULL, *demod = NULL;
>  	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
>  	struct media_interface *intf;
>  
> @@ -451,26 +451,26 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
>  		case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
>  			tuner = entity;
>  			break;
> -		case MEDIA_ENT_T_DEVNODE_DVB_FE:
> -			fe = entity;
> +		case MEDIA_ENT_T_DVB_DEMOD:
> +			demod = entity;
>  			break;
> -		case MEDIA_ENT_T_DEVNODE_DVB_DEMUX:
> +		case MEDIA_ENT_T_DVB_DEMUX:
>  			demux = entity;
>  			break;
> -		case MEDIA_ENT_T_DEVNODE_DVB_DVR:
> +		case MEDIA_ENT_T_DVB_TSOUT:
>  			dvr = entity;
>  			break;
> -		case MEDIA_ENT_T_DEVNODE_DVB_CA:
> +		case MEDIA_ENT_T_DVB_CA:
>  			ca = entity;
>  			break;
>  		}
>  	}
>  
> -	if (tuner && fe)
> -		media_create_pad_link(tuner, 0, fe, 0, 0);
> +	if (tuner && demod)
> +		media_create_pad_link(tuner, 0, demod, 0, 0);
>  
> -	if (fe && demux)
> -		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
> +	if (demod && demux)
> +		media_create_pad_link(demod, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
>  
>  	if (demux && dvr)
>  		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index aca828709bad..3bbda409353f 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -42,31 +42,71 @@ struct media_device_info {
>  
>  #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
>  
> +/*
> + * Base numbers for entity types
> + *
> + * Please notice that the huge gap of 16 bits for each base is overkill!
> + * 8 bits is more than enough to avoid starving entity types for each
> + * subsystem.
> + *
> + * However, It is kept this way just to avoid binary breakages with the
> + * namespace provided on legacy versions of this header.
> + */
> +#define MEDIA_ENT_T_DVB_BASE		0x00000001

I would change this to 0x00000000, see follow-up comment later for why.

> +#define MEDIA_ENT_T_V4L2_BASE		0x00010000
> +#define MEDIA_ENT_T_V4L2_SUBDEV_BASE	0x00020000
> +
> +/*
> + * V4L2 entities - Those are used for DMA (mmap/DMABUF) and
> + *	read()/write() data I/O associated with the V4L2 devnodes.
> + */
> +#define MEDIA_ENT_T_V4L2_VIDEO		(MEDIA_ENT_T_V4L2_BASE + 1)
> +	/*
> +	 * Please notice that numbers between MEDIA_ENT_T_V4L2_BASE + 2 and
> +	 * MEDIA_ENT_T_V4L2_BASE + 4 can't be used, as those values used
> +	 * to be declared for FB, ALSA and DVB entities.
> +	 * As those values were never actually used in practice, we're just
> +	 * adding them as backward compatibility macros and keeping the
> +	 * numberspace clean here. This way, we avoid breaking compilation,
> +	 * in the case of having some userspace application using the old
> +	 * symbols.
> +	 */
> +#define MEDIA_ENT_T_V4L2_VBI		(MEDIA_ENT_T_V4L2_BASE + 5)
> +	/* for TX radio, as RX is done via either ALSA or wire */
> +#define MEDIA_ENT_T_V4L2_RADIO		(MEDIA_ENT_T_V4L2_BASE + 6)

But TX is also done via either ALSA or wire. This shouldn't be needed.

> +#define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 7)

How about MEDIA_ENT_T_DVB_IO_* and MEDIA_ENT_T_V4L2_IO_* to indicate that
this entity deals with data I/O?

Or, perhaps even better, MEDIA_ENT_T_IO_DVB_ and MEDIA_ENT_T_IO_V4L2_.

Entities should do something, and just saying 'V4L2_VIDEO' doesn't really convey
that meaning. It is also very easy to confuse with INTF_T_V4L_* types. BTW, we
should decide whether V4L2 or V4L is used here (interfaces now use V4L, entities
V4L2). Since entities already use V4L2, I think the interface defines should
use V4L2 as well.

> +
> +/* V4L2 Sub-device entities */
> +#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
> +#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
> +#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
> +	/* A converter of analogue video to its digital representation. */
> +#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 4)
> +	/* Tuner entity is actually both V4L2 and DVB subdev */
> +#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 5)
> +
> +/* DVB entities */
> +#define MEDIA_ENT_T_DVB_DEMOD		(MEDIA_ENT_T_DVB_BASE)

After changing DVB_BASE to 0, change this to DVB_BASE + 1, and adjust the other DVB
entity types accordingly.

This keeps the base defines consistent (i.e. the lower 16 bits are always 0).

It surprised me when reading this patch, so I'm probably not the only one.

Regards,

	Hans

> +#define MEDIA_ENT_T_DVB_DEMUX		(MEDIA_ENT_T_DVB_BASE + 1)
> +#define MEDIA_ENT_T_DVB_TSOUT		(MEDIA_ENT_T_DVB_BASE + 2)
> +#define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 3)
> +#define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 4)
> +
> +/* Legacy symbols used to avoid userspace compilation breakages */
>  #define MEDIA_ENT_TYPE_SHIFT		16
>  #define MEDIA_ENT_TYPE_MASK		0x00ff0000
>  #define MEDIA_ENT_SUBTYPE_MASK		0x0000ffff
>  
> -#define MEDIA_ENT_T_DEVNODE		(1 << MEDIA_ENT_TYPE_SHIFT)
> -#define MEDIA_ENT_T_DEVNODE_V4L		(MEDIA_ENT_T_DEVNODE + 1)
> +#define MEDIA_ENT_T_DEVNODE		MEDIA_ENT_T_V4L2_BASE
> +#define MEDIA_ENT_T_V4L2_SUBDEV		MEDIA_ENT_T_V4L2_SUBDEV_BASE
> +
> +#define MEDIA_ENT_T_DEVNODE_V4L		MEDIA_ENT_T_V4L2_VIDEO
> +
>  #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
>  #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
> -#define MEDIA_ENT_T_DEVNODE_DVB_FE	(MEDIA_ENT_T_DEVNODE + 4)
> -#define MEDIA_ENT_T_DEVNODE_DVB_DEMUX	(MEDIA_ENT_T_DEVNODE + 5)
> -#define MEDIA_ENT_T_DEVNODE_DVB_DVR	(MEDIA_ENT_T_DEVNODE + 6)
> -#define MEDIA_ENT_T_DEVNODE_DVB_CA	(MEDIA_ENT_T_DEVNODE + 7)
> -#define MEDIA_ENT_T_DEVNODE_DVB_NET	(MEDIA_ENT_T_DEVNODE + 8)
> +#define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
>  
> -/* Legacy symbol. Use it to avoid userspace compilation breakages */
> -#define MEDIA_ENT_T_DEVNODE_DVB		MEDIA_ENT_T_DEVNODE_DVB_FE
> -
> -#define MEDIA_ENT_T_V4L2_SUBDEV		(2 << MEDIA_ENT_TYPE_SHIFT)
> -#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV + 1)
> -#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV + 2)
> -#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV + 3)
> -/* A converter of analogue video to its digital representation. */
> -#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV + 4)
> -
> -#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV + 5)
> +/* Entity types */
>  
>  #define MEDIA_ENT_FL_DEFAULT		(1 << 0)
>  
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 30/55] [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_DVB
  2015-08-30  3:06 ` [PATCH v8 30/55] [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_DVB Mauro Carvalho Chehab
@ 2015-08-31 11:21   ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:21 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Jonathan Corbet, linux-doc

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Now that interfaces and entities are distinct, it makes no sense
> of keeping something named as MEDIA_ENT_T_DEVNODE_DVB_foo.
> 
> Made via this script:
> 	for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DEVNODE_DVB_,MEDIA_ENT_T_DVB_, <$i >a && mv a $i; done
> 	for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DVB_DVR,MEDIA_ENT_T_DVB_TSOUT, <$i >a && mv a $i; done
> 	for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DVB_FE,MEDIA_ENT_T_DVB_DEMOD, <$i >a && mv a $i; done
> 	for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DVB_NET,MEDIA_ENT_T_DVB_DEMOD_NET_DECAP, <$i >a && mv a $i; done
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> index 910243d4edb8..32a783635649 100644
> --- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> +++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> @@ -195,23 +195,23 @@
>  	    <entry>ALSA card</entry>
>  	  </row>
>  	  <row>
> -	    <entry><constant>MEDIA_ENT_T_DEVNODE_DVB_FE</constant></entry>
> +	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD</constant></entry>
>  	    <entry>DVB frontend devnode</entry>
>  	  </row>
>  	  <row>
> -	    <entry><constant>MEDIA_ENT_T_DEVNODE_DVB_DEMUX</constant></entry>
> +	    <entry><constant>MEDIA_ENT_T_DVB_DEMUX</constant></entry>
>  	    <entry>DVB demux devnode</entry>
>  	  </row>
>  	  <row>
> -	    <entry><constant>MEDIA_ENT_T_DEVNODE_DVB_DVR</constant></entry>
> +	    <entry><constant>MEDIA_ENT_T_DVB_TSOUT</constant></entry>
>  	    <entry>DVB DVR devnode</entry>
>  	  </row>
>  	  <row>
> -	    <entry><constant>MEDIA_ENT_T_DEVNODE_DVB_CA</constant></entry>
> +	    <entry><constant>MEDIA_ENT_T_DVB_CA</constant></entry>
>  	    <entry>DVB CAM devnode</entry>
>  	  </row>
>  	  <row>
> -	    <entry><constant>MEDIA_ENT_T_DEVNODE_DVB_NET</constant></entry>
> +	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD_NET_DECAP</constant></entry>
>  	    <entry>DVB network devnode</entry>
>  	  </row>
>  	  <row>
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 29/55] [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_V4L
  2015-08-30  3:06   ` Mauro Carvalho Chehab
@ 2015-08-31 11:22     ` Hans Verkuil
  -1 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:22 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Jonathan Corbet, Hyun Kwon,
	Laurent Pinchart, Michal Simek, Sören Brinkmann,
	Sakari Ailus, Prabhakar Lad, Sylwester Nawrocki,
	Lars-Peter Clausen, Markus Elfring, linux-doc, linux-arm-kernel

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Now that interfaces and entities are distinct, it makes no sense
> of keeping something named as MEDIA_ENT_T_DEVNODE.
> 
> This change was done with this script:
> 
> 	for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DEVNODE_V4L,MEDIA_ENT_T_V4L2_VIDEO, <$i >a && mv a $i; done
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> index 5872f8bbf774..910243d4edb8 100644
> --- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> +++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> @@ -183,7 +183,7 @@
>  	    <entry>Unknown device node</entry>
>  	  </row>
>  	  <row>
> -	    <entry><constant>MEDIA_ENT_T_DEVNODE_V4L</constant></entry>
> +	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
>  	    <entry>V4L video, radio or vbi device node</entry>
>  	  </row>
>  	  <row>
> diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> index 92e8116dc28f..88cd789cdaf7 100644
> --- a/drivers/media/platform/xilinx/xilinx-dma.c
> +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> @@ -193,7 +193,7 @@ static int xvip_pipeline_validate(struct xvip_pipeline *pipe,
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  		struct xvip_dma *dma;
>  
> -		if (entity->type != MEDIA_ENT_T_DEVNODE_V4L)
> +		if (entity->type != MEDIA_ENT_T_V4L2_VIDEO)
>  			continue;
>  
>  		dma = to_xvip_dma(media_entity_to_video_device(entity));
> diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
> index 71a1b93b0790..44b330589787 100644
> --- a/drivers/media/v4l2-core/v4l2-dev.c
> +++ b/drivers/media/v4l2-core/v4l2-dev.c
> @@ -912,7 +912,7 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
>  	/* Part 5: Register the entity. */
>  	if (vdev->v4l2_dev->mdev &&
>  	    vdev->vfl_type != VFL_TYPE_SUBDEV) {
> -		vdev->entity.type = MEDIA_ENT_T_DEVNODE_V4L;
> +		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
>  		vdev->entity.name = vdev->name;
>  		vdev->entity.info.dev.major = VIDEO_MAJOR;
>  		vdev->entity.info.dev.minor = vdev->minor;
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index 83615b8fb46a..e6e1115d8215 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -535,7 +535,7 @@ v4l2_subdev_link_validate_get_format(struct media_pad *pad,
>  		return v4l2_subdev_call(sd, pad, get_fmt, NULL, fmt);
>  	}
>  
> -	WARN(pad->entity->type != MEDIA_ENT_T_DEVNODE_V4L,
> +	WARN(pad->entity->type != MEDIA_ENT_T_V4L2_VIDEO,
>  	     "Driver bug! Wrong media entity type 0x%08x, entity %s\n",
>  	     pad->entity->type, pad->entity->name);
>  
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH v8 29/55] [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_V4L
@ 2015-08-31 11:22     ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:22 UTC (permalink / raw)
  To: linux-arm-kernel

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Now that interfaces and entities are distinct, it makes no sense
> of keeping something named as MEDIA_ENT_T_DEVNODE.
> 
> This change was done with this script:
> 
> 	for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DEVNODE_V4L,MEDIA_ENT_T_V4L2_VIDEO, <$i >a && mv a $i; done
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> index 5872f8bbf774..910243d4edb8 100644
> --- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> +++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> @@ -183,7 +183,7 @@
>  	    <entry>Unknown device node</entry>
>  	  </row>
>  	  <row>
> -	    <entry><constant>MEDIA_ENT_T_DEVNODE_V4L</constant></entry>
> +	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
>  	    <entry>V4L video, radio or vbi device node</entry>
>  	  </row>
>  	  <row>
> diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> index 92e8116dc28f..88cd789cdaf7 100644
> --- a/drivers/media/platform/xilinx/xilinx-dma.c
> +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> @@ -193,7 +193,7 @@ static int xvip_pipeline_validate(struct xvip_pipeline *pipe,
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  		struct xvip_dma *dma;
>  
> -		if (entity->type != MEDIA_ENT_T_DEVNODE_V4L)
> +		if (entity->type != MEDIA_ENT_T_V4L2_VIDEO)
>  			continue;
>  
>  		dma = to_xvip_dma(media_entity_to_video_device(entity));
> diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
> index 71a1b93b0790..44b330589787 100644
> --- a/drivers/media/v4l2-core/v4l2-dev.c
> +++ b/drivers/media/v4l2-core/v4l2-dev.c
> @@ -912,7 +912,7 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
>  	/* Part 5: Register the entity. */
>  	if (vdev->v4l2_dev->mdev &&
>  	    vdev->vfl_type != VFL_TYPE_SUBDEV) {
> -		vdev->entity.type = MEDIA_ENT_T_DEVNODE_V4L;
> +		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
>  		vdev->entity.name = vdev->name;
>  		vdev->entity.info.dev.major = VIDEO_MAJOR;
>  		vdev->entity.info.dev.minor = vdev->minor;
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index 83615b8fb46a..e6e1115d8215 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -535,7 +535,7 @@ v4l2_subdev_link_validate_get_format(struct media_pad *pad,
>  		return v4l2_subdev_call(sd, pad, get_fmt, NULL, fmt);
>  	}
>  
> -	WARN(pad->entity->type != MEDIA_ENT_T_DEVNODE_V4L,
> +	WARN(pad->entity->type != MEDIA_ENT_T_V4L2_VIDEO,
>  	     "Driver bug! Wrong media entity type 0x%08x, entity %s\n",
>  	     pad->entity->type, pad->entity->name);
>  
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 41/55] [media] DocBook: update descriptions for the media controller entities
  2015-08-30  3:06 ` [PATCH v8 41/55] [media] DocBook: update descriptions for the media controller entities Mauro Carvalho Chehab
@ 2015-08-31 11:22   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:22 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Jonathan Corbet, linux-doc

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Cleanup the media controller entities description:
> - remove MEDIA_ENT_T_DEVNODE and MEDIA_ENT_T_V4L2_SUBDEV entity
>   types, as they don't mean anything;

Shouldn't this add MEDIA_ENT_T_V4L2_VBI and _SWRADIO descriptions?

Regards,

	Hans

> - add MEDIA_ENT_T_UNKNOWN with a proper description;
> - remove ALSA and FB entity types. Those should not be used, as
>   the types are deprecated. We'll soon be adidng ALSA, but with
>   a different entity namespace;
> - improve the description of some entities.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> index 32a783635649..bd90dde54416 100644
> --- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> +++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> @@ -179,70 +179,59 @@
>          <colspec colname="c2"/>
>  	<tbody valign="top">
>  	  <row>
> -	    <entry><constant>MEDIA_ENT_T_DEVNODE</constant></entry>
> -	    <entry>Unknown device node</entry>
> +	    <entry><constant>MEDIA_ENT_T_UNKNOWN</constant> and <constant>MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN</constant></entry>
> +	    <entry>Unknown entity. That generally indicates that
> +	    a driver didn't initialize properly the entity, with is a Kernel bug</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
> -	    <entry>V4L video, radio or vbi device node</entry>
> -	  </row>
> -	  <row>
> -	    <entry><constant>MEDIA_ENT_T_DEVNODE_FB</constant></entry>
> -	    <entry>Frame buffer device node</entry>
> -	  </row>
> -	  <row>
> -	    <entry><constant>MEDIA_ENT_T_DEVNODE_ALSA</constant></entry>
> -	    <entry>ALSA card</entry>
> +	    <entry>V4L video streaming input or output entity</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD</constant></entry>
> -	    <entry>DVB frontend devnode</entry>
> +	    <entry>DVB demodulator entity</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_DVB_DEMUX</constant></entry>
> -	    <entry>DVB demux devnode</entry>
> +	    <entry>DVB demux entity. Could be implemented on hardware or in Kernelspace</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_DVB_TSOUT</constant></entry>
> -	    <entry>DVB DVR devnode</entry>
> +	    <entry>DVB Transport Stream output entity</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_DVB_CA</constant></entry>
> -	    <entry>DVB CAM devnode</entry>
> +	    <entry>DVB Conditional Access module (CAM) entity</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD_NET_DECAP</constant></entry>
> -	    <entry>DVB network devnode</entry>
> -	  </row>
> -	  <row>
> -	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV</constant></entry>
> -	    <entry>Unknown V4L sub-device</entry>
> +	    <entry>DVB network ULE/MLE desencapsulation entity. Could be implemented on hardware or in Kernelspace</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_SENSOR</constant></entry>
> -	    <entry>Video sensor</entry>
> +	    <entry>Camera video sensor entity</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_FLASH</constant></entry>
> -	    <entry>Flash controller</entry>
> +	    <entry>Flash controller entity</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_LENS</constant></entry>
> -	    <entry>Lens controller</entry>
> +	    <entry>Lens controller entity</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_DECODER</constant></entry>
> -	    <entry>Video decoder, the basic function of the video decoder is to
> -	    accept analogue video from a wide variety of sources such as
> +	    <entry>Analog video decoder, the basic function of the video decoder
> +	    is to accept analogue video from a wide variety of sources such as
>  	    broadcast, DVD players, cameras and video cassette recorders, in
> -	    either NTSC, PAL or HD format and still occasionally SECAM, separate
> -	    it into its component parts, luminance and chrominance, and output
> +	    either NTSC, PAL, SECAM or HD format, separating the stream
> +	    into its component parts, luminance and chrominance, and output
>  	    it in some digital video standard, with appropriate embedded timing
>  	    signals.</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_TUNER</constant></entry>
> -	    <entry>TV and/or radio tuner</entry>
> +	    <entry>Digital TV, analog TV, radio and/or software radio tuner</entry>
>  	  </row>
>  	</tbody>
>        </tgroup>
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA
  2015-08-30  3:06 ` [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA Mauro Carvalho Chehab
@ 2015-08-31 11:31   ` Hans Verkuil
  2015-08-31 11:40     ` Hans Verkuil
  2015-08-31 13:08     ` Mauro Carvalho Chehab
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 2 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:31 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> As we'll be removing entity subtypes from the Kernel, we need
> to provide a way for drivers and core to check if a given
> entity is represented by a V4L2 subdev or if it is an V4L2
> I/O entity (typically with DMA).

This needs more discussion. The plan (as I understand it) is to have properties
that describe the entity's functionalities.

The existing entity subtypes will exist only as backwards compat types, but in
the future properties should be used to describe the functionalities.

This raises the question if we shouldn't use MEDIA_ENT_T_V4L2_SUBDEV to tell
userspace that this is a subdev-controlled entity, and let userspace look at
the properties to figure out what it is exactly?

It could be that this is a transitional patch, and this will be fixed later.
If so, this should be mentioned in the commit message.

Regards,

	Hans

> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index e7b20bdc735d..b0cfbc0dffc7 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -220,6 +220,39 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
>  	return id;
>  }
>  
> +static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
> +{
> +	if (!entity)
> +		return false;
> +
> +	switch (entity->type) {
> +	case MEDIA_ENT_T_V4L2_VIDEO:
> +	case MEDIA_ENT_T_V4L2_VBI:
> +	case MEDIA_ENT_T_V4L2_SWRADIO:
> +		return true;
> +	default:
> +		return false;
> +	}
> +}
> +
> +static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
> +{
> +	if (!entity)
> +		return false;
> +
> +	switch (entity->type) {
> +	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
> +	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
> +	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
> +	case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
> +	case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
> +		return true;
> +
> +	default:
> +		return false;
> +	}
> +}
> +
>  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
>  #define MEDIA_ENTITY_ENUM_MAX_ID	64
>  
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA
  2015-08-31 11:31   ` Hans Verkuil
@ 2015-08-31 11:40     ` Hans Verkuil
  2015-08-31 13:08     ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:40 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/31/2015 01:31 PM, Hans Verkuil wrote:
> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
>> As we'll be removing entity subtypes from the Kernel, we need
>> to provide a way for drivers and core to check if a given
>> entity is represented by a V4L2 subdev or if it is an V4L2
>> I/O entity (typically with DMA).
> 
> This needs more discussion. The plan (as I understand it) is to have properties
> that describe the entity's functionalities.
> 
> The existing entity subtypes will exist only as backwards compat types, but in
> the future properties should be used to describe the functionalities.
> 
> This raises the question if we shouldn't use MEDIA_ENT_T_V4L2_SUBDEV to tell
> userspace that this is a subdev-controlled entity, and let userspace look at
> the properties to figure out what it is exactly?
> 
> It could be that this is a transitional patch, and this will be fixed later.
> If so, this should be mentioned in the commit message.

FYI, I'm skipping patches that change the MEDIA_ENT_T_V4L2_SUBDEV usage until
I understand the long-term plan for this define as discussed above.

Regards,

	Hans

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 38/55] [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs
@ 2015-08-31 11:43     ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:43 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Hans Verkuil, Laurent Pinchart,
	Sylwester Nawrocki, Prabhakar Lad, Lars-Peter Clausen,
	Markus Elfring, linux-api

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Instead of abusing MEDIA_ENT_T_V4L2_SUBDEV, initialize
> new subdev entities as MEDIA_ENT_T_UNKNOWN.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 659507bce63f..134fe7510195 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -435,6 +435,12 @@ int __must_check media_device_register_entity(struct media_device *mdev,
>  {
>  	int i;
>  
> +	if (entity->type == MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN ||
> +	    entity->type == MEDIA_ENT_T_UNKNOWN)
> +		dev_warn(mdev->dev,
> +			 "Entity type for entity %s was not initialized!\n",
> +			 entity->name);
> +
>  	/* Warn if we apparently re-register an entity */
>  	WARN_ON(entity->graph_obj.mdev != NULL);
>  	entity->graph_obj.mdev = mdev;
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index 60da43772de9..b3bcc8253182 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -584,7 +584,7 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops)
>  	sd->host_priv = NULL;
>  #if defined(CONFIG_MEDIA_CONTROLLER)
>  	sd->entity.name = sd->name;
> -	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
> +	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN;
>  #endif
>  }
>  EXPORT_SYMBOL(v4l2_subdev_init);
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index 3bbda409353f..44b84aae8b02 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -42,6 +42,14 @@ struct media_device_info {
>  
>  #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
>  
> +/* Used values for media_entity_desc::type */
> +
> +/*
> + * Initial value when an entity is created
> + * Drivers should change it to something useful
> + */
> +#define MEDIA_ENT_T_UNKNOWN	0x00000000
> +
>  /*
>   * Base numbers for entity types
>   *
> @@ -77,6 +85,15 @@ struct media_device_info {
>  #define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 7)
>  
>  /* V4L2 Sub-device entities */
> +
> +	/*
> +	 * Subdevs are initialized with MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN,
> +	 * in order to preserve backward compatibility.
> +	 * Drivers should change to the proper subdev type before
> +	 * registering the entity.
> +	 */
> +#define MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN	MEDIA_ENT_T_V4L2_SUBDEV_BASE
> +
>  #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
>  #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
>  #define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 38/55] [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs
@ 2015-08-31 11:43     ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:43 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Hans Verkuil, Laurent Pinchart,
	Sylwester Nawrocki, Prabhakar Lad, Lars-Peter Clausen,
	Markus Elfring, linux-api-u79uwXL29TY76Z2rM5mHXA

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Instead of abusing MEDIA_ENT_T_V4L2_SUBDEV, initialize
> new subdev entities as MEDIA_ENT_T_UNKNOWN.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>

Acked-by: Hans Verkuil <hans.verkuil-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>

> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 659507bce63f..134fe7510195 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -435,6 +435,12 @@ int __must_check media_device_register_entity(struct media_device *mdev,
>  {
>  	int i;
>  
> +	if (entity->type == MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN ||
> +	    entity->type == MEDIA_ENT_T_UNKNOWN)
> +		dev_warn(mdev->dev,
> +			 "Entity type for entity %s was not initialized!\n",
> +			 entity->name);
> +
>  	/* Warn if we apparently re-register an entity */
>  	WARN_ON(entity->graph_obj.mdev != NULL);
>  	entity->graph_obj.mdev = mdev;
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index 60da43772de9..b3bcc8253182 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -584,7 +584,7 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops)
>  	sd->host_priv = NULL;
>  #if defined(CONFIG_MEDIA_CONTROLLER)
>  	sd->entity.name = sd->name;
> -	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
> +	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN;
>  #endif
>  }
>  EXPORT_SYMBOL(v4l2_subdev_init);
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index 3bbda409353f..44b84aae8b02 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -42,6 +42,14 @@ struct media_device_info {
>  
>  #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
>  
> +/* Used values for media_entity_desc::type */
> +
> +/*
> + * Initial value when an entity is created
> + * Drivers should change it to something useful
> + */
> +#define MEDIA_ENT_T_UNKNOWN	0x00000000
> +
>  /*
>   * Base numbers for entity types
>   *
> @@ -77,6 +85,15 @@ struct media_device_info {
>  #define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 7)
>  
>  /* V4L2 Sub-device entities */
> +
> +	/*
> +	 * Subdevs are initialized with MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN,
> +	 * in order to preserve backward compatibility.
> +	 * Drivers should change to the proper subdev type before
> +	 * registering the entity.
> +	 */
> +#define MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN	MEDIA_ENT_T_V4L2_SUBDEV_BASE
> +
>  #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
>  #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
>  #define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 39/55] [media] media controller: get rid of entity subtype on Kernel
@ 2015-08-31 11:44     ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:44 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, linux-api

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Don't use anymore the type/subtype entity data/macros
> inside the Kernel.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index b0cfbc0dffc7..756e1960fd7f 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -185,16 +185,6 @@ struct media_intf_devnode {
>  	u32				minor;
>  };
>  
> -static inline u32 media_entity_type(struct media_entity *entity)
> -{
> -	return entity->type & MEDIA_ENT_TYPE_MASK;
> -}
> -
> -static inline u32 media_entity_subtype(struct media_entity *entity)
> -{
> -	return entity->type & MEDIA_ENT_SUBTYPE_MASK;
> -}
> -
>  static inline u32 media_entity_id(struct media_entity *entity)
>  {
>  	return entity->graph_obj.id;
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index 44b84aae8b02..cd486fc25f1e 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -42,10 +42,8 @@ struct media_device_info {
>  
>  #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
>  
> -/* Used values for media_entity_desc::type */
> -
>  /*
> - * Initial value when an entity is created
> + * Initial value to be used when a new entity is created

This change should be moved to patch 38.

>   * Drivers should change it to something useful
>   */
>  #define MEDIA_ENT_T_UNKNOWN	0x00000000
> 

Regards,

	Hans

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 39/55] [media] media controller: get rid of entity subtype on Kernel
@ 2015-08-31 11:44     ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:44 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, linux-api-u79uwXL29TY76Z2rM5mHXA

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Don't use anymore the type/subtype entity data/macros
> inside the Kernel.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index b0cfbc0dffc7..756e1960fd7f 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -185,16 +185,6 @@ struct media_intf_devnode {
>  	u32				minor;
>  };
>  
> -static inline u32 media_entity_type(struct media_entity *entity)
> -{
> -	return entity->type & MEDIA_ENT_TYPE_MASK;
> -}
> -
> -static inline u32 media_entity_subtype(struct media_entity *entity)
> -{
> -	return entity->type & MEDIA_ENT_SUBTYPE_MASK;
> -}
> -
>  static inline u32 media_entity_id(struct media_entity *entity)
>  {
>  	return entity->graph_obj.id;
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index 44b84aae8b02..cd486fc25f1e 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -42,10 +42,8 @@ struct media_device_info {
>  
>  #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
>  
> -/* Used values for media_entity_desc::type */
> -
>  /*
> - * Initial value when an entity is created
> + * Initial value to be used when a new entity is created

This change should be moved to patch 38.

>   * Drivers should change it to something useful
>   */
>  #define MEDIA_ENT_T_UNKNOWN	0x00000000
> 

Regards,

	Hans

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 40/55] [media] media.h: don't use legacy entity macros at Kernel
@ 2015-08-31 11:44     ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:44 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, linux-api

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Put the legacy MEDIA_ENT_* macros under a #ifndef __KERNEL__,
> in order to be sure that none of those old symbols are used
> inside the Kernel.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index cd486fc25f1e..4186891e5e81 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -107,6 +107,7 @@ struct media_device_info {
>  #define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 3)
>  #define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 4)
>  
> +#ifndef __KERNEL__
>  /* Legacy symbols used to avoid userspace compilation breakages */
>  #define MEDIA_ENT_TYPE_SHIFT		16
>  #define MEDIA_ENT_TYPE_MASK		0x00ff0000
> @@ -120,6 +121,7 @@ struct media_device_info {
>  #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
>  #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
>  #define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
> +#endif
>  
>  /* Entity types */
>  
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 40/55] [media] media.h: don't use legacy entity macros at Kernel
@ 2015-08-31 11:44     ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:44 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, linux-api-u79uwXL29TY76Z2rM5mHXA

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Put the legacy MEDIA_ENT_* macros under a #ifndef __KERNEL__,
> in order to be sure that none of those old symbols are used
> inside the Kernel.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>

Acked-by: Hans Verkuil <hans.verkuil-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>

> 
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index cd486fc25f1e..4186891e5e81 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -107,6 +107,7 @@ struct media_device_info {
>  #define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 3)
>  #define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 4)
>  
> +#ifndef __KERNEL__
>  /* Legacy symbols used to avoid userspace compilation breakages */
>  #define MEDIA_ENT_TYPE_SHIFT		16
>  #define MEDIA_ENT_TYPE_MASK		0x00ff0000
> @@ -120,6 +121,7 @@ struct media_device_info {
>  #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
>  #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
>  #define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
> +#endif
>  
>  /* Entity types */
>  
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 42/55] [media] dvb: modify core to implement interfaces/entities at MC new gen
  2015-08-30  3:06 ` [PATCH v8 42/55] [media] dvb: modify core to implement interfaces/entities at MC new gen Mauro Carvalho Chehab
@ 2015-08-31 11:49   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:49 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Stefan Richter, Changbing Xiong,
	Hans Verkuil, Markus Elfring, Jonathan Corbet, Akihiro Tsukada,
	Dan Carpenter, Tina Ruchandani, Antti Palosaari, Joe Perches,
	Eric W. Biederman, Vaishali Thakkar, Sakari Ailus,
	Laurent Pinchart, Takeshi Yoshimura, linux1394-devel

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> The Media Controller New Generation redefines the types for both
> interfaces and entities to be used on DVB. Make the needed
> changes at the DVB core for all interfaces, entities and
> data and interface links to appear in the graph.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c
> index d0e3f9d85f34..baaed28ee975 100644
> --- a/drivers/media/dvb-core/dmxdev.c
> +++ b/drivers/media/dvb-core/dmxdev.c
> @@ -1242,9 +1242,9 @@ int dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *dvb_adapter)
>  	}
>  
>  	dvb_register_device(dvb_adapter, &dmxdev->dvbdev, &dvbdev_demux, dmxdev,
> -			    DVB_DEVICE_DEMUX);
> +			    DVB_DEVICE_DEMUX, dmxdev->filternum);
>  	dvb_register_device(dvb_adapter, &dmxdev->dvr_dvbdev, &dvbdev_dvr,
> -			    dmxdev, DVB_DEVICE_DVR);
> +			    dmxdev, DVB_DEVICE_DVR, dmxdev->filternum);
>  
>  	dvb_ringbuffer_init(&dmxdev->dvr_buffer, NULL, 8192);
>  
> diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb-core/dvb_ca_en50221.c
> index fb66184dc9b6..f82cd1ff4f3a 100644
> --- a/drivers/media/dvb-core/dvb_ca_en50221.c
> +++ b/drivers/media/dvb-core/dvb_ca_en50221.c
> @@ -1695,7 +1695,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
>  	pubca->private = ca;
>  
>  	/* register the DVB device */
> -	ret = dvb_register_device(dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, DVB_DEVICE_CA);
> +	ret = dvb_register_device(dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, DVB_DEVICE_CA, 0);
>  	if (ret)
>  		goto free_slot_info;
>  
> diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
> index 2d06bcff0946..58601bfe0b8d 100644
> --- a/drivers/media/dvb-core/dvb_frontend.c
> +++ b/drivers/media/dvb-core/dvb_frontend.c
> @@ -2754,7 +2754,7 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
>  			fe->dvb->num, fe->id, fe->ops.info.name);
>  
>  	dvb_register_device (fe->dvb, &fepriv->dvbdev, &dvbdev_template,
> -			     fe, DVB_DEVICE_FRONTEND);
> +			     fe, DVB_DEVICE_FRONTEND, 0);
>  
>  	/*
>  	 * Initialize the cache to the proper values according with the
> diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c
> index b81e026edab3..14f51b68f4fe 100644
> --- a/drivers/media/dvb-core/dvb_net.c
> +++ b/drivers/media/dvb-core/dvb_net.c
> @@ -1503,6 +1503,6 @@ int dvb_net_init (struct dvb_adapter *adap, struct dvb_net *dvbnet,
>  		dvbnet->state[i] = 0;
>  
>  	return dvb_register_device(adap, &dvbnet->dvbdev, &dvbdev_net,
> -			     dvbnet, DVB_DEVICE_NET);
> +			     dvbnet, DVB_DEVICE_NET, 0);
>  }
>  EXPORT_SYMBOL(dvb_net_init);
> diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
> index 88013d1a2c39..f638c67defbe 100644
> --- a/drivers/media/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb-core/dvbdev.c
> @@ -180,18 +180,86 @@ skip:
>  	return -ENFILE;
>  }
>  
> +static void dvb_create_tsout_entity(struct dvb_device *dvbdev,
> +				    const char *name, int npads)
> +{
> +#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
> +	int i, ret = 0;
> +
> +	dvbdev->tsout_pads = kcalloc(npads, sizeof(*dvbdev->tsout_pads),
> +				     GFP_KERNEL);
> +	if (!dvbdev->tsout_pads)
> +		return;
> +	dvbdev->tsout_entity = kcalloc(npads, sizeof(*dvbdev->tsout_entity),
> +				       GFP_KERNEL);
> +	if (!dvbdev->tsout_entity) {
> +		kfree(dvbdev->tsout_pads);
> +		dvbdev->tsout_pads = NULL;
> +		return;
> +	}
> +	for (i = 0; i < npads; i++) {
> +		struct media_pad *pads = &dvbdev->tsout_pads[i];
> +		struct media_entity *entity = &dvbdev->tsout_entity[i];
> +
> +		entity->name = kasprintf(GFP_KERNEL, "%s #%d", name, i);
> +		if (!entity->name) {
> +			ret = -ENOMEM;
> +			break;
> +		}
> +
> +		entity->type = MEDIA_ENT_T_DVB_TSOUT;
> +		pads->flags = MEDIA_PAD_FL_SINK;
> +
> +		ret = media_entity_init(entity, 1, pads);
> +		if (ret < 0)
> +			break;
> +
> +		ret = media_device_register_entity(dvbdev->adapter->mdev,
> +						   entity);
> +		if (ret < 0)
> +			break;
> +	}
> +
> +	if (!ret) {
> +		dvbdev->tsout_num_entities = npads;
> +		return;
> +	}
> +
> +	for (i--; i >= 0; i--) {
> +		media_device_unregister_entity(&dvbdev->tsout_entity[i]);
> +		kfree(dvbdev->tsout_entity[i].name);
> +	}
> +
> +	printk(KERN_ERR
> +		"%s: media_device_register_entity failed for %s\n",
> +		__func__, name);
> +
> +	kfree(dvbdev->tsout_entity);
> +	kfree(dvbdev->tsout_pads);
> +	dvbdev->tsout_entity = NULL;
> +	dvbdev->tsout_pads = NULL;
> +#endif
> +}
> +
> +#define DEMUX_TSOUT	"demux_tsout"
> +#define DVR_TSOUT	"dvr_tsout"
> +

I have a preference for - instead of _.

Your choice, though.

Regards,

	Hans

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 43/55] [media] media: report if a pad is sink or source at debug msg
  2015-08-30  3:06 ` [PATCH v8 43/55] [media] media: report if a pad is sink or source at debug msg Mauro Carvalho Chehab
@ 2015-08-31 11:51   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 11:51 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Sakari Ailus, Laurent Pinchart, Hans Verkuil

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Sometimes, it is important to see if the created pad is
> sink or source. Add info to track that.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
> index f638c67defbe..610d2bab1368 100644
> --- a/drivers/media/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb-core/dvbdev.c
> @@ -528,8 +528,8 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
>  	struct media_entity *entity, *tuner = NULL, *demod = NULL;
>  	struct media_entity *demux = NULL, *ca = NULL;
>  	struct media_interface *intf;
> -	unsigned demux_pad = 1;
> -	unsigned dvr_pad = 1;
> +	unsigned demux_pad = 0;
> +	unsigned dvr_pad = 0;
>  
>  	if (!mdev)
>  		return;
> @@ -561,15 +561,19 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
>  
>  	/* Create demux links for each ringbuffer/pad */
>  	if (demux) {
> -		if (entity->type == MEDIA_ENT_T_DVB_TSOUT) {
> -			if (!strncmp(entity->name, DVR_TSOUT,
> -				     sizeof(DVR_TSOUT)))
> -				media_create_pad_link(demux, ++dvr_pad,
> -						      entity, 0, 0);
> -			if (!strncmp(entity->name, DEMUX_TSOUT,
> -				     sizeof(DEMUX_TSOUT)))
> -				media_create_pad_link(demux, ++demux_pad,
> -						      entity, 0, 0);
> +		media_device_for_each_entity(entity, mdev) {
> +			if (entity->type == MEDIA_ENT_T_DVB_TSOUT) {
> +				if (!strncmp(entity->name, DVR_TSOUT,
> +					strlen(DVR_TSOUT)))
> +					media_create_pad_link(demux,
> +							      ++dvr_pad,
> +							entity, 0, 0);
> +				if (!strncmp(entity->name, DEMUX_TSOUT,
> +					strlen(DEMUX_TSOUT)))
> +					media_create_pad_link(demux,
> +							      ++demux_pad,
> +							entity, 0, 0);
> +			}
>  		}
>  	}
>  

Does this chunk belong here? I'd expect this in the previous patch or in a
patch on its own.

> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 15bc92d3a648..d62a6ffbc929 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -121,8 +121,11 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
>  		struct media_pad *pad = gobj_to_pad(gobj);
>  
>  		dev_dbg(gobj->mdev->dev,
> -			"%s: id 0x%08x pad#%d: '%s':%d\n",
> -			event_name, gobj->id, media_localid(gobj),
> +			"%s: id 0x%08x %s%spad#%d: '%s':%d\n",
> +			event_name, gobj->id,
> +			pad->flags & MEDIA_PAD_FL_SINK   ? "  sink " : "",
> +			pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
> +			media_localid(gobj),
>  			pad->entity->name, pad->index);
>  		break;
>  	}
> 

Regards,

	Hans

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
  2015-08-30  3:06 ` [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl Mauro Carvalho Chehab
@ 2015-08-31 12:00   ` Hans Verkuil
  2015-08-31 13:35       ` Mauro Carvalho Chehab
  2015-09-06 12:03     ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 12:00 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, linux-api

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Add a new ioctl that will report the entire topology on
> one go.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 756e1960fd7f..358a0c6b1f86 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -181,6 +181,8 @@ struct media_interface {
>   */
>  struct media_intf_devnode {
>  	struct media_interface		intf;
> +
> +	/* Should match the fields at media_v2_intf_devnode */
>  	u32				major;
>  	u32				minor;
>  };
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index 4186891e5e81..fa0b68e670b0 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -251,11 +251,94 @@ struct media_links_enum {
>  #define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
>  #define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
>  
> -/* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
> +/*
> + * MC next gen API definitions
> + *
> + * NOTE: The declarations below are close to the MC RFC for the Media
> + *	 Controller, the next generation. Yet, there are a few adjustments
> + *	 to do, as we want to be able to have a functional API before
> + *	 the MC properties change. Those will be properly marked below.
> + *	 Please also notice that I removed "num_pads", "num_links",
> + *	 from the proposal, as a proper userspace application will likely
> + *	 use lists for pads/links, just as we intend todo in Kernelspace.

s/todo/to do/

> + *	 The API definition should be freed from fields that are bound to
> + *	 some specific data structure.
> + *
> + * FIXME: Currently, I opted to name the new types as "media_v2", as this
> + *	  won't cause any conflict with the Kernelspace namespace, nor with
> + *	  the previous kAPI media_*_desc namespace. This can be changed
> + *	  latter, before the adding this API upstream.

s/latter/later/ :-)

I think this comment belongs to the commit log and not in this header.

> + */
> +
> +
> +#define MEDIA_NEW_LNK_FL_ENABLED		MEDIA_LNK_FL_ENABLED
> +#define MEDIA_NEW_LNK_FL_IMMUTABLE		MEDIA_LNK_FL_IMMUTABLE
> +#define MEDIA_NEW_LNK_FL_DYNAMIC		MEDIA_NEW_FL_DYNAMIC
> +#define MEDIA_NEW_LNK_FL_INTERFACE_LINK		(1 << 3)

Shouldn't this be MEDIA_V2_ instead of MEDIA_NEW_?

Do we need the INTERFACE_LINK flag? You can deduce it by checking the
ID type.

I don't have a clear preference one way or another, just wondering about the
reason for adding it.

> +
> +struct media_v2_entity {
> +	__u32 id;
> +	char name[64];		/* FIXME: move to a property? (RFC says so) */
> +	__u16 reserved[14];
> +};
> +
> +/* Should match the specific fields at media_intf_devnode */
> +struct media_v2_intf_devnode {
> +	__u32 major;
> +	__u32 minor;
> +};
> +
> +struct media_v2_interface {
> +	__u32 id;
> +	__u32 intf_type;
> +	__u32 flags;
> +	__u32 reserved[9];
> +
> +	union {
> +		struct media_v2_intf_devnode devnode;
> +		__u32 raw[16];
> +	};
> +};
> +
> +struct media_v2_pad {
> +	__u32 id;
> +	__u32 entity_id;
> +	__u32 flags;
> +	__u16 reserved[9];
> +};
> +
> +struct media_v2_link {
> +    __u32 id;
> +    __u32 source_id;
> +    __u32 sink_id;

Like in media_link I would use a union here as well to be able to refer to
source/sink_id and entity/interface_id.

> +    __u32 flags;
> +    __u32 reserved[5];
> +};
> +
> +struct media_v2_topology {
> +	__u32 topology_version;
> +
> +	__u32 num_entities;
> +	struct media_v2_entity *entities;
> +
> +	__u32 num_interfaces;
> +	struct media_v2_interface *interfaces;
> +
> +	__u32 num_pads;
> +	struct media_v2_pad *pads;
> +
> +	__u32 num_links;
> +	struct media_v2_link *links;
> +
> +	__u32 reserved[64];

As mentioned before: use this instead to prevent horrible 32/64 bit arch
compat code:

	struct {
		__u32 reserved_num;
		void *reserved_ptr;
	} reserved_types[16];
	__u32 reserved[8];

Sizes for these arrays are TBD.

> +};
> +
> +/* ioctls */
>  
>  #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
>  #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct media_entity_desc)
>  #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
>  #define MEDIA_IOC_SETUP_LINK		_IOWR('|', 0x03, struct media_link_desc)
> +#define MEDIA_IOC_G_TOPOLOGY		_IOWR('|', 0x04, struct media_v2_topology)
>  
>  #endif /* __LINUX_MEDIA_H */
> 

Regards,

	Hans

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 45/55] [media] media: Use a macro to interate between all interfaces
  2015-08-30  3:06 ` [PATCH v8 45/55] [media] media: Use a macro to interate between all interfaces Mauro Carvalho Chehab
@ 2015-08-31 12:01   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 12:01 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Laurent Pinchart, Hans Verkuil, Sakari Ailus

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Just like we do with entities, use a similar macro for the
> interfaces loop.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
> index 610d2bab1368..95b5b4b11230 100644
> --- a/drivers/media/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb-core/dvbdev.c
> @@ -578,9 +578,10 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
>  	}
>  
>  	/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca */
> -	list_for_each_entry(intf, &mdev->interfaces, list) {
> +	media_device_for_each_intf(intf, mdev) {
>  		if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
>  			media_create_intf_link(ca, intf, 0);
> +
>  		if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
>  			media_create_intf_link(tuner, intf, 0);
>  
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index 51807efa505b..f23d686aaac6 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -113,6 +113,11 @@ struct media_device *media_device_find_devres(struct device *dev);
>  #define media_device_for_each_entity(entity, mdev)			\
>  	list_for_each_entry(entity, &(mdev)->entities, list)
>  
> +/* Iterate over all interfaces. */
> +#define media_device_for_each_intf(intf, mdev)			\
> +	list_for_each_entry(intf, &(mdev)->interfaces, list)
> +
> +
>  #else
>  static inline int media_device_register(struct media_device *mdev)
>  {
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 46/55] [media] media: move mdev list init to gobj
  2015-08-30  3:06 ` [PATCH v8 46/55] [media] media: move mdev list init to gobj Mauro Carvalho Chehab
@ 2015-08-31 12:03   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 12:03 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Let's control the topology changes inside the graph_object.
> So, move the removal of interfaces/entities from the mdev
> lists to media_gobj_init() and media_gobj_remove().

s/removal/addition and removal/

> 
> The main reason is that mdev should have lists for all
> object types, as the new MC api will require to store
> objects in separate places.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 134fe7510195..ec98595b8a7a 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -415,7 +415,7 @@ void media_device_unregister(struct media_device *mdev)
>  	struct media_entity *entity;
>  	struct media_entity *next;
>  
> -	list_for_each_entry_safe(entity, next, &mdev->entities, list)
> +	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
>  		media_device_unregister_entity(entity);
>  
>  	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
> @@ -449,7 +449,6 @@ int __must_check media_device_register_entity(struct media_device *mdev,
>  	spin_lock(&mdev->lock);
>  	/* Initialize media_gobj embedded at the entity */
>  	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
> -	list_add_tail(&entity->list, &mdev->entities);
>  
>  	/* Initialize objects at the pads */
>  	for (i = 0; i < entity->num_pads; i++)
> @@ -487,7 +486,6 @@ void media_device_unregister_entity(struct media_entity *entity)
>  	for (i = 0; i < entity->num_pads; i++)
>  		media_gobj_remove(&entity->pads[i].graph_obj);
>  	media_gobj_remove(&entity->graph_obj);
> -	list_del(&entity->list);
>  	spin_unlock(&mdev->lock);
>  	entity->graph_obj.mdev = NULL;
>  }
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index d62a6ffbc929..192af193a394 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -170,6 +170,7 @@ void media_gobj_init(struct media_device *mdev,
>  	switch (type) {
>  	case MEDIA_GRAPH_ENTITY:
>  		gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
> +		list_add_tail(&gobj->list, &mdev->entities);
>  		break;
>  	case MEDIA_GRAPH_PAD:
>  		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
> @@ -178,6 +179,7 @@ void media_gobj_init(struct media_device *mdev,
>  		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
>  		break;
>  	case MEDIA_GRAPH_INTF_DEVNODE:
> +		list_add_tail(&gobj->list, &mdev->interfaces);
>  		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
>  		break;
>  	}
> @@ -193,6 +195,15 @@ void media_gobj_init(struct media_device *mdev,
>   */
>  void media_gobj_remove(struct media_gobj *gobj)
>  {
> +	/* Remove the object from mdev list */
> +	switch (media_type(gobj)) {
> +	case MEDIA_GRAPH_ENTITY:
> +	case MEDIA_GRAPH_INTF_DEVNODE:
> +		list_del(&gobj->list);

Missing break!

> +	default:
> +		break;
> +	}
> +
>  	dev_dbg_obj(__func__, gobj);
>  }
>  
> @@ -864,8 +875,6 @@ static void media_interface_init(struct media_device *mdev,
>  	INIT_LIST_HEAD(&intf->links);
>  
>  	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
> -
> -	list_add_tail(&intf->list, &mdev->interfaces);
>  }
>  
>  /* Functions related to the media interface via device nodes */
> @@ -894,7 +903,6 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
>  void media_devnode_remove(struct media_intf_devnode *devnode)
>  {
>  	media_gobj_remove(&devnode->intf.graph_obj);
> -	list_del(&devnode->intf.list);
>  	kfree(devnode);
>  }
>  EXPORT_SYMBOL_GPL(media_devnode_remove);
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index f23d686aaac6..85fa302047bd 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -111,11 +111,11 @@ struct media_device *media_device_find_devres(struct device *dev);
>  
>  /* Iterate over all entities. */
>  #define media_device_for_each_entity(entity, mdev)			\
> -	list_for_each_entry(entity, &(mdev)->entities, list)
> +	list_for_each_entry(entity, &(mdev)->entities, graph_obj.list)
>  
>  /* Iterate over all interfaces. */
>  #define media_device_for_each_intf(intf, mdev)			\
> -	list_for_each_entry(intf, &(mdev)->interfaces, list)
> +	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
>  
>  
>  #else
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 358a0c6b1f86..8c344a07636c 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -66,6 +66,7 @@ enum media_gobj_type {
>  struct media_gobj {
>  	struct media_device	*mdev;
>  	u32			id;
> +	struct list_head	list;
>  };
>  
>  
> @@ -114,7 +115,6 @@ struct media_entity_operations {
>  
>  struct media_entity {
>  	struct media_gobj graph_obj;	/* must be first field in struct */
> -	struct list_head list;
>  	const char *name;		/* Entity name */
>  	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
>  	u32 revision;			/* Entity revision, driver specific */
> @@ -166,7 +166,6 @@ struct media_entity {
>   */
>  struct media_interface {
>  	struct media_gobj		graph_obj;
> -	struct list_head		list;
>  	struct list_head		links;
>  	u32				type;
>  	u32				flags;
> 

Regards,

	Hans

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 28/55] [media] uapi/media.h: Fix entity namespace
  2015-08-31 11:17   ` Hans Verkuil
@ 2015-08-31 12:12     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-31 12:12 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	Laurent Pinchart, Sakari Ailus, Hans Verkuil, linux-api

Em Mon, 31 Aug 2015 13:17:08 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> > Now that interfaces got created, we need to fix the entity
> > namespace.
> > 
> > So, let's create a consistent new namespace and add backward
> > compatibility macros to keep the old namespace preserved.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
> > index 14d32cdcdd47..88013d1a2c39 100644
> > --- a/drivers/media/dvb-core/dvbdev.c
> > +++ b/drivers/media/dvb-core/dvbdev.c
> > @@ -230,17 +230,17 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
> >  
> >  	switch (type) {
> >  	case DVB_DEVICE_FRONTEND:
> > -		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_FE;
> > +		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMOD;
> >  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
> >  		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
> >  		break;
> >  	case DVB_DEVICE_DEMUX:
> > -		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_DEMUX;
> > +		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMUX;
> >  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
> >  		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
> >  		break;
> >  	case DVB_DEVICE_CA:
> > -		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_CA;
> > +		dvbdev->entity->type = MEDIA_ENT_T_DVB_CA;
> >  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
> >  		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
> >  		break;
> > @@ -439,7 +439,7 @@ EXPORT_SYMBOL(dvb_unregister_device);
> >  void dvb_create_media_graph(struct dvb_adapter *adap)
> >  {
> >  	struct media_device *mdev = adap->mdev;
> > -	struct media_entity *entity, *tuner = NULL, *fe = NULL;
> > +	struct media_entity *entity, *tuner = NULL, *demod = NULL;
> >  	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
> >  	struct media_interface *intf;
> >  
> > @@ -451,26 +451,26 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
> >  		case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
> >  			tuner = entity;
> >  			break;
> > -		case MEDIA_ENT_T_DEVNODE_DVB_FE:
> > -			fe = entity;
> > +		case MEDIA_ENT_T_DVB_DEMOD:
> > +			demod = entity;
> >  			break;
> > -		case MEDIA_ENT_T_DEVNODE_DVB_DEMUX:
> > +		case MEDIA_ENT_T_DVB_DEMUX:
> >  			demux = entity;
> >  			break;
> > -		case MEDIA_ENT_T_DEVNODE_DVB_DVR:
> > +		case MEDIA_ENT_T_DVB_TSOUT:
> >  			dvr = entity;
> >  			break;
> > -		case MEDIA_ENT_T_DEVNODE_DVB_CA:
> > +		case MEDIA_ENT_T_DVB_CA:
> >  			ca = entity;
> >  			break;
> >  		}
> >  	}
> >  
> > -	if (tuner && fe)
> > -		media_create_pad_link(tuner, 0, fe, 0, 0);
> > +	if (tuner && demod)
> > +		media_create_pad_link(tuner, 0, demod, 0, 0);
> >  
> > -	if (fe && demux)
> > -		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
> > +	if (demod && demux)
> > +		media_create_pad_link(demod, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
> >  
> >  	if (demux && dvr)
> >  		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
> > diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> > index aca828709bad..3bbda409353f 100644
> > --- a/include/uapi/linux/media.h
> > +++ b/include/uapi/linux/media.h
> > @@ -42,31 +42,71 @@ struct media_device_info {
> >  
> >  #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
> >  
> > +/*
> > + * Base numbers for entity types
> > + *
> > + * Please notice that the huge gap of 16 bits for each base is overkill!
> > + * 8 bits is more than enough to avoid starving entity types for each
> > + * subsystem.
> > + *
> > + * However, It is kept this way just to avoid binary breakages with the
> > + * namespace provided on legacy versions of this header.
> > + */
> > +#define MEDIA_ENT_T_DVB_BASE		0x00000001
> 
> I would change this to 0x00000000, see follow-up comment later for why.
> 
> > +#define MEDIA_ENT_T_V4L2_BASE		0x00010000
> > +#define MEDIA_ENT_T_V4L2_SUBDEV_BASE	0x00020000
> > +
> > +/*
> > + * V4L2 entities - Those are used for DMA (mmap/DMABUF) and
> > + *	read()/write() data I/O associated with the V4L2 devnodes.
> > + */
> > +#define MEDIA_ENT_T_V4L2_VIDEO		(MEDIA_ENT_T_V4L2_BASE + 1)
> > +	/*
> > +	 * Please notice that numbers between MEDIA_ENT_T_V4L2_BASE + 2 and
> > +	 * MEDIA_ENT_T_V4L2_BASE + 4 can't be used, as those values used
> > +	 * to be declared for FB, ALSA and DVB entities.
> > +	 * As those values were never actually used in practice, we're just
> > +	 * adding them as backward compatibility macros and keeping the
> > +	 * numberspace clean here. This way, we avoid breaking compilation,
> > +	 * in the case of having some userspace application using the old
> > +	 * symbols.
> > +	 */
> > +#define MEDIA_ENT_T_V4L2_VBI		(MEDIA_ENT_T_V4L2_BASE + 5)
> > +	/* for TX radio, as RX is done via either ALSA or wire */
> > +#define MEDIA_ENT_T_V4L2_RADIO		(MEDIA_ENT_T_V4L2_BASE + 6)
> 
> But TX is also done via either ALSA or wire. This shouldn't be needed.

OK. I'll drop it.

> 
> > +#define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 7)
> 
> How about MEDIA_ENT_T_DVB_IO_* and MEDIA_ENT_T_V4L2_IO_* to indicate that
> this entity deals with data I/O?
> 
> Or, perhaps even better, MEDIA_ENT_T_IO_DVB_ and MEDIA_ENT_T_IO_V4L2_.

Works for me.

> 
> Entities should do something, and just saying 'V4L2_VIDEO' doesn't really convey
> that meaning. It is also very easy to confuse with INTF_T_V4L_* types. BTW, we
> should decide whether V4L2 or V4L is used here (interfaces now use V4L, entities
> V4L2). Since entities already use V4L2, I think the interface defines should
> use V4L2 as well.

Yes, agreed. We actually need to discuss a little more about
namespacing and do some additional renaming stuff.

For example, calling a tuner entity as MEDIA_ENT_T_V4L2_SUBDEV_TUNER
is wrong, because the tuner can be used only at the DVB side.

So, both V4L2 and SUBDEV prefixes there are wrong. Yet, this should be
under the V4L2_SUBDEV range to avoid breaking userspace. 

> 
> > +
> > +/* V4L2 Sub-device entities */
> > +#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
> > +#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
> > +#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
> > +	/* A converter of analogue video to its digital representation. */
> > +#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 4)
> > +	/* Tuner entity is actually both V4L2 and DVB subdev */
> > +#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 5)
> > +
> > +/* DVB entities */
> > +#define MEDIA_ENT_T_DVB_DEMOD		(MEDIA_ENT_T_DVB_BASE)
> 
> After changing DVB_BASE to 0, change this to DVB_BASE + 1, and adjust the other DVB
> entity types accordingly.
> 
> This keeps the base defines consistent (i.e. the lower 16 bits are always 0).
> 
> It surprised me when reading this patch, so I'm probably not the only one.

This is another thing for discussion: keeping the MEDIA_ENT_T_foo_BASE
unused opens space for API abuse.

There are several entities at OMAP3 driver, for example, that keeps
entity->type undefined. So, they got whatever is the default at
v4l2-device.c (before this series: MEDIA_ENT_T_V4L2_SUBDEV, after
that: MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN):

$ media-ctl --print-t|grep -B1 Unknown
- entity 1: OMAP3 ISP CCP2 (2 pads, 2 links)
            type V4L2 subdev subtype Unknown flags 0
--
- entity 3: OMAP3 ISP CSI2a (2 pads, 2 links)
            type V4L2 subdev subtype Unknown flags 0
--
- entity 5: OMAP3 ISP CCDC (3 pads, 8 links)
            type V4L2 subdev subtype Unknown flags 0
--
- entity 7: OMAP3 ISP preview (2 pads, 4 links)
            type V4L2 subdev subtype Unknown flags 0
--
- entity 10: OMAP3 ISP resizer (2 pads, 4 links)
             type V4L2 subdev subtype Unknown flags 0
--
- entity 13: OMAP3 ISP AEWB (1 pad, 1 link)
             type V4L2 subdev subtype Unknown flags 0
--
- entity 14: OMAP3 ISP AF (1 pad, 1 link)
             type V4L2 subdev subtype Unknown flags 0
--
- entity 15: OMAP3 ISP histogram (1 pad, 1 link)
             type V4L2 subdev subtype Unknown flags 0

I guess all the above entities are processing units, so they
should have, instead, some type like:
	MEDIA_ENT_T_V4L2_SUBDEV_PROCESSING

Or, even some of the above would actually deserves to have an specific
type, like:
	MEDIA_ENT_T_V4L2_SUBDEV_HISTOGRAM
	MEDIA_ENT_T_V4L2_SUBDEV_RESIZER
	...

Let's try to find some time to discuss the entities namespace on IRC during
this week.

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 47/55] [media] media-device: add pads and links to media_device
  2015-08-30  3:06 ` [PATCH v8 47/55] [media] media-device: add pads and links to media_device Mauro Carvalho Chehab
@ 2015-08-31 12:25   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 12:25 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> The MC next gen API sends objects to userspace grouped by
> their types.
> 
> In the case of pads and links, in order to improve performance
> and have a simpler code, the best is to store them also on
> separate linked lists at MC.
> 
> If we don't do that, we would need this kind of interaction
> to send data to userspace (code is in structured english):
> 
> 	for each entity:
> 		for each pad:
> 			store pads
> 
> 	for each entity:
> 		for each link:
> 			store link
> 
> 	for each interface:
> 		for each link:
> 			store link
> 
> With would require one nexted loop for pads and two nested
> loops for links. By using  separate linked lists for them,
> just one loop would be enough.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index ec98595b8a7a..5b2c9f7fcd45 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -382,6 +382,8 @@ int __must_check __media_device_register(struct media_device *mdev,
>  
>  	INIT_LIST_HEAD(&mdev->entities);
>  	INIT_LIST_HEAD(&mdev->interfaces);
> +	INIT_LIST_HEAD(&mdev->pads);
> +	INIT_LIST_HEAD(&mdev->links);
>  	spin_lock_init(&mdev->lock);
>  	mutex_init(&mdev->graph_mutex);
>  
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 192af193a394..c89f51bc688d 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -174,13 +174,15 @@ void media_gobj_init(struct media_device *mdev,
>  		break;
>  	case MEDIA_GRAPH_PAD:
>  		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
> +		list_add_tail(&gobj->list, &mdev->pads);
>  		break;
>  	case MEDIA_GRAPH_LINK:
>  		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
> +		list_add_tail(&gobj->list, &mdev->links);
>  		break;
>  	case MEDIA_GRAPH_INTF_DEVNODE:
> -		list_add_tail(&gobj->list, &mdev->interfaces);
>  		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
> +		list_add_tail(&gobj->list, &mdev->interfaces);
>  		break;
>  	}
>  	dev_dbg_obj(__func__, gobj);
> @@ -195,16 +197,10 @@ void media_gobj_init(struct media_device *mdev,
>   */
>  void media_gobj_remove(struct media_gobj *gobj)
>  {
> +	dev_dbg_obj(__func__, gobj);
> +
>  	/* Remove the object from mdev list */
> -	switch (media_type(gobj)) {
> -	case MEDIA_GRAPH_ENTITY:
> -	case MEDIA_GRAPH_INTF_DEVNODE:
> -		list_del(&gobj->list);
> -	default:
> -		break;
> -	}
> -
> -	dev_dbg_obj(__func__, gobj);
> +	list_del(&gobj->list);
>  }
>  
>  /**
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index 85fa302047bd..0d1b9c687454 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -47,6 +47,8 @@ struct device;
>   * @intf_devnode_id: Unique ID used on the last interface devnode registered
>   * @entities:	List of registered entities
>   * @interfaces:	List of registered interfaces
> + * @pads:	List of registered pads
> + * @links:	List of registered links
>   * @lock:	Entities list lock
>   * @graph_mutex: Entities graph operation lock
>   * @link_notify: Link state change notification callback
> @@ -79,6 +81,8 @@ struct media_device {
>  
>  	struct list_head entities;
>  	struct list_head interfaces;
> +	struct list_head pads;
> +	struct list_head links;
>  
>  	/* Protects the entities list */
>  	spinlock_t lock;
> @@ -117,6 +121,14 @@ struct media_device *media_device_find_devres(struct device *dev);
>  #define media_device_for_each_intf(intf, mdev)			\
>  	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
>  
> +/* Iterate over all pads. */
> +#define media_device_for_each_pad(pad, mdev)			\
> +	list_for_each_entry(pad, &(mdev)->pads, graph_obj.list)
> +
> +/* Iterate over all links. */
> +#define media_device_for_each_link(link, mdev)			\
> +	list_for_each_entry(link, &(mdev)->links, graph_obj.list)
> +
>  
>  #else
>  static inline int media_device_register(struct media_device *mdev)
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 48/55] [media] media_device: add a topology version field
  2015-08-30  3:06 ` [PATCH v8 48/55] [media] media_device: add a topology version field Mauro Carvalho Chehab
@ 2015-08-31 12:29   ` Hans Verkuil
  2015-08-31 12:52     ` Mauro Carvalho Chehab
  2015-11-23 22:20     ` Laurent Pinchart
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  1 sibling, 2 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 12:29 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> Every time a graph object is added or removed, the version
> of the topology changes. That's a requirement for the new
> MEDIA_IOC_G_TOPOLOGY, in order to allow userspace to know
> that the topology has changed after a previous call to it.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

I think this should be postponed until we actually have dynamic reconfigurable
graphs.

I would also like to reserve version 0: if 0 is returned, then the graph is
static.

In G_TOPOLOGY we'd return always 0 for now.

Regards,

	Hans

> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index c89f51bc688d..c18f4af52771 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -185,6 +185,9 @@ void media_gobj_init(struct media_device *mdev,
>  		list_add_tail(&gobj->list, &mdev->interfaces);
>  		break;
>  	}
> +
> +	mdev->topology_version++;
> +
>  	dev_dbg_obj(__func__, gobj);
>  }
>  
> @@ -199,6 +202,8 @@ void media_gobj_remove(struct media_gobj *gobj)
>  {
>  	dev_dbg_obj(__func__, gobj);
>  
> +	gobj->mdev->topology_version++;
> +
>  	/* Remove the object from mdev list */
>  	list_del(&gobj->list);
>  }
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index 0d1b9c687454..1b12774a9ab4 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -41,6 +41,8 @@ struct device;
>   * @bus_info:	Unique and stable device location identifier
>   * @hw_revision: Hardware device revision
>   * @driver_version: Device driver version
> + * @topology_version: Monotonic counter for storing the version of the graph
> + *		topology. Should be incremented each time the topology changes.
>   * @entity_id:	Unique ID used on the last entity registered
>   * @pad_id:	Unique ID used on the last pad registered
>   * @link_id:	Unique ID used on the last link registered
> @@ -74,6 +76,8 @@ struct media_device {
>  	u32 hw_revision;
>  	u32 driver_version;
>  
> +	u32 topology_version;
> +
>  	u32 entity_id;
>  	u32 pad_id;
>  	u32 link_id;
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-08-30  3:07 ` [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl Mauro Carvalho Chehab
@ 2015-08-31 12:47   ` Hans Verkuil
  2015-08-31 13:40     ` Mauro Carvalho Chehab
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 12:47 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:07 AM, Mauro Carvalho Chehab wrote:
> Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
> with the RFC for the MC next generation.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 5b2c9f7fcd45..a91e1ec076a6 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -232,6 +232,136 @@ static long media_device_setup_link(struct media_device *mdev,
>  	return ret;
>  }
>  
> +static long __media_device_get_topology(struct media_device *mdev,
> +				      struct media_v2_topology *topo)
> +{
> +	struct media_entity *entity;
> +	struct media_interface *intf;
> +	struct media_pad *pad;
> +	struct media_link *link;
> +	struct media_v2_entity uentity;
> +	struct media_v2_interface uintf;
> +	struct media_v2_pad upad;
> +	struct media_v2_link ulink;
> +	int ret = 0, i;
> +
> +	topo->topology_version = mdev->topology_version;
> +
> +	/* Get entities and number of entities */
> +	i = 0;
> +	media_device_for_each_entity(entity, mdev) {
> +		i++;
> +
> +		if (ret || !topo->entities)
> +			continue;

I would add:

		if (i > topo->num_entities)
			continue;

The copy_to_user can succeed, even if i > num_entities depending on how the
memory was allocated. So I would always check num_entities and refuse to go
beyond it.

> +
> +		/* Copy fields to userspace struct if not error */
> +		memset(&uentity, 0, sizeof(uentity));
> +		uentity.id = entity->graph_obj.id;
> +		strncpy(uentity.name, entity->name,
> +			sizeof(uentity.name));
> +
> +		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
> +			ret = -EFAULT;

I would just return here. If the user gives bogus values for this, then just
give up.

> +	}
> +	topo->num_entities = i;

What to do if topo->entities != NULL and i > topo->num_entities? Just return 0
or return ENOSPC? I'm in favor of ENOSPC since a partial topology result is
useless. But if ENOSPC is returned, then all num_foo values should be updated
with the current number of elements.

This behavior would be consistent with e.g. VIDIOC_G_EXT_CTRLS.

> +
> +	/* Get interfaces and number of interfaces */
> +	i = 0;
> +	media_device_for_each_intf(intf, mdev) {
> +		i++;
> +
> +		if (ret || !topo->interfaces)
> +			continue;
> +
> +		memset(&uintf, 0, sizeof(uintf));
> +
> +		/* Copy intf fields to userspace struct */
> +		uintf.id = intf->graph_obj.id;
> +		uintf.intf_type = intf->type;
> +		uintf.flags = intf->flags;
> +
> +		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
> +			struct media_intf_devnode *devnode;
> +
> +			devnode = intf_to_devnode(intf);
> +
> +			uintf.devnode.major = devnode->major;
> +			uintf.devnode.minor = devnode->minor;
> +		}
> +
> +		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_interfaces = i;
> +
> +	/* Get pads and number of pads */
> +	i = 0;
> +	media_device_for_each_pad(pad, mdev) {
> +		i++;
> +
> +		if (ret || !topo->pads)
> +			continue;
> +
> +		memset(&upad, 0, sizeof(upad));
> +
> +		/* Copy pad fields to userspace struct */
> +		upad.id = pad->graph_obj.id;
> +		upad.entity_id = pad->entity->graph_obj.id;
> +		upad.flags = pad->flags;
> +
> +		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_pads = i;
> +
> +	/* Get links and number of links */
> +	i = 0;
> +	media_device_for_each_link(link, mdev) {
> +		i++;
> +
> +		if (ret || !topo->links)
> +			continue;
> +
> +		memset(&ulink, 0, sizeof(ulink));
> +
> +		/* Copy link fields to userspace struct */
> +		ulink.id = link->graph_obj.id;
> +		ulink.source_id = link->gobj0->id;
> +		ulink.sink_id = link->gobj1->id;
> +		ulink.flags = link->flags;
> +
> +		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
> +			ulink.flags |= MEDIA_NEW_LNK_FL_INTERFACE_LINK;
> +
> +		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_links = i;
> +
> +	return ret;
> +}
> +
> +static long media_device_get_topology(struct media_device *mdev,
> +				      struct media_v2_topology __user *utopo)
> +{
> +	struct media_v2_topology ktopo;
> +	int ret;
> +
> +	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
> +
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = __media_device_get_topology(mdev, &ktopo);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));
> +
> +	return ret;
> +}
> +
>  static long media_device_ioctl(struct file *filp, unsigned int cmd,
>  			       unsigned long arg)
>  {
> @@ -264,6 +394,13 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
>  		mutex_unlock(&dev->graph_mutex);
>  		break;
>  
> +	case MEDIA_IOC_G_TOPOLOGY:
> +		mutex_lock(&dev->graph_mutex);
> +		ret = media_device_get_topology(dev,
> +				(struct media_v2_topology __user *)arg);
> +		mutex_unlock(&dev->graph_mutex);
> +		break;
> +
>  	default:
>  		ret = -ENOIOCTLCMD;
>  	}
> @@ -312,6 +449,7 @@ static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
>  	case MEDIA_IOC_DEVICE_INFO:
>  	case MEDIA_IOC_ENUM_ENTITIES:
>  	case MEDIA_IOC_SETUP_LINK:
> +	case MEDIA_IOC_G_TOPOLOGY:
>  		return media_device_ioctl(filp, cmd, arg);
>  
>  	case MEDIA_IOC_ENUM_LINKS32:
> 

Note that this will need compat32 code eventually. Should probably be added to the
todo list in the cover letter.

Regards,

	Hans

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 50/55] [media] media-entity: unregister entity links
  2015-08-30  3:07 ` [PATCH v8 50/55] [media] media-entity: unregister entity links Mauro Carvalho Chehab
@ 2015-08-31 12:48   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 12:48 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:07 AM, Mauro Carvalho Chehab wrote:
> Add functions to explicitly unregister all entity links.
> This function is called automatically when an entity
> link is destroyed.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index c18f4af52771..96303a0ade59 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -903,6 +903,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
>  
>  void media_devnode_remove(struct media_intf_devnode *devnode)
>  {
> +	media_remove_intf_links(&devnode->intf);
>  	media_gobj_remove(&devnode->intf.graph_obj);
>  	kfree(devnode);
>  }
> @@ -944,3 +945,25 @@ void media_remove_intf_link(struct media_link *link)
>  	mutex_unlock(&link->graph_obj.mdev->graph_mutex);
>  }
>  EXPORT_SYMBOL_GPL(media_remove_intf_link);
> +
> +void __media_remove_intf_links(struct media_interface *intf)
> +{
> +	struct media_link *link, *tmp;
> +
> +	list_for_each_entry_safe(link, tmp, &intf->links, list)
> +		__media_remove_intf_link(link);
> +
> +}
> +EXPORT_SYMBOL_GPL(__media_remove_intf_links);
> +
> +void media_remove_intf_links(struct media_interface *intf)
> +{
> +	/* Do nothing if the intf is not registered. */
> +	if (intf->graph_obj.mdev == NULL)
> +		return;
> +
> +	mutex_lock(&intf->graph_obj.mdev->graph_mutex);
> +	__media_remove_intf_links(intf);
> +	mutex_unlock(&intf->graph_obj.mdev->graph_mutex);
> +}
> +EXPORT_SYMBOL_GPL(media_remove_intf_links);
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 8c344a07636c..0e7e193a6736 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -318,6 +318,9 @@ struct media_link *media_create_intf_link(struct media_entity *entity,
>  					    struct media_interface *intf,
>  					    u32 flags);
>  void media_remove_intf_link(struct media_link *link);
> +void __media_remove_intf_links(struct media_interface *intf);
> +void media_remove_intf_links(struct media_interface *intf);
> +
>  
>  #define media_entity_call(entity, operation, args...)			\
>  	(((entity)->ops && (entity)->ops->operation) ?			\
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 48/55] [media] media_device: add a topology version field
  2015-08-31 12:29   ` Hans Verkuil
@ 2015-08-31 12:52     ` Mauro Carvalho Chehab
  2015-08-31 13:35       ` Hans Verkuil
  2015-11-23 22:20     ` Laurent Pinchart
  1 sibling, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-31 12:52 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Em Mon, 31 Aug 2015 14:29:28 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> > Every time a graph object is added or removed, the version
> > of the topology changes. That's a requirement for the new
> > MEDIA_IOC_G_TOPOLOGY, in order to allow userspace to know
> > that the topology has changed after a previous call to it.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> I think this should be postponed until we actually have dynamic reconfigurable
> graphs.

So far, we're using the term "dynamic" to mean partial graph object
removal.

But even today, MC does support "dynamic" in the sense of graph
object additions.

You should notice that having a topology_version is something that
IMHO, it is needed since the beginning, even without dynamic
reconfigurable graphs, because the graph may grow in runtime.

That will happen, for example, if usb-snd-audio is blacklisted
at /etc/modprobe*, and someone connects an au0828.

New entities/links will be created (after Shuah patches) if one would
modprobe latter snd-usb-audio.

> 
> I would also like to reserve version 0: if 0 is returned, then the graph is
> static.

Why? Implementing this would be really hard, as that would mean that
G_TOPOLOGY would need to be blocked until all drivers and subdevices
get probed.

In order to implement that, some logic would be needed at the drivers
to identify if everything was set and unlock G_TOPOLOGY.

What would be the gain for that? I fail to see any.

On the other hand, the patch below offers a simple way to detect if topology
changes, as, no matter if an object was added or removed, the topology
version will be increased.

Btw, I added a logic at the mc_nextgen_test program to identify if the
topology changes between the two calls:
	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c?h=mc-next-gen&id=fdc16ece9732c94cfa76eee86978158c5976c00a#n504

Regards,
Mauro

> 
> In G_TOPOLOGY we'd return always 0 for now.
> 
> Regards,
> 
> 	Hans
> 
> > 
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index c89f51bc688d..c18f4af52771 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -185,6 +185,9 @@ void media_gobj_init(struct media_device *mdev,
> >  		list_add_tail(&gobj->list, &mdev->interfaces);
> >  		break;
> >  	}
> > +
> > +	mdev->topology_version++;
> > +
> >  	dev_dbg_obj(__func__, gobj);
> >  }
> >  
> > @@ -199,6 +202,8 @@ void media_gobj_remove(struct media_gobj *gobj)
> >  {
> >  	dev_dbg_obj(__func__, gobj);
> >  
> > +	gobj->mdev->topology_version++;
> > +
> >  	/* Remove the object from mdev list */
> >  	list_del(&gobj->list);
> >  }
> > diff --git a/include/media/media-device.h b/include/media/media-device.h
> > index 0d1b9c687454..1b12774a9ab4 100644
> > --- a/include/media/media-device.h
> > +++ b/include/media/media-device.h
> > @@ -41,6 +41,8 @@ struct device;
> >   * @bus_info:	Unique and stable device location identifier
> >   * @hw_revision: Hardware device revision
> >   * @driver_version: Device driver version
> > + * @topology_version: Monotonic counter for storing the version of the graph
> > + *		topology. Should be incremented each time the topology changes.
> >   * @entity_id:	Unique ID used on the last entity registered
> >   * @pad_id:	Unique ID used on the last pad registered
> >   * @link_id:	Unique ID used on the last link registered
> > @@ -74,6 +76,8 @@ struct media_device {
> >  	u32 hw_revision;
> >  	u32 driver_version;
> >  
> > +	u32 topology_version;
> > +
> >  	u32 entity_id;
> >  	u32 pad_id;
> >  	u32 link_id;
> > 
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 51/55] [media] remove interface links at media_entity_unregister()
  2015-08-30  3:07 ` [PATCH v8 51/55] [media] remove interface links at media_entity_unregister() Mauro Carvalho Chehab
@ 2015-08-31 12:53   ` Hans Verkuil
  2015-08-31 13:42     ` Mauro Carvalho Chehab
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 12:53 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:07 AM, Mauro Carvalho Chehab wrote:
> Interface links connected to an entity should be removed
> before being able of removing the entity.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index a91e1ec076a6..638c682b79c4 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -618,14 +618,30 @@ void media_device_unregister_entity(struct media_entity *entity)
>  		return;
>  
>  	spin_lock(&mdev->lock);
> +
> +	/* Remove interface links with this entity on it */
> +	list_for_each_entry_safe(link, tmp, &mdev->links, graph_obj.list) {
> +		if (media_type(link->gobj1) == MEDIA_GRAPH_ENTITY
> +		    && link->entity == entity) {

I don't think you need the == MEDIA_GRAPH_ENTITY check here. That should always be
true if link->entity == entity.

> +			media_gobj_remove(&link->graph_obj);
> +			kfree(link);
> +		}
> +	}
> +
> +	/* Remove all data links that belong to this entity */
>  	list_for_each_entry_safe(link, tmp, &entity->links, list) {
>  		media_gobj_remove(&link->graph_obj);
>  		list_del(&link->list);
>  		kfree(link);
>  	}
> +
> +	/* Remove all pads that belong to this entity */
>  	for (i = 0; i < entity->num_pads; i++)
>  		media_gobj_remove(&entity->pads[i].graph_obj);
> +
> +	/* Remove the entity */
>  	media_gobj_remove(&entity->graph_obj);
> +
>  	spin_unlock(&mdev->lock);
>  	entity->graph_obj.mdev = NULL;
>  }
> 

Regards,

	Hans

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 52/55] [media] media-device: remove interfaces and interface links
  2015-08-30  3:07 ` [PATCH v8 52/55] [media] media-device: remove interfaces and interface links Mauro Carvalho Chehab
@ 2015-08-31 12:57   ` Hans Verkuil
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 12:57 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/30/2015 05:07 AM, Mauro Carvalho Chehab wrote:
> Just like what's done with entities, when the media controller is
> unregistered, release and interface and interface links that

s/release and/release any/

> might still be there.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 638c682b79c4..2c16a46ea530 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -554,6 +554,22 @@ void media_device_unregister(struct media_device *mdev)
>  {
>  	struct media_entity *entity;
>  	struct media_entity *next;
> +	struct media_link *link, *tmp_link;
> +	struct media_interface *intf, *tmp_intf;
> +
> +	/* Remove interface links from the media device */
> +	list_for_each_entry_safe(link, tmp_link, &mdev->links,
> +				 graph_obj.list) {
> +		media_gobj_remove(&link->graph_obj);
> +		kfree(link);
> +	}
> +
> +	/* Remove all interfaces from the media device */
> +	list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces,
> +				 graph_obj.list) {
> +		media_gobj_remove(&intf->graph_obj);
> +		kfree(intf);
> +	}
>  
>  	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
>  		media_device_unregister_entity(entity);
> @@ -631,7 +647,6 @@ void media_device_unregister_entity(struct media_entity *entity)
>  	/* Remove all data links that belong to this entity */
>  	list_for_each_entry_safe(link, tmp, &entity->links, list) {
>  		media_gobj_remove(&link->graph_obj);
> -		list_del(&link->list);
>  		kfree(link);
>  	}
>  
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 96303a0ade59..1cdda9cb0512 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -206,6 +206,10 @@ void media_gobj_remove(struct media_gobj *gobj)
>  
>  	/* Remove the object from mdev list */
>  	list_del(&gobj->list);
> +
> +	/* Links have their own list - we need to drop them there too */
> +	if (media_type(gobj) == MEDIA_GRAPH_LINK)
> +		list_del(&gobj_to_link(gobj)->list);
>  }
>  
>  /**
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 0e7e193a6736..7fd6265f0bcb 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -153,7 +153,7 @@ struct media_entity {
>  };
>  
>  /**
> - * struct media_intf_devnode - Define a Kernel API interface
> + * struct media_interface - Define a Kernel API interface
>   *
>   * @graph_obj:		embedded graph object
>   * @list:		Linked list used to find other interfaces that belong
> @@ -163,6 +163,11 @@ struct media_entity {
>   *			uapi/media/media.h header, e. g.
>   *			MEDIA_INTF_T_*
>   * @flags:		Interface flags as defined at uapi/media/media.h
> + *
> + * NOTE: As media_device_unregister() will free the address of the
> + *	 media_interface, this structure should be embedded as the first
> + *	 element of the derivated functions, in order for the address to be

s/derivated/derived/

> + *	 the same.
>   */
>  struct media_interface {
>  	struct media_gobj		graph_obj;
> @@ -179,11 +184,11 @@ struct media_interface {
>   * @minor:	Minor number of a device node
>   */
>  struct media_intf_devnode {
> -	struct media_interface		intf;
> +	struct media_interface	intf; /* must be first field in struct */
>  
>  	/* Should match the fields at media_v2_intf_devnode */
> -	u32				major;
> -	u32				minor;
> +	u32			major;
> +	u32			minor;
>  };
>  
>  static inline u32 media_entity_id(struct media_entity *entity)
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA
  2015-08-31 11:31   ` Hans Verkuil
  2015-08-31 11:40     ` Hans Verkuil
@ 2015-08-31 13:08     ` Mauro Carvalho Chehab
  2015-08-31 13:46       ` Hans Verkuil
  1 sibling, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-31 13:08 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Em Mon, 31 Aug 2015 13:31:32 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> > As we'll be removing entity subtypes from the Kernel, we need
> > to provide a way for drivers and core to check if a given
> > entity is represented by a V4L2 subdev or if it is an V4L2
> > I/O entity (typically with DMA).
> 
> This needs more discussion. The plan (as I understand it) is to have properties
> that describe the entity's functionalities.
> 
> The existing entity subtypes will exist only as backwards compat types, but in
> the future properties should be used to describe the functionalities.
> 
> This raises the question if we shouldn't use MEDIA_ENT_T_V4L2_SUBDEV to tell
> userspace that this is a subdev-controlled entity, and let userspace look at
> the properties to figure out what it is exactly?
> 
> It could be that this is a transitional patch, and this will be fixed later.
> If so, this should be mentioned in the commit message.

There are several different issues here:

1) drivers should not rely on type/subtype at MEDIA_ENT_T_*, as we need
   to get rid of it, as this got deprecated;

2) Keep backward compatibility.

3) the addition of properties;

The next patch on this series addresses (1) and (2), and this change is
needed for them.

We can't tell if this is a transitional patch or not, as we don't have
yet any idea about how (3) will be added. Maybe it will preserve
entity->type. Maybe it will convert it into an array. Maybe it would
do something different.

In any case, whatever the property patches will be doing, after this
patch, it will need to touch only at the implementation of the two
macros, not needing to touch at the drivers again.

What I can do is to tell at the description that this patch is in
preparation for the removal of media type/subtype concept that will 
happen on the next patches, but this is what's described there already
at:
	"As we'll be removing entity subtypes from the Kernel,"

Perhaps I should let it clearer there.

Regards,
Mauro

> 
> Regards,
> 
> 	Hans
> 
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index e7b20bdc735d..b0cfbc0dffc7 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -220,6 +220,39 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
> >  	return id;
> >  }
> >  
> > +static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
> > +{
> > +	if (!entity)
> > +		return false;
> > +
> > +	switch (entity->type) {
> > +	case MEDIA_ENT_T_V4L2_VIDEO:
> > +	case MEDIA_ENT_T_V4L2_VBI:
> > +	case MEDIA_ENT_T_V4L2_SWRADIO:
> > +		return true;
> > +	default:
> > +		return false;
> > +	}
> > +}
> > +
> > +static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
> > +{
> > +	if (!entity)
> > +		return false;
> > +
> > +	switch (entity->type) {
> > +	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
> > +	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
> > +	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
> > +	case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
> > +	case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
> > +		return true;
> > +
> > +	default:
> > +		return false;
> > +	}
> > +}
> > +
> >  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
> >  #define MEDIA_ENTITY_ENUM_MAX_ID	64
> >  
> > 
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes
  2015-08-30  3:07 ` [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes Mauro Carvalho Chehab
@ 2015-08-31 13:23   ` Hans Verkuil
  2015-09-04 16:13     ` Mauro Carvalho Chehab
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 13:23 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Sakari Ailus

On 08/30/2015 05:07 AM, Mauro Carvalho Chehab wrote:
> V4L2 device (and subdevice) nodes should create an
> interface, if the Media Controller support is enabled.
> 
> Please notice that radio devices should not create an
> entity, as radio input/output is either via wires or
> via ALSA.

A general note: I think this patch (and any prerequisite patches) should come before
the patches adding G_TOPOLOGY support.

What the G_TOPOLOGY ioctl returns only makes sense IMHO if this code is present as well,
so it is a more logical order for this patch series.

In addition, since G_TOPOLOGY is a userspace API it is likely that that will create
more discussions, whereas this is internal to the kernel and could be merged before
G_TOPOLOGY.

> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
> index 44b330589787..427a5a32b3de 100644
> --- a/drivers/media/v4l2-core/v4l2-dev.c
> +++ b/drivers/media/v4l2-core/v4l2-dev.c
> @@ -194,9 +194,12 @@ static void v4l2_device_release(struct device *cd)
>  	mutex_unlock(&videodev_lock);
>  
>  #if defined(CONFIG_MEDIA_CONTROLLER)
> -	if (v4l2_dev->mdev &&
> -	    vdev->vfl_type != VFL_TYPE_SUBDEV)
> -		media_device_unregister_entity(&vdev->entity);
> +	if (v4l2_dev->mdev) {
> +		/* Remove interfaces and interface links */
> +		media_devnode_remove(vdev->intf_devnode);
> +		if (vdev->vfl_type != VFL_TYPE_SUBDEV)
> +			media_device_unregister_entity(&vdev->entity);

RADIO doesn't have an entity either, so this should probably check for both
SUBDEV and RADIO.

I think it is cleaner if video_register_media_controller() sets a new video_device
flag: V4L2_FL_CREATED_ENTITY, and if this release function would just check the
flag.

> +	}
>  #endif
>  
>  	/* Do not call v4l2_device_put if there is no release callback set.
> @@ -713,6 +716,85 @@ static void determine_valid_ioctls(struct video_device *vdev)
>  			BASE_VIDIOC_PRIVATE);
>  }
>  
> +
> +static int video_register_media_controller(struct video_device *vdev, int type)
> +{
> +#if defined(CONFIG_MEDIA_CONTROLLER)
> +	u32 entity_type = MEDIA_ENT_T_UNKNOWN;
> +	u32 intf_type;
> +	int ret;
> +	bool create_entity = true;
> +
> +	if (!vdev->v4l2_dev->mdev)
> +		return 0;
> +
> +	switch (type) {
> +	case VFL_TYPE_GRABBER:
> +		intf_type = MEDIA_INTF_T_V4L_VIDEO;
> +		entity_type = MEDIA_ENT_T_V4L2_VIDEO;
> +		break;
> +	case VFL_TYPE_VBI:
> +		intf_type = MEDIA_INTF_T_V4L_VBI;
> +		entity_type = MEDIA_ENT_T_V4L2_VBI;
> +		break;
> +	case VFL_TYPE_SDR:
> +		intf_type = MEDIA_INTF_T_V4L_SWRADIO;
> +		entity_type = MEDIA_ENT_T_V4L2_SWRADIO;
> +		break;
> +	case VFL_TYPE_RADIO:
> +		intf_type = MEDIA_INTF_T_V4L_RADIO;
> +		/*
> +		 * Radio doesn't have an entity at the V4L2 side to represent
> +		 * radio input or output. Instead, the audio input/output goes
> +		 * via either physical wires or ALSA.
> +		 */
> +		create_entity = false;
> +		break;
> +	case VFL_TYPE_SUBDEV:
> +		intf_type = MEDIA_INTF_T_V4L_SUBDEV;
> +		/* Entity will be created via v4l2_device_register_subdev() */
> +		create_entity = false;
> +		break;
> +	default:
> +		return 0;
> +	}
> +
> +	if (create_entity) {
> +		vdev->entity.type = entity_type;
> +		vdev->entity.name = vdev->name;
> +
> +		/* Needed just for backward compatibility with legacy MC API */
> +		vdev->entity.info.dev.major = VIDEO_MAJOR;
> +		vdev->entity.info.dev.minor = vdev->minor;
> +
> +		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
> +						   &vdev->entity);
> +		if (ret < 0) {
> +			printk(KERN_WARNING
> +				"%s: media_device_register_entity failed\n",
> +				__func__);
> +			return ret;
> +		}
> +	}
> +
> +	vdev->intf_devnode = media_devnode_create(vdev->v4l2_dev->mdev,
> +						  intf_type,
> +						  0, VIDEO_MAJOR,
> +						  vdev->minor,
> +						  GFP_KERNEL);
> +	if (!vdev->intf_devnode)
> +		return -ENOMEM;
> +
> +	if (create_entity)
> +		media_create_intf_link(&vdev->entity,
> +				       &vdev->intf_devnode->intf, 0);

You need a NULL pointer check here as well. It might be a good idea to add
__must_check to the media_create_intf_link() prototype. I think there are
more places where this isn't checked.

> +
> +	/* FIXME: how to create the other interface links? */
> +
> +#endif
> +	return 0;
> +}
> +
>  /**
>   *	__video_register_device - register video4linux devices
>   *	@vdev: video device structure we want to register
> @@ -908,22 +990,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
>  	/* Increase v4l2_device refcount */
>  	v4l2_device_get(vdev->v4l2_dev);
>  
> -#if defined(CONFIG_MEDIA_CONTROLLER)
>  	/* Part 5: Register the entity. */
> -	if (vdev->v4l2_dev->mdev &&
> -	    vdev->vfl_type != VFL_TYPE_SUBDEV) {
> -		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
> -		vdev->entity.name = vdev->name;
> -		vdev->entity.info.dev.major = VIDEO_MAJOR;
> -		vdev->entity.info.dev.minor = vdev->minor;
> -		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
> -			&vdev->entity);
> -		if (ret < 0)
> -			printk(KERN_WARNING
> -			       "%s: media_device_register_entity failed\n",
> -			       __func__);
> -	}
> -#endif
> +	ret = video_register_media_controller(vdev, type);
> +
>  	/* Part 6: Activate this minor. The char device can now be used. */
>  	set_bit(V4L2_FL_REGISTERED, &vdev->flags);
>  
> diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
> index 5b0a30b9252b..17ec73b1796e 100644
> --- a/drivers/media/v4l2-core/v4l2-device.c
> +++ b/drivers/media/v4l2-core/v4l2-device.c
> @@ -249,6 +249,11 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
>  #if defined(CONFIG_MEDIA_CONTROLLER)
>  		sd->entity.info.dev.major = VIDEO_MAJOR;
>  		sd->entity.info.dev.minor = vdev->minor;
> +
> +		/* Interface is created by __video_register_device() */
> +		if (vdev->v4l2_dev->mdev)
> +			media_create_intf_link(&sd->entity,
> +					       &vdev->intf_devnode->intf, 0);
>  #endif
>  		sd->devnode = vdev;
>  	}
> @@ -285,7 +290,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
>  
>  #if defined(CONFIG_MEDIA_CONTROLLER)
>  	if (v4l2_dev->mdev) {
> -		media_entity_remove_links(&sd->entity);
> +		/*
> +		 * No need to explicitly remove links, as both pads and
> +		 * links are removed by the function below, at the right order

s/, at/ in/

> +		 */
>  		media_device_unregister_entity(&sd->entity);
>  	}
>  #endif
> diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
> index acbcd2f5fe7f..eeabf20e87a6 100644
> --- a/include/media/v4l2-dev.h
> +++ b/include/media/v4l2-dev.h
> @@ -86,6 +86,7 @@ struct video_device
>  {
>  #if defined(CONFIG_MEDIA_CONTROLLER)
>  	struct media_entity entity;
> +	struct media_intf_devnode *intf_devnode;
>  #endif
>  	/* device ops */
>  	const struct v4l2_file_operations *fops;
> 

Regards,

	Hans

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 54/55] [media] au0828: unregister MC at the end
  2015-08-30  3:07 ` [PATCH v8 54/55] [media] au0828: unregister MC at the end Mauro Carvalho Chehab
@ 2015-08-31 13:25   ` Hans Verkuil
  2015-09-04 22:24     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 13:25 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Rafael Lourenço de Lima Chehab,
	Hans Verkuil, Shuah Khan

On 08/30/2015 05:07 AM, Mauro Carvalho Chehab wrote:
> au0828_analog_unregister() calls video_unregister_device(),
> with, in turn, calls media_devnode_remove() in order to drop
> the media interfaces.
> 
> We can't release the media controller before that, or an
> OOPS will occur:

So this patch should be moved to a place earlier in the patch series,
right? To prevent bisects that hit this bug.

Regards,

	Hans

> 
> [  176.938752] usb 1-4.4: Media device released
> [  176.938753] usb 1-4.4: Media device unregistered
> [  177.091235] general protection fault: 0000 [#1] SMP
> [  177.091253] Modules linked in: ir_lirc_codec ir_xmp_decoder lirc_dev ir_mce_kbd_decoder ir_sharp_decoder ir_sanyo_decoder ir_sony_decoder ir_jvc_decoder ir_rc6_decoder ir_nec_decoder ir_rc5_decoder au8522_dig xc5000 tuner au8522_decoder au8522_common au0828(-) videobuf2_vmalloc videobuf2_memops tveeprom videobuf2_core dvb_core rc_core v4l2_common videodev media cpufreq_powersave cpufreq_conservative cpufreq_userspace cpufreq_stats parport_pc ppdev lp parport snd_hda_codec_hdmi i915 x86_pkg_temp_thermal intel_powerclamp intel_rapl iosf_mbi coretemp kvm_intel kvm btusb crct10dif_pclmul snd_hda_codec_realtek crc32_pclmul btrtl crc32c_intel btbcm snd_hda_codec_generic ghash_clmulni_intel btintel i2c_algo_bit drm_kms_helper bluetooth iTCO_wdt snd_usb_audio snd_hda_intel iTCO_vendor_support jitterentropy_rng
> [  177.091455]  snd_hda_codec evdev sha256_ssse3 drm sha256_generic hmac snd_usbmidi_lib snd_hwdep snd_hda_core snd_rawmidi drbg snd_seq_device snd_pcm aesni_intel aes_x86_64 lrw gf128mul mei_me glue_helper snd_timer ablk_helper cryptd mei rfkill snd psmouse sg shpchp soundcore lpc_ich serio_raw i2c_i801 pcspkr mfd_core tpm_tis tpm battery dw_dmac video i2c_designware_platform dw_dmac_core i2c_designware_core acpi_pad processor button ext4 crc16 mbcache jbd2 dm_mod sd_mod ahci libahci libata e1000e scsi_mod ptp pps_core ehci_pci xhci_pci ehci_hcd xhci_hcd thermal fan thermal_sys sdhci_acpi sdhci mmc_core i2c_hid hid [last unloaded: rc_core]
> [  177.091632] CPU: 1 PID: 18040 Comm: rmmod Tainted: G        W       4.2.0-rc2+ #9
> [  177.091648] Hardware name: \xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff \xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff\xffffffff/NUC5i7RYB, BIOS RYBDWi35.86A.0246.2015.0309.1355 03/09/2015
> [  177.091677] task: ffff88040811b080 ti: ffff880036b88000 task.ti: ffff880036b88000
> [  177.091693] RIP: 0010:[<ffffffff810aecc3>]  [<ffffffff810aecc3>] native_queued_spin_lock_slowpath+0x103/0x180
> [  177.091718] RSP: 0018:ffff880036b8bcd8  EFLAGS: 00010202
> [  177.091730] RAX: 0000000000003ffe RBX: ffff880407e11b70 RCX: ffff88041ec962c0
> [  177.091745] RDX: 7463656a62506357 RSI: 0000000000080000 RDI: ffff880407e11b74
> [  177.091760] RBP: ffff880407e11b74 R08: 0000000000000001 R09: ffffffff812bf4e0
> [  177.091776] R10: 0000000000000000 R11: 0000000000000000 R12: ffff88040811b080
> [  177.091791] R13: ffff88003601cec8 R14: ffff8804084b8890 R15: ffff8804084b8800
> [  177.091807] FS:  00007f2f9bab1700(0000) GS:ffff88041ec80000(0000) knlGS:0000000000000000
> [  177.091824] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [  177.091837] CR2: 00007fe8c0f900e0 CR3: 0000000035c47000 CR4: 00000000003407e0
> [  177.091852] Stack:
> [  177.091857]  ffffffff81562e3d ffffffff815613b3 0000000000000000 0000000000000000
> [  177.091876]  ffff88040b6d3240 ffff8804084b8890 ffff880407e11b70 ffff88003601cd30
> [  177.091895]  ffff88003601ce28 ffff88003601cec8 ffff8804084b8890 ffffffff8156148b
> [  177.091914] Call Trace:
> [  177.091923]  [<ffffffff81562e3d>] ? _raw_spin_lock+0x1d/0x20
> [  177.091936]  [<ffffffff815613b3>] ? __mutex_lock_slowpath+0x43/0x100
> [  177.091951]  [<ffffffff8156148b>] ? mutex_lock+0x1b/0x30
> [  177.091965]  [<ffffffffa028480d>] ? media_remove_intf_links+0x1d/0x40 [media]
> [  177.091981]  [<ffffffffa028483e>] ? media_devnode_remove+0xe/0x20 [media]
> [  177.091997]  [<ffffffffa063d875>] ? v4l2_device_release+0x95/0x100 [videodev]
> [  177.092014]  [<ffffffff813ca19d>] ? device_release+0x2d/0x90
> [  177.092028]  [<ffffffff812be5e9>] ? kobject_release+0x79/0x1b0
> [  177.092042]  [<ffffffffa07b19ea>] ? au0828_analog_unregister+0x2a/0x60 [au0828]
> [  177.092059]  [<ffffffffa07ac10e>] ? au0828_usb_disconnect+0x9e/0xd0 [au0828]
> [  177.092075]  [<ffffffff8140e609>] ? usb_unbind_interface+0x79/0x270
> [  177.092090]  [<ffffffff813cf285>] ? __device_release_driver+0x95/0x130
> [  177.092105]  [<ffffffff813cf41b>] ? driver_detach+0xab/0xb0
> [  177.092120]  [<ffffffff813ce4c5>] ? bus_remove_driver+0x55/0xd0
> [  177.092134]  [<ffffffff8140d951>] ? usb_deregister+0x71/0xc0
> [  177.092148]  [<ffffffff810e438a>] ? SyS_delete_module+0x1aa/0x250
> [  177.092163]  [<ffffffff81088ee9>] ? task_work_run+0x89/0xc0
> [  177.092176]  [<ffffffff815631f2>] ? entry_SYSCALL_64_fastpath+0x16/0x75
> [  177.092191] Code: 87 47 02 c1 e0 10 85 c0 74 38 48 89 c2 c1 e8 12 48 c1 ea 0c 83 e8 01 83 e2 30 48 98 48 81 c2 c0 62 01 00 48 03 14 c5 c0 62 90 81 <48> 89 0a 8b 41 08 85 c0 75 0d f3 90 8b 41 08 85 c0 74 f7 eb 02
> [  177.092281] RIP  [<ffffffff810aecc3>] native_queued_spin_lock_slowpath+0x103/0x180
> [  177.092299]  RSP <ffff880036b8bcd8>
> [  177.097721] ---[ end trace b12d5a66f4c6f1c1 ]---
> [  177.243899] lirc_dev: module unloaded
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
> index 7f645bcb7463..e28cabe65934 100644
> --- a/drivers/media/usb/au0828/au0828-core.c
> +++ b/drivers/media/usb/au0828/au0828-core.c
> @@ -175,8 +175,6 @@ static void au0828_usb_disconnect(struct usb_interface *interface)
>  	*/
>  	dev->dev_state = DEV_DISCONNECTED;
>  
> -	au0828_unregister_media_device(dev);
> -
>  	au0828_rc_unregister(dev);
>  	/* Digital TV */
>  	au0828_dvb_unregister(dev);
> @@ -193,6 +191,8 @@ static void au0828_usb_disconnect(struct usb_interface *interface)
>  		return;
>  	}
>  #endif
> +	au0828_unregister_media_device(dev);
> +
>  	au0828_usb_release(dev);
>  }
>  
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
@ 2015-08-31 13:35       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-31 13:35 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-api

Em Mon, 31 Aug 2015 14:00:42 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> > Add a new ioctl that will report the entire topology on
> > one go.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index 756e1960fd7f..358a0c6b1f86 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -181,6 +181,8 @@ struct media_interface {
> >   */
> >  struct media_intf_devnode {
> >  	struct media_interface		intf;
> > +
> > +	/* Should match the fields at media_v2_intf_devnode */
> >  	u32				major;
> >  	u32				minor;
> >  };
> > diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> > index 4186891e5e81..fa0b68e670b0 100644
> > --- a/include/uapi/linux/media.h
> > +++ b/include/uapi/linux/media.h
> > @@ -251,11 +251,94 @@ struct media_links_enum {
> >  #define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
> >  #define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
> >  
> > -/* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
> > +/*
> > + * MC next gen API definitions
> > + *
> > + * NOTE: The declarations below are close to the MC RFC for the Media
> > + *	 Controller, the next generation. Yet, there are a few adjustments
> > + *	 to do, as we want to be able to have a functional API before
> > + *	 the MC properties change. Those will be properly marked below.
> > + *	 Please also notice that I removed "num_pads", "num_links",
> > + *	 from the proposal, as a proper userspace application will likely
> > + *	 use lists for pads/links, just as we intend todo in Kernelspace.
> 
> s/todo/to do/
> 
> > + *	 The API definition should be freed from fields that are bound to
> > + *	 some specific data structure.
> > + *
> > + * FIXME: Currently, I opted to name the new types as "media_v2", as this
> > + *	  won't cause any conflict with the Kernelspace namespace, nor with
> > + *	  the previous kAPI media_*_desc namespace. This can be changed
> > + *	  latter, before the adding this API upstream.
> 
> s/latter/later/ :-)
> 
> I think this comment belongs to the commit log and not in this header.

True, but I opted to keep it here for now to produce some discussions ;)

I'm actually in doubt if we should rename the flags as proposed below,
and use the newer flags only at G_TOPOLOGY or if we should keep the same
namespace for them and accept newer flags with legacy ioctls.

> 
> > + */
> > +
> > +
> > +#define MEDIA_NEW_LNK_FL_ENABLED		MEDIA_LNK_FL_ENABLED
> > +#define MEDIA_NEW_LNK_FL_IMMUTABLE		MEDIA_LNK_FL_IMMUTABLE
> > +#define MEDIA_NEW_LNK_FL_DYNAMIC		MEDIA_NEW_FL_DYNAMIC
> > +#define MEDIA_NEW_LNK_FL_INTERFACE_LINK		(1 << 3)
> 
> Shouldn't this be MEDIA_V2_ instead of MEDIA_NEW_?
> 
> Do we need the INTERFACE_LINK flag? You can deduce it by checking the
> ID type.

Yes, this can be deduced from the type of the objects inside the link.

I guess I added it because of some comment from your media.h RFC
proposal.

Right now, I'm using it at the application to better represent the graph
elements:

	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c?h=mc-next-gen&id=fdc16ece9732c94cfa76eee86978158c5976c00a#n438 
	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c?h=mc-next-gen&id=fdc16ece9732c94cfa76eee86978158c5976c00a#n444

But it could, instead, be doing something like:

	if media_type(link->gobj1.id == MEDIA_GRAPH_PAD)
		link_is_pad = true;
	else
		link_is_pad = false;


Btw, I'm using the same type for both data and interface links, as
I don't see any reason why to differentiate internally: they all share
the same linked list at mdev and the same object ID range.

> 
> I don't have a clear preference one way or another, just wondering about the
> reason for adding it.
> 
> > +
> > +struct media_v2_entity {
> > +	__u32 id;
> > +	char name[64];		/* FIXME: move to a property? (RFC says so) */
> > +	__u16 reserved[14];
> > +};
> > +
> > +/* Should match the specific fields at media_intf_devnode */
> > +struct media_v2_intf_devnode {
> > +	__u32 major;
> > +	__u32 minor;
> > +};
> > +
> > +struct media_v2_interface {
> > +	__u32 id;
> > +	__u32 intf_type;
> > +	__u32 flags;
> > +	__u32 reserved[9];
> > +
> > +	union {
> > +		struct media_v2_intf_devnode devnode;
> > +		__u32 raw[16];
> > +	};
> > +};
> > +
> > +struct media_v2_pad {
> > +	__u32 id;
> > +	__u32 entity_id;
> > +	__u32 flags;
> > +	__u16 reserved[9];
> > +};
> > +
> > +struct media_v2_link {
> > +    __u32 id;
> > +    __u32 source_id;
> > +    __u32 sink_id;
> 
> Like in media_link I would use a union here as well to be able to refer to
> source/sink_id and entity/interface_id.

That would be overkill, and won't help.

Unions make the code harder to read and kernel-doc-nano doesn't like unions
very much.

Ok, there are some cases where it helps, but there's no good reason
for doing it here.

If you don't like the name, let's just rename it to something else.

> 
> > +    __u32 flags;
> > +    __u32 reserved[5];
> > +};
> > +
> > +struct media_v2_topology {
> > +	__u32 topology_version;
> > +
> > +	__u32 num_entities;
> > +	struct media_v2_entity *entities;
> > +
> > +	__u32 num_interfaces;
> > +	struct media_v2_interface *interfaces;
> > +
> > +	__u32 num_pads;
> > +	struct media_v2_pad *pads;
> > +
> > +	__u32 num_links;
> > +	struct media_v2_link *links;
> > +
> > +	__u32 reserved[64];
> 
> As mentioned before: use this instead to prevent horrible 32/64 bit arch
> compat code:
> 
> 	struct {
> 		__u32 reserved_num;
> 		void *reserved_ptr;
> 	} reserved_types[16];
> 	__u32 reserved[8];
> 
> Sizes for these arrays are TBD.

OK. Sorry, I forgot to do this change.

> 
> > +};
> > +
> > +/* ioctls */
> >  
> >  #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
> >  #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct media_entity_desc)
> >  #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
> >  #define MEDIA_IOC_SETUP_LINK		_IOWR('|', 0x03, struct media_link_desc)
> > +#define MEDIA_IOC_G_TOPOLOGY		_IOWR('|', 0x04, struct media_v2_topology)
> >  
> >  #endif /* __LINUX_MEDIA_H */
> > 
> 
> Regards,
> 
> 	Hans
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
@ 2015-08-31 13:35       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-31 13:35 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	linux-api-u79uwXL29TY76Z2rM5mHXA

Em Mon, 31 Aug 2015 14:00:42 +0200
Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org> escreveu:

> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> > Add a new ioctl that will report the entire topology on
> > one go.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>
> > 
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index 756e1960fd7f..358a0c6b1f86 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -181,6 +181,8 @@ struct media_interface {
> >   */
> >  struct media_intf_devnode {
> >  	struct media_interface		intf;
> > +
> > +	/* Should match the fields at media_v2_intf_devnode */
> >  	u32				major;
> >  	u32				minor;
> >  };
> > diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> > index 4186891e5e81..fa0b68e670b0 100644
> > --- a/include/uapi/linux/media.h
> > +++ b/include/uapi/linux/media.h
> > @@ -251,11 +251,94 @@ struct media_links_enum {
> >  #define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
> >  #define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
> >  
> > -/* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
> > +/*
> > + * MC next gen API definitions
> > + *
> > + * NOTE: The declarations below are close to the MC RFC for the Media
> > + *	 Controller, the next generation. Yet, there are a few adjustments
> > + *	 to do, as we want to be able to have a functional API before
> > + *	 the MC properties change. Those will be properly marked below.
> > + *	 Please also notice that I removed "num_pads", "num_links",
> > + *	 from the proposal, as a proper userspace application will likely
> > + *	 use lists for pads/links, just as we intend todo in Kernelspace.
> 
> s/todo/to do/
> 
> > + *	 The API definition should be freed from fields that are bound to
> > + *	 some specific data structure.
> > + *
> > + * FIXME: Currently, I opted to name the new types as "media_v2", as this
> > + *	  won't cause any conflict with the Kernelspace namespace, nor with
> > + *	  the previous kAPI media_*_desc namespace. This can be changed
> > + *	  latter, before the adding this API upstream.
> 
> s/latter/later/ :-)
> 
> I think this comment belongs to the commit log and not in this header.

True, but I opted to keep it here for now to produce some discussions ;)

I'm actually in doubt if we should rename the flags as proposed below,
and use the newer flags only at G_TOPOLOGY or if we should keep the same
namespace for them and accept newer flags with legacy ioctls.

> 
> > + */
> > +
> > +
> > +#define MEDIA_NEW_LNK_FL_ENABLED		MEDIA_LNK_FL_ENABLED
> > +#define MEDIA_NEW_LNK_FL_IMMUTABLE		MEDIA_LNK_FL_IMMUTABLE
> > +#define MEDIA_NEW_LNK_FL_DYNAMIC		MEDIA_NEW_FL_DYNAMIC
> > +#define MEDIA_NEW_LNK_FL_INTERFACE_LINK		(1 << 3)
> 
> Shouldn't this be MEDIA_V2_ instead of MEDIA_NEW_?
> 
> Do we need the INTERFACE_LINK flag? You can deduce it by checking the
> ID type.

Yes, this can be deduced from the type of the objects inside the link.

I guess I added it because of some comment from your media.h RFC
proposal.

Right now, I'm using it at the application to better represent the graph
elements:

	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c?h=mc-next-gen&id=fdc16ece9732c94cfa76eee86978158c5976c00a#n438 
	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c?h=mc-next-gen&id=fdc16ece9732c94cfa76eee86978158c5976c00a#n444

But it could, instead, be doing something like:

	if media_type(link->gobj1.id == MEDIA_GRAPH_PAD)
		link_is_pad = true;
	else
		link_is_pad = false;


Btw, I'm using the same type for both data and interface links, as
I don't see any reason why to differentiate internally: they all share
the same linked list at mdev and the same object ID range.

> 
> I don't have a clear preference one way or another, just wondering about the
> reason for adding it.
> 
> > +
> > +struct media_v2_entity {
> > +	__u32 id;
> > +	char name[64];		/* FIXME: move to a property? (RFC says so) */
> > +	__u16 reserved[14];
> > +};
> > +
> > +/* Should match the specific fields at media_intf_devnode */
> > +struct media_v2_intf_devnode {
> > +	__u32 major;
> > +	__u32 minor;
> > +};
> > +
> > +struct media_v2_interface {
> > +	__u32 id;
> > +	__u32 intf_type;
> > +	__u32 flags;
> > +	__u32 reserved[9];
> > +
> > +	union {
> > +		struct media_v2_intf_devnode devnode;
> > +		__u32 raw[16];
> > +	};
> > +};
> > +
> > +struct media_v2_pad {
> > +	__u32 id;
> > +	__u32 entity_id;
> > +	__u32 flags;
> > +	__u16 reserved[9];
> > +};
> > +
> > +struct media_v2_link {
> > +    __u32 id;
> > +    __u32 source_id;
> > +    __u32 sink_id;
> 
> Like in media_link I would use a union here as well to be able to refer to
> source/sink_id and entity/interface_id.

That would be overkill, and won't help.

Unions make the code harder to read and kernel-doc-nano doesn't like unions
very much.

Ok, there are some cases where it helps, but there's no good reason
for doing it here.

If you don't like the name, let's just rename it to something else.

> 
> > +    __u32 flags;
> > +    __u32 reserved[5];
> > +};
> > +
> > +struct media_v2_topology {
> > +	__u32 topology_version;
> > +
> > +	__u32 num_entities;
> > +	struct media_v2_entity *entities;
> > +
> > +	__u32 num_interfaces;
> > +	struct media_v2_interface *interfaces;
> > +
> > +	__u32 num_pads;
> > +	struct media_v2_pad *pads;
> > +
> > +	__u32 num_links;
> > +	struct media_v2_link *links;
> > +
> > +	__u32 reserved[64];
> 
> As mentioned before: use this instead to prevent horrible 32/64 bit arch
> compat code:
> 
> 	struct {
> 		__u32 reserved_num;
> 		void *reserved_ptr;
> 	} reserved_types[16];
> 	__u32 reserved[8];
> 
> Sizes for these arrays are TBD.

OK. Sorry, I forgot to do this change.

> 
> > +};
> > +
> > +/* ioctls */
> >  
> >  #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
> >  #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct media_entity_desc)
> >  #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
> >  #define MEDIA_IOC_SETUP_LINK		_IOWR('|', 0x03, struct media_link_desc)
> > +#define MEDIA_IOC_G_TOPOLOGY		_IOWR('|', 0x04, struct media_v2_topology)
> >  
> >  #endif /* __LINUX_MEDIA_H */
> > 
> 
> Regards,
> 
> 	Hans
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 48/55] [media] media_device: add a topology version field
  2015-08-31 12:52     ` Mauro Carvalho Chehab
@ 2015-08-31 13:35       ` Hans Verkuil
  2015-09-04 17:08         ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 13:35 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

On 08/31/2015 02:52 PM, Mauro Carvalho Chehab wrote:
> Em Mon, 31 Aug 2015 14:29:28 +0200
> Hans Verkuil <hverkuil@xs4all.nl> escreveu:
> 
>> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
>>> Every time a graph object is added or removed, the version
>>> of the topology changes. That's a requirement for the new
>>> MEDIA_IOC_G_TOPOLOGY, in order to allow userspace to know
>>> that the topology has changed after a previous call to it.
>>>
>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>>
>> I think this should be postponed until we actually have dynamic reconfigurable
>> graphs.
> 
> So far, we're using the term "dynamic" to mean partial graph object
> removal.
> 
> But even today, MC does support "dynamic" in the sense of graph
> object additions.
> 
> You should notice that having a topology_version is something that
> IMHO, it is needed since the beginning, even without dynamic
> reconfigurable graphs, because the graph may grow in runtime.
> 
> That will happen, for example, if usb-snd-audio is blacklisted
> at /etc/modprobe*, and someone connects an au0828.
> 
> New entities/links will be created (after Shuah patches) if one would
> modprobe latter snd-usb-audio.

latter -> later :-)

You are right, this would trigger a topology change. I hadn't thought about
that.

> 
>>
>> I would also like to reserve version 0: if 0 is returned, then the graph is
>> static.
> 
> Why? Implementing this would be really hard, as that would mean that
> G_TOPOLOGY would need to be blocked until all drivers and subdevices
> get probed.
> 
> In order to implement that, some logic would be needed at the drivers
> to identify if everything was set and unlock G_TOPOLOGY.

That wouldn't be needed if the media device node was created last. Which
I think is a good idea anyway.

> 
> What would be the gain for that? I fail to see any.

It would tell userspace that it doesn't have to cope with dynamically
changing graphs.

Even though with the au0828 example you can expect to see cases like that,
I can pretty much guarantee that no generic v4l2 applications will ever
support dynamic changes. Those that will support it will be custom-made.

Being able to see that graphs can change dynamically would allow such apps
to either refuse to use the device, or warn the user.

Regards,

	Hans

> 
> On the other hand, the patch below offers a simple way to detect if topology
> changes, as, no matter if an object was added or removed, the topology
> version will be increased.
> 
> Btw, I added a logic at the mc_nextgen_test program to identify if the
> topology changes between the two calls:
> 	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c?h=mc-next-gen&id=fdc16ece9732c94cfa76eee86978158c5976c00a#n504
> 
> Regards,
> Mauro
> 
>>
>> In G_TOPOLOGY we'd return always 0 for now.
>>
>> Regards,
>>
>> 	Hans
>>
>>>
>>> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
>>> index c89f51bc688d..c18f4af52771 100644
>>> --- a/drivers/media/media-entity.c
>>> +++ b/drivers/media/media-entity.c
>>> @@ -185,6 +185,9 @@ void media_gobj_init(struct media_device *mdev,
>>>  		list_add_tail(&gobj->list, &mdev->interfaces);
>>>  		break;
>>>  	}
>>> +
>>> +	mdev->topology_version++;
>>> +
>>>  	dev_dbg_obj(__func__, gobj);
>>>  }
>>>  
>>> @@ -199,6 +202,8 @@ void media_gobj_remove(struct media_gobj *gobj)
>>>  {
>>>  	dev_dbg_obj(__func__, gobj);
>>>  
>>> +	gobj->mdev->topology_version++;
>>> +
>>>  	/* Remove the object from mdev list */
>>>  	list_del(&gobj->list);
>>>  }
>>> diff --git a/include/media/media-device.h b/include/media/media-device.h
>>> index 0d1b9c687454..1b12774a9ab4 100644
>>> --- a/include/media/media-device.h
>>> +++ b/include/media/media-device.h
>>> @@ -41,6 +41,8 @@ struct device;
>>>   * @bus_info:	Unique and stable device location identifier
>>>   * @hw_revision: Hardware device revision
>>>   * @driver_version: Device driver version
>>> + * @topology_version: Monotonic counter for storing the version of the graph
>>> + *		topology. Should be incremented each time the topology changes.
>>>   * @entity_id:	Unique ID used on the last entity registered
>>>   * @pad_id:	Unique ID used on the last pad registered
>>>   * @link_id:	Unique ID used on the last link registered
>>> @@ -74,6 +76,8 @@ struct media_device {
>>>  	u32 hw_revision;
>>>  	u32 driver_version;
>>>  
>>> +	u32 topology_version;
>>> +
>>>  	u32 entity_id;
>>>  	u32 pad_id;
>>>  	u32 link_id;
>>>
>>


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-08-31 12:47   ` Hans Verkuil
@ 2015-08-31 13:40     ` Mauro Carvalho Chehab
  2015-08-31 13:48       ` Hans Verkuil
  0 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-31 13:40 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Em Mon, 31 Aug 2015 14:47:03 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 08/30/2015 05:07 AM, Mauro Carvalho Chehab wrote:
> > Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
> > with the RFC for the MC next generation.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index 5b2c9f7fcd45..a91e1ec076a6 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -232,6 +232,136 @@ static long media_device_setup_link(struct media_device *mdev,
> >  	return ret;
> >  }
> >  
> > +static long __media_device_get_topology(struct media_device *mdev,
> > +				      struct media_v2_topology *topo)
> > +{
> > +	struct media_entity *entity;
> > +	struct media_interface *intf;
> > +	struct media_pad *pad;
> > +	struct media_link *link;
> > +	struct media_v2_entity uentity;
> > +	struct media_v2_interface uintf;
> > +	struct media_v2_pad upad;
> > +	struct media_v2_link ulink;
> > +	int ret = 0, i;
> > +
> > +	topo->topology_version = mdev->topology_version;
> > +
> > +	/* Get entities and number of entities */
> > +	i = 0;
> > +	media_device_for_each_entity(entity, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->entities)
> > +			continue;
> 
> I would add:
> 
> 		if (i > topo->num_entities)
> 			continue;
> 
> The copy_to_user can succeed, even if i > num_entities depending on how the
> memory was allocated. So I would always check num_entities and refuse to go
> beyond it.

I think that the best is:

	if (i > topo->num_entities) {
		ret = -ENOSPC;
		continue;
	}

> 
> > +
> > +		/* Copy fields to userspace struct if not error */
> > +		memset(&uentity, 0, sizeof(uentity));
> > +		uentity.id = entity->graph_obj.id;
> > +		strncpy(uentity.name, entity->name,
> > +			sizeof(uentity.name));
> > +
> > +		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
> > +			ret = -EFAULT;
> 
> I would just return here. If the user gives bogus values for this, then just
> give up.

With the above change, yes, we can just return -EFAULT here.

> 
> > +	}
> > +	topo->num_entities = i;
> 
> What to do if topo->entities != NULL and i > topo->num_entities? Just return 0
> or return ENOSPC? I'm in favor of ENOSPC since a partial topology result is
> useless. But if ENOSPC is returned, then all num_foo values should be updated
> with the current number of elements.
> 
> This behavior would be consistent with e.g. VIDIOC_G_EXT_CTRLS.

Ok. See above.

> > +
> > +	/* Get interfaces and number of interfaces */
> > +	i = 0;
> > +	media_device_for_each_intf(intf, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->interfaces)
> > +			continue;
> > +
> > +		memset(&uintf, 0, sizeof(uintf));
> > +
> > +		/* Copy intf fields to userspace struct */
> > +		uintf.id = intf->graph_obj.id;
> > +		uintf.intf_type = intf->type;
> > +		uintf.flags = intf->flags;
> > +
> > +		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
> > +			struct media_intf_devnode *devnode;
> > +
> > +			devnode = intf_to_devnode(intf);
> > +
> > +			uintf.devnode.major = devnode->major;
> > +			uintf.devnode.minor = devnode->minor;
> > +		}
> > +
> > +		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_interfaces = i;
> > +
> > +	/* Get pads and number of pads */
> > +	i = 0;
> > +	media_device_for_each_pad(pad, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->pads)
> > +			continue;
> > +
> > +		memset(&upad, 0, sizeof(upad));
> > +
> > +		/* Copy pad fields to userspace struct */
> > +		upad.id = pad->graph_obj.id;
> > +		upad.entity_id = pad->entity->graph_obj.id;
> > +		upad.flags = pad->flags;
> > +
> > +		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_pads = i;
> > +
> > +	/* Get links and number of links */
> > +	i = 0;
> > +	media_device_for_each_link(link, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->links)
> > +			continue;
> > +
> > +		memset(&ulink, 0, sizeof(ulink));
> > +
> > +		/* Copy link fields to userspace struct */
> > +		ulink.id = link->graph_obj.id;
> > +		ulink.source_id = link->gobj0->id;
> > +		ulink.sink_id = link->gobj1->id;
> > +		ulink.flags = link->flags;
> > +
> > +		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
> > +			ulink.flags |= MEDIA_NEW_LNK_FL_INTERFACE_LINK;
> > +
> > +		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_links = i;
> > +
> > +	return ret;
> > +}
> > +
> > +static long media_device_get_topology(struct media_device *mdev,
> > +				      struct media_v2_topology __user *utopo)
> > +{
> > +	struct media_v2_topology ktopo;
> > +	int ret;
> > +
> > +	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
> > +
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	ret = __media_device_get_topology(mdev, &ktopo);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));
> > +
> > +	return ret;
> > +}
> > +
> >  static long media_device_ioctl(struct file *filp, unsigned int cmd,
> >  			       unsigned long arg)
> >  {
> > @@ -264,6 +394,13 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
> >  		mutex_unlock(&dev->graph_mutex);
> >  		break;
> >  
> > +	case MEDIA_IOC_G_TOPOLOGY:
> > +		mutex_lock(&dev->graph_mutex);
> > +		ret = media_device_get_topology(dev,
> > +				(struct media_v2_topology __user *)arg);
> > +		mutex_unlock(&dev->graph_mutex);
> > +		break;
> > +
> >  	default:
> >  		ret = -ENOIOCTLCMD;
> >  	}
> > @@ -312,6 +449,7 @@ static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
> >  	case MEDIA_IOC_DEVICE_INFO:
> >  	case MEDIA_IOC_ENUM_ENTITIES:
> >  	case MEDIA_IOC_SETUP_LINK:
> > +	case MEDIA_IOC_G_TOPOLOGY:
> >  		return media_device_ioctl(filp, cmd, arg);
> >  
> >  	case MEDIA_IOC_ENUM_LINKS32:
> > 
> 
> Note that this will need compat32 code eventually. Should probably be added to the
> todo list in the cover letter.

Ok.

> 
> Regards,
> 
> 	Hans
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 51/55] [media] remove interface links at media_entity_unregister()
  2015-08-31 12:53   ` Hans Verkuil
@ 2015-08-31 13:42     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-31 13:42 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Em Mon, 31 Aug 2015 14:53:45 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 08/30/2015 05:07 AM, Mauro Carvalho Chehab wrote:
> > Interface links connected to an entity should be removed
> > before being able of removing the entity.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index a91e1ec076a6..638c682b79c4 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -618,14 +618,30 @@ void media_device_unregister_entity(struct media_entity *entity)
> >  		return;
> >  
> >  	spin_lock(&mdev->lock);
> > +
> > +	/* Remove interface links with this entity on it */
> > +	list_for_each_entry_safe(link, tmp, &mdev->links, graph_obj.list) {
> > +		if (media_type(link->gobj1) == MEDIA_GRAPH_ENTITY
> > +		    && link->entity == entity) {
> 
> I don't think you need the == MEDIA_GRAPH_ENTITY check here. That should always be
> true if link->entity == entity.

Yes, I know. Actually, I coded it as just  if (link->entity == entity).
Latter, when reviewing my own patch, I decided to add the extra
check, as it sounded me a little better.

Not sure really what would be the better.

> 
> > +			media_gobj_remove(&link->graph_obj);
> > +			kfree(link);
> > +		}
> > +	}
> > +
> > +	/* Remove all data links that belong to this entity */
> >  	list_for_each_entry_safe(link, tmp, &entity->links, list) {
> >  		media_gobj_remove(&link->graph_obj);
> >  		list_del(&link->list);
> >  		kfree(link);
> >  	}
> > +
> > +	/* Remove all pads that belong to this entity */
> >  	for (i = 0; i < entity->num_pads; i++)
> >  		media_gobj_remove(&entity->pads[i].graph_obj);
> > +
> > +	/* Remove the entity */
> >  	media_gobj_remove(&entity->graph_obj);
> > +
> >  	spin_unlock(&mdev->lock);
> >  	entity->graph_obj.mdev = NULL;
> >  }
> > 
> 
> Regards,
> 
> 	Hans
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA
  2015-08-31 13:08     ` Mauro Carvalho Chehab
@ 2015-08-31 13:46       ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 13:46 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

On 08/31/2015 03:08 PM, Mauro Carvalho Chehab wrote:
> Em Mon, 31 Aug 2015 13:31:32 +0200
> Hans Verkuil <hverkuil@xs4all.nl> escreveu:
> 
>> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
>>> As we'll be removing entity subtypes from the Kernel, we need
>>> to provide a way for drivers and core to check if a given
>>> entity is represented by a V4L2 subdev or if it is an V4L2
>>> I/O entity (typically with DMA).
>>
>> This needs more discussion. The plan (as I understand it) is to have properties
>> that describe the entity's functionalities.
>>
>> The existing entity subtypes will exist only as backwards compat types, but in
>> the future properties should be used to describe the functionalities.
>>
>> This raises the question if we shouldn't use MEDIA_ENT_T_V4L2_SUBDEV to tell
>> userspace that this is a subdev-controlled entity, and let userspace look at
>> the properties to figure out what it is exactly?
>>
>> It could be that this is a transitional patch, and this will be fixed later.
>> If so, this should be mentioned in the commit message.
> 
> There are several different issues here:
> 
> 1) drivers should not rely on type/subtype at MEDIA_ENT_T_*, as we need
>    to get rid of it, as this got deprecated;
> 
> 2) Keep backward compatibility.
> 
> 3) the addition of properties;
> 
> The next patch on this series addresses (1) and (2), and this change is
> needed for them.
> 
> We can't tell if this is a transitional patch or not, as we don't have
> yet any idea about how (3) will be added. Maybe it will preserve
> entity->type. Maybe it will convert it into an array. Maybe it would
> do something different.
> 
> In any case, whatever the property patches will be doing, after this
> patch, it will need to touch only at the implementation of the two
> macros, not needing to touch at the drivers again.
> 
> What I can do is to tell at the description that this patch is in
> preparation for the removal of media type/subtype concept that will 
> happen on the next patches, but this is what's described there already
> at:
> 	"As we'll be removing entity subtypes from the Kernel,"
> 
> Perhaps I should let it clearer there.

Just mention this in the cover letter as part of the todo list.

As long as I know that this might change later depending on how properties
are going to affect this, then that's OK and I can keep it in mind when I
review.

Regards,

	Hans

> 
> Regards,
> Mauro
> 
>>
>> Regards,
>>
>> 	Hans
>>
>>>
>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>>>
>>> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
>>> index e7b20bdc735d..b0cfbc0dffc7 100644
>>> --- a/include/media/media-entity.h
>>> +++ b/include/media/media-entity.h
>>> @@ -220,6 +220,39 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
>>>  	return id;
>>>  }
>>>  
>>> +static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
>>> +{
>>> +	if (!entity)
>>> +		return false;
>>> +
>>> +	switch (entity->type) {
>>> +	case MEDIA_ENT_T_V4L2_VIDEO:
>>> +	case MEDIA_ENT_T_V4L2_VBI:
>>> +	case MEDIA_ENT_T_V4L2_SWRADIO:
>>> +		return true;
>>> +	default:
>>> +		return false;
>>> +	}
>>> +}
>>> +
>>> +static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
>>> +{
>>> +	if (!entity)
>>> +		return false;
>>> +
>>> +	switch (entity->type) {
>>> +	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
>>> +	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
>>> +	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
>>> +	case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
>>> +	case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
>>> +		return true;
>>> +
>>> +	default:
>>> +		return false;
>>> +	}
>>> +}
>>> +
>>>  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
>>>  #define MEDIA_ENTITY_ENUM_MAX_ID	64
>>>  
>>>
>>


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-08-31 13:40     ` Mauro Carvalho Chehab
@ 2015-08-31 13:48       ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-08-31 13:48 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

On 08/31/2015 03:40 PM, Mauro Carvalho Chehab wrote:
> Em Mon, 31 Aug 2015 14:47:03 +0200
> Hans Verkuil <hverkuil@xs4all.nl> escreveu:
> 
>> On 08/30/2015 05:07 AM, Mauro Carvalho Chehab wrote:
>>> Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
>>> with the RFC for the MC next generation.
>>>
>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>>>
>>> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
>>> index 5b2c9f7fcd45..a91e1ec076a6 100644
>>> --- a/drivers/media/media-device.c
>>> +++ b/drivers/media/media-device.c
>>> @@ -232,6 +232,136 @@ static long media_device_setup_link(struct media_device *mdev,
>>>  	return ret;
>>>  }
>>>  
>>> +static long __media_device_get_topology(struct media_device *mdev,
>>> +				      struct media_v2_topology *topo)
>>> +{
>>> +	struct media_entity *entity;
>>> +	struct media_interface *intf;
>>> +	struct media_pad *pad;
>>> +	struct media_link *link;
>>> +	struct media_v2_entity uentity;
>>> +	struct media_v2_interface uintf;
>>> +	struct media_v2_pad upad;
>>> +	struct media_v2_link ulink;
>>> +	int ret = 0, i;
>>> +
>>> +	topo->topology_version = mdev->topology_version;
>>> +
>>> +	/* Get entities and number of entities */
>>> +	i = 0;
>>> +	media_device_for_each_entity(entity, mdev) {
>>> +		i++;
>>> +
>>> +		if (ret || !topo->entities)
>>> +			continue;
>>
>> I would add:
>>
>> 		if (i > topo->num_entities)
>> 			continue;
>>
>> The copy_to_user can succeed, even if i > num_entities depending on how the
>> memory was allocated. So I would always check num_entities and refuse to go
>> beyond it.
> 
> I think that the best is:
> 
> 	if (i > topo->num_entities) {
> 		ret = -ENOSPC;
> 		continue;
> 	}

Agreed.

Regards,

	Hans


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 16/55] [media] media: Don't accept early-created links
  2015-08-31 11:01       ` Hans Verkuil
@ 2015-08-31 14:39         ` Javier Martinez Canillas
  2015-08-31 15:05           ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-08-31 14:39 UTC (permalink / raw)
  To: Hans Verkuil, Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Hello Hans,

On 08/31/2015 01:01 PM, Hans Verkuil wrote:
> On 08/31/2015 12:54 PM, Mauro Carvalho Chehab wrote:
>> Em Mon, 31 Aug 2015 12:30:16 +0200
>> Hans Verkuil <hverkuil@xs4all.nl> escreveu:
>>
>>> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
>>>> Links are graph objects that represent the links of two already
>>>> existing objects in the graph.
>>>>
>>>> While with the current implementation, it is possible to create
>>>> the links earlier, It doesn't make any sense to allow linking
>>>> two objects when they are not both created.
>>>>
>>>> So, remove the code that would be handling those early-created
>>>> links and add a BUG_ON() to ensure that.
>>>>
>>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>>>
>>> The code is OK, so:
>>>
>>> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
>>>
>>> But shouldn't this go *after* the omap3isp fixes? After this patch the
>>> omap3isp will call BUG_ON, and that's not what you want.
>>
>> Yes. I'll change the order on my git tree.
>>
>>> It is also not clear if the omap3isp driver is the only one that has this
>>> 'create link before objects' problem. I would expect that the omap4 staging
>>> driver has the same issue and possibly others as well.
>>>
>>> Did someone look at that?
>>
>> I guess other drivers are doing the same.
>>
>> Javier's planning to review the other platform drivers in order to add the 
>> needed fixes there too, and to do more tests with some other platform
>> drivers that he has hardware for testing.
> 
> OK, good. Just wanted to know that.
>

Yes, the omap4iss driver in staging has a similar logic and thus the
same issues than the omap3isp driver. I'll write patches for this as
well but I don't have an OMAP4 board here so testing is appreciated.

As Mauro mentioned, I was reviewing the others driver that are creating
pad links and found more that are creating links before registering:

drivers/media/usb/uvc
drivers/media/platform/vsp1
drivers/media/i2c/smiapp

I'll try to take care of these too.

The other drivers that are creating pad links are doing the right thing
AFAICT by registering the entity with the media device before.

> Perhaps it is a good idea to add a TODO list to the cover letter. This would
> be one item on that list.
>

A TODO list is a good idea indeed.
 
> Regards,
> 
> 	Hans
> 

Best regards,
-- 
Javier Martinez Canillas
Open Source Group
Samsung Research America

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 16/55] [media] media: Don't accept early-created links
  2015-08-31 14:39         ` Javier Martinez Canillas
@ 2015-08-31 15:05           ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-31 15:05 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: Hans Verkuil, Linux Media Mailing List, Mauro Carvalho Chehab

Em Mon, 31 Aug 2015 16:39:34 +0200
Javier Martinez Canillas <javier@osg.samsung.com> escreveu:

> Hello Hans,
> 
> On 08/31/2015 01:01 PM, Hans Verkuil wrote:
> > On 08/31/2015 12:54 PM, Mauro Carvalho Chehab wrote:
> >> Em Mon, 31 Aug 2015 12:30:16 +0200
> >> Hans Verkuil <hverkuil@xs4all.nl> escreveu:
> >>
> >>> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> >>>> Links are graph objects that represent the links of two already
> >>>> existing objects in the graph.
> >>>>
> >>>> While with the current implementation, it is possible to create
> >>>> the links earlier, It doesn't make any sense to allow linking
> >>>> two objects when they are not both created.
> >>>>
> >>>> So, remove the code that would be handling those early-created
> >>>> links and add a BUG_ON() to ensure that.
> >>>>
> >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> >>>
> >>> The code is OK, so:
> >>>
> >>> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> >>>
> >>> But shouldn't this go *after* the omap3isp fixes? After this patch the
> >>> omap3isp will call BUG_ON, and that's not what you want.
> >>
> >> Yes. I'll change the order on my git tree.
> >>
> >>> It is also not clear if the omap3isp driver is the only one that has this
> >>> 'create link before objects' problem. I would expect that the omap4 staging
> >>> driver has the same issue and possibly others as well.
> >>>
> >>> Did someone look at that?
> >>
> >> I guess other drivers are doing the same.
> >>
> >> Javier's planning to review the other platform drivers in order to add the 
> >> needed fixes there too, and to do more tests with some other platform
> >> drivers that he has hardware for testing.
> > 
> > OK, good. Just wanted to know that.
> >
> 
> Yes, the omap4iss driver in staging has a similar logic and thus the
> same issues than the omap3isp driver. I'll write patches for this as
> well but I don't have an OMAP4 board here so testing is appreciated.

Well, I can try to test it here on my PandaBoard. Not sure if it will work,
as I think that the sensor connector was not properly soldered.

> 
> As Mauro mentioned, I was reviewing the others driver that are creating
> pad links and found more that are creating links before registering:
> 
> drivers/media/usb/uvc
> drivers/media/platform/vsp1
> drivers/media/i2c/smiapp
> 
> I'll try to take care of these too.
> 
> The other drivers that are creating pad links are doing the right thing
> AFAICT by registering the entity with the media device before.
> 
> > Perhaps it is a good idea to add a TODO list to the cover letter. This would
> > be one item on that list.
> >
> 
> A TODO list is a good idea indeed.
>  
> > Regards,
> > 
> > 	Hans
> > 
> 
> Best regards,

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 19/55] [media] media: convert links from array to list
  2015-08-30  3:06 ` [PATCH v8 19/55] [media] media: convert links from array to list Mauro Carvalho Chehab
@ 2015-09-04  8:41   ` Sakari Ailus
  2015-09-04  9:00     ` Hans Verkuil
  2015-09-04 11:28   ` [PATCH v8.1 " Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Sakari Ailus @ 2015-09-04  8:41 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Akihiro Tsukada,
	Stefan Richter, Jonathan Corbet, Tina Ruchandani,
	Antti Palosaari, Dan Carpenter,
	Rafael Lourenço de Lima Chehab, Hans Verkuil, Shuah Khan,
	Prabhakar Lad, Julia Lawall, Markus Elfring, Sakari Ailus,
	Scott Jiang, Boris BREZILLON

Hi Mauro,

On Sun, Aug 30, 2015 at 12:06:30AM -0300, Mauro Carvalho Chehab wrote:
> The entire logic that represent graph links were developed on a
> time where there were no needs to dynamic remove links. So,
> although links are created/removed one by one via some
> functions, they're stored as an array inside the entity struct.
> 
> As the array may grow, there's a logic inside the code that
> checks if the amount of space is not enough to store
> the needed links. If it isn't the core uses krealloc()
> to change the size of the link, with is bad, as it
> leaves the memory fragmented.

The Linux kernel constantly allocates and releases memory for various
reasons. Even the V4L2 IOCTL handler does that when the argument is too
large to fit into the stack-allocated buffer. There's no reason to avoid
allocating and releasing small chunks of memory when hardware configuration
changes.

> 
> So, convert links into a list.

Instead, if you're worried about the time the memory re-allocation takes
that'd be needed to dynamically add a large number of links, I'd just
allocate more memory at a time, say, rounding up to a power of two, and use
vmalloc() instead of kmalloc() when the size grows over one page.

That'd avoid the vast majority of reallocs without wasting much memory: the
granularity of memory allocation is much larger than the size of struct
media_link except in the case of very small link numbers.

The reason I'm proposing this is that linked lists, as you're allocating
them, can end up anywhere in the system memory. Walking over the media graph
is quite a job if you have as many links as in your example, and the
additional cache misses caused by scattering the data structure all over the
system memory will not make the effort smaller.

Adding links dynamically (for a change in hardware topology?) is by far less
performance critical than e.g. starting and stopping streaming or
enumerating the links so the latter should have the priority IMHO.

> 
> Also, currently,  both source and sink entities need the link
> at the graph traversal logic inside media_entity. So there's
> a logic duplicating all links. That makes it to spend
> twice the memory needed. This is not a big deal for today's
> usage, where the number of links are not big.
> 
> Yet, if during the MC workshop discussions, it was said that
> IIO graphs could have up to 4,000 entities. So, we may
> want to remove the duplication on some future. The problem
> is that it would require a separate linked list to store
> the backlinks inside the entity, or to use a more complex
> algorithm to do graph backlink traversal, with is something
> that the current graph traversal inside the core can't cope
> with. So, let's postpone a such change if/when it is actually
> needed.

Would keeping the links in a linked list help with that?

I think this could be done using both the current arrays or linked lists ---
instead of storing links themselves, you'd store pointers to the links
(array or a linked list) which then are stored elsewhere. Helper functions
would be needed to e.g. loop over the links in that case though.

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 19/55] [media] media: convert links from array to list
  2015-09-04  8:41   ` Sakari Ailus
@ 2015-09-04  9:00     ` Hans Verkuil
  2015-09-04 11:10       ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Hans Verkuil @ 2015-09-04  9:00 UTC (permalink / raw)
  To: Sakari Ailus, Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Akihiro Tsukada,
	Stefan Richter, Jonathan Corbet, Tina Ruchandani,
	Antti Palosaari, Dan Carpenter,
	Rafael Lourenço de Lima Chehab, Hans Verkuil, Shuah Khan,
	Prabhakar Lad, Julia Lawall, Markus Elfring, Sakari Ailus,
	Scott Jiang, Boris BREZILLON

On 09/04/2015 10:41 AM, Sakari Ailus wrote:
> Hi Mauro,
> 
> On Sun, Aug 30, 2015 at 12:06:30AM -0300, Mauro Carvalho Chehab wrote:
>> The entire logic that represent graph links were developed on a
>> time where there were no needs to dynamic remove links. So,
>> although links are created/removed one by one via some
>> functions, they're stored as an array inside the entity struct.
>>
>> As the array may grow, there's a logic inside the code that
>> checks if the amount of space is not enough to store
>> the needed links. If it isn't the core uses krealloc()
>> to change the size of the link, with is bad, as it
>> leaves the memory fragmented.
> 
> The Linux kernel constantly allocates and releases memory for various
> reasons. Even the V4L2 IOCTL handler does that when the argument is too
> large to fit into the stack-allocated buffer. There's no reason to avoid
> allocating and releasing small chunks of memory when hardware configuration
> changes.
> 
>>
>> So, convert links into a list.
> 
> Instead, if you're worried about the time the memory re-allocation takes
> that'd be needed to dynamically add a large number of links, I'd just
> allocate more memory at a time, say, rounding up to a power of two, and use
> vmalloc() instead of kmalloc() when the size grows over one page.
> 
> That'd avoid the vast majority of reallocs without wasting much memory: the
> granularity of memory allocation is much larger than the size of struct
> media_link except in the case of very small link numbers.
> 
> The reason I'm proposing this is that linked lists, as you're allocating
> them, can end up anywhere in the system memory. Walking over the media graph
> is quite a job if you have as many links as in your example, and the
> additional cache misses caused by scattering the data structure all over the
> system memory will not make the effort smaller.
> 
> Adding links dynamically (for a change in hardware topology?) is by far less
> performance critical than e.g. starting and stopping streaming or
> enumerating the links so the latter should have the priority IMHO.

You don't do either of these jobs very often either. As I have said before, the
enemy of media drivers is rarely performance but always complexity. Based
on the patches I've seen I agree with Mauro that a linked list is a better
fit and simplifies the code.

If you have *proof* that this hurts performance in certain real-life cases,
then this can always be optimized later.

But unless someone shows me proof that it really hurts performance in realistic
cases, I will always favor simplicity.

In all the time that I have been involved in the media subsystem the only
performance issue I am aware of was that enumerating all the links in the MC
can be too slow due to all the ioctl calls that it takes (vsp driver). This
will be solved with the proposed G_TOPOLOGY ioctl since that returns everything
in a single call (or two calls if you need to know how much memory to allocate
first).

Hmm, actually, I think there is another related issue if you want to enumerate
all combinations of pixelformats, discrete framesizes and framerates. There too
the problem is the number of ioctl calls you have to do. It's never been
important enough to do something about it, though.

Bottom line, always go for simplicity unless you can demonstrate with numbers
that there are real performance issues.

Regards,

	Hans

> 
>>
>> Also, currently,  both source and sink entities need the link
>> at the graph traversal logic inside media_entity. So there's
>> a logic duplicating all links. That makes it to spend
>> twice the memory needed. This is not a big deal for today's
>> usage, where the number of links are not big.
>>
>> Yet, if during the MC workshop discussions, it was said that
>> IIO graphs could have up to 4,000 entities. So, we may
>> want to remove the duplication on some future. The problem
>> is that it would require a separate linked list to store
>> the backlinks inside the entity, or to use a more complex
>> algorithm to do graph backlink traversal, with is something
>> that the current graph traversal inside the core can't cope
>> with. So, let's postpone a such change if/when it is actually
>> needed.
> 
> Would keeping the links in a linked list help with that?
> 
> I think this could be done using both the current arrays or linked lists ---
> instead of storing links themselves, you'd store pointers to the links
> (array or a linked list) which then are stored elsewhere. Helper functions
> would be needed to e.g. loop over the links in that case though.
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 19/55] [media] media: convert links from array to list
  2015-09-04  9:00     ` Hans Verkuil
@ 2015-09-04 11:10       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-04 11:10 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Sakari Ailus, Linux Media Mailing List, Mauro Carvalho Chehab,
	Akihiro Tsukada, Stefan Richter, Jonathan Corbet,
	Tina Ruchandani, Antti Palosaari, Dan Carpenter,
	Rafael Lourenço de Lima Chehab, Hans Verkuil, Shuah Khan,
	Prabhakar Lad, Julia Lawall, Markus Elfring, Sakari Ailus,
	Scott Jiang, Boris BREZILLON

Em Fri, 04 Sep 2015 11:00:38 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 09/04/2015 10:41 AM, Sakari Ailus wrote:
> > Hi Mauro,
> > 
> > On Sun, Aug 30, 2015 at 12:06:30AM -0300, Mauro Carvalho Chehab wrote:
> >> The entire logic that represent graph links were developed on a
> >> time where there were no needs to dynamic remove links. So,
> >> although links are created/removed one by one via some
> >> functions, they're stored as an array inside the entity struct.
> >>
> >> As the array may grow, there's a logic inside the code that
> >> checks if the amount of space is not enough to store
> >> the needed links. If it isn't the core uses krealloc()
> >> to change the size of the link, with is bad, as it
> >> leaves the memory fragmented.
> > 
> > The Linux kernel constantly allocates and releases memory for various
> > reasons. Even the V4L2 IOCTL handler does that when the argument is too
> > large to fit into the stack-allocated buffer. There's no reason to avoid
> > allocating and releasing small chunks of memory when hardware configuration
> > changes.
> > 
> >>
> >> So, convert links into a list.
> > 
> > Instead, if you're worried about the time the memory re-allocation takes
> > that'd be needed to dynamically add a large number of links, I'd just
> > allocate more memory at a time, say, rounding up to a power of two, and use
> > vmalloc() instead of kmalloc() when the size grows over one page.

We had support to allocate more links via that "extra_links" parameter.
This never worked in practice: there was no single client for that.

> > 
> > That'd avoid the vast majority of reallocs without wasting much memory: the
> > granularity of memory allocation is much larger than the size of struct
> > media_link except in the case of very small link numbers.
> > 
> > The reason I'm proposing this is that linked lists, as you're allocating
> > them, can end up anywhere in the system memory. Walking over the media graph
> > is quite a job if you have as many links as in your example, and the
> > additional cache misses caused by scattering the data structure all over the
> > system memory will not make the effort smaller.

First of all, I agree with Hans: the major issues we have is not due
to performance, but due to complexity.

Talking about the graph traversal algorithm, it curently doesn't work
even for simple hybrid TV devices, as it currently allows to have only 64
entities, due to the loop detection code there.

Ok, it would be possible to extend it to support real case scenarios, but
the patch is not as trivial as changing the max number of entities. Just
doing that would cause the stack to crash, as the bitmap structs are 
allocated at the stack.

Also, what you're saying regards to the increase of cache misses,
this is not true. The links memory are still fragmented, as they're
allocated during entities init code. On most codes, that means that
they'll be allocated after each entity.

So, memory would look like:
	entity#1
	links for entity#1
	entity#2
	links for entity#2
...

If you want to put the links at consecutive addresses, what you would
need to do is to create first all entities, and then create the links
altogether. After this patch, drivers that have timing issues can do
it, having the memory allocated as:
	entity#1
	entity#2
	links for entity#1
	links for entity#2
	...

So, I won't doubt that this patch would actually improve performance
by putting the links altogether ;)

Ok, when we have lots of dynamic entity creation/removal, the memory
will become more fragmented, but that would happen with or without
this change.

I mean, if this patch is not applied and entity#2 is created after
a long runtime, we would have:

	entity#1
	links for entity #1

	<some other data allocated>

	entity#2
	links for entity #2

While, on the other case, the memory would be:

	entity#1
	links for entity #1 (except for the link with entity#2)
	backlinks for entity #1 (except for the link with entity#2)

	<some other data allocated>

	entity#2
	link between entity#1 and entity#2
	other links for entity #2

I bet performance would be pretty much the same.

Anyway, let's go to real numbers. Javier ran some tests in order to check
what would be the difference using the omap3isp driver.

He hacked yavta to suppress glibc calls to printf() with this hack:

#define printf(...) do { } while (0)

Then, he measured the times with and without this patch series.
Doing the graph traversal needed for this command:
	$ time ./yavta/yavta -f UYVY -s 720x312 -n 1 --capture=1 -F /dev/video2

Resulted in:
	real	0m0.022s
	user	0m0.000s
	sys	0m0.010s

The complete results form Javier are at:
	http://hastebin.com/turixebuyo.pl

He did that with both with and without this patch series.

On all cases, it took 10ms to setup the pipeline.

> > 
> > Adding links dynamically (for a change in hardware topology?) is by far less
> > performance critical than e.g. starting and stopping streaming or
> > enumerating the links so the latter should have the priority IMHO.
> 
> You don't do either of these jobs very often either. As I have said before, the
> enemy of media drivers is rarely performance but always complexity. Based
> on the patches I've seen I agree with Mauro that a linked list is a better
> fit and simplifies the code.
> 
> If you have *proof* that this hurts performance in certain real-life cases,
> then this can always be optimized later.
> 
> But unless someone shows me proof that it really hurts performance in realistic
> cases, I will always favor simplicity.
> 
> In all the time that I have been involved in the media subsystem the only
> performance issue I am aware of was that enumerating all the links in the MC
> can be too slow due to all the ioctl calls that it takes (vsp driver). This
> will be solved with the proposed G_TOPOLOGY ioctl since that returns everything
> in a single call (or two calls if you need to know how much memory to allocate
> first).

Some timing measurements using au0828 driver:

This is the time mc_nextgen_test takes with a hack that:
	- Reduces the number of demux outputs from 256 to 5;
	- Reduces the number of output ringbuffers from 512 to 10;
	- Adds one subdev for tuner (helps me to test subdevs).

$ time ~/mc_nextgen_test 
version: 97
number of entities: 19
number of interfaces: 7
number of pads: 28
number of links: 25

real	0m0.002s
user	0m0.000s
sys	0m0.000s

The time spent at the Kernel (sys) is less than 1ms. Hardly would cause
any harm.

Btw, that's with the real graph (without a fake subdev for tuner, and
with all ringbuffers mapped):

$ time ~/mc_nextgen_test
version: 2354
number of entities: 521
number of interfaces: 6
number of pads: 781
number of links: 526

real	0m0.002s
user	0m0.000s
sys	0m0.000s

No difference: it still took less than 1 ms.

Ok, this is not graph traversal, but the G_TOPOLOGY should read all
objects that belong to the graph. So, if cache miss would cause any
performance issue, some difference would be noticed here.

Also, please notice that cache misses inside a graph traversal
loop should happen only one for a given memory object, as, the
memory will be cached on the second access to it (provided, of
course, that the amount of memory used to store the links is smaller
than the size of the cache - that should be the case even for graphs
like what we have at au0828 without the hacks).

We might try to use ftrace to measure the time spent in Kernel
to have a better measurement, but I'm afraid that ftrace could
actually mangle the results by causing cache flushes at L1 cache,
due to the long jump to the ftrace event store routine.

> 
> Hmm, actually, I think there is another related issue if you want to enumerate
> all combinations of pixelformats, discrete framesizes and framerates. There too
> the problem is the number of ioctl calls you have to do. It's never been
> important enough to do something about it, though.
> 
> Bottom line, always go for simplicity unless you can demonstrate with numbers
> that there are real performance issues.
> 
> Regards,
> 
> 	Hans
> 
> > 
> >>
> >> Also, currently,  both source and sink entities need the link
> >> at the graph traversal logic inside media_entity. So there's
> >> a logic duplicating all links. That makes it to spend
> >> twice the memory needed. This is not a big deal for today's
> >> usage, where the number of links are not big.
> >>
> >> Yet, if during the MC workshop discussions, it was said that
> >> IIO graphs could have up to 4,000 entities. So, we may
> >> want to remove the duplication on some future. The problem
> >> is that it would require a separate linked list to store
> >> the backlinks inside the entity, or to use a more complex
> >> algorithm to do graph backlink traversal, with is something
> >> that the current graph traversal inside the core can't cope
> >> with. So, let's postpone a such change if/when it is actually
> >> needed.
> > 
> > Would keeping the links in a linked list help with that?

Well, if we reduce the links by half, removing the allocation of
a memory for backlinks, then yes. I was planning to to that, but
this would require a non-trivial change at the graph traversal
algorithm and the usage of a separate linked list for the backlink.

Please notice that, if you're concerned with cache misses, using
half of the memory to store the links/backlinks would actually be
an improvement in terms of performance.

> > 
> > I think this could be done using both the current arrays or linked lists ---
> > instead of storing links themselves, you'd store pointers to the links
> > (array or a linked list) which then are stored elsewhere. Helper functions
> > would be needed to e.g. loop over the links in that case though.
> > 
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH v8.1 19/55] [media] media: convert links from array to list
  2015-08-30  3:06 ` [PATCH v8 19/55] [media] media: convert links from array to list Mauro Carvalho Chehab
  2015-09-04  8:41   ` Sakari Ailus
@ 2015-09-04 11:28   ` Mauro Carvalho Chehab
  2015-09-04 11:48     ` [PATCH v8.2 " Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-04 11:28 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Stefan Richter,
	Akihiro Tsukada, Arnd Bergmann, Tina Ruchandani, Dan Carpenter,
	Antti Palosaari, Rafael Lourenço de Lima Chehab, Shuah Khan,
	Hans Verkuil, Prabhakar Lad, Markus Elfring, Sakari Ailus,
	Laurent Pinchart, Boris BREZILLON

The entire logic that represent graph links were developed on a
time where there were no needs to dynamic remove links. So,
although links are created/removed one by one via some
functions, they're stored as an array inside the entity struct.

As the array may grow, there's a logic inside the code that
checks if the amount of space is not enough to store
the needed links. If it isn't the core uses krealloc()
to change the size of the link, with is bad, as it
leaves the memory fragmented.

So, convert links into a list.

Also, currently,  both source and sink entities need the link
at the graph traversal logic inside media_entity. So there's
a logic duplicating all links. That makes it to spend
twice the memory needed. This is not a big deal for today's
usage, where the number of links are not big.

Yet, if during the MC workshop discussions, it was said that
IIO graphs could have up to 4,000 entities. So, we may
want to remove the duplication on some future. The problem
is that it would require a separate linked list to store
the backlinks inside the entity, or to use a more complex
algorithm to do graph backlink traversal, with is something
that the current graph traversal inside the core can't cope
with. So, let's postpone a such change if/when it is actually
needed.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

---

This version contains a few bug fixes folded on it, resulted
from Javier's tests. I won't be respinning the entire series
just due to that.

Javier: Thanks for that! I'll add you proper credits on
the final version.

diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index c38ef1a72b4a..2d06bcff0946 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -622,7 +622,7 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
 	struct media_device *mdev = adapter->mdev;
 	struct media_entity  *entity, *source;
 	struct media_link *link, *found_link = NULL;
-	int i, ret, n_links = 0, active_links = 0;
+	int ret, n_links = 0, active_links = 0;
 
 	fepriv->pipe_start_entity = NULL;
 
@@ -632,8 +632,7 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
 	entity = fepriv->dvbdev->entity;
 	fepriv->pipe_start_entity = entity;
 
-	for (i = 0; i < entity->num_links; i++) {
-		link = &entity->links[i];
+	list_for_each_entry(link, &entity->links, list) {
 		if (link->sink->entity == entity) {
 			found_link = link;
 			n_links++;
@@ -659,13 +658,11 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
 
 	source = found_link->source->entity;
 	fepriv->pipe_start_entity = source;
-	for (i = 0; i < source->num_links; i++) {
+	list_for_each_entry(link, &source->links, list) {
 		struct media_entity *sink;
 		int flags = 0;
 
-		link = &source->links[i];
 		sink = link->sink->entity;
-
 		if (sink == entity)
 			flags = MEDIA_LNK_FL_ENABLED;
 
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 0d85c6c28004..3e649cacfc07 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -25,6 +25,7 @@
 #include <linux/ioctl.h>
 #include <linux/media.h>
 #include <linux/types.h>
+#include <linux/slab.h>
 
 #include <media/media-device.h>
 #include <media/media-devnode.h>
@@ -150,22 +151,21 @@ static long __media_device_enum_links(struct media_device *mdev,
 	}
 
 	if (links->links) {
-		struct media_link_desc __user *ulink;
-		unsigned int l;
+		struct media_link *ent_link;
+		struct media_link_desc __user *ulink = links->links;
 
-		for (l = 0, ulink = links->links; l < entity->num_links; l++) {
+		list_for_each_entry(ent_link, &entity->links, list) {
 			struct media_link_desc link;
 
 			/* Ignore backlinks. */
-			if (entity->links[l].source->entity != entity)
+			if (ent_link->source->entity != entity)
 				continue;
-
 			memset(&link, 0, sizeof(link));
-			media_device_kpad_to_upad(entity->links[l].source,
+			media_device_kpad_to_upad(ent_link->source,
 						  &link.source);
-			media_device_kpad_to_upad(entity->links[l].sink,
+			media_device_kpad_to_upad(ent_link->sink,
 						  &link.sink);
-			link.flags = entity->links[l].flags;
+			link.flags = ent_link->flags;
 			if (copy_to_user(ulink, &link, sizeof(*ulink)))
 				return -EFAULT;
 			ulink++;
@@ -437,6 +437,7 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	/* Warn if we apparently re-register an entity */
 	WARN_ON(entity->graph_obj.mdev != NULL);
 	entity->graph_obj.mdev = mdev;
+	INIT_LIST_HEAD(&entity->links);
 
 	spin_lock(&mdev->lock);
 	/* Initialize media_gobj embedded at the entity */
@@ -465,13 +466,17 @@ void media_device_unregister_entity(struct media_entity *entity)
 {
 	int i;
 	struct media_device *mdev = entity->graph_obj.mdev;
+	struct media_link *link, *tmp;
 
 	if (mdev == NULL)
 		return;
 
 	spin_lock(&mdev->lock);
-	for (i = 0; i < entity->num_links; i++)
-		media_gobj_remove(&entity->links[i].graph_obj);
+	list_for_each_entry_safe(link, tmp, &entity->links, list) {
+		media_gobj_remove(&link->graph_obj);
+		list_del(&link->list);
+		kfree(link);
+	}
 	for (i = 0; i < entity->num_pads; i++)
 		media_gobj_remove(&entity->pads[i].graph_obj);
 	media_gobj_remove(&entity->graph_obj);
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 9f8e0145db7a..ff63201443d7 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -221,21 +221,13 @@ int
 media_entity_init(struct media_entity *entity, u16 num_pads,
 		  struct media_pad *pads)
 {
-	struct media_link *links;
-	unsigned int max_links = num_pads;
 	unsigned int i;
 
-	links = kzalloc(max_links * sizeof(links[0]), GFP_KERNEL);
-	if (links == NULL)
-		return -ENOMEM;
-
 	entity->group_id = 0;
-	entity->max_links = max_links;
 	entity->num_links = 0;
 	entity->num_backlinks = 0;
 	entity->num_pads = num_pads;
 	entity->pads = pads;
-	entity->links = links;
 
 	for (i = 0; i < num_pads; i++) {
 		pads[i].entity = entity;
@@ -249,7 +241,13 @@ EXPORT_SYMBOL_GPL(media_entity_init);
 void
 media_entity_cleanup(struct media_entity *entity)
 {
-	kfree(entity->links);
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &entity->links, list) {
+		media_gobj_remove(&link->graph_obj);
+		list_del(&link->list);
+		kfree(link);
+	}
 }
 EXPORT_SYMBOL_GPL(media_entity_cleanup);
 
@@ -275,7 +273,7 @@ static void stack_push(struct media_entity_graph *graph,
 		return;
 	}
 	graph->top++;
-	graph->stack[graph->top].link = 0;
+	graph->stack[graph->top].link = entity->links;
 	graph->stack[graph->top].entity = entity;
 }
 
@@ -317,6 +315,7 @@ void media_entity_graph_walk_start(struct media_entity_graph *graph,
 }
 EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
 
+
 /**
  * media_entity_graph_walk_next - Get the next entity in the graph
  * @graph: Media graph structure
@@ -340,14 +339,16 @@ media_entity_graph_walk_next(struct media_entity_graph *graph)
 	 * top of the stack until no more entities on the level can be
 	 * found.
 	 */
-	while (link_top(graph) < stack_top(graph)->num_links) {
+	while (list_is_last(&link_top(graph), &(stack_top(graph)->links))) {
 		struct media_entity *entity = stack_top(graph);
-		struct media_link *link = &entity->links[link_top(graph)];
+		struct media_link *link;
 		struct media_entity *next;
 
+		link = list_last_entry(&link_top(graph), typeof(*link), list);
+
 		/* The link is not enabled so we do not follow. */
 		if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {
-			link_top(graph)++;
+			list_rotate_left(&link_top(graph));
 			continue;
 		}
 
@@ -358,12 +359,12 @@ media_entity_graph_walk_next(struct media_entity_graph *graph)
 
 		/* Has the entity already been visited? */
 		if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
-			link_top(graph)++;
+			list_rotate_left(&link_top(graph));
 			continue;
 		}
 
 		/* Push the new entity to stack and start over. */
-		link_top(graph)++;
+		list_rotate_left(&link_top(graph));
 		stack_push(graph, next);
 	}
 
@@ -395,6 +396,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph graph;
 	struct media_entity *entity_err = entity;
+	struct media_link *link;
 	int ret;
 
 	mutex_lock(&mdev->graph_mutex);
@@ -404,7 +406,6 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		DECLARE_BITMAP(active, entity->num_pads);
 		DECLARE_BITMAP(has_no_links, entity->num_pads);
-		unsigned int i;
 
 		entity->stream_count++;
 		WARN_ON(entity->pipe && entity->pipe != pipe);
@@ -420,8 +421,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 		bitmap_zero(active, entity->num_pads);
 		bitmap_fill(has_no_links, entity->num_pads);
 
-		for (i = 0; i < entity->num_links; i++) {
-			struct media_link *link = &entity->links[i];
+		list_for_each_entry(link, &entity->links, list) {
 			struct media_pad *pad = link->sink->entity == entity
 						? link->sink : link->source;
 
@@ -582,25 +582,20 @@ EXPORT_SYMBOL_GPL(media_entity_put);
 
 static struct media_link *media_entity_add_link(struct media_entity *entity)
 {
-	if (entity->num_links >= entity->max_links) {
-		struct media_link *links = entity->links;
-		unsigned int max_links = entity->max_links + 2;
-		unsigned int i;
+	struct media_link *link;
 
-		links = krealloc(links, max_links * sizeof(*links), GFP_KERNEL);
-		if (links == NULL)
-			return NULL;
+	link = kzalloc(sizeof(*link), GFP_KERNEL);
+	if (link == NULL)
+		return NULL;
 
-		for (i = 0; i < entity->num_links; i++)
-			links[i].reverse->reverse = &links[i];
+	list_add_tail(&link->list, &entity->links);
 
-		entity->max_links = max_links;
-		entity->links = links;
-	}
-
-	return &entity->links[entity->num_links++];
+	return link;
 }
 
+static void __media_entity_remove_link(struct media_entity *entity,
+				       struct media_link *link);
+
 int
 media_create_pad_link(struct media_entity *source, u16 source_pad,
 			 struct media_entity *sink, u16 sink_pad, u32 flags)
@@ -629,7 +624,7 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	 */
 	backlink = media_entity_add_link(sink);
 	if (backlink == NULL) {
-		source->num_links--;
+		__media_entity_remove_link(source, link);
 		return -ENOMEM;
 	}
 
@@ -645,43 +640,51 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	backlink->reverse = link;
 
 	sink->num_backlinks++;
+	sink->num_links++;
+	source->num_links++;
 
 	return 0;
 }
 EXPORT_SYMBOL_GPL(media_create_pad_link);
 
-void __media_entity_remove_links(struct media_entity *entity)
+static void __media_entity_remove_link(struct media_entity *entity,
+				       struct media_link *link)
 {
-	unsigned int i;
+	struct media_link *rlink, *tmp;
+	struct media_entity *remote;
+	unsigned int r = 0;
 
-	for (i = 0; i < entity->num_links; i++) {
-		struct media_link *link = &entity->links[i];
-		struct media_entity *remote;
-		unsigned int r = 0;
+	if (link->source->entity == entity)
+		remote = link->sink->entity;
+	else
+		remote = link->source->entity;
+
+	list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
+		if (rlink != link->reverse) {
+			r++;
+			continue;
+		}
 
 		if (link->source->entity == entity)
-			remote = link->sink->entity;
-		else
-			remote = link->source->entity;
+			remote->num_backlinks--;
 
-		while (r < remote->num_links) {
-			struct media_link *rlink = &remote->links[r];
+		if (--remote->num_links == 0)
+			break;
 
-			if (rlink != link->reverse) {
-				r++;
-				continue;
-			}
-
-			if (link->source->entity == entity)
-				remote->num_backlinks--;
-
-			if (--remote->num_links == 0)
-				break;
-
-			/* Insert last entry in place of the dropped link. */
-			*rlink = remote->links[remote->num_links];
-		}
+		/* Remove the remote link */
+		list_del(&rlink->list);
+		kfree(rlink);
 	}
+	list_del(&link->list);
+	kfree(link);
+}
+
+void __media_entity_remove_links(struct media_entity *entity)
+{
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &entity->links, list)
+		__media_entity_remove_link(entity, link);
 
 	entity->num_links = 0;
 	entity->num_backlinks = 0;
@@ -806,11 +809,8 @@ struct media_link *
 media_entity_find_link(struct media_pad *source, struct media_pad *sink)
 {
 	struct media_link *link;
-	unsigned int i;
-
-	for (i = 0; i < source->entity->num_links; ++i) {
-		link = &source->entity->links[i];
 
+	list_for_each_entry(link, &source->entity->links, list) {
 		if (link->source->entity == source->entity &&
 		    link->source->index == source->index &&
 		    link->sink->entity == sink->entity &&
@@ -834,11 +834,9 @@ EXPORT_SYMBOL_GPL(media_entity_find_link);
  */
 struct media_pad *media_entity_remote_pad(struct media_pad *pad)
 {
-	unsigned int i;
-
-	for (i = 0; i < pad->entity->num_links; i++) {
-		struct media_link *link = &pad->entity->links[i];
+	struct media_link *link;
 
+	list_for_each_entry(link, &pad->entity->links, list) {
 		if (!(link->flags & MEDIA_LNK_FL_ENABLED))
 			continue;
 
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index a55eb524ea21..7f645bcb7463 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -261,13 +261,11 @@ static void au0828_create_media_graph(struct au0828_dev *dev)
 
 	if (tuner)
 		media_create_pad_link(tuner, 0, decoder, 0,
-					 MEDIA_LNK_FL_ENABLED);
-	if (dev->vdev.entity.links)
-		media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
-				 MEDIA_LNK_FL_ENABLED);
-	if (dev->vbi_dev.entity.links)
-		media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
-				 MEDIA_LNK_FL_ENABLED);
+				      MEDIA_LNK_FL_ENABLED);
+	media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
+			      MEDIA_LNK_FL_ENABLED);
+	media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
+			      MEDIA_LNK_FL_ENABLED);
 #endif
 }
 
diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 2c040056d4eb..4511e2893282 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -643,7 +643,7 @@ static int au0828_enable_analog_tuner(struct au0828_dev *dev)
 	struct media_device *mdev = dev->media_dev;
 	struct media_entity *source;
 	struct media_link *link, *found_link = NULL;
-	int i, ret, active_links = 0;
+	int ret, active_links = 0;
 
 	if (!mdev || !dev->decoder)
 		return 0;
@@ -655,8 +655,7 @@ static int au0828_enable_analog_tuner(struct au0828_dev *dev)
 	 * do DVB streaming while the DMA engine is being used for V4L2,
 	 * this should be enough for the actual needs.
 	 */
-	for (i = 0; i < dev->decoder->num_links; i++) {
-		link = &dev->decoder->links[i];
+	list_for_each_entry(link, &dev->decoder->links, list) {
 		if (link->sink->entity == dev->decoder) {
 			found_link = link;
 			if (link->flags & MEDIA_LNK_FL_ENABLED)
@@ -669,11 +668,10 @@ static int au0828_enable_analog_tuner(struct au0828_dev *dev)
 		return 0;
 
 	source = found_link->source->entity;
-	for (i = 0; i < source->num_links; i++) {
+	list_for_each_entry(link, &source->links, list) {
 		struct media_entity *sink;
 		int flags = 0;
 
-		link = &source->links[i];
 		sink = link->sink->entity;
 
 		if (sink == dev->decoder)
diff --git a/drivers/media/usb/cx231xx/cx231xx-video.c b/drivers/media/usb/cx231xx/cx231xx-video.c
index 8f04b125486f..e8baff4d6290 100644
--- a/drivers/media/usb/cx231xx/cx231xx-video.c
+++ b/drivers/media/usb/cx231xx/cx231xx-video.c
@@ -106,7 +106,7 @@ static int cx231xx_enable_analog_tuner(struct cx231xx *dev)
 	struct media_device *mdev = dev->media_dev;
 	struct media_entity  *entity, *decoder = NULL, *source;
 	struct media_link *link, *found_link = NULL;
-	int i, ret, active_links = 0;
+	int ret, active_links = 0;
 
 	if (!mdev)
 		return 0;
@@ -127,8 +127,7 @@ static int cx231xx_enable_analog_tuner(struct cx231xx *dev)
 	if (!decoder)
 		return 0;
 
-	for (i = 0; i < decoder->num_links; i++) {
-		link = &decoder->links[i];
+	list_for_each_entry(link, &decoder->links, list) {
 		if (link->sink->entity == decoder) {
 			found_link = link;
 			if (link->flags & MEDIA_LNK_FL_ENABLED)
@@ -141,11 +140,10 @@ static int cx231xx_enable_analog_tuner(struct cx231xx *dev)
 		return 0;
 
 	source = found_link->source->entity;
-	for (i = 0; i < source->num_links; i++) {
+	list_for_each_entry(link, &source->links, list) {
 		struct media_entity *sink;
 		int flags = 0;
 
-		link = &source->links[i];
 		sink = link->sink->entity;
 
 		if (sink == entity)
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 7df8836f4eef..bb89cedb0c40 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -74,6 +74,7 @@ struct media_pipeline {
 
 struct media_link {
 	struct media_gobj graph_obj;
+	struct list_head list;
 	struct media_pad *source;	/* Source pad */
 	struct media_pad *sink;		/* Sink pad  */
 	struct media_link *reverse;	/* Link in the reverse direction */
@@ -116,10 +117,9 @@ struct media_entity {
 	u16 num_links;			/* Number of existing links, both
 					 * enabled and disabled */
 	u16 num_backlinks;		/* Number of backlinks */
-	u16 max_links;			/* Maximum number of links */
 
-	struct media_pad *pads;		/* Pads array (num_pads elements) */
-	struct media_link *links;	/* Links array (max_links elements)*/
+	struct media_pad *pads;		/* Pads array (num_pads objects) */
+	struct list_head links;		/* Links list */
 
 	const struct media_entity_operations *ops;	/* Entity operations */
 
@@ -213,7 +213,7 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
 struct media_entity_graph {
 	struct {
 		struct media_entity *entity;
-		int link;
+		struct list_head link;
 	} stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
 
 	DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID);
@@ -247,7 +247,7 @@ void media_gobj_init(struct media_device *mdev,
 void media_gobj_remove(struct media_gobj *gobj);
 
 int media_entity_init(struct media_entity *entity, u16 num_pads,
-		struct media_pad *pads);
+		      struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
 
 int media_create_pad_link(struct media_entity *source, u16 source_pad,
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH v8.2 19/55] [media] media: convert links from array to list
  2015-09-04 11:28   ` [PATCH v8.1 " Mauro Carvalho Chehab
@ 2015-09-04 11:48     ` Mauro Carvalho Chehab
  2015-09-06 12:02       ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-04 11:48 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Dan Carpenter,
	Arnd Bergmann, Akihiro Tsukada, Antti Palosaari, Tina Ruchandani,
	Rafael Lourenço de Lima Chehab, Hans Verkuil, Shuah Khan,
	Prabhakar Lad, Markus Elfring, Julia Lawall, Sakari Ailus,
	Laurent Pinchart, Boris BREZILLON

The entire logic that represent graph links were developed on a
time where there were no needs to dynamic remove links. So,
although links are created/removed one by one via some
functions, they're stored as an array inside the entity struct.

As the array may grow, there's a logic inside the code that
checks if the amount of space is not enough to store
the needed links. If it isn't the core uses krealloc()
to change the size of the link, with is bad, as it
leaves the memory fragmented.

So, convert links into a list.

Also, currently,  both source and sink entities need the link
at the graph traversal logic inside media_entity. So there's
a logic duplicating all links. That makes it to spend
twice the memory needed. This is not a big deal for today's
usage, where the number of links are not big.

Yet, if during the MC workshop discussions, it was said that
IIO graphs could have up to 4,000 entities. So, we may
want to remove the duplication on some future. The problem
is that it would require a separate linked list to store
the backlinks inside the entity, or to use a more complex
algorithm to do graph backlink traversal, with is something
that the current graph traversal inside the core can't cope
with. So, let's postpone a such change if/when it is actually
needed.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

---

Sorry, I did some mess with my trees, and just re-sent the same
patch as before. That's the right one with Javier fixes.
Please ignore PATCH v8.1.

This version contains a few bug fixes folded on it, resulted
from Javier's tests. I won't be respinning the entire series
just due to that.

Javier: Thanks for that! I'll add you proper credits on
the final version.

diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index c38ef1a72b4a..2d06bcff0946 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -622,7 +622,7 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
 	struct media_device *mdev = adapter->mdev;
 	struct media_entity  *entity, *source;
 	struct media_link *link, *found_link = NULL;
-	int i, ret, n_links = 0, active_links = 0;
+	int ret, n_links = 0, active_links = 0;
 
 	fepriv->pipe_start_entity = NULL;
 
@@ -632,8 +632,7 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
 	entity = fepriv->dvbdev->entity;
 	fepriv->pipe_start_entity = entity;
 
-	for (i = 0; i < entity->num_links; i++) {
-		link = &entity->links[i];
+	list_for_each_entry(link, &entity->links, list) {
 		if (link->sink->entity == entity) {
 			found_link = link;
 			n_links++;
@@ -659,13 +658,11 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
 
 	source = found_link->source->entity;
 	fepriv->pipe_start_entity = source;
-	for (i = 0; i < source->num_links; i++) {
+	list_for_each_entry(link, &source->links, list) {
 		struct media_entity *sink;
 		int flags = 0;
 
-		link = &source->links[i];
 		sink = link->sink->entity;
-
 		if (sink == entity)
 			flags = MEDIA_LNK_FL_ENABLED;
 
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 0d85c6c28004..3e649cacfc07 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -25,6 +25,7 @@
 #include <linux/ioctl.h>
 #include <linux/media.h>
 #include <linux/types.h>
+#include <linux/slab.h>
 
 #include <media/media-device.h>
 #include <media/media-devnode.h>
@@ -150,22 +151,21 @@ static long __media_device_enum_links(struct media_device *mdev,
 	}
 
 	if (links->links) {
-		struct media_link_desc __user *ulink;
-		unsigned int l;
+		struct media_link *ent_link;
+		struct media_link_desc __user *ulink = links->links;
 
-		for (l = 0, ulink = links->links; l < entity->num_links; l++) {
+		list_for_each_entry(ent_link, &entity->links, list) {
 			struct media_link_desc link;
 
 			/* Ignore backlinks. */
-			if (entity->links[l].source->entity != entity)
+			if (ent_link->source->entity != entity)
 				continue;
-
 			memset(&link, 0, sizeof(link));
-			media_device_kpad_to_upad(entity->links[l].source,
+			media_device_kpad_to_upad(ent_link->source,
 						  &link.source);
-			media_device_kpad_to_upad(entity->links[l].sink,
+			media_device_kpad_to_upad(ent_link->sink,
 						  &link.sink);
-			link.flags = entity->links[l].flags;
+			link.flags = ent_link->flags;
 			if (copy_to_user(ulink, &link, sizeof(*ulink)))
 				return -EFAULT;
 			ulink++;
@@ -437,6 +437,7 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	/* Warn if we apparently re-register an entity */
 	WARN_ON(entity->graph_obj.mdev != NULL);
 	entity->graph_obj.mdev = mdev;
+	INIT_LIST_HEAD(&entity->links);
 
 	spin_lock(&mdev->lock);
 	/* Initialize media_gobj embedded at the entity */
@@ -465,13 +466,17 @@ void media_device_unregister_entity(struct media_entity *entity)
 {
 	int i;
 	struct media_device *mdev = entity->graph_obj.mdev;
+	struct media_link *link, *tmp;
 
 	if (mdev == NULL)
 		return;
 
 	spin_lock(&mdev->lock);
-	for (i = 0; i < entity->num_links; i++)
-		media_gobj_remove(&entity->links[i].graph_obj);
+	list_for_each_entry_safe(link, tmp, &entity->links, list) {
+		media_gobj_remove(&link->graph_obj);
+		list_del(&link->list);
+		kfree(link);
+	}
 	for (i = 0; i < entity->num_pads; i++)
 		media_gobj_remove(&entity->pads[i].graph_obj);
 	media_gobj_remove(&entity->graph_obj);
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 9f8e0145db7a..c297ef7e010c 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -221,21 +221,13 @@ int
 media_entity_init(struct media_entity *entity, u16 num_pads,
 		  struct media_pad *pads)
 {
-	struct media_link *links;
-	unsigned int max_links = num_pads;
 	unsigned int i;
 
-	links = kzalloc(max_links * sizeof(links[0]), GFP_KERNEL);
-	if (links == NULL)
-		return -ENOMEM;
-
 	entity->group_id = 0;
-	entity->max_links = max_links;
 	entity->num_links = 0;
 	entity->num_backlinks = 0;
 	entity->num_pads = num_pads;
 	entity->pads = pads;
-	entity->links = links;
 
 	for (i = 0; i < num_pads; i++) {
 		pads[i].entity = entity;
@@ -249,7 +241,13 @@ EXPORT_SYMBOL_GPL(media_entity_init);
 void
 media_entity_cleanup(struct media_entity *entity)
 {
-	kfree(entity->links);
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &entity->links, list) {
+		media_gobj_remove(&link->graph_obj);
+		list_del(&link->list);
+		kfree(link);
+	}
 }
 EXPORT_SYMBOL_GPL(media_entity_cleanup);
 
@@ -275,7 +273,7 @@ static void stack_push(struct media_entity_graph *graph,
 		return;
 	}
 	graph->top++;
-	graph->stack[graph->top].link = 0;
+	graph->stack[graph->top].link = (&entity->links)->next;
 	graph->stack[graph->top].entity = entity;
 }
 
@@ -317,6 +315,7 @@ void media_entity_graph_walk_start(struct media_entity_graph *graph,
 }
 EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
 
+
 /**
  * media_entity_graph_walk_next - Get the next entity in the graph
  * @graph: Media graph structure
@@ -340,14 +339,16 @@ media_entity_graph_walk_next(struct media_entity_graph *graph)
 	 * top of the stack until no more entities on the level can be
 	 * found.
 	 */
-	while (link_top(graph) < stack_top(graph)->num_links) {
+	while (link_top(graph) != &(stack_top(graph)->links)) {
 		struct media_entity *entity = stack_top(graph);
-		struct media_link *link = &entity->links[link_top(graph)];
+		struct media_link *link;
 		struct media_entity *next;
 
+		link = list_entry(link_top(graph), typeof(*link), list);
+
 		/* The link is not enabled so we do not follow. */
 		if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {
-			link_top(graph)++;
+			link_top(graph) = link_top(graph)->next;
 			continue;
 		}
 
@@ -358,12 +359,12 @@ media_entity_graph_walk_next(struct media_entity_graph *graph)
 
 		/* Has the entity already been visited? */
 		if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
-			link_top(graph)++;
+			link_top(graph) = link_top(graph)->next;
 			continue;
 		}
 
 		/* Push the new entity to stack and start over. */
-		link_top(graph)++;
+		link_top(graph) = link_top(graph)->next;
 		stack_push(graph, next);
 	}
 
@@ -395,6 +396,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph graph;
 	struct media_entity *entity_err = entity;
+	struct media_link *link;
 	int ret;
 
 	mutex_lock(&mdev->graph_mutex);
@@ -404,7 +406,6 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		DECLARE_BITMAP(active, entity->num_pads);
 		DECLARE_BITMAP(has_no_links, entity->num_pads);
-		unsigned int i;
 
 		entity->stream_count++;
 		WARN_ON(entity->pipe && entity->pipe != pipe);
@@ -420,8 +421,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 		bitmap_zero(active, entity->num_pads);
 		bitmap_fill(has_no_links, entity->num_pads);
 
-		for (i = 0; i < entity->num_links; i++) {
-			struct media_link *link = &entity->links[i];
+		list_for_each_entry(link, &entity->links, list) {
 			struct media_pad *pad = link->sink->entity == entity
 						? link->sink : link->source;
 
@@ -582,25 +582,20 @@ EXPORT_SYMBOL_GPL(media_entity_put);
 
 static struct media_link *media_entity_add_link(struct media_entity *entity)
 {
-	if (entity->num_links >= entity->max_links) {
-		struct media_link *links = entity->links;
-		unsigned int max_links = entity->max_links + 2;
-		unsigned int i;
+	struct media_link *link;
 
-		links = krealloc(links, max_links * sizeof(*links), GFP_KERNEL);
-		if (links == NULL)
-			return NULL;
+	link = kzalloc(sizeof(*link), GFP_KERNEL);
+	if (link == NULL)
+		return NULL;
 
-		for (i = 0; i < entity->num_links; i++)
-			links[i].reverse->reverse = &links[i];
+	list_add_tail(&link->list, &entity->links);
 
-		entity->max_links = max_links;
-		entity->links = links;
-	}
-
-	return &entity->links[entity->num_links++];
+	return link;
 }
 
+static void __media_entity_remove_link(struct media_entity *entity,
+				       struct media_link *link);
+
 int
 media_create_pad_link(struct media_entity *source, u16 source_pad,
 			 struct media_entity *sink, u16 sink_pad, u32 flags)
@@ -629,7 +624,7 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	 */
 	backlink = media_entity_add_link(sink);
 	if (backlink == NULL) {
-		source->num_links--;
+		__media_entity_remove_link(source, link);
 		return -ENOMEM;
 	}
 
@@ -645,43 +640,51 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	backlink->reverse = link;
 
 	sink->num_backlinks++;
+	sink->num_links++;
+	source->num_links++;
 
 	return 0;
 }
 EXPORT_SYMBOL_GPL(media_create_pad_link);
 
-void __media_entity_remove_links(struct media_entity *entity)
+static void __media_entity_remove_link(struct media_entity *entity,
+				       struct media_link *link)
 {
-	unsigned int i;
+	struct media_link *rlink, *tmp;
+	struct media_entity *remote;
+	unsigned int r = 0;
 
-	for (i = 0; i < entity->num_links; i++) {
-		struct media_link *link = &entity->links[i];
-		struct media_entity *remote;
-		unsigned int r = 0;
+	if (link->source->entity == entity)
+		remote = link->sink->entity;
+	else
+		remote = link->source->entity;
+
+	list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
+		if (rlink != link->reverse) {
+			r++;
+			continue;
+		}
 
 		if (link->source->entity == entity)
-			remote = link->sink->entity;
-		else
-			remote = link->source->entity;
+			remote->num_backlinks--;
 
-		while (r < remote->num_links) {
-			struct media_link *rlink = &remote->links[r];
+		if (--remote->num_links == 0)
+			break;
 
-			if (rlink != link->reverse) {
-				r++;
-				continue;
-			}
-
-			if (link->source->entity == entity)
-				remote->num_backlinks--;
-
-			if (--remote->num_links == 0)
-				break;
-
-			/* Insert last entry in place of the dropped link. */
-			*rlink = remote->links[remote->num_links];
-		}
+		/* Remove the remote link */
+		list_del(&rlink->list);
+		kfree(rlink);
 	}
+	list_del(&link->list);
+	kfree(link);
+}
+
+void __media_entity_remove_links(struct media_entity *entity)
+{
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &entity->links, list)
+		__media_entity_remove_link(entity, link);
 
 	entity->num_links = 0;
 	entity->num_backlinks = 0;
@@ -806,11 +809,8 @@ struct media_link *
 media_entity_find_link(struct media_pad *source, struct media_pad *sink)
 {
 	struct media_link *link;
-	unsigned int i;
-
-	for (i = 0; i < source->entity->num_links; ++i) {
-		link = &source->entity->links[i];
 
+	list_for_each_entry(link, &source->entity->links, list) {
 		if (link->source->entity == source->entity &&
 		    link->source->index == source->index &&
 		    link->sink->entity == sink->entity &&
@@ -834,11 +834,9 @@ EXPORT_SYMBOL_GPL(media_entity_find_link);
  */
 struct media_pad *media_entity_remote_pad(struct media_pad *pad)
 {
-	unsigned int i;
-
-	for (i = 0; i < pad->entity->num_links; i++) {
-		struct media_link *link = &pad->entity->links[i];
+	struct media_link *link;
 
+	list_for_each_entry(link, &pad->entity->links, list) {
 		if (!(link->flags & MEDIA_LNK_FL_ENABLED))
 			continue;
 
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index a55eb524ea21..7f645bcb7463 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -261,13 +261,11 @@ static void au0828_create_media_graph(struct au0828_dev *dev)
 
 	if (tuner)
 		media_create_pad_link(tuner, 0, decoder, 0,
-					 MEDIA_LNK_FL_ENABLED);
-	if (dev->vdev.entity.links)
-		media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
-				 MEDIA_LNK_FL_ENABLED);
-	if (dev->vbi_dev.entity.links)
-		media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
-				 MEDIA_LNK_FL_ENABLED);
+				      MEDIA_LNK_FL_ENABLED);
+	media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
+			      MEDIA_LNK_FL_ENABLED);
+	media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
+			      MEDIA_LNK_FL_ENABLED);
 #endif
 }
 
diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 2c040056d4eb..4511e2893282 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -643,7 +643,7 @@ static int au0828_enable_analog_tuner(struct au0828_dev *dev)
 	struct media_device *mdev = dev->media_dev;
 	struct media_entity *source;
 	struct media_link *link, *found_link = NULL;
-	int i, ret, active_links = 0;
+	int ret, active_links = 0;
 
 	if (!mdev || !dev->decoder)
 		return 0;
@@ -655,8 +655,7 @@ static int au0828_enable_analog_tuner(struct au0828_dev *dev)
 	 * do DVB streaming while the DMA engine is being used for V4L2,
 	 * this should be enough for the actual needs.
 	 */
-	for (i = 0; i < dev->decoder->num_links; i++) {
-		link = &dev->decoder->links[i];
+	list_for_each_entry(link, &dev->decoder->links, list) {
 		if (link->sink->entity == dev->decoder) {
 			found_link = link;
 			if (link->flags & MEDIA_LNK_FL_ENABLED)
@@ -669,11 +668,10 @@ static int au0828_enable_analog_tuner(struct au0828_dev *dev)
 		return 0;
 
 	source = found_link->source->entity;
-	for (i = 0; i < source->num_links; i++) {
+	list_for_each_entry(link, &source->links, list) {
 		struct media_entity *sink;
 		int flags = 0;
 
-		link = &source->links[i];
 		sink = link->sink->entity;
 
 		if (sink == dev->decoder)
diff --git a/drivers/media/usb/cx231xx/cx231xx-video.c b/drivers/media/usb/cx231xx/cx231xx-video.c
index 8f04b125486f..e8baff4d6290 100644
--- a/drivers/media/usb/cx231xx/cx231xx-video.c
+++ b/drivers/media/usb/cx231xx/cx231xx-video.c
@@ -106,7 +106,7 @@ static int cx231xx_enable_analog_tuner(struct cx231xx *dev)
 	struct media_device *mdev = dev->media_dev;
 	struct media_entity  *entity, *decoder = NULL, *source;
 	struct media_link *link, *found_link = NULL;
-	int i, ret, active_links = 0;
+	int ret, active_links = 0;
 
 	if (!mdev)
 		return 0;
@@ -127,8 +127,7 @@ static int cx231xx_enable_analog_tuner(struct cx231xx *dev)
 	if (!decoder)
 		return 0;
 
-	for (i = 0; i < decoder->num_links; i++) {
-		link = &decoder->links[i];
+	list_for_each_entry(link, &decoder->links, list) {
 		if (link->sink->entity == decoder) {
 			found_link = link;
 			if (link->flags & MEDIA_LNK_FL_ENABLED)
@@ -141,11 +140,10 @@ static int cx231xx_enable_analog_tuner(struct cx231xx *dev)
 		return 0;
 
 	source = found_link->source->entity;
-	for (i = 0; i < source->num_links; i++) {
+	list_for_each_entry(link, &source->links, list) {
 		struct media_entity *sink;
 		int flags = 0;
 
-		link = &source->links[i];
 		sink = link->sink->entity;
 
 		if (sink == entity)
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 7df8836f4eef..7016f0619415 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -74,6 +74,7 @@ struct media_pipeline {
 
 struct media_link {
 	struct media_gobj graph_obj;
+	struct list_head list;
 	struct media_pad *source;	/* Source pad */
 	struct media_pad *sink;		/* Sink pad  */
 	struct media_link *reverse;	/* Link in the reverse direction */
@@ -116,10 +117,9 @@ struct media_entity {
 	u16 num_links;			/* Number of existing links, both
 					 * enabled and disabled */
 	u16 num_backlinks;		/* Number of backlinks */
-	u16 max_links;			/* Maximum number of links */
 
-	struct media_pad *pads;		/* Pads array (num_pads elements) */
-	struct media_link *links;	/* Links array (max_links elements)*/
+	struct media_pad *pads;		/* Pads array (num_pads objects) */
+	struct list_head links;		/* Links list */
 
 	const struct media_entity_operations *ops;	/* Entity operations */
 
@@ -213,7 +213,7 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
 struct media_entity_graph {
 	struct {
 		struct media_entity *entity;
-		int link;
+		struct list_head *link;
 	} stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
 
 	DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID);
@@ -247,7 +247,7 @@ void media_gobj_init(struct media_device *mdev,
 void media_gobj_remove(struct media_gobj *gobj);
 
 int media_entity_init(struct media_entity *entity, u16 num_pads,
-		struct media_pad *pads);
+		      struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
 
 int media_create_pad_link(struct media_entity *source, u16 source_pad,
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes
  2015-08-31 13:23   ` Hans Verkuil
@ 2015-09-04 16:13     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-04 16:13 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Sakari Ailus

Em Mon, 31 Aug 2015 15:23:59 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 08/30/2015 05:07 AM, Mauro Carvalho Chehab wrote:
> > V4L2 device (and subdevice) nodes should create an
> > interface, if the Media Controller support is enabled.
> > 
> > Please notice that radio devices should not create an
> > entity, as radio input/output is either via wires or
> > via ALSA.
> 
> A general note: I think this patch (and any prerequisite patches) should come before
> the patches adding G_TOPOLOGY support.
> 
> What the G_TOPOLOGY ioctl returns only makes sense IMHO if this code is present as well,
> so it is a more logical order for this patch series.
> 
> In addition, since G_TOPOLOGY is a userspace API it is likely that that will create
> more discussions, whereas this is internal to the kernel and could be merged before
> G_TOPOLOGY.
> 
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
> > index 44b330589787..427a5a32b3de 100644
> > --- a/drivers/media/v4l2-core/v4l2-dev.c
> > +++ b/drivers/media/v4l2-core/v4l2-dev.c
> > @@ -194,9 +194,12 @@ static void v4l2_device_release(struct device *cd)
> >  	mutex_unlock(&videodev_lock);
> >  
> >  #if defined(CONFIG_MEDIA_CONTROLLER)
> > -	if (v4l2_dev->mdev &&
> > -	    vdev->vfl_type != VFL_TYPE_SUBDEV)
> > -		media_device_unregister_entity(&vdev->entity);
> > +	if (v4l2_dev->mdev) {
> > +		/* Remove interfaces and interface links */
> > +		media_devnode_remove(vdev->intf_devnode);
> > +		if (vdev->vfl_type != VFL_TYPE_SUBDEV)
> > +			media_device_unregister_entity(&vdev->entity);
> 
> RADIO doesn't have an entity either, so this should probably check for both
> SUBDEV and RADIO.
> 
> I think it is cleaner if video_register_media_controller() sets a new video_device
> flag: V4L2_FL_CREATED_ENTITY, and if this release function would just check the
> flag.

I don't see the need for a new flag here. I guess this should do the job:

diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 427a5a32b3de..298aaf6f4296 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -197,7 +197,7 @@ static void v4l2_device_release(struct device *cd)
 	if (v4l2_dev->mdev) {
 		/* Remove interfaces and interface links */
 		media_devnode_remove(vdev->intf_devnode);
-		if (vdev->vfl_type != VFL_TYPE_SUBDEV)
+		if (vdev->entity.type)
 			media_device_unregister_entity(&vdev->entity);
 	}
 #endif
@@ -775,6 +775,8 @@ static int video_register_media_controller(struct video_device *vdev, int type)
 				__func__);
 			return ret;
 		}
+	} else {
+		vdev->entity.type = 0;
 	}
 
 	vdev->intf_devnode = media_devnode_create(vdev->v4l2_dev->mdev,

Regards,
Mauro

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 48/55] [media] media_device: add a topology version field
  2015-08-31 13:35       ` Hans Verkuil
@ 2015-09-04 17:08         ` Mauro Carvalho Chehab
  2015-11-23 22:18           ` Laurent Pinchart
  0 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-04 17:08 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Em Mon, 31 Aug 2015 15:35:38 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 08/31/2015 02:52 PM, Mauro Carvalho Chehab wrote:
> > Em Mon, 31 Aug 2015 14:29:28 +0200
> > Hans Verkuil <hverkuil@xs4all.nl> escreveu:
> > 
> >> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> >>> Every time a graph object is added or removed, the version
> >>> of the topology changes. That's a requirement for the new
> >>> MEDIA_IOC_G_TOPOLOGY, in order to allow userspace to know
> >>> that the topology has changed after a previous call to it.
> >>>
> >>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> >>
> >> I think this should be postponed until we actually have dynamic reconfigurable
> >> graphs.
> > 
> > So far, we're using the term "dynamic" to mean partial graph object
> > removal.
> > 
> > But even today, MC does support "dynamic" in the sense of graph
> > object additions.
> > 
> > You should notice that having a topology_version is something that
> > IMHO, it is needed since the beginning, even without dynamic
> > reconfigurable graphs, because the graph may grow in runtime.
> > 
> > That will happen, for example, if usb-snd-audio is blacklisted
> > at /etc/modprobe*, and someone connects an au0828.
> > 
> > New entities/links will be created (after Shuah patches) if one would
> > modprobe latter snd-usb-audio.
> 
> latter -> later :-)
> 
> You are right, this would trigger a topology change. I hadn't thought about
> that.
> 
> > 
> >>
> >> I would also like to reserve version 0: if 0 is returned, then the graph is
> >> static.
> > 
> > Why? Implementing this would be really hard, as that would mean that
> > G_TOPOLOGY would need to be blocked until all drivers and subdevices
> > get probed.
> > 
> > In order to implement that, some logic would be needed at the drivers
> > to identify if everything was set and unlock G_TOPOLOGY.
> 
> That wouldn't be needed if the media device node was created last. Which
> I think is a good idea anyway.

Creating the media device node last won't work. It should be the first
thing to be created, as all objects should be added to media_device
linked lists. 

Also, the numberspace should be local to a given media_device, as the
graph traversal algorithm relies on having the number of entities <= 64,
currently, in order to be able to detect loops. We should increase that
number, but removing an "as low as possible" entity number limit is not
trivial.

> 
> > 
> > What would be the gain for that? I fail to see any.
> 
> It would tell userspace that it doesn't have to cope with dynamically
> changing graphs.
> 
> Even though with the au0828 example you can expect to see cases like that,
> I can pretty much guarantee that no generic v4l2 applications will ever
> support dynamic changes.

Well, my test app supports it and it is generic ;) My plan is to use it
as a basis for the library to be used on userspace for generic apps,
extending it to be used by other tools like xawtv, qv4l2 and the dvbv5 apps.

I don't think it is hard to handle it on a generic app, and this should
be done anyway if we want dynamic support.

The logic seems actually be simple:

at G_TOPOLOGY, if the topology changes, reload the objects;

at SETUP_LINK_V2, the topology will be sent. if the driver detects that
topology changed, it returns an error.

The caller will then need to reload the topology and re-apply the
transaction to select the links, if the entities affected still
exists. In other words, if the user's intent were to change the pipeline
to receive the data at /dev/video2, e. g. something like:
	./yavta/yavta -f UYVY -s 720x312 -n 1 --capture=1 -F /dev/video2

What userspace would do is to reload everything, check if /dev/video2
still exists and then redo the function that it is equivalent to the
above command, failing otherwise. That doesn't sound hard to implement.

> Those that will support it will be custom-made.
> 
> Being able to see that graphs can change dynamically would allow such apps
> to either refuse to use the device, or warn the user.

The way I see is that applications that will assume that the graph
is static will be the custom-made ones. As they know the hardware,
they can just either ignore the topology_version or wait for it to
stabilize when the hardware is still being probed.

In any case, if we end by needing to have an explicit way for the
Kernelspace to tell userspace that a graph is static, that could
be done via an extra flag at MEDIA_INFO.

Enabling this flag could be as easy as waiting for all graph
elements to be created (where the topology is still dynamic),
and raise such flag after finishing the probe sequence.

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 54/55] [media] au0828: unregister MC at the end
  2015-08-31 13:25   ` Hans Verkuil
@ 2015-09-04 22:24     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-04 22:24 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	Rafael Lourenço de Lima Chehab, Hans Verkuil, Shuah Khan

Em Mon, 31 Aug 2015 15:25:39 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 08/30/2015 05:07 AM, Mauro Carvalho Chehab wrote:
> > au0828_analog_unregister() calls video_unregister_device(),
> > with, in turn, calls media_devnode_remove() in order to drop
> > the media interfaces.
> > 
> > We can't release the media controller before that, or an
> > OOPS will occur:
> 
> So this patch should be moved to a place earlier in the patch series,
> right? To prevent bisects that hit this bug.

Yes, it should be before the previous patch.

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 14/55] [media] media: add functions to allow creating interfaces
  2015-08-30  3:06 ` [PATCH v8 14/55] [media] media: add functions to allow creating interfaces Mauro Carvalho Chehab
  2015-08-31 10:20   ` Hans Verkuil
@ 2015-09-06 12:02   ` Mauro Carvalho Chehab
  2015-09-09  7:34     ` Sakari Ailus
                       ` (2 more replies)
  1 sibling, 3 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

Interfaces are different than entities: they represent a
Kernel<->userspace interaction, while entities represent a
piece of hardware/firmware/software that executes a function.

Let's distinguish them by creating a separate structure to
store the interfaces.

Later patches should change the existing drivers and logic
to split the current interface embedded inside the entity
structure (device nodes) into a separate object of the graph.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index a23c93369a04..dc679dfe8ade 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -44,11 +44,41 @@ static inline const char *gobj_type(enum media_gobj_type type)
 		return "pad";
 	case MEDIA_GRAPH_LINK:
 		return "link";
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		return "intf-devnode";
 	default:
 		return "unknown";
 	}
 }
 
+static inline const char *intf_type(struct media_interface *intf)
+{
+	switch (intf->type) {
+	case MEDIA_INTF_T_DVB_FE:
+		return "frontend";
+	case MEDIA_INTF_T_DVB_DEMUX:
+		return "demux";
+	case MEDIA_INTF_T_DVB_DVR:
+		return "DVR";
+	case MEDIA_INTF_T_DVB_CA:
+		return  "CA";
+	case MEDIA_INTF_T_DVB_NET:
+		return "dvbnet";
+	case MEDIA_INTF_T_V4L_VIDEO:
+		return "video";
+	case MEDIA_INTF_T_V4L_VBI:
+		return "vbi";
+	case MEDIA_INTF_T_V4L_RADIO:
+		return "radio";
+	case MEDIA_INTF_T_V4L_SUBDEV:
+		return "v4l2-subdev";
+	case MEDIA_INTF_T_V4L_SWRADIO:
+		return "swradio";
+	default:
+		return "unknown-intf";
+	}
+};
+
 static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 {
 #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
@@ -84,6 +114,19 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 			"%s: id 0x%08x pad#%d: '%s':%d\n",
 			event_name, gobj->id, media_localid(gobj),
 			pad->entity->name, pad->index);
+		break;
+	}
+	case MEDIA_GRAPH_INTF_DEVNODE:
+	{
+		struct media_interface *intf = gobj_to_intf(gobj);
+		struct media_intf_devnode *devnode = intf_to_devnode(intf);
+
+		dev_dbg(gobj->mdev->dev,
+			"%s: id 0x%08x intf_devnode#%d: %s - major: %d, minor: %d\n",
+			event_name, gobj->id, media_localid(gobj),
+			intf_type(intf),
+			devnode->major, devnode->minor);
+		break;
 	}
 	}
 #endif
@@ -119,6 +162,9 @@ void media_gobj_init(struct media_device *mdev,
 	case MEDIA_GRAPH_LINK:
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
 		break;
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
+		break;
 	}
 	dev_dbg_obj(__func__, gobj);
 }
@@ -793,3 +839,40 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
 
 }
 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
+
+
+/* Functions related to the media interface via device nodes */
+
+struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
+						u32 type, u32 flags,
+						u32 major, u32 minor,
+						gfp_t gfp_flags)
+{
+	struct media_intf_devnode *devnode;
+	struct media_interface *intf;
+
+	devnode = kzalloc(sizeof(*devnode), gfp_flags);
+	if (!devnode)
+		return NULL;
+
+	intf = &devnode->intf;
+
+	intf->type = type;
+	intf->flags = flags;
+
+	devnode->major = major;
+	devnode->minor = minor;
+
+	media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
+		       &devnode->intf.graph_obj);
+
+	return devnode;
+}
+EXPORT_SYMBOL_GPL(media_devnode_create);
+
+void media_devnode_remove(struct media_intf_devnode *devnode)
+{
+	media_gobj_remove(&devnode->intf.graph_obj);
+	kfree(devnode);
+}
+EXPORT_SYMBOL_GPL(media_devnode_remove);
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 05414e351f8e..3b14394d5701 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -44,6 +44,7 @@ struct device;
  * @entity_id:	Unique ID used on the last entity registered
  * @pad_id:	Unique ID used on the last pad registered
  * @link_id:	Unique ID used on the last link registered
+ * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:	List of registered entities
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
@@ -73,6 +74,7 @@ struct media_device {
 	u32 entity_id;
 	u32 pad_id;
 	u32 link_id;
+	u32 intf_devnode_id;
 
 	struct list_head entities;
 
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 239c4ec30ef6..7df8836f4eef 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -36,11 +36,14 @@
  * @MEDIA_GRAPH_ENTITY:		Identify a media entity
  * @MEDIA_GRAPH_PAD:		Identify a media pad
  * @MEDIA_GRAPH_LINK:		Identify a media link
+ * @MEDIA_GRAPH_INTF_DEVNODE:	Identify a media Kernel API interface via
+ *				a device node
  */
 enum media_gobj_type {
 	MEDIA_GRAPH_ENTITY,
 	MEDIA_GRAPH_PAD,
 	MEDIA_GRAPH_LINK,
+	MEDIA_GRAPH_INTF_DEVNODE,
 };
 
 #define MEDIA_BITS_PER_TYPE		8
@@ -141,6 +144,34 @@ struct media_entity {
 	} info;
 };
 
+/**
+ * struct media_intf_devnode - Define a Kernel API interface
+ *
+ * @graph_obj:		embedded graph object
+ * @type:		Type of the interface as defined at the
+ *			uapi/media/media.h header, e. g.
+ *			MEDIA_INTF_T_*
+ * @flags:		Interface flags as defined at uapi/media/media.h
+ */
+struct media_interface {
+	struct media_gobj		graph_obj;
+	u32				type;
+	u32				flags;
+};
+
+/**
+ * struct media_intf_devnode - Define a Kernel API interface via a device node
+ *
+ * @intf:	embedded interface object
+ * @major:	Major number of a device node
+ * @minor:	Minor number of a device node
+ */
+struct media_intf_devnode {
+	struct media_interface		intf;
+	u32				major;
+	u32				minor;
+};
+
 static inline u32 media_entity_type(struct media_entity *entity)
 {
 	return entity->type & MEDIA_ENT_TYPE_MASK;
@@ -198,6 +229,18 @@ struct media_entity_graph {
 #define gobj_to_link(gobj) \
 		container_of(gobj, struct media_link, graph_obj)
 
+#define gobj_to_link(gobj) \
+		container_of(gobj, struct media_link, graph_obj)
+
+#define gobj_to_pad(gobj) \
+		container_of(gobj, struct media_pad, graph_obj)
+
+#define gobj_to_intf(gobj) \
+		container_of(gobj, struct media_interface, graph_obj)
+
+#define intf_to_devnode(intf) \
+		container_of(intf, struct media_intf_devnode, intf)
+
 void media_gobj_init(struct media_device *mdev,
 		    enum media_gobj_type type,
 		    struct media_gobj *gobj);
@@ -229,6 +272,11 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 					     struct media_pipeline *pipe);
 void media_entity_pipeline_stop(struct media_entity *entity);
 
+struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
+						u32 type, u32 flags,
+						u32 major, u32 minor,
+						gfp_t gfp_flags);
+void media_devnode_remove(struct media_intf_devnode *devnode);
 #define media_entity_call(entity, operation, args...)			\
 	(((entity)->ops && (entity)->ops->operation) ?			\
 	 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 15/55] [media] uapi/media.h: Declare interface types for ALSA
@ 2015-09-06 12:02     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, linux-api

Declare the interface types to be used on alsa for the new
G_TOPOLOGY ioctl.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index dc679dfe8ade..27fce6224972 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -74,6 +74,18 @@ static inline const char *intf_type(struct media_interface *intf)
 		return "v4l2-subdev";
 	case MEDIA_INTF_T_V4L_SWRADIO:
 		return "swradio";
+	case MEDIA_INTF_T_ALSA_PCM_CAPTURE:
+		return "pcm-capture";
+	case MEDIA_INTF_T_ALSA_PCM_PLAYBACK:
+		return "pcm-playback";
+	case MEDIA_INTF_T_ALSA_CONTROL:
+		return "alsa-control";
+	case MEDIA_INTF_T_ALSA_COMPRESS:
+		return "compress";
+	case MEDIA_INTF_T_ALSA_RAWMIDI:
+		return "rawmidi";
+	case MEDIA_INTF_T_ALSA_HWDEP:
+		return "hwdep";
 	default:
 		return "unknown-intf";
 	}
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 3ad3d6be293f..aca828709bad 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -171,6 +171,7 @@ struct media_links_enum {
 
 #define MEDIA_INTF_T_DVB_BASE	0x00000100
 #define MEDIA_INTF_T_V4L_BASE	0x00000200
+#define MEDIA_INTF_T_ALSA_BASE	0x00000300
 
 /* Interface types */
 
@@ -186,6 +187,13 @@ struct media_links_enum {
 #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
 #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
 
+#define MEDIA_INTF_T_ALSA_PCM_CAPTURE   (MEDIA_INTF_T_ALSA_BASE)
+#define MEDIA_INTF_T_ALSA_PCM_PLAYBACK  (MEDIA_INTF_T_ALSA_BASE + 1)
+#define MEDIA_INTF_T_ALSA_CONTROL       (MEDIA_INTF_T_ALSA_BASE + 2)
+#define MEDIA_INTF_T_ALSA_COMPRESS      (MEDIA_INTF_T_ALSA_BASE + 3)
+#define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
+#define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
+
 /* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
 
 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 15/55] [media] uapi/media.h: Declare interface types for ALSA
@ 2015-09-06 12:02     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, linux-api-u79uwXL29TY76Z2rM5mHXA

Declare the interface types to be used on alsa for the new
G_TOPOLOGY ioctl.

Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index dc679dfe8ade..27fce6224972 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -74,6 +74,18 @@ static inline const char *intf_type(struct media_interface *intf)
 		return "v4l2-subdev";
 	case MEDIA_INTF_T_V4L_SWRADIO:
 		return "swradio";
+	case MEDIA_INTF_T_ALSA_PCM_CAPTURE:
+		return "pcm-capture";
+	case MEDIA_INTF_T_ALSA_PCM_PLAYBACK:
+		return "pcm-playback";
+	case MEDIA_INTF_T_ALSA_CONTROL:
+		return "alsa-control";
+	case MEDIA_INTF_T_ALSA_COMPRESS:
+		return "compress";
+	case MEDIA_INTF_T_ALSA_RAWMIDI:
+		return "rawmidi";
+	case MEDIA_INTF_T_ALSA_HWDEP:
+		return "hwdep";
 	default:
 		return "unknown-intf";
 	}
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 3ad3d6be293f..aca828709bad 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -171,6 +171,7 @@ struct media_links_enum {
 
 #define MEDIA_INTF_T_DVB_BASE	0x00000100
 #define MEDIA_INTF_T_V4L_BASE	0x00000200
+#define MEDIA_INTF_T_ALSA_BASE	0x00000300
 
 /* Interface types */
 
@@ -186,6 +187,13 @@ struct media_links_enum {
 #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
 #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
 
+#define MEDIA_INTF_T_ALSA_PCM_CAPTURE   (MEDIA_INTF_T_ALSA_BASE)
+#define MEDIA_INTF_T_ALSA_PCM_PLAYBACK  (MEDIA_INTF_T_ALSA_BASE + 1)
+#define MEDIA_INTF_T_ALSA_CONTROL       (MEDIA_INTF_T_ALSA_BASE + 2)
+#define MEDIA_INTF_T_ALSA_COMPRESS      (MEDIA_INTF_T_ALSA_BASE + 3)
+#define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
+#define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
+
 /* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
 
 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 16/55] [media] media: Don't accept early-created links
  2015-08-30  3:06 ` [PATCH v8 16/55] [media] media: Don't accept early-created links Mauro Carvalho Chehab
  2015-08-31 10:30   ` Hans Verkuil
@ 2015-09-06 12:02   ` Mauro Carvalho Chehab
  2015-12-06  3:13     ` Laurent Pinchart
  1 sibling, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

Links are graph objects that represent the links of two already
existing objects in the graph.

While with the current implementation, it is possible to create
the links earlier, It doesn't make any sense to allow linking
two objects when they are not both created.

So, remove the code that would be handling those early-created
links and add a BUG_ON() to ensure that.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 138b18416460..0d85c6c28004 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -443,13 +443,6 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
 	list_add_tail(&entity->list, &mdev->entities);
 
-	/*
-	 * Initialize objects at the links
-	 * in the case where links got created before entity register
-	 */
-	for (i = 0; i < entity->num_links; i++)
-		media_gobj_init(mdev, MEDIA_GRAPH_LINK,
-				&entity->links[i].graph_obj);
 	/* Initialize objects at the pads */
 	for (i = 0; i < entity->num_pads; i++)
 		media_gobj_init(mdev, MEDIA_GRAPH_PAD,
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 27fce6224972..0926f08be981 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -161,6 +161,8 @@ void media_gobj_init(struct media_device *mdev,
 			   enum media_gobj_type type,
 			   struct media_gobj *gobj)
 {
+	BUG_ON(!mdev);
+
 	gobj->mdev = mdev;
 
 	/* Create a per-type unique object ID */
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8.2 19/55] [media] media: convert links from array to list
  2015-09-04 11:48     ` [PATCH v8.2 " Mauro Carvalho Chehab
@ 2015-09-06 12:02       ` Mauro Carvalho Chehab
  2015-11-23 15:37         ` Laurent Pinchart
  0 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Akihiro Tsukada, Antti Palosaari,
	Jonathan Corbet, Stefan Richter, Tina Ruchandani, Dan Carpenter,
	Rafael Lourenço de Lima Chehab, Hans Verkuil, Shuah Khan,
	Lad, Prabhakar, Julia Lawall, Sakari Ailus, Boris BREZILLON

The entire logic that represent graph links were developed on a
time where there were no needs to dynamic remove links. So,
although links are created/removed one by one via some
functions, they're stored as an array inside the entity struct.

As the array may grow, there's a logic inside the code that
checks if the amount of space is not enough to store
the needed links. If it isn't the core uses krealloc()
to change the size of the link, with is bad, as it
leaves the memory fragmented.

So, convert links into a list.

Also, currently,  both source and sink entities need the link
at the graph traversal logic inside media_entity. So there's
a logic duplicating all links. That makes it to spend
twice the memory needed. This is not a big deal for today's
usage, where the number of links are not big.

Yet, if during the MC workshop discussions, it was said that
IIO graphs could have up to 4,000 entities. So, we may
want to remove the duplication on some future. The problem
is that it would require a separate linked list to store
the backlinks inside the entity, or to use a more complex
algorithm to do graph backlink traversal, with is something
that the current graph traversal inside the core can't cope
with. So, let's postpone a such change if/when it is actually
needed.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index c38ef1a72b4a..2d06bcff0946 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -622,7 +622,7 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
 	struct media_device *mdev = adapter->mdev;
 	struct media_entity  *entity, *source;
 	struct media_link *link, *found_link = NULL;
-	int i, ret, n_links = 0, active_links = 0;
+	int ret, n_links = 0, active_links = 0;
 
 	fepriv->pipe_start_entity = NULL;
 
@@ -632,8 +632,7 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
 	entity = fepriv->dvbdev->entity;
 	fepriv->pipe_start_entity = entity;
 
-	for (i = 0; i < entity->num_links; i++) {
-		link = &entity->links[i];
+	list_for_each_entry(link, &entity->links, list) {
 		if (link->sink->entity == entity) {
 			found_link = link;
 			n_links++;
@@ -659,13 +658,11 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
 
 	source = found_link->source->entity;
 	fepriv->pipe_start_entity = source;
-	for (i = 0; i < source->num_links; i++) {
+	list_for_each_entry(link, &source->links, list) {
 		struct media_entity *sink;
 		int flags = 0;
 
-		link = &source->links[i];
 		sink = link->sink->entity;
-
 		if (sink == entity)
 			flags = MEDIA_LNK_FL_ENABLED;
 
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 0d85c6c28004..3e649cacfc07 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -25,6 +25,7 @@
 #include <linux/ioctl.h>
 #include <linux/media.h>
 #include <linux/types.h>
+#include <linux/slab.h>
 
 #include <media/media-device.h>
 #include <media/media-devnode.h>
@@ -150,22 +151,21 @@ static long __media_device_enum_links(struct media_device *mdev,
 	}
 
 	if (links->links) {
-		struct media_link_desc __user *ulink;
-		unsigned int l;
+		struct media_link *ent_link;
+		struct media_link_desc __user *ulink = links->links;
 
-		for (l = 0, ulink = links->links; l < entity->num_links; l++) {
+		list_for_each_entry(ent_link, &entity->links, list) {
 			struct media_link_desc link;
 
 			/* Ignore backlinks. */
-			if (entity->links[l].source->entity != entity)
+			if (ent_link->source->entity != entity)
 				continue;
-
 			memset(&link, 0, sizeof(link));
-			media_device_kpad_to_upad(entity->links[l].source,
+			media_device_kpad_to_upad(ent_link->source,
 						  &link.source);
-			media_device_kpad_to_upad(entity->links[l].sink,
+			media_device_kpad_to_upad(ent_link->sink,
 						  &link.sink);
-			link.flags = entity->links[l].flags;
+			link.flags = ent_link->flags;
 			if (copy_to_user(ulink, &link, sizeof(*ulink)))
 				return -EFAULT;
 			ulink++;
@@ -437,6 +437,7 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	/* Warn if we apparently re-register an entity */
 	WARN_ON(entity->graph_obj.mdev != NULL);
 	entity->graph_obj.mdev = mdev;
+	INIT_LIST_HEAD(&entity->links);
 
 	spin_lock(&mdev->lock);
 	/* Initialize media_gobj embedded at the entity */
@@ -465,13 +466,17 @@ void media_device_unregister_entity(struct media_entity *entity)
 {
 	int i;
 	struct media_device *mdev = entity->graph_obj.mdev;
+	struct media_link *link, *tmp;
 
 	if (mdev == NULL)
 		return;
 
 	spin_lock(&mdev->lock);
-	for (i = 0; i < entity->num_links; i++)
-		media_gobj_remove(&entity->links[i].graph_obj);
+	list_for_each_entry_safe(link, tmp, &entity->links, list) {
+		media_gobj_remove(&link->graph_obj);
+		list_del(&link->list);
+		kfree(link);
+	}
 	for (i = 0; i < entity->num_pads; i++)
 		media_gobj_remove(&entity->pads[i].graph_obj);
 	media_gobj_remove(&entity->graph_obj);
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 0926f08be981..d5efa0e2c88c 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -221,21 +221,13 @@ int
 media_entity_init(struct media_entity *entity, u16 num_pads,
 		  struct media_pad *pads)
 {
-	struct media_link *links;
-	unsigned int max_links = num_pads;
 	unsigned int i;
 
-	links = kzalloc(max_links * sizeof(links[0]), GFP_KERNEL);
-	if (links == NULL)
-		return -ENOMEM;
-
 	entity->group_id = 0;
-	entity->max_links = max_links;
 	entity->num_links = 0;
 	entity->num_backlinks = 0;
 	entity->num_pads = num_pads;
 	entity->pads = pads;
-	entity->links = links;
 
 	for (i = 0; i < num_pads; i++) {
 		pads[i].entity = entity;
@@ -249,7 +241,13 @@ EXPORT_SYMBOL_GPL(media_entity_init);
 void
 media_entity_cleanup(struct media_entity *entity)
 {
-	kfree(entity->links);
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &entity->links, list) {
+		media_gobj_remove(&link->graph_obj);
+		list_del(&link->list);
+		kfree(link);
+	}
 }
 EXPORT_SYMBOL_GPL(media_entity_cleanup);
 
@@ -275,7 +273,7 @@ static void stack_push(struct media_entity_graph *graph,
 		return;
 	}
 	graph->top++;
-	graph->stack[graph->top].link = 0;
+	graph->stack[graph->top].link = (&entity->links)->next;
 	graph->stack[graph->top].entity = entity;
 }
 
@@ -317,6 +315,7 @@ void media_entity_graph_walk_start(struct media_entity_graph *graph,
 }
 EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
 
+
 /**
  * media_entity_graph_walk_next - Get the next entity in the graph
  * @graph: Media graph structure
@@ -340,14 +339,16 @@ media_entity_graph_walk_next(struct media_entity_graph *graph)
 	 * top of the stack until no more entities on the level can be
 	 * found.
 	 */
-	while (link_top(graph) < stack_top(graph)->num_links) {
+	while (link_top(graph) != &(stack_top(graph)->links)) {
 		struct media_entity *entity = stack_top(graph);
-		struct media_link *link = &entity->links[link_top(graph)];
+		struct media_link *link;
 		struct media_entity *next;
 
+		link = list_entry(link_top(graph), typeof(*link), list);
+
 		/* The link is not enabled so we do not follow. */
 		if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {
-			link_top(graph)++;
+			link_top(graph) = link_top(graph)->next;
 			continue;
 		}
 
@@ -358,12 +359,12 @@ media_entity_graph_walk_next(struct media_entity_graph *graph)
 
 		/* Has the entity already been visited? */
 		if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
-			link_top(graph)++;
+			link_top(graph) = link_top(graph)->next;
 			continue;
 		}
 
 		/* Push the new entity to stack and start over. */
-		link_top(graph)++;
+		link_top(graph) = link_top(graph)->next;
 		stack_push(graph, next);
 	}
 
@@ -395,6 +396,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph graph;
 	struct media_entity *entity_err = entity;
+	struct media_link *link;
 	int ret;
 
 	mutex_lock(&mdev->graph_mutex);
@@ -404,7 +406,6 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		DECLARE_BITMAP(active, entity->num_pads);
 		DECLARE_BITMAP(has_no_links, entity->num_pads);
-		unsigned int i;
 
 		entity->stream_count++;
 		WARN_ON(entity->pipe && entity->pipe != pipe);
@@ -420,8 +421,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 		bitmap_zero(active, entity->num_pads);
 		bitmap_fill(has_no_links, entity->num_pads);
 
-		for (i = 0; i < entity->num_links; i++) {
-			struct media_link *link = &entity->links[i];
+		list_for_each_entry(link, &entity->links, list) {
 			struct media_pad *pad = link->sink->entity == entity
 						? link->sink : link->source;
 
@@ -582,25 +582,20 @@ EXPORT_SYMBOL_GPL(media_entity_put);
 
 static struct media_link *media_entity_add_link(struct media_entity *entity)
 {
-	if (entity->num_links >= entity->max_links) {
-		struct media_link *links = entity->links;
-		unsigned int max_links = entity->max_links + 2;
-		unsigned int i;
+	struct media_link *link;
 
-		links = krealloc(links, max_links * sizeof(*links), GFP_KERNEL);
-		if (links == NULL)
-			return NULL;
+	link = kzalloc(sizeof(*link), GFP_KERNEL);
+	if (link == NULL)
+		return NULL;
 
-		for (i = 0; i < entity->num_links; i++)
-			links[i].reverse->reverse = &links[i];
+	list_add_tail(&link->list, &entity->links);
 
-		entity->max_links = max_links;
-		entity->links = links;
-	}
-
-	return &entity->links[entity->num_links++];
+	return link;
 }
 
+static void __media_entity_remove_link(struct media_entity *entity,
+				       struct media_link *link);
+
 int
 media_create_pad_link(struct media_entity *source, u16 source_pad,
 			 struct media_entity *sink, u16 sink_pad, u32 flags)
@@ -629,7 +624,7 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	 */
 	backlink = media_entity_add_link(sink);
 	if (backlink == NULL) {
-		source->num_links--;
+		__media_entity_remove_link(source, link);
 		return -ENOMEM;
 	}
 
@@ -645,43 +640,51 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	backlink->reverse = link;
 
 	sink->num_backlinks++;
+	sink->num_links++;
+	source->num_links++;
 
 	return 0;
 }
 EXPORT_SYMBOL_GPL(media_create_pad_link);
 
-void __media_entity_remove_links(struct media_entity *entity)
+static void __media_entity_remove_link(struct media_entity *entity,
+				       struct media_link *link)
 {
-	unsigned int i;
+	struct media_link *rlink, *tmp;
+	struct media_entity *remote;
+	unsigned int r = 0;
 
-	for (i = 0; i < entity->num_links; i++) {
-		struct media_link *link = &entity->links[i];
-		struct media_entity *remote;
-		unsigned int r = 0;
+	if (link->source->entity == entity)
+		remote = link->sink->entity;
+	else
+		remote = link->source->entity;
+
+	list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
+		if (rlink != link->reverse) {
+			r++;
+			continue;
+		}
 
 		if (link->source->entity == entity)
-			remote = link->sink->entity;
-		else
-			remote = link->source->entity;
+			remote->num_backlinks--;
 
-		while (r < remote->num_links) {
-			struct media_link *rlink = &remote->links[r];
+		if (--remote->num_links == 0)
+			break;
 
-			if (rlink != link->reverse) {
-				r++;
-				continue;
-			}
-
-			if (link->source->entity == entity)
-				remote->num_backlinks--;
-
-			if (--remote->num_links == 0)
-				break;
-
-			/* Insert last entry in place of the dropped link. */
-			*rlink = remote->links[remote->num_links];
-		}
+		/* Remove the remote link */
+		list_del(&rlink->list);
+		kfree(rlink);
 	}
+	list_del(&link->list);
+	kfree(link);
+}
+
+void __media_entity_remove_links(struct media_entity *entity)
+{
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &entity->links, list)
+		__media_entity_remove_link(entity, link);
 
 	entity->num_links = 0;
 	entity->num_backlinks = 0;
@@ -806,11 +809,8 @@ struct media_link *
 media_entity_find_link(struct media_pad *source, struct media_pad *sink)
 {
 	struct media_link *link;
-	unsigned int i;
-
-	for (i = 0; i < source->entity->num_links; ++i) {
-		link = &source->entity->links[i];
 
+	list_for_each_entry(link, &source->entity->links, list) {
 		if (link->source->entity == source->entity &&
 		    link->source->index == source->index &&
 		    link->sink->entity == sink->entity &&
@@ -834,11 +834,9 @@ EXPORT_SYMBOL_GPL(media_entity_find_link);
  */
 struct media_pad *media_entity_remote_pad(struct media_pad *pad)
 {
-	unsigned int i;
-
-	for (i = 0; i < pad->entity->num_links; i++) {
-		struct media_link *link = &pad->entity->links[i];
+	struct media_link *link;
 
+	list_for_each_entry(link, &pad->entity->links, list) {
 		if (!(link->flags & MEDIA_LNK_FL_ENABLED))
 			continue;
 
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index a55eb524ea21..7f645bcb7463 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -261,13 +261,11 @@ static void au0828_create_media_graph(struct au0828_dev *dev)
 
 	if (tuner)
 		media_create_pad_link(tuner, 0, decoder, 0,
-					 MEDIA_LNK_FL_ENABLED);
-	if (dev->vdev.entity.links)
-		media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
-				 MEDIA_LNK_FL_ENABLED);
-	if (dev->vbi_dev.entity.links)
-		media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
-				 MEDIA_LNK_FL_ENABLED);
+				      MEDIA_LNK_FL_ENABLED);
+	media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
+			      MEDIA_LNK_FL_ENABLED);
+	media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
+			      MEDIA_LNK_FL_ENABLED);
 #endif
 }
 
diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 2c040056d4eb..4511e2893282 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -643,7 +643,7 @@ static int au0828_enable_analog_tuner(struct au0828_dev *dev)
 	struct media_device *mdev = dev->media_dev;
 	struct media_entity *source;
 	struct media_link *link, *found_link = NULL;
-	int i, ret, active_links = 0;
+	int ret, active_links = 0;
 
 	if (!mdev || !dev->decoder)
 		return 0;
@@ -655,8 +655,7 @@ static int au0828_enable_analog_tuner(struct au0828_dev *dev)
 	 * do DVB streaming while the DMA engine is being used for V4L2,
 	 * this should be enough for the actual needs.
 	 */
-	for (i = 0; i < dev->decoder->num_links; i++) {
-		link = &dev->decoder->links[i];
+	list_for_each_entry(link, &dev->decoder->links, list) {
 		if (link->sink->entity == dev->decoder) {
 			found_link = link;
 			if (link->flags & MEDIA_LNK_FL_ENABLED)
@@ -669,11 +668,10 @@ static int au0828_enable_analog_tuner(struct au0828_dev *dev)
 		return 0;
 
 	source = found_link->source->entity;
-	for (i = 0; i < source->num_links; i++) {
+	list_for_each_entry(link, &source->links, list) {
 		struct media_entity *sink;
 		int flags = 0;
 
-		link = &source->links[i];
 		sink = link->sink->entity;
 
 		if (sink == dev->decoder)
diff --git a/drivers/media/usb/cx231xx/cx231xx-video.c b/drivers/media/usb/cx231xx/cx231xx-video.c
index 8f04b125486f..e8baff4d6290 100644
--- a/drivers/media/usb/cx231xx/cx231xx-video.c
+++ b/drivers/media/usb/cx231xx/cx231xx-video.c
@@ -106,7 +106,7 @@ static int cx231xx_enable_analog_tuner(struct cx231xx *dev)
 	struct media_device *mdev = dev->media_dev;
 	struct media_entity  *entity, *decoder = NULL, *source;
 	struct media_link *link, *found_link = NULL;
-	int i, ret, active_links = 0;
+	int ret, active_links = 0;
 
 	if (!mdev)
 		return 0;
@@ -127,8 +127,7 @@ static int cx231xx_enable_analog_tuner(struct cx231xx *dev)
 	if (!decoder)
 		return 0;
 
-	for (i = 0; i < decoder->num_links; i++) {
-		link = &decoder->links[i];
+	list_for_each_entry(link, &decoder->links, list) {
 		if (link->sink->entity == decoder) {
 			found_link = link;
 			if (link->flags & MEDIA_LNK_FL_ENABLED)
@@ -141,11 +140,10 @@ static int cx231xx_enable_analog_tuner(struct cx231xx *dev)
 		return 0;
 
 	source = found_link->source->entity;
-	for (i = 0; i < source->num_links; i++) {
+	list_for_each_entry(link, &source->links, list) {
 		struct media_entity *sink;
 		int flags = 0;
 
-		link = &source->links[i];
 		sink = link->sink->entity;
 
 		if (sink == entity)
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 7df8836f4eef..7016f0619415 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -74,6 +74,7 @@ struct media_pipeline {
 
 struct media_link {
 	struct media_gobj graph_obj;
+	struct list_head list;
 	struct media_pad *source;	/* Source pad */
 	struct media_pad *sink;		/* Sink pad  */
 	struct media_link *reverse;	/* Link in the reverse direction */
@@ -116,10 +117,9 @@ struct media_entity {
 	u16 num_links;			/* Number of existing links, both
 					 * enabled and disabled */
 	u16 num_backlinks;		/* Number of backlinks */
-	u16 max_links;			/* Maximum number of links */
 
-	struct media_pad *pads;		/* Pads array (num_pads elements) */
-	struct media_link *links;	/* Links array (max_links elements)*/
+	struct media_pad *pads;		/* Pads array (num_pads objects) */
+	struct list_head links;		/* Links list */
 
 	const struct media_entity_operations *ops;	/* Entity operations */
 
@@ -213,7 +213,7 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
 struct media_entity_graph {
 	struct {
 		struct media_entity *entity;
-		int link;
+		struct list_head *link;
 	} stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
 
 	DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID);
@@ -247,7 +247,7 @@ void media_gobj_init(struct media_device *mdev,
 void media_gobj_remove(struct media_gobj *gobj);
 
 int media_entity_init(struct media_entity *entity, u16 num_pads,
-		struct media_pad *pads);
+		      struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
 
 int media_create_pad_link(struct media_entity *source, u16 source_pad,
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 20/55] [media] media: make add link more generic
  2015-08-30  3:06 ` [PATCH v8 20/55] [media] media: make add link more generic Mauro Carvalho Chehab
  2015-08-31 10:44   ` Hans Verkuil
@ 2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

The media_entity_add_link() function takes an entity
as an argument just to get the list head.

Make it more generic by changing the function argument
to list_head.

No functional changes.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index d5efa0e2c88c..625b505e8496 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -580,7 +580,7 @@ EXPORT_SYMBOL_GPL(media_entity_put);
  * Links management
  */
 
-static struct media_link *media_entity_add_link(struct media_entity *entity)
+static struct media_link *media_add_link(struct list_head *head)
 {
 	struct media_link *link;
 
@@ -588,7 +588,7 @@ static struct media_link *media_entity_add_link(struct media_entity *entity)
 	if (link == NULL)
 		return NULL;
 
-	list_add_tail(&link->list, &entity->links);
+	list_add_tail(&link->list, head);
 
 	return link;
 }
@@ -607,7 +607,7 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	BUG_ON(source_pad >= source->num_pads);
 	BUG_ON(sink_pad >= sink->num_pads);
 
-	link = media_entity_add_link(source);
+	link = media_add_link(&source->links);
 	if (link == NULL)
 		return -ENOMEM;
 
@@ -622,7 +622,7 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	/* Create the backlink. Backlinks are used to help graph traversal and
 	 * are not reported to userspace.
 	 */
-	backlink = media_entity_add_link(sink);
+	backlink = media_add_link(&sink->links);
 	if (backlink == NULL) {
 		__media_entity_remove_link(source, link);
 		return -ENOMEM;
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 21/55] [media] media: make media_link more generic to handle interace links
  2015-08-30  3:06 ` [PATCH v8 21/55] [media] media: make media_link more generic to handle interace links Mauro Carvalho Chehab
  2015-08-31 10:44   ` Hans Verkuil
@ 2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

By adding an union at media_link, we get for free a way to
represent interface->entity links.

No need to change anything at the code, just at the internal
header file.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 7016f0619415..6015e996f213 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -75,14 +75,20 @@ struct media_pipeline {
 struct media_link {
 	struct media_gobj graph_obj;
 	struct list_head list;
-	struct media_pad *source;	/* Source pad */
-	struct media_pad *sink;		/* Sink pad  */
+	union {
+		struct media_gobj *gobj0;
+		struct media_pad *source;
+	};
+	union {
+		struct media_gobj *gobj1;
+		struct media_pad *sink;
+	};
 	struct media_link *reverse;	/* Link in the reverse direction */
 	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
 };
 
 struct media_pad {
-	struct media_gobj graph_obj;
+	struct media_gobj graph_obj;	/* must be first field in struct */
 	struct media_entity *entity;	/* Entity this pad belongs to */
 	u16 index;			/* Pad index in the entity pads array */
 	unsigned long flags;		/* Pad flags (MEDIA_PAD_FL_*) */
@@ -105,7 +111,7 @@ struct media_entity_operations {
 };
 
 struct media_entity {
-	struct media_gobj graph_obj;
+	struct media_gobj graph_obj;	/* must be first field in struct */
 	struct list_head list;
 	const char *name;		/* Entity name */
 	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
@@ -119,7 +125,7 @@ struct media_entity {
 	u16 num_backlinks;		/* Number of backlinks */
 
 	struct media_pad *pads;		/* Pads array (num_pads objects) */
-	struct list_head links;		/* Links list */
+	struct list_head links;		/* Pad-to-pad links list */
 
 	const struct media_entity_operations *ops;	/* Entity operations */
 
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 22/55] [media] media: make link debug printk more generic
  2015-08-30  3:06 ` [PATCH v8 22/55] [media] media: make link debug printk more generic Mauro Carvalho Chehab
@ 2015-09-06 12:02   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

Remove entity name from the link as this exists only if the object
type is PAD on both link ends.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 625b505e8496..f9c6c2a81903 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -106,16 +106,14 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 		struct media_link *link = gobj_to_link(gobj);
 
 		dev_dbg(gobj->mdev->dev,
-			"%s: id 0x%08x link#%d: '%s' %s#%d ==> '%s' %s#%d\n",
+			"%s: id 0x%08x link#%d: %s#%d ==> %s#%d\n",
 			event_name, gobj->id, media_localid(gobj),
 
-			link->source->entity->name,
-			gobj_type(media_type(&link->source->graph_obj)),
-			media_localid(&link->source->graph_obj),
+			gobj_type(media_type(link->gobj0)),
+			media_localid(link->gobj0),
 
-			link->sink->entity->name,
-			gobj_type(media_type(&link->sink->graph_obj)),
-			media_localid(&link->sink->graph_obj));
+			gobj_type(media_type(link->gobj1)),
+			media_localid(link->gobj1));
 		break;
 	}
 	case MEDIA_GRAPH_PAD:
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 23/55] [media] media: add support to link interfaces and entities
  2015-08-30  3:06 ` [PATCH v8 23/55] [media] media: add support to link interfaces and entities Mauro Carvalho Chehab
  2015-08-31 10:48   ` Hans Verkuil
@ 2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

Now that we have a new graph object called "interfaces", we
need to be able to link them to the entities.

Add a linked list to the interfaces to allow them to be
linked to the entities.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index f9c6c2a81903..8e17272936c9 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -869,6 +869,7 @@ struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
 
 	intf->type = type;
 	intf->flags = flags;
+	INIT_LIST_HEAD(&intf->links);
 
 	devnode->major = major;
 	devnode->minor = minor;
@@ -886,3 +887,40 @@ void media_devnode_remove(struct media_intf_devnode *devnode)
 	kfree(devnode);
 }
 EXPORT_SYMBOL_GPL(media_devnode_remove);
+
+struct media_link *media_create_intf_link(struct media_entity *entity,
+					    struct media_interface *intf,
+					    u32 flags)
+{
+	struct media_link *link;
+
+	link = media_add_link(&intf->links);
+	if (link == NULL)
+		return NULL;
+
+	link->intf = intf;
+	link->entity = entity;
+	link->flags = flags;
+
+	/* Initialize graph object embedded at the new link */
+	media_gobj_init(intf->graph_obj.mdev, MEDIA_GRAPH_LINK,
+			&link->graph_obj);
+
+	return link;
+}
+EXPORT_SYMBOL_GPL(media_create_intf_link);
+
+
+static void __media_remove_intf_link(struct media_link *link)
+{
+	media_gobj_remove(&link->graph_obj);
+	kfree(link);
+}
+
+void media_remove_intf_link(struct media_link *link)
+{
+	mutex_lock(&link->graph_obj.mdev->graph_mutex);
+	__media_remove_intf_link(link);
+	mutex_unlock(&link->graph_obj.mdev->graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_remove_intf_link);
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 6015e996f213..f67c01419268 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -78,10 +78,12 @@ struct media_link {
 	union {
 		struct media_gobj *gobj0;
 		struct media_pad *source;
+		struct media_interface *intf;
 	};
 	union {
 		struct media_gobj *gobj1;
 		struct media_pad *sink;
+		struct media_entity *entity;
 	};
 	struct media_link *reverse;	/* Link in the reverse direction */
 	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
@@ -154,6 +156,7 @@ struct media_entity {
  * struct media_intf_devnode - Define a Kernel API interface
  *
  * @graph_obj:		embedded graph object
+ * @links:		List of links pointing to graph entities
  * @type:		Type of the interface as defined at the
  *			uapi/media/media.h header, e. g.
  *			MEDIA_INTF_T_*
@@ -161,6 +164,7 @@ struct media_entity {
  */
 struct media_interface {
 	struct media_gobj		graph_obj;
+	struct list_head		links;
 	u32				type;
 	u32				flags;
 };
@@ -283,6 +287,11 @@ struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
 						u32 major, u32 minor,
 						gfp_t gfp_flags);
 void media_devnode_remove(struct media_intf_devnode *devnode);
+struct media_link *media_create_intf_link(struct media_entity *entity,
+					    struct media_interface *intf,
+					    u32 flags);
+void media_remove_intf_link(struct media_link *link);
+
 #define media_entity_call(entity, operation, args...)			\
 	(((entity)->ops && (entity)->ops->operation) ?			\
 	 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 24/55] [media] media-entity: add a helper function to create interface
  2015-08-30  3:06 ` [PATCH v8 24/55] [media] media-entity: add a helper function to create interface Mauro Carvalho Chehab
  2015-08-31 10:49   ` Hans Verkuil
@ 2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

As we'll be adding other interface types in the future, put the
common interface create code on a separate function.

Suggested-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 8e17272936c9..74aaa5a5d5bc 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -851,6 +851,18 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
 
 
+static void media_interface_init(struct media_device *mdev,
+				 struct media_interface *intf,
+				 u32 gobj_type,
+				 u32 intf_type, u32 flags)
+{
+	intf->type = intf_type;
+	intf->flags = flags;
+	INIT_LIST_HEAD(&intf->links);
+
+	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
+}
+
 /* Functions related to the media interface via device nodes */
 
 struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
@@ -859,23 +871,16 @@ struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
 						gfp_t gfp_flags)
 {
 	struct media_intf_devnode *devnode;
-	struct media_interface *intf;
 
 	devnode = kzalloc(sizeof(*devnode), gfp_flags);
 	if (!devnode)
 		return NULL;
 
-	intf = &devnode->intf;
-
-	intf->type = type;
-	intf->flags = flags;
-	INIT_LIST_HEAD(&intf->links);
-
 	devnode->major = major;
 	devnode->minor = minor;
 
-	media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
-		       &devnode->intf.graph_obj);
+	media_interface_init(mdev, &devnode->intf, MEDIA_GRAPH_INTF_DEVNODE,
+			     type, flags);
 
 	return devnode;
 }
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 26/55] [media] media: add a linked list to track interfaces by mdev
  2015-08-30  3:06 ` [PATCH v8 26/55] [media] media: add a linked list to track interfaces by mdev Mauro Carvalho Chehab
  2015-08-31 10:52   ` Hans Verkuil
@ 2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

The media device should list the interface objects, so add a linked list
for those interfaces in struct media_device.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 3e649cacfc07..659507bce63f 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -381,6 +381,7 @@ int __must_check __media_device_register(struct media_device *mdev,
 		return -EINVAL;
 
 	INIT_LIST_HEAD(&mdev->entities);
+	INIT_LIST_HEAD(&mdev->interfaces);
 	spin_lock_init(&mdev->lock);
 	mutex_init(&mdev->graph_mutex);
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 74aaa5a5d5bc..d8038a53f945 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -861,6 +861,8 @@ static void media_interface_init(struct media_device *mdev,
 	INIT_LIST_HEAD(&intf->links);
 
 	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
+
+	list_add_tail(&intf->list, &mdev->interfaces);
 }
 
 /* Functions related to the media interface via device nodes */
@@ -889,6 +891,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
 	media_gobj_remove(&devnode->intf.graph_obj);
+	list_del(&devnode->intf.list);
 	kfree(devnode);
 }
 EXPORT_SYMBOL_GPL(media_devnode_remove);
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 3b14394d5701..51807efa505b 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -46,6 +46,7 @@ struct device;
  * @link_id:	Unique ID used on the last link registered
  * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:	List of registered entities
+ * @interfaces:	List of registered interfaces
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
  * @link_notify: Link state change notification callback
@@ -77,6 +78,7 @@ struct media_device {
 	u32 intf_devnode_id;
 
 	struct list_head entities;
+	struct list_head interfaces;
 
 	/* Protects the entities list */
 	spinlock_t lock;
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index f67c01419268..4e36b1f2b2d7 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -156,6 +156,8 @@ struct media_entity {
  * struct media_intf_devnode - Define a Kernel API interface
  *
  * @graph_obj:		embedded graph object
+ * @list:		Linked list used to find other interfaces that belong
+ *			to the same media controller
  * @links:		List of links pointing to graph entities
  * @type:		Type of the interface as defined at the
  *			uapi/media/media.h header, e. g.
@@ -164,6 +166,7 @@ struct media_entity {
  */
 struct media_interface {
 	struct media_gobj		graph_obj;
+	struct list_head		list;
 	struct list_head		links;
 	u32				type;
 	u32				flags;
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 27/55] [media] dvbdev: add support for indirect interface links
  2015-08-30  3:06 ` [PATCH v8 27/55] [media] dvbdev: add support for indirect interface links Mauro Carvalho Chehab
  2015-08-31 10:54   ` Hans Verkuil
@ 2015-09-06 12:02   ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Hans Verkuil, Sakari Ailus, Laurent Pinchart

Some interfaces indirectly control multiple entities.
Add support for those.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 6bf61d42c017..ada0738d26f2 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -441,6 +441,7 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	struct media_device *mdev = adap->mdev;
 	struct media_entity *entity, *tuner = NULL, *fe = NULL;
 	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
+	struct media_interface *intf;
 
 	if (!mdev)
 		return;
@@ -476,6 +477,16 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 
 	if (demux && ca)
 		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
+
+	/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca */
+	list_for_each_entry(intf, &mdev->interfaces, list) {
+		if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
+			media_create_intf_link(ca, intf, 0);
+		if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
+			media_create_intf_link(tuner, intf, 0);
+		if (intf->type == MEDIA_INTF_T_DVB_DVR && demux)
+			media_create_intf_link(demux, intf, 0);
+	}
 }
 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
 #endif
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 28/55] [media] uapi/media.h: Fix entity namespace
@ 2015-09-06 12:02     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Hans Verkuil, Laurent Pinchart,
	Sakari Ailus, linux-api

Now that interfaces got created, we need to fix the entity
namespace.

So, let's create a consistent new namespace and add backward
compatibility macros to keep the old namespace preserved.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index ada0738d26f2..dadcf1655070 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -230,17 +230,17 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
 
 	switch (type) {
 	case DVB_DEVICE_FRONTEND:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_FE;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMOD;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
 	case DVB_DEVICE_DEMUX:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_DEMUX;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMUX;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
 	case DVB_DEVICE_CA:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_CA;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_CA;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
@@ -439,7 +439,7 @@ EXPORT_SYMBOL(dvb_unregister_device);
 void dvb_create_media_graph(struct dvb_adapter *adap)
 {
 	struct media_device *mdev = adap->mdev;
-	struct media_entity *entity, *tuner = NULL, *fe = NULL;
+	struct media_entity *entity, *tuner = NULL, *demod = NULL;
 	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
 	struct media_interface *intf;
 
@@ -451,26 +451,26 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 		case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
 			tuner = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_FE:
-			fe = entity;
+		case MEDIA_ENT_T_DVB_DEMOD:
+			demod = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_DEMUX:
+		case MEDIA_ENT_T_DVB_DEMUX:
 			demux = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_DVR:
+		case MEDIA_ENT_T_DVB_TSOUT:
 			dvr = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_CA:
+		case MEDIA_ENT_T_DVB_CA:
 			ca = entity;
 			break;
 		}
 	}
 
-	if (tuner && fe)
-		media_create_pad_link(tuner, 0, fe, 0, 0);
+	if (tuner && demod)
+		media_create_pad_link(tuner, 0, demod, 0, 0);
 
-	if (fe && demux)
-		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
+	if (demod && demux)
+		media_create_pad_link(demod, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && dvr)
 		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index aca828709bad..f8725b881a1d 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -42,31 +42,69 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
+/*
+ * Base numbers for entity types
+ *
+ * Please notice that the huge gap of 16 bits for each base is overkill!
+ * 8 bits is more than enough to avoid starving entity types for each
+ * subsystem.
+ *
+ * However, It is kept this way just to avoid binary breakages with the
+ * namespace provided on legacy versions of this header.
+ */
+#define MEDIA_ENT_T_DVB_BASE		0x00000000
+#define MEDIA_ENT_T_V4L2_BASE		0x00010000
+#define MEDIA_ENT_T_V4L2_SUBDEV_BASE	0x00020000
+
+/*
+ * V4L2 entities - Those are used for DMA (mmap/DMABUF) and
+ *	read()/write() data I/O associated with the V4L2 devnodes.
+ */
+#define MEDIA_ENT_T_V4L2_VIDEO		(MEDIA_ENT_T_V4L2_BASE + 1)
+	/*
+	 * Please notice that numbers between MEDIA_ENT_T_V4L2_BASE + 2 and
+	 * MEDIA_ENT_T_V4L2_BASE + 4 can't be used, as those values used
+	 * to be declared for FB, ALSA and DVB entities.
+	 * As those values were never actually used in practice, we're just
+	 * adding them as backward compatibility macros and keeping the
+	 * numberspace clean here. This way, we avoid breaking compilation,
+	 * in the case of having some userspace application using the old
+	 * symbols.
+	 */
+#define MEDIA_ENT_T_V4L2_VBI		(MEDIA_ENT_T_V4L2_BASE + 5)
+#define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 6)
+
+/* V4L2 Sub-device entities */
+#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
+#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
+#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
+	/* A converter of analogue video to its digital representation. */
+#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 4)
+	/* Tuner entity is actually both V4L2 and DVB subdev */
+#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 5)
+
+/* DVB entities */
+#define MEDIA_ENT_T_DVB_DEMOD		(MEDIA_ENT_T_DVB_BASE + 1)
+#define MEDIA_ENT_T_DVB_DEMUX		(MEDIA_ENT_T_DVB_BASE + 2)
+#define MEDIA_ENT_T_DVB_TSOUT		(MEDIA_ENT_T_DVB_BASE + 3)
+#define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 4)
+#define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 5)
+
+/* Legacy symbols used to avoid userspace compilation breakages */
 #define MEDIA_ENT_TYPE_SHIFT		16
 #define MEDIA_ENT_TYPE_MASK		0x00ff0000
 #define MEDIA_ENT_SUBTYPE_MASK		0x0000ffff
 
-#define MEDIA_ENT_T_DEVNODE		(1 << MEDIA_ENT_TYPE_SHIFT)
-#define MEDIA_ENT_T_DEVNODE_V4L		(MEDIA_ENT_T_DEVNODE + 1)
+#define MEDIA_ENT_T_DEVNODE		MEDIA_ENT_T_V4L2_BASE
+#define MEDIA_ENT_T_V4L2_SUBDEV		MEDIA_ENT_T_V4L2_SUBDEV_BASE
+
+#define MEDIA_ENT_T_DEVNODE_V4L		MEDIA_ENT_T_V4L2_VIDEO
+
 #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
 #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
-#define MEDIA_ENT_T_DEVNODE_DVB_FE	(MEDIA_ENT_T_DEVNODE + 4)
-#define MEDIA_ENT_T_DEVNODE_DVB_DEMUX	(MEDIA_ENT_T_DEVNODE + 5)
-#define MEDIA_ENT_T_DEVNODE_DVB_DVR	(MEDIA_ENT_T_DEVNODE + 6)
-#define MEDIA_ENT_T_DEVNODE_DVB_CA	(MEDIA_ENT_T_DEVNODE + 7)
-#define MEDIA_ENT_T_DEVNODE_DVB_NET	(MEDIA_ENT_T_DEVNODE + 8)
+#define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
 
-/* Legacy symbol. Use it to avoid userspace compilation breakages */
-#define MEDIA_ENT_T_DEVNODE_DVB		MEDIA_ENT_T_DEVNODE_DVB_FE
-
-#define MEDIA_ENT_T_V4L2_SUBDEV		(2 << MEDIA_ENT_TYPE_SHIFT)
-#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV + 1)
-#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV + 2)
-#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV + 3)
-/* A converter of analogue video to its digital representation. */
-#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV + 4)
-
-#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV + 5)
+/* Entity types */
 
 #define MEDIA_ENT_FL_DEFAULT		(1 << 0)
 
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 28/55] [media] uapi/media.h: Fix entity namespace
@ 2015-09-06 12:02     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Hans Verkuil, Laurent Pinchart,
	Sakari Ailus, linux-api-u79uwXL29TY76Z2rM5mHXA

Now that interfaces got created, we need to fix the entity
namespace.

So, let's create a consistent new namespace and add backward
compatibility macros to keep the old namespace preserved.

Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index ada0738d26f2..dadcf1655070 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -230,17 +230,17 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
 
 	switch (type) {
 	case DVB_DEVICE_FRONTEND:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_FE;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMOD;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
 	case DVB_DEVICE_DEMUX:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_DEMUX;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMUX;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
 	case DVB_DEVICE_CA:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_CA;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_CA;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
@@ -439,7 +439,7 @@ EXPORT_SYMBOL(dvb_unregister_device);
 void dvb_create_media_graph(struct dvb_adapter *adap)
 {
 	struct media_device *mdev = adap->mdev;
-	struct media_entity *entity, *tuner = NULL, *fe = NULL;
+	struct media_entity *entity, *tuner = NULL, *demod = NULL;
 	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
 	struct media_interface *intf;
 
@@ -451,26 +451,26 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 		case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
 			tuner = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_FE:
-			fe = entity;
+		case MEDIA_ENT_T_DVB_DEMOD:
+			demod = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_DEMUX:
+		case MEDIA_ENT_T_DVB_DEMUX:
 			demux = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_DVR:
+		case MEDIA_ENT_T_DVB_TSOUT:
 			dvr = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_CA:
+		case MEDIA_ENT_T_DVB_CA:
 			ca = entity;
 			break;
 		}
 	}
 
-	if (tuner && fe)
-		media_create_pad_link(tuner, 0, fe, 0, 0);
+	if (tuner && demod)
+		media_create_pad_link(tuner, 0, demod, 0, 0);
 
-	if (fe && demux)
-		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
+	if (demod && demux)
+		media_create_pad_link(demod, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && dvr)
 		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index aca828709bad..f8725b881a1d 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -42,31 +42,69 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
+/*
+ * Base numbers for entity types
+ *
+ * Please notice that the huge gap of 16 bits for each base is overkill!
+ * 8 bits is more than enough to avoid starving entity types for each
+ * subsystem.
+ *
+ * However, It is kept this way just to avoid binary breakages with the
+ * namespace provided on legacy versions of this header.
+ */
+#define MEDIA_ENT_T_DVB_BASE		0x00000000
+#define MEDIA_ENT_T_V4L2_BASE		0x00010000
+#define MEDIA_ENT_T_V4L2_SUBDEV_BASE	0x00020000
+
+/*
+ * V4L2 entities - Those are used for DMA (mmap/DMABUF) and
+ *	read()/write() data I/O associated with the V4L2 devnodes.
+ */
+#define MEDIA_ENT_T_V4L2_VIDEO		(MEDIA_ENT_T_V4L2_BASE + 1)
+	/*
+	 * Please notice that numbers between MEDIA_ENT_T_V4L2_BASE + 2 and
+	 * MEDIA_ENT_T_V4L2_BASE + 4 can't be used, as those values used
+	 * to be declared for FB, ALSA and DVB entities.
+	 * As those values were never actually used in practice, we're just
+	 * adding them as backward compatibility macros and keeping the
+	 * numberspace clean here. This way, we avoid breaking compilation,
+	 * in the case of having some userspace application using the old
+	 * symbols.
+	 */
+#define MEDIA_ENT_T_V4L2_VBI		(MEDIA_ENT_T_V4L2_BASE + 5)
+#define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 6)
+
+/* V4L2 Sub-device entities */
+#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
+#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
+#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
+	/* A converter of analogue video to its digital representation. */
+#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 4)
+	/* Tuner entity is actually both V4L2 and DVB subdev */
+#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 5)
+
+/* DVB entities */
+#define MEDIA_ENT_T_DVB_DEMOD		(MEDIA_ENT_T_DVB_BASE + 1)
+#define MEDIA_ENT_T_DVB_DEMUX		(MEDIA_ENT_T_DVB_BASE + 2)
+#define MEDIA_ENT_T_DVB_TSOUT		(MEDIA_ENT_T_DVB_BASE + 3)
+#define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 4)
+#define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 5)
+
+/* Legacy symbols used to avoid userspace compilation breakages */
 #define MEDIA_ENT_TYPE_SHIFT		16
 #define MEDIA_ENT_TYPE_MASK		0x00ff0000
 #define MEDIA_ENT_SUBTYPE_MASK		0x0000ffff
 
-#define MEDIA_ENT_T_DEVNODE		(1 << MEDIA_ENT_TYPE_SHIFT)
-#define MEDIA_ENT_T_DEVNODE_V4L		(MEDIA_ENT_T_DEVNODE + 1)
+#define MEDIA_ENT_T_DEVNODE		MEDIA_ENT_T_V4L2_BASE
+#define MEDIA_ENT_T_V4L2_SUBDEV		MEDIA_ENT_T_V4L2_SUBDEV_BASE
+
+#define MEDIA_ENT_T_DEVNODE_V4L		MEDIA_ENT_T_V4L2_VIDEO
+
 #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
 #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
-#define MEDIA_ENT_T_DEVNODE_DVB_FE	(MEDIA_ENT_T_DEVNODE + 4)
-#define MEDIA_ENT_T_DEVNODE_DVB_DEMUX	(MEDIA_ENT_T_DEVNODE + 5)
-#define MEDIA_ENT_T_DEVNODE_DVB_DVR	(MEDIA_ENT_T_DEVNODE + 6)
-#define MEDIA_ENT_T_DEVNODE_DVB_CA	(MEDIA_ENT_T_DEVNODE + 7)
-#define MEDIA_ENT_T_DEVNODE_DVB_NET	(MEDIA_ENT_T_DEVNODE + 8)
+#define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
 
-/* Legacy symbol. Use it to avoid userspace compilation breakages */
-#define MEDIA_ENT_T_DEVNODE_DVB		MEDIA_ENT_T_DEVNODE_DVB_FE
-
-#define MEDIA_ENT_T_V4L2_SUBDEV		(2 << MEDIA_ENT_TYPE_SHIFT)
-#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV + 1)
-#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV + 2)
-#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV + 3)
-/* A converter of analogue video to its digital representation. */
-#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV + 4)
-
-#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV + 5)
+/* Entity types */
 
 #define MEDIA_ENT_FL_DEFAULT		(1 << 0)
 
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA
  2015-08-30  3:06 ` [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA Mauro Carvalho Chehab
  2015-08-31 11:31   ` Hans Verkuil
@ 2015-09-06 12:02   ` Mauro Carvalho Chehab
  2015-12-06  2:20     ` Laurent Pinchart
  1 sibling, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

As we'll be removing entity subtypes from the Kernel, we need
to provide a way for drivers and core to check if a given
entity is represented by a V4L2 subdev or if it is an V4L2
I/O entity (typically with DMA).

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 4e36b1f2b2d7..220864319d21 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -220,6 +220,39 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
 	return id;
 }
 
+static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_VIDEO:
+	case MEDIA_ENT_T_V4L2_VBI:
+	case MEDIA_ENT_T_V4L2_SWRADIO:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
+	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
+	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
+	case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
+	case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
+		return true;
+
+	default:
+		return false;
+	}
+}
+
 #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
 #define MEDIA_ENTITY_ENUM_MAX_ID	64
 
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 38/55] [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs
  2015-08-30  3:06 ` [PATCH v8 38/55] [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs Mauro Carvalho Chehab
  2015-08-31 11:43     ` Hans Verkuil
@ 2015-09-06 12:02   ` Mauro Carvalho Chehab
  2015-12-06  1:37     ` Laurent Pinchart
  1 sibling, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Hans Verkuil, Laurent Pinchart,
	Sylwester Nawrocki, Lad, Prabhakar, Markus Elfring,
	Lars-Peter Clausen, linux-api

Instead of abusing MEDIA_ENT_T_V4L2_SUBDEV, initialize
new subdev entities as MEDIA_ENT_T_UNKNOWN.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 659507bce63f..134fe7510195 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -435,6 +435,12 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 {
 	int i;
 
+	if (entity->type == MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN ||
+	    entity->type == MEDIA_ENT_T_UNKNOWN)
+		dev_warn(mdev->dev,
+			 "Entity type for entity %s was not initialized!\n",
+			 entity->name);
+
 	/* Warn if we apparently re-register an entity */
 	WARN_ON(entity->graph_obj.mdev != NULL);
 	entity->graph_obj.mdev = mdev;
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index 60da43772de9..b3bcc8253182 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -584,7 +584,7 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops)
 	sd->host_priv = NULL;
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	sd->entity.name = sd->name;
-	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
+	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN;
 #endif
 }
 EXPORT_SYMBOL(v4l2_subdev_init);
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index f8725b881a1d..3d6210095336 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -42,6 +42,14 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
+/* Used values for media_entity_desc::type */
+
+/*
+ * Initial value to be used when a new entity is created
+ * Drivers should change it to something useful
+ */
+#define MEDIA_ENT_T_UNKNOWN	0x00000000
+
 /*
  * Base numbers for entity types
  *
@@ -75,6 +83,15 @@ struct media_device_info {
 #define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 6)
 
 /* V4L2 Sub-device entities */
+
+	/*
+	 * Subdevs are initialized with MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN,
+	 * in order to preserve backward compatibility.
+	 * Drivers should change to the proper subdev type before
+	 * registering the entity.
+	 */
+#define MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN	MEDIA_ENT_T_V4L2_SUBDEV_BASE
+
 #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
 #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
 #define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 39/55] [media] media controller: get rid of entity subtype on Kernel
@ 2015-09-06 12:02     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, linux-api

Don't use anymore the type/subtype entity data/macros
inside the Kernel.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 220864319d21..7320cdc45833 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -185,16 +185,6 @@ struct media_intf_devnode {
 	u32				minor;
 };
 
-static inline u32 media_entity_type(struct media_entity *entity)
-{
-	return entity->type & MEDIA_ENT_TYPE_MASK;
-}
-
-static inline u32 media_entity_subtype(struct media_entity *entity)
-{
-	return entity->type & MEDIA_ENT_SUBTYPE_MASK;
-}
-
 static inline u32 media_entity_id(struct media_entity *entity)
 {
 	return entity->graph_obj.id;
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 3d6210095336..f90147cb9b57 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -42,8 +42,6 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
-/* Used values for media_entity_desc::type */
-
 /*
  * Initial value to be used when a new entity is created
  * Drivers should change it to something useful
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 39/55] [media] media controller: get rid of entity subtype on Kernel
@ 2015-09-06 12:02     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:02 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, linux-api-u79uwXL29TY76Z2rM5mHXA

Don't use anymore the type/subtype entity data/macros
inside the Kernel.

Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 220864319d21..7320cdc45833 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -185,16 +185,6 @@ struct media_intf_devnode {
 	u32				minor;
 };
 
-static inline u32 media_entity_type(struct media_entity *entity)
-{
-	return entity->type & MEDIA_ENT_TYPE_MASK;
-}
-
-static inline u32 media_entity_subtype(struct media_entity *entity)
-{
-	return entity->type & MEDIA_ENT_SUBTYPE_MASK;
-}
-
 static inline u32 media_entity_id(struct media_entity *entity)
 {
 	return entity->graph_obj.id;
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 3d6210095336..f90147cb9b57 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -42,8 +42,6 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
-/* Used values for media_entity_desc::type */
-
 /*
  * Initial value to be used when a new entity is created
  * Drivers should change it to something useful
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 40/55] [media] media.h: don't use legacy entity macros at Kernel
@ 2015-09-06 12:03     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, linux-api

Put the legacy MEDIA_ENT_* macros under a #ifndef __KERNEL__,
in order to be sure that none of those old symbols are used
inside the Kernel.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index f90147cb9b57..a1bd7afba110 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -105,6 +105,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 4)
 #define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 5)
 
+#ifndef __KERNEL__
 /* Legacy symbols used to avoid userspace compilation breakages */
 #define MEDIA_ENT_TYPE_SHIFT		16
 #define MEDIA_ENT_TYPE_MASK		0x00ff0000
@@ -118,6 +119,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
 #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
 #define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
+#endif
 
 /* Entity types */
 
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 40/55] [media] media.h: don't use legacy entity macros at Kernel
@ 2015-09-06 12:03     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, linux-api-u79uwXL29TY76Z2rM5mHXA

Put the legacy MEDIA_ENT_* macros under a #ifndef __KERNEL__,
in order to be sure that none of those old symbols are used
inside the Kernel.

Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>
Acked-by: Hans Verkuil <hans.verkuil-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>

diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index f90147cb9b57..a1bd7afba110 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -105,6 +105,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 4)
 #define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 5)
 
+#ifndef __KERNEL__
 /* Legacy symbols used to avoid userspace compilation breakages */
 #define MEDIA_ENT_TYPE_SHIFT		16
 #define MEDIA_ENT_TYPE_MASK		0x00ff0000
@@ -118,6 +119,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
 #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
 #define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
+#endif
 
 /* Entity types */
 
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 41/55] [media] DocBook: update descriptions for the media controller entities
  2015-08-30  3:06 ` [PATCH v8 41/55] [media] DocBook: update descriptions for the media controller entities Mauro Carvalho Chehab
  2015-08-31 11:22   ` Hans Verkuil
@ 2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-11 13:13     ` Hans Verkuil
  1 sibling, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Jonathan Corbet, Hans Verkuil, linux-doc

Cleanup the media controller entities description:
- remove MEDIA_ENT_T_DEVNODE and MEDIA_ENT_T_V4L2_SUBDEV entity
  types, as they don't mean anything;
- add MEDIA_ENT_T_UNKNOWN with a proper description;
- remove ALSA and FB entity types. Those should not be used, as
  the types are deprecated. We'll soon be adidng ALSA, but with
  a different entity namespace;
- improve the description of some entities.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
index 32a783635649..bc101516e372 100644
--- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
+++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
@@ -179,70 +179,65 @@
         <colspec colname="c2"/>
 	<tbody valign="top">
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE</constant></entry>
-	    <entry>Unknown device node</entry>
+	    <entry><constant>MEDIA_ENT_T_UNKNOWN</constant> and <constant>MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN</constant></entry>
+	    <entry>Unknown entity. That generally indicates that
+	    a driver didn't initialize properly the entity, with is a Kernel bug</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
-	    <entry>V4L video, radio or vbi device node</entry>
+	    <entry>V4L video streaming input or output entity</entry>
 	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_FB</constant></entry>
-	    <entry>Frame buffer device node</entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_VBI</constant></entry>
+	    <entry>V4L VBI streaming input or output entity</entry>
 	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_ALSA</constant></entry>
-	    <entry>ALSA card</entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_SWRADIO</constant></entry>
+	    <entry>V4L Sofware Digital Radio (SDR) streaming input or output entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD</constant></entry>
-	    <entry>DVB frontend devnode</entry>
+	    <entry>DVB demodulator entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMUX</constant></entry>
-	    <entry>DVB demux devnode</entry>
+	    <entry>DVB demux entity. Could be implemented on hardware or in Kernelspace</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_TSOUT</constant></entry>
-	    <entry>DVB DVR devnode</entry>
+	    <entry>DVB Transport Stream output entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_CA</constant></entry>
-	    <entry>DVB CAM devnode</entry>
+	    <entry>DVB Conditional Access module (CAM) entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD_NET_DECAP</constant></entry>
-	    <entry>DVB network devnode</entry>
-	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV</constant></entry>
-	    <entry>Unknown V4L sub-device</entry>
+	    <entry>DVB network ULE/MLE desencapsulation entity. Could be implemented on hardware or in Kernelspace</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_SENSOR</constant></entry>
-	    <entry>Video sensor</entry>
+	    <entry>Camera video sensor entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_FLASH</constant></entry>
-	    <entry>Flash controller</entry>
+	    <entry>Flash controller entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_LENS</constant></entry>
-	    <entry>Lens controller</entry>
+	    <entry>Lens controller entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_DECODER</constant></entry>
-	    <entry>Video decoder, the basic function of the video decoder is to
-	    accept analogue video from a wide variety of sources such as
+	    <entry>Analog video decoder, the basic function of the video decoder
+	    is to accept analogue video from a wide variety of sources such as
 	    broadcast, DVD players, cameras and video cassette recorders, in
-	    either NTSC, PAL or HD format and still occasionally SECAM, separate
-	    it into its component parts, luminance and chrominance, and output
+	    either NTSC, PAL, SECAM or HD format, separating the stream
+	    into its component parts, luminance and chrominance, and output
 	    it in some digital video standard, with appropriate embedded timing
 	    signals.</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_TUNER</constant></entry>
-	    <entry>TV and/or radio tuner</entry>
+	    <entry>Digital TV, analog TV, radio and/or software radio tuner</entry>
 	  </row>
 	</tbody>
       </tgroup>
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 42/55] [media] dvb: modify core to implement interfaces/entities at MC new gen
  2015-08-30  3:06 ` [PATCH v8 42/55] [media] dvb: modify core to implement interfaces/entities at MC new gen Mauro Carvalho Chehab
  2015-08-31 11:49   ` Hans Verkuil
@ 2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-11 13:51     ` Hans Verkuil
  1 sibling, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Stefan Richter, Hans Verkuil,
	Markus Elfring, Jonathan Corbet, Akihiro Tsukada, Dan Carpenter,
	Arnd Bergmann, Tina Ruchandani, Antti Palosaari, Joe Perches,
	David S. Miller, Vaishali Thakkar, Eric W. Biederman,
	Laurent Pinchart, Sakari Ailus, Takeshi Yoshimura,
	linux1394-devel

The Media Controller New Generation redefines the types for both
interfaces and entities to be used on DVB. Make the needed
changes at the DVB core for all interfaces, entities and
data and interface links to appear in the graph.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c
index d0e3f9d85f34..baaed28ee975 100644
--- a/drivers/media/dvb-core/dmxdev.c
+++ b/drivers/media/dvb-core/dmxdev.c
@@ -1242,9 +1242,9 @@ int dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *dvb_adapter)
 	}
 
 	dvb_register_device(dvb_adapter, &dmxdev->dvbdev, &dvbdev_demux, dmxdev,
-			    DVB_DEVICE_DEMUX);
+			    DVB_DEVICE_DEMUX, dmxdev->filternum);
 	dvb_register_device(dvb_adapter, &dmxdev->dvr_dvbdev, &dvbdev_dvr,
-			    dmxdev, DVB_DEVICE_DVR);
+			    dmxdev, DVB_DEVICE_DVR, dmxdev->filternum);
 
 	dvb_ringbuffer_init(&dmxdev->dvr_buffer, NULL, 8192);
 
diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb-core/dvb_ca_en50221.c
index fb66184dc9b6..f82cd1ff4f3a 100644
--- a/drivers/media/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb-core/dvb_ca_en50221.c
@@ -1695,7 +1695,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 	pubca->private = ca;
 
 	/* register the DVB device */
-	ret = dvb_register_device(dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, DVB_DEVICE_CA);
+	ret = dvb_register_device(dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, DVB_DEVICE_CA, 0);
 	if (ret)
 		goto free_slot_info;
 
diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index 2d06bcff0946..58601bfe0b8d 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -2754,7 +2754,7 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
 			fe->dvb->num, fe->id, fe->ops.info.name);
 
 	dvb_register_device (fe->dvb, &fepriv->dvbdev, &dvbdev_template,
-			     fe, DVB_DEVICE_FRONTEND);
+			     fe, DVB_DEVICE_FRONTEND, 0);
 
 	/*
 	 * Initialize the cache to the proper values according with the
diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c
index b81e026edab3..14f51b68f4fe 100644
--- a/drivers/media/dvb-core/dvb_net.c
+++ b/drivers/media/dvb-core/dvb_net.c
@@ -1503,6 +1503,6 @@ int dvb_net_init (struct dvb_adapter *adap, struct dvb_net *dvbnet,
 		dvbnet->state[i] = 0;
 
 	return dvb_register_device(adap, &dvbnet->dvbdev, &dvbdev_net,
-			     dvbnet, DVB_DEVICE_NET);
+			     dvbnet, DVB_DEVICE_NET, 0);
 }
 EXPORT_SYMBOL(dvb_net_init);
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index dadcf1655070..6babc688801b 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -180,18 +180,86 @@ skip:
 	return -ENFILE;
 }
 
+static void dvb_create_tsout_entity(struct dvb_device *dvbdev,
+				    const char *name, int npads)
+{
+#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
+	int i, ret = 0;
+
+	dvbdev->tsout_pads = kcalloc(npads, sizeof(*dvbdev->tsout_pads),
+				     GFP_KERNEL);
+	if (!dvbdev->tsout_pads)
+		return;
+	dvbdev->tsout_entity = kcalloc(npads, sizeof(*dvbdev->tsout_entity),
+				       GFP_KERNEL);
+	if (!dvbdev->tsout_entity) {
+		kfree(dvbdev->tsout_pads);
+		dvbdev->tsout_pads = NULL;
+		return;
+	}
+	for (i = 0; i < npads; i++) {
+		struct media_pad *pads = &dvbdev->tsout_pads[i];
+		struct media_entity *entity = &dvbdev->tsout_entity[i];
+
+		entity->name = kasprintf(GFP_KERNEL, "%s #%d", name, i);
+		if (!entity->name) {
+			ret = -ENOMEM;
+			break;
+		}
+
+		entity->type = MEDIA_ENT_T_DVB_TSOUT;
+		pads->flags = MEDIA_PAD_FL_SINK;
+
+		ret = media_entity_init(entity, 1, pads);
+		if (ret < 0)
+			break;
+
+		ret = media_device_register_entity(dvbdev->adapter->mdev,
+						   entity);
+		if (ret < 0)
+			break;
+	}
+
+	if (!ret) {
+		dvbdev->tsout_num_entities = npads;
+		return;
+	}
+
+	for (i--; i >= 0; i--) {
+		media_device_unregister_entity(&dvbdev->tsout_entity[i]);
+		kfree(dvbdev->tsout_entity[i].name);
+	}
+
+	printk(KERN_ERR
+		"%s: media_device_register_entity failed for %s\n",
+		__func__, name);
+
+	kfree(dvbdev->tsout_entity);
+	kfree(dvbdev->tsout_pads);
+	dvbdev->tsout_entity = NULL;
+	dvbdev->tsout_pads = NULL;
+#endif
+}
+
+#define DEMUX_TSOUT	"demux-tsout"
+#define DVR_TSOUT	"dvr-tsout"
+
 static void dvb_create_media_entity(struct dvb_device *dvbdev,
-				       int type, int minor)
+				    int type, int demux_sink_pads)
 {
 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
-	int ret = 0, npads;
+	int i, ret = 0, npads;
 
 	switch (type) {
 	case DVB_DEVICE_FRONTEND:
 		npads = 2;
 		break;
+	case DVB_DEVICE_DVR:
+		dvb_create_tsout_entity(dvbdev, DVR_TSOUT, demux_sink_pads);
+		return;
 	case DVB_DEVICE_DEMUX:
-		npads = 2;
+		npads = 1 + demux_sink_pads;
+		dvb_create_tsout_entity(dvbdev, DEMUX_TSOUT, demux_sink_pads);
 		break;
 	case DVB_DEVICE_CA:
 		npads = 2;
@@ -215,8 +283,6 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
 	if (!dvbdev->entity)
 		return;
 
-	dvbdev->entity->info.dev.major = DVB_MAJOR;
-	dvbdev->entity->info.dev.minor = minor;
 	dvbdev->entity->name = dvbdev->name;
 
 	if (npads) {
@@ -237,7 +303,8 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
 	case DVB_DEVICE_DEMUX:
 		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMUX;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
-		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
+		for (i = 1; i < npads; i++)
+			dvbdev->pads[i].flags = MEDIA_PAD_FL_SOURCE;
 		break;
 	case DVB_DEVICE_CA:
 		dvbdev->entity->type = MEDIA_ENT_T_DVB_CA;
@@ -259,8 +326,16 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
 		printk(KERN_ERR
 			"%s: media_device_register_entity failed for %s\n",
 			__func__, dvbdev->entity->name);
+
+		media_device_unregister_entity(dvbdev->entity);
+		for (i = 0; i < dvbdev->tsout_num_entities; i++) {
+			media_device_unregister_entity(&dvbdev->tsout_entity[i]);
+			kfree(dvbdev->tsout_entity[i].name);
+		}
 		kfree(dvbdev->pads);
 		kfree(dvbdev->entity);
+		kfree(dvbdev->tsout_pads);
+		kfree(dvbdev->tsout_entity);
 		dvbdev->entity = NULL;
 		return;
 	}
@@ -271,7 +346,8 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
 }
 
 static void dvb_register_media_device(struct dvb_device *dvbdev,
-				      int type, int minor)
+				      int type, int minor,
+				      unsigned demux_sink_pads)
 {
 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
 	u32 intf_type;
@@ -279,7 +355,7 @@ static void dvb_register_media_device(struct dvb_device *dvbdev,
 	if (!dvbdev->adapter->mdev)
 		return;
 
-	dvb_create_media_entity(dvbdev, type, minor);
+	dvb_create_media_entity(dvbdev, type, demux_sink_pads);
 
 	switch (type) {
 	case DVB_DEVICE_FRONTEND:
@@ -323,7 +399,8 @@ static void dvb_register_media_device(struct dvb_device *dvbdev,
 }
 
 int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
-			const struct dvb_device *template, void *priv, int type)
+			const struct dvb_device *template, void *priv, int type,
+			int demux_sink_pads)
 {
 	struct dvb_device *dvbdev;
 	struct file_operations *dvbdevfops;
@@ -402,7 +479,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
 	dprintk(KERN_DEBUG "DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n",
 		adap->num, dnames[type], id, minor, minor);
 
-	dvb_register_media_device(dvbdev, type, minor);
+	dvb_register_media_device(dvbdev, type, minor, demux_sink_pads);
 
 	return 0;
 }
@@ -422,9 +499,18 @@ void dvb_unregister_device(struct dvb_device *dvbdev)
 
 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
 	if (dvbdev->entity) {
+		int i;
+
 		media_device_unregister_entity(dvbdev->entity);
+		for (i = 0; i < dvbdev->tsout_num_entities; i++) {
+			media_device_unregister_entity(&dvbdev->tsout_entity[i]);
+			kfree(dvbdev->tsout_entity[i].name);
+		}
+
 		kfree(dvbdev->entity);
 		kfree(dvbdev->pads);
+		kfree(dvbdev->tsout_entity);
+		kfree(dvbdev->tsout_pads);
 	}
 #endif
 
@@ -440,8 +526,10 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 {
 	struct media_device *mdev = adap->mdev;
 	struct media_entity *entity, *tuner = NULL, *demod = NULL;
-	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
+	struct media_entity *demux = NULL, *ca = NULL;
 	struct media_interface *intf;
+	unsigned demux_pad = 0;
+	unsigned dvr_pad = 0;
 
 	if (!mdev)
 		return;
@@ -457,9 +545,6 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 		case MEDIA_ENT_T_DVB_DEMUX:
 			demux = entity;
 			break;
-		case MEDIA_ENT_T_DVB_TSOUT:
-			dvr = entity;
-			break;
 		case MEDIA_ENT_T_DVB_CA:
 			ca = entity;
 			break;
@@ -471,21 +556,46 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 
 	if (demod && demux)
 		media_create_pad_link(demod, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
-
-	if (demux && dvr)
-		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
-
 	if (demux && ca)
 		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
 
+	/* Create demux links for each ringbuffer/pad */
+	if (demux) {
+		media_device_for_each_entity(entity, mdev) {
+			if (entity->type == MEDIA_ENT_T_DVB_TSOUT) {
+				if (!strncmp(entity->name, DVR_TSOUT,
+					strlen(DVR_TSOUT)))
+					media_create_pad_link(demux,
+							      ++dvr_pad,
+							entity, 0, 0);
+				if (!strncmp(entity->name, DEMUX_TSOUT,
+					strlen(DEMUX_TSOUT)))
+					media_create_pad_link(demux,
+							      ++demux_pad,
+							entity, 0, 0);
+			}
+		}
+	}
+
 	/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca */
 	list_for_each_entry(intf, &mdev->interfaces, list) {
 		if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
 			media_create_intf_link(ca, intf, 0);
 		if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
 			media_create_intf_link(tuner, intf, 0);
+
 		if (intf->type == MEDIA_INTF_T_DVB_DVR && demux)
 			media_create_intf_link(demux, intf, 0);
+
+		media_device_for_each_entity(entity, mdev) {
+			if (entity->type == MEDIA_ENT_T_DVB_TSOUT) {
+				if (!strcmp(entity->name, DVR_TSOUT))
+					media_create_intf_link(entity, intf, 0);
+				if (!strcmp(entity->name, DEMUX_TSOUT))
+					media_create_intf_link(entity, intf, 0);
+				break;
+			}
+		}
 	}
 }
 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
diff --git a/drivers/media/dvb-core/dvbdev.h b/drivers/media/dvb-core/dvbdev.h
index 5f37b4dd1e69..0b140e8595de 100644
--- a/drivers/media/dvb-core/dvbdev.h
+++ b/drivers/media/dvb-core/dvbdev.h
@@ -148,9 +148,11 @@ struct dvb_device {
 	const char *name;
 
 	/* Allocated and filled inside dvbdev.c */
-	struct media_entity *entity;
 	struct media_intf_devnode *intf_devnode;
-	struct media_pad *pads;
+
+	unsigned tsout_num_entities;
+	struct media_entity *entity, *tsout_entity;
+	struct media_pad *pads, *tsout_pads;
 #endif
 
 	void *priv;
@@ -197,7 +199,8 @@ int dvb_register_device(struct dvb_adapter *adap,
 			struct dvb_device **pdvbdev,
 			const struct dvb_device *template,
 			void *priv,
-			int type);
+			int type,
+			int demux_sink_pads);
 
 /**
  * dvb_unregister_device - Unregisters a DVB device
diff --git a/drivers/media/firewire/firedtv-ci.c b/drivers/media/firewire/firedtv-ci.c
index e63f582378bf..edbb30fdd9d9 100644
--- a/drivers/media/firewire/firedtv-ci.c
+++ b/drivers/media/firewire/firedtv-ci.c
@@ -241,7 +241,7 @@ int fdtv_ca_register(struct firedtv *fdtv)
 		return -EFAULT;
 
 	err = dvb_register_device(&fdtv->adapter, &fdtv->cadev,
-				  &fdtv_ca, fdtv, DVB_DEVICE_CA);
+				  &fdtv_ca, fdtv, DVB_DEVICE_CA, 0);
 
 	if (stat.ca_application_info == 0)
 		dev_err(fdtv->device, "CaApplicationInfo is not set\n");
diff --git a/drivers/media/pci/bt8xx/dst_ca.c b/drivers/media/pci/bt8xx/dst_ca.c
index c5cc14ef8347..0149a9ed6e58 100644
--- a/drivers/media/pci/bt8xx/dst_ca.c
+++ b/drivers/media/pci/bt8xx/dst_ca.c
@@ -705,7 +705,8 @@ struct dvb_device *dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_
 	struct dvb_device *dvbdev;
 
 	dprintk(verbose, DST_CA_ERROR, 1, "registering DST-CA device");
-	if (dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA) == 0) {
+	if (dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst,
+			        DVB_DEVICE_CA, 0) == 0) {
 		dst->dst_ca = dvbdev;
 		return dst->dst_ca;
 	}
diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
index 0ac2dd35fe50..4caca5df2931 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1065,7 +1065,7 @@ static int ddb_ci_attach(struct ddb_port *port)
 			    port->en, 0, 1);
 	ret = dvb_register_device(&port->output->adap, &port->output->dev,
 				  &dvbdev_ci, (void *) port->output,
-				  DVB_DEVICE_SEC);
+				  DVB_DEVICE_SEC, 0);
 	return ret;
 }
 
diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c
index 1b92d836a564..4e924e2d1638 100644
--- a/drivers/media/pci/ngene/ngene-core.c
+++ b/drivers/media/pci/ngene/ngene-core.c
@@ -1513,7 +1513,7 @@ static int init_channel(struct ngene_channel *chan)
 		set_transfer(&chan->dev->channel[2], 1);
 		dvb_register_device(adapter, &chan->ci_dev,
 				    &ngene_dvbdev_ci, (void *) chan,
-				    DVB_DEVICE_SEC);
+				    DVB_DEVICE_SEC, 0);
 		if (!chan->ci_dev)
 			goto err;
 	}
diff --git a/drivers/media/pci/ttpci/av7110.c b/drivers/media/pci/ttpci/av7110.c
index 3f24fce74fc1..63f1d56bdfb2 100644
--- a/drivers/media/pci/ttpci/av7110.c
+++ b/drivers/media/pci/ttpci/av7110.c
@@ -1361,7 +1361,7 @@ static int av7110_register(struct av7110 *av7110)
 
 #ifdef CONFIG_DVB_AV7110_OSD
 	dvb_register_device(&av7110->dvb_adapter, &av7110->osd_dev,
-			    &dvbdev_osd, av7110, DVB_DEVICE_OSD);
+			    &dvbdev_osd, av7110, DVB_DEVICE_OSD, 0);
 #endif
 
 	dvb_net_init(&av7110->dvb_adapter, &av7110->dvb_net, &dvbdemux->dmx);
diff --git a/drivers/media/pci/ttpci/av7110_av.c b/drivers/media/pci/ttpci/av7110_av.c
index 9544cfc06601..da11501fe5d2 100644
--- a/drivers/media/pci/ttpci/av7110_av.c
+++ b/drivers/media/pci/ttpci/av7110_av.c
@@ -1589,10 +1589,10 @@ int av7110_av_register(struct av7110 *av7110)
 	memset(&av7110->video_size, 0, sizeof (video_size_t));
 
 	dvb_register_device(&av7110->dvb_adapter, &av7110->video_dev,
-			    &dvbdev_video, av7110, DVB_DEVICE_VIDEO);
+			    &dvbdev_video, av7110, DVB_DEVICE_VIDEO, 0);
 
 	dvb_register_device(&av7110->dvb_adapter, &av7110->audio_dev,
-			    &dvbdev_audio, av7110, DVB_DEVICE_AUDIO);
+			    &dvbdev_audio, av7110, DVB_DEVICE_AUDIO, 0);
 
 	return 0;
 }
diff --git a/drivers/media/pci/ttpci/av7110_ca.c b/drivers/media/pci/ttpci/av7110_ca.c
index a6079b90252a..235f0202dc7e 100644
--- a/drivers/media/pci/ttpci/av7110_ca.c
+++ b/drivers/media/pci/ttpci/av7110_ca.c
@@ -378,7 +378,7 @@ static struct dvb_device dvbdev_ca = {
 int av7110_ca_register(struct av7110 *av7110)
 {
 	return dvb_register_device(&av7110->dvb_adapter, &av7110->ca_dev,
-				   &dvbdev_ca, av7110, DVB_DEVICE_CA);
+				   &dvbdev_ca, av7110, DVB_DEVICE_CA, 0);
 }
 
 void av7110_ca_unregister(struct av7110 *av7110)
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 43/55] [media] media: report if a pad is sink or source at debug msg
  2015-08-30  3:06 ` [PATCH v8 43/55] [media] media: report if a pad is sink or source at debug msg Mauro Carvalho Chehab
  2015-08-31 11:51   ` Hans Verkuil
@ 2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-11 13:52     ` Hans Verkuil
  2015-12-06  0:53     ` Laurent Pinchart
  1 sibling, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

Sometimes, it is important to see if the created pad is
sink or source. Add info to track that.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index d8038a53f945..6ed5eef88593 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -121,8 +121,11 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 		struct media_pad *pad = gobj_to_pad(gobj);
 
 		dev_dbg(gobj->mdev->dev,
-			"%s: id 0x%08x pad#%d: '%s':%d\n",
-			event_name, gobj->id, media_localid(gobj),
+			"%s: id 0x%08x %s%spad#%d: '%s':%d\n",
+			event_name, gobj->id,
+			pad->flags & MEDIA_PAD_FL_SINK   ? "  sink " : "",
+			pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
+			media_localid(gobj),
 			pad->entity->name, pad->index);
 		break;
 	}
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
@ 2015-09-06 12:03     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, linux-api

Add a new ioctl that will report the entire topology on
one go.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 7320cdc45833..2d5ad40254b7 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -181,6 +181,8 @@ struct media_interface {
  */
 struct media_intf_devnode {
 	struct media_interface		intf;
+
+	/* Should match the fields at media_v2_intf_devnode */
 	u32				major;
 	u32				minor;
 };
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index a1bd7afba110..b17f6763aff4 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -206,6 +206,10 @@ struct media_pad_desc {
 #define MEDIA_LNK_FL_IMMUTABLE		(1 << 1)
 #define MEDIA_LNK_FL_DYNAMIC		(1 << 2)
 
+#define MEDIA_LNK_FL_LINK_TYPE		(0xf << 28)
+#  define MEDIA_LNK_FL_DATA_LINK	(0 << 28)
+#  define MEDIA_LNK_FL_INTERFACE_LINK	(1 << 28)
+
 struct media_link_desc {
 	struct media_pad_desc source;
 	struct media_pad_desc sink;
@@ -249,11 +253,93 @@ struct media_links_enum {
 #define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
 #define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
 
-/* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
+/*
+ * MC next gen API definitions
+ *
+ * NOTE: The declarations below are close to the MC RFC for the Media
+ *	 Controller, the next generation. Yet, there are a few adjustments
+ *	 to do, as we want to be able to have a functional API before
+ *	 the MC properties change. Those will be properly marked below.
+ *	 Please also notice that I removed "num_pads", "num_links",
+ *	 from the proposal, as a proper userspace application will likely
+ *	 use lists for pads/links, just as we intend to do in Kernelspace.
+ *	 The API definition should be freed from fields that are bound to
+ *	 some specific data structure.
+ *
+ * FIXME: Currently, I opted to name the new types as "media_v2", as this
+ *	  won't cause any conflict with the Kernelspace namespace, nor with
+ *	  the previous kAPI media_*_desc namespace. This can be changed
+ *	  later, before the adding this API upstream.
+ */
+
+
+struct media_v2_entity {
+	__u32 id;
+	char name[64];		/* FIXME: move to a property? (RFC says so) */
+	__u16 reserved[14];
+};
+
+/* Should match the specific fields at media_intf_devnode */
+struct media_v2_intf_devnode {
+	__u32 major;
+	__u32 minor;
+};
+
+struct media_v2_interface {
+	__u32 id;
+	__u32 intf_type;
+	__u32 flags;
+	__u32 reserved[9];
+
+	union {
+		struct media_v2_intf_devnode devnode;
+		__u32 raw[16];
+	};
+};
+
+struct media_v2_pad {
+	__u32 id;
+	__u32 entity_id;
+	__u32 flags;
+	__u16 reserved[9];
+};
+
+struct media_v2_link {
+    __u32 id;
+    __u32 source_id;
+    __u32 sink_id;
+    __u32 flags;
+    __u32 reserved[5];
+};
+
+struct media_v2_topology {
+	__u32 topology_version;
+
+	__u32 num_entities;
+	struct media_v2_entity *entities;
+
+	__u32 num_interfaces;
+	struct media_v2_interface *interfaces;
+
+	__u32 num_pads;
+	struct media_v2_pad *pads;
+
+	__u32 num_links;
+	struct media_v2_link *links;
+
+	struct {
+		__u32 reserved_num;
+		void *reserved_ptr;
+	} reserved_types[16];
+	__u32 reserved[8];
+};
+
+/* ioctls */
 
 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
 #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct media_entity_desc)
 #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
 #define MEDIA_IOC_SETUP_LINK		_IOWR('|', 0x03, struct media_link_desc)
+#define MEDIA_IOC_G_TOPOLOGY		_IOWR('|', 0x04, struct media_v2_topology)
 
 #endif /* __LINUX_MEDIA_H */
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
@ 2015-09-06 12:03     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, linux-api-u79uwXL29TY76Z2rM5mHXA

Add a new ioctl that will report the entire topology on
one go.

Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 7320cdc45833..2d5ad40254b7 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -181,6 +181,8 @@ struct media_interface {
  */
 struct media_intf_devnode {
 	struct media_interface		intf;
+
+	/* Should match the fields at media_v2_intf_devnode */
 	u32				major;
 	u32				minor;
 };
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index a1bd7afba110..b17f6763aff4 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -206,6 +206,10 @@ struct media_pad_desc {
 #define MEDIA_LNK_FL_IMMUTABLE		(1 << 1)
 #define MEDIA_LNK_FL_DYNAMIC		(1 << 2)
 
+#define MEDIA_LNK_FL_LINK_TYPE		(0xf << 28)
+#  define MEDIA_LNK_FL_DATA_LINK	(0 << 28)
+#  define MEDIA_LNK_FL_INTERFACE_LINK	(1 << 28)
+
 struct media_link_desc {
 	struct media_pad_desc source;
 	struct media_pad_desc sink;
@@ -249,11 +253,93 @@ struct media_links_enum {
 #define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
 #define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
 
-/* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
+/*
+ * MC next gen API definitions
+ *
+ * NOTE: The declarations below are close to the MC RFC for the Media
+ *	 Controller, the next generation. Yet, there are a few adjustments
+ *	 to do, as we want to be able to have a functional API before
+ *	 the MC properties change. Those will be properly marked below.
+ *	 Please also notice that I removed "num_pads", "num_links",
+ *	 from the proposal, as a proper userspace application will likely
+ *	 use lists for pads/links, just as we intend to do in Kernelspace.
+ *	 The API definition should be freed from fields that are bound to
+ *	 some specific data structure.
+ *
+ * FIXME: Currently, I opted to name the new types as "media_v2", as this
+ *	  won't cause any conflict with the Kernelspace namespace, nor with
+ *	  the previous kAPI media_*_desc namespace. This can be changed
+ *	  later, before the adding this API upstream.
+ */
+
+
+struct media_v2_entity {
+	__u32 id;
+	char name[64];		/* FIXME: move to a property? (RFC says so) */
+	__u16 reserved[14];
+};
+
+/* Should match the specific fields at media_intf_devnode */
+struct media_v2_intf_devnode {
+	__u32 major;
+	__u32 minor;
+};
+
+struct media_v2_interface {
+	__u32 id;
+	__u32 intf_type;
+	__u32 flags;
+	__u32 reserved[9];
+
+	union {
+		struct media_v2_intf_devnode devnode;
+		__u32 raw[16];
+	};
+};
+
+struct media_v2_pad {
+	__u32 id;
+	__u32 entity_id;
+	__u32 flags;
+	__u16 reserved[9];
+};
+
+struct media_v2_link {
+    __u32 id;
+    __u32 source_id;
+    __u32 sink_id;
+    __u32 flags;
+    __u32 reserved[5];
+};
+
+struct media_v2_topology {
+	__u32 topology_version;
+
+	__u32 num_entities;
+	struct media_v2_entity *entities;
+
+	__u32 num_interfaces;
+	struct media_v2_interface *interfaces;
+
+	__u32 num_pads;
+	struct media_v2_pad *pads;
+
+	__u32 num_links;
+	struct media_v2_link *links;
+
+	struct {
+		__u32 reserved_num;
+		void *reserved_ptr;
+	} reserved_types[16];
+	__u32 reserved[8];
+};
+
+/* ioctls */
 
 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
 #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct media_entity_desc)
 #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
 #define MEDIA_IOC_SETUP_LINK		_IOWR('|', 0x03, struct media_link_desc)
+#define MEDIA_IOC_G_TOPOLOGY		_IOWR('|', 0x04, struct media_v2_topology)
 
 #endif /* __LINUX_MEDIA_H */
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 45/55] [media] media: Use a macro to interate between all interfaces
  2015-08-30  3:06 ` [PATCH v8 45/55] [media] media: Use a macro to interate between all interfaces Mauro Carvalho Chehab
  2015-08-31 12:01   ` Hans Verkuil
@ 2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-11-23 22:36     ` Laurent Pinchart
  1 sibling, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Hans Verkuil, Sakari Ailus, Laurent Pinchart

Just like we do with entities, use a similar macro for the
interfaces loop.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 6babc688801b..f00f1a5f279c 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -578,9 +578,10 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	}
 
 	/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca */
-	list_for_each_entry(intf, &mdev->interfaces, list) {
+	media_device_for_each_intf(intf, mdev) {
 		if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
 			media_create_intf_link(ca, intf, 0);
+
 		if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
 			media_create_intf_link(tuner, intf, 0);
 
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 51807efa505b..f23d686aaac6 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -113,6 +113,11 @@ struct media_device *media_device_find_devres(struct device *dev);
 #define media_device_for_each_entity(entity, mdev)			\
 	list_for_each_entry(entity, &(mdev)->entities, list)
 
+/* Iterate over all interfaces. */
+#define media_device_for_each_intf(intf, mdev)			\
+	list_for_each_entry(intf, &(mdev)->interfaces, list)
+
+
 #else
 static inline int media_device_register(struct media_device *mdev)
 {
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 46/55] [media] media: move mdev list init to gobj
  2015-08-30  3:06 ` [PATCH v8 46/55] [media] media: move mdev list init to gobj Mauro Carvalho Chehab
  2015-08-31 12:03   ` Hans Verkuil
@ 2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-11 13:59     ` Hans Verkuil
  2015-11-23 22:32     ` Laurent Pinchart
  1 sibling, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

Let's control the topology changes inside the graph_object. So, move the
addition and removal of interfaces/entities from the mdev lists to
media_gobj_init() and media_gobj_remove().

The main reason is that mdev should have lists for all object types, as
the new MC api will require to store objects in separate places.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 134fe7510195..ec98595b8a7a 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -415,7 +415,7 @@ void media_device_unregister(struct media_device *mdev)
 	struct media_entity *entity;
 	struct media_entity *next;
 
-	list_for_each_entry_safe(entity, next, &mdev->entities, list)
+	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
 		media_device_unregister_entity(entity);
 
 	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
@@ -449,7 +449,6 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	spin_lock(&mdev->lock);
 	/* Initialize media_gobj embedded at the entity */
 	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
-	list_add_tail(&entity->list, &mdev->entities);
 
 	/* Initialize objects at the pads */
 	for (i = 0; i < entity->num_pads; i++)
@@ -487,7 +486,6 @@ void media_device_unregister_entity(struct media_entity *entity)
 	for (i = 0; i < entity->num_pads; i++)
 		media_gobj_remove(&entity->pads[i].graph_obj);
 	media_gobj_remove(&entity->graph_obj);
-	list_del(&entity->list);
 	spin_unlock(&mdev->lock);
 	entity->graph_obj.mdev = NULL;
 }
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 6ed5eef88593..cbb0604e81c1 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -170,6 +170,7 @@ void media_gobj_init(struct media_device *mdev,
 	switch (type) {
 	case MEDIA_GRAPH_ENTITY:
 		gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
+		list_add_tail(&gobj->list, &mdev->entities);
 		break;
 	case MEDIA_GRAPH_PAD:
 		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
@@ -178,6 +179,7 @@ void media_gobj_init(struct media_device *mdev,
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
 		break;
 	case MEDIA_GRAPH_INTF_DEVNODE:
+		list_add_tail(&gobj->list, &mdev->interfaces);
 		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
 		break;
 	}
@@ -193,6 +195,16 @@ void media_gobj_init(struct media_device *mdev,
  */
 void media_gobj_remove(struct media_gobj *gobj)
 {
+	/* Remove the object from mdev list */
+	switch (media_type(gobj)) {
+	case MEDIA_GRAPH_ENTITY:
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		list_del(&gobj->list);
+		break;
+	default:
+		break;
+	}
+
 	dev_dbg_obj(__func__, gobj);
 }
 
@@ -864,8 +876,6 @@ static void media_interface_init(struct media_device *mdev,
 	INIT_LIST_HEAD(&intf->links);
 
 	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
-
-	list_add_tail(&intf->list, &mdev->interfaces);
 }
 
 /* Functions related to the media interface via device nodes */
@@ -894,7 +904,6 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
 	media_gobj_remove(&devnode->intf.graph_obj);
-	list_del(&devnode->intf.list);
 	kfree(devnode);
 }
 EXPORT_SYMBOL_GPL(media_devnode_remove);
diff --git a/include/media/media-device.h b/include/media/media-device.h
index f23d686aaac6..85fa302047bd 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -111,11 +111,11 @@ struct media_device *media_device_find_devres(struct device *dev);
 
 /* Iterate over all entities. */
 #define media_device_for_each_entity(entity, mdev)			\
-	list_for_each_entry(entity, &(mdev)->entities, list)
+	list_for_each_entry(entity, &(mdev)->entities, graph_obj.list)
 
 /* Iterate over all interfaces. */
 #define media_device_for_each_intf(intf, mdev)			\
-	list_for_each_entry(intf, &(mdev)->interfaces, list)
+	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
 
 
 #else
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 2d5ad40254b7..bc7eb6240795 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -66,6 +66,7 @@ enum media_gobj_type {
 struct media_gobj {
 	struct media_device	*mdev;
 	u32			id;
+	struct list_head	list;
 };
 
 
@@ -114,7 +115,6 @@ struct media_entity_operations {
 
 struct media_entity {
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	struct list_head list;
 	const char *name;		/* Entity name */
 	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
 	u32 revision;			/* Entity revision, driver specific */
@@ -166,7 +166,6 @@ struct media_entity {
  */
 struct media_interface {
 	struct media_gobj		graph_obj;
-	struct list_head		list;
 	struct list_head		links;
 	u32				type;
 	u32				flags;
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 47/55] [media] media-device: add pads and links to media_device
  2015-08-30  3:06 ` [PATCH v8 47/55] [media] media-device: add pads and links to media_device Mauro Carvalho Chehab
  2015-08-31 12:25   ` Hans Verkuil
@ 2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-11-23 22:28     ` Laurent Pinchart
  1 sibling, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

The MC next gen API sends objects to userspace grouped by
their types.

In the case of pads and links, in order to improve performance
and have a simpler code, the best is to store them also on
separate linked lists at MC.

If we don't do that, we would need this kind of interaction
to send data to userspace (code is in structured english):

	for each entity:
		for each pad:
			store pads

	for each entity:
		for each link:
			store link

	for each interface:
		for each link:
			store link

With would require one nexted loop for pads and two nested
loops for links. By using  separate linked lists for them,
just one loop would be enough.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index ec98595b8a7a..5b2c9f7fcd45 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -382,6 +382,8 @@ int __must_check __media_device_register(struct media_device *mdev,
 
 	INIT_LIST_HEAD(&mdev->entities);
 	INIT_LIST_HEAD(&mdev->interfaces);
+	INIT_LIST_HEAD(&mdev->pads);
+	INIT_LIST_HEAD(&mdev->links);
 	spin_lock_init(&mdev->lock);
 	mutex_init(&mdev->graph_mutex);
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index cbb0604e81c1..568553d41f5d 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -174,13 +174,15 @@ void media_gobj_init(struct media_device *mdev,
 		break;
 	case MEDIA_GRAPH_PAD:
 		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
+		list_add_tail(&gobj->list, &mdev->pads);
 		break;
 	case MEDIA_GRAPH_LINK:
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
+		list_add_tail(&gobj->list, &mdev->links);
 		break;
 	case MEDIA_GRAPH_INTF_DEVNODE:
-		list_add_tail(&gobj->list, &mdev->interfaces);
 		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
+		list_add_tail(&gobj->list, &mdev->interfaces);
 		break;
 	}
 	dev_dbg_obj(__func__, gobj);
@@ -195,17 +197,10 @@ void media_gobj_init(struct media_device *mdev,
  */
 void media_gobj_remove(struct media_gobj *gobj)
 {
+	dev_dbg_obj(__func__, gobj);
+
 	/* Remove the object from mdev list */
-	switch (media_type(gobj)) {
-	case MEDIA_GRAPH_ENTITY:
-	case MEDIA_GRAPH_INTF_DEVNODE:
-		list_del(&gobj->list);
-		break;
-	default:
-		break;
-	}
-
-	dev_dbg_obj(__func__, gobj);
+	list_del(&gobj->list);
 }
 
 /**
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 85fa302047bd..0d1b9c687454 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -47,6 +47,8 @@ struct device;
  * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:	List of registered entities
  * @interfaces:	List of registered interfaces
+ * @pads:	List of registered pads
+ * @links:	List of registered links
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
  * @link_notify: Link state change notification callback
@@ -79,6 +81,8 @@ struct media_device {
 
 	struct list_head entities;
 	struct list_head interfaces;
+	struct list_head pads;
+	struct list_head links;
 
 	/* Protects the entities list */
 	spinlock_t lock;
@@ -117,6 +121,14 @@ struct media_device *media_device_find_devres(struct device *dev);
 #define media_device_for_each_intf(intf, mdev)			\
 	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
 
+/* Iterate over all pads. */
+#define media_device_for_each_pad(pad, mdev)			\
+	list_for_each_entry(pad, &(mdev)->pads, graph_obj.list)
+
+/* Iterate over all links. */
+#define media_device_for_each_link(link, mdev)			\
+	list_for_each_entry(link, &(mdev)->links, graph_obj.list)
+
 
 #else
 static inline int media_device_register(struct media_device *mdev)
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 48/55] [media] media_device: add a topology version field
  2015-08-30  3:06 ` [PATCH v8 48/55] [media] media_device: add a topology version field Mauro Carvalho Chehab
  2015-08-31 12:29   ` Hans Verkuil
@ 2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-11 13:59     ` Hans Verkuil
  1 sibling, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

Every time a graph object is added or removed, the version
of the topology changes. That's a requirement for the new
MEDIA_IOC_G_TOPOLOGY, in order to allow userspace to know
that the topology has changed after a previous call to it.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 568553d41f5d..064515f2ba9b 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -185,6 +185,9 @@ void media_gobj_init(struct media_device *mdev,
 		list_add_tail(&gobj->list, &mdev->interfaces);
 		break;
 	}
+
+	mdev->topology_version++;
+
 	dev_dbg_obj(__func__, gobj);
 }
 
@@ -199,6 +202,8 @@ void media_gobj_remove(struct media_gobj *gobj)
 {
 	dev_dbg_obj(__func__, gobj);
 
+	gobj->mdev->topology_version++;
+
 	/* Remove the object from mdev list */
 	list_del(&gobj->list);
 }
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 0d1b9c687454..1b12774a9ab4 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -41,6 +41,8 @@ struct device;
  * @bus_info:	Unique and stable device location identifier
  * @hw_revision: Hardware device revision
  * @driver_version: Device driver version
+ * @topology_version: Monotonic counter for storing the version of the graph
+ *		topology. Should be incremented each time the topology changes.
  * @entity_id:	Unique ID used on the last entity registered
  * @pad_id:	Unique ID used on the last pad registered
  * @link_id:	Unique ID used on the last link registered
@@ -74,6 +76,8 @@ struct media_device {
 	u32 hw_revision;
 	u32 driver_version;
 
+	u32 topology_version;
+
 	u32 entity_id;
 	u32 pad_id;
 	u32 link_id;
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-08-30  3:07 ` [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl Mauro Carvalho Chehab
  2015-08-31 12:47   ` Hans Verkuil
@ 2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-07 22:18     ` Sakari Ailus
                       ` (2 more replies)
  1 sibling, 3 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
with the RFC for the MC next generation.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 5b2c9f7fcd45..96a476eeb16e 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
 	return ret;
 }
 
+static long __media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology *topo)
+{
+	struct media_entity *entity;
+	struct media_interface *intf;
+	struct media_pad *pad;
+	struct media_link *link;
+	struct media_v2_entity uentity;
+	struct media_v2_interface uintf;
+	struct media_v2_pad upad;
+	struct media_v2_link ulink;
+	int ret = 0, i;
+
+	topo->topology_version = mdev->topology_version;
+
+	/* Get entities and number of entities */
+	i = 0;
+	media_device_for_each_entity(entity, mdev) {
+		i++;
+
+		if (ret || !topo->entities)
+			continue;
+
+		if (i > topo->num_entities) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		/* Copy fields to userspace struct if not error */
+		memset(&uentity, 0, sizeof(uentity));
+		uentity.id = entity->graph_obj.id;
+		strncpy(uentity.name, entity->name,
+			sizeof(uentity.name));
+
+		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
+			ret = -EFAULT;
+	}
+	topo->num_entities = i;
+
+	/* Get interfaces and number of interfaces */
+	i = 0;
+	media_device_for_each_intf(intf, mdev) {
+		i++;
+
+		if (ret || !topo->interfaces)
+			continue;
+
+		if (i > topo->num_interfaces) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&uintf, 0, sizeof(uintf));
+
+		/* Copy intf fields to userspace struct */
+		uintf.id = intf->graph_obj.id;
+		uintf.intf_type = intf->type;
+		uintf.flags = intf->flags;
+
+		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
+			struct media_intf_devnode *devnode;
+
+			devnode = intf_to_devnode(intf);
+
+			uintf.devnode.major = devnode->major;
+			uintf.devnode.minor = devnode->minor;
+		}
+
+		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
+			ret = -EFAULT;
+	}
+	topo->num_interfaces = i;
+
+	/* Get pads and number of pads */
+	i = 0;
+	media_device_for_each_pad(pad, mdev) {
+		i++;
+
+		if (ret || !topo->pads)
+			continue;
+
+		if (i > topo->num_pads) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&upad, 0, sizeof(upad));
+
+		/* Copy pad fields to userspace struct */
+		upad.id = pad->graph_obj.id;
+		upad.entity_id = pad->entity->graph_obj.id;
+		upad.flags = pad->flags;
+
+		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
+			ret = -EFAULT;
+	}
+	topo->num_pads = i;
+
+	/* Get links and number of links */
+	i = 0;
+	media_device_for_each_link(link, mdev) {
+		i++;
+
+		if (ret || !topo->links)
+			continue;
+
+		if (i > topo->num_links) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&ulink, 0, sizeof(ulink));
+
+		/* Copy link fields to userspace struct */
+		ulink.id = link->graph_obj.id;
+		ulink.source_id = link->gobj0->id;
+		ulink.sink_id = link->gobj1->id;
+		ulink.flags = link->flags;
+
+		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
+			ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;
+
+		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
+			ret = -EFAULT;
+	}
+	topo->num_links = i;
+
+	return ret;
+}
+
+static long media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology __user *utopo)
+{
+	struct media_v2_topology ktopo;
+	int ret;
+
+	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
+
+	if (ret < 0)
+		return ret;
+
+	ret = __media_device_get_topology(mdev, &ktopo);
+	if (ret < 0)
+		return ret;
+
+	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));
+
+	return ret;
+}
+
 static long media_device_ioctl(struct file *filp, unsigned int cmd,
 			       unsigned long arg)
 {
@@ -264,6 +414,13 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
 		mutex_unlock(&dev->graph_mutex);
 		break;
 
+	case MEDIA_IOC_G_TOPOLOGY:
+		mutex_lock(&dev->graph_mutex);
+		ret = media_device_get_topology(dev,
+				(struct media_v2_topology __user *)arg);
+		mutex_unlock(&dev->graph_mutex);
+		break;
+
 	default:
 		ret = -ENOIOCTLCMD;
 	}
@@ -312,6 +469,7 @@ static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
 	case MEDIA_IOC_DEVICE_INFO:
 	case MEDIA_IOC_ENUM_ENTITIES:
 	case MEDIA_IOC_SETUP_LINK:
+	case MEDIA_IOC_G_TOPOLOGY:
 		return media_device_ioctl(filp, cmd, arg);
 
 	case MEDIA_IOC_ENUM_LINKS32:
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 50/55] [media] media-entity: unregister entity links
  2015-08-30  3:07 ` [PATCH v8 50/55] [media] media-entity: unregister entity links Mauro Carvalho Chehab
  2015-08-31 12:48   ` Hans Verkuil
@ 2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-11-23 21:27     ` Laurent Pinchart
  1 sibling, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

Add functions to explicitly unregister all entity links.
This function is called automatically when an entity
link is destroyed.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 064515f2ba9b..a37ccd2edfd5 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -903,6 +903,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
+	media_remove_intf_links(&devnode->intf);
 	media_gobj_remove(&devnode->intf.graph_obj);
 	kfree(devnode);
 }
@@ -944,3 +945,25 @@ void media_remove_intf_link(struct media_link *link)
 	mutex_unlock(&link->graph_obj.mdev->graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_remove_intf_link);
+
+void __media_remove_intf_links(struct media_interface *intf)
+{
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &intf->links, list)
+		__media_remove_intf_link(link);
+
+}
+EXPORT_SYMBOL_GPL(__media_remove_intf_links);
+
+void media_remove_intf_links(struct media_interface *intf)
+{
+	/* Do nothing if the intf is not registered. */
+	if (intf->graph_obj.mdev == NULL)
+		return;
+
+	mutex_lock(&intf->graph_obj.mdev->graph_mutex);
+	__media_remove_intf_links(intf);
+	mutex_unlock(&intf->graph_obj.mdev->graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_remove_intf_links);
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index bc7eb6240795..ca4a4f23362f 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -318,6 +318,9 @@ struct media_link *media_create_intf_link(struct media_entity *entity,
 					    struct media_interface *intf,
 					    u32 flags);
 void media_remove_intf_link(struct media_link *link);
+void __media_remove_intf_links(struct media_interface *intf);
+void media_remove_intf_links(struct media_interface *intf);
+
 
 #define media_entity_call(entity, operation, args...)			\
 	(((entity)->ops && (entity)->ops->operation) ?			\
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 51/55] [media] remove interface links at media_entity_unregister()
  2015-08-30  3:07 ` [PATCH v8 51/55] [media] remove interface links at media_entity_unregister() Mauro Carvalho Chehab
  2015-08-31 12:53   ` Hans Verkuil
@ 2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-11 14:18     ` Hans Verkuil
  1 sibling, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

Interface links connected to an entity should be removed
before being able of removing the entity.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 96a476eeb16e..7c37aeab05bb 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -638,14 +638,30 @@ void media_device_unregister_entity(struct media_entity *entity)
 		return;
 
 	spin_lock(&mdev->lock);
+
+	/* Remove interface links with this entity on it */
+	list_for_each_entry_safe(link, tmp, &mdev->links, graph_obj.list) {
+		if (media_type(link->gobj1) == MEDIA_GRAPH_ENTITY
+		    && link->entity == entity) {
+			media_gobj_remove(&link->graph_obj);
+			kfree(link);
+		}
+	}
+
+	/* Remove all data links that belong to this entity */
 	list_for_each_entry_safe(link, tmp, &entity->links, list) {
 		media_gobj_remove(&link->graph_obj);
 		list_del(&link->list);
 		kfree(link);
 	}
+
+	/* Remove all pads that belong to this entity */
 	for (i = 0; i < entity->num_pads; i++)
 		media_gobj_remove(&entity->pads[i].graph_obj);
+
+	/* Remove the entity */
 	media_gobj_remove(&entity->graph_obj);
+
 	spin_unlock(&mdev->lock);
 	entity->graph_obj.mdev = NULL;
 }
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 52/55] [media] media-device: remove interfaces and interface links
  2015-08-30  3:07 ` [PATCH v8 52/55] [media] media-device: remove interfaces and interface links Mauro Carvalho Chehab
  2015-08-31 12:57   ` Hans Verkuil
@ 2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-11 14:20     ` Hans Verkuil
  2015-11-23 21:22     ` Laurent Pinchart
  1 sibling, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

Just like what's done with entities, when the media controller is
unregistered, release any interface and interface links that
might still be there.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 7c37aeab05bb..0238885fcc74 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -574,6 +574,22 @@ void media_device_unregister(struct media_device *mdev)
 {
 	struct media_entity *entity;
 	struct media_entity *next;
+	struct media_link *link, *tmp_link;
+	struct media_interface *intf, *tmp_intf;
+
+	/* Remove interface links from the media device */
+	list_for_each_entry_safe(link, tmp_link, &mdev->links,
+				 graph_obj.list) {
+		media_gobj_remove(&link->graph_obj);
+		kfree(link);
+	}
+
+	/* Remove all interfaces from the media device */
+	list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces,
+				 graph_obj.list) {
+		media_gobj_remove(&intf->graph_obj);
+		kfree(intf);
+	}
 
 	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
 		media_device_unregister_entity(entity);
@@ -651,7 +667,6 @@ void media_device_unregister_entity(struct media_entity *entity)
 	/* Remove all data links that belong to this entity */
 	list_for_each_entry_safe(link, tmp, &entity->links, list) {
 		media_gobj_remove(&link->graph_obj);
-		list_del(&link->list);
 		kfree(link);
 	}
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index a37ccd2edfd5..cd4d767644df 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -206,6 +206,10 @@ void media_gobj_remove(struct media_gobj *gobj)
 
 	/* Remove the object from mdev list */
 	list_del(&gobj->list);
+
+	/* Links have their own list - we need to drop them there too */
+	if (media_type(gobj) == MEDIA_GRAPH_LINK)
+		list_del(&gobj_to_link(gobj)->list);
 }
 
 /**
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index ca4a4f23362f..fb5f0e21f137 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -153,7 +153,7 @@ struct media_entity {
 };
 
 /**
- * struct media_intf_devnode - Define a Kernel API interface
+ * struct media_interface - Define a Kernel API interface
  *
  * @graph_obj:		embedded graph object
  * @list:		Linked list used to find other interfaces that belong
@@ -163,6 +163,11 @@ struct media_entity {
  *			uapi/media/media.h header, e. g.
  *			MEDIA_INTF_T_*
  * @flags:		Interface flags as defined at uapi/media/media.h
+ *
+ * NOTE: As media_device_unregister() will free the address of the
+ *	 media_interface, this structure should be embedded as the first
+ *	 element of the derived functions, in order for the address to be
+ *	 the same.
  */
 struct media_interface {
 	struct media_gobj		graph_obj;
@@ -179,11 +184,11 @@ struct media_interface {
  * @minor:	Minor number of a device node
  */
 struct media_intf_devnode {
-	struct media_interface		intf;
+	struct media_interface	intf; /* must be first field in struct */
 
 	/* Should match the fields at media_v2_intf_devnode */
-	u32				major;
-	u32				minor;
+	u32			major;
+	u32			minor;
 };
 
 static inline u32 media_entity_id(struct media_entity *entity)
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes
  2015-08-30  3:07 ` [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes Mauro Carvalho Chehab
  2015-08-31 13:23   ` Hans Verkuil
@ 2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-11 14:38     ` Hans Verkuil
  2015-11-23 21:10     ` Laurent Pinchart
  1 sibling, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Hans Verkuil, Sakari Ailus

V4L2 device (and subdevice) nodes should create an interface, if the
Media Controller support is enabled.

Please notice that radio devices should not create an entity, as radio
input/output is either via wires or via ALSA.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 44b330589787..07123dd569c4 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -194,9 +194,12 @@ static void v4l2_device_release(struct device *cd)
 	mutex_unlock(&videodev_lock);
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
-	if (v4l2_dev->mdev &&
-	    vdev->vfl_type != VFL_TYPE_SUBDEV)
-		media_device_unregister_entity(&vdev->entity);
+	if (v4l2_dev->mdev) {
+		/* Remove interfaces and interface links */
+		media_devnode_remove(vdev->intf_devnode);
+		if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN)
+			media_device_unregister_entity(&vdev->entity);
+	}
 #endif
 
 	/* Do not call v4l2_device_put if there is no release callback set.
@@ -713,6 +716,92 @@ static void determine_valid_ioctls(struct video_device *vdev)
 			BASE_VIDIOC_PRIVATE);
 }
 
+
+static int video_register_media_controller(struct video_device *vdev, int type)
+{
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	u32 intf_type;
+	int ret;
+
+	if (!vdev->v4l2_dev->mdev)
+		return 0;
+
+	vdev->entity.type = MEDIA_ENT_T_UNKNOWN;
+
+	switch (type) {
+	case VFL_TYPE_GRABBER:
+		intf_type = MEDIA_INTF_T_V4L_VIDEO;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
+		break;
+	case VFL_TYPE_VBI:
+		intf_type = MEDIA_INTF_T_V4L_VBI;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_VBI;
+		break;
+	case VFL_TYPE_SDR:
+		intf_type = MEDIA_INTF_T_V4L_SWRADIO;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_SWRADIO;
+		break;
+	case VFL_TYPE_RADIO:
+		intf_type = MEDIA_INTF_T_V4L_RADIO;
+		/*
+		 * Radio doesn't have an entity at the V4L2 side to represent
+		 * radio input or output. Instead, the audio input/output goes
+		 * via either physical wires or ALSA.
+		 */
+		break;
+	case VFL_TYPE_SUBDEV:
+		intf_type = MEDIA_INTF_T_V4L_SUBDEV;
+		/* Entity will be created via v4l2_device_register_subdev() */
+		break;
+	default:
+		return 0;
+	}
+
+	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
+		vdev->entity.name = vdev->name;
+
+		/* Needed just for backward compatibility with legacy MC API */
+		vdev->entity.info.dev.major = VIDEO_MAJOR;
+		vdev->entity.info.dev.minor = vdev->minor;
+
+		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
+						   &vdev->entity);
+		if (ret < 0) {
+			printk(KERN_WARNING
+				"%s: media_device_register_entity failed\n",
+				__func__);
+			return ret;
+		}
+	}
+
+	vdev->intf_devnode = media_devnode_create(vdev->v4l2_dev->mdev,
+						  intf_type,
+						  0, VIDEO_MAJOR,
+						  vdev->minor,
+						  GFP_KERNEL);
+	if (!vdev->intf_devnode) {
+		media_device_unregister_entity(&vdev->entity);
+		return -ENOMEM;
+	}
+
+	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
+		struct media_link *link;
+
+		link = media_create_intf_link(&vdev->entity,
+					      &vdev->intf_devnode->intf, 0);
+		if (!link) {
+			media_devnode_remove(vdev->intf_devnode);
+			media_device_unregister_entity(&vdev->entity);
+			return -ENOMEM;
+		}
+	}
+
+	/* FIXME: how to create the other interface links? */
+
+#endif
+	return 0;
+}
+
 /**
  *	__video_register_device - register video4linux devices
  *	@vdev: video device structure we want to register
@@ -908,22 +997,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
 	/* Increase v4l2_device refcount */
 	v4l2_device_get(vdev->v4l2_dev);
 
-#if defined(CONFIG_MEDIA_CONTROLLER)
 	/* Part 5: Register the entity. */
-	if (vdev->v4l2_dev->mdev &&
-	    vdev->vfl_type != VFL_TYPE_SUBDEV) {
-		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
-		vdev->entity.name = vdev->name;
-		vdev->entity.info.dev.major = VIDEO_MAJOR;
-		vdev->entity.info.dev.minor = vdev->minor;
-		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
-			&vdev->entity);
-		if (ret < 0)
-			printk(KERN_WARNING
-			       "%s: media_device_register_entity failed\n",
-			       __func__);
-	}
-#endif
+	ret = video_register_media_controller(vdev, type);
+
 	/* Part 6: Activate this minor. The char device can now be used. */
 	set_bit(V4L2_FL_REGISTERED, &vdev->flags);
 
diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
index 5b0a30b9252b..e788a085ba96 100644
--- a/drivers/media/v4l2-core/v4l2-device.c
+++ b/drivers/media/v4l2-core/v4l2-device.c
@@ -249,6 +249,17 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
 #if defined(CONFIG_MEDIA_CONTROLLER)
 		sd->entity.info.dev.major = VIDEO_MAJOR;
 		sd->entity.info.dev.minor = vdev->minor;
+
+		/* Interface is created by __video_register_device() */
+		if (vdev->v4l2_dev->mdev) {
+			struct media_link *link;
+
+			link = media_create_intf_link(&sd->entity,
+						      &vdev->intf_devnode->intf,
+						      0);
+			if (!link)
+				goto clean_up;
+		}
 #endif
 		sd->devnode = vdev;
 	}
@@ -285,7 +296,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	if (v4l2_dev->mdev) {
-		media_entity_remove_links(&sd->entity);
+		/*
+		 * No need to explicitly remove links, as both pads and
+		 * links are removed by the function below, in the right order
+		 */
 		media_device_unregister_entity(&sd->entity);
 	}
 #endif
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index acbcd2f5fe7f..eeabf20e87a6 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -86,6 +86,7 @@ struct video_device
 {
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	struct media_entity entity;
+	struct media_intf_devnode *intf_devnode;
 #endif
 	/* device ops */
 	const struct v4l2_file_operations *fops;
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 55/55] [media] media-entity.h: document all the structs
  2015-08-30  3:07 ` [PATCH v8 55/55] [media] media-entity.h: document all the structs Mauro Carvalho Chehab
@ 2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-11 14:45     ` Hans Verkuil
  2015-11-23 20:19     ` Laurent Pinchart
  0 siblings, 2 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-06 12:03 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

Only a few structs are documented on kernel-doc-nano format
(the ones added by the MC next gen patches).

Add a documentation for all structs, and ensure that they'll
be producing the documentation at the Kernel's device driver
DocBook.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index fb5f0e21f137..e1a89899deef 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -55,11 +55,13 @@ enum media_gobj_type {
 /**
  * struct media_gobj - Define a graph object.
  *
+ * @mdev:	Pointer to the struct media_device that owns the object
  * @id:		Non-zero object ID identifier. The ID should be unique
  *		inside a media_device, as it is composed by
  *		MEDIA_BITS_PER_TYPE to store the type plus
  *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
  *		(called as "local ID").
+ * @list:	Linked list associated to one of the per-type mdev object lists
  *
  * All objects on the media graph should have this struct embedded
  */
@@ -73,6 +75,28 @@ struct media_gobj {
 struct media_pipeline {
 };
 
+/**
+ * struct media_link - Define a media link graph object.
+ *
+ * @graph_obj:	Embedded structure containing the media object common data
+ * @list:	Linked list associated with an entity or an interface that
+ *		owns the link.
+ * @gobj0:	Part of an union. Used to get the pointer for the first
+ *		graph_object of the link.
+ * @source:	Part of an union. Used only if the first object (gobj0) is
+ *		a pad. On such case, it represents the source pad.
+ * @intf:	Part of an union. Used only if the first object (gobj0) is
+ *		an interface.
+ * @gobj1:	Part of an union. Used to get the pointer for the second
+ *		graph_object of the link.
+ * @source:	Part of an union. Used only if the second object (gobj0) is
+ *		a pad. On such case, it represents the sink pad.
+ * @entity:	Part of an union. Used only if the second object (gobj0) is
+ *		an entity.
+ * @reverse:	Pointer to the link for the reverse direction of a pad to pad
+ *		link.
+ * @flags:	Link flags, as defined at uapi/media.h (MEDIA_LNK_FL_*)
+ */
 struct media_link {
 	struct media_gobj graph_obj;
 	struct list_head list;
@@ -86,15 +110,23 @@ struct media_link {
 		struct media_pad *sink;
 		struct media_entity *entity;
 	};
-	struct media_link *reverse;	/* Link in the reverse direction */
-	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
+	struct media_link *reverse;
+	unsigned long flags;
 };
 
+/**
+ * struct media_pad - Define a media pad graph object.
+ *
+ * @graph_obj:	Embedded structure containing the media object common data
+ * @entity:	Entity where this object belongs
+ * @index:	Pad index in the entity pads array, numbered from 0 to n
+ * @flags:	Pad flags, as defined at uapi/media.h (MEDIA_PAD_FL_*)
+ */
 struct media_pad {
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	struct media_entity *entity;	/* Entity this pad belongs to */
-	u16 index;			/* Pad index in the entity pads array */
-	unsigned long flags;		/* Pad flags (MEDIA_PAD_FL_*) */
+	struct media_entity *entity;
+	u16 index;
+	unsigned long flags;
 };
 
 /**
@@ -113,51 +145,73 @@ struct media_entity_operations {
 	int (*link_validate)(struct media_link *link);
 };
 
+/**
+ * struct media_entity - Define a media entity graph object.
+ *
+ * @graph_obj:	Embedded structure containing the media object common data.
+ * @name:	Entity name.
+ * @type:	Entity type, as defined at uapi/media.h (MEDIA_ENT_T_*)
+ * @revision:	Entity revision - OBSOLETE - should be removed soon.
+ * @flags:	Entity flags, as defined at uapi/media.h (MEDIA_ENT_FL_*)
+ * @group_id:	Entity group ID - OBSOLETE - should be removed soon.
+ * @num_pads:	Number of sink and source pads.
+ * @num_links:	Number of existing links, both enabled and disabled.
+ * @num_backlinks: Number of backlinks
+ * @pads:	Pads array with the size defined by @num_pads.
+ * @links:	Linked list for the data links.
+ * @ops:	Entity operations.
+ * @stream_count: Stream count for the entity.
+ * @use_count:	Use count for the entity.
+ * @pipe:	Pipeline this entity belongs to.
+ * @info:	Union with devnode information.  Kept just for backward
+ * 		compatibility.
+ * @major:	Devnode major number (zero if not applicable). Kept just
+ * 		for backward compatibility.
+ * @minor:	Devnode minor number (zero if not applicable). Kept just
+ * 		for backward compatibility.
+ *
+ * NOTE: @stream_count and @use_count reference counts must never be
+ * negative, but are signed integers on purpose: a simple WARN_ON(<0) check
+ * can be used to detect reference count bugs that would make them negative.
+ */
 struct media_entity {
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	const char *name;		/* Entity name */
-	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
-	u32 revision;			/* Entity revision, driver specific */
-	unsigned long flags;		/* Entity flags (MEDIA_ENT_FL_*) */
-	u32 group_id;			/* Entity group ID */
+	const char *name;
+	u32 type;
+	u32 revision;
+	unsigned long flags;
+	u32 group_id;
 
-	u16 num_pads;			/* Number of sink and source pads */
-	u16 num_links;			/* Number of existing links, both
-					 * enabled and disabled */
-	u16 num_backlinks;		/* Number of backlinks */
+	u16 num_pads;
+	u16 num_links;
+	u16 num_backlinks;
 
-	struct media_pad *pads;		/* Pads array (num_pads objects) */
-	struct list_head links;		/* Pad-to-pad links list */
+	struct media_pad *pads;
+	struct list_head links;
 
-	const struct media_entity_operations *ops;	/* Entity operations */
+	const struct media_entity_operations *ops;
 
 	/* Reference counts must never be negative, but are signed integers on
 	 * purpose: a simple WARN_ON(<0) check can be used to detect reference
 	 * count bugs that would make them negative.
 	 */
-	int stream_count;		/* Stream count for the entity. */
-	int use_count;			/* Use count for the entity. */
+	int stream_count;
+	int use_count;
 
-	struct media_pipeline *pipe;	/* Pipeline this entity belongs to. */
+	struct media_pipeline *pipe;
 
 	union {
-		/* Node specifications */
 		struct {
 			u32 major;
 			u32 minor;
 		} dev;
-
-		/* Sub-device specifications */
-		/* Nothing needed yet */
 	} info;
 };
 
 /**
- * struct media_interface - Define a Kernel API interface
+ * struct media_interface - Define a media interface graph object
  *
  * @graph_obj:		embedded graph object
- * @list:		Linked list used to find other interfaces that belong
- *			to the same media controller
  * @links:		List of links pointing to graph entities
  * @type:		Type of the interface as defined at the
  *			uapi/media/media.h header, e. g.
@@ -177,7 +231,7 @@ struct media_interface {
 };
 
 /**
- * struct media_intf_devnode - Define a Kernel API interface via a device node
+ * struct media_intf_devnode - Define a media interface via a device node
  *
  * @intf:	embedded interface object
  * @major:	Major number of a device node
-- 
2.4.3



^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-09-06 12:03   ` Mauro Carvalho Chehab
@ 2015-09-07 22:18     ` Sakari Ailus
  2015-09-08  1:23       ` Mauro Carvalho Chehab
  2015-09-11 14:08     ` Hans Verkuil
  2015-11-23 22:04     ` Laurent Pinchart
  2 siblings, 1 reply; 309+ messages in thread
From: Sakari Ailus @ 2015-09-07 22:18 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

Hi Mauro,

A few comments below.

On Sun, Sep 06, 2015 at 09:03:09AM -0300, Mauro Carvalho Chehab wrote:
> Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
> with the RFC for the MC next generation.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 5b2c9f7fcd45..96a476eeb16e 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
>  	return ret;
>  }
>  
> +static long __media_device_get_topology(struct media_device *mdev,
> +				      struct media_v2_topology *topo)
> +{
> +	struct media_entity *entity;
> +	struct media_interface *intf;
> +	struct media_pad *pad;
> +	struct media_link *link;
> +	struct media_v2_entity uentity;
> +	struct media_v2_interface uintf;
> +	struct media_v2_pad upad;
> +	struct media_v2_link ulink;
> +	int ret = 0, i;

I think i wants to be unsigned.

> +
> +	topo->topology_version = mdev->topology_version;
> +
> +	/* Get entities and number of entities */
> +	i = 0;
> +	media_device_for_each_entity(entity, mdev) {
> +		i++;
> +
> +		if (ret || !topo->entities)
> +			continue;
> +
> +		if (i > topo->num_entities) {
> +			ret = -ENOSPC;
> +			continue;
> +		}
> +
> +		/* Copy fields to userspace struct if not error */
> +		memset(&uentity, 0, sizeof(uentity));
> +		uentity.id = entity->graph_obj.id;
> +		strncpy(uentity.name, entity->name,
> +			sizeof(uentity.name));
> +
> +		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_entities = i;
> +
> +	/* Get interfaces and number of interfaces */
> +	i = 0;
> +	media_device_for_each_intf(intf, mdev) {
> +		i++;
> +
> +		if (ret || !topo->interfaces)
> +			continue;
> +
> +		if (i > topo->num_interfaces) {
> +			ret = -ENOSPC;
> +			continue;
> +		}
> +
> +		memset(&uintf, 0, sizeof(uintf));
> +
> +		/* Copy intf fields to userspace struct */
> +		uintf.id = intf->graph_obj.id;
> +		uintf.intf_type = intf->type;
> +		uintf.flags = intf->flags;
> +
> +		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
> +			struct media_intf_devnode *devnode;
> +
> +			devnode = intf_to_devnode(intf);
> +
> +			uintf.devnode.major = devnode->major;
> +			uintf.devnode.minor = devnode->minor;
> +		}
> +
> +		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_interfaces = i;
> +
> +	/* Get pads and number of pads */
> +	i = 0;
> +	media_device_for_each_pad(pad, mdev) {
> +		i++;
> +
> +		if (ret || !topo->pads)
> +			continue;
> +
> +		if (i > topo->num_pads) {
> +			ret = -ENOSPC;
> +			continue;
> +		}
> +
> +		memset(&upad, 0, sizeof(upad));
> +
> +		/* Copy pad fields to userspace struct */
> +		upad.id = pad->graph_obj.id;

How about the pad index? Shouldn't that be also passed to the user space for
every pad?

> +		upad.entity_id = pad->entity->graph_obj.id;
> +		upad.flags = pad->flags;
> +
> +		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_pads = i;
> +
> +	/* Get links and number of links */
> +	i = 0;
> +	media_device_for_each_link(link, mdev) {
> +		i++;
> +
> +		if (ret || !topo->links)
> +			continue;
> +
> +		if (i > topo->num_links) {
> +			ret = -ENOSPC;
> +			continue;
> +		}
> +
> +		memset(&ulink, 0, sizeof(ulink));
> +
> +		/* Copy link fields to userspace struct */
> +		ulink.id = link->graph_obj.id;
> +		ulink.source_id = link->gobj0->id;
> +		ulink.sink_id = link->gobj1->id;
> +		ulink.flags = link->flags;
> +
> +		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
> +			ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;
> +
> +		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_links = i;
> +
> +	return ret;
> +}
> +
> +static long media_device_get_topology(struct media_device *mdev,
> +				      struct media_v2_topology __user *utopo)
> +{
> +	struct media_v2_topology ktopo;
> +	int ret;
> +
> +	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
> +
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = __media_device_get_topology(mdev, &ktopo);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));

You can return the result from copy_to_user() without assigning it to ret in
between.

> +
> +	return ret;
> +}
> +
>  static long media_device_ioctl(struct file *filp, unsigned int cmd,
>  			       unsigned long arg)
>  {
> @@ -264,6 +414,13 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
>  		mutex_unlock(&dev->graph_mutex);
>  		break;
>  
> +	case MEDIA_IOC_G_TOPOLOGY:
> +		mutex_lock(&dev->graph_mutex);
> +		ret = media_device_get_topology(dev,
> +				(struct media_v2_topology __user *)arg);
> +		mutex_unlock(&dev->graph_mutex);
> +		break;
> +
>  	default:
>  		ret = -ENOIOCTLCMD;
>  	}
> @@ -312,6 +469,7 @@ static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
>  	case MEDIA_IOC_DEVICE_INFO:
>  	case MEDIA_IOC_ENUM_ENTITIES:
>  	case MEDIA_IOC_SETUP_LINK:
> +	case MEDIA_IOC_G_TOPOLOGY:
>  		return media_device_ioctl(filp, cmd, arg);
>  
>  	case MEDIA_IOC_ENUM_LINKS32:

-- 
Regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-09-07 22:18     ` Sakari Ailus
@ 2015-09-08  1:23       ` Mauro Carvalho Chehab
  2015-09-08  7:26         ` Sakari Ailus
  0 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-08  1:23 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: Linux Media Mailing List

Em Tue, 8 Sep 2015 01:18:30 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> A few comments below.

Thanks for review!

> 
> On Sun, Sep 06, 2015 at 09:03:09AM -0300, Mauro Carvalho Chehab wrote:
> > Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
> > with the RFC for the MC next generation.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index 5b2c9f7fcd45..96a476eeb16e 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
> >  	return ret;
> >  }
> >  
> > +static long __media_device_get_topology(struct media_device *mdev,
> > +				      struct media_v2_topology *topo)
> > +{
> > +	struct media_entity *entity;
> > +	struct media_interface *intf;
> > +	struct media_pad *pad;
> > +	struct media_link *link;
> > +	struct media_v2_entity uentity;
> > +	struct media_v2_interface uintf;
> > +	struct media_v2_pad upad;
> > +	struct media_v2_link ulink;
> > +	int ret = 0, i;
> 
> I think i wants to be unsigned.

Yes, "i" can be unsigned. I'll change that.

> 
> > +
> > +	topo->topology_version = mdev->topology_version;
> > +
> > +	/* Get entities and number of entities */
> > +	i = 0;
> > +	media_device_for_each_entity(entity, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->entities)
> > +			continue;
> > +
> > +		if (i > topo->num_entities) {
> > +			ret = -ENOSPC;
> > +			continue;
> > +		}
> > +
> > +		/* Copy fields to userspace struct if not error */
> > +		memset(&uentity, 0, sizeof(uentity));
> > +		uentity.id = entity->graph_obj.id;
> > +		strncpy(uentity.name, entity->name,
> > +			sizeof(uentity.name));
> > +
> > +		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_entities = i;
> > +
> > +	/* Get interfaces and number of interfaces */
> > +	i = 0;
> > +	media_device_for_each_intf(intf, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->interfaces)
> > +			continue;
> > +
> > +		if (i > topo->num_interfaces) {
> > +			ret = -ENOSPC;
> > +			continue;
> > +		}
> > +
> > +		memset(&uintf, 0, sizeof(uintf));
> > +
> > +		/* Copy intf fields to userspace struct */
> > +		uintf.id = intf->graph_obj.id;
> > +		uintf.intf_type = intf->type;
> > +		uintf.flags = intf->flags;
> > +
> > +		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
> > +			struct media_intf_devnode *devnode;
> > +
> > +			devnode = intf_to_devnode(intf);
> > +
> > +			uintf.devnode.major = devnode->major;
> > +			uintf.devnode.minor = devnode->minor;
> > +		}
> > +
> > +		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_interfaces = i;
> > +
> > +	/* Get pads and number of pads */
> > +	i = 0;
> > +	media_device_for_each_pad(pad, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->pads)
> > +			continue;
> > +
> > +		if (i > topo->num_pads) {
> > +			ret = -ENOSPC;
> > +			continue;
> > +		}
> > +
> > +		memset(&upad, 0, sizeof(upad));
> > +
> > +		/* Copy pad fields to userspace struct */
> > +		upad.id = pad->graph_obj.id;
> 
> How about the pad index? Shouldn't that be also passed to the user space for
> every pad?

We've agreed to not pass the pad index to userspace at the MC workshop.

There are two aspects here to consider:

a) to properly represent the topology (e. g. TOPOLOGY)

Writing the userspace code to support it, I didn't find any need to
pass it to userspace, as the data links are connected via the PAD object 
ID.

The PAD index for userspace is just a number that it uses when
generating the dot graph. See:
	https://mchehab.fedorapeople.org/mc-next-gen/au0828.png

This was generated by this tool:
	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c

And no pad index was required at all. What the tool does is that it
generates the pad numbers just when the --dot option is used,
at the media_show_graphviz() function.

Also, please notice that having a pad index makes harder to support
dynamic PAD addition/removal, as the pad index numberspace will
be discontinued.

b) using the PAD index to setup a link.

As I argued with Hans on one of his reviews, I don't think that
an index is always the best way to refer to a PAD. 

See for example, the entity_1 on the au0828 (ATV decoder). It 
has 3 PADs:
	- pad 0 - sink - receives an ATV signal [1]
	- pad 1 - source - it outputs a Video stream
	- pad 2 - source - it outputs a VBI stream

Pads 1 and 2 are not interchangeable, as they carry different
types of data.

[1] Actually, to be honest, pad 0 there is also wrong. In a matter
of fact, Composite, S-Video and Tuner interfaces are actually
supported by 3 different PADs on the hardware. On some hardware,
it is just a software configuration, but on others, different
pins are used for each different input type. We just don't need
to have all those details ATM on the Media Controller data flow,
as the V4L2 input selection API at the /dev/video0 devnode hides
those dirty details. Note however that, if we end by adding support
for ATV decoder subdevice nodes, such level of detail may be
required.

However some other ATV decoder could have mapped it on some
different order, like:
	- pad 0 - sink - receives an ATV signal
	- pad 1 - source - it outputs a VBI stream
	- pad 2 - source - it outputs a Video stream

Any (generic) application would need to check the properties of
pads 1 and 2 in order to identify what of those pads has video
and what pad has VBI. The pad index is meaningless.

Ok, there are cases where the pad index are meaningful. I guess
that the best is to use properties to properly identify the
pad, or add some strings to them.

Anyway, I guess this should be covered via the properties API.

> 
> > +		upad.entity_id = pad->entity->graph_obj.id;
> > +		upad.flags = pad->flags;
> > +
> > +		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_pads = i;
> > +
> > +	/* Get links and number of links */
> > +	i = 0;
> > +	media_device_for_each_link(link, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->links)
> > +			continue;
> > +
> > +		if (i > topo->num_links) {
> > +			ret = -ENOSPC;
> > +			continue;
> > +		}
> > +
> > +		memset(&ulink, 0, sizeof(ulink));
> > +
> > +		/* Copy link fields to userspace struct */
> > +		ulink.id = link->graph_obj.id;
> > +		ulink.source_id = link->gobj0->id;
> > +		ulink.sink_id = link->gobj1->id;
> > +		ulink.flags = link->flags;
> > +
> > +		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
> > +			ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;
> > +
> > +		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_links = i;
> > +
> > +	return ret;
> > +}
> > +
> > +static long media_device_get_topology(struct media_device *mdev,
> > +				      struct media_v2_topology __user *utopo)
> > +{
> > +	struct media_v2_topology ktopo;
> > +	int ret;
> > +
> > +	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
> > +
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	ret = __media_device_get_topology(mdev, &ktopo);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));
> 
> You can return the result from copy_to_user() without assigning it to ret in
> between.

True. Will change on the next version.

> > +
> > +	return ret;
> > +}
> > +
> >  static long media_device_ioctl(struct file *filp, unsigned int cmd,
> >  			       unsigned long arg)
> >  {
> > @@ -264,6 +414,13 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
> >  		mutex_unlock(&dev->graph_mutex);
> >  		break;
> >  
> > +	case MEDIA_IOC_G_TOPOLOGY:
> > +		mutex_lock(&dev->graph_mutex);
> > +		ret = media_device_get_topology(dev,
> > +				(struct media_v2_topology __user *)arg);
> > +		mutex_unlock(&dev->graph_mutex);
> > +		break;
> > +
> >  	default:
> >  		ret = -ENOIOCTLCMD;
> >  	}
> > @@ -312,6 +469,7 @@ static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
> >  	case MEDIA_IOC_DEVICE_INFO:
> >  	case MEDIA_IOC_ENUM_ENTITIES:
> >  	case MEDIA_IOC_SETUP_LINK:
> > +	case MEDIA_IOC_G_TOPOLOGY:
> >  		return media_device_ioctl(filp, cmd, arg);
> >  
> >  	case MEDIA_IOC_ENUM_LINKS32:
> 

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-09-08  1:23       ` Mauro Carvalho Chehab
@ 2015-09-08  7:26         ` Sakari Ailus
  2015-09-08 10:49           ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Sakari Ailus @ 2015-09-08  7:26 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

Hi Mauro,

On Mon, Sep 07, 2015 at 10:23:57PM -0300, Mauro Carvalho Chehab wrote:
> Em Tue, 8 Sep 2015 01:18:30 +0300
> Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> 
> > Hi Mauro,
> > 
> > A few comments below.
> 
> Thanks for review!

You're welcome!

> > 
> > On Sun, Sep 06, 2015 at 09:03:09AM -0300, Mauro Carvalho Chehab wrote:
> > > Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
> > > with the RFC for the MC next generation.
> > > 
> > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > 
> > > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > > index 5b2c9f7fcd45..96a476eeb16e 100644
> > > --- a/drivers/media/media-device.c
> > > +++ b/drivers/media/media-device.c
> > > @@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
> > >  	return ret;
> > >  }
> > >  
> > > +static long __media_device_get_topology(struct media_device *mdev,
> > > +				      struct media_v2_topology *topo)
> > > +{
> > > +	struct media_entity *entity;
> > > +	struct media_interface *intf;
> > > +	struct media_pad *pad;
> > > +	struct media_link *link;
> > > +	struct media_v2_entity uentity;
> > > +	struct media_v2_interface uintf;
> > > +	struct media_v2_pad upad;
> > > +	struct media_v2_link ulink;
> > > +	int ret = 0, i;
> > 
> > I think i wants to be unsigned.
> 
> Yes, "i" can be unsigned. I'll change that.
> 
> > 
> > > +
> > > +	topo->topology_version = mdev->topology_version;
> > > +
> > > +	/* Get entities and number of entities */
> > > +	i = 0;
> > > +	media_device_for_each_entity(entity, mdev) {
> > > +		i++;
> > > +
> > > +		if (ret || !topo->entities)
> > > +			continue;
> > > +
> > > +		if (i > topo->num_entities) {
> > > +			ret = -ENOSPC;
> > > +			continue;
> > > +		}
> > > +
> > > +		/* Copy fields to userspace struct if not error */
> > > +		memset(&uentity, 0, sizeof(uentity));
> > > +		uentity.id = entity->graph_obj.id;
> > > +		strncpy(uentity.name, entity->name,
> > > +			sizeof(uentity.name));
> > > +
> > > +		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
> > > +			ret = -EFAULT;
> > > +	}
> > > +	topo->num_entities = i;
> > > +
> > > +	/* Get interfaces and number of interfaces */
> > > +	i = 0;
> > > +	media_device_for_each_intf(intf, mdev) {
> > > +		i++;
> > > +
> > > +		if (ret || !topo->interfaces)
> > > +			continue;
> > > +
> > > +		if (i > topo->num_interfaces) {
> > > +			ret = -ENOSPC;
> > > +			continue;
> > > +		}
> > > +
> > > +		memset(&uintf, 0, sizeof(uintf));
> > > +
> > > +		/* Copy intf fields to userspace struct */
> > > +		uintf.id = intf->graph_obj.id;
> > > +		uintf.intf_type = intf->type;
> > > +		uintf.flags = intf->flags;
> > > +
> > > +		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
> > > +			struct media_intf_devnode *devnode;
> > > +
> > > +			devnode = intf_to_devnode(intf);
> > > +
> > > +			uintf.devnode.major = devnode->major;
> > > +			uintf.devnode.minor = devnode->minor;
> > > +		}
> > > +
> > > +		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
> > > +			ret = -EFAULT;
> > > +	}
> > > +	topo->num_interfaces = i;
> > > +
> > > +	/* Get pads and number of pads */
> > > +	i = 0;
> > > +	media_device_for_each_pad(pad, mdev) {
> > > +		i++;
> > > +
> > > +		if (ret || !topo->pads)
> > > +			continue;
> > > +
> > > +		if (i > topo->num_pads) {
> > > +			ret = -ENOSPC;
> > > +			continue;
> > > +		}
> > > +
> > > +		memset(&upad, 0, sizeof(upad));
> > > +
> > > +		/* Copy pad fields to userspace struct */
> > > +		upad.id = pad->graph_obj.id;
> > 
> > How about the pad index? Shouldn't that be also passed to the user space for
> > every pad?
> 
> We've agreed to not pass the pad index to userspace at the MC workshop.
> 
> There are two aspects here to consider:
> 
> a) to properly represent the topology (e. g. TOPOLOGY)
> 
> Writing the userspace code to support it, I didn't find any need to
> pass it to userspace, as the data links are connected via the PAD object 
> ID.
> 
> The PAD index for userspace is just a number that it uses when
> generating the dot graph. See:
> 	https://mchehab.fedorapeople.org/mc-next-gen/au0828.png
> 
> This was generated by this tool:
> 	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c
> 
> And no pad index was required at all. What the tool does is that it
> generates the pad numbers just when the --dot option is used,
> at the media_show_graphviz() function.
> 
> Also, please notice that having a pad index makes harder to support
> dynamic PAD addition/removal, as the pad index numberspace will
> be discontinued.
> 
> b) using the PAD index to setup a link.
> 
> As I argued with Hans on one of his reviews, I don't think that
> an index is always the best way to refer to a PAD. 
> 
> See for example, the entity_1 on the au0828 (ATV decoder). It 
> has 3 PADs:
> 	- pad 0 - sink - receives an ATV signal [1]
> 	- pad 1 - source - it outputs a Video stream
> 	- pad 2 - source - it outputs a VBI stream
> 
> Pads 1 and 2 are not interchangeable, as they carry different
> types of data.
> 
> [1] Actually, to be honest, pad 0 there is also wrong. In a matter
> of fact, Composite, S-Video and Tuner interfaces are actually
> supported by 3 different PADs on the hardware. On some hardware,
> it is just a software configuration, but on others, different
> pins are used for each different input type. We just don't need
> to have all those details ATM on the Media Controller data flow,
> as the V4L2 input selection API at the /dev/video0 devnode hides
> those dirty details. Note however that, if we end by adding support
> for ATV decoder subdevice nodes, such level of detail may be
> required.
> 
> However some other ATV decoder could have mapped it on some
> different order, like:
> 	- pad 0 - sink - receives an ATV signal
> 	- pad 1 - source - it outputs a VBI stream
> 	- pad 2 - source - it outputs a Video stream
> 
> Any (generic) application would need to check the properties of
> pads 1 and 2 in order to identify what of those pads has video
> and what pad has VBI. The pad index is meaningless.
> 
> Ok, there are cases where the pad index are meaningful. I guess
> that the best is to use properties to properly identify the
> pad, or add some strings to them.
> 
> Anyway, I guess this should be covered via the properties API.

That's a good summary, however I believe we have to pay attention to the
existing API in order not to break user space. The current expectation is
that pad numbers start from zero, their range is contiguous and that they
are also stable.

The documentation does not say all that, but that's what's currently
offered. That's what I believe all hardware specific applications expect.
Generic applications probably have no such limitations.

The pad index is indeed just a number but it's an important one. If we
provide the pad ID (i.e. the graph object ID) to the user space, it has none
of the three properties, and missing even one would be enough to break the
user space.

Then, it indeed becomes a naming issue. Names can be stable even if the
index wouldn't be. The user would convert the names to integers that may not
be stable.

Do you have a use case for dynamically adding or removing pads --- wouldn't
it take a change in hardware topology to do that? If it's software only, I'd
definitely favour solutions that didn't involve changes in topology ---
software changes are generally very fast, and changing the media device
topology for that could also affect the device nodes, forcing the user space
to wait for udev to create them. That's very inconvenient when you want to
take a photo, for instance.

-- 
Best regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-09-08  7:26         ` Sakari Ailus
@ 2015-09-08 10:49           ` Mauro Carvalho Chehab
  2015-09-08 13:34             ` Sakari Ailus
  0 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-08 10:49 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: Linux Media Mailing List

Em Tue, 8 Sep 2015 10:26:29 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Mon, Sep 07, 2015 at 10:23:57PM -0300, Mauro Carvalho Chehab wrote:
> > Em Tue, 8 Sep 2015 01:18:30 +0300
> > Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> > 
> > > Hi Mauro,
> > > 
> > > A few comments below.
> > 
> > Thanks for review!
> 
> You're welcome!
> 
> > > 
> > > On Sun, Sep 06, 2015 at 09:03:09AM -0300, Mauro Carvalho Chehab wrote:
> > > > Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
> > > > with the RFC for the MC next generation.
> > > > 
> > > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > > 
> > > > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > > > index 5b2c9f7fcd45..96a476eeb16e 100644
> > > > --- a/drivers/media/media-device.c
> > > > +++ b/drivers/media/media-device.c
> > > > @@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
> > > >  	return ret;
> > > >  }
> > > >  
> > > > +static long __media_device_get_topology(struct media_device *mdev,
> > > > +				      struct media_v2_topology *topo)
> > > > +{
> > > > +	struct media_entity *entity;
> > > > +	struct media_interface *intf;
> > > > +	struct media_pad *pad;
> > > > +	struct media_link *link;
> > > > +	struct media_v2_entity uentity;
> > > > +	struct media_v2_interface uintf;
> > > > +	struct media_v2_pad upad;
> > > > +	struct media_v2_link ulink;
> > > > +	int ret = 0, i;
> > > 
> > > I think i wants to be unsigned.
> > 
> > Yes, "i" can be unsigned. I'll change that.
> > 
> > > 
> > > > +
> > > > +	topo->topology_version = mdev->topology_version;
> > > > +
> > > > +	/* Get entities and number of entities */
> > > > +	i = 0;
> > > > +	media_device_for_each_entity(entity, mdev) {
> > > > +		i++;
> > > > +
> > > > +		if (ret || !topo->entities)
> > > > +			continue;
> > > > +
> > > > +		if (i > topo->num_entities) {
> > > > +			ret = -ENOSPC;
> > > > +			continue;
> > > > +		}
> > > > +
> > > > +		/* Copy fields to userspace struct if not error */
> > > > +		memset(&uentity, 0, sizeof(uentity));
> > > > +		uentity.id = entity->graph_obj.id;
> > > > +		strncpy(uentity.name, entity->name,
> > > > +			sizeof(uentity.name));
> > > > +
> > > > +		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
> > > > +			ret = -EFAULT;
> > > > +	}
> > > > +	topo->num_entities = i;
> > > > +
> > > > +	/* Get interfaces and number of interfaces */
> > > > +	i = 0;
> > > > +	media_device_for_each_intf(intf, mdev) {
> > > > +		i++;
> > > > +
> > > > +		if (ret || !topo->interfaces)
> > > > +			continue;
> > > > +
> > > > +		if (i > topo->num_interfaces) {
> > > > +			ret = -ENOSPC;
> > > > +			continue;
> > > > +		}
> > > > +
> > > > +		memset(&uintf, 0, sizeof(uintf));
> > > > +
> > > > +		/* Copy intf fields to userspace struct */
> > > > +		uintf.id = intf->graph_obj.id;
> > > > +		uintf.intf_type = intf->type;
> > > > +		uintf.flags = intf->flags;
> > > > +
> > > > +		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
> > > > +			struct media_intf_devnode *devnode;
> > > > +
> > > > +			devnode = intf_to_devnode(intf);
> > > > +
> > > > +			uintf.devnode.major = devnode->major;
> > > > +			uintf.devnode.minor = devnode->minor;
> > > > +		}
> > > > +
> > > > +		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
> > > > +			ret = -EFAULT;
> > > > +	}
> > > > +	topo->num_interfaces = i;
> > > > +
> > > > +	/* Get pads and number of pads */
> > > > +	i = 0;
> > > > +	media_device_for_each_pad(pad, mdev) {
> > > > +		i++;
> > > > +
> > > > +		if (ret || !topo->pads)
> > > > +			continue;
> > > > +
> > > > +		if (i > topo->num_pads) {
> > > > +			ret = -ENOSPC;
> > > > +			continue;
> > > > +		}
> > > > +
> > > > +		memset(&upad, 0, sizeof(upad));
> > > > +
> > > > +		/* Copy pad fields to userspace struct */
> > > > +		upad.id = pad->graph_obj.id;
> > > 
> > > How about the pad index? Shouldn't that be also passed to the user space for
> > > every pad?
> > 
> > We've agreed to not pass the pad index to userspace at the MC workshop.
> > 
> > There are two aspects here to consider:
> > 
> > a) to properly represent the topology (e. g. TOPOLOGY)
> > 
> > Writing the userspace code to support it, I didn't find any need to
> > pass it to userspace, as the data links are connected via the PAD object 
> > ID.
> > 
> > The PAD index for userspace is just a number that it uses when
> > generating the dot graph. See:
> > 	https://mchehab.fedorapeople.org/mc-next-gen/au0828.png
> > 
> > This was generated by this tool:
> > 	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c
> > 
> > And no pad index was required at all. What the tool does is that it
> > generates the pad numbers just when the --dot option is used,
> > at the media_show_graphviz() function.
> > 
> > Also, please notice that having a pad index makes harder to support
> > dynamic PAD addition/removal, as the pad index numberspace will
> > be discontinued.
> > 
> > b) using the PAD index to setup a link.
> > 
> > As I argued with Hans on one of his reviews, I don't think that
> > an index is always the best way to refer to a PAD. 
> > 
> > See for example, the entity_1 on the au0828 (ATV decoder). It 
> > has 3 PADs:
> > 	- pad 0 - sink - receives an ATV signal [1]
> > 	- pad 1 - source - it outputs a Video stream
> > 	- pad 2 - source - it outputs a VBI stream
> > 
> > Pads 1 and 2 are not interchangeable, as they carry different
> > types of data.
> > 
> > [1] Actually, to be honest, pad 0 there is also wrong. In a matter
> > of fact, Composite, S-Video and Tuner interfaces are actually
> > supported by 3 different PADs on the hardware. On some hardware,
> > it is just a software configuration, but on others, different
> > pins are used for each different input type. We just don't need
> > to have all those details ATM on the Media Controller data flow,
> > as the V4L2 input selection API at the /dev/video0 devnode hides
> > those dirty details. Note however that, if we end by adding support
> > for ATV decoder subdevice nodes, such level of detail may be
> > required.
> > 
> > However some other ATV decoder could have mapped it on some
> > different order, like:
> > 	- pad 0 - sink - receives an ATV signal
> > 	- pad 1 - source - it outputs a VBI stream
> > 	- pad 2 - source - it outputs a Video stream
> > 
> > Any (generic) application would need to check the properties of
> > pads 1 and 2 in order to identify what of those pads has video
> > and what pad has VBI. The pad index is meaningless.
> > 
> > Ok, there are cases where the pad index are meaningful. I guess
> > that the best is to use properties to properly identify the
> > pad, or add some strings to them.
> > 
> > Anyway, I guess this should be covered via the properties API.
> 
> That's a good summary, however I believe we have to pay attention to the
> existing API in order not to break user space. The current expectation is
> that pad numbers start from zero, their range is contiguous and that they
> are also stable.
> 
> The documentation does not say all that, but that's what's currently
> offered. That's what I believe all hardware specific applications expect.
> Generic applications probably have no such limitations.

That's true, but there are two situations here to consider:

1) existing drivers/applications:
- No dynamic support, so PAD numbers are stable. Index is provided
  via v1;

2) new drivers/applications:
- We need a way to provide stable equivalents to PAD indexes via
  v2.

> The pad index is indeed just a number but it's an important one. If we
> provide the pad ID (i.e. the graph object ID) to the user space, it has none
> of the three properties, and missing even one would be enough to break the
> user space.

No userspace will be broken on v1 ioctls, as it will still be there.

> Then, it indeed becomes a naming issue. Names can be stable even if the
> index wouldn't be. The user would convert the names to integers that may not
> be stable.

Yes, I guess a name is the best alternative here, as it fits both the
cases where a simple number index is enough and cases where userspace
need to use some other criteria to detect the PAD he needs.

> Do you have a use case for dynamically adding or removing pads --- wouldn't
> it take a change in hardware topology to do that? If it's software only, I'd
> definitely favour solutions that didn't involve changes in topology ---
> software changes are generally very fast, and changing the media device
> topology for that could also affect the device nodes, forcing the user space
> to wait for udev to create them. That's very inconvenient when you want to
> take a photo, for instance.

I'm pretty sure we'll need dynamic pad addition/removal in some future,
but they're not of the first use cases I want to address.

There are some hardware that allows to dynamically reconfigure it to
provide more PADs. I've seen two different cases of that, at the DVB
side:

1) One hardware with a fixed number of pads (like 4 sink pads and
   40 source pads), where it is capable of being dynamically
   configured to become 4 independent hardware entities, each one with
   one sink pad and a number of source pads. So, it could start like
   4 entities, with one sink and 10 sources. However, if user needs
   more than 10 sources, it can send a command to the hardware to get
   some unused PADs from the other entities;

2) Firmware or FPGA-based devices, where you can dynamically
   reconfigure the hardware any time. We have one such driver
   merged for 4.3 whose vendor is promising to release the
   FPGA code as an Open Source, in order to allow users to
   change the hardware in real time.

The first case could actually be handled by always creating 4
entities, each with 40 source pads, and adding a new flag to tell
that a pad was not actually created yet, but this sounds hacky
and would allocate 4 times more memory for the PADs than actually
needed. Btw, the memory allocation is already a problem on one of
the hardwares I know that uses this device, as the DVB core doesn't
support dynamic filter reconfiguration neither. The amount of memory
required there to handle each source PAD on a demux is not small,
as one ringbuffer to handle the I/O transfer is needed for each
PAD source. We're working to fix it at the DVB side, but having
the DVB to use a different number of PADs than what's there at
the MC would be really messy.

For the second case, I don't know any alternative but to support
dynamic PAD changes.

Please notice that, on DVB, I don't see any usage for subdevs, so 
there's no need to wait for udev to create new devices to address 
those new entities/pads.

The second case, e. g. a Firmware/FPGA-based device can also work at
the V4L2 side. I remember someone (from Intel - I guess) commenting
about one such hardware on one of our media workshops, but it was
for some hardware he was not allowed to upstream.

Yeah, assuming that someone would upstream such driver and we would
need to find a solution, yeah, reconfiguration while taking a photo
can be very inconvenient.

Perhaps the solution for such case would be to create the new
pads/entities when the camera software would be loaded, and not
when the user takes a photo.

I don't expect us to solve all issues related to dynamic PAD
addition this year, but we should be sure that no API changes
will be needed at G_TOPOLOGY when we add support for it, and
I guess that the right thing here is to provide properties that
would allow userspace to retrieve what's needed to uniquely
identify a PAD on a stable manner. Eventually, some devices
could just use an u32 pad_index properties, while others may
use strings.

Regards,
Mauro



^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-09-08 10:49           ` Mauro Carvalho Chehab
@ 2015-09-08 13:34             ` Sakari Ailus
  2015-09-08 15:11               ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Sakari Ailus @ 2015-09-08 13:34 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

Hi Mauro,

On Tue, Sep 08, 2015 at 07:49:45AM -0300, Mauro Carvalho Chehab wrote:
> Em Tue, 8 Sep 2015 10:26:29 +0300
> Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> 
> > Hi Mauro,
> > 
> > On Mon, Sep 07, 2015 at 10:23:57PM -0300, Mauro Carvalho Chehab wrote:
> > > Em Tue, 8 Sep 2015 01:18:30 +0300
> > > Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> > > 
> > > > Hi Mauro,
> > > > 
> > > > A few comments below.
> > > 
> > > Thanks for review!
> > 
> > You're welcome!
> > 
> > > > 
> > > > On Sun, Sep 06, 2015 at 09:03:09AM -0300, Mauro Carvalho Chehab wrote:
> > > > > Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
> > > > > with the RFC for the MC next generation.
> > > > > 
> > > > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > > > 
> > > > > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > > > > index 5b2c9f7fcd45..96a476eeb16e 100644
> > > > > --- a/drivers/media/media-device.c
> > > > > +++ b/drivers/media/media-device.c
> > > > > @@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
> > > > >  	return ret;
> > > > >  }
> > > > >  
> > > > > +static long __media_device_get_topology(struct media_device *mdev,
> > > > > +				      struct media_v2_topology *topo)
> > > > > +{
> > > > > +	struct media_entity *entity;
> > > > > +	struct media_interface *intf;
> > > > > +	struct media_pad *pad;
> > > > > +	struct media_link *link;
> > > > > +	struct media_v2_entity uentity;
> > > > > +	struct media_v2_interface uintf;
> > > > > +	struct media_v2_pad upad;
> > > > > +	struct media_v2_link ulink;
> > > > > +	int ret = 0, i;
> > > > 
> > > > I think i wants to be unsigned.
> > > 
> > > Yes, "i" can be unsigned. I'll change that.
> > > 
> > > > 
> > > > > +
> > > > > +	topo->topology_version = mdev->topology_version;
> > > > > +
> > > > > +	/* Get entities and number of entities */
> > > > > +	i = 0;
> > > > > +	media_device_for_each_entity(entity, mdev) {
> > > > > +		i++;
> > > > > +
> > > > > +		if (ret || !topo->entities)
> > > > > +			continue;
> > > > > +
> > > > > +		if (i > topo->num_entities) {
> > > > > +			ret = -ENOSPC;
> > > > > +			continue;
> > > > > +		}
> > > > > +
> > > > > +		/* Copy fields to userspace struct if not error */
> > > > > +		memset(&uentity, 0, sizeof(uentity));
> > > > > +		uentity.id = entity->graph_obj.id;
> > > > > +		strncpy(uentity.name, entity->name,
> > > > > +			sizeof(uentity.name));
> > > > > +
> > > > > +		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
> > > > > +			ret = -EFAULT;
> > > > > +	}
> > > > > +	topo->num_entities = i;
> > > > > +
> > > > > +	/* Get interfaces and number of interfaces */
> > > > > +	i = 0;
> > > > > +	media_device_for_each_intf(intf, mdev) {
> > > > > +		i++;
> > > > > +
> > > > > +		if (ret || !topo->interfaces)
> > > > > +			continue;
> > > > > +
> > > > > +		if (i > topo->num_interfaces) {
> > > > > +			ret = -ENOSPC;
> > > > > +			continue;
> > > > > +		}
> > > > > +
> > > > > +		memset(&uintf, 0, sizeof(uintf));
> > > > > +
> > > > > +		/* Copy intf fields to userspace struct */
> > > > > +		uintf.id = intf->graph_obj.id;
> > > > > +		uintf.intf_type = intf->type;
> > > > > +		uintf.flags = intf->flags;
> > > > > +
> > > > > +		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
> > > > > +			struct media_intf_devnode *devnode;
> > > > > +
> > > > > +			devnode = intf_to_devnode(intf);
> > > > > +
> > > > > +			uintf.devnode.major = devnode->major;
> > > > > +			uintf.devnode.minor = devnode->minor;
> > > > > +		}
> > > > > +
> > > > > +		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
> > > > > +			ret = -EFAULT;
> > > > > +	}
> > > > > +	topo->num_interfaces = i;
> > > > > +
> > > > > +	/* Get pads and number of pads */
> > > > > +	i = 0;
> > > > > +	media_device_for_each_pad(pad, mdev) {
> > > > > +		i++;
> > > > > +
> > > > > +		if (ret || !topo->pads)
> > > > > +			continue;
> > > > > +
> > > > > +		if (i > topo->num_pads) {
> > > > > +			ret = -ENOSPC;
> > > > > +			continue;
> > > > > +		}
> > > > > +
> > > > > +		memset(&upad, 0, sizeof(upad));
> > > > > +
> > > > > +		/* Copy pad fields to userspace struct */
> > > > > +		upad.id = pad->graph_obj.id;
> > > > 
> > > > How about the pad index? Shouldn't that be also passed to the user space for
> > > > every pad?
> > > 
> > > We've agreed to not pass the pad index to userspace at the MC workshop.
> > > 
> > > There are two aspects here to consider:
> > > 
> > > a) to properly represent the topology (e. g. TOPOLOGY)
> > > 
> > > Writing the userspace code to support it, I didn't find any need to
> > > pass it to userspace, as the data links are connected via the PAD object 
> > > ID.
> > > 
> > > The PAD index for userspace is just a number that it uses when
> > > generating the dot graph. See:
> > > 	https://mchehab.fedorapeople.org/mc-next-gen/au0828.png
> > > 
> > > This was generated by this tool:
> > > 	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c
> > > 
> > > And no pad index was required at all. What the tool does is that it
> > > generates the pad numbers just when the --dot option is used,
> > > at the media_show_graphviz() function.
> > > 
> > > Also, please notice that having a pad index makes harder to support
> > > dynamic PAD addition/removal, as the pad index numberspace will
> > > be discontinued.
> > > 
> > > b) using the PAD index to setup a link.
> > > 
> > > As I argued with Hans on one of his reviews, I don't think that
> > > an index is always the best way to refer to a PAD. 
> > > 
> > > See for example, the entity_1 on the au0828 (ATV decoder). It 
> > > has 3 PADs:
> > > 	- pad 0 - sink - receives an ATV signal [1]
> > > 	- pad 1 - source - it outputs a Video stream
> > > 	- pad 2 - source - it outputs a VBI stream
> > > 
> > > Pads 1 and 2 are not interchangeable, as they carry different
> > > types of data.
> > > 
> > > [1] Actually, to be honest, pad 0 there is also wrong. In a matter
> > > of fact, Composite, S-Video and Tuner interfaces are actually
> > > supported by 3 different PADs on the hardware. On some hardware,
> > > it is just a software configuration, but on others, different
> > > pins are used for each different input type. We just don't need
> > > to have all those details ATM on the Media Controller data flow,
> > > as the V4L2 input selection API at the /dev/video0 devnode hides
> > > those dirty details. Note however that, if we end by adding support
> > > for ATV decoder subdevice nodes, such level of detail may be
> > > required.
> > > 
> > > However some other ATV decoder could have mapped it on some
> > > different order, like:
> > > 	- pad 0 - sink - receives an ATV signal
> > > 	- pad 1 - source - it outputs a VBI stream
> > > 	- pad 2 - source - it outputs a Video stream
> > > 
> > > Any (generic) application would need to check the properties of
> > > pads 1 and 2 in order to identify what of those pads has video
> > > and what pad has VBI. The pad index is meaningless.
> > > 
> > > Ok, there are cases where the pad index are meaningful. I guess
> > > that the best is to use properties to properly identify the
> > > pad, or add some strings to them.
> > > 
> > > Anyway, I guess this should be covered via the properties API.
> > 
> > That's a good summary, however I believe we have to pay attention to the
> > existing API in order not to break user space. The current expectation is
> > that pad numbers start from zero, their range is contiguous and that they
> > are also stable.
> > 
> > The documentation does not say all that, but that's what's currently
> > offered. That's what I believe all hardware specific applications expect.
> > Generic applications probably have no such limitations.
> 
> That's true, but there are two situations here to consider:
> 
> 1) existing drivers/applications:
> - No dynamic support, so PAD numbers are stable. Index is provided
>   via v1;

Agreed, in such cases it's fine as long as the pad indices will be
essentially defined by the driver --- as they used to.

> 
> 2) new drivers/applications:
> - We need a way to provide stable equivalents to PAD indexes via
>   v2.

I propose to only add them once we have the use case. This could be through
the property API. My hands are pretty full of other work at the moment but
this does not seem urgent either, which is good.

I think that applications that are hardware specific would still often
prefer hard-coding the pad number there, but instead use the new interface.
Do you think we could guarantee the same pad number stability there, as long
as no dynamic hardware changes affecting the pads are made? Such
applications couldn't cope with those changes anyway.

> 
> > The pad index is indeed just a number but it's an important one. If we
> > provide the pad ID (i.e. the graph object ID) to the user space, it has none
> > of the three properties, and missing even one would be enough to break the
> > user space.
> 
> No userspace will be broken on v1 ioctls, as it will still be there.
> 
> > Then, it indeed becomes a naming issue. Names can be stable even if the
> > index wouldn't be. The user would convert the names to integers that may not
> > be stable.
> 
> Yes, I guess a name is the best alternative here, as it fits both the
> cases where a simple number index is enough and cases where userspace
> need to use some other criteria to detect the PAD he needs.

I think the names would have to be entity specific. Otherwise we'll have the
same entity naming problem there.

> 
> > Do you have a use case for dynamically adding or removing pads --- wouldn't
> > it take a change in hardware topology to do that? If it's software only, I'd
> > definitely favour solutions that didn't involve changes in topology ---
> > software changes are generally very fast, and changing the media device
> > topology for that could also affect the device nodes, forcing the user space
> > to wait for udev to create them. That's very inconvenient when you want to
> > take a photo, for instance.
> 
> I'm pretty sure we'll need dynamic pad addition/removal in some future,
> but they're not of the first use cases I want to address.
> 
> There are some hardware that allows to dynamically reconfigure it to
> provide more PADs. I've seen two different cases of that, at the DVB
> side:
> 
> 1) One hardware with a fixed number of pads (like 4 sink pads and
>    40 source pads), where it is capable of being dynamically
>    configured to become 4 independent hardware entities, each one with
>    one sink pad and a number of source pads. So, it could start like
>    4 entities, with one sink and 10 sources. However, if user needs
>    more than 10 sources, it can send a command to the hardware to get
>    some unused PADs from the other entities;

This is not completely unlike many CSI-2 receivers which can share the lanes
found in the receiver block between different receivers, say dividing five
receiver lanes in 4:1:0 or 2:2:1 configuration among three receivers
depending on the connected sensors. Those are not shown to the user space at
all.

Althrough that's configuration made in board design time whereas yours is
runtime if I understand you correctly.

What are these 40 pads in your example? Is it a DVB demux or something else?

I'm not that much worried about the number alone, but if the pads are
indistinguishable from each other, I'd look for other ways to expose (or
avoid exposing) them to the user.

> 
> 2) Firmware or FPGA-based devices, where you can dynamically
>    reconfigure the hardware any time. We have one such driver
>    merged for 4.3 whose vendor is promising to release the
>    FPGA code as an Open Source, in order to allow users to
>    change the hardware in real time.

If you replace the FPGA configuration with another, it's essentially a new
piece of hardware which will require its own driver. Of course you could do
that with some limitations, but you have to take it into account in the
driver in that case.

> 
> The first case could actually be handled by always creating 4
> entities, each with 40 source pads, and adding a new flag to tell
> that a pad was not actually created yet, but this sounds hacky
> and would allocate 4 times more memory for the PADs than actually
> needed. Btw, the memory allocation is already a problem on one of
> the hardwares I know that uses this device, as the DVB core doesn't
> support dynamic filter reconfiguration neither. The amount of memory
> required there to handle each source PAD on a demux is not small,
> as one ringbuffer to handle the I/O transfer is needed for each
> PAD source. We're working to fix it at the DVB side, but having
> the DVB to use a different number of PADs than what's there at
> the MC would be really messy.
> 
> For the second case, I don't know any alternative but to support
> dynamic PAD changes.
> 
> Please notice that, on DVB, I don't see any usage for subdevs, so 
> there's no need to wait for udev to create new devices to address 
> those new entities/pads.
> 
> The second case, e. g. a Firmware/FPGA-based device can also work at
> the V4L2 side. I remember someone (from Intel - I guess) commenting
> about one such hardware on one of our media workshops, but it was
> for some hardware he was not allowed to upstream.
> 
> Yeah, assuming that someone would upstream such driver and we would
> need to find a solution, yeah, reconfiguration while taking a photo
> can be very inconvenient.

Yes. As the "hardware topology" of such a device is essentially defined by
software, I wouldn't try to represent it as hardware. There's a subtle but
significant difference to FPGA devices: FPGAs are essentially hardware,
albeit you can change the layout to whatever you like, whereas the devices
running software require software frameworks to support the device on both
sides (the CPU and the device firmware). They more resemble programmable
GPUs in that sense: even if what the device does (computes) changes, the
drivers do not (and should not).

> Perhaps the solution for such case would be to create the new
> pads/entities when the camera software would be loaded, and not
> when the user takes a photo.
> 
> I don't expect us to solve all issues related to dynamic PAD
> addition this year, but we should be sure that no API changes
> will be needed at G_TOPOLOGY when we add support for it, and
> I guess that the right thing here is to provide properties that
> would allow userspace to retrieve what's needed to uniquely
> identify a PAD on a stable manner. Eventually, some devices
> could just use an u32 pad_index properties, while others may
> use strings.

New properties (such as the name) could be added later on without affecting
the existing users that depend on the index.

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-09-08 13:34             ` Sakari Ailus
@ 2015-09-08 15:11               ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-08 15:11 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: Linux Media Mailing List

Em Tue, 08 Sep 2015 16:34:59 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Tue, Sep 08, 2015 at 07:49:45AM -0300, Mauro Carvalho Chehab wrote:
> > Em Tue, 8 Sep 2015 10:26:29 +0300
> > Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> > 
> > > Hi Mauro,
> > > 
> > > On Mon, Sep 07, 2015 at 10:23:57PM -0300, Mauro Carvalho Chehab wrote:
> > > > Em Tue, 8 Sep 2015 01:18:30 +0300
> > > > Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> > > > 
> > > > > Hi Mauro,
> > > > > 
> > > > > A few comments below.
> > > > 
> > > > Thanks for review!
> > > 
> > > You're welcome!
> > > 
> > > > > 
> > > > > On Sun, Sep 06, 2015 at 09:03:09AM -0300, Mauro Carvalho Chehab wrote:
> > > > > > Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
> > > > > > with the RFC for the MC next generation.
> > > > > > 
> > > > > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > > > > 
> > > > > > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > > > > > index 5b2c9f7fcd45..96a476eeb16e 100644
> > > > > > --- a/drivers/media/media-device.c
> > > > > > +++ b/drivers/media/media-device.c
> > > > > > @@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
> > > > > >  	return ret;
> > > > > >  }
> > > > > >  
> > > > > > +static long __media_device_get_topology(struct media_device *mdev,
> > > > > > +				      struct media_v2_topology *topo)
> > > > > > +{
> > > > > > +	struct media_entity *entity;
> > > > > > +	struct media_interface *intf;
> > > > > > +	struct media_pad *pad;
> > > > > > +	struct media_link *link;
> > > > > > +	struct media_v2_entity uentity;
> > > > > > +	struct media_v2_interface uintf;
> > > > > > +	struct media_v2_pad upad;
> > > > > > +	struct media_v2_link ulink;
> > > > > > +	int ret = 0, i;
> > > > > 
> > > > > I think i wants to be unsigned.
> > > > 
> > > > Yes, "i" can be unsigned. I'll change that.
> > > > 
> > > > > 
> > > > > > +
> > > > > > +	topo->topology_version = mdev->topology_version;
> > > > > > +
> > > > > > +	/* Get entities and number of entities */
> > > > > > +	i = 0;
> > > > > > +	media_device_for_each_entity(entity, mdev) {
> > > > > > +		i++;
> > > > > > +
> > > > > > +		if (ret || !topo->entities)
> > > > > > +			continue;
> > > > > > +
> > > > > > +		if (i > topo->num_entities) {
> > > > > > +			ret = -ENOSPC;
> > > > > > +			continue;
> > > > > > +		}
> > > > > > +
> > > > > > +		/* Copy fields to userspace struct if not error */
> > > > > > +		memset(&uentity, 0, sizeof(uentity));
> > > > > > +		uentity.id = entity->graph_obj.id;
> > > > > > +		strncpy(uentity.name, entity->name,
> > > > > > +			sizeof(uentity.name));
> > > > > > +
> > > > > > +		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
> > > > > > +			ret = -EFAULT;
> > > > > > +	}
> > > > > > +	topo->num_entities = i;
> > > > > > +
> > > > > > +	/* Get interfaces and number of interfaces */
> > > > > > +	i = 0;
> > > > > > +	media_device_for_each_intf(intf, mdev) {
> > > > > > +		i++;
> > > > > > +
> > > > > > +		if (ret || !topo->interfaces)
> > > > > > +			continue;
> > > > > > +
> > > > > > +		if (i > topo->num_interfaces) {
> > > > > > +			ret = -ENOSPC;
> > > > > > +			continue;
> > > > > > +		}
> > > > > > +
> > > > > > +		memset(&uintf, 0, sizeof(uintf));
> > > > > > +
> > > > > > +		/* Copy intf fields to userspace struct */
> > > > > > +		uintf.id = intf->graph_obj.id;
> > > > > > +		uintf.intf_type = intf->type;
> > > > > > +		uintf.flags = intf->flags;
> > > > > > +
> > > > > > +		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
> > > > > > +			struct media_intf_devnode *devnode;
> > > > > > +
> > > > > > +			devnode = intf_to_devnode(intf);
> > > > > > +
> > > > > > +			uintf.devnode.major = devnode->major;
> > > > > > +			uintf.devnode.minor = devnode->minor;
> > > > > > +		}
> > > > > > +
> > > > > > +		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
> > > > > > +			ret = -EFAULT;
> > > > > > +	}
> > > > > > +	topo->num_interfaces = i;
> > > > > > +
> > > > > > +	/* Get pads and number of pads */
> > > > > > +	i = 0;
> > > > > > +	media_device_for_each_pad(pad, mdev) {
> > > > > > +		i++;
> > > > > > +
> > > > > > +		if (ret || !topo->pads)
> > > > > > +			continue;
> > > > > > +
> > > > > > +		if (i > topo->num_pads) {
> > > > > > +			ret = -ENOSPC;
> > > > > > +			continue;
> > > > > > +		}
> > > > > > +
> > > > > > +		memset(&upad, 0, sizeof(upad));
> > > > > > +
> > > > > > +		/* Copy pad fields to userspace struct */
> > > > > > +		upad.id = pad->graph_obj.id;
> > > > > 
> > > > > How about the pad index? Shouldn't that be also passed to the user space for
> > > > > every pad?
> > > > 
> > > > We've agreed to not pass the pad index to userspace at the MC workshop.
> > > > 
> > > > There are two aspects here to consider:
> > > > 
> > > > a) to properly represent the topology (e. g. TOPOLOGY)
> > > > 
> > > > Writing the userspace code to support it, I didn't find any need to
> > > > pass it to userspace, as the data links are connected via the PAD object 
> > > > ID.
> > > > 
> > > > The PAD index for userspace is just a number that it uses when
> > > > generating the dot graph. See:
> > > > 	https://mchehab.fedorapeople.org/mc-next-gen/au0828.png
> > > > 
> > > > This was generated by this tool:
> > > > 	http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c
> > > > 
> > > > And no pad index was required at all. What the tool does is that it
> > > > generates the pad numbers just when the --dot option is used,
> > > > at the media_show_graphviz() function.
> > > > 
> > > > Also, please notice that having a pad index makes harder to support
> > > > dynamic PAD addition/removal, as the pad index numberspace will
> > > > be discontinued.
> > > > 
> > > > b) using the PAD index to setup a link.
> > > > 
> > > > As I argued with Hans on one of his reviews, I don't think that
> > > > an index is always the best way to refer to a PAD. 
> > > > 
> > > > See for example, the entity_1 on the au0828 (ATV decoder). It 
> > > > has 3 PADs:
> > > > 	- pad 0 - sink - receives an ATV signal [1]
> > > > 	- pad 1 - source - it outputs a Video stream
> > > > 	- pad 2 - source - it outputs a VBI stream
> > > > 
> > > > Pads 1 and 2 are not interchangeable, as they carry different
> > > > types of data.
> > > > 
> > > > [1] Actually, to be honest, pad 0 there is also wrong. In a matter
> > > > of fact, Composite, S-Video and Tuner interfaces are actually
> > > > supported by 3 different PADs on the hardware. On some hardware,
> > > > it is just a software configuration, but on others, different
> > > > pins are used for each different input type. We just don't need
> > > > to have all those details ATM on the Media Controller data flow,
> > > > as the V4L2 input selection API at the /dev/video0 devnode hides
> > > > those dirty details. Note however that, if we end by adding support
> > > > for ATV decoder subdevice nodes, such level of detail may be
> > > > required.
> > > > 
> > > > However some other ATV decoder could have mapped it on some
> > > > different order, like:
> > > > 	- pad 0 - sink - receives an ATV signal
> > > > 	- pad 1 - source - it outputs a VBI stream
> > > > 	- pad 2 - source - it outputs a Video stream
> > > > 
> > > > Any (generic) application would need to check the properties of
> > > > pads 1 and 2 in order to identify what of those pads has video
> > > > and what pad has VBI. The pad index is meaningless.
> > > > 
> > > > Ok, there are cases where the pad index are meaningful. I guess
> > > > that the best is to use properties to properly identify the
> > > > pad, or add some strings to them.
> > > > 
> > > > Anyway, I guess this should be covered via the properties API.
> > > 
> > > That's a good summary, however I believe we have to pay attention to the
> > > existing API in order not to break user space. The current expectation is
> > > that pad numbers start from zero, their range is contiguous and that they
> > > are also stable.
> > > 
> > > The documentation does not say all that, but that's what's currently
> > > offered. That's what I believe all hardware specific applications expect.
> > > Generic applications probably have no such limitations.
> > 
> > That's true, but there are two situations here to consider:
> > 
> > 1) existing drivers/applications:
> > - No dynamic support, so PAD numbers are stable. Index is provided
> >   via v1;
> 
> Agreed, in such cases it's fine as long as the pad indices will be
> essentially defined by the driver --- as they used to.

True. Well, the patches I made so far, meant for Kernel v4.4 don't change
them. We need to ensure that newer patches will do changes on a backward
compatible way.

> > 
> > 2) new drivers/applications:
> > - We need a way to provide stable equivalents to PAD indexes via
> >   v2.
> 
> I propose to only add them once we have the use case. This could be through
> the property API. My hands are pretty full of other work at the moment but
> this does not seem urgent either, which is good.

Agreed.

> I think that applications that are hardware specific would still often
> prefer hard-coding the pad number there, but instead use the new interface.
> Do you think we could guarantee the same pad number stability there, as long
> as no dynamic hardware changes affecting the pads are made? Such
> applications couldn't cope with those changes anyway.

I guess so. That will depend, of course, on how you'll be 
implementing the properties API ;)

I would map it as a series of PAD properties where the Kernelspace may
opt to have the ones that makes sense, like:
	- pad_index;
	- pad_data_type;
	- pad_name;
	...

For simple devices (no dynamic support, all pads carry on the same type of
data), it would just use pad index. More complex devices like hybrid TV ones
would use, instead pad_data_type and pad_name.

> > 
> > > The pad index is indeed just a number but it's an important one. If we
> > > provide the pad ID (i.e. the graph object ID) to the user space, it has none
> > > of the three properties, and missing even one would be enough to break the
> > > user space.
> > 
> > No userspace will be broken on v1 ioctls, as it will still be there.
> > 
> > > Then, it indeed becomes a naming issue. Names can be stable even if the
> > > index wouldn't be. The user would convert the names to integers that may not
> > > be stable.
> > 
> > Yes, I guess a name is the best alternative here, as it fits both the
> > cases where a simple number index is enough and cases where userspace
> > need to use some other criteria to detect the PAD he needs.
> 
> I think the names would have to be entity specific. Otherwise we'll have the
> same entity naming problem there.

Agreed.

> 
> > 
> > > Do you have a use case for dynamically adding or removing pads --- wouldn't
> > > it take a change in hardware topology to do that? If it's software only, I'd
> > > definitely favour solutions that didn't involve changes in topology ---
> > > software changes are generally very fast, and changing the media device
> > > topology for that could also affect the device nodes, forcing the user space
> > > to wait for udev to create them. That's very inconvenient when you want to
> > > take a photo, for instance.
> > 
> > I'm pretty sure we'll need dynamic pad addition/removal in some future,
> > but they're not of the first use cases I want to address.
> > 
> > There are some hardware that allows to dynamically reconfigure it to
> > provide more PADs. I've seen two different cases of that, at the DVB
> > side:
> > 
> > 1) One hardware with a fixed number of pads (like 4 sink pads and
> >    40 source pads), where it is capable of being dynamically
> >    configured to become 4 independent hardware entities, each one with
> >    one sink pad and a number of source pads. So, it could start like
> >    4 entities, with one sink and 10 sources. However, if user needs
> >    more than 10 sources, it can send a command to the hardware to get
> >    some unused PADs from the other entities;
> 
> This is not completely unlike many CSI-2 receivers which can share the lanes
> found in the receiver block between different receivers, say dividing five
> receiver lanes in 4:1:0 or 2:2:1 configuration among three receivers
> depending on the connected sensors. Those are not shown to the user space at
> all.
> 
> Althrough that's configuration made in board design time whereas yours is
> runtime if I understand you correctly.

Yes, this is a runtime decision on the case I mentioned.

> 
> What are these 40 pads in your example? Is it a DVB demux or something else?

Yes, DVB demux.

As I explained on IRC, the DVB demux works by setting one filter per PAD.
This filter has either the first 16 bytes of a DVB package or a set of
PIDs.

For each packet a DVB demux receives, it checks the header against one
of the filters there and outputs it to one (or more) output ports.

On a real case example for DVB-C (cable), one single physical channel
has 17 logical channels inside, each with at least one audio and one
video channel, and sometimes other PIDs for interactive contents.
There are some PIDs there with the programming guide, CATV internet,
interactive content and data channels for firmware upgrades.

Some of those channels:

[TNT]
	SERVICE_ID = 48
	VIDEO_PID = 336
	AUDIO_PID = 337 338 849
	PID_86 = 816
	FREQUENCY = 573000000

[Boomerang]
	SERVICE_ID = 57
	VIDEO_PID = 352
	AUDIO_PID = 353 354
	FREQUENCY = 573000000

[Cartoon]
	SERVICE_ID = 104
	VIDEO_PID = 320
	AUDIO_PID = 321 322
	PID_86 = 1840
	PID_05 = 3295
	FREQUENCY = 573000000

[Games]
	SERVICE_ID = 252
	PID_05 = 3047 3046 3045 3044 3042
	FREQUENCY = 573000000

[Soundtracks]
	SERVICE_ID = 342
	AUDIO_PID = 104
	PID_05 = 204
	FREQUENCY = 573000000

It is possible to record one (or more) logical channel(s) while some
logical channel is being displayed, using just one frontend, as all
those 17 channels are at the same frequency.

So, a typical usage would be an user that wants to listen to
the TNT channel, record everything from Boomerang and only
record audio and video from Cartoon. On such use case, the
applications started by the user would be setting:

Demux output#0: filter PID 336 and route to GPU (DRM domain);
Demux output#1: filter PID 337 (or all 3 audio pids) routing to the audio
		IP blocks (ALSA domain);
Demux output#2: filter PID 48 and route to ringbuffer#0
Demux output#3: filter PID 816 and route to ringbuffer #1
Demux output#4: filter PIDs 57, 352 to 354 and route to ringbuffer #2
		ringbuffer#2 will be routed to disk by userspace app.
Demux output#5: filter PIDs 320 to 322 and route to ringbuffer #3
		ringbuffer#3 will be routed to disk by userspace app.

Depending on the program, some of those outputs may need to be
dynamically routed in runtime to a CA module, in order to decrypt the
data. The applications should be able to do that, if needed.

There will be also some other filters set to get the programming
guide, CATV, firmware upgrades, emergency broadcast messages (to
announce events like earthquakes, tsunamis, and other calamity
events at the area), etc. Those filters are configured by some
other applications that are designed specifically to handle those
stuff.

FYI, 40 there is just a random number. The actual number is usually
a power of 2.

A cheap hardware has 16 or 32 such hardware filters on their demux.
Hardware used on STB or TV sets typically have 64 or more filters.
The software implementation usually has 256 filters (the number is
actually defined by the driver, but most just use 256).

The way the DVB core works is that if all hardware filters at the
demux are exhausted, it will implement software filtering/demux 
for the remaining filters.

> I'm not that much worried about the number alone, but if the pads are
> indistinguishable from each other,

All pads work at the same way, but they're not indistinguishible.
They map different ringbuffers used to do I/O via the read()
interface (or, in the future, also via mmap and DMABUF), as explained
above.

For this specific usecase, a pad index could make sense. Another
way to expose it to userspace would be to expose the PID filter
associated with the DEMUX port to userspace.

> I'd look for other ways to expose (or
> avoid exposing) them to the user.

Why avoid exposing? That would break the use case. As explained
earlier, the user applications need to be able to dynamically route
each output of the Demux to the right place, e. g. either to a 
hardware entity (a GPU, ALSA or CA entity) or to an output ringbuffer.

Am I understanding wrong or are you seriously proposing to fork the
Media Controller? Why? This is no different from what the MC already
does. We don't need a duplicated subsystem to do the same thing.

> > 
> > 2) Firmware or FPGA-based devices, where you can dynamically
> >    reconfigure the hardware any time. We have one such driver
> >    merged for 4.3 whose vendor is promising to release the
> >    FPGA code as an Open Source, in order to allow users to
> >    change the hardware in real time.
> 
> If you replace the FPGA configuration with another, it's essentially a new
> piece of hardware which will require its own driver. Of course you could do
> that with some limitations, but you have to take it into account in the
> driver in that case.

Sure. It doesn't make much sense to change the FPGA configuration
to turn a DVB device into a software radio while streaming. Yet,
it could make sense to add more demux filters or CA entities in
runtime, without stopping streaming.

> > The first case could actually be handled by always creating 4
> > entities, each with 40 source pads, and adding a new flag to tell
> > that a pad was not actually created yet, but this sounds hacky
> > and would allocate 4 times more memory for the PADs than actually
> > needed. Btw, the memory allocation is already a problem on one of
> > the hardwares I know that uses this device, as the DVB core doesn't
> > support dynamic filter reconfiguration neither. The amount of memory
> > required there to handle each source PAD on a demux is not small,
> > as one ringbuffer to handle the I/O transfer is needed for each
> > PAD source. We're working to fix it at the DVB side, but having
> > the DVB to use a different number of PADs than what's there at
> > the MC would be really messy.
> > 
> > For the second case, I don't know any alternative but to support
> > dynamic PAD changes.
> > 
> > Please notice that, on DVB, I don't see any usage for subdevs, so 
> > there's no need to wait for udev to create new devices to address 
> > those new entities/pads.
> > 
> > The second case, e. g. a Firmware/FPGA-based device can also work at
> > the V4L2 side. I remember someone (from Intel - I guess) commenting
> > about one such hardware on one of our media workshops, but it was
> > for some hardware he was not allowed to upstream.
> > 
> > Yeah, assuming that someone would upstream such driver and we would
> > need to find a solution, yeah, reconfiguration while taking a photo
> > can be very inconvenient.
> 
> Yes. As the "hardware topology" of such a device is essentially defined by
> software, I wouldn't try to represent it as hardware.

Well, we don't represent hardware at MC. We represent entities. Most
DVB hardware nowadays actually have software embedded there somehow.
Some allow changes in runtime, most don't. We don't and should not
deny an entity to represent something that it is internally implemented
by a FPGA or firmware. We also should not implement the pipelines using
a different framework if the entities are implemented inside a FPGA
or not.

> There's a subtle but
> significant difference to FPGA devices: FPGAs are essentially hardware,
> albeit you can change the layout to whatever you like, whereas the devices
> running software require software frameworks to support the device on both
> sides (the CPU and the device firmware). They more resemble programmable
> GPUs in that sense: even if what the device does (computes) changes, the
> drivers do not (and should not).

Sorry, didn't got what you're meaning here. Drivers/userspace should
not change, but it should be aware of the changes, in order to do
the right thing.

> > Perhaps the solution for such case would be to create the new
> > pads/entities when the camera software would be loaded, and not
> > when the user takes a photo.
> > 
> > I don't expect us to solve all issues related to dynamic PAD
> > addition this year, but we should be sure that no API changes
> > will be needed at G_TOPOLOGY when we add support for it, and
> > I guess that the right thing here is to provide properties that
> > would allow userspace to retrieve what's needed to uniquely
> > identify a PAD on a stable manner. Eventually, some devices
> > could just use an u32 pad_index properties, while others may
> > use strings.
> 
> New properties (such as the name) could be added later on without affecting
> the existing users that depend on the index.

True, and this is also true for pad index.

We need to solve this before adding the SETUP_LINK_V2, and before
start converting apps that sets links to use G_TOPOLOGY as such
apps will need to be able to uniquely identify a PAD.

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 04/55] [media] media: add a common struct to be embed on media graph objects
  2015-08-30  3:06 ` [PATCH v8 04/55] [media] media: add a common struct to be embed on media graph objects Mauro Carvalho Chehab
@ 2015-09-09  7:01   ` Sakari Ailus
  2015-09-09 11:10     ` Mauro Carvalho Chehab
  2015-09-10 14:02   ` Javier Martinez Canillas
  1 sibling, 1 reply; 309+ messages in thread
From: Sakari Ailus @ 2015-09-09  7:01 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Hi Mauro,

On Sun, Aug 30, 2015 at 12:06:15AM -0300, Mauro Carvalho Chehab wrote:
> Due to the MC API proposed changes, we'll need to have an unique
> object ID for all graph objects, and have some shared fields
> that will be common on all media graph objects.
> 
> Right now, the only common object is the object ID, but other
> fields will be added later on.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index cb0ac4e0dfa5..4834172bf6f8 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -27,6 +27,38 @@
>  #include <media/media-device.h>
>  
>  /**
> + *  media_gobj_init - Initialize a graph object
> + *
> + * @mdev:	Pointer to the media_device that contains the object
> + * @type:	Type of the object
> + * @gobj:	Pointer to the object
> + *
> + * This routine initializes the embedded struct media_gobj inside a
> + * media graph object. It is called automatically if media_*_create()
> + * calls are used. However, if the object (entity, link, pad, interface)
> + * is embedded on some other object, this function should be called before
> + * registering the object at the media controller.
> + */
> +void media_gobj_init(struct media_device *mdev,
> +			   enum media_gobj_type type,
> +			   struct media_gobj *gobj)
> +{
> +	/* For now, nothing to do */
> +}
> +
> +/**
> + *  media_gobj_remove - Stop using a graph object on a media device
> + *
> + * @graph_obj:	Pointer to the object
> + *
> + * This should be called at media_device_unregister_*() routines
> + */
> +void media_gobj_remove(struct media_gobj *gobj)
> +{
> +	/* For now, nothing to do */
> +}
> +
> +/**
>   * media_entity_init - Initialize a media entity
>   *
>   * @num_pads: Total number of sink and source pads.
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 0a66fc225559..b1854239a476 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -28,6 +28,39 @@
>  #include <linux/list.h>
>  #include <linux/media.h>
>  
> +/* Enums used internally at the media controller to represent graphs */
> +
> +/**
> + * enum media_gobj_type - type of a graph object
> + *
> + */
> +enum media_gobj_type {
> +	 /* FIXME: add the types here, as we embed media_gobj */
> +	MEDIA_GRAPH_NONE
> +};
> +
> +#define MEDIA_BITS_PER_TYPE		8
> +#define MEDIA_BITS_PER_LOCAL_ID		(32 - MEDIA_BITS_PER_TYPE)
> +#define MEDIA_LOCAL_ID_MASK		 GENMASK(MEDIA_BITS_PER_LOCAL_ID - 1, 0)
> +
> +/* Structs to represent the objects that belong to a media graph */
> +
> +/**
> + * struct media_gobj - Define a graph object.
> + *
> + * @id:		Non-zero object ID identifier. The ID should be unique
> + *		inside a media_device, as it is composed by
> + *		MEDIA_BITS_PER_TYPE to store the type plus
> + *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
> + *		(called as "local ID").
> + *
> + * All objects on the media graph should have this struct embedded
> + */
> +struct media_gobj {
> +	u32			id;
> +};
> +
> +

Two newlines. Looks like one would be enough. A minor matter though.

>  struct media_pipeline {
>  };
>  
> @@ -118,6 +151,26 @@ static inline u32 media_entity_id(struct media_entity *entity)
>  	return entity->id;
>  }
>  
> +static inline enum media_gobj_type media_type(struct media_gobj *gobj)
> +{
> +	return gobj->id >> MEDIA_BITS_PER_LOCAL_ID;
> +}
> +
> +static inline u32 media_localid(struct media_gobj *gobj)
> +{
> +	return gobj->id & MEDIA_LOCAL_ID_MASK;
> +}
> +
> +static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
> +{
> +	u32 id;
> +
> +	id = type << MEDIA_BITS_PER_LOCAL_ID;
> +	id |= local_id & MEDIA_LOCAL_ID_MASK;
> +
> +	return id;
> +}
> +
>  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
>  #define MEDIA_ENTITY_ENUM_MAX_ID	64
>  
> @@ -131,6 +184,14 @@ struct media_entity_graph {
>  	int top;
>  };
>  
> +#define gobj_to_entity(gobj) \
> +		container_of(gobj, struct media_entity, graph_obj)

Just on naming: I'd call this media_gobj_to_entity, as the type is called
media_gobj and secondly the common media prefix is used throughout the MC
API.

Same for the rest of similar macros in further patches.

> +
> +void media_gobj_init(struct media_device *mdev,
> +		    enum media_gobj_type type,
> +		    struct media_gobj *gobj);
> +void media_gobj_remove(struct media_gobj *gobj);
> +
>  int media_entity_init(struct media_entity *entity, u16 num_pads,
>  		struct media_pad *pads);
>  void media_entity_cleanup(struct media_entity *entity);

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 14/55] [media] media: add functions to allow creating interfaces
  2015-09-06 12:02   ` Mauro Carvalho Chehab
@ 2015-09-09  7:34     ` Sakari Ailus
  2015-09-09 10:00       ` Mauro Carvalho Chehab
  2015-09-10 14:22     ` Javier Martinez Canillas
  2015-09-11 12:57     ` Hans Verkuil
  2 siblings, 1 reply; 309+ messages in thread
From: Sakari Ailus @ 2015-09-09  7:34 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

Hi Mauro,

On Sun, Sep 06, 2015 at 09:02:45AM -0300, Mauro Carvalho Chehab wrote:
> Interfaces are different than entities: they represent a
> Kernel<->userspace interaction, while entities represent a
> piece of hardware/firmware/software that executes a function.
> 
> Let's distinguish them by creating a separate structure to
> store the interfaces.
> 
> Later patches should change the existing drivers and logic
> to split the current interface embedded inside the entity
> structure (device nodes) into a separate object of the graph.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index a23c93369a04..dc679dfe8ade 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -44,11 +44,41 @@ static inline const char *gobj_type(enum media_gobj_type type)
>  		return "pad";
>  	case MEDIA_GRAPH_LINK:
>  		return "link";
> +	case MEDIA_GRAPH_INTF_DEVNODE:
> +		return "intf-devnode";
>  	default:
>  		return "unknown";
>  	}
>  }
>  
> +static inline const char *intf_type(struct media_interface *intf)
> +{
> +	switch (intf->type) {
> +	case MEDIA_INTF_T_DVB_FE:
> +		return "frontend";
> +	case MEDIA_INTF_T_DVB_DEMUX:
> +		return "demux";
> +	case MEDIA_INTF_T_DVB_DVR:
> +		return "DVR";
> +	case MEDIA_INTF_T_DVB_CA:
> +		return  "CA";
> +	case MEDIA_INTF_T_DVB_NET:
> +		return "dvbnet";
> +	case MEDIA_INTF_T_V4L_VIDEO:
> +		return "video";
> +	case MEDIA_INTF_T_V4L_VBI:
> +		return "vbi";
> +	case MEDIA_INTF_T_V4L_RADIO:
> +		return "radio";
> +	case MEDIA_INTF_T_V4L_SUBDEV:
> +		return "v4l2-subdev";
> +	case MEDIA_INTF_T_V4L_SWRADIO:
> +		return "swradio";
> +	default:
> +		return "unknown-intf";
> +	}
> +};
> +
>  static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
>  {
>  #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
> @@ -84,6 +114,19 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
>  			"%s: id 0x%08x pad#%d: '%s':%d\n",
>  			event_name, gobj->id, media_localid(gobj),
>  			pad->entity->name, pad->index);
> +		break;
> +	}
> +	case MEDIA_GRAPH_INTF_DEVNODE:
> +	{
> +		struct media_interface *intf = gobj_to_intf(gobj);
> +		struct media_intf_devnode *devnode = intf_to_devnode(intf);
> +
> +		dev_dbg(gobj->mdev->dev,
> +			"%s: id 0x%08x intf_devnode#%d: %s - major: %d, minor: %d\n",
> +			event_name, gobj->id, media_localid(gobj),
> +			intf_type(intf),
> +			devnode->major, devnode->minor);
> +		break;
>  	}
>  	}
>  #endif
> @@ -119,6 +162,9 @@ void media_gobj_init(struct media_device *mdev,
>  	case MEDIA_GRAPH_LINK:
>  		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
>  		break;
> +	case MEDIA_GRAPH_INTF_DEVNODE:
> +		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
> +		break;
>  	}
>  	dev_dbg_obj(__func__, gobj);
>  }
> @@ -793,3 +839,40 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
>  
>  }
>  EXPORT_SYMBOL_GPL(media_entity_remote_pad);
> +
> +
> +/* Functions related to the media interface via device nodes */
> +
> +struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
> +						u32 type, u32 flags,
> +						u32 major, u32 minor,
> +						gfp_t gfp_flags)
> +{
> +	struct media_intf_devnode *devnode;
> +	struct media_interface *intf;
> +
> +	devnode = kzalloc(sizeof(*devnode), gfp_flags);

Do you think the user might want to specify something else then GFP_KERNEL
as gfp_flags? If not, I'd keep this internal to the function. It can also be
added later if needed.

> +	if (!devnode)
> +		return NULL;
> +
> +	intf = &devnode->intf;
> +
> +	intf->type = type;
> +	intf->flags = flags;
> +
> +	devnode->major = major;
> +	devnode->minor = minor;
> +
> +	media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
> +		       &devnode->intf.graph_obj);
> +
> +	return devnode;
> +}
> +EXPORT_SYMBOL_GPL(media_devnode_create);
> +
> +void media_devnode_remove(struct media_intf_devnode *devnode)
> +{
> +	media_gobj_remove(&devnode->intf.graph_obj);
> +	kfree(devnode);
> +}
> +EXPORT_SYMBOL_GPL(media_devnode_remove);
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index 05414e351f8e..3b14394d5701 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -44,6 +44,7 @@ struct device;
>   * @entity_id:	Unique ID used on the last entity registered
>   * @pad_id:	Unique ID used on the last pad registered
>   * @link_id:	Unique ID used on the last link registered
> + * @intf_devnode_id: Unique ID used on the last interface devnode registered

What's your plan with the graph object IDs? Now we have several ID spaces,
one for each object type. Should we export these to the user space, it would
have to come together with an object type, or make the IDs unique.

I think I'd favour a flat ID space for all objects; they are reported
separately by G_TOPOLOGY IOCTL so the user will gain the type information
with the object IDs anyway.

This way, if there's a need to pass the objects back to the kernel, just the
ID will be sufficient. Depending on how the API will develop in the future,
the kernel may continue to keep a single data structure of graph objects or
several data structures.

>   * @entities:	List of registered entities
>   * @lock:	Entities list lock
>   * @graph_mutex: Entities graph operation lock
> @@ -73,6 +74,7 @@ struct media_device {
>  	u32 entity_id;
>  	u32 pad_id;
>  	u32 link_id;
> +	u32 intf_devnode_id;
>  
>  	struct list_head entities;
>  
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 239c4ec30ef6..7df8836f4eef 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -36,11 +36,14 @@
>   * @MEDIA_GRAPH_ENTITY:		Identify a media entity
>   * @MEDIA_GRAPH_PAD:		Identify a media pad
>   * @MEDIA_GRAPH_LINK:		Identify a media link
> + * @MEDIA_GRAPH_INTF_DEVNODE:	Identify a media Kernel API interface via
> + *				a device node
>   */
>  enum media_gobj_type {
>  	MEDIA_GRAPH_ENTITY,
>  	MEDIA_GRAPH_PAD,
>  	MEDIA_GRAPH_LINK,
> +	MEDIA_GRAPH_INTF_DEVNODE,
>  };
>  
>  #define MEDIA_BITS_PER_TYPE		8
> @@ -141,6 +144,34 @@ struct media_entity {
>  	} info;
>  };
>  
> +/**
> + * struct media_intf_devnode - Define a Kernel API interface
> + *
> + * @graph_obj:		embedded graph object
> + * @type:		Type of the interface as defined at the
> + *			uapi/media/media.h header, e. g.
> + *			MEDIA_INTF_T_*
> + * @flags:		Interface flags as defined at uapi/media/media.h
> + */
> +struct media_interface {
> +	struct media_gobj		graph_obj;
> +	u32				type;
> +	u32				flags;
> +};
> +
> +/**
> + * struct media_intf_devnode - Define a Kernel API interface via a device node
> + *
> + * @intf:	embedded interface object
> + * @major:	Major number of a device node
> + * @minor:	Minor number of a device node
> + */
> +struct media_intf_devnode {
> +	struct media_interface		intf;
> +	u32				major;
> +	u32				minor;
> +};
> +
>  static inline u32 media_entity_type(struct media_entity *entity)
>  {
>  	return entity->type & MEDIA_ENT_TYPE_MASK;
> @@ -198,6 +229,18 @@ struct media_entity_graph {
>  #define gobj_to_link(gobj) \
>  		container_of(gobj, struct media_link, graph_obj)
>  
> +#define gobj_to_link(gobj) \
> +		container_of(gobj, struct media_link, graph_obj)

How about media_gobj_to_link() etc.?

> +
> +#define gobj_to_pad(gobj) \
> +		container_of(gobj, struct media_pad, graph_obj)
> +
> +#define gobj_to_intf(gobj) \
> +		container_of(gobj, struct media_interface, graph_obj)
> +
> +#define intf_to_devnode(intf) \
> +		container_of(intf, struct media_intf_devnode, intf)
> +
>  void media_gobj_init(struct media_device *mdev,
>  		    enum media_gobj_type type,
>  		    struct media_gobj *gobj);
> @@ -229,6 +272,11 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
>  					     struct media_pipeline *pipe);
>  void media_entity_pipeline_stop(struct media_entity *entity);
>  
> +struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
> +						u32 type, u32 flags,
> +						u32 major, u32 minor,
> +						gfp_t gfp_flags);
> +void media_devnode_remove(struct media_intf_devnode *devnode);
>  #define media_entity_call(entity, operation, args...)			\
>  	(((entity)->ops && (entity)->ops->operation) ?			\
>  	 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 06/55] [media] media: use media_gobj inside pads
  2015-08-30  3:06 ` [PATCH v8 06/55] [media] media: use media_gobj inside pads Mauro Carvalho Chehab
@ 2015-09-09  7:37   ` Sakari Ailus
  2015-09-10 14:09   ` Javier Martinez Canillas
  1 sibling, 0 replies; 309+ messages in thread
From: Sakari Ailus @ 2015-09-09  7:37 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Hi Mauro,

On Sun, Aug 30, 2015 at 12:06:17AM -0300, Mauro Carvalho Chehab wrote:
> PADs also need unique object IDs that won't conflict with
> the entity object IDs.
> 
> The pad objects are currently created via media_entity_init()
> and, once created, never change.
> 
> While this will likely change in the future in order to
> support dynamic changes, for now we'll keep PADs as arrays
> and initialize the media_gobj embedded structs when
> registering the entity.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 81d6a130efef..3bdda16584fe 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -427,6 +427,8 @@ EXPORT_SYMBOL_GPL(media_device_unregister);
>  int __must_check media_device_register_entity(struct media_device *mdev,
>  					      struct media_entity *entity)
>  {
> +	int i;

unsigned int?

> +
>  	/* Warn if we apparently re-register an entity */
>  	WARN_ON(entity->parent != NULL);
>  	entity->parent = mdev;
> @@ -435,6 +437,12 @@ int __must_check media_device_register_entity(struct media_device *mdev,
>  	/* Initialize media_gobj embedded at the entity */
>  	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
>  	list_add_tail(&entity->list, &mdev->entities);
> +
> +	/* Initialize objects at the pads */
> +	for (i = 0; i < entity->num_pads; i++)
> +		media_gobj_init(mdev, MEDIA_GRAPH_PAD,
> +			       &entity->pads[i].graph_obj);
> +
>  	spin_unlock(&mdev->lock);
>  
>  	return 0;
> @@ -450,12 +458,15 @@ EXPORT_SYMBOL_GPL(media_device_register_entity);
>   */
>  void media_device_unregister_entity(struct media_entity *entity)
>  {
> +	int i;

Ditto. It'd be nice to declare short temporary and counter variables as
last (i.e. after mdev).

>  	struct media_device *mdev = entity->parent;
>  
>  	if (mdev == NULL)
>  		return;
>  
>  	spin_lock(&mdev->lock);
> +	for (i = 0; i < entity->num_pads; i++)
> +		media_gobj_remove(&entity->pads[i].graph_obj);
>  	media_gobj_remove(&entity->graph_obj);
>  	list_del(&entity->list);
>  	spin_unlock(&mdev->lock);
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 888cb88e19bf..377c6655c5d0 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -48,6 +48,9 @@ void media_gobj_init(struct media_device *mdev,
>  	case MEDIA_GRAPH_ENTITY:
>  		gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
>  		break;
> +	case MEDIA_GRAPH_PAD:
> +		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
> +		break;
>  	}
>  }
>  
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index f6deef6e5820..9493721f630e 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -42,6 +42,7 @@ struct device;
>   * @hw_revision: Hardware device revision
>   * @driver_version: Device driver version
>   * @entity_id:	Unique ID used on the last entity registered
> + * @pad_id:	Unique ID used on the last pad registered
>   * @entities:	List of registered entities
>   * @lock:	Entities list lock
>   * @graph_mutex: Entities graph operation lock
> @@ -69,6 +70,7 @@ struct media_device {
>  	u32 driver_version;
>  
>  	u32 entity_id;
> +	u32 pad_id;
>  
>  	struct list_head entities;
>  
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index bb74b5883cbb..ce4c654486d6 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -34,9 +34,11 @@
>   * enum media_gobj_type - type of a graph object
>   *
>   * @MEDIA_GRAPH_ENTITY:		Identify a media entity
> + * @MEDIA_GRAPH_PAD:		Identify a media pad
>   */
>  enum media_gobj_type {
>  	MEDIA_GRAPH_ENTITY,
> +	MEDIA_GRAPH_PAD,
>  };
>  
>  #define MEDIA_BITS_PER_TYPE		8
> @@ -72,6 +74,7 @@ struct media_link {
>  };
>  
>  struct media_pad {
> +	struct media_gobj graph_obj;
>  	struct media_entity *entity;	/* Entity this pad belongs to */
>  	u16 index;			/* Pad index in the entity pads array */
>  	unsigned long flags;		/* Pad flags (MEDIA_PAD_FL_*) */

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 18/55] [media] omap3isp: create links after all subdevs have been bound
  2015-08-30  3:06 ` [PATCH v8 18/55] [media] omap3isp: create links after all subdevs have been bound Mauro Carvalho Chehab
@ 2015-09-09  8:03   ` Sakari Ailus
  2015-09-09  8:48     ` Javier Martinez Canillas
  2015-09-09 10:28     ` Mauro Carvalho Chehab
  0 siblings, 2 replies; 309+ messages in thread
From: Sakari Ailus @ 2015-09-09  8:03 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Javier Martinez Canillas,
	Mauro Carvalho Chehab, Laurent Pinchart

Hi Javier and Mauro,

On Sun, Aug 30, 2015 at 12:06:29AM -0300, Mauro Carvalho Chehab wrote:
> From: Javier Martinez Canillas <javier@osg.samsung.com>
> 
> The omap3isp driver parses the graph endpoints to know how many subdevices
> needs to be registered async and register notifiers callbacks for to know
> when these are bound and when the async registrations are completed.
> 
> Currently the entities pad are linked with the correct ISP input interface
> when the subdevs are bound but it happens before entitities are registered
> with the media device so that won't work now that the entity links list is
> initialized on device registration.
> 
> So instead creating the pad links when the subdevice is bound, create them
> on the complete callback once all the subdevices have been bound but only
> try to create for the ones that have a bus configuration set during bound.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> index b8f6f81d2db2..69e7733d36cd 100644
> --- a/drivers/media/platform/omap3isp/isp.c
> +++ b/drivers/media/platform/omap3isp/isp.c
> @@ -2321,26 +2321,33 @@ static int isp_subdev_notifier_bound(struct v4l2_async_notifier *async,
>  				     struct v4l2_subdev *subdev,
>  				     struct v4l2_async_subdev *asd)
>  {
> -	struct isp_device *isp = container_of(async, struct isp_device,
> -					      notifier);
>  	struct isp_async_subdev *isd =
>  		container_of(asd, struct isp_async_subdev, asd);
> -	int ret;
> -
> -	ret = isp_link_entity(isp, &subdev->entity, isd->bus.interface);
> -	if (ret < 0)
> -		return ret;
>  
>  	isd->sd = subdev;
>  	isd->sd->host_priv = &isd->bus;
>  
> -	return ret;
> +	return 0;
>  }
>  
>  static int isp_subdev_notifier_complete(struct v4l2_async_notifier *async)
>  {
>  	struct isp_device *isp = container_of(async, struct isp_device,
>  					      notifier);
> +	struct v4l2_device *v4l2_dev = &isp->v4l2_dev;
> +	struct v4l2_subdev *sd;
> +	struct isp_bus_cfg *bus;
> +	int ret;
> +
> +	list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
> +		/* Only try to link entities whose interface was set on bound */
> +		if (sd->host_priv) {
> +			bus = (struct isp_bus_cfg *)sd->host_priv;
> +			ret = isp_link_entity(isp, &sd->entity, bus->interface);
> +			if (ret < 0)
> +				return ret;
> +		}
> +	}
>  
>  	return v4l2_device_register_subdev_nodes(&isp->v4l2_dev);
>  }

I think you're working around a problem here, not really fixing it.

This change will create the links only after the media device is registered,
which means the user may obtain a partial enumeration of links if the
enumeration is performed too early.

Before this set, the problem also was that the media device was registered
before the async entities were bound, again making it possible to obtain a
partial enumeration of entities.

What I'd suggest instead is that we split media device initialisation and
registration to the system; that way the media device can be prepared
(entities registered and links created) before it becomes visible to the
user space. I can write a patch for that if you like.

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 18/55] [media] omap3isp: create links after all subdevs have been bound
  2015-09-09  8:03   ` Sakari Ailus
@ 2015-09-09  8:48     ` Javier Martinez Canillas
  2015-12-06  3:05       ` Laurent Pinchart
  2015-09-09 10:28     ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-09  8:48 UTC (permalink / raw)
  To: Sakari Ailus, Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Laurent Pinchart

Hello Sakari,

On 09/09/2015 10:03 AM, Sakari Ailus wrote:
> Hi Javier and Mauro,
> 
> On Sun, Aug 30, 2015 at 12:06:29AM -0300, Mauro Carvalho Chehab wrote:
>> From: Javier Martinez Canillas <javier@osg.samsung.com>
>>
>> The omap3isp driver parses the graph endpoints to know how many subdevices
>> needs to be registered async and register notifiers callbacks for to know
>> when these are bound and when the async registrations are completed.
>>
>> Currently the entities pad are linked with the correct ISP input interface
>> when the subdevs are bound but it happens before entitities are registered
>> with the media device so that won't work now that the entity links list is
>> initialized on device registration.
>>
>> So instead creating the pad links when the subdevice is bound, create them
>> on the complete callback once all the subdevices have been bound but only
>> try to create for the ones that have a bus configuration set during bound.
>>
>> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>>
>> diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
>> index b8f6f81d2db2..69e7733d36cd 100644
>> --- a/drivers/media/platform/omap3isp/isp.c
>> +++ b/drivers/media/platform/omap3isp/isp.c
>> @@ -2321,26 +2321,33 @@ static int isp_subdev_notifier_bound(struct v4l2_async_notifier *async,
>>  				     struct v4l2_subdev *subdev,
>>  				     struct v4l2_async_subdev *asd)
>>  {
>> -	struct isp_device *isp = container_of(async, struct isp_device,
>> -					      notifier);
>>  	struct isp_async_subdev *isd =
>>  		container_of(asd, struct isp_async_subdev, asd);
>> -	int ret;
>> -
>> -	ret = isp_link_entity(isp, &subdev->entity, isd->bus.interface);
>> -	if (ret < 0)
>> -		return ret;
>>  
>>  	isd->sd = subdev;
>>  	isd->sd->host_priv = &isd->bus;
>>  
>> -	return ret;
>> +	return 0;
>>  }
>>  
>>  static int isp_subdev_notifier_complete(struct v4l2_async_notifier *async)
>>  {
>>  	struct isp_device *isp = container_of(async, struct isp_device,
>>  					      notifier);
>> +	struct v4l2_device *v4l2_dev = &isp->v4l2_dev;
>> +	struct v4l2_subdev *sd;
>> +	struct isp_bus_cfg *bus;
>> +	int ret;
>> +
>> +	list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
>> +		/* Only try to link entities whose interface was set on bound */
>> +		if (sd->host_priv) {
>> +			bus = (struct isp_bus_cfg *)sd->host_priv;
>> +			ret = isp_link_entity(isp, &sd->entity, bus->interface);
>> +			if (ret < 0)
>> +				return ret;
>> +		}
>> +	}
>>  
>>  	return v4l2_device_register_subdev_nodes(&isp->v4l2_dev);
>>  }
> 
> I think you're working around a problem here, not really fixing it.
> 
> This change will create the links only after the media device is registered,
> which means the user may obtain a partial enumeration of links if the
> enumeration is performed too early.
> 
> Before this set, the problem also was that the media device was registered
> before the async entities were bound, again making it possible to obtain a
> partial enumeration of entities.
>

You are absolutely correct but I think these are separate issues. The problem
here is that v4l2_async_test_notify() [0] first invokes the bound notifier
callback and then calls v4l2_device_register_subdev() that register the media
entity with the media device.

Since now is a requirement that the entities must be registered prior creating
pads links (because to init a MEDIA_GRAPH_LINK object a mdev has to be set),
$SUBJECT is needed regardless of the race between subdev registration and the
media dev node being available to user-space before everything is registered.
 
> What I'd suggest instead is that we split media device initialisation and
> registration to the system; that way the media device can be prepared
> (entities registered and links created) before it becomes visible to the
> user space. I can write a patch for that if you like.
>

Agreed, looking at the implementation it seems that __media_device_register()
has to be split (possibly being renamed to __media_device_init) so it only
contains the initialization logic and all the media device node registration
logic moved to another function (that would become media_device_register).

I think the media dev node registration has to be made in the complete callback
to make sure that happens when all the subdevs have been already registered.

Is that what you had in mind? I can also write such a patch if you want.

[0]: http://lxr.free-electrons.com/source/drivers/media/v4l2-core/v4l2-async.c#L96
[1]: http://lxr.free-electrons.com/source/drivers/media/media-device.c#L372

Best regards,
-- 
Javier Martinez Canillas
Open Source Group
Samsung Research America

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 14/55] [media] media: add functions to allow creating interfaces
  2015-09-09  7:34     ` Sakari Ailus
@ 2015-09-09 10:00       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-09 10:00 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: Linux Media Mailing List

Em Wed, 09 Sep 2015 10:34:05 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Sun, Sep 06, 2015 at 09:02:45AM -0300, Mauro Carvalho Chehab wrote:
> > Interfaces are different than entities: they represent a
> > Kernel<->userspace interaction, while entities represent a
> > piece of hardware/firmware/software that executes a function.
> > 
> > Let's distinguish them by creating a separate structure to
> > store the interfaces.
> > 
> > Later patches should change the existing drivers and logic
> > to split the current interface embedded inside the entity
> > structure (device nodes) into a separate object of the graph.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index a23c93369a04..dc679dfe8ade 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -44,11 +44,41 @@ static inline const char *gobj_type(enum media_gobj_type type)
> >  		return "pad";
> >  	case MEDIA_GRAPH_LINK:
> >  		return "link";
> > +	case MEDIA_GRAPH_INTF_DEVNODE:
> > +		return "intf-devnode";
> >  	default:
> >  		return "unknown";
> >  	}
> >  }
> >  
> > +static inline const char *intf_type(struct media_interface *intf)
> > +{
> > +	switch (intf->type) {
> > +	case MEDIA_INTF_T_DVB_FE:
> > +		return "frontend";
> > +	case MEDIA_INTF_T_DVB_DEMUX:
> > +		return "demux";
> > +	case MEDIA_INTF_T_DVB_DVR:
> > +		return "DVR";
> > +	case MEDIA_INTF_T_DVB_CA:
> > +		return  "CA";
> > +	case MEDIA_INTF_T_DVB_NET:
> > +		return "dvbnet";
> > +	case MEDIA_INTF_T_V4L_VIDEO:
> > +		return "video";
> > +	case MEDIA_INTF_T_V4L_VBI:
> > +		return "vbi";
> > +	case MEDIA_INTF_T_V4L_RADIO:
> > +		return "radio";
> > +	case MEDIA_INTF_T_V4L_SUBDEV:
> > +		return "v4l2-subdev";
> > +	case MEDIA_INTF_T_V4L_SWRADIO:
> > +		return "swradio";
> > +	default:
> > +		return "unknown-intf";
> > +	}
> > +};
> > +
> >  static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
> >  {
> >  #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
> > @@ -84,6 +114,19 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
> >  			"%s: id 0x%08x pad#%d: '%s':%d\n",
> >  			event_name, gobj->id, media_localid(gobj),
> >  			pad->entity->name, pad->index);
> > +		break;
> > +	}
> > +	case MEDIA_GRAPH_INTF_DEVNODE:
> > +	{
> > +		struct media_interface *intf = gobj_to_intf(gobj);
> > +		struct media_intf_devnode *devnode = intf_to_devnode(intf);
> > +
> > +		dev_dbg(gobj->mdev->dev,
> > +			"%s: id 0x%08x intf_devnode#%d: %s - major: %d, minor: %d\n",
> > +			event_name, gobj->id, media_localid(gobj),
> > +			intf_type(intf),
> > +			devnode->major, devnode->minor);
> > +		break;
> >  	}
> >  	}
> >  #endif
> > @@ -119,6 +162,9 @@ void media_gobj_init(struct media_device *mdev,
> >  	case MEDIA_GRAPH_LINK:
> >  		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
> >  		break;
> > +	case MEDIA_GRAPH_INTF_DEVNODE:
> > +		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
> > +		break;
> >  	}
> >  	dev_dbg_obj(__func__, gobj);
> >  }
> > @@ -793,3 +839,40 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
> >  
> >  }
> >  EXPORT_SYMBOL_GPL(media_entity_remote_pad);
> > +
> > +
> > +/* Functions related to the media interface via device nodes */
> > +
> > +struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
> > +						u32 type, u32 flags,
> > +						u32 major, u32 minor,
> > +						gfp_t gfp_flags)
> > +{
> > +	struct media_intf_devnode *devnode;
> > +	struct media_interface *intf;
> > +
> > +	devnode = kzalloc(sizeof(*devnode), gfp_flags);
> 
> Do you think the user might want to specify something else then GFP_KERNEL
> as gfp_flags? If not, I'd keep this internal to the function. It can also be
> added later if needed.

Yeah, hardly interfaces would need something different than GFP_KERNEL.

I'll change it.

> 
> > +	if (!devnode)
> > +		return NULL;
> > +
> > +	intf = &devnode->intf;
> > +
> > +	intf->type = type;
> > +	intf->flags = flags;
> > +
> > +	devnode->major = major;
> > +	devnode->minor = minor;
> > +
> > +	media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
> > +		       &devnode->intf.graph_obj);
> > +
> > +	return devnode;
> > +}
> > +EXPORT_SYMBOL_GPL(media_devnode_create);
> > +
> > +void media_devnode_remove(struct media_intf_devnode *devnode)
> > +{
> > +	media_gobj_remove(&devnode->intf.graph_obj);
> > +	kfree(devnode);
> > +}
> > +EXPORT_SYMBOL_GPL(media_devnode_remove);
> > diff --git a/include/media/media-device.h b/include/media/media-device.h
> > index 05414e351f8e..3b14394d5701 100644
> > --- a/include/media/media-device.h
> > +++ b/include/media/media-device.h
> > @@ -44,6 +44,7 @@ struct device;
> >   * @entity_id:	Unique ID used on the last entity registered
> >   * @pad_id:	Unique ID used on the last pad registered
> >   * @link_id:	Unique ID used on the last link registered
> > + * @intf_devnode_id: Unique ID used on the last interface devnode registered
> 
> What's your plan with the graph object IDs? Now we have several ID spaces,
> one for each object type. Should we export these to the user space, it would
> have to come together with an object type, or make the IDs unique.

The IDs are always unique, as they're created with 8 bits for type and
24 bits for the per-range ID.

> I think I'd favour a flat ID space for all objects; they are reported
> separately by G_TOPOLOGY IOCTL so the user will gain the type information
> with the object IDs anyway.

Actually, we still need to pass the type somehow to userspace, as we're
actually grouping different object ID types at G_TOPOLOGY IOCTL:

- we're grouping different interface types together (currently, only
  devnode interfaces are there, but we'll add sysfs interfaces and
  maybe more in the future);

- we're passing data and control links together;

- we're passing connectors and entities together (ok, I used a flag
  for connectors, but Hans RFC proposed to use a different type for
  connectors).

> This way, if there's a need to pass the objects back to the kernel, just the
> ID will be sufficient. Depending on how the API will develop in the future,
> the kernel may continue to keep a single data structure of graph objects or
> several data structures.

As I explained earlier, an unique object ID range would break the
graph traversal algorithm at the Kernelspace. Several drivers rely on
the fact that the entities ID will always be below 32. The graph
traversal algorithm assumes that the entity ID will always be below
64. I won't doubt that userspace would also have the same assumption.

So, at least the entity ID should have a separate range than the other
objects.

So, we actually have two alternatives only:

1) two ranges:
	entity_id;
	non_entities_id;

I think it is really ugly to call it as "non_entities_id" and I can't
find any nice name for such range.

2) one range per type, as proposed.

The drawback of one range per type is that mdev will have 4 ranges, so
it will be spending 8 more bytes. It is not much, as we have just one
media_device struct per machine.

There are some advantages of using one range per type: all object
types will start on 1 and will have sequencial numbers. That makes
easier for humans to read. See:

$ ./mc_nextgen_test -i
interface intf_devnode#1: video /dev/video0
interface intf_devnode#2: vbi /dev/vbi0
interface intf_devnode#3: v4l2-subdev /dev/v4l-subdev0
interface intf_devnode#4: frontend /dev/dvb/adapter0/frontend0
interface intf_devnode#5: demux /dev/dvb/adapter0/demux0
interface intf_devnode#6: DVR /dev/dvb/adapter0/dvr0
interface intf_devnode#7: dvbnet /dev/dvb/adapter0/net0

$ ./mc_nextgen_test -e
entity entity#1: 'ATV decoder' au8522 5-0047, 3 pad(s), 1 sink(s), 2 source(s)
entity entity#2: 'tuner' Xceive XC5000, 2 pad(s), 1 sink(s), 1 source(s)
entity entity#3: 'RF connector' Television, 1 pad(s), 1 source(s)
entity entity#4: 'Composite connector' Composite, 1 pad(s), 1 source(s)
entity entity#5: 'S-Video connector' S-Video, 1 pad(s), 1 source(s)
entity entity#6: 'I/O' au0828a video, 1 pad(s), 1 sink(s)
entity entity#7: 'I/O' au0828a vbi, 1 pad(s), 1 sink(s)
entity entity#8: 'DTV demod' Auvitek AU8522 QAM/8VSB Frontend, 2 pad(s), 1 sink(s), 1 source(s)
entity entity#9: 'I/O' demux-tsout #0, 1 pad(s), 1 sink(s)
entity entity#10: 'I/O' demux-tsout #1, 1 pad(s), 1 sink(s)
entity entity#11: 'I/O' demux-tsout #2, 1 pad(s), 1 sink(s)
entity entity#12: 'I/O' demux-tsout #3, 1 pad(s), 1 sink(s)
entity entity#13: 'I/O' demux-tsout #4, 1 pad(s), 1 sink(s)
entity entity#14: 'MPEG-TS demux' dvb-demux, 6 pad(s), 1 sink(s), 5 source(s)
entity entity#15: 'I/O' dvr-tsout #0, 1 pad(s), 1 sink(s)
entity entity#16: 'I/O' dvr-tsout #1, 1 pad(s), 1 sink(s)
entity entity#17: 'I/O' dvr-tsout #2, 1 pad(s), 1 sink(s)
entity entity#18: 'I/O' dvr-tsout #3, 1 pad(s), 1 sink(s)
entity entity#19: 'I/O' dvr-tsout #4, 1 pad(s), 1 sink(s)

 $ ./mc_nextgen_test -l -I
interface link link#1: intf_devnode#1 <=> entity#6 [ENABLED]
interface link link#2: intf_devnode#2 <=> entity#7 [ENABLED]
interface link link#3: intf_devnode#3 <=> entity#2 [ENABLED]
interface link link#4: intf_devnode#4 <=> entity#8 [ENABLED]
interface link link#5: intf_devnode#5 <=> entity#14 [ENABLED]
data link link#6: pad#5 => pad#11 [ENABLED]
data link link#8: pad#12 => pad#18 [ENABLED]
data link link#10: pad#19 => pad#13
data link link#12: pad#20 => pad#14
data link link#14: pad#21 => pad#15
data link link#16: pad#22 => pad#16
data link link#18: pad#23 => pad#17
data link link#20: pad#19 => pad#24
data link link#22: pad#20 => pad#25
data link link#24: pad#21 => pad#26
data link link#26: pad#22 => pad#27
data link link#28: pad#23 => pad#28
interface link link#30: intf_devnode#4 <=> entity#2 [ENABLED]
interface link link#31: intf_devnode#5 <=> entity#9 [ENABLED]
interface link link#32: intf_devnode#5 <=> entity#10 [ENABLED]
interface link link#33: intf_devnode#5 <=> entity#11 [ENABLED]
interface link link#34: intf_devnode#5 <=> entity#12 [ENABLED]
interface link link#35: intf_devnode#5 <=> entity#13 [ENABLED]
interface link link#36: intf_devnode#6 <=> entity#15 [ENABLED]
interface link link#37: intf_devnode#6 <=> entity#16 [ENABLED]
interface link link#38: intf_devnode#6 <=> entity#17 [ENABLED]
interface link link#39: intf_devnode#6 <=> entity#18 [ENABLED]
interface link link#40: intf_devnode#6 <=> entity#19 [ENABLED]
data link link#41: pad#5 => pad#1 [ENABLED]
data link link#43: pad#2 => pad#9 [ENABLED]
data link link#45: pad#3 => pad#10 [ENABLED]
data link link#47: pad#6 => pad#4 [ENABLED]
data link link#49: pad#7 => pad#1
data link link#51: pad#8 => pad#1

That, IMHO, makes easier for humans to read and if they need, for example,
to refer to an interface, use intf#5.

Anyway, I wouldn't mind to change to two ranges, if this is the only
way for us to move forward.

> 
> >   * @entities:	List of registered entities
> >   * @lock:	Entities list lock
> >   * @graph_mutex: Entities graph operation lock
> > @@ -73,6 +74,7 @@ struct media_device {
> >  	u32 entity_id;
> >  	u32 pad_id;
> >  	u32 link_id;
> > +	u32 intf_devnode_id;
> >  
> >  	struct list_head entities;
> >  
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index 239c4ec30ef6..7df8836f4eef 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -36,11 +36,14 @@
> >   * @MEDIA_GRAPH_ENTITY:		Identify a media entity
> >   * @MEDIA_GRAPH_PAD:		Identify a media pad
> >   * @MEDIA_GRAPH_LINK:		Identify a media link
> > + * @MEDIA_GRAPH_INTF_DEVNODE:	Identify a media Kernel API interface via
> > + *				a device node
> >   */
> >  enum media_gobj_type {
> >  	MEDIA_GRAPH_ENTITY,
> >  	MEDIA_GRAPH_PAD,
> >  	MEDIA_GRAPH_LINK,
> > +	MEDIA_GRAPH_INTF_DEVNODE,
> >  };
> >  
> >  #define MEDIA_BITS_PER_TYPE		8
> > @@ -141,6 +144,34 @@ struct media_entity {
> >  	} info;
> >  };
> >  
> > +/**
> > + * struct media_intf_devnode - Define a Kernel API interface
> > + *
> > + * @graph_obj:		embedded graph object
> > + * @type:		Type of the interface as defined at the
> > + *			uapi/media/media.h header, e. g.
> > + *			MEDIA_INTF_T_*
> > + * @flags:		Interface flags as defined at uapi/media/media.h
> > + */
> > +struct media_interface {
> > +	struct media_gobj		graph_obj;
> > +	u32				type;
> > +	u32				flags;
> > +};
> > +
> > +/**
> > + * struct media_intf_devnode - Define a Kernel API interface via a device node
> > + *
> > + * @intf:	embedded interface object
> > + * @major:	Major number of a device node
> > + * @minor:	Minor number of a device node
> > + */
> > +struct media_intf_devnode {
> > +	struct media_interface		intf;
> > +	u32				major;
> > +	u32				minor;
> > +};
> > +
> >  static inline u32 media_entity_type(struct media_entity *entity)
> >  {
> >  	return entity->type & MEDIA_ENT_TYPE_MASK;
> > @@ -198,6 +229,18 @@ struct media_entity_graph {
> >  #define gobj_to_link(gobj) \
> >  		container_of(gobj, struct media_link, graph_obj)
> >  
> > +#define gobj_to_link(gobj) \
> > +		container_of(gobj, struct media_link, graph_obj)
> 
> How about media_gobj_to_link() etc.?

I already answered that to a previous e-mail series:

If you do a check at the global defines with:

$ git grep -B1 container_of include/

you'll see that there are two namespaces used for those container_of
macros:
	1) to_bar
	2) foo_to_bar

Those defines are meant to be short, to avoid needing to break long
lines whenever those macros are used.

(1) is used when the origin type is always the same.
(2) is used when you might have more than one origin type, as we'll
    have on interfaces.

I opted for the longest form (2).

Adding "media_" on those macros would require to re-check all lines where
those macros are used, breaking several of them into two lines for no
good reason, as the only symbols that usually have the "_to_" sub-string
inside Kernel are those container_of macros.

I really hate typing long names. Ok, I do when needed, but this is not
needed here: there's no namespace conflict. I checked, as everything
compiled fine both with allyesconfig/allmodconfig and building for all
arm sub-arch that have media drivers.

> > +
> > +#define gobj_to_pad(gobj) \
> > +		container_of(gobj, struct media_pad, graph_obj)
> > +
> > +#define gobj_to_intf(gobj) \
> > +		container_of(gobj, struct media_interface, graph_obj)
> > +
> > +#define intf_to_devnode(intf) \
> > +		container_of(intf, struct media_intf_devnode, intf)
> > +
> >  void media_gobj_init(struct media_device *mdev,
> >  		    enum media_gobj_type type,
> >  		    struct media_gobj *gobj);
> > @@ -229,6 +272,11 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
> >  					     struct media_pipeline *pipe);
> >  void media_entity_pipeline_stop(struct media_entity *entity);
> >  
> > +struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
> > +						u32 type, u32 flags,
> > +						u32 major, u32 minor,
> > +						gfp_t gfp_flags);
> > +void media_devnode_remove(struct media_intf_devnode *devnode);
> >  #define media_entity_call(entity, operation, args...)			\
> >  	(((entity)->ops && (entity)->ops->operation) ?			\
> >  	 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 18/55] [media] omap3isp: create links after all subdevs have been bound
  2015-09-09  8:03   ` Sakari Ailus
  2015-09-09  8:48     ` Javier Martinez Canillas
@ 2015-09-09 10:28     ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-09 10:28 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Linux Media Mailing List, Javier Martinez Canillas,
	Mauro Carvalho Chehab, Laurent Pinchart

Hi Sakari,

Em Wed, 09 Sep 2015 11:03:33 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Javier and Mauro,
> 
> On Sun, Aug 30, 2015 at 12:06:29AM -0300, Mauro Carvalho Chehab wrote:
> > From: Javier Martinez Canillas <javier@osg.samsung.com>
> > 
> > The omap3isp driver parses the graph endpoints to know how many subdevices
> > needs to be registered async and register notifiers callbacks for to know
> > when these are bound and when the async registrations are completed.
> > 
> > Currently the entities pad are linked with the correct ISP input interface
> > when the subdevs are bound but it happens before entitities are registered
> > with the media device so that won't work now that the entity links list is
> > initialized on device registration.
> > 
> > So instead creating the pad links when the subdevice is bound, create them
> > on the complete callback once all the subdevices have been bound but only
> > try to create for the ones that have a bus configuration set during bound.
> > 
> > Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > index b8f6f81d2db2..69e7733d36cd 100644
> > --- a/drivers/media/platform/omap3isp/isp.c
> > +++ b/drivers/media/platform/omap3isp/isp.c
> > @@ -2321,26 +2321,33 @@ static int isp_subdev_notifier_bound(struct v4l2_async_notifier *async,
> >  				     struct v4l2_subdev *subdev,
> >  				     struct v4l2_async_subdev *asd)
> >  {
> > -	struct isp_device *isp = container_of(async, struct isp_device,
> > -					      notifier);
> >  	struct isp_async_subdev *isd =
> >  		container_of(asd, struct isp_async_subdev, asd);
> > -	int ret;
> > -
> > -	ret = isp_link_entity(isp, &subdev->entity, isd->bus.interface);
> > -	if (ret < 0)
> > -		return ret;
> >  
> >  	isd->sd = subdev;
> >  	isd->sd->host_priv = &isd->bus;
> >  
> > -	return ret;
> > +	return 0;
> >  }
> >  
> >  static int isp_subdev_notifier_complete(struct v4l2_async_notifier *async)
> >  {
> >  	struct isp_device *isp = container_of(async, struct isp_device,
> >  					      notifier);
> > +	struct v4l2_device *v4l2_dev = &isp->v4l2_dev;
> > +	struct v4l2_subdev *sd;
> > +	struct isp_bus_cfg *bus;
> > +	int ret;
> > +
> > +	list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
> > +		/* Only try to link entities whose interface was set on bound */
> > +		if (sd->host_priv) {
> > +			bus = (struct isp_bus_cfg *)sd->host_priv;
> > +			ret = isp_link_entity(isp, &sd->entity, bus->interface);
> > +			if (ret < 0)
> > +				return ret;
> > +		}
> > +	}
> >  
> >  	return v4l2_device_register_subdev_nodes(&isp->v4l2_dev);
> >  }
> 
> I think you're working around a problem here, not really fixing it.
> 
> This change will create the links only after the media device is registered,
> which means the user may obtain a partial enumeration of links if the
> enumeration is performed too early.
> 
> Before this set, the problem also was that the media device was registered
> before the async entities were bound, again making it possible to obtain a
> partial enumeration of entities.

Before of after this series, if userspace tries to read the topology too
early, it will get a partial topology. Before this series, it may lose
entities and links; after this series, it may lose any object.

In any case, userspace won't do the right thing, whatever order we
initialize.

The patches on this series is not meant to solve this issue.

The rationale for this patch is due to a different reason. You should 
notice that, due to the G_TOPOLOGY ioctl requirements, all objects
should have their ID assigned and should be added at the mdev linked
lists, as those are used by G_TOPOLOGY loops that copy the object
data to userspace.

So, before registering/creating any object, the media_device struct
need to exist internally at Kernelspace.

> 
> What I'd suggest instead is that we split media device initialisation and
> registration to the system; that way the media device can be prepared
> (entities registered and links created) before it becomes visible to the
> user space. I can write a patch for that if you like.

Yes, we can split the internal media register stuff from the
creation of the /dev/media0 device node, doing that only after
having everything set in Kernel, as the patch that Javier proposed
on IRC.

Another alternative would be to add a "busy" flag at media_device,
making all ioctl's at /dev/mdeia0 to return -EBUSY during massive
graph changes.

Such flag would be rised at media_device registration and dropped
at the end of the device probe routine.

The advantage of using such flags is that this could be used,
for example, on ARA project, when a module is removed or inserted.

The disadvantage is that current userspace apps may not be prepared
to receive -EBUSY.

I'm OK with both strategies.

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 04/55] [media] media: add a common struct to be embed on media graph objects
  2015-09-09  7:01   ` Sakari Ailus
@ 2015-09-09 11:10     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-09 11:10 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Hi Sakari,

Em Wed, 09 Sep 2015 10:01:49 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Sun, Aug 30, 2015 at 12:06:15AM -0300, Mauro Carvalho Chehab wrote:
> > Due to the MC API proposed changes, we'll need to have an unique
> > object ID for all graph objects, and have some shared fields
> > that will be common on all media graph objects.
> > 
> > Right now, the only common object is the object ID, but other
> > fields will be added later on.

Thanks for the review!

There are already too much patches on the top of this one. So, I'll
be addressing anything we've agreed on at a separate patch series.

I guess this makes easier for reviewers, and avoid spending hours with rebases
and re-tests. On my experience, rebasing a long series like this is not
a good idea, as errors can be introduced on every rebase. So, doing a 
separate patch is usually better.

> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index cb0ac4e0dfa5..4834172bf6f8 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -27,6 +27,38 @@
> >  #include <media/media-device.h>
> >  
> >  /**
> > + *  media_gobj_init - Initialize a graph object
> > + *
> > + * @mdev:	Pointer to the media_device that contains the object
> > + * @type:	Type of the object
> > + * @gobj:	Pointer to the object
> > + *
> > + * This routine initializes the embedded struct media_gobj inside a
> > + * media graph object. It is called automatically if media_*_create()
> > + * calls are used. However, if the object (entity, link, pad, interface)
> > + * is embedded on some other object, this function should be called before
> > + * registering the object at the media controller.
> > + */
> > +void media_gobj_init(struct media_device *mdev,
> > +			   enum media_gobj_type type,
> > +			   struct media_gobj *gobj)
> > +{
> > +	/* For now, nothing to do */
> > +}
> > +
> > +/**
> > + *  media_gobj_remove - Stop using a graph object on a media device
> > + *
> > + * @graph_obj:	Pointer to the object
> > + *
> > + * This should be called at media_device_unregister_*() routines
> > + */
> > +void media_gobj_remove(struct media_gobj *gobj)
> > +{
> > +	/* For now, nothing to do */
> > +}
> > +
> > +/**
> >   * media_entity_init - Initialize a media entity
> >   *
> >   * @num_pads: Total number of sink and source pads.
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index 0a66fc225559..b1854239a476 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -28,6 +28,39 @@
> >  #include <linux/list.h>
> >  #include <linux/media.h>
> >  
> > +/* Enums used internally at the media controller to represent graphs */
> > +
> > +/**
> > + * enum media_gobj_type - type of a graph object
> > + *
> > + */
> > +enum media_gobj_type {
> > +	 /* FIXME: add the types here, as we embed media_gobj */
> > +	MEDIA_GRAPH_NONE
> > +};
> > +
> > +#define MEDIA_BITS_PER_TYPE		8
> > +#define MEDIA_BITS_PER_LOCAL_ID		(32 - MEDIA_BITS_PER_TYPE)
> > +#define MEDIA_LOCAL_ID_MASK		 GENMASK(MEDIA_BITS_PER_LOCAL_ID - 1, 0)
> > +
> > +/* Structs to represent the objects that belong to a media graph */
> > +
> > +/**
> > + * struct media_gobj - Define a graph object.
> > + *
> > + * @id:		Non-zero object ID identifier. The ID should be unique
> > + *		inside a media_device, as it is composed by
> > + *		MEDIA_BITS_PER_TYPE to store the type plus
> > + *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
> > + *		(called as "local ID").
> > + *
> > + * All objects on the media graph should have this struct embedded
> > + */
> > +struct media_gobj {
> > +	u32			id;
> > +};
> > +
> > +
> 
> Two newlines. Looks like one would be enough. A minor matter though.

Ok, I'll be dropping the extra line.

> >  struct media_pipeline {
> >  };
> >  
> > @@ -118,6 +151,26 @@ static inline u32 media_entity_id(struct media_entity *entity)
> >  	return entity->id;
> >  }
> >  
> > +static inline enum media_gobj_type media_type(struct media_gobj *gobj)
> > +{
> > +	return gobj->id >> MEDIA_BITS_PER_LOCAL_ID;
> > +}
> > +
> > +static inline u32 media_localid(struct media_gobj *gobj)
> > +{
> > +	return gobj->id & MEDIA_LOCAL_ID_MASK;
> > +}
> > +
> > +static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
> > +{
> > +	u32 id;
> > +
> > +	id = type << MEDIA_BITS_PER_LOCAL_ID;
> > +	id |= local_id & MEDIA_LOCAL_ID_MASK;
> > +
> > +	return id;
> > +}
> > +
> >  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
> >  #define MEDIA_ENTITY_ENUM_MAX_ID	64
> >  
> > @@ -131,6 +184,14 @@ struct media_entity_graph {
> >  	int top;
> >  };
> >  
> > +#define gobj_to_entity(gobj) \
> > +		container_of(gobj, struct media_entity, graph_obj)
> 
> Just on naming: I'd call this media_gobj_to_entity, as the type is called
> media_gobj and secondly the common media prefix is used throughout the MC
> API.
> 
> Same for the rest of similar macros in further patches.

As commented on my answer to your review on patch 14/55, the above is
the right namespace for this kind of macro. Nobody uses big names for
those container_of macros, as the hole idea is to have a short name
at the form of:
	"to_bar"
or
	"foo_to_bar"

> > +
> > +void media_gobj_init(struct media_device *mdev,
> > +		    enum media_gobj_type type,
> > +		    struct media_gobj *gobj);
> > +void media_gobj_remove(struct media_gobj *gobj);
> > +
> >  int media_entity_init(struct media_entity *entity, u16 num_pads,
> >  		struct media_pad *pads);
> >  void media_entity_cleanup(struct media_entity *entity);
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 01/55] [media] media: create a macro to get entity ID
  2015-08-30  3:06   ` Mauro Carvalho Chehab
@ 2015-09-10 13:58     ` Javier Martinez Canillas
  -1 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 13:58 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	Laurent Pinchart, linux-sh

On Sun, Aug 30, 2015 at 5:06 AM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> Instead of accessing directly entity.id, let's create a macro,
> as this field will be moved into a common struct later on.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 01/55] [media] media: create a macro to get entity ID
@ 2015-09-10 13:58     ` Javier Martinez Canillas
  0 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 13:58 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	Laurent Pinchart, linux-sh

On Sun, Aug 30, 2015 at 5:06 AM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> Instead of accessing directly entity.id, let's create a macro,
> as this field will be moved into a common struct later on.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 04/55] [media] media: add a common struct to be embed on media graph objects
  2015-08-30  3:06 ` [PATCH v8 04/55] [media] media: add a common struct to be embed on media graph objects Mauro Carvalho Chehab
  2015-09-09  7:01   ` Sakari Ailus
@ 2015-09-10 14:02   ` Javier Martinez Canillas
  1 sibling, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 14:02 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

On Sun, Aug 30, 2015 at 5:06 AM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> Due to the MC API proposed changes, we'll need to have an unique
> object ID for all graph objects, and have some shared fields
> that will be common on all media graph objects.
>
> Right now, the only common object is the object ID, but other
> fields will be added later on.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 05/55] [media] media: use media_gobj inside entities
  2015-08-30  3:06 ` [PATCH v8 05/55] [media] media: use media_gobj inside entities Mauro Carvalho Chehab
@ 2015-09-10 14:04   ` Javier Martinez Canillas
  0 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 14:04 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

On Sun, Aug 30, 2015 at 5:06 AM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> As entities are graph objects, let's embed media_gobj
> on it. That ensures an unique ID for entities that can be
> global along the entire media controller.
>
> For now, we'll keep the already existing entity ID. Such
> field need to be dropped at some point, but for now, let's
> not do this, to avoid needing to review all drivers and
> the userspace apps.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 06/55] [media] media: use media_gobj inside pads
  2015-08-30  3:06 ` [PATCH v8 06/55] [media] media: use media_gobj inside pads Mauro Carvalho Chehab
  2015-09-09  7:37   ` Sakari Ailus
@ 2015-09-10 14:09   ` Javier Martinez Canillas
  1 sibling, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 14:09 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

On Sun, Aug 30, 2015 at 5:06 AM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> PADs also need unique object IDs that won't conflict with
> the entity object IDs.
>
> The pad objects are currently created via media_entity_init()
> and, once created, never change.
>
> While this will likely change in the future in order to
> support dynamic changes, for now we'll keep PADs as arrays
> and initialize the media_gobj embedded structs when
> registering the entity.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 07/55] [media] media: use media_gobj inside links
  2015-08-30  3:06 ` [PATCH v8 07/55] [media] media: use media_gobj inside links Mauro Carvalho Chehab
@ 2015-09-10 14:10   ` Javier Martinez Canillas
  0 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 14:10 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

On Sun, Aug 30, 2015 at 5:06 AM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> Just like entities and pads, links also need to have unique
> Object IDs along a given media controller.
>
> So, let's add a media_gobj inside it and initialize
> the object then a new link is created.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 08/55] [media] media: add messages when media device gets (un)registered
  2015-08-30  3:06 ` [PATCH v8 08/55] [media] media: add messages when media device gets (un)registered Mauro Carvalho Chehab
@ 2015-09-10 14:12   ` Javier Martinez Canillas
  0 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 14:12 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

On Sun, Aug 30, 2015 at 5:06 AM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> We can only free the media device after being sure that no
> graph object is used.
>
> In order to help tracking it, let's add debug messages
> that will print when the media controller gets registered
> or unregistered.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 09/55] [media] media: add a debug message to warn about gobj creation/removal
  2015-08-30  3:06 ` [PATCH v8 09/55] [media] media: add a debug message to warn about gobj creation/removal Mauro Carvalho Chehab
@ 2015-09-10 14:14   ` Javier Martinez Canillas
  0 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 14:14 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

On Sun, Aug 30, 2015 at 5:06 AM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> It helps to check if the media controller is doing the
> right thing with the object creation and removal.
>
> No extra code/data will be produced if DEBUG or
> CONFIG_DYNAMIC_DEBUG is not enabled.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 10/55] [media] media: rename the function that create pad links
  2015-08-30  3:06   ` Mauro Carvalho Chehab
  (?)
  (?)
@ 2015-09-10 14:16     ` Javier Martinez Canillas
  -1 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 14:16 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Aug 30, 2015 at 5:06 AM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> With the new API, a link can be either between two PADs or between an interface
> and an entity. So, we need to use a better name for the function that create
> links between two pads.
>
> So, rename the such function to media_create_pad_link().
>
> No functional changes.
>
> This patch was created via this shell script:
>         for i in $(find drivers/media -name '*.[ch]' -type f) $(find drivers/staging/media -name '*.[ch]' -type f) $(find include/ -name '*.h' -type f) ; do sed s,media_entity_create_link,media_create_pad_link,g <$i >a && mv a $i; done
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 10/55] [media] media: rename the function that create pad links
@ 2015-09-10 14:16     ` Javier Martinez Canillas
  0 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 14:16 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Jonathan Corbet,
	Kyungmin Park, Andrzej Hajda, Sakari Ailus, Sylwester Nawrocki,
	Kukjin Kim, Krzysztof Kozlowski, Laurent Pinchart, Hyun Kwon,
	Michal Simek, Sören Brinkmann, Greg Kroah-Hartman,
	Hans Verkuil, Rafael Lourenço de Lima Chehab, Shuah Khan,
	Matthias Schwarzott, Antti Palosaari, Olli Salonen,
	Tommi Rantala, Navya Sri Nizamkari, Boris BREZILLON, Aya Mahfouz,
	anuvazhayil, Mahati Chamarthy, Prabhakar Lad, Jiayi Ye,
	Wolfram Sang, Heena Sirwani, linux-doc, linux-arm-kernel,
	linux-samsung-soc, linux-sh, devel

On Sun, Aug 30, 2015 at 5:06 AM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> With the new API, a link can be either between two PADs or between an interface
> and an entity. So, we need to use a better name for the function that create
> links between two pads.
>
> So, rename the such function to media_create_pad_link().
>
> No functional changes.
>
> This patch was created via this shell script:
>         for i in $(find drivers/media -name '*.[ch]' -type f) $(find drivers/staging/media -name '*.[ch]' -type f) $(find include/ -name '*.h' -type f) ; do sed s,media_entity_create_link,media_create_pad_link,g <$i >a && mv a $i; done
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 10/55] [media] media: rename the function that create pad links
@ 2015-09-10 14:16     ` Javier Martinez Canillas
  0 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 14:16 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Jonathan Corbet,
	Kyungmin Park, Andrzej Hajda, Sakari Ailus, Sylwester Nawrocki,
	Kukjin Kim, Krzysztof Kozlowski, Laurent Pinchart, Hyun Kwon,
	Michal Simek, Sören Brinkmann, Greg Kroah-Hartman,
	Hans Verkuil, Rafael Lourenço de Lima Chehab, Shuah Khan,
	Matthias Schwarzott, Antti Palosaari, Olli Salonen

On Sun, Aug 30, 2015 at 5:06 AM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> With the new API, a link can be either between two PADs or between an interface
> and an entity. So, we need to use a better name for the function that create
> links between two pads.
>
> So, rename the such function to media_create_pad_link().
>
> No functional changes.
>
> This patch was created via this shell script:
>         for i in $(find drivers/media -name '*.[ch]' -type f) $(find drivers/staging/media -name '*.[ch]' -type f) $(find include/ -name '*.h' -type f) ; do sed s,media_entity_create_link,media_create_pad_link,g <$i >a && mv a $i; done
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH v8 10/55] [media] media: rename the function that create pad links
@ 2015-09-10 14:16     ` Javier Martinez Canillas
  0 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 14:16 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Aug 30, 2015 at 5:06 AM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> With the new API, a link can be either between two PADs or between an interface
> and an entity. So, we need to use a better name for the function that create
> links between two pads.
>
> So, rename the such function to media_create_pad_link().
>
> No functional changes.
>
> This patch was created via this shell script:
>         for i in $(find drivers/media -name '*.[ch]' -type f) $(find drivers/staging/media -name '*.[ch]' -type f) $(find include/ -name '*.h' -type f) ; do sed s,media_entity_create_link,media_create_pad_link,g <$i >a && mv a $i; done
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 13/55] [media] uapi/media.h: Declare interface types for V4L2 and DVB
@ 2015-09-10 14:19     ` Javier Martinez Canillas
  0 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 14:19 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-api

On Sun, Aug 30, 2015 at 5:06 AM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> Declare the interface types that will be used by the new
> G_TOPOLOGY ioctl that will be defined latter on.
>
> For now, we need those types, as they'll be used on the
> internal structs associated with the new media_interface
> graph object defined on the next patch.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 13/55] [media] uapi/media.h: Declare interface types for V4L2 and DVB
@ 2015-09-10 14:19     ` Javier Martinez Canillas
  0 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 14:19 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	linux-api-u79uwXL29TY76Z2rM5mHXA

On Sun, Aug 30, 2015 at 5:06 AM, Mauro Carvalho Chehab
<mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org> wrote:
> Declare the interface types that will be used by the new
> G_TOPOLOGY ioctl that will be defined latter on.
>
> For now, we need those types, as they'll be used on the
> internal structs associated with the new media_interface
> graph object defined on the next patch.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>
> Acked-by: Hans Verkuil <hans.verkuil-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
>

Reviewed-by: Javier Martinez Canillas <javier-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 14/55] [media] media: add functions to allow creating interfaces
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  2015-09-09  7:34     ` Sakari Ailus
@ 2015-09-10 14:22     ` Javier Martinez Canillas
  2015-09-11 12:57     ` Hans Verkuil
  2 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 14:22 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

On Sun, Sep 6, 2015 at 2:02 PM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> Interfaces are different than entities: they represent a
> Kernel<->userspace interaction, while entities represent a
> piece of hardware/firmware/software that executes a function.
>
> Let's distinguish them by creating a separate structure to
> store the interfaces.
>
> Later patches should change the existing drivers and logic
> to split the current interface embedded inside the entity
> structure (device nodes) into a separate object of the graph.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 15/55] [media] uapi/media.h: Declare interface types for ALSA
  2015-09-06 12:02     ` Mauro Carvalho Chehab
  (?)
@ 2015-09-10 14:23     ` Javier Martinez Canillas
  -1 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-09-10 14:23 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, linux-api

On Sun, Sep 6, 2015 at 2:02 PM, Mauro Carvalho Chehab
<mchehab@osg.samsung.com> wrote:
> Declare the interface types to be used on alsa for the new
> G_TOPOLOGY ioctl.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>

Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 14/55] [media] media: add functions to allow creating interfaces
  2015-09-06 12:02   ` Mauro Carvalho Chehab
  2015-09-09  7:34     ` Sakari Ailus
  2015-09-10 14:22     ` Javier Martinez Canillas
@ 2015-09-11 12:57     ` Hans Verkuil
  2015-12-08 14:36       ` Mauro Carvalho Chehab
  2 siblings, 1 reply; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 12:57 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List

On 09/06/2015 02:02 PM, Mauro Carvalho Chehab wrote:
> Interfaces are different than entities: they represent a
> Kernel<->userspace interaction, while entities represent a
> piece of hardware/firmware/software that executes a function.
> 
> Let's distinguish them by creating a separate structure to
> store the interfaces.
> 
> Later patches should change the existing drivers and logic
> to split the current interface embedded inside the entity
> structure (device nodes) into a separate object of the graph.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

But see a small note below:

> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index a23c93369a04..dc679dfe8ade 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -44,11 +44,41 @@ static inline const char *gobj_type(enum media_gobj_type type)
>  		return "pad";
>  	case MEDIA_GRAPH_LINK:
>  		return "link";
> +	case MEDIA_GRAPH_INTF_DEVNODE:
> +		return "intf-devnode";
>  	default:
>  		return "unknown";
>  	}
>  }
>  
> +static inline const char *intf_type(struct media_interface *intf)
> +{
> +	switch (intf->type) {
> +	case MEDIA_INTF_T_DVB_FE:
> +		return "frontend";
> +	case MEDIA_INTF_T_DVB_DEMUX:
> +		return "demux";
> +	case MEDIA_INTF_T_DVB_DVR:
> +		return "DVR";
> +	case MEDIA_INTF_T_DVB_CA:
> +		return  "CA";

Would lower case be better? "dvr" and "ca"? Although for some reason I feel that "CA"
is fine too. Not sure why :-)

What is the name of the associated device node? Upper or lower case? I feel that the
name here should match the name of the device node.

> +	case MEDIA_INTF_T_DVB_NET:
> +		return "dvbnet";
> +	case MEDIA_INTF_T_V4L_VIDEO:
> +		return "video";
> +	case MEDIA_INTF_T_V4L_VBI:
> +		return "vbi";
> +	case MEDIA_INTF_T_V4L_RADIO:
> +		return "radio";
> +	case MEDIA_INTF_T_V4L_SUBDEV:
> +		return "v4l2-subdev";
> +	case MEDIA_INTF_T_V4L_SWRADIO:
> +		return "swradio";
> +	default:
> +		return "unknown-intf";
> +	}
> +};

Regards,

	Hans


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 28/55] [media] uapi/media.h: Fix entity namespace
@ 2015-09-11 13:06       ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 13:06 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Hans Verkuil, Laurent Pinchart, Sakari Ailus, linux-api

On 09/06/2015 02:02 PM, Mauro Carvalho Chehab wrote:
> Now that interfaces got created, we need to fix the entity
> namespace.
> 
> So, let's create a consistent new namespace and add backward
> compatibility macros to keep the old namespace preserved.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
> index ada0738d26f2..dadcf1655070 100644
> --- a/drivers/media/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb-core/dvbdev.c
> @@ -230,17 +230,17 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
>  
>  	switch (type) {
>  	case DVB_DEVICE_FRONTEND:
> -		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_FE;
> +		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMOD;
>  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
>  		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
>  		break;
>  	case DVB_DEVICE_DEMUX:
> -		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_DEMUX;
> +		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMUX;
>  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
>  		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
>  		break;
>  	case DVB_DEVICE_CA:
> -		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_CA;
> +		dvbdev->entity->type = MEDIA_ENT_T_DVB_CA;
>  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
>  		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
>  		break;
> @@ -439,7 +439,7 @@ EXPORT_SYMBOL(dvb_unregister_device);
>  void dvb_create_media_graph(struct dvb_adapter *adap)
>  {
>  	struct media_device *mdev = adap->mdev;
> -	struct media_entity *entity, *tuner = NULL, *fe = NULL;
> +	struct media_entity *entity, *tuner = NULL, *demod = NULL;
>  	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
>  	struct media_interface *intf;
>  
> @@ -451,26 +451,26 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
>  		case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
>  			tuner = entity;
>  			break;
> -		case MEDIA_ENT_T_DEVNODE_DVB_FE:
> -			fe = entity;
> +		case MEDIA_ENT_T_DVB_DEMOD:
> +			demod = entity;
>  			break;
> -		case MEDIA_ENT_T_DEVNODE_DVB_DEMUX:
> +		case MEDIA_ENT_T_DVB_DEMUX:
>  			demux = entity;
>  			break;
> -		case MEDIA_ENT_T_DEVNODE_DVB_DVR:
> +		case MEDIA_ENT_T_DVB_TSOUT:
>  			dvr = entity;
>  			break;
> -		case MEDIA_ENT_T_DEVNODE_DVB_CA:
> +		case MEDIA_ENT_T_DVB_CA:
>  			ca = entity;
>  			break;
>  		}
>  	}
>  
> -	if (tuner && fe)
> -		media_create_pad_link(tuner, 0, fe, 0, 0);
> +	if (tuner && demod)
> +		media_create_pad_link(tuner, 0, demod, 0, 0);
>  
> -	if (fe && demux)
> -		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
> +	if (demod && demux)
> +		media_create_pad_link(demod, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
>  
>  	if (demux && dvr)
>  		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index aca828709bad..f8725b881a1d 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -42,31 +42,69 @@ struct media_device_info {
>  
>  #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
>  
> +/*
> + * Base numbers for entity types
> + *
> + * Please notice that the huge gap of 16 bits for each base is overkill!
> + * 8 bits is more than enough to avoid starving entity types for each
> + * subsystem.
> + *
> + * However, It is kept this way just to avoid binary breakages with the
> + * namespace provided on legacy versions of this header.
> + */
> +#define MEDIA_ENT_T_DVB_BASE		0x00000000
> +#define MEDIA_ENT_T_V4L2_BASE		0x00010000
> +#define MEDIA_ENT_T_V4L2_SUBDEV_BASE	0x00020000
> +
> +/*
> + * V4L2 entities - Those are used for DMA (mmap/DMABUF) and
> + *	read()/write() data I/O associated with the V4L2 devnodes.
> + */
> +#define MEDIA_ENT_T_V4L2_VIDEO		(MEDIA_ENT_T_V4L2_BASE + 1)
> +	/*
> +	 * Please notice that numbers between MEDIA_ENT_T_V4L2_BASE + 2 and
> +	 * MEDIA_ENT_T_V4L2_BASE + 4 can't be used, as those values used
> +	 * to be declared for FB, ALSA and DVB entities.
> +	 * As those values were never actually used in practice, we're just
> +	 * adding them as backward compatibility macros and keeping the
> +	 * numberspace clean here. This way, we avoid breaking compilation,
> +	 * in the case of having some userspace application using the old
> +	 * symbols.
> +	 */
> +#define MEDIA_ENT_T_V4L2_VBI		(MEDIA_ENT_T_V4L2_BASE + 5)
> +#define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 6)
> +
> +/* V4L2 Sub-device entities */
> +#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
> +#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
> +#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
> +	/* A converter of analogue video to its digital representation. */
> +#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 4)
> +	/* Tuner entity is actually both V4L2 and DVB subdev */
> +#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 5)
> +
> +/* DVB entities */
> +#define MEDIA_ENT_T_DVB_DEMOD		(MEDIA_ENT_T_DVB_BASE + 1)
> +#define MEDIA_ENT_T_DVB_DEMUX		(MEDIA_ENT_T_DVB_BASE + 2)
> +#define MEDIA_ENT_T_DVB_TSOUT		(MEDIA_ENT_T_DVB_BASE + 3)
> +#define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 4)
> +#define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 5)
> +
> +/* Legacy symbols used to avoid userspace compilation breakages */
>  #define MEDIA_ENT_TYPE_SHIFT		16
>  #define MEDIA_ENT_TYPE_MASK		0x00ff0000
>  #define MEDIA_ENT_SUBTYPE_MASK		0x0000ffff
>  
> -#define MEDIA_ENT_T_DEVNODE		(1 << MEDIA_ENT_TYPE_SHIFT)
> -#define MEDIA_ENT_T_DEVNODE_V4L		(MEDIA_ENT_T_DEVNODE + 1)
> +#define MEDIA_ENT_T_DEVNODE		MEDIA_ENT_T_V4L2_BASE
> +#define MEDIA_ENT_T_V4L2_SUBDEV		MEDIA_ENT_T_V4L2_SUBDEV_BASE
> +
> +#define MEDIA_ENT_T_DEVNODE_V4L		MEDIA_ENT_T_V4L2_VIDEO
> +
>  #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
>  #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
> -#define MEDIA_ENT_T_DEVNODE_DVB_FE	(MEDIA_ENT_T_DEVNODE + 4)
> -#define MEDIA_ENT_T_DEVNODE_DVB_DEMUX	(MEDIA_ENT_T_DEVNODE + 5)
> -#define MEDIA_ENT_T_DEVNODE_DVB_DVR	(MEDIA_ENT_T_DEVNODE + 6)
> -#define MEDIA_ENT_T_DEVNODE_DVB_CA	(MEDIA_ENT_T_DEVNODE + 7)
> -#define MEDIA_ENT_T_DEVNODE_DVB_NET	(MEDIA_ENT_T_DEVNODE + 8)
> +#define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
>  
> -/* Legacy symbol. Use it to avoid userspace compilation breakages */
> -#define MEDIA_ENT_T_DEVNODE_DVB		MEDIA_ENT_T_DEVNODE_DVB_FE
> -
> -#define MEDIA_ENT_T_V4L2_SUBDEV		(2 << MEDIA_ENT_TYPE_SHIFT)
> -#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV + 1)
> -#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV + 2)
> -#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV + 3)
> -/* A converter of analogue video to its digital representation. */
> -#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV + 4)
> -
> -#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV + 5)
> +/* Entity types */
>  
>  #define MEDIA_ENT_FL_DEFAULT		(1 << 0)
>  
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 28/55] [media] uapi/media.h: Fix entity namespace
@ 2015-09-11 13:06       ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 13:06 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Hans Verkuil, Laurent Pinchart, Sakari Ailus,
	linux-api-u79uwXL29TY76Z2rM5mHXA

On 09/06/2015 02:02 PM, Mauro Carvalho Chehab wrote:
> Now that interfaces got created, we need to fix the entity
> namespace.
> 
> So, let's create a consistent new namespace and add backward
> compatibility macros to keep the old namespace preserved.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>

Acked-by: Hans Verkuil <hans.verkuil-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>

> 
> diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
> index ada0738d26f2..dadcf1655070 100644
> --- a/drivers/media/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb-core/dvbdev.c
> @@ -230,17 +230,17 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
>  
>  	switch (type) {
>  	case DVB_DEVICE_FRONTEND:
> -		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_FE;
> +		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMOD;
>  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
>  		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
>  		break;
>  	case DVB_DEVICE_DEMUX:
> -		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_DEMUX;
> +		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMUX;
>  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
>  		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
>  		break;
>  	case DVB_DEVICE_CA:
> -		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_CA;
> +		dvbdev->entity->type = MEDIA_ENT_T_DVB_CA;
>  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
>  		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
>  		break;
> @@ -439,7 +439,7 @@ EXPORT_SYMBOL(dvb_unregister_device);
>  void dvb_create_media_graph(struct dvb_adapter *adap)
>  {
>  	struct media_device *mdev = adap->mdev;
> -	struct media_entity *entity, *tuner = NULL, *fe = NULL;
> +	struct media_entity *entity, *tuner = NULL, *demod = NULL;
>  	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
>  	struct media_interface *intf;
>  
> @@ -451,26 +451,26 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
>  		case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
>  			tuner = entity;
>  			break;
> -		case MEDIA_ENT_T_DEVNODE_DVB_FE:
> -			fe = entity;
> +		case MEDIA_ENT_T_DVB_DEMOD:
> +			demod = entity;
>  			break;
> -		case MEDIA_ENT_T_DEVNODE_DVB_DEMUX:
> +		case MEDIA_ENT_T_DVB_DEMUX:
>  			demux = entity;
>  			break;
> -		case MEDIA_ENT_T_DEVNODE_DVB_DVR:
> +		case MEDIA_ENT_T_DVB_TSOUT:
>  			dvr = entity;
>  			break;
> -		case MEDIA_ENT_T_DEVNODE_DVB_CA:
> +		case MEDIA_ENT_T_DVB_CA:
>  			ca = entity;
>  			break;
>  		}
>  	}
>  
> -	if (tuner && fe)
> -		media_create_pad_link(tuner, 0, fe, 0, 0);
> +	if (tuner && demod)
> +		media_create_pad_link(tuner, 0, demod, 0, 0);
>  
> -	if (fe && demux)
> -		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
> +	if (demod && demux)
> +		media_create_pad_link(demod, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
>  
>  	if (demux && dvr)
>  		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index aca828709bad..f8725b881a1d 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -42,31 +42,69 @@ struct media_device_info {
>  
>  #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
>  
> +/*
> + * Base numbers for entity types
> + *
> + * Please notice that the huge gap of 16 bits for each base is overkill!
> + * 8 bits is more than enough to avoid starving entity types for each
> + * subsystem.
> + *
> + * However, It is kept this way just to avoid binary breakages with the
> + * namespace provided on legacy versions of this header.
> + */
> +#define MEDIA_ENT_T_DVB_BASE		0x00000000
> +#define MEDIA_ENT_T_V4L2_BASE		0x00010000
> +#define MEDIA_ENT_T_V4L2_SUBDEV_BASE	0x00020000
> +
> +/*
> + * V4L2 entities - Those are used for DMA (mmap/DMABUF) and
> + *	read()/write() data I/O associated with the V4L2 devnodes.
> + */
> +#define MEDIA_ENT_T_V4L2_VIDEO		(MEDIA_ENT_T_V4L2_BASE + 1)
> +	/*
> +	 * Please notice that numbers between MEDIA_ENT_T_V4L2_BASE + 2 and
> +	 * MEDIA_ENT_T_V4L2_BASE + 4 can't be used, as those values used
> +	 * to be declared for FB, ALSA and DVB entities.
> +	 * As those values were never actually used in practice, we're just
> +	 * adding them as backward compatibility macros and keeping the
> +	 * numberspace clean here. This way, we avoid breaking compilation,
> +	 * in the case of having some userspace application using the old
> +	 * symbols.
> +	 */
> +#define MEDIA_ENT_T_V4L2_VBI		(MEDIA_ENT_T_V4L2_BASE + 5)
> +#define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 6)
> +
> +/* V4L2 Sub-device entities */
> +#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
> +#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
> +#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
> +	/* A converter of analogue video to its digital representation. */
> +#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 4)
> +	/* Tuner entity is actually both V4L2 and DVB subdev */
> +#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 5)
> +
> +/* DVB entities */
> +#define MEDIA_ENT_T_DVB_DEMOD		(MEDIA_ENT_T_DVB_BASE + 1)
> +#define MEDIA_ENT_T_DVB_DEMUX		(MEDIA_ENT_T_DVB_BASE + 2)
> +#define MEDIA_ENT_T_DVB_TSOUT		(MEDIA_ENT_T_DVB_BASE + 3)
> +#define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 4)
> +#define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 5)
> +
> +/* Legacy symbols used to avoid userspace compilation breakages */
>  #define MEDIA_ENT_TYPE_SHIFT		16
>  #define MEDIA_ENT_TYPE_MASK		0x00ff0000
>  #define MEDIA_ENT_SUBTYPE_MASK		0x0000ffff
>  
> -#define MEDIA_ENT_T_DEVNODE		(1 << MEDIA_ENT_TYPE_SHIFT)
> -#define MEDIA_ENT_T_DEVNODE_V4L		(MEDIA_ENT_T_DEVNODE + 1)
> +#define MEDIA_ENT_T_DEVNODE		MEDIA_ENT_T_V4L2_BASE
> +#define MEDIA_ENT_T_V4L2_SUBDEV		MEDIA_ENT_T_V4L2_SUBDEV_BASE
> +
> +#define MEDIA_ENT_T_DEVNODE_V4L		MEDIA_ENT_T_V4L2_VIDEO
> +
>  #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
>  #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
> -#define MEDIA_ENT_T_DEVNODE_DVB_FE	(MEDIA_ENT_T_DEVNODE + 4)
> -#define MEDIA_ENT_T_DEVNODE_DVB_DEMUX	(MEDIA_ENT_T_DEVNODE + 5)
> -#define MEDIA_ENT_T_DEVNODE_DVB_DVR	(MEDIA_ENT_T_DEVNODE + 6)
> -#define MEDIA_ENT_T_DEVNODE_DVB_CA	(MEDIA_ENT_T_DEVNODE + 7)
> -#define MEDIA_ENT_T_DEVNODE_DVB_NET	(MEDIA_ENT_T_DEVNODE + 8)
> +#define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
>  
> -/* Legacy symbol. Use it to avoid userspace compilation breakages */
> -#define MEDIA_ENT_T_DEVNODE_DVB		MEDIA_ENT_T_DEVNODE_DVB_FE
> -
> -#define MEDIA_ENT_T_V4L2_SUBDEV		(2 << MEDIA_ENT_TYPE_SHIFT)
> -#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV + 1)
> -#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV + 2)
> -#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV + 3)
> -/* A converter of analogue video to its digital representation. */
> -#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV + 4)
> -
> -#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV + 5)
> +/* Entity types */
>  
>  #define MEDIA_ENT_FL_DEFAULT		(1 << 0)
>  
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 39/55] [media] media controller: get rid of entity subtype on Kernel
@ 2015-09-11 13:08       ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 13:08 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: linux-api

On 09/06/2015 02:02 PM, Mauro Carvalho Chehab wrote:
> Don't use anymore the type/subtype entity data/macros
> inside the Kernel.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 220864319d21..7320cdc45833 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -185,16 +185,6 @@ struct media_intf_devnode {
>  	u32				minor;
>  };
>  
> -static inline u32 media_entity_type(struct media_entity *entity)
> -{
> -	return entity->type & MEDIA_ENT_TYPE_MASK;
> -}
> -
> -static inline u32 media_entity_subtype(struct media_entity *entity)
> -{
> -	return entity->type & MEDIA_ENT_SUBTYPE_MASK;
> -}
> -
>  static inline u32 media_entity_id(struct media_entity *entity)
>  {
>  	return entity->graph_obj.id;
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index 3d6210095336..f90147cb9b57 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -42,8 +42,6 @@ struct media_device_info {
>  
>  #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
>  
> -/* Used values for media_entity_desc::type */
> -
>  /*
>   * Initial value to be used when a new entity is created
>   * Drivers should change it to something useful
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 39/55] [media] media controller: get rid of entity subtype on Kernel
@ 2015-09-11 13:08       ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 13:08 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: linux-api-u79uwXL29TY76Z2rM5mHXA

On 09/06/2015 02:02 PM, Mauro Carvalho Chehab wrote:
> Don't use anymore the type/subtype entity data/macros
> inside the Kernel.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>

Acked-by: Hans Verkuil <hans.verkuil-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>

> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 220864319d21..7320cdc45833 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -185,16 +185,6 @@ struct media_intf_devnode {
>  	u32				minor;
>  };
>  
> -static inline u32 media_entity_type(struct media_entity *entity)
> -{
> -	return entity->type & MEDIA_ENT_TYPE_MASK;
> -}
> -
> -static inline u32 media_entity_subtype(struct media_entity *entity)
> -{
> -	return entity->type & MEDIA_ENT_SUBTYPE_MASK;
> -}
> -
>  static inline u32 media_entity_id(struct media_entity *entity)
>  {
>  	return entity->graph_obj.id;
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index 3d6210095336..f90147cb9b57 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -42,8 +42,6 @@ struct media_device_info {
>  
>  #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
>  
> -/* Used values for media_entity_desc::type */
> -
>  /*
>   * Initial value to be used when a new entity is created
>   * Drivers should change it to something useful
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 41/55] [media] DocBook: update descriptions for the media controller entities
  2015-09-06 12:03   ` Mauro Carvalho Chehab
@ 2015-09-11 13:13     ` Hans Verkuil
  2015-12-06  1:00       ` Laurent Pinchart
  0 siblings, 1 reply; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 13:13 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Jonathan Corbet, linux-doc

On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> Cleanup the media controller entities description:
> - remove MEDIA_ENT_T_DEVNODE and MEDIA_ENT_T_V4L2_SUBDEV entity
>   types, as they don't mean anything;
> - add MEDIA_ENT_T_UNKNOWN with a proper description;
> - remove ALSA and FB entity types. Those should not be used, as
>   the types are deprecated. We'll soon be adidng ALSA, but with
>   a different entity namespace;
> - improve the description of some entities.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> index 32a783635649..bc101516e372 100644
> --- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> +++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> @@ -179,70 +179,65 @@
>          <colspec colname="c2"/>
>  	<tbody valign="top">
>  	  <row>
> -	    <entry><constant>MEDIA_ENT_T_DEVNODE</constant></entry>
> -	    <entry>Unknown device node</entry>
> +	    <entry><constant>MEDIA_ENT_T_UNKNOWN</constant> and <constant>MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN</constant></entry>
> +	    <entry>Unknown entity. That generally indicates that
> +	    a driver didn't initialize properly the entity, with is a Kernel bug</entry>
>  	  </row>

I'm wondering: if userspace should never see an unknown entity, wouldn't it
be better to move these UNKNOWN defines out of the public header to a kernel
header and drop this from the documentation?

>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
> -	    <entry>V4L video, radio or vbi device node</entry>
> +	    <entry>V4L video streaming input or output entity</entry>
>  	  </row>
> -	  <row>
> -	    <entry><constant>MEDIA_ENT_T_DEVNODE_FB</constant></entry>
> -	    <entry>Frame buffer device node</entry>
> +	    <entry><constant>MEDIA_ENT_T_V4L2_VBI</constant></entry>
> +	    <entry>V4L VBI streaming input or output entity</entry>
>  	  </row>
> -	  <row>
> -	    <entry><constant>MEDIA_ENT_T_DEVNODE_ALSA</constant></entry>
> -	    <entry>ALSA card</entry>
> +	    <entry><constant>MEDIA_ENT_T_V4L2_SWRADIO</constant></entry>
> +	    <entry>V4L Sofware Digital Radio (SDR) streaming input or output entity</entry>

s/Sofware/Software/

>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD</constant></entry>
> -	    <entry>DVB frontend devnode</entry>
> +	    <entry>DVB demodulator entity</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_DVB_DEMUX</constant></entry>
> -	    <entry>DVB demux devnode</entry>
> +	    <entry>DVB demux entity. Could be implemented on hardware or in Kernelspace</entry>

s/on/in/

>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_DVB_TSOUT</constant></entry>
> -	    <entry>DVB DVR devnode</entry>
> +	    <entry>DVB Transport Stream output entity</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_DVB_CA</constant></entry>
> -	    <entry>DVB CAM devnode</entry>
> +	    <entry>DVB Conditional Access module (CAM) entity</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD_NET_DECAP</constant></entry>
> -	    <entry>DVB network devnode</entry>
> -	  </row>
> -	  <row>
> -	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV</constant></entry>
> -	    <entry>Unknown V4L sub-device</entry>
> +	    <entry>DVB network ULE/MLE desencapsulation entity. Could be implemented on hardware or in Kernelspace</entry>

s/on/in/

Hmm, is desencapsulation correct? Could it be 'de-encapsulation' instead? It looks weird.

>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_SENSOR</constant></entry>
> -	    <entry>Video sensor</entry>
> +	    <entry>Camera video sensor entity</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_FLASH</constant></entry>
> -	    <entry>Flash controller</entry>
> +	    <entry>Flash controller entity</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_LENS</constant></entry>
> -	    <entry>Lens controller</entry>
> +	    <entry>Lens controller entity</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_DECODER</constant></entry>
> -	    <entry>Video decoder, the basic function of the video decoder is to
> -	    accept analogue video from a wide variety of sources such as
> +	    <entry>Analog video decoder, the basic function of the video decoder
> +	    is to accept analogue video from a wide variety of sources such as
>  	    broadcast, DVD players, cameras and video cassette recorders, in
> -	    either NTSC, PAL or HD format and still occasionally SECAM, separate
> -	    it into its component parts, luminance and chrominance, and output
> +	    either NTSC, PAL, SECAM or HD format, separating the stream
> +	    into its component parts, luminance and chrominance, and output
>  	    it in some digital video standard, with appropriate embedded timing
>  	    signals.</entry>
>  	  </row>
>  	  <row>
>  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_TUNER</constant></entry>
> -	    <entry>TV and/or radio tuner</entry>
> +	    <entry>Digital TV, analog TV, radio and/or software radio tuner</entry>
>  	  </row>
>  	</tbody>
>        </tgroup>
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 42/55] [media] dvb: modify core to implement interfaces/entities at MC new gen
  2015-09-06 12:03   ` Mauro Carvalho Chehab
@ 2015-09-11 13:51     ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 13:51 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: Stefan Richter, Hans Verkuil, Markus Elfring, Jonathan Corbet,
	Akihiro Tsukada, Dan Carpenter, Arnd Bergmann, Tina Ruchandani,
	Antti Palosaari, Joe Perches, David S. Miller, Vaishali Thakkar,
	Eric W. Biederman, Laurent Pinchart, Sakari Ailus,
	Takeshi Yoshimura, linux1394-devel

On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> The Media Controller New Generation redefines the types for both
> interfaces and entities to be used on DVB. Make the needed
> changes at the DVB core for all interfaces, entities and
> data and interface links to appear in the graph.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c
> index d0e3f9d85f34..baaed28ee975 100644
> --- a/drivers/media/dvb-core/dmxdev.c
> +++ b/drivers/media/dvb-core/dmxdev.c
> @@ -1242,9 +1242,9 @@ int dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *dvb_adapter)
>  	}
>  
>  	dvb_register_device(dvb_adapter, &dmxdev->dvbdev, &dvbdev_demux, dmxdev,
> -			    DVB_DEVICE_DEMUX);
> +			    DVB_DEVICE_DEMUX, dmxdev->filternum);
>  	dvb_register_device(dvb_adapter, &dmxdev->dvr_dvbdev, &dvbdev_dvr,
> -			    dmxdev, DVB_DEVICE_DVR);
> +			    dmxdev, DVB_DEVICE_DVR, dmxdev->filternum);
>  
>  	dvb_ringbuffer_init(&dmxdev->dvr_buffer, NULL, 8192);
>  
> diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb-core/dvb_ca_en50221.c
> index fb66184dc9b6..f82cd1ff4f3a 100644
> --- a/drivers/media/dvb-core/dvb_ca_en50221.c
> +++ b/drivers/media/dvb-core/dvb_ca_en50221.c
> @@ -1695,7 +1695,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
>  	pubca->private = ca;
>  
>  	/* register the DVB device */
> -	ret = dvb_register_device(dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, DVB_DEVICE_CA);
> +	ret = dvb_register_device(dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, DVB_DEVICE_CA, 0);
>  	if (ret)
>  		goto free_slot_info;
>  
> diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
> index 2d06bcff0946..58601bfe0b8d 100644
> --- a/drivers/media/dvb-core/dvb_frontend.c
> +++ b/drivers/media/dvb-core/dvb_frontend.c
> @@ -2754,7 +2754,7 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
>  			fe->dvb->num, fe->id, fe->ops.info.name);
>  
>  	dvb_register_device (fe->dvb, &fepriv->dvbdev, &dvbdev_template,
> -			     fe, DVB_DEVICE_FRONTEND);
> +			     fe, DVB_DEVICE_FRONTEND, 0);
>  
>  	/*
>  	 * Initialize the cache to the proper values according with the
> diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c
> index b81e026edab3..14f51b68f4fe 100644
> --- a/drivers/media/dvb-core/dvb_net.c
> +++ b/drivers/media/dvb-core/dvb_net.c
> @@ -1503,6 +1503,6 @@ int dvb_net_init (struct dvb_adapter *adap, struct dvb_net *dvbnet,
>  		dvbnet->state[i] = 0;
>  
>  	return dvb_register_device(adap, &dvbnet->dvbdev, &dvbdev_net,
> -			     dvbnet, DVB_DEVICE_NET);
> +			     dvbnet, DVB_DEVICE_NET, 0);
>  }
>  EXPORT_SYMBOL(dvb_net_init);
> diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
> index dadcf1655070..6babc688801b 100644
> --- a/drivers/media/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb-core/dvbdev.c
> @@ -180,18 +180,86 @@ skip:
>  	return -ENFILE;
>  }
>  
> +static void dvb_create_tsout_entity(struct dvb_device *dvbdev,
> +				    const char *name, int npads)
> +{
> +#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
> +	int i, ret = 0;
> +
> +	dvbdev->tsout_pads = kcalloc(npads, sizeof(*dvbdev->tsout_pads),
> +				     GFP_KERNEL);
> +	if (!dvbdev->tsout_pads)
> +		return;
> +	dvbdev->tsout_entity = kcalloc(npads, sizeof(*dvbdev->tsout_entity),
> +				       GFP_KERNEL);
> +	if (!dvbdev->tsout_entity) {
> +		kfree(dvbdev->tsout_pads);
> +		dvbdev->tsout_pads = NULL;
> +		return;
> +	}
> +	for (i = 0; i < npads; i++) {
> +		struct media_pad *pads = &dvbdev->tsout_pads[i];
> +		struct media_entity *entity = &dvbdev->tsout_entity[i];
> +
> +		entity->name = kasprintf(GFP_KERNEL, "%s #%d", name, i);
> +		if (!entity->name) {
> +			ret = -ENOMEM;
> +			break;
> +		}
> +
> +		entity->type = MEDIA_ENT_T_DVB_TSOUT;
> +		pads->flags = MEDIA_PAD_FL_SINK;
> +
> +		ret = media_entity_init(entity, 1, pads);
> +		if (ret < 0)
> +			break;
> +
> +		ret = media_device_register_entity(dvbdev->adapter->mdev,
> +						   entity);
> +		if (ret < 0)
> +			break;
> +	}
> +
> +	if (!ret) {
> +		dvbdev->tsout_num_entities = npads;
> +		return;
> +	}
> +
> +	for (i--; i >= 0; i--) {
> +		media_device_unregister_entity(&dvbdev->tsout_entity[i]);
> +		kfree(dvbdev->tsout_entity[i].name);
> +	}
> +
> +	printk(KERN_ERR
> +		"%s: media_device_register_entity failed for %s\n",
> +		__func__, name);
> +
> +	kfree(dvbdev->tsout_entity);
> +	kfree(dvbdev->tsout_pads);
> +	dvbdev->tsout_entity = NULL;
> +	dvbdev->tsout_pads = NULL;
> +#endif
> +}
> +
> +#define DEMUX_TSOUT	"demux-tsout"
> +#define DVR_TSOUT	"dvr-tsout"
> +
>  static void dvb_create_media_entity(struct dvb_device *dvbdev,
> -				       int type, int minor)
> +				    int type, int demux_sink_pads)
>  {
>  #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
> -	int ret = 0, npads;
> +	int i, ret = 0, npads;
>  
>  	switch (type) {
>  	case DVB_DEVICE_FRONTEND:
>  		npads = 2;
>  		break;
> +	case DVB_DEVICE_DVR:
> +		dvb_create_tsout_entity(dvbdev, DVR_TSOUT, demux_sink_pads);
> +		return;
>  	case DVB_DEVICE_DEMUX:
> -		npads = 2;
> +		npads = 1 + demux_sink_pads;
> +		dvb_create_tsout_entity(dvbdev, DEMUX_TSOUT, demux_sink_pads);
>  		break;
>  	case DVB_DEVICE_CA:
>  		npads = 2;
> @@ -215,8 +283,6 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
>  	if (!dvbdev->entity)
>  		return;
>  
> -	dvbdev->entity->info.dev.major = DVB_MAJOR;
> -	dvbdev->entity->info.dev.minor = minor;
>  	dvbdev->entity->name = dvbdev->name;
>  
>  	if (npads) {
> @@ -237,7 +303,8 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
>  	case DVB_DEVICE_DEMUX:
>  		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMUX;
>  		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
> -		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
> +		for (i = 1; i < npads; i++)
> +			dvbdev->pads[i].flags = MEDIA_PAD_FL_SOURCE;
>  		break;
>  	case DVB_DEVICE_CA:
>  		dvbdev->entity->type = MEDIA_ENT_T_DVB_CA;
> @@ -259,8 +326,16 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
>  		printk(KERN_ERR
>  			"%s: media_device_register_entity failed for %s\n",
>  			__func__, dvbdev->entity->name);
> +
> +		media_device_unregister_entity(dvbdev->entity);
> +		for (i = 0; i < dvbdev->tsout_num_entities; i++) {
> +			media_device_unregister_entity(&dvbdev->tsout_entity[i]);
> +			kfree(dvbdev->tsout_entity[i].name);
> +		}
>  		kfree(dvbdev->pads);
>  		kfree(dvbdev->entity);
> +		kfree(dvbdev->tsout_pads);
> +		kfree(dvbdev->tsout_entity);
>  		dvbdev->entity = NULL;
>  		return;
>  	}
> @@ -271,7 +346,8 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
>  }
>  
>  static void dvb_register_media_device(struct dvb_device *dvbdev,
> -				      int type, int minor)
> +				      int type, int minor,
> +				      unsigned demux_sink_pads)
>  {
>  #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
>  	u32 intf_type;
> @@ -279,7 +355,7 @@ static void dvb_register_media_device(struct dvb_device *dvbdev,
>  	if (!dvbdev->adapter->mdev)
>  		return;
>  
> -	dvb_create_media_entity(dvbdev, type, minor);
> +	dvb_create_media_entity(dvbdev, type, demux_sink_pads);
>  
>  	switch (type) {
>  	case DVB_DEVICE_FRONTEND:
> @@ -323,7 +399,8 @@ static void dvb_register_media_device(struct dvb_device *dvbdev,
>  }
>  
>  int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
> -			const struct dvb_device *template, void *priv, int type)
> +			const struct dvb_device *template, void *priv, int type,
> +			int demux_sink_pads)
>  {
>  	struct dvb_device *dvbdev;
>  	struct file_operations *dvbdevfops;
> @@ -402,7 +479,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
>  	dprintk(KERN_DEBUG "DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n",
>  		adap->num, dnames[type], id, minor, minor);
>  
> -	dvb_register_media_device(dvbdev, type, minor);
> +	dvb_register_media_device(dvbdev, type, minor, demux_sink_pads);
>  
>  	return 0;
>  }
> @@ -422,9 +499,18 @@ void dvb_unregister_device(struct dvb_device *dvbdev)
>  
>  #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
>  	if (dvbdev->entity) {
> +		int i;
> +
>  		media_device_unregister_entity(dvbdev->entity);
> +		for (i = 0; i < dvbdev->tsout_num_entities; i++) {
> +			media_device_unregister_entity(&dvbdev->tsout_entity[i]);
> +			kfree(dvbdev->tsout_entity[i].name);
> +		}
> +
>  		kfree(dvbdev->entity);
>  		kfree(dvbdev->pads);
> +		kfree(dvbdev->tsout_entity);
> +		kfree(dvbdev->tsout_pads);
>  	}
>  #endif
>  
> @@ -440,8 +526,10 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
>  {
>  	struct media_device *mdev = adap->mdev;
>  	struct media_entity *entity, *tuner = NULL, *demod = NULL;
> -	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
> +	struct media_entity *demux = NULL, *ca = NULL;
>  	struct media_interface *intf;
> +	unsigned demux_pad = 0;
> +	unsigned dvr_pad = 0;
>  
>  	if (!mdev)
>  		return;
> @@ -457,9 +545,6 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
>  		case MEDIA_ENT_T_DVB_DEMUX:
>  			demux = entity;
>  			break;
> -		case MEDIA_ENT_T_DVB_TSOUT:
> -			dvr = entity;
> -			break;
>  		case MEDIA_ENT_T_DVB_CA:
>  			ca = entity;
>  			break;
> @@ -471,21 +556,46 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
>  
>  	if (demod && demux)
>  		media_create_pad_link(demod, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
> -
> -	if (demux && dvr)
> -		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
> -
>  	if (demux && ca)
>  		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
>  
> +	/* Create demux links for each ringbuffer/pad */
> +	if (demux) {
> +		media_device_for_each_entity(entity, mdev) {
> +			if (entity->type == MEDIA_ENT_T_DVB_TSOUT) {
> +				if (!strncmp(entity->name, DVR_TSOUT,
> +					strlen(DVR_TSOUT)))
> +					media_create_pad_link(demux,
> +							      ++dvr_pad,
> +							entity, 0, 0);
> +				if (!strncmp(entity->name, DEMUX_TSOUT,
> +					strlen(DEMUX_TSOUT)))
> +					media_create_pad_link(demux,
> +							      ++demux_pad,
> +							entity, 0, 0);
> +			}
> +		}
> +	}
> +
>  	/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca */
>  	list_for_each_entry(intf, &mdev->interfaces, list) {
>  		if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
>  			media_create_intf_link(ca, intf, 0);
>  		if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
>  			media_create_intf_link(tuner, intf, 0);
> +
>  		if (intf->type == MEDIA_INTF_T_DVB_DVR && demux)
>  			media_create_intf_link(demux, intf, 0);
> +
> +		media_device_for_each_entity(entity, mdev) {
> +			if (entity->type == MEDIA_ENT_T_DVB_TSOUT) {
> +				if (!strcmp(entity->name, DVR_TSOUT))
> +					media_create_intf_link(entity, intf, 0);
> +				if (!strcmp(entity->name, DEMUX_TSOUT))
> +					media_create_intf_link(entity, intf, 0);
> +				break;
> +			}
> +		}
>  	}
>  }
>  EXPORT_SYMBOL_GPL(dvb_create_media_graph);
> diff --git a/drivers/media/dvb-core/dvbdev.h b/drivers/media/dvb-core/dvbdev.h
> index 5f37b4dd1e69..0b140e8595de 100644
> --- a/drivers/media/dvb-core/dvbdev.h
> +++ b/drivers/media/dvb-core/dvbdev.h
> @@ -148,9 +148,11 @@ struct dvb_device {
>  	const char *name;
>  
>  	/* Allocated and filled inside dvbdev.c */
> -	struct media_entity *entity;
>  	struct media_intf_devnode *intf_devnode;
> -	struct media_pad *pads;
> +
> +	unsigned tsout_num_entities;
> +	struct media_entity *entity, *tsout_entity;
> +	struct media_pad *pads, *tsout_pads;
>  #endif
>  
>  	void *priv;
> @@ -197,7 +199,8 @@ int dvb_register_device(struct dvb_adapter *adap,
>  			struct dvb_device **pdvbdev,
>  			const struct dvb_device *template,
>  			void *priv,
> -			int type);
> +			int type,
> +			int demux_sink_pads);
>  
>  /**
>   * dvb_unregister_device - Unregisters a DVB device
> diff --git a/drivers/media/firewire/firedtv-ci.c b/drivers/media/firewire/firedtv-ci.c
> index e63f582378bf..edbb30fdd9d9 100644
> --- a/drivers/media/firewire/firedtv-ci.c
> +++ b/drivers/media/firewire/firedtv-ci.c
> @@ -241,7 +241,7 @@ int fdtv_ca_register(struct firedtv *fdtv)
>  		return -EFAULT;
>  
>  	err = dvb_register_device(&fdtv->adapter, &fdtv->cadev,
> -				  &fdtv_ca, fdtv, DVB_DEVICE_CA);
> +				  &fdtv_ca, fdtv, DVB_DEVICE_CA, 0);
>  
>  	if (stat.ca_application_info == 0)
>  		dev_err(fdtv->device, "CaApplicationInfo is not set\n");
> diff --git a/drivers/media/pci/bt8xx/dst_ca.c b/drivers/media/pci/bt8xx/dst_ca.c
> index c5cc14ef8347..0149a9ed6e58 100644
> --- a/drivers/media/pci/bt8xx/dst_ca.c
> +++ b/drivers/media/pci/bt8xx/dst_ca.c
> @@ -705,7 +705,8 @@ struct dvb_device *dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_
>  	struct dvb_device *dvbdev;
>  
>  	dprintk(verbose, DST_CA_ERROR, 1, "registering DST-CA device");
> -	if (dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA) == 0) {
> +	if (dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst,
> +			        DVB_DEVICE_CA, 0) == 0) {
>  		dst->dst_ca = dvbdev;
>  		return dst->dst_ca;
>  	}
> diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
> index 0ac2dd35fe50..4caca5df2931 100644
> --- a/drivers/media/pci/ddbridge/ddbridge-core.c
> +++ b/drivers/media/pci/ddbridge/ddbridge-core.c
> @@ -1065,7 +1065,7 @@ static int ddb_ci_attach(struct ddb_port *port)
>  			    port->en, 0, 1);
>  	ret = dvb_register_device(&port->output->adap, &port->output->dev,
>  				  &dvbdev_ci, (void *) port->output,
> -				  DVB_DEVICE_SEC);
> +				  DVB_DEVICE_SEC, 0);
>  	return ret;
>  }
>  
> diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c
> index 1b92d836a564..4e924e2d1638 100644
> --- a/drivers/media/pci/ngene/ngene-core.c
> +++ b/drivers/media/pci/ngene/ngene-core.c
> @@ -1513,7 +1513,7 @@ static int init_channel(struct ngene_channel *chan)
>  		set_transfer(&chan->dev->channel[2], 1);
>  		dvb_register_device(adapter, &chan->ci_dev,
>  				    &ngene_dvbdev_ci, (void *) chan,
> -				    DVB_DEVICE_SEC);
> +				    DVB_DEVICE_SEC, 0);
>  		if (!chan->ci_dev)
>  			goto err;
>  	}
> diff --git a/drivers/media/pci/ttpci/av7110.c b/drivers/media/pci/ttpci/av7110.c
> index 3f24fce74fc1..63f1d56bdfb2 100644
> --- a/drivers/media/pci/ttpci/av7110.c
> +++ b/drivers/media/pci/ttpci/av7110.c
> @@ -1361,7 +1361,7 @@ static int av7110_register(struct av7110 *av7110)
>  
>  #ifdef CONFIG_DVB_AV7110_OSD
>  	dvb_register_device(&av7110->dvb_adapter, &av7110->osd_dev,
> -			    &dvbdev_osd, av7110, DVB_DEVICE_OSD);
> +			    &dvbdev_osd, av7110, DVB_DEVICE_OSD, 0);
>  #endif
>  
>  	dvb_net_init(&av7110->dvb_adapter, &av7110->dvb_net, &dvbdemux->dmx);
> diff --git a/drivers/media/pci/ttpci/av7110_av.c b/drivers/media/pci/ttpci/av7110_av.c
> index 9544cfc06601..da11501fe5d2 100644
> --- a/drivers/media/pci/ttpci/av7110_av.c
> +++ b/drivers/media/pci/ttpci/av7110_av.c
> @@ -1589,10 +1589,10 @@ int av7110_av_register(struct av7110 *av7110)
>  	memset(&av7110->video_size, 0, sizeof (video_size_t));
>  
>  	dvb_register_device(&av7110->dvb_adapter, &av7110->video_dev,
> -			    &dvbdev_video, av7110, DVB_DEVICE_VIDEO);
> +			    &dvbdev_video, av7110, DVB_DEVICE_VIDEO, 0);
>  
>  	dvb_register_device(&av7110->dvb_adapter, &av7110->audio_dev,
> -			    &dvbdev_audio, av7110, DVB_DEVICE_AUDIO);
> +			    &dvbdev_audio, av7110, DVB_DEVICE_AUDIO, 0);
>  
>  	return 0;
>  }
> diff --git a/drivers/media/pci/ttpci/av7110_ca.c b/drivers/media/pci/ttpci/av7110_ca.c
> index a6079b90252a..235f0202dc7e 100644
> --- a/drivers/media/pci/ttpci/av7110_ca.c
> +++ b/drivers/media/pci/ttpci/av7110_ca.c
> @@ -378,7 +378,7 @@ static struct dvb_device dvbdev_ca = {
>  int av7110_ca_register(struct av7110 *av7110)
>  {
>  	return dvb_register_device(&av7110->dvb_adapter, &av7110->ca_dev,
> -				   &dvbdev_ca, av7110, DVB_DEVICE_CA);
> +				   &dvbdev_ca, av7110, DVB_DEVICE_CA, 0);
>  }
>  
>  void av7110_ca_unregister(struct av7110 *av7110)
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 43/55] [media] media: report if a pad is sink or source at debug msg
  2015-09-06 12:03   ` Mauro Carvalho Chehab
@ 2015-09-11 13:52     ` Hans Verkuil
  2015-12-06  0:53     ` Laurent Pinchart
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 13:52 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List

On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> Sometimes, it is important to see if the created pad is
> sink or source. Add info to track that.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index d8038a53f945..6ed5eef88593 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -121,8 +121,11 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
>  		struct media_pad *pad = gobj_to_pad(gobj);
>  
>  		dev_dbg(gobj->mdev->dev,
> -			"%s: id 0x%08x pad#%d: '%s':%d\n",
> -			event_name, gobj->id, media_localid(gobj),
> +			"%s: id 0x%08x %s%spad#%d: '%s':%d\n",
> +			event_name, gobj->id,
> +			pad->flags & MEDIA_PAD_FL_SINK   ? "  sink " : "",
> +			pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
> +			media_localid(gobj),
>  			pad->entity->name, pad->index);
>  		break;
>  	}
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
@ 2015-09-11 13:58       ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 13:58 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: linux-api

On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> Add a new ioctl that will report the entire topology on
> one go.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

I do have one suggestion: media_v2_interface, media_v2_pad and media_v2_link all
have a 'flags' field, but it is not clear from the code in the header which flag
#defines are used for which struct. Perhaps a few comments would help with that.

> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index a1bd7afba110..b17f6763aff4 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h

<snip>

> +
> +struct media_v2_pad {
> +	__u32 id;
> +	__u32 entity_id;
> +	__u32 flags;
> +	__u16 reserved[9];

Strange odd number here for no clear reason. Perhaps use 8 or 10 instead?

Anyway, you have my Ack.

Regards,

	Hans

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
@ 2015-09-11 13:58       ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 13:58 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List
  Cc: linux-api-u79uwXL29TY76Z2rM5mHXA

On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> Add a new ioctl that will report the entire topology on
> one go.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>

Acked-by: Hans Verkuil <hans.verkuil-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>

I do have one suggestion: media_v2_interface, media_v2_pad and media_v2_link all
have a 'flags' field, but it is not clear from the code in the header which flag
#defines are used for which struct. Perhaps a few comments would help with that.

> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index a1bd7afba110..b17f6763aff4 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h

<snip>

> +
> +struct media_v2_pad {
> +	__u32 id;
> +	__u32 entity_id;
> +	__u32 flags;
> +	__u16 reserved[9];

Strange odd number here for no clear reason. Perhaps use 8 or 10 instead?

Anyway, you have my Ack.

Regards,

	Hans

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 46/55] [media] media: move mdev list init to gobj
  2015-09-06 12:03   ` Mauro Carvalho Chehab
@ 2015-09-11 13:59     ` Hans Verkuil
  2015-11-23 22:32     ` Laurent Pinchart
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 13:59 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List

On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> Let's control the topology changes inside the graph_object. So, move the
> addition and removal of interfaces/entities from the mdev lists to
> media_gobj_init() and media_gobj_remove().
> 
> The main reason is that mdev should have lists for all object types, as
> the new MC api will require to store objects in separate places.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 134fe7510195..ec98595b8a7a 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -415,7 +415,7 @@ void media_device_unregister(struct media_device *mdev)
>  	struct media_entity *entity;
>  	struct media_entity *next;
>  
> -	list_for_each_entry_safe(entity, next, &mdev->entities, list)
> +	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
>  		media_device_unregister_entity(entity);
>  
>  	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
> @@ -449,7 +449,6 @@ int __must_check media_device_register_entity(struct media_device *mdev,
>  	spin_lock(&mdev->lock);
>  	/* Initialize media_gobj embedded at the entity */
>  	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
> -	list_add_tail(&entity->list, &mdev->entities);
>  
>  	/* Initialize objects at the pads */
>  	for (i = 0; i < entity->num_pads; i++)
> @@ -487,7 +486,6 @@ void media_device_unregister_entity(struct media_entity *entity)
>  	for (i = 0; i < entity->num_pads; i++)
>  		media_gobj_remove(&entity->pads[i].graph_obj);
>  	media_gobj_remove(&entity->graph_obj);
> -	list_del(&entity->list);
>  	spin_unlock(&mdev->lock);
>  	entity->graph_obj.mdev = NULL;
>  }
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 6ed5eef88593..cbb0604e81c1 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -170,6 +170,7 @@ void media_gobj_init(struct media_device *mdev,
>  	switch (type) {
>  	case MEDIA_GRAPH_ENTITY:
>  		gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
> +		list_add_tail(&gobj->list, &mdev->entities);
>  		break;
>  	case MEDIA_GRAPH_PAD:
>  		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
> @@ -178,6 +179,7 @@ void media_gobj_init(struct media_device *mdev,
>  		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
>  		break;
>  	case MEDIA_GRAPH_INTF_DEVNODE:
> +		list_add_tail(&gobj->list, &mdev->interfaces);
>  		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
>  		break;
>  	}
> @@ -193,6 +195,16 @@ void media_gobj_init(struct media_device *mdev,
>   */
>  void media_gobj_remove(struct media_gobj *gobj)
>  {
> +	/* Remove the object from mdev list */
> +	switch (media_type(gobj)) {
> +	case MEDIA_GRAPH_ENTITY:
> +	case MEDIA_GRAPH_INTF_DEVNODE:
> +		list_del(&gobj->list);
> +		break;
> +	default:
> +		break;
> +	}
> +
>  	dev_dbg_obj(__func__, gobj);
>  }
>  
> @@ -864,8 +876,6 @@ static void media_interface_init(struct media_device *mdev,
>  	INIT_LIST_HEAD(&intf->links);
>  
>  	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
> -
> -	list_add_tail(&intf->list, &mdev->interfaces);
>  }
>  
>  /* Functions related to the media interface via device nodes */
> @@ -894,7 +904,6 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
>  void media_devnode_remove(struct media_intf_devnode *devnode)
>  {
>  	media_gobj_remove(&devnode->intf.graph_obj);
> -	list_del(&devnode->intf.list);
>  	kfree(devnode);
>  }
>  EXPORT_SYMBOL_GPL(media_devnode_remove);
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index f23d686aaac6..85fa302047bd 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -111,11 +111,11 @@ struct media_device *media_device_find_devres(struct device *dev);
>  
>  /* Iterate over all entities. */
>  #define media_device_for_each_entity(entity, mdev)			\
> -	list_for_each_entry(entity, &(mdev)->entities, list)
> +	list_for_each_entry(entity, &(mdev)->entities, graph_obj.list)
>  
>  /* Iterate over all interfaces. */
>  #define media_device_for_each_intf(intf, mdev)			\
> -	list_for_each_entry(intf, &(mdev)->interfaces, list)
> +	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
>  
>  
>  #else
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 2d5ad40254b7..bc7eb6240795 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -66,6 +66,7 @@ enum media_gobj_type {
>  struct media_gobj {
>  	struct media_device	*mdev;
>  	u32			id;
> +	struct list_head	list;
>  };
>  
>  
> @@ -114,7 +115,6 @@ struct media_entity_operations {
>  
>  struct media_entity {
>  	struct media_gobj graph_obj;	/* must be first field in struct */
> -	struct list_head list;
>  	const char *name;		/* Entity name */
>  	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
>  	u32 revision;			/* Entity revision, driver specific */
> @@ -166,7 +166,6 @@ struct media_entity {
>   */
>  struct media_interface {
>  	struct media_gobj		graph_obj;
> -	struct list_head		list;
>  	struct list_head		links;
>  	u32				type;
>  	u32				flags;
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 48/55] [media] media_device: add a topology version field
  2015-09-06 12:03   ` Mauro Carvalho Chehab
@ 2015-09-11 13:59     ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 13:59 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List

On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> Every time a graph object is added or removed, the version
> of the topology changes. That's a requirement for the new
> MEDIA_IOC_G_TOPOLOGY, in order to allow userspace to know
> that the topology has changed after a previous call to it.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 568553d41f5d..064515f2ba9b 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -185,6 +185,9 @@ void media_gobj_init(struct media_device *mdev,
>  		list_add_tail(&gobj->list, &mdev->interfaces);
>  		break;
>  	}
> +
> +	mdev->topology_version++;
> +
>  	dev_dbg_obj(__func__, gobj);
>  }
>  
> @@ -199,6 +202,8 @@ void media_gobj_remove(struct media_gobj *gobj)
>  {
>  	dev_dbg_obj(__func__, gobj);
>  
> +	gobj->mdev->topology_version++;
> +
>  	/* Remove the object from mdev list */
>  	list_del(&gobj->list);
>  }
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index 0d1b9c687454..1b12774a9ab4 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -41,6 +41,8 @@ struct device;
>   * @bus_info:	Unique and stable device location identifier
>   * @hw_revision: Hardware device revision
>   * @driver_version: Device driver version
> + * @topology_version: Monotonic counter for storing the version of the graph
> + *		topology. Should be incremented each time the topology changes.
>   * @entity_id:	Unique ID used on the last entity registered
>   * @pad_id:	Unique ID used on the last pad registered
>   * @link_id:	Unique ID used on the last link registered
> @@ -74,6 +76,8 @@ struct media_device {
>  	u32 hw_revision;
>  	u32 driver_version;
>  
> +	u32 topology_version;
> +
>  	u32 entity_id;
>  	u32 pad_id;
>  	u32 link_id;
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-07 22:18     ` Sakari Ailus
@ 2015-09-11 14:08     ` Hans Verkuil
  2015-12-08 20:20       ` Mauro Carvalho Chehab
  2015-11-23 22:04     ` Laurent Pinchart
  2 siblings, 1 reply; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 14:08 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List

On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
> with the RFC for the MC next generation.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Two comments:

> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 5b2c9f7fcd45..96a476eeb16e 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
>  	return ret;
>  }
>  
> +static long __media_device_get_topology(struct media_device *mdev,
> +				      struct media_v2_topology *topo)
> +{
> +	struct media_entity *entity;
> +	struct media_interface *intf;
> +	struct media_pad *pad;
> +	struct media_link *link;
> +	struct media_v2_entity uentity;
> +	struct media_v2_interface uintf;
> +	struct media_v2_pad upad;
> +	struct media_v2_link ulink;
> +	int ret = 0, i;
> +
> +	topo->topology_version = mdev->topology_version;
> +
> +	/* Get entities and number of entities */
> +	i = 0;
> +	media_device_for_each_entity(entity, mdev) {
> +		i++;
> +
> +		if (ret || !topo->entities)
> +			continue;
> +
> +		if (i > topo->num_entities) {
> +			ret = -ENOSPC;
> +			continue;
> +		}
> +
> +		/* Copy fields to userspace struct if not error */
> +		memset(&uentity, 0, sizeof(uentity));
> +		uentity.id = entity->graph_obj.id;
> +		strncpy(uentity.name, entity->name,
> +			sizeof(uentity.name));
> +
> +		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_entities = i;
> +
> +	/* Get interfaces and number of interfaces */
> +	i = 0;
> +	media_device_for_each_intf(intf, mdev) {
> +		i++;
> +
> +		if (ret || !topo->interfaces)
> +			continue;
> +
> +		if (i > topo->num_interfaces) {
> +			ret = -ENOSPC;
> +			continue;
> +		}
> +
> +		memset(&uintf, 0, sizeof(uintf));
> +
> +		/* Copy intf fields to userspace struct */
> +		uintf.id = intf->graph_obj.id;
> +		uintf.intf_type = intf->type;
> +		uintf.flags = intf->flags;
> +
> +		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
> +			struct media_intf_devnode *devnode;
> +
> +			devnode = intf_to_devnode(intf);
> +
> +			uintf.devnode.major = devnode->major;
> +			uintf.devnode.minor = devnode->minor;
> +		}
> +
> +		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_interfaces = i;
> +
> +	/* Get pads and number of pads */
> +	i = 0;
> +	media_device_for_each_pad(pad, mdev) {
> +		i++;
> +
> +		if (ret || !topo->pads)
> +			continue;
> +
> +		if (i > topo->num_pads) {
> +			ret = -ENOSPC;
> +			continue;
> +		}
> +
> +		memset(&upad, 0, sizeof(upad));
> +
> +		/* Copy pad fields to userspace struct */
> +		upad.id = pad->graph_obj.id;
> +		upad.entity_id = pad->entity->graph_obj.id;
> +		upad.flags = pad->flags;
> +
> +		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_pads = i;
> +
> +	/* Get links and number of links */
> +	i = 0;
> +	media_device_for_each_link(link, mdev) {
> +		i++;
> +
> +		if (ret || !topo->links)
> +			continue;
> +
> +		if (i > topo->num_links) {
> +			ret = -ENOSPC;
> +			continue;
> +		}
> +
> +		memset(&ulink, 0, sizeof(ulink));
> +
> +		/* Copy link fields to userspace struct */
> +		ulink.id = link->graph_obj.id;
> +		ulink.source_id = link->gobj0->id;
> +		ulink.sink_id = link->gobj1->id;
> +		ulink.flags = link->flags;
> +
> +		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
> +			ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;

Why isn't this flag part of link->flags? I would expect that when an interface
link is created the media core code will set this flag automatically.

It's a bit strange that this flag is set here. Or am I missing something?

> +
> +		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_links = i;
> +
> +	return ret;
> +}
> +
> +static long media_device_get_topology(struct media_device *mdev,
> +				      struct media_v2_topology __user *utopo)
> +{
> +	struct media_v2_topology ktopo;
> +	int ret;
> +
> +	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
> +
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = __media_device_get_topology(mdev, &ktopo);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));
> +
> +	return ret;
> +}
> +
>  static long media_device_ioctl(struct file *filp, unsigned int cmd,
>  			       unsigned long arg)
>  {
> @@ -264,6 +414,13 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
>  		mutex_unlock(&dev->graph_mutex);
>  		break;
>  
> +	case MEDIA_IOC_G_TOPOLOGY:
> +		mutex_lock(&dev->graph_mutex);
> +		ret = media_device_get_topology(dev,
> +				(struct media_v2_topology __user *)arg);
> +		mutex_unlock(&dev->graph_mutex);
> +		break;
> +
>  	default:
>  		ret = -ENOIOCTLCMD;
>  	}
> @@ -312,6 +469,7 @@ static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
>  	case MEDIA_IOC_DEVICE_INFO:
>  	case MEDIA_IOC_ENUM_ENTITIES:
>  	case MEDIA_IOC_SETUP_LINK:
> +	case MEDIA_IOC_G_TOPOLOGY:
>  		return media_device_ioctl(filp, cmd, arg);

This doesn't work: G_TOPOLOGY needs pointer conversion.

Regards,

	Hans

>  
>  	case MEDIA_IOC_ENUM_LINKS32:
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 51/55] [media] remove interface links at media_entity_unregister()
  2015-09-06 12:03   ` Mauro Carvalho Chehab
@ 2015-09-11 14:18     ` Hans Verkuil
  0 siblings, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 14:18 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List

On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> Interface links connected to an entity should be removed
> before being able of removing the entity.

I'd replace that with:

...before the entity itself can be removed.

> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 96a476eeb16e..7c37aeab05bb 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -638,14 +638,30 @@ void media_device_unregister_entity(struct media_entity *entity)
>  		return;
>  
>  	spin_lock(&mdev->lock);
> +
> +	/* Remove interface links with this entity on it */
> +	list_for_each_entry_safe(link, tmp, &mdev->links, graph_obj.list) {
> +		if (media_type(link->gobj1) == MEDIA_GRAPH_ENTITY

I honestly think that the media_type() check can be removed. I think I
mentioned it before. Not important enough to withhold the Ack, though.

> +		    && link->entity == entity) {
> +			media_gobj_remove(&link->graph_obj);
> +			kfree(link);
> +		}
> +	}
> +
> +	/* Remove all data links that belong to this entity */
>  	list_for_each_entry_safe(link, tmp, &entity->links, list) {
>  		media_gobj_remove(&link->graph_obj);
>  		list_del(&link->list);
>  		kfree(link);
>  	}
> +
> +	/* Remove all pads that belong to this entity */
>  	for (i = 0; i < entity->num_pads; i++)
>  		media_gobj_remove(&entity->pads[i].graph_obj);
> +
> +	/* Remove the entity */
>  	media_gobj_remove(&entity->graph_obj);
> +
>  	spin_unlock(&mdev->lock);
>  	entity->graph_obj.mdev = NULL;
>  }
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 52/55] [media] media-device: remove interfaces and interface links
  2015-09-06 12:03   ` Mauro Carvalho Chehab
@ 2015-09-11 14:20     ` Hans Verkuil
  2015-11-23 21:22     ` Laurent Pinchart
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 14:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List

On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> Just like what's done with entities, when the media controller is
> unregistered, release any interface and interface links that
> might still be there.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 7c37aeab05bb..0238885fcc74 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -574,6 +574,22 @@ void media_device_unregister(struct media_device *mdev)
>  {
>  	struct media_entity *entity;
>  	struct media_entity *next;
> +	struct media_link *link, *tmp_link;
> +	struct media_interface *intf, *tmp_intf;
> +
> +	/* Remove interface links from the media device */
> +	list_for_each_entry_safe(link, tmp_link, &mdev->links,
> +				 graph_obj.list) {
> +		media_gobj_remove(&link->graph_obj);
> +		kfree(link);
> +	}
> +
> +	/* Remove all interfaces from the media device */
> +	list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces,
> +				 graph_obj.list) {
> +		media_gobj_remove(&intf->graph_obj);
> +		kfree(intf);
> +	}
>  
>  	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
>  		media_device_unregister_entity(entity);
> @@ -651,7 +667,6 @@ void media_device_unregister_entity(struct media_entity *entity)
>  	/* Remove all data links that belong to this entity */
>  	list_for_each_entry_safe(link, tmp, &entity->links, list) {
>  		media_gobj_remove(&link->graph_obj);
> -		list_del(&link->list);
>  		kfree(link);
>  	}
>  
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index a37ccd2edfd5..cd4d767644df 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -206,6 +206,10 @@ void media_gobj_remove(struct media_gobj *gobj)
>  
>  	/* Remove the object from mdev list */
>  	list_del(&gobj->list);
> +
> +	/* Links have their own list - we need to drop them there too */
> +	if (media_type(gobj) == MEDIA_GRAPH_LINK)
> +		list_del(&gobj_to_link(gobj)->list);
>  }
>  
>  /**
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index ca4a4f23362f..fb5f0e21f137 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -153,7 +153,7 @@ struct media_entity {
>  };
>  
>  /**
> - * struct media_intf_devnode - Define a Kernel API interface
> + * struct media_interface - Define a Kernel API interface
>   *
>   * @graph_obj:		embedded graph object
>   * @list:		Linked list used to find other interfaces that belong
> @@ -163,6 +163,11 @@ struct media_entity {
>   *			uapi/media/media.h header, e. g.
>   *			MEDIA_INTF_T_*
>   * @flags:		Interface flags as defined at uapi/media/media.h
> + *
> + * NOTE: As media_device_unregister() will free the address of the
> + *	 media_interface, this structure should be embedded as the first
> + *	 element of the derived functions, in order for the address to be
> + *	 the same.
>   */
>  struct media_interface {
>  	struct media_gobj		graph_obj;
> @@ -179,11 +184,11 @@ struct media_interface {
>   * @minor:	Minor number of a device node
>   */
>  struct media_intf_devnode {
> -	struct media_interface		intf;
> +	struct media_interface	intf; /* must be first field in struct */
>  
>  	/* Should match the fields at media_v2_intf_devnode */
> -	u32				major;
> -	u32				minor;
> +	u32			major;
> +	u32			minor;
>  };
>  
>  static inline u32 media_entity_id(struct media_entity *entity)
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes
  2015-09-06 12:03   ` Mauro Carvalho Chehab
@ 2015-09-11 14:38     ` Hans Verkuil
  2015-11-23 21:10     ` Laurent Pinchart
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 14:38 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Sakari Ailus

On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> V4L2 device (and subdevice) nodes should create an interface, if the
> Media Controller support is enabled.
> 
> Please notice that radio devices should not create an entity, as radio
> input/output is either via wires or via ALSA.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
> index 44b330589787..07123dd569c4 100644
> --- a/drivers/media/v4l2-core/v4l2-dev.c
> +++ b/drivers/media/v4l2-core/v4l2-dev.c
> @@ -194,9 +194,12 @@ static void v4l2_device_release(struct device *cd)
>  	mutex_unlock(&videodev_lock);
>  
>  #if defined(CONFIG_MEDIA_CONTROLLER)
> -	if (v4l2_dev->mdev &&
> -	    vdev->vfl_type != VFL_TYPE_SUBDEV)
> -		media_device_unregister_entity(&vdev->entity);
> +	if (v4l2_dev->mdev) {
> +		/* Remove interfaces and interface links */
> +		media_devnode_remove(vdev->intf_devnode);
> +		if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN)
> +			media_device_unregister_entity(&vdev->entity);
> +	}
>  #endif
>  
>  	/* Do not call v4l2_device_put if there is no release callback set.
> @@ -713,6 +716,92 @@ static void determine_valid_ioctls(struct video_device *vdev)
>  			BASE_VIDIOC_PRIVATE);
>  }
>  
> +
> +static int video_register_media_controller(struct video_device *vdev, int type)
> +{
> +#if defined(CONFIG_MEDIA_CONTROLLER)
> +	u32 intf_type;
> +	int ret;
> +
> +	if (!vdev->v4l2_dev->mdev)
> +		return 0;
> +
> +	vdev->entity.type = MEDIA_ENT_T_UNKNOWN;
> +
> +	switch (type) {
> +	case VFL_TYPE_GRABBER:
> +		intf_type = MEDIA_INTF_T_V4L_VIDEO;
> +		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
> +		break;
> +	case VFL_TYPE_VBI:
> +		intf_type = MEDIA_INTF_T_V4L_VBI;
> +		vdev->entity.type = MEDIA_ENT_T_V4L2_VBI;
> +		break;
> +	case VFL_TYPE_SDR:
> +		intf_type = MEDIA_INTF_T_V4L_SWRADIO;
> +		vdev->entity.type = MEDIA_ENT_T_V4L2_SWRADIO;
> +		break;
> +	case VFL_TYPE_RADIO:
> +		intf_type = MEDIA_INTF_T_V4L_RADIO;
> +		/*
> +		 * Radio doesn't have an entity at the V4L2 side to represent
> +		 * radio input or output. Instead, the audio input/output goes
> +		 * via either physical wires or ALSA.
> +		 */
> +		break;
> +	case VFL_TYPE_SUBDEV:
> +		intf_type = MEDIA_INTF_T_V4L_SUBDEV;
> +		/* Entity will be created via v4l2_device_register_subdev() */
> +		break;
> +	default:
> +		return 0;
> +	}
> +
> +	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
> +		vdev->entity.name = vdev->name;
> +
> +		/* Needed just for backward compatibility with legacy MC API */
> +		vdev->entity.info.dev.major = VIDEO_MAJOR;
> +		vdev->entity.info.dev.minor = vdev->minor;
> +
> +		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
> +						   &vdev->entity);
> +		if (ret < 0) {
> +			printk(KERN_WARNING
> +				"%s: media_device_register_entity failed\n",
> +				__func__);
> +			return ret;
> +		}
> +	}
> +
> +	vdev->intf_devnode = media_devnode_create(vdev->v4l2_dev->mdev,
> +						  intf_type,
> +						  0, VIDEO_MAJOR,
> +						  vdev->minor,
> +						  GFP_KERNEL);
> +	if (!vdev->intf_devnode) {
> +		media_device_unregister_entity(&vdev->entity);
> +		return -ENOMEM;
> +	}
> +
> +	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
> +		struct media_link *link;
> +
> +		link = media_create_intf_link(&vdev->entity,
> +					      &vdev->intf_devnode->intf, 0);
> +		if (!link) {
> +			media_devnode_remove(vdev->intf_devnode);
> +			media_device_unregister_entity(&vdev->entity);
> +			return -ENOMEM;
> +		}
> +	}
> +
> +	/* FIXME: how to create the other interface links? */
> +
> +#endif
> +	return 0;
> +}
> +
>  /**
>   *	__video_register_device - register video4linux devices
>   *	@vdev: video device structure we want to register
> @@ -908,22 +997,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
>  	/* Increase v4l2_device refcount */
>  	v4l2_device_get(vdev->v4l2_dev);
>  
> -#if defined(CONFIG_MEDIA_CONTROLLER)
>  	/* Part 5: Register the entity. */
> -	if (vdev->v4l2_dev->mdev &&
> -	    vdev->vfl_type != VFL_TYPE_SUBDEV) {
> -		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
> -		vdev->entity.name = vdev->name;
> -		vdev->entity.info.dev.major = VIDEO_MAJOR;
> -		vdev->entity.info.dev.minor = vdev->minor;
> -		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
> -			&vdev->entity);
> -		if (ret < 0)
> -			printk(KERN_WARNING
> -			       "%s: media_device_register_entity failed\n",
> -			       __func__);
> -	}
> -#endif
> +	ret = video_register_media_controller(vdev, type);
> +

This is weird. The 'ret' value is ignored. This was also the case in the original
code, but I don't see why it is ignored. I think that if this fails, then an error
should be returned. Otherwise you'll have an incomplete media graph.

Regards,

	Hans

>  	/* Part 6: Activate this minor. The char device can now be used. */
>  	set_bit(V4L2_FL_REGISTERED, &vdev->flags);
>  
> diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
> index 5b0a30b9252b..e788a085ba96 100644
> --- a/drivers/media/v4l2-core/v4l2-device.c
> +++ b/drivers/media/v4l2-core/v4l2-device.c
> @@ -249,6 +249,17 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
>  #if defined(CONFIG_MEDIA_CONTROLLER)
>  		sd->entity.info.dev.major = VIDEO_MAJOR;
>  		sd->entity.info.dev.minor = vdev->minor;
> +
> +		/* Interface is created by __video_register_device() */
> +		if (vdev->v4l2_dev->mdev) {
> +			struct media_link *link;
> +
> +			link = media_create_intf_link(&sd->entity,
> +						      &vdev->intf_devnode->intf,
> +						      0);
> +			if (!link)
> +				goto clean_up;
> +		}
>  #endif
>  		sd->devnode = vdev;
>  	}
> @@ -285,7 +296,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
>  
>  #if defined(CONFIG_MEDIA_CONTROLLER)
>  	if (v4l2_dev->mdev) {
> -		media_entity_remove_links(&sd->entity);
> +		/*
> +		 * No need to explicitly remove links, as both pads and
> +		 * links are removed by the function below, in the right order
> +		 */
>  		media_device_unregister_entity(&sd->entity);
>  	}
>  #endif
> diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
> index acbcd2f5fe7f..eeabf20e87a6 100644
> --- a/include/media/v4l2-dev.h
> +++ b/include/media/v4l2-dev.h
> @@ -86,6 +86,7 @@ struct video_device
>  {
>  #if defined(CONFIG_MEDIA_CONTROLLER)
>  	struct media_entity entity;
> +	struct media_intf_devnode *intf_devnode;
>  #endif
>  	/* device ops */
>  	const struct v4l2_file_operations *fops;
> 


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 55/55] [media] media-entity.h: document all the structs
  2015-09-06 12:03   ` Mauro Carvalho Chehab
@ 2015-09-11 14:45     ` Hans Verkuil
  2015-11-23 20:19     ` Laurent Pinchart
  1 sibling, 0 replies; 309+ messages in thread
From: Hans Verkuil @ 2015-09-11 14:45 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List

On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> Only a few structs are documented on kernel-doc-nano format
> (the ones added by the MC next gen patches).
> 
> Add a documentation for all structs, and ensure that they'll
> be producing the documentation at the Kernel's device driver
> DocBook.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

After correcting some typos (see below):

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index fb5f0e21f137..e1a89899deef 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -55,11 +55,13 @@ enum media_gobj_type {
>  /**
>   * struct media_gobj - Define a graph object.
>   *
> + * @mdev:	Pointer to the struct media_device that owns the object
>   * @id:		Non-zero object ID identifier. The ID should be unique
>   *		inside a media_device, as it is composed by
>   *		MEDIA_BITS_PER_TYPE to store the type plus
>   *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
>   *		(called as "local ID").
> + * @list:	Linked list associated to one of the per-type mdev object lists
>   *
>   * All objects on the media graph should have this struct embedded
>   */
> @@ -73,6 +75,28 @@ struct media_gobj {
>  struct media_pipeline {
>  };
>  
> +/**
> + * struct media_link - Define a media link graph object.
> + *
> + * @graph_obj:	Embedded structure containing the media object common data
> + * @list:	Linked list associated with an entity or an interface that
> + *		owns the link.
> + * @gobj0:	Part of an union. Used to get the pointer for the first

s/an union/a union/  (in multiple places)

See: https://answers.yahoo.com/question/index?qid=20081006092816AAvPO9n

> + *		graph_object of the link.
> + * @source:	Part of an union. Used only if the first object (gobj0) is
> + *		a pad. On such case, it represents the source pad.

s/On such case/In that case/  (in multiple places)

> + * @intf:	Part of an union. Used only if the first object (gobj0) is
> + *		an interface.
> + * @gobj1:	Part of an union. Used to get the pointer for the second
> + *		graph_object of the link.
> + * @source:	Part of an union. Used only if the second object (gobj0) is
> + *		a pad. On such case, it represents the sink pad.
> + * @entity:	Part of an union. Used only if the second object (gobj0) is
> + *		an entity.
> + * @reverse:	Pointer to the link for the reverse direction of a pad to pad
> + *		link.
> + * @flags:	Link flags, as defined at uapi/media.h (MEDIA_LNK_FL_*)

s/as defined at/as defined in/  (in multiple places)

> + */
>  struct media_link {
>  	struct media_gobj graph_obj;
>  	struct list_head list;
> @@ -86,15 +110,23 @@ struct media_link {
>  		struct media_pad *sink;
>  		struct media_entity *entity;
>  	};
> -	struct media_link *reverse;	/* Link in the reverse direction */
> -	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
> +	struct media_link *reverse;
> +	unsigned long flags;
>  };
>  
> +/**
> + * struct media_pad - Define a media pad graph object.
> + *
> + * @graph_obj:	Embedded structure containing the media object common data
> + * @entity:	Entity where this object belongs
> + * @index:	Pad index in the entity pads array, numbered from 0 to n
> + * @flags:	Pad flags, as defined at uapi/media.h (MEDIA_PAD_FL_*)
> + */
>  struct media_pad {
>  	struct media_gobj graph_obj;	/* must be first field in struct */
> -	struct media_entity *entity;	/* Entity this pad belongs to */
> -	u16 index;			/* Pad index in the entity pads array */
> -	unsigned long flags;		/* Pad flags (MEDIA_PAD_FL_*) */
> +	struct media_entity *entity;
> +	u16 index;
> +	unsigned long flags;
>  };
>  
>  /**
> @@ -113,51 +145,73 @@ struct media_entity_operations {
>  	int (*link_validate)(struct media_link *link);
>  };
>  
> +/**
> + * struct media_entity - Define a media entity graph object.
> + *
> + * @graph_obj:	Embedded structure containing the media object common data.
> + * @name:	Entity name.
> + * @type:	Entity type, as defined at uapi/media.h (MEDIA_ENT_T_*)
> + * @revision:	Entity revision - OBSOLETE - should be removed soon.
> + * @flags:	Entity flags, as defined at uapi/media.h (MEDIA_ENT_FL_*)
> + * @group_id:	Entity group ID - OBSOLETE - should be removed soon.
> + * @num_pads:	Number of sink and source pads.
> + * @num_links:	Number of existing links, both enabled and disabled.
> + * @num_backlinks: Number of backlinks
> + * @pads:	Pads array with the size defined by @num_pads.
> + * @links:	Linked list for the data links.
> + * @ops:	Entity operations.
> + * @stream_count: Stream count for the entity.
> + * @use_count:	Use count for the entity.
> + * @pipe:	Pipeline this entity belongs to.
> + * @info:	Union with devnode information.  Kept just for backward
> + * 		compatibility.
> + * @major:	Devnode major number (zero if not applicable). Kept just
> + * 		for backward compatibility.
> + * @minor:	Devnode minor number (zero if not applicable). Kept just
> + * 		for backward compatibility.
> + *
> + * NOTE: @stream_count and @use_count reference counts must never be
> + * negative, but are signed integers on purpose: a simple WARN_ON(<0) check
> + * can be used to detect reference count bugs that would make them negative.
> + */
>  struct media_entity {
>  	struct media_gobj graph_obj;	/* must be first field in struct */
> -	const char *name;		/* Entity name */
> -	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
> -	u32 revision;			/* Entity revision, driver specific */
> -	unsigned long flags;		/* Entity flags (MEDIA_ENT_FL_*) */
> -	u32 group_id;			/* Entity group ID */
> +	const char *name;
> +	u32 type;
> +	u32 revision;
> +	unsigned long flags;
> +	u32 group_id;
>  
> -	u16 num_pads;			/* Number of sink and source pads */
> -	u16 num_links;			/* Number of existing links, both
> -					 * enabled and disabled */
> -	u16 num_backlinks;		/* Number of backlinks */
> +	u16 num_pads;
> +	u16 num_links;
> +	u16 num_backlinks;
>  
> -	struct media_pad *pads;		/* Pads array (num_pads objects) */
> -	struct list_head links;		/* Pad-to-pad links list */
> +	struct media_pad *pads;
> +	struct list_head links;
>  
> -	const struct media_entity_operations *ops;	/* Entity operations */
> +	const struct media_entity_operations *ops;
>  
>  	/* Reference counts must never be negative, but are signed integers on
>  	 * purpose: a simple WARN_ON(<0) check can be used to detect reference
>  	 * count bugs that would make them negative.
>  	 */
> -	int stream_count;		/* Stream count for the entity. */
> -	int use_count;			/* Use count for the entity. */
> +	int stream_count;
> +	int use_count;
>  
> -	struct media_pipeline *pipe;	/* Pipeline this entity belongs to. */
> +	struct media_pipeline *pipe;
>  
>  	union {
> -		/* Node specifications */
>  		struct {
>  			u32 major;
>  			u32 minor;
>  		} dev;
> -
> -		/* Sub-device specifications */
> -		/* Nothing needed yet */
>  	} info;
>  };
>  
>  /**
> - * struct media_interface - Define a Kernel API interface
> + * struct media_interface - Define a media interface graph object
>   *
>   * @graph_obj:		embedded graph object
> - * @list:		Linked list used to find other interfaces that belong
> - *			to the same media controller
>   * @links:		List of links pointing to graph entities
>   * @type:		Type of the interface as defined at the
>   *			uapi/media/media.h header, e. g.
> @@ -177,7 +231,7 @@ struct media_interface {
>  };
>  
>  /**
> - * struct media_intf_devnode - Define a Kernel API interface via a device node
> + * struct media_intf_devnode - Define a media interface via a device node
>   *
>   * @intf:	embedded interface object
>   * @major:	Major number of a device node
> 

Regards,

	Hans

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
  2015-08-30  3:06   ` Mauro Carvalho Chehab
  (?)
  (?)
@ 2015-10-11 21:07     ` Sakari Ailus
  -1 siblings, 0 replies; 309+ messages in thread
From: Sakari Ailus @ 2015-10-11 21:07 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Mauro,

On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> Instead of relying on media subtype, use the new macros to detect
> if an entity is a subdev or an A/V DMA entity.
> 
> Please note that most drivers assume that there's just AV_DMA or
> V4L2 subdevs. This is not true anymore, as we've added MC support
> for DVB, and there are plans to add support for ALSA and FB/DRM
> too.
> 
> Ok, on the current pipelines supported by those drivers, just V4L
> stuff are there, but, assuming that some day a pipeline that also
> works with other subsystems will ever added, it is better to add
> explicit checks for the AV_DMA stuff.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> index 0eb34ecb8ee4..8c9a29e0e294 100644
> --- a/drivers/media/platform/exynos4-is/common.c
> +++ b/drivers/media/platform/exynos4-is/common.c
> @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
>  	while (pad->flags & MEDIA_PAD_FL_SINK) {
>  		/* source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> index 0627a93b2f3b..e9810fee4c30 100644
> --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
>  			}
>  		}
>  
> -		if (src_pad = NULL ||
> -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
>  			break;
>  
>  		/* Don't call FIMC subdev operation to avoid nested locking */
> @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
>  	struct fimc_vid_cap *vc = &fimc->vid_cap;
>  	struct v4l2_subdev *sensor;
>  
> -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!is_media_entity_v4l2_subdev(remote->entity))
>  		return -EINVAL;
>  
>  	if (WARN_ON(fimc = NULL))
> diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> index 3d9ccbf5f10f..5fbaf5e39903 100644
> --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
>  
>  		/* Retrieve format at the source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> index b2607da4ad14..c2327147b360 100644
> --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
>  		}
>  		/* Retrieve format at the source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  {
>  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> -	unsigned int remote_ent_type = media_entity_type(remote->entity);
>  	int ret = 0;
>  
>  	if (WARN_ON(fimc = NULL))
> @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  
>  	switch (local->index) {
>  	case FLITE_SD_PAD_SINK:
> -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
>  			ret = -EINVAL;
>  			break;
>  		}
> @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  	case FLITE_SD_PAD_SOURCE_DMA:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED))
>  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> -		else if (remote_ent_type = MEDIA_ENT_T_DEVNODE)
> +		else if (is_media_entity_v4l2_io(remote->entity))
>  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
>  		else
>  			ret = -EINVAL;
> @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  	case FLITE_SD_PAD_SOURCE_ISP:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED))
>  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> -		else if (remote_ent_type = MEDIA_ENT_T_V4L2_SUBDEV)
> +		else if (is_media_entity_v4l2_subdev(remote->entity))
>  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
>  		else
>  			ret = -EINVAL;
> diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> index 92dbade2fffc..4a25df9dd869 100644
> --- a/drivers/media/platform/exynos4-is/media-dev.c
> +++ b/drivers/media/platform/exynos4-is/media-dev.c
> @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
>  				break;
>  		}
>  
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
>  
> @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
>  
>  		ret  = __fimc_md_modify_pipeline(entity, enable);
> @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
>  	media_entity_graph_walk_start(&graph, entity_err);
>  
>  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity_err))
>  			continue;
>  
>  		__fimc_md_modify_pipeline(entity_err, !enable);
> diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> index 69e7733d36cd..cb8ac90086c1 100644
> --- a/drivers/media/platform/omap3isp/isp.c
> +++ b/drivers/media/platform/omap3isp/isp.c
> @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_io(entity))
>  			use += entity->use_count;
>  	}
>  
> @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
>  	struct v4l2_subdev *subdev;
>  	int ret;
>  
> -	subdev = media_entity_type(entity) = MEDIA_ENT_T_V4L2_SUBDEV
> +	subdev = is_media_entity_v4l2_subdev(entity)
>  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
>  
>  	if (entity->use_count = 0 && change > 0 && subdev != NULL) {
> @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(entity))
>  			ret = isp_pipeline_pm_power_one(entity, change);
>  
>  	if (!ret)
> @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
>  
>  	while ((first = media_entity_graph_walk_next(&graph))
>  	       && first != entity)
> -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(first))
>  			isp_pipeline_pm_power_one(first, -change);
>  
>  	return ret;
> @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> index 4c367352b1f7..52843ac2a9ca 100644
> --- a/drivers/media/platform/omap3isp/ispvideo.c
> +++ b/drivers/media/platform/omap3isp/ispvideo.c
> @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
>  
>  	remote = media_entity_remote_pad(&video->pad);
>  
> -	if (remote = NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
>  		if (entity = &video->video.entity)
>  			continue;
>  
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
>  
>  		__video = to_isp_video(media_entity_to_video_device(entity));
> @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
>  		return -EINVAL;
>  	}
>  
> -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!is_media_entity_v4l2_subdev(source))
>  		return 0;
>  
>  	pipe->external = media_entity_to_v4l2_subdev(source);
> diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> index eae667eab1b9..fb5b016cc0a1 100644
> --- a/drivers/media/platform/s3c-camif/camif-capture.c
> +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
>  
>  	/* Retrieve format at the sensor subdev source pad */
>  	pad = media_entity_remote_pad(&camif->pads[0]);
> -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  		return -EPIPE;
>  
>  	src_fmt.pad = pad->index;
> diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> index 1f94c1a54e00..f74158224b93 100644
> --- a/drivers/media/platform/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
>  	struct media_pad *remote;
>  
>  	remote = media_entity_remote_pad(local);
> -	if (remote = NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
>  			return -EPIPE;
>  
>  		/* We've reached a video node, that shouldn't have happened. */
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!is_media_entity_v4l2_subdev(pad->entity))
>  			return -EPIPE;
>  
>  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
>  		struct vsp1_rwpf *rwpf;
>  		struct vsp1_entity *e;
>  
> -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> +		if (is_media_entity_v4l2_io(entity)) {
>  			pipe->num_video++;
>  			continue;
>  		}
> @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
>  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
>  
>  	while (pad) {
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> index 88cd789cdaf7..8e14841bf445 100644
> --- a/drivers/media/platform/xilinx/xilinx-dma.c
> +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
>  	struct media_pad *remote;
>  
>  	remote = media_entity_remote_pad(local);
> -	if (remote = NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index e6e1115d8215..60da43772de9 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -526,7 +526,7 @@ static int
>  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
>  				     struct v4l2_subdev_format *fmt)
>  {
> -	if (media_entity_type(pad->entity) = MEDIA_ENT_T_V4L2_SUBDEV) {
> +	if (is_media_entity_v4l2_subdev(pad->entity)) {
>  		struct v4l2_subdev *sd >  			media_entity_to_v4l2_subdev(pad->entity);
>  
> diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> index 92573fa852a9..16763e0831f2 100644
> --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  		if (entity = &video->video_dev.entity)
>  			continue;
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if ((!is_media_entity_v4l2_io(remote->entity))
>  			continue;
>  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
>  		if (far_end->type = V4L2_BUF_TYPE_VIDEO_OUTPUT)
> @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
>  	media_entity_graph_walk_start(&graph, entity);
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  
> -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> +		if !is_media_entity_v4l2_subdev(entity))
>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  
> -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_subdev(entity))
>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> index 40591963b42b..44b88ff3ba83 100644
> --- a/drivers/staging/media/omap4iss/iss.c
> +++ b/drivers/staging/media/omap4iss/iss.c
> @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_io(entity))
>  			use += entity->use_count;
>  	}
>  
> @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
>  {
>  	struct v4l2_subdev *subdev;
>  
> -	subdev = media_entity_type(entity) = MEDIA_ENT_T_V4L2_SUBDEV
> +	subdev = is_media_entity_v4l2_subdev(entity)
>  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
>  
>  	if (entity->use_count = 0 && change > 0 && subdev != NULL) {
> @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(entity))
>  			ret = iss_pipeline_pm_power_one(entity, change);
>  
>  	if (!ret)
> @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
>  
>  	while ((first = media_entity_graph_walk_next(&graph))
>  	       && first != entity)
> -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(first))
>  			iss_pipeline_pm_power_one(first, -change);
>  
>  	return ret;
> @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> index 45a3f2d778fc..cbe5783735dc 100644
> --- a/drivers/staging/media/omap4iss/iss_video.c
> +++ b/drivers/staging/media/omap4iss/iss_video.c
> @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
>  
>  	remote = media_entity_remote_pad(&video->pad);
>  
> -	if (remote = NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
>  		if (entity = &video->video.entity)
>  			continue;
>  
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
>  
>  		far_end = to_iss_video(media_entity_to_video_device(entity));

I finally got around to test these patches eventually, and after some
debugging found this one. I think it's a good idea to have macros to
determine whether an entity exposes a V4L2 sub-device interface but it
should be more robust than is_media_entity_v4l2_subdev() right now is.

Incorrect result can have consequences from a pipeline start failure (due to
a failure in link validation) to memory corruption as struct media_entity
pointer is assumed to be a pointer to a field of another struct.

How about assigning that in V4L2 sub-device / video device registration,
for example?

-- 
Regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-10-11 21:07     ` Sakari Ailus
  0 siblings, 0 replies; 309+ messages in thread
From: Sakari Ailus @ 2015-10-11 21:07 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Kukjin Kim, Krzysztof Kozlowski,
	Laurent Pinchart, Hyun Kwon, Michal Simek, Sören Brinkmann,
	Greg Kroah-Hartman, Hans Verkuil, Prabhakar Lad,
	Lars-Peter Clausen, Markus Elfring, Sakari Ailus,
	Javier Martinez Canillas, linux-arm-kernel, linux-samsung-soc,
	linux-sh, devel

Hi Mauro,

On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> Instead of relying on media subtype, use the new macros to detect
> if an entity is a subdev or an A/V DMA entity.
> 
> Please note that most drivers assume that there's just AV_DMA or
> V4L2 subdevs. This is not true anymore, as we've added MC support
> for DVB, and there are plans to add support for ALSA and FB/DRM
> too.
> 
> Ok, on the current pipelines supported by those drivers, just V4L
> stuff are there, but, assuming that some day a pipeline that also
> works with other subsystems will ever added, it is better to add
> explicit checks for the AV_DMA stuff.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> index 0eb34ecb8ee4..8c9a29e0e294 100644
> --- a/drivers/media/platform/exynos4-is/common.c
> +++ b/drivers/media/platform/exynos4-is/common.c
> @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
>  	while (pad->flags & MEDIA_PAD_FL_SINK) {
>  		/* source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> index 0627a93b2f3b..e9810fee4c30 100644
> --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
>  			}
>  		}
>  
> -		if (src_pad == NULL ||
> -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
>  			break;
>  
>  		/* Don't call FIMC subdev operation to avoid nested locking */
> @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
>  	struct fimc_vid_cap *vc = &fimc->vid_cap;
>  	struct v4l2_subdev *sensor;
>  
> -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!is_media_entity_v4l2_subdev(remote->entity))
>  		return -EINVAL;
>  
>  	if (WARN_ON(fimc == NULL))
> diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> index 3d9ccbf5f10f..5fbaf5e39903 100644
> --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
>  
>  		/* Retrieve format at the source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> index b2607da4ad14..c2327147b360 100644
> --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
>  		}
>  		/* Retrieve format at the source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  {
>  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> -	unsigned int remote_ent_type = media_entity_type(remote->entity);
>  	int ret = 0;
>  
>  	if (WARN_ON(fimc == NULL))
> @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  
>  	switch (local->index) {
>  	case FLITE_SD_PAD_SINK:
> -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
>  			ret = -EINVAL;
>  			break;
>  		}
> @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  	case FLITE_SD_PAD_SOURCE_DMA:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED))
>  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> +		else if (is_media_entity_v4l2_io(remote->entity))
>  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
>  		else
>  			ret = -EINVAL;
> @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  	case FLITE_SD_PAD_SOURCE_ISP:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED))
>  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> +		else if (is_media_entity_v4l2_subdev(remote->entity))
>  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
>  		else
>  			ret = -EINVAL;
> diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> index 92dbade2fffc..4a25df9dd869 100644
> --- a/drivers/media/platform/exynos4-is/media-dev.c
> +++ b/drivers/media/platform/exynos4-is/media-dev.c
> @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
>  				break;
>  		}
>  
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
>  
> @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
>  
>  		ret  = __fimc_md_modify_pipeline(entity, enable);
> @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
>  	media_entity_graph_walk_start(&graph, entity_err);
>  
>  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity_err))
>  			continue;
>  
>  		__fimc_md_modify_pipeline(entity_err, !enable);
> diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> index 69e7733d36cd..cb8ac90086c1 100644
> --- a/drivers/media/platform/omap3isp/isp.c
> +++ b/drivers/media/platform/omap3isp/isp.c
> @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_io(entity))
>  			use += entity->use_count;
>  	}
>  
> @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
>  	struct v4l2_subdev *subdev;
>  	int ret;
>  
> -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> +	subdev = is_media_entity_v4l2_subdev(entity)
>  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
>  
>  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(entity))
>  			ret = isp_pipeline_pm_power_one(entity, change);
>  
>  	if (!ret)
> @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
>  
>  	while ((first = media_entity_graph_walk_next(&graph))
>  	       && first != entity)
> -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(first))
>  			isp_pipeline_pm_power_one(first, -change);
>  
>  	return ret;
> @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> index 4c367352b1f7..52843ac2a9ca 100644
> --- a/drivers/media/platform/omap3isp/ispvideo.c
> +++ b/drivers/media/platform/omap3isp/ispvideo.c
> @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
>  
>  	remote = media_entity_remote_pad(&video->pad);
>  
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
>  		if (entity == &video->video.entity)
>  			continue;
>  
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
>  
>  		__video = to_isp_video(media_entity_to_video_device(entity));
> @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
>  		return -EINVAL;
>  	}
>  
> -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!is_media_entity_v4l2_subdev(source))
>  		return 0;
>  
>  	pipe->external = media_entity_to_v4l2_subdev(source);
> diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> index eae667eab1b9..fb5b016cc0a1 100644
> --- a/drivers/media/platform/s3c-camif/camif-capture.c
> +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
>  
>  	/* Retrieve format at the sensor subdev source pad */
>  	pad = media_entity_remote_pad(&camif->pads[0]);
> -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  		return -EPIPE;
>  
>  	src_fmt.pad = pad->index;
> diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> index 1f94c1a54e00..f74158224b93 100644
> --- a/drivers/media/platform/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
>  	struct media_pad *remote;
>  
>  	remote = media_entity_remote_pad(local);
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
>  			return -EPIPE;
>  
>  		/* We've reached a video node, that shouldn't have happened. */
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!is_media_entity_v4l2_subdev(pad->entity))
>  			return -EPIPE;
>  
>  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
>  		struct vsp1_rwpf *rwpf;
>  		struct vsp1_entity *e;
>  
> -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> +		if (is_media_entity_v4l2_io(entity)) {
>  			pipe->num_video++;
>  			continue;
>  		}
> @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
>  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
>  
>  	while (pad) {
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> index 88cd789cdaf7..8e14841bf445 100644
> --- a/drivers/media/platform/xilinx/xilinx-dma.c
> +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
>  	struct media_pad *remote;
>  
>  	remote = media_entity_remote_pad(local);
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index e6e1115d8215..60da43772de9 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -526,7 +526,7 @@ static int
>  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
>  				     struct v4l2_subdev_format *fmt)
>  {
> -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> +	if (is_media_entity_v4l2_subdev(pad->entity)) {
>  		struct v4l2_subdev *sd =
>  			media_entity_to_v4l2_subdev(pad->entity);
>  
> diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> index 92573fa852a9..16763e0831f2 100644
> --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  		if (entity == &video->video_dev.entity)
>  			continue;
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if ((!is_media_entity_v4l2_io(remote->entity))
>  			continue;
>  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
>  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
>  	media_entity_graph_walk_start(&graph, entity);
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if !is_media_entity_v4l2_subdev(entity))
>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_subdev(entity))
>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> index 40591963b42b..44b88ff3ba83 100644
> --- a/drivers/staging/media/omap4iss/iss.c
> +++ b/drivers/staging/media/omap4iss/iss.c
> @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_io(entity))
>  			use += entity->use_count;
>  	}
>  
> @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
>  {
>  	struct v4l2_subdev *subdev;
>  
> -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> +	subdev = is_media_entity_v4l2_subdev(entity)
>  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
>  
>  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(entity))
>  			ret = iss_pipeline_pm_power_one(entity, change);
>  
>  	if (!ret)
> @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
>  
>  	while ((first = media_entity_graph_walk_next(&graph))
>  	       && first != entity)
> -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(first))
>  			iss_pipeline_pm_power_one(first, -change);
>  
>  	return ret;
> @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> index 45a3f2d778fc..cbe5783735dc 100644
> --- a/drivers/staging/media/omap4iss/iss_video.c
> +++ b/drivers/staging/media/omap4iss/iss_video.c
> @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
>  
>  	remote = media_entity_remote_pad(&video->pad);
>  
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
>  		if (entity == &video->video.entity)
>  			continue;
>  
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
>  
>  		far_end = to_iss_video(media_entity_to_video_device(entity));

I finally got around to test these patches eventually, and after some
debugging found this one. I think it's a good idea to have macros to
determine whether an entity exposes a V4L2 sub-device interface but it
should be more robust than is_media_entity_v4l2_subdev() right now is.

Incorrect result can have consequences from a pipeline start failure (due to
a failure in link validation) to memory corruption as struct media_entity
pointer is assumed to be a pointer to a field of another struct.

How about assigning that in V4L2 sub-device / video device registration,
for example?

-- 
Regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-10-11 21:07     ` Sakari Ailus
  0 siblings, 0 replies; 309+ messages in thread
From: Sakari Ailus @ 2015-10-11 21:07 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linux-arm-kernel, devel, Krzysztof Kozlowski, Lars-Peter Clausen,
	Sakari Ailus, Hyun Kwon, linux-sh, Greg Kroah-Hartman,
	Michal Simek, Mauro Carvalho Chehab, Javier Martinez Canillas,
	Kyungmin Park, Kukjin Kim, Hans Verkuil, Laurent Pinchart,
	Sylwester Nawrocki, linux-samsung-soc, Prabhakar Lad,
	Markus Elfring, Sören Brinkmann

Hi Mauro,

On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> Instead of relying on media subtype, use the new macros to detect
> if an entity is a subdev or an A/V DMA entity.
> 
> Please note that most drivers assume that there's just AV_DMA or
> V4L2 subdevs. This is not true anymore, as we've added MC support
> for DVB, and there are plans to add support for ALSA and FB/DRM
> too.
> 
> Ok, on the current pipelines supported by those drivers, just V4L
> stuff are there, but, assuming that some day a pipeline that also
> works with other subsystems will ever added, it is better to add
> explicit checks for the AV_DMA stuff.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> index 0eb34ecb8ee4..8c9a29e0e294 100644
> --- a/drivers/media/platform/exynos4-is/common.c
> +++ b/drivers/media/platform/exynos4-is/common.c
> @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
>  	while (pad->flags & MEDIA_PAD_FL_SINK) {
>  		/* source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> index 0627a93b2f3b..e9810fee4c30 100644
> --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
>  			}
>  		}
>  
> -		if (src_pad == NULL ||
> -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
>  			break;
>  
>  		/* Don't call FIMC subdev operation to avoid nested locking */
> @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
>  	struct fimc_vid_cap *vc = &fimc->vid_cap;
>  	struct v4l2_subdev *sensor;
>  
> -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!is_media_entity_v4l2_subdev(remote->entity))
>  		return -EINVAL;
>  
>  	if (WARN_ON(fimc == NULL))
> diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> index 3d9ccbf5f10f..5fbaf5e39903 100644
> --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
>  
>  		/* Retrieve format at the source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> index b2607da4ad14..c2327147b360 100644
> --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
>  		}
>  		/* Retrieve format at the source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  {
>  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> -	unsigned int remote_ent_type = media_entity_type(remote->entity);
>  	int ret = 0;
>  
>  	if (WARN_ON(fimc == NULL))
> @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  
>  	switch (local->index) {
>  	case FLITE_SD_PAD_SINK:
> -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
>  			ret = -EINVAL;
>  			break;
>  		}
> @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  	case FLITE_SD_PAD_SOURCE_DMA:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED))
>  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> +		else if (is_media_entity_v4l2_io(remote->entity))
>  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
>  		else
>  			ret = -EINVAL;
> @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  	case FLITE_SD_PAD_SOURCE_ISP:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED))
>  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> +		else if (is_media_entity_v4l2_subdev(remote->entity))
>  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
>  		else
>  			ret = -EINVAL;
> diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> index 92dbade2fffc..4a25df9dd869 100644
> --- a/drivers/media/platform/exynos4-is/media-dev.c
> +++ b/drivers/media/platform/exynos4-is/media-dev.c
> @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
>  				break;
>  		}
>  
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
>  
> @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
>  
>  		ret  = __fimc_md_modify_pipeline(entity, enable);
> @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
>  	media_entity_graph_walk_start(&graph, entity_err);
>  
>  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity_err))
>  			continue;
>  
>  		__fimc_md_modify_pipeline(entity_err, !enable);
> diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> index 69e7733d36cd..cb8ac90086c1 100644
> --- a/drivers/media/platform/omap3isp/isp.c
> +++ b/drivers/media/platform/omap3isp/isp.c
> @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_io(entity))
>  			use += entity->use_count;
>  	}
>  
> @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
>  	struct v4l2_subdev *subdev;
>  	int ret;
>  
> -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> +	subdev = is_media_entity_v4l2_subdev(entity)
>  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
>  
>  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(entity))
>  			ret = isp_pipeline_pm_power_one(entity, change);
>  
>  	if (!ret)
> @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
>  
>  	while ((first = media_entity_graph_walk_next(&graph))
>  	       && first != entity)
> -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(first))
>  			isp_pipeline_pm_power_one(first, -change);
>  
>  	return ret;
> @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> index 4c367352b1f7..52843ac2a9ca 100644
> --- a/drivers/media/platform/omap3isp/ispvideo.c
> +++ b/drivers/media/platform/omap3isp/ispvideo.c
> @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
>  
>  	remote = media_entity_remote_pad(&video->pad);
>  
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
>  		if (entity == &video->video.entity)
>  			continue;
>  
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
>  
>  		__video = to_isp_video(media_entity_to_video_device(entity));
> @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
>  		return -EINVAL;
>  	}
>  
> -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!is_media_entity_v4l2_subdev(source))
>  		return 0;
>  
>  	pipe->external = media_entity_to_v4l2_subdev(source);
> diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> index eae667eab1b9..fb5b016cc0a1 100644
> --- a/drivers/media/platform/s3c-camif/camif-capture.c
> +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
>  
>  	/* Retrieve format at the sensor subdev source pad */
>  	pad = media_entity_remote_pad(&camif->pads[0]);
> -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  		return -EPIPE;
>  
>  	src_fmt.pad = pad->index;
> diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> index 1f94c1a54e00..f74158224b93 100644
> --- a/drivers/media/platform/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
>  	struct media_pad *remote;
>  
>  	remote = media_entity_remote_pad(local);
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
>  			return -EPIPE;
>  
>  		/* We've reached a video node, that shouldn't have happened. */
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!is_media_entity_v4l2_subdev(pad->entity))
>  			return -EPIPE;
>  
>  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
>  		struct vsp1_rwpf *rwpf;
>  		struct vsp1_entity *e;
>  
> -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> +		if (is_media_entity_v4l2_io(entity)) {
>  			pipe->num_video++;
>  			continue;
>  		}
> @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
>  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
>  
>  	while (pad) {
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> index 88cd789cdaf7..8e14841bf445 100644
> --- a/drivers/media/platform/xilinx/xilinx-dma.c
> +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
>  	struct media_pad *remote;
>  
>  	remote = media_entity_remote_pad(local);
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index e6e1115d8215..60da43772de9 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -526,7 +526,7 @@ static int
>  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
>  				     struct v4l2_subdev_format *fmt)
>  {
> -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> +	if (is_media_entity_v4l2_subdev(pad->entity)) {
>  		struct v4l2_subdev *sd =
>  			media_entity_to_v4l2_subdev(pad->entity);
>  
> diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> index 92573fa852a9..16763e0831f2 100644
> --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  		if (entity == &video->video_dev.entity)
>  			continue;
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if ((!is_media_entity_v4l2_io(remote->entity))
>  			continue;
>  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
>  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
>  	media_entity_graph_walk_start(&graph, entity);
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if !is_media_entity_v4l2_subdev(entity))
>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_subdev(entity))
>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> index 40591963b42b..44b88ff3ba83 100644
> --- a/drivers/staging/media/omap4iss/iss.c
> +++ b/drivers/staging/media/omap4iss/iss.c
> @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_io(entity))
>  			use += entity->use_count;
>  	}
>  
> @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
>  {
>  	struct v4l2_subdev *subdev;
>  
> -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> +	subdev = is_media_entity_v4l2_subdev(entity)
>  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
>  
>  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(entity))
>  			ret = iss_pipeline_pm_power_one(entity, change);
>  
>  	if (!ret)
> @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
>  
>  	while ((first = media_entity_graph_walk_next(&graph))
>  	       && first != entity)
> -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(first))
>  			iss_pipeline_pm_power_one(first, -change);
>  
>  	return ret;
> @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> index 45a3f2d778fc..cbe5783735dc 100644
> --- a/drivers/staging/media/omap4iss/iss_video.c
> +++ b/drivers/staging/media/omap4iss/iss_video.c
> @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
>  
>  	remote = media_entity_remote_pad(&video->pad);
>  
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
>  		if (entity == &video->video.entity)
>  			continue;
>  
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
>  
>  		far_end = to_iss_video(media_entity_to_video_device(entity));

I finally got around to test these patches eventually, and after some
debugging found this one. I think it's a good idea to have macros to
determine whether an entity exposes a V4L2 sub-device interface but it
should be more robust than is_media_entity_v4l2_subdev() right now is.

Incorrect result can have consequences from a pipeline start failure (due to
a failure in link validation) to memory corruption as struct media_entity
pointer is assumed to be a pointer to a field of another struct.

How about assigning that in V4L2 sub-device / video device registration,
for example?

-- 
Regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-10-11 21:07     ` Sakari Ailus
  0 siblings, 0 replies; 309+ messages in thread
From: Sakari Ailus @ 2015-10-11 21:07 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Mauro,

On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> Instead of relying on media subtype, use the new macros to detect
> if an entity is a subdev or an A/V DMA entity.
> 
> Please note that most drivers assume that there's just AV_DMA or
> V4L2 subdevs. This is not true anymore, as we've added MC support
> for DVB, and there are plans to add support for ALSA and FB/DRM
> too.
> 
> Ok, on the current pipelines supported by those drivers, just V4L
> stuff are there, but, assuming that some day a pipeline that also
> works with other subsystems will ever added, it is better to add
> explicit checks for the AV_DMA stuff.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> index 0eb34ecb8ee4..8c9a29e0e294 100644
> --- a/drivers/media/platform/exynos4-is/common.c
> +++ b/drivers/media/platform/exynos4-is/common.c
> @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
>  	while (pad->flags & MEDIA_PAD_FL_SINK) {
>  		/* source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> index 0627a93b2f3b..e9810fee4c30 100644
> --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
>  			}
>  		}
>  
> -		if (src_pad == NULL ||
> -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
>  			break;
>  
>  		/* Don't call FIMC subdev operation to avoid nested locking */
> @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
>  	struct fimc_vid_cap *vc = &fimc->vid_cap;
>  	struct v4l2_subdev *sensor;
>  
> -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!is_media_entity_v4l2_subdev(remote->entity))
>  		return -EINVAL;
>  
>  	if (WARN_ON(fimc == NULL))
> diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> index 3d9ccbf5f10f..5fbaf5e39903 100644
> --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
>  
>  		/* Retrieve format at the source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> index b2607da4ad14..c2327147b360 100644
> --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
>  		}
>  		/* Retrieve format at the source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  {
>  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> -	unsigned int remote_ent_type = media_entity_type(remote->entity);
>  	int ret = 0;
>  
>  	if (WARN_ON(fimc == NULL))
> @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  
>  	switch (local->index) {
>  	case FLITE_SD_PAD_SINK:
> -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
>  			ret = -EINVAL;
>  			break;
>  		}
> @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  	case FLITE_SD_PAD_SOURCE_DMA:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED))
>  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> +		else if (is_media_entity_v4l2_io(remote->entity))
>  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
>  		else
>  			ret = -EINVAL;
> @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
>  	case FLITE_SD_PAD_SOURCE_ISP:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED))
>  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> +		else if (is_media_entity_v4l2_subdev(remote->entity))
>  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
>  		else
>  			ret = -EINVAL;
> diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> index 92dbade2fffc..4a25df9dd869 100644
> --- a/drivers/media/platform/exynos4-is/media-dev.c
> +++ b/drivers/media/platform/exynos4-is/media-dev.c
> @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
>  				break;
>  		}
>  
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
>  
> @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
>  
>  		ret  = __fimc_md_modify_pipeline(entity, enable);
> @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
>  	media_entity_graph_walk_start(&graph, entity_err);
>  
>  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity_err))
>  			continue;
>  
>  		__fimc_md_modify_pipeline(entity_err, !enable);
> diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> index 69e7733d36cd..cb8ac90086c1 100644
> --- a/drivers/media/platform/omap3isp/isp.c
> +++ b/drivers/media/platform/omap3isp/isp.c
> @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_io(entity))
>  			use += entity->use_count;
>  	}
>  
> @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
>  	struct v4l2_subdev *subdev;
>  	int ret;
>  
> -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> +	subdev = is_media_entity_v4l2_subdev(entity)
>  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
>  
>  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(entity))
>  			ret = isp_pipeline_pm_power_one(entity, change);
>  
>  	if (!ret)
> @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
>  
>  	while ((first = media_entity_graph_walk_next(&graph))
>  	       && first != entity)
> -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(first))
>  			isp_pipeline_pm_power_one(first, -change);
>  
>  	return ret;
> @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> index 4c367352b1f7..52843ac2a9ca 100644
> --- a/drivers/media/platform/omap3isp/ispvideo.c
> +++ b/drivers/media/platform/omap3isp/ispvideo.c
> @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
>  
>  	remote = media_entity_remote_pad(&video->pad);
>  
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
>  		if (entity == &video->video.entity)
>  			continue;
>  
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
>  
>  		__video = to_isp_video(media_entity_to_video_device(entity));
> @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
>  		return -EINVAL;
>  	}
>  
> -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!is_media_entity_v4l2_subdev(source))
>  		return 0;
>  
>  	pipe->external = media_entity_to_v4l2_subdev(source);
> diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> index eae667eab1b9..fb5b016cc0a1 100644
> --- a/drivers/media/platform/s3c-camif/camif-capture.c
> +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
>  
>  	/* Retrieve format at the sensor subdev source pad */
>  	pad = media_entity_remote_pad(&camif->pads[0]);
> -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  		return -EPIPE;
>  
>  	src_fmt.pad = pad->index;
> diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> index 1f94c1a54e00..f74158224b93 100644
> --- a/drivers/media/platform/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
>  	struct media_pad *remote;
>  
>  	remote = media_entity_remote_pad(local);
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
>  			return -EPIPE;
>  
>  		/* We've reached a video node, that shouldn't have happened. */
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!is_media_entity_v4l2_subdev(pad->entity))
>  			return -EPIPE;
>  
>  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
>  		struct vsp1_rwpf *rwpf;
>  		struct vsp1_entity *e;
>  
> -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> +		if (is_media_entity_v4l2_io(entity)) {
>  			pipe->num_video++;
>  			continue;
>  		}
> @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
>  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
>  
>  	while (pad) {
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> index 88cd789cdaf7..8e14841bf445 100644
> --- a/drivers/media/platform/xilinx/xilinx-dma.c
> +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
>  	struct media_pad *remote;
>  
>  	remote = media_entity_remote_pad(local);
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index e6e1115d8215..60da43772de9 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -526,7 +526,7 @@ static int
>  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
>  				     struct v4l2_subdev_format *fmt)
>  {
> -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> +	if (is_media_entity_v4l2_subdev(pad->entity)) {
>  		struct v4l2_subdev *sd =
>  			media_entity_to_v4l2_subdev(pad->entity);
>  
> diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> index 92573fa852a9..16763e0831f2 100644
> --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  		if (entity == &video->video_dev.entity)
>  			continue;
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if ((!is_media_entity_v4l2_io(remote->entity))
>  			continue;
>  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
>  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
>  	media_entity_graph_walk_start(&graph, entity);
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if !is_media_entity_v4l2_subdev(entity))
>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_subdev(entity))
>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> index 40591963b42b..44b88ff3ba83 100644
> --- a/drivers/staging/media/omap4iss/iss.c
> +++ b/drivers/staging/media/omap4iss/iss.c
> @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_io(entity))
>  			use += entity->use_count;
>  	}
>  
> @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
>  {
>  	struct v4l2_subdev *subdev;
>  
> -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> +	subdev = is_media_entity_v4l2_subdev(entity)
>  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
>  
>  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
>  	media_entity_graph_walk_start(&graph, entity);
>  
>  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(entity))
>  			ret = iss_pipeline_pm_power_one(entity, change);
>  
>  	if (!ret)
> @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
>  
>  	while ((first = media_entity_graph_walk_next(&graph))
>  	       && first != entity)
> -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(first))
>  			iss_pipeline_pm_power_one(first, -change);
>  
>  	return ret;
> @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
>  			break;
>  
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  
>  		entity = pad->entity;
> diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> index 45a3f2d778fc..cbe5783735dc 100644
> --- a/drivers/staging/media/omap4iss/iss_video.c
> +++ b/drivers/staging/media/omap4iss/iss_video.c
> @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
>  
>  	remote = media_entity_remote_pad(&video->pad);
>  
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  
>  	if (pad)
> @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
>  		if (entity == &video->video.entity)
>  			continue;
>  
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
>  
>  		far_end = to_iss_video(media_entity_to_video_device(entity));

I finally got around to test these patches eventually, and after some
debugging found this one. I think it's a good idea to have macros to
determine whether an entity exposes a V4L2 sub-device interface but it
should be more robust than is_media_entity_v4l2_subdev() right now is.

Incorrect result can have consequences from a pipeline start failure (due to
a failure in link validation) to memory corruption as struct media_entity
pointer is assumed to be a pointer to a field of another struct.

How about assigning that in V4L2 sub-device / video device registration,
for example?

-- 
Regards,

Sakari Ailus
e-mail: sakari.ailus at iki.fi	XMPP: sailus at retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
  2015-10-11 21:07     ` Sakari Ailus
  (?)
  (?)
@ 2015-10-12  0:56       ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-10-12  0:56 UTC (permalink / raw)
  To: linux-arm-kernel

Em Mon, 12 Oct 2015 00:07:52 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > Instead of relying on media subtype, use the new macros to detect
> > if an entity is a subdev or an A/V DMA entity.
> > 
> > Please note that most drivers assume that there's just AV_DMA or
> > V4L2 subdevs. This is not true anymore, as we've added MC support
> > for DVB, and there are plans to add support for ALSA and FB/DRM
> > too.
> > 
> > Ok, on the current pipelines supported by those drivers, just V4L
> > stuff are there, but, assuming that some day a pipeline that also
> > works with other subsystems will ever added, it is better to add
> > explicit checks for the AV_DMA stuff.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > --- a/drivers/media/platform/exynos4-is/common.c
> > +++ b/drivers/media/platform/exynos4-is/common.c
> > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> >  		/* source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > index 0627a93b2f3b..e9810fee4c30 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> >  			}
> >  		}
> >  
> > -		if (src_pad = NULL ||
> > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> >  			break;
> >  
> >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> >  	struct v4l2_subdev *sensor;
> >  
> > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> >  		return -EINVAL;
> >  
> >  	if (WARN_ON(fimc = NULL))
> > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> >  
> >  		/* Retrieve format at the source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > index b2607da4ad14..c2327147b360 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> >  		}
> >  		/* Retrieve format at the source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  {
> >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> >  	int ret = 0;
> >  
> >  	if (WARN_ON(fimc = NULL))
> > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  
> >  	switch (local->index) {
> >  	case FLITE_SD_PAD_SINK:
> > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> >  			ret = -EINVAL;
> >  			break;
> >  		}
> > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  	case FLITE_SD_PAD_SOURCE_DMA:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > -		else if (remote_ent_type = MEDIA_ENT_T_DEVNODE)
> > +		else if (is_media_entity_v4l2_io(remote->entity))
> >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> >  		else
> >  			ret = -EINVAL;
> > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  	case FLITE_SD_PAD_SOURCE_ISP:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > -		else if (remote_ent_type = MEDIA_ENT_T_V4L2_SUBDEV)
> > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> >  		else
> >  			ret = -EINVAL;
> > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > index 92dbade2fffc..4a25df9dd869 100644
> > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> >  				break;
> >  		}
> >  
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> >  
> > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> >  
> >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> >  	media_entity_graph_walk_start(&graph, entity_err);
> >  
> >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity_err))
> >  			continue;
> >  
> >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > index 69e7733d36cd..cb8ac90086c1 100644
> > --- a/drivers/media/platform/omap3isp/isp.c
> > +++ b/drivers/media/platform/omap3isp/isp.c
> > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_io(entity))
> >  			use += entity->use_count;
> >  	}
> >  
> > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> >  	struct v4l2_subdev *subdev;
> >  	int ret;
> >  
> > -	subdev = media_entity_type(entity) = MEDIA_ENT_T_V4L2_SUBDEV
> > +	subdev = is_media_entity_v4l2_subdev(entity)
> >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> >  
> >  	if (entity->use_count = 0 && change > 0 && subdev != NULL) {
> > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(entity))
> >  			ret = isp_pipeline_pm_power_one(entity, change);
> >  
> >  	if (!ret)
> > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> >  
> >  	while ((first = media_entity_graph_walk_next(&graph))
> >  	       && first != entity)
> > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(first))
> >  			isp_pipeline_pm_power_one(first, -change);
> >  
> >  	return ret;
> > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > index 4c367352b1f7..52843ac2a9ca 100644
> > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> >  
> >  	remote = media_entity_remote_pad(&video->pad);
> >  
> > -	if (remote = NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> >  		if (entity = &video->video.entity)
> >  			continue;
> >  
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> >  
> >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> >  		return -EINVAL;
> >  	}
> >  
> > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!is_media_entity_v4l2_subdev(source))
> >  		return 0;
> >  
> >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > index eae667eab1b9..fb5b016cc0a1 100644
> > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> >  
> >  	/* Retrieve format at the sensor subdev source pad */
> >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  		return -EPIPE;
> >  
> >  	src_fmt.pad = pad->index;
> > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > index 1f94c1a54e00..f74158224b93 100644
> > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> >  	struct media_pad *remote;
> >  
> >  	remote = media_entity_remote_pad(local);
> > -	if (remote = NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> >  			return -EPIPE;
> >  
> >  		/* We've reached a video node, that shouldn't have happened. */
> > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> >  			return -EPIPE;
> >  
> >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> >  		struct vsp1_rwpf *rwpf;
> >  		struct vsp1_entity *e;
> >  
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > +		if (is_media_entity_v4l2_io(entity)) {
> >  			pipe->num_video++;
> >  			continue;
> >  		}
> > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> >  
> >  	while (pad) {
> > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > index 88cd789cdaf7..8e14841bf445 100644
> > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> >  	struct media_pad *remote;
> >  
> >  	remote = media_entity_remote_pad(local);
> > -	if (remote = NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > index e6e1115d8215..60da43772de9 100644
> > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > @@ -526,7 +526,7 @@ static int
> >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> >  				     struct v4l2_subdev_format *fmt)
> >  {
> > -	if (media_entity_type(pad->entity) = MEDIA_ENT_T_V4L2_SUBDEV) {
> > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> >  		struct v4l2_subdev *sd > >  			media_entity_to_v4l2_subdev(pad->entity);
> >  
> > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > index 92573fa852a9..16763e0831f2 100644
> > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> >  		if (entity = &video->video_dev.entity)
> >  			continue;
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if ((!is_media_entity_v4l2_io(remote->entity))
> >  			continue;
> >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> >  		if (far_end->type = V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> >  
> > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > +		if !is_media_entity_v4l2_subdev(entity))
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> >  
> > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_subdev(entity))
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > index 40591963b42b..44b88ff3ba83 100644
> > --- a/drivers/staging/media/omap4iss/iss.c
> > +++ b/drivers/staging/media/omap4iss/iss.c
> > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_io(entity))
> >  			use += entity->use_count;
> >  	}
> >  
> > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> >  {
> >  	struct v4l2_subdev *subdev;
> >  
> > -	subdev = media_entity_type(entity) = MEDIA_ENT_T_V4L2_SUBDEV
> > +	subdev = is_media_entity_v4l2_subdev(entity)
> >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> >  
> >  	if (entity->use_count = 0 && change > 0 && subdev != NULL) {
> > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(entity))
> >  			ret = iss_pipeline_pm_power_one(entity, change);
> >  
> >  	if (!ret)
> > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> >  
> >  	while ((first = media_entity_graph_walk_next(&graph))
> >  	       && first != entity)
> > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(first))
> >  			iss_pipeline_pm_power_one(first, -change);
> >  
> >  	return ret;
> > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > index 45a3f2d778fc..cbe5783735dc 100644
> > --- a/drivers/staging/media/omap4iss/iss_video.c
> > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> >  
> >  	remote = media_entity_remote_pad(&video->pad);
> >  
> > -	if (remote = NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> >  		if (entity = &video->video.entity)
> >  			continue;
> >  
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> >  
> >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> 
> I finally got around to test these patches eventually, and after some
> debugging found this one. I think it's a good idea to have macros to
> determine whether an entity exposes a V4L2 sub-device interface but it
> should be more robust than is_media_entity_v4l2_subdev() right now is.

Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
actually a separate graph object (interfaces). Those macros work at the
entities, not at the interface objects.

> Incorrect result can have consequences from a pipeline start failure (due to
> a failure in link validation) to memory corruption as struct media_entity
> pointer is assumed to be a pointer to a field of another struct.

Yes, an incorrect result would cause pipeline failures.

> How about assigning that in V4L2 sub-device / video device registration,
> for example?

What do you mean? Could you give an example to make it clearer?

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-10-12  0:56       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-10-12  0:56 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Kukjin Kim, Krzysztof Kozlowski,
	Laurent Pinchart, Hyun Kwon, Michal Simek, Sören Brinkmann,
	Greg Kroah-Hartman, Hans Verkuil, Prabhakar Lad,
	Lars-Peter Clausen, Markus Elfring, Sakari Ailus,
	Javier Martinez Canillas, linux-arm-kernel, linux-samsung-soc,
	linux-sh, devel

Em Mon, 12 Oct 2015 00:07:52 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > Instead of relying on media subtype, use the new macros to detect
> > if an entity is a subdev or an A/V DMA entity.
> > 
> > Please note that most drivers assume that there's just AV_DMA or
> > V4L2 subdevs. This is not true anymore, as we've added MC support
> > for DVB, and there are plans to add support for ALSA and FB/DRM
> > too.
> > 
> > Ok, on the current pipelines supported by those drivers, just V4L
> > stuff are there, but, assuming that some day a pipeline that also
> > works with other subsystems will ever added, it is better to add
> > explicit checks for the AV_DMA stuff.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > --- a/drivers/media/platform/exynos4-is/common.c
> > +++ b/drivers/media/platform/exynos4-is/common.c
> > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> >  		/* source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > index 0627a93b2f3b..e9810fee4c30 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> >  			}
> >  		}
> >  
> > -		if (src_pad == NULL ||
> > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> >  			break;
> >  
> >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> >  	struct v4l2_subdev *sensor;
> >  
> > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> >  		return -EINVAL;
> >  
> >  	if (WARN_ON(fimc == NULL))
> > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> >  
> >  		/* Retrieve format at the source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > index b2607da4ad14..c2327147b360 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> >  		}
> >  		/* Retrieve format at the source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  {
> >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> >  	int ret = 0;
> >  
> >  	if (WARN_ON(fimc == NULL))
> > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  
> >  	switch (local->index) {
> >  	case FLITE_SD_PAD_SINK:
> > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> >  			ret = -EINVAL;
> >  			break;
> >  		}
> > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  	case FLITE_SD_PAD_SOURCE_DMA:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> > +		else if (is_media_entity_v4l2_io(remote->entity))
> >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> >  		else
> >  			ret = -EINVAL;
> > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  	case FLITE_SD_PAD_SOURCE_ISP:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> >  		else
> >  			ret = -EINVAL;
> > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > index 92dbade2fffc..4a25df9dd869 100644
> > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> >  				break;
> >  		}
> >  
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> >  
> > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> >  
> >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> >  	media_entity_graph_walk_start(&graph, entity_err);
> >  
> >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity_err))
> >  			continue;
> >  
> >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > index 69e7733d36cd..cb8ac90086c1 100644
> > --- a/drivers/media/platform/omap3isp/isp.c
> > +++ b/drivers/media/platform/omap3isp/isp.c
> > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_io(entity))
> >  			use += entity->use_count;
> >  	}
> >  
> > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> >  	struct v4l2_subdev *subdev;
> >  	int ret;
> >  
> > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > +	subdev = is_media_entity_v4l2_subdev(entity)
> >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> >  
> >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(entity))
> >  			ret = isp_pipeline_pm_power_one(entity, change);
> >  
> >  	if (!ret)
> > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> >  
> >  	while ((first = media_entity_graph_walk_next(&graph))
> >  	       && first != entity)
> > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(first))
> >  			isp_pipeline_pm_power_one(first, -change);
> >  
> >  	return ret;
> > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > index 4c367352b1f7..52843ac2a9ca 100644
> > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> >  
> >  	remote = media_entity_remote_pad(&video->pad);
> >  
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> >  		if (entity == &video->video.entity)
> >  			continue;
> >  
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> >  
> >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> >  		return -EINVAL;
> >  	}
> >  
> > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!is_media_entity_v4l2_subdev(source))
> >  		return 0;
> >  
> >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > index eae667eab1b9..fb5b016cc0a1 100644
> > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> >  
> >  	/* Retrieve format at the sensor subdev source pad */
> >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  		return -EPIPE;
> >  
> >  	src_fmt.pad = pad->index;
> > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > index 1f94c1a54e00..f74158224b93 100644
> > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> >  	struct media_pad *remote;
> >  
> >  	remote = media_entity_remote_pad(local);
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> >  			return -EPIPE;
> >  
> >  		/* We've reached a video node, that shouldn't have happened. */
> > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> >  			return -EPIPE;
> >  
> >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> >  		struct vsp1_rwpf *rwpf;
> >  		struct vsp1_entity *e;
> >  
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > +		if (is_media_entity_v4l2_io(entity)) {
> >  			pipe->num_video++;
> >  			continue;
> >  		}
> > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> >  
> >  	while (pad) {
> > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > index 88cd789cdaf7..8e14841bf445 100644
> > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> >  	struct media_pad *remote;
> >  
> >  	remote = media_entity_remote_pad(local);
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > index e6e1115d8215..60da43772de9 100644
> > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > @@ -526,7 +526,7 @@ static int
> >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> >  				     struct v4l2_subdev_format *fmt)
> >  {
> > -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> >  		struct v4l2_subdev *sd =
> >  			media_entity_to_v4l2_subdev(pad->entity);
> >  
> > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > index 92573fa852a9..16763e0831f2 100644
> > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> >  		if (entity == &video->video_dev.entity)
> >  			continue;
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if ((!is_media_entity_v4l2_io(remote->entity))
> >  			continue;
> >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> >  
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if !is_media_entity_v4l2_subdev(entity))
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> >  
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_subdev(entity))
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > index 40591963b42b..44b88ff3ba83 100644
> > --- a/drivers/staging/media/omap4iss/iss.c
> > +++ b/drivers/staging/media/omap4iss/iss.c
> > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_io(entity))
> >  			use += entity->use_count;
> >  	}
> >  
> > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> >  {
> >  	struct v4l2_subdev *subdev;
> >  
> > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > +	subdev = is_media_entity_v4l2_subdev(entity)
> >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> >  
> >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(entity))
> >  			ret = iss_pipeline_pm_power_one(entity, change);
> >  
> >  	if (!ret)
> > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> >  
> >  	while ((first = media_entity_graph_walk_next(&graph))
> >  	       && first != entity)
> > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(first))
> >  			iss_pipeline_pm_power_one(first, -change);
> >  
> >  	return ret;
> > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > index 45a3f2d778fc..cbe5783735dc 100644
> > --- a/drivers/staging/media/omap4iss/iss_video.c
> > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> >  
> >  	remote = media_entity_remote_pad(&video->pad);
> >  
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> >  		if (entity == &video->video.entity)
> >  			continue;
> >  
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> >  
> >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> 
> I finally got around to test these patches eventually, and after some
> debugging found this one. I think it's a good idea to have macros to
> determine whether an entity exposes a V4L2 sub-device interface but it
> should be more robust than is_media_entity_v4l2_subdev() right now is.

Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
actually a separate graph object (interfaces). Those macros work at the
entities, not at the interface objects.

> Incorrect result can have consequences from a pipeline start failure (due to
> a failure in link validation) to memory corruption as struct media_entity
> pointer is assumed to be a pointer to a field of another struct.

Yes, an incorrect result would cause pipeline failures.

> How about assigning that in V4L2 sub-device / video device registration,
> for example?

What do you mean? Could you give an example to make it clearer?

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-10-12  0:56       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-10-12  0:56 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Kukjin Kim, Krzysztof Kozlowski,
	Laurent Pinchart, Hyun Kwon, Michal Simek, Sören Brinkmann,
	Greg Kroah-Hartman, Hans Verkuil, Prabhakar Lad,
	Lars-Peter Clausen, Markus Elfring, Sakari Ailus,
	Javier Martinez Canillas, linux-arm-kernel, linux-samsung-soc,
	linux-sh

Em Mon, 12 Oct 2015 00:07:52 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > Instead of relying on media subtype, use the new macros to detect
> > if an entity is a subdev or an A/V DMA entity.
> > 
> > Please note that most drivers assume that there's just AV_DMA or
> > V4L2 subdevs. This is not true anymore, as we've added MC support
> > for DVB, and there are plans to add support for ALSA and FB/DRM
> > too.
> > 
> > Ok, on the current pipelines supported by those drivers, just V4L
> > stuff are there, but, assuming that some day a pipeline that also
> > works with other subsystems will ever added, it is better to add
> > explicit checks for the AV_DMA stuff.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > --- a/drivers/media/platform/exynos4-is/common.c
> > +++ b/drivers/media/platform/exynos4-is/common.c
> > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> >  		/* source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > index 0627a93b2f3b..e9810fee4c30 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> >  			}
> >  		}
> >  
> > -		if (src_pad == NULL ||
> > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> >  			break;
> >  
> >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> >  	struct v4l2_subdev *sensor;
> >  
> > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> >  		return -EINVAL;
> >  
> >  	if (WARN_ON(fimc == NULL))
> > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> >  
> >  		/* Retrieve format at the source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > index b2607da4ad14..c2327147b360 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> >  		}
> >  		/* Retrieve format at the source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  {
> >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> >  	int ret = 0;
> >  
> >  	if (WARN_ON(fimc == NULL))
> > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  
> >  	switch (local->index) {
> >  	case FLITE_SD_PAD_SINK:
> > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> >  			ret = -EINVAL;
> >  			break;
> >  		}
> > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  	case FLITE_SD_PAD_SOURCE_DMA:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> > +		else if (is_media_entity_v4l2_io(remote->entity))
> >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> >  		else
> >  			ret = -EINVAL;
> > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  	case FLITE_SD_PAD_SOURCE_ISP:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> >  		else
> >  			ret = -EINVAL;
> > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > index 92dbade2fffc..4a25df9dd869 100644
> > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> >  				break;
> >  		}
> >  
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> >  
> > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> >  
> >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> >  	media_entity_graph_walk_start(&graph, entity_err);
> >  
> >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity_err))
> >  			continue;
> >  
> >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > index 69e7733d36cd..cb8ac90086c1 100644
> > --- a/drivers/media/platform/omap3isp/isp.c
> > +++ b/drivers/media/platform/omap3isp/isp.c
> > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_io(entity))
> >  			use += entity->use_count;
> >  	}
> >  
> > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> >  	struct v4l2_subdev *subdev;
> >  	int ret;
> >  
> > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > +	subdev = is_media_entity_v4l2_subdev(entity)
> >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> >  
> >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(entity))
> >  			ret = isp_pipeline_pm_power_one(entity, change);
> >  
> >  	if (!ret)
> > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> >  
> >  	while ((first = media_entity_graph_walk_next(&graph))
> >  	       && first != entity)
> > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(first))
> >  			isp_pipeline_pm_power_one(first, -change);
> >  
> >  	return ret;
> > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > index 4c367352b1f7..52843ac2a9ca 100644
> > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> >  
> >  	remote = media_entity_remote_pad(&video->pad);
> >  
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> >  		if (entity == &video->video.entity)
> >  			continue;
> >  
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> >  
> >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> >  		return -EINVAL;
> >  	}
> >  
> > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!is_media_entity_v4l2_subdev(source))
> >  		return 0;
> >  
> >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > index eae667eab1b9..fb5b016cc0a1 100644
> > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> >  
> >  	/* Retrieve format at the sensor subdev source pad */
> >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  		return -EPIPE;
> >  
> >  	src_fmt.pad = pad->index;
> > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > index 1f94c1a54e00..f74158224b93 100644
> > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> >  	struct media_pad *remote;
> >  
> >  	remote = media_entity_remote_pad(local);
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> >  			return -EPIPE;
> >  
> >  		/* We've reached a video node, that shouldn't have happened. */
> > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> >  			return -EPIPE;
> >  
> >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> >  		struct vsp1_rwpf *rwpf;
> >  		struct vsp1_entity *e;
> >  
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > +		if (is_media_entity_v4l2_io(entity)) {
> >  			pipe->num_video++;
> >  			continue;
> >  		}
> > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> >  
> >  	while (pad) {
> > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > index 88cd789cdaf7..8e14841bf445 100644
> > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> >  	struct media_pad *remote;
> >  
> >  	remote = media_entity_remote_pad(local);
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > index e6e1115d8215..60da43772de9 100644
> > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > @@ -526,7 +526,7 @@ static int
> >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> >  				     struct v4l2_subdev_format *fmt)
> >  {
> > -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> >  		struct v4l2_subdev *sd =
> >  			media_entity_to_v4l2_subdev(pad->entity);
> >  
> > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > index 92573fa852a9..16763e0831f2 100644
> > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> >  		if (entity == &video->video_dev.entity)
> >  			continue;
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if ((!is_media_entity_v4l2_io(remote->entity))
> >  			continue;
> >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> >  
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if !is_media_entity_v4l2_subdev(entity))
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> >  
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_subdev(entity))
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > index 40591963b42b..44b88ff3ba83 100644
> > --- a/drivers/staging/media/omap4iss/iss.c
> > +++ b/drivers/staging/media/omap4iss/iss.c
> > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_io(entity))
> >  			use += entity->use_count;
> >  	}
> >  
> > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> >  {
> >  	struct v4l2_subdev *subdev;
> >  
> > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > +	subdev = is_media_entity_v4l2_subdev(entity)
> >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> >  
> >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(entity))
> >  			ret = iss_pipeline_pm_power_one(entity, change);
> >  
> >  	if (!ret)
> > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> >  
> >  	while ((first = media_entity_graph_walk_next(&graph))
> >  	       && first != entity)
> > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(first))
> >  			iss_pipeline_pm_power_one(first, -change);
> >  
> >  	return ret;
> > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > index 45a3f2d778fc..cbe5783735dc 100644
> > --- a/drivers/staging/media/omap4iss/iss_video.c
> > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> >  
> >  	remote = media_entity_remote_pad(&video->pad);
> >  
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> >  		if (entity == &video->video.entity)
> >  			continue;
> >  
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> >  
> >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> 
> I finally got around to test these patches eventually, and after some
> debugging found this one. I think it's a good idea to have macros to
> determine whether an entity exposes a V4L2 sub-device interface but it
> should be more robust than is_media_entity_v4l2_subdev() right now is.

Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
actually a separate graph object (interfaces). Those macros work at the
entities, not at the interface objects.

> Incorrect result can have consequences from a pipeline start failure (due to
> a failure in link validation) to memory corruption as struct media_entity
> pointer is assumed to be a pointer to a field of another struct.

Yes, an incorrect result would cause pipeline failures.

> How about assigning that in V4L2 sub-device / video device registration,
> for example?

What do you mean? Could you give an example to make it clearer?

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-10-12  0:56       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-10-12  0:56 UTC (permalink / raw)
  To: linux-arm-kernel

Em Mon, 12 Oct 2015 00:07:52 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > Instead of relying on media subtype, use the new macros to detect
> > if an entity is a subdev or an A/V DMA entity.
> > 
> > Please note that most drivers assume that there's just AV_DMA or
> > V4L2 subdevs. This is not true anymore, as we've added MC support
> > for DVB, and there are plans to add support for ALSA and FB/DRM
> > too.
> > 
> > Ok, on the current pipelines supported by those drivers, just V4L
> > stuff are there, but, assuming that some day a pipeline that also
> > works with other subsystems will ever added, it is better to add
> > explicit checks for the AV_DMA stuff.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > --- a/drivers/media/platform/exynos4-is/common.c
> > +++ b/drivers/media/platform/exynos4-is/common.c
> > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> >  		/* source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > index 0627a93b2f3b..e9810fee4c30 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> >  			}
> >  		}
> >  
> > -		if (src_pad == NULL ||
> > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> >  			break;
> >  
> >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> >  	struct v4l2_subdev *sensor;
> >  
> > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> >  		return -EINVAL;
> >  
> >  	if (WARN_ON(fimc == NULL))
> > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> >  
> >  		/* Retrieve format at the source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > index b2607da4ad14..c2327147b360 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> >  		}
> >  		/* Retrieve format at the source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  {
> >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> >  	int ret = 0;
> >  
> >  	if (WARN_ON(fimc == NULL))
> > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  
> >  	switch (local->index) {
> >  	case FLITE_SD_PAD_SINK:
> > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> >  			ret = -EINVAL;
> >  			break;
> >  		}
> > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  	case FLITE_SD_PAD_SOURCE_DMA:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> > +		else if (is_media_entity_v4l2_io(remote->entity))
> >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> >  		else
> >  			ret = -EINVAL;
> > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> >  	case FLITE_SD_PAD_SOURCE_ISP:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> >  		else
> >  			ret = -EINVAL;
> > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > index 92dbade2fffc..4a25df9dd869 100644
> > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> >  				break;
> >  		}
> >  
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> >  
> > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> >  
> >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> >  	media_entity_graph_walk_start(&graph, entity_err);
> >  
> >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity_err))
> >  			continue;
> >  
> >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > index 69e7733d36cd..cb8ac90086c1 100644
> > --- a/drivers/media/platform/omap3isp/isp.c
> > +++ b/drivers/media/platform/omap3isp/isp.c
> > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_io(entity))
> >  			use += entity->use_count;
> >  	}
> >  
> > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> >  	struct v4l2_subdev *subdev;
> >  	int ret;
> >  
> > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > +	subdev = is_media_entity_v4l2_subdev(entity)
> >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> >  
> >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(entity))
> >  			ret = isp_pipeline_pm_power_one(entity, change);
> >  
> >  	if (!ret)
> > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> >  
> >  	while ((first = media_entity_graph_walk_next(&graph))
> >  	       && first != entity)
> > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(first))
> >  			isp_pipeline_pm_power_one(first, -change);
> >  
> >  	return ret;
> > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > index 4c367352b1f7..52843ac2a9ca 100644
> > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> >  
> >  	remote = media_entity_remote_pad(&video->pad);
> >  
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> >  		if (entity == &video->video.entity)
> >  			continue;
> >  
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> >  
> >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> >  		return -EINVAL;
> >  	}
> >  
> > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!is_media_entity_v4l2_subdev(source))
> >  		return 0;
> >  
> >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > index eae667eab1b9..fb5b016cc0a1 100644
> > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> >  
> >  	/* Retrieve format at the sensor subdev source pad */
> >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  		return -EPIPE;
> >  
> >  	src_fmt.pad = pad->index;
> > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > index 1f94c1a54e00..f74158224b93 100644
> > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> >  	struct media_pad *remote;
> >  
> >  	remote = media_entity_remote_pad(local);
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> >  			return -EPIPE;
> >  
> >  		/* We've reached a video node, that shouldn't have happened. */
> > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> >  			return -EPIPE;
> >  
> >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> >  		struct vsp1_rwpf *rwpf;
> >  		struct vsp1_entity *e;
> >  
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > +		if (is_media_entity_v4l2_io(entity)) {
> >  			pipe->num_video++;
> >  			continue;
> >  		}
> > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> >  
> >  	while (pad) {
> > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > index 88cd789cdaf7..8e14841bf445 100644
> > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> >  	struct media_pad *remote;
> >  
> >  	remote = media_entity_remote_pad(local);
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > index e6e1115d8215..60da43772de9 100644
> > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > @@ -526,7 +526,7 @@ static int
> >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> >  				     struct v4l2_subdev_format *fmt)
> >  {
> > -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> >  		struct v4l2_subdev *sd =
> >  			media_entity_to_v4l2_subdev(pad->entity);
> >  
> > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > index 92573fa852a9..16763e0831f2 100644
> > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> >  		if (entity == &video->video_dev.entity)
> >  			continue;
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if ((!is_media_entity_v4l2_io(remote->entity))
> >  			continue;
> >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> >  
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if !is_media_entity_v4l2_subdev(entity))
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> >  
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_subdev(entity))
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > index 40591963b42b..44b88ff3ba83 100644
> > --- a/drivers/staging/media/omap4iss/iss.c
> > +++ b/drivers/staging/media/omap4iss/iss.c
> > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_io(entity))
> >  			use += entity->use_count;
> >  	}
> >  
> > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> >  {
> >  	struct v4l2_subdev *subdev;
> >  
> > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > +	subdev = is_media_entity_v4l2_subdev(entity)
> >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> >  
> >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> >  	media_entity_graph_walk_start(&graph, entity);
> >  
> >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(entity))
> >  			ret = iss_pipeline_pm_power_one(entity, change);
> >  
> >  	if (!ret)
> > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> >  
> >  	while ((first = media_entity_graph_walk_next(&graph))
> >  	       && first != entity)
> > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(first))
> >  			iss_pipeline_pm_power_one(first, -change);
> >  
> >  	return ret;
> > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> >  			break;
> >  
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  
> >  		entity = pad->entity;
> > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > index 45a3f2d778fc..cbe5783735dc 100644
> > --- a/drivers/staging/media/omap4iss/iss_video.c
> > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> >  
> >  	remote = media_entity_remote_pad(&video->pad);
> >  
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  
> >  	if (pad)
> > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> >  		if (entity == &video->video.entity)
> >  			continue;
> >  
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> >  
> >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> 
> I finally got around to test these patches eventually, and after some
> debugging found this one. I think it's a good idea to have macros to
> determine whether an entity exposes a V4L2 sub-device interface but it
> should be more robust than is_media_entity_v4l2_subdev() right now is.

Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
actually a separate graph object (interfaces). Those macros work at the
entities, not at the interface objects.

> Incorrect result can have consequences from a pipeline start failure (due to
> a failure in link validation) to memory corruption as struct media_entity
> pointer is assumed to be a pointer to a field of another struct.

Yes, an incorrect result would cause pipeline failures.

> How about assigning that in V4L2 sub-device / video device registration,
> for example?

What do you mean? Could you give an example to make it clearer?

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
  2015-10-12  0:56       ` Mauro Carvalho Chehab
  (?)
  (?)
@ 2015-10-12 15:35         ` Sakari Ailus
  -1 siblings, 0 replies; 309+ messages in thread
From: Sakari Ailus @ 2015-10-12 15:35 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Mauro,

On Sun, Oct 11, 2015 at 09:56:25PM -0300, Mauro Carvalho Chehab wrote:
> Em Mon, 12 Oct 2015 00:07:52 +0300
> Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> 
> > Hi Mauro,
> > 
> > On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > > Instead of relying on media subtype, use the new macros to detect
> > > if an entity is a subdev or an A/V DMA entity.
> > > 
> > > Please note that most drivers assume that there's just AV_DMA or
> > > V4L2 subdevs. This is not true anymore, as we've added MC support
> > > for DVB, and there are plans to add support for ALSA and FB/DRM
> > > too.
> > > 
> > > Ok, on the current pipelines supported by those drivers, just V4L
> > > stuff are there, but, assuming that some day a pipeline that also
> > > works with other subsystems will ever added, it is better to add
> > > explicit checks for the AV_DMA stuff.
> > > 
> > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > 
> > > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > > --- a/drivers/media/platform/exynos4-is/common.c
> > > +++ b/drivers/media/platform/exynos4-is/common.c
> > > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> > >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> > >  		/* source pad */
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad = NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > index 0627a93b2f3b..e9810fee4c30 100644
> > > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> > >  			}
> > >  		}
> > >  
> > > -		if (src_pad = NULL ||
> > > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> > >  			break;
> > >  
> > >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> > >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> > >  	struct v4l2_subdev *sensor;
> > >  
> > > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> > >  		return -EINVAL;
> > >  
> > >  	if (WARN_ON(fimc = NULL))
> > > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> > >  
> > >  		/* Retrieve format at the source pad */
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad = NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > index b2607da4ad14..c2327147b360 100644
> > > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> > >  		}
> > >  		/* Retrieve format at the source pad */
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad = NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  {
> > >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> > >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> > >  	int ret = 0;
> > >  
> > >  	if (WARN_ON(fimc = NULL))
> > > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  
> > >  	switch (local->index) {
> > >  	case FLITE_SD_PAD_SINK:
> > > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> > >  			ret = -EINVAL;
> > >  			break;
> > >  		}
> > > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  	case FLITE_SD_PAD_SOURCE_DMA:
> > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > -		else if (remote_ent_type = MEDIA_ENT_T_DEVNODE)
> > > +		else if (is_media_entity_v4l2_io(remote->entity))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> > >  		else
> > >  			ret = -EINVAL;
> > > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  	case FLITE_SD_PAD_SOURCE_ISP:
> > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > -		else if (remote_ent_type = MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> > >  		else
> > >  			ret = -EINVAL;
> > > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > > index 92dbade2fffc..4a25df9dd869 100644
> > > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> > >  				break;
> > >  		}
> > >  
> > > -		if (pad = NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > >  
> > > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity))
> > >  			continue;
> > >  
> > >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > >  	media_entity_graph_walk_start(&graph, entity_err);
> > >  
> > >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity_err))
> > >  			continue;
> > >  
> > >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > > index 69e7733d36cd..cb8ac90086c1 100644
> > > --- a/drivers/media/platform/omap3isp/isp.c
> > > +++ b/drivers/media/platform/omap3isp/isp.c
> > > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_io(entity))
> > >  			use += entity->use_count;
> > >  	}
> > >  
> > > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> > >  	struct v4l2_subdev *subdev;
> > >  	int ret;
> > >  
> > > -	subdev = media_entity_type(entity) = MEDIA_ENT_T_V4L2_SUBDEV
> > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > >  
> > >  	if (entity->use_count = 0 && change > 0 && subdev != NULL) {
> > > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(entity))
> > >  			ret = isp_pipeline_pm_power_one(entity, change);
> > >  
> > >  	if (!ret)
> > > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > >  
> > >  	while ((first = media_entity_graph_walk_next(&graph))
> > >  	       && first != entity)
> > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(first))
> > >  			isp_pipeline_pm_power_one(first, -change);
> > >  
> > >  	return ret;
> > > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad = NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad = NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > > index 4c367352b1f7..52843ac2a9ca 100644
> > > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> > >  
> > >  	remote = media_entity_remote_pad(&video->pad);
> > >  
> > > -	if (remote = NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> > >  		if (entity = &video->video.entity)
> > >  			continue;
> > >  
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity))
> > >  			continue;
> > >  
> > >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> > >  		return -EINVAL;
> > >  	}
> > >  
> > > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!is_media_entity_v4l2_subdev(source))
> > >  		return 0;
> > >  
> > >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > > index eae667eab1b9..fb5b016cc0a1 100644
> > > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> > >  
> > >  	/* Retrieve format at the sensor subdev source pad */
> > >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  		return -EPIPE;
> > >  
> > >  	src_fmt.pad = pad->index;
> > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > > index 1f94c1a54e00..f74158224b93 100644
> > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> > >  	struct media_pad *remote;
> > >  
> > >  	remote = media_entity_remote_pad(local);
> > > -	if (remote = NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> > >  			return -EPIPE;
> > >  
> > >  		/* We've reached a video node, that shouldn't have happened. */
> > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > >  			return -EPIPE;
> > >  
> > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> > >  		struct vsp1_rwpf *rwpf;
> > >  		struct vsp1_entity *e;
> > >  
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > +		if (is_media_entity_v4l2_io(entity)) {
> > >  			pipe->num_video++;
> > >  			continue;
> > >  		}
> > > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> > >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> > >  
> > >  	while (pad) {
> > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > > index 88cd789cdaf7..8e14841bf445 100644
> > > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> > >  	struct media_pad *remote;
> > >  
> > >  	remote = media_entity_remote_pad(local);
> > > -	if (remote = NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad = NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > > index e6e1115d8215..60da43772de9 100644
> > > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > > @@ -526,7 +526,7 @@ static int
> > >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> > >  				     struct v4l2_subdev_format *fmt)
> > >  {
> > > -	if (media_entity_type(pad->entity) = MEDIA_ENT_T_V4L2_SUBDEV) {
> > > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> > >  		struct v4l2_subdev *sd > > >  			media_entity_to_v4l2_subdev(pad->entity);
> > >  
> > > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > index 92573fa852a9..16763e0831f2 100644
> > > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > >  		if (entity = &video->video_dev.entity)
> > >  			continue;
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if ((!is_media_entity_v4l2_io(remote->entity))
> > >  			continue;
> > >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> > >  		if (far_end->type = V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > >  
> > > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > > +		if !is_media_entity_v4l2_subdev(entity))
> > >  			continue;
> > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > >  
> > > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_subdev(entity))
> > >  			continue;
> > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > > index 40591963b42b..44b88ff3ba83 100644
> > > --- a/drivers/staging/media/omap4iss/iss.c
> > > +++ b/drivers/staging/media/omap4iss/iss.c
> > > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_io(entity))
> > >  			use += entity->use_count;
> > >  	}
> > >  
> > > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> > >  {
> > >  	struct v4l2_subdev *subdev;
> > >  
> > > -	subdev = media_entity_type(entity) = MEDIA_ENT_T_V4L2_SUBDEV
> > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > >  
> > >  	if (entity->use_count = 0 && change > 0 && subdev != NULL) {
> > > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(entity))
> > >  			ret = iss_pipeline_pm_power_one(entity, change);
> > >  
> > >  	if (!ret)
> > > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > >  
> > >  	while ((first = media_entity_graph_walk_next(&graph))
> > >  	       && first != entity)
> > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(first))
> > >  			iss_pipeline_pm_power_one(first, -change);
> > >  
> > >  	return ret;
> > > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad = NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad = NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > > index 45a3f2d778fc..cbe5783735dc 100644
> > > --- a/drivers/staging/media/omap4iss/iss_video.c
> > > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> > >  
> > >  	remote = media_entity_remote_pad(&video->pad);
> > >  
> > > -	if (remote = NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> > >  		if (entity = &video->video.entity)
> > >  			continue;
> > >  
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity))
> > >  			continue;
> > >  
> > >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> > 
> > I finally got around to test these patches eventually, and after some
> > debugging found this one. I think it's a good idea to have macros to
> > determine whether an entity exposes a V4L2 sub-device interface but it
> > should be more robust than is_media_entity_v4l2_subdev() right now is.
> 
> Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
> actually a separate graph object (interfaces). Those macros work at the
> entities, not at the interface objects.

is_media_entity_v4l2_subdev() will produce wrong results for a large part of
V4L2 sub-devices with these patches applied.

I checked again the original implementation, and it seems to be based only
on the type as well, albeit that's a range, not a set of different
functions.

I suppose this will change at some point in the future: the interface indeed
should not be determined by the function of the entity. At least it needs to
be fixed now until the rework. I'll submit a patch for that.

-- 
Regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-10-12 15:35         ` Sakari Ailus
  0 siblings, 0 replies; 309+ messages in thread
From: Sakari Ailus @ 2015-10-12 15:35 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Kukjin Kim, Krzysztof Kozlowski,
	Laurent Pinchart, Hyun Kwon, Michal Simek, Sören Brinkmann,
	Greg Kroah-Hartman, Hans Verkuil, Prabhakar Lad,
	Lars-Peter Clausen, Markus Elfring, Sakari Ailus,
	Javier Martinez Canillas, linux-arm-kernel, linux-samsung-soc,
	linux-sh, devel

Hi Mauro,

On Sun, Oct 11, 2015 at 09:56:25PM -0300, Mauro Carvalho Chehab wrote:
> Em Mon, 12 Oct 2015 00:07:52 +0300
> Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> 
> > Hi Mauro,
> > 
> > On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > > Instead of relying on media subtype, use the new macros to detect
> > > if an entity is a subdev or an A/V DMA entity.
> > > 
> > > Please note that most drivers assume that there's just AV_DMA or
> > > V4L2 subdevs. This is not true anymore, as we've added MC support
> > > for DVB, and there are plans to add support for ALSA and FB/DRM
> > > too.
> > > 
> > > Ok, on the current pipelines supported by those drivers, just V4L
> > > stuff are there, but, assuming that some day a pipeline that also
> > > works with other subsystems will ever added, it is better to add
> > > explicit checks for the AV_DMA stuff.
> > > 
> > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > 
> > > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > > --- a/drivers/media/platform/exynos4-is/common.c
> > > +++ b/drivers/media/platform/exynos4-is/common.c
> > > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> > >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> > >  		/* source pad */
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > index 0627a93b2f3b..e9810fee4c30 100644
> > > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> > >  			}
> > >  		}
> > >  
> > > -		if (src_pad == NULL ||
> > > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> > >  			break;
> > >  
> > >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> > >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> > >  	struct v4l2_subdev *sensor;
> > >  
> > > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> > >  		return -EINVAL;
> > >  
> > >  	if (WARN_ON(fimc == NULL))
> > > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> > >  
> > >  		/* Retrieve format at the source pad */
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > index b2607da4ad14..c2327147b360 100644
> > > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> > >  		}
> > >  		/* Retrieve format at the source pad */
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  {
> > >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> > >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> > >  	int ret = 0;
> > >  
> > >  	if (WARN_ON(fimc == NULL))
> > > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  
> > >  	switch (local->index) {
> > >  	case FLITE_SD_PAD_SINK:
> > > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> > >  			ret = -EINVAL;
> > >  			break;
> > >  		}
> > > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  	case FLITE_SD_PAD_SOURCE_DMA:
> > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> > > +		else if (is_media_entity_v4l2_io(remote->entity))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> > >  		else
> > >  			ret = -EINVAL;
> > > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  	case FLITE_SD_PAD_SOURCE_ISP:
> > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> > >  		else
> > >  			ret = -EINVAL;
> > > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > > index 92dbade2fffc..4a25df9dd869 100644
> > > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> > >  				break;
> > >  		}
> > >  
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > >  
> > > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity))
> > >  			continue;
> > >  
> > >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > >  	media_entity_graph_walk_start(&graph, entity_err);
> > >  
> > >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity_err))
> > >  			continue;
> > >  
> > >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > > index 69e7733d36cd..cb8ac90086c1 100644
> > > --- a/drivers/media/platform/omap3isp/isp.c
> > > +++ b/drivers/media/platform/omap3isp/isp.c
> > > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_io(entity))
> > >  			use += entity->use_count;
> > >  	}
> > >  
> > > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> > >  	struct v4l2_subdev *subdev;
> > >  	int ret;
> > >  
> > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > >  
> > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(entity))
> > >  			ret = isp_pipeline_pm_power_one(entity, change);
> > >  
> > >  	if (!ret)
> > > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > >  
> > >  	while ((first = media_entity_graph_walk_next(&graph))
> > >  	       && first != entity)
> > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(first))
> > >  			isp_pipeline_pm_power_one(first, -change);
> > >  
> > >  	return ret;
> > > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > > index 4c367352b1f7..52843ac2a9ca 100644
> > > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> > >  
> > >  	remote = media_entity_remote_pad(&video->pad);
> > >  
> > > -	if (remote == NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> > >  		if (entity == &video->video.entity)
> > >  			continue;
> > >  
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity))
> > >  			continue;
> > >  
> > >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> > >  		return -EINVAL;
> > >  	}
> > >  
> > > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!is_media_entity_v4l2_subdev(source))
> > >  		return 0;
> > >  
> > >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > > index eae667eab1b9..fb5b016cc0a1 100644
> > > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> > >  
> > >  	/* Retrieve format at the sensor subdev source pad */
> > >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  		return -EPIPE;
> > >  
> > >  	src_fmt.pad = pad->index;
> > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > > index 1f94c1a54e00..f74158224b93 100644
> > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> > >  	struct media_pad *remote;
> > >  
> > >  	remote = media_entity_remote_pad(local);
> > > -	if (remote == NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> > >  			return -EPIPE;
> > >  
> > >  		/* We've reached a video node, that shouldn't have happened. */
> > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > >  			return -EPIPE;
> > >  
> > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> > >  		struct vsp1_rwpf *rwpf;
> > >  		struct vsp1_entity *e;
> > >  
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > +		if (is_media_entity_v4l2_io(entity)) {
> > >  			pipe->num_video++;
> > >  			continue;
> > >  		}
> > > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> > >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> > >  
> > >  	while (pad) {
> > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > > index 88cd789cdaf7..8e14841bf445 100644
> > > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> > >  	struct media_pad *remote;
> > >  
> > >  	remote = media_entity_remote_pad(local);
> > > -	if (remote == NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > > index e6e1115d8215..60da43772de9 100644
> > > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > > @@ -526,7 +526,7 @@ static int
> > >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> > >  				     struct v4l2_subdev_format *fmt)
> > >  {
> > > -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> > > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> > >  		struct v4l2_subdev *sd =
> > >  			media_entity_to_v4l2_subdev(pad->entity);
> > >  
> > > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > index 92573fa852a9..16763e0831f2 100644
> > > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > >  		if (entity == &video->video_dev.entity)
> > >  			continue;
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if ((!is_media_entity_v4l2_io(remote->entity))
> > >  			continue;
> > >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> > >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > >  
> > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > +		if !is_media_entity_v4l2_subdev(entity))
> > >  			continue;
> > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > >  
> > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_subdev(entity))
> > >  			continue;
> > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > > index 40591963b42b..44b88ff3ba83 100644
> > > --- a/drivers/staging/media/omap4iss/iss.c
> > > +++ b/drivers/staging/media/omap4iss/iss.c
> > > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_io(entity))
> > >  			use += entity->use_count;
> > >  	}
> > >  
> > > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> > >  {
> > >  	struct v4l2_subdev *subdev;
> > >  
> > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > >  
> > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(entity))
> > >  			ret = iss_pipeline_pm_power_one(entity, change);
> > >  
> > >  	if (!ret)
> > > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > >  
> > >  	while ((first = media_entity_graph_walk_next(&graph))
> > >  	       && first != entity)
> > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(first))
> > >  			iss_pipeline_pm_power_one(first, -change);
> > >  
> > >  	return ret;
> > > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > > index 45a3f2d778fc..cbe5783735dc 100644
> > > --- a/drivers/staging/media/omap4iss/iss_video.c
> > > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> > >  
> > >  	remote = media_entity_remote_pad(&video->pad);
> > >  
> > > -	if (remote == NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> > >  		if (entity == &video->video.entity)
> > >  			continue;
> > >  
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity))
> > >  			continue;
> > >  
> > >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> > 
> > I finally got around to test these patches eventually, and after some
> > debugging found this one. I think it's a good idea to have macros to
> > determine whether an entity exposes a V4L2 sub-device interface but it
> > should be more robust than is_media_entity_v4l2_subdev() right now is.
> 
> Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
> actually a separate graph object (interfaces). Those macros work at the
> entities, not at the interface objects.

is_media_entity_v4l2_subdev() will produce wrong results for a large part of
V4L2 sub-devices with these patches applied.

I checked again the original implementation, and it seems to be based only
on the type as well, albeit that's a range, not a set of different
functions.

I suppose this will change at some point in the future: the interface indeed
should not be determined by the function of the entity. At least it needs to
be fixed now until the rework. I'll submit a patch for that.

-- 
Regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-10-12 15:35         ` Sakari Ailus
  0 siblings, 0 replies; 309+ messages in thread
From: Sakari Ailus @ 2015-10-12 15:35 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Kukjin Kim, Krzysztof Kozlowski,
	Laurent Pinchart, Hyun Kwon, Michal Simek, Sören Brinkmann,
	Greg Kroah-Hartman, Hans Verkuil, Prabhakar Lad,
	Lars-Peter Clausen, Markus Elfring, Sakari Ailus,
	Javier Martinez Canillas, linux-arm-kernel, linux-samsung-soc,
	linux-sh

Hi Mauro,

On Sun, Oct 11, 2015 at 09:56:25PM -0300, Mauro Carvalho Chehab wrote:
> Em Mon, 12 Oct 2015 00:07:52 +0300
> Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> 
> > Hi Mauro,
> > 
> > On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > > Instead of relying on media subtype, use the new macros to detect
> > > if an entity is a subdev or an A/V DMA entity.
> > > 
> > > Please note that most drivers assume that there's just AV_DMA or
> > > V4L2 subdevs. This is not true anymore, as we've added MC support
> > > for DVB, and there are plans to add support for ALSA and FB/DRM
> > > too.
> > > 
> > > Ok, on the current pipelines supported by those drivers, just V4L
> > > stuff are there, but, assuming that some day a pipeline that also
> > > works with other subsystems will ever added, it is better to add
> > > explicit checks for the AV_DMA stuff.
> > > 
> > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > 
> > > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > > --- a/drivers/media/platform/exynos4-is/common.c
> > > +++ b/drivers/media/platform/exynos4-is/common.c
> > > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> > >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> > >  		/* source pad */
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > index 0627a93b2f3b..e9810fee4c30 100644
> > > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> > >  			}
> > >  		}
> > >  
> > > -		if (src_pad == NULL ||
> > > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> > >  			break;
> > >  
> > >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> > >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> > >  	struct v4l2_subdev *sensor;
> > >  
> > > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> > >  		return -EINVAL;
> > >  
> > >  	if (WARN_ON(fimc == NULL))
> > > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> > >  
> > >  		/* Retrieve format at the source pad */
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > index b2607da4ad14..c2327147b360 100644
> > > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> > >  		}
> > >  		/* Retrieve format at the source pad */
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  {
> > >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> > >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> > >  	int ret = 0;
> > >  
> > >  	if (WARN_ON(fimc == NULL))
> > > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  
> > >  	switch (local->index) {
> > >  	case FLITE_SD_PAD_SINK:
> > > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> > >  			ret = -EINVAL;
> > >  			break;
> > >  		}
> > > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  	case FLITE_SD_PAD_SOURCE_DMA:
> > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> > > +		else if (is_media_entity_v4l2_io(remote->entity))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> > >  		else
> > >  			ret = -EINVAL;
> > > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  	case FLITE_SD_PAD_SOURCE_ISP:
> > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> > >  		else
> > >  			ret = -EINVAL;
> > > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > > index 92dbade2fffc..4a25df9dd869 100644
> > > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> > >  				break;
> > >  		}
> > >  
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > >  
> > > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity))
> > >  			continue;
> > >  
> > >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > >  	media_entity_graph_walk_start(&graph, entity_err);
> > >  
> > >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity_err))
> > >  			continue;
> > >  
> > >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > > index 69e7733d36cd..cb8ac90086c1 100644
> > > --- a/drivers/media/platform/omap3isp/isp.c
> > > +++ b/drivers/media/platform/omap3isp/isp.c
> > > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_io(entity))
> > >  			use += entity->use_count;
> > >  	}
> > >  
> > > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> > >  	struct v4l2_subdev *subdev;
> > >  	int ret;
> > >  
> > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > >  
> > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(entity))
> > >  			ret = isp_pipeline_pm_power_one(entity, change);
> > >  
> > >  	if (!ret)
> > > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > >  
> > >  	while ((first = media_entity_graph_walk_next(&graph))
> > >  	       && first != entity)
> > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(first))
> > >  			isp_pipeline_pm_power_one(first, -change);
> > >  
> > >  	return ret;
> > > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > > index 4c367352b1f7..52843ac2a9ca 100644
> > > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> > >  
> > >  	remote = media_entity_remote_pad(&video->pad);
> > >  
> > > -	if (remote == NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> > >  		if (entity == &video->video.entity)
> > >  			continue;
> > >  
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity))
> > >  			continue;
> > >  
> > >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> > >  		return -EINVAL;
> > >  	}
> > >  
> > > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!is_media_entity_v4l2_subdev(source))
> > >  		return 0;
> > >  
> > >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > > index eae667eab1b9..fb5b016cc0a1 100644
> > > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> > >  
> > >  	/* Retrieve format at the sensor subdev source pad */
> > >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  		return -EPIPE;
> > >  
> > >  	src_fmt.pad = pad->index;
> > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > > index 1f94c1a54e00..f74158224b93 100644
> > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> > >  	struct media_pad *remote;
> > >  
> > >  	remote = media_entity_remote_pad(local);
> > > -	if (remote == NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> > >  			return -EPIPE;
> > >  
> > >  		/* We've reached a video node, that shouldn't have happened. */
> > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > >  			return -EPIPE;
> > >  
> > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> > >  		struct vsp1_rwpf *rwpf;
> > >  		struct vsp1_entity *e;
> > >  
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > +		if (is_media_entity_v4l2_io(entity)) {
> > >  			pipe->num_video++;
> > >  			continue;
> > >  		}
> > > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> > >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> > >  
> > >  	while (pad) {
> > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > > index 88cd789cdaf7..8e14841bf445 100644
> > > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> > >  	struct media_pad *remote;
> > >  
> > >  	remote = media_entity_remote_pad(local);
> > > -	if (remote == NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > > index e6e1115d8215..60da43772de9 100644
> > > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > > @@ -526,7 +526,7 @@ static int
> > >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> > >  				     struct v4l2_subdev_format *fmt)
> > >  {
> > > -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> > > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> > >  		struct v4l2_subdev *sd =
> > >  			media_entity_to_v4l2_subdev(pad->entity);
> > >  
> > > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > index 92573fa852a9..16763e0831f2 100644
> > > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > >  		if (entity == &video->video_dev.entity)
> > >  			continue;
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if ((!is_media_entity_v4l2_io(remote->entity))
> > >  			continue;
> > >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> > >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > >  
> > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > +		if !is_media_entity_v4l2_subdev(entity))
> > >  			continue;
> > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > >  
> > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_subdev(entity))
> > >  			continue;
> > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > > index 40591963b42b..44b88ff3ba83 100644
> > > --- a/drivers/staging/media/omap4iss/iss.c
> > > +++ b/drivers/staging/media/omap4iss/iss.c
> > > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_io(entity))
> > >  			use += entity->use_count;
> > >  	}
> > >  
> > > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> > >  {
> > >  	struct v4l2_subdev *subdev;
> > >  
> > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > >  
> > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(entity))
> > >  			ret = iss_pipeline_pm_power_one(entity, change);
> > >  
> > >  	if (!ret)
> > > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > >  
> > >  	while ((first = media_entity_graph_walk_next(&graph))
> > >  	       && first != entity)
> > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(first))
> > >  			iss_pipeline_pm_power_one(first, -change);
> > >  
> > >  	return ret;
> > > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > > index 45a3f2d778fc..cbe5783735dc 100644
> > > --- a/drivers/staging/media/omap4iss/iss_video.c
> > > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> > >  
> > >  	remote = media_entity_remote_pad(&video->pad);
> > >  
> > > -	if (remote == NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> > >  		if (entity == &video->video.entity)
> > >  			continue;
> > >  
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity))
> > >  			continue;
> > >  
> > >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> > 
> > I finally got around to test these patches eventually, and after some
> > debugging found this one. I think it's a good idea to have macros to
> > determine whether an entity exposes a V4L2 sub-device interface but it
> > should be more robust than is_media_entity_v4l2_subdev() right now is.
> 
> Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
> actually a separate graph object (interfaces). Those macros work at the
> entities, not at the interface objects.

is_media_entity_v4l2_subdev() will produce wrong results for a large part of
V4L2 sub-devices with these patches applied.

I checked again the original implementation, and it seems to be based only
on the type as well, albeit that's a range, not a set of different
functions.

I suppose this will change at some point in the future: the interface indeed
should not be determined by the function of the entity. At least it needs to
be fixed now until the rework. I'll submit a patch for that.

-- 
Regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-10-12 15:35         ` Sakari Ailus
  0 siblings, 0 replies; 309+ messages in thread
From: Sakari Ailus @ 2015-10-12 15:35 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Mauro,

On Sun, Oct 11, 2015 at 09:56:25PM -0300, Mauro Carvalho Chehab wrote:
> Em Mon, 12 Oct 2015 00:07:52 +0300
> Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> 
> > Hi Mauro,
> > 
> > On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > > Instead of relying on media subtype, use the new macros to detect
> > > if an entity is a subdev or an A/V DMA entity.
> > > 
> > > Please note that most drivers assume that there's just AV_DMA or
> > > V4L2 subdevs. This is not true anymore, as we've added MC support
> > > for DVB, and there are plans to add support for ALSA and FB/DRM
> > > too.
> > > 
> > > Ok, on the current pipelines supported by those drivers, just V4L
> > > stuff are there, but, assuming that some day a pipeline that also
> > > works with other subsystems will ever added, it is better to add
> > > explicit checks for the AV_DMA stuff.
> > > 
> > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > 
> > > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > > --- a/drivers/media/platform/exynos4-is/common.c
> > > +++ b/drivers/media/platform/exynos4-is/common.c
> > > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> > >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> > >  		/* source pad */
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > index 0627a93b2f3b..e9810fee4c30 100644
> > > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> > >  			}
> > >  		}
> > >  
> > > -		if (src_pad == NULL ||
> > > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> > >  			break;
> > >  
> > >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> > >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> > >  	struct v4l2_subdev *sensor;
> > >  
> > > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> > >  		return -EINVAL;
> > >  
> > >  	if (WARN_ON(fimc == NULL))
> > > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> > >  
> > >  		/* Retrieve format at the source pad */
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > index b2607da4ad14..c2327147b360 100644
> > > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> > >  		}
> > >  		/* Retrieve format at the source pad */
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  {
> > >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> > >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> > >  	int ret = 0;
> > >  
> > >  	if (WARN_ON(fimc == NULL))
> > > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  
> > >  	switch (local->index) {
> > >  	case FLITE_SD_PAD_SINK:
> > > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> > >  			ret = -EINVAL;
> > >  			break;
> > >  		}
> > > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  	case FLITE_SD_PAD_SOURCE_DMA:
> > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> > > +		else if (is_media_entity_v4l2_io(remote->entity))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> > >  		else
> > >  			ret = -EINVAL;
> > > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > >  	case FLITE_SD_PAD_SOURCE_ISP:
> > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> > >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> > >  		else
> > >  			ret = -EINVAL;
> > > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > > index 92dbade2fffc..4a25df9dd869 100644
> > > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> > >  				break;
> > >  		}
> > >  
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > >  
> > > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity))
> > >  			continue;
> > >  
> > >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > >  	media_entity_graph_walk_start(&graph, entity_err);
> > >  
> > >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity_err))
> > >  			continue;
> > >  
> > >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > > index 69e7733d36cd..cb8ac90086c1 100644
> > > --- a/drivers/media/platform/omap3isp/isp.c
> > > +++ b/drivers/media/platform/omap3isp/isp.c
> > > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_io(entity))
> > >  			use += entity->use_count;
> > >  	}
> > >  
> > > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> > >  	struct v4l2_subdev *subdev;
> > >  	int ret;
> > >  
> > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > >  
> > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(entity))
> > >  			ret = isp_pipeline_pm_power_one(entity, change);
> > >  
> > >  	if (!ret)
> > > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > >  
> > >  	while ((first = media_entity_graph_walk_next(&graph))
> > >  	       && first != entity)
> > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(first))
> > >  			isp_pipeline_pm_power_one(first, -change);
> > >  
> > >  	return ret;
> > > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > > index 4c367352b1f7..52843ac2a9ca 100644
> > > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> > >  
> > >  	remote = media_entity_remote_pad(&video->pad);
> > >  
> > > -	if (remote == NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> > >  		if (entity == &video->video.entity)
> > >  			continue;
> > >  
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity))
> > >  			continue;
> > >  
> > >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> > >  		return -EINVAL;
> > >  	}
> > >  
> > > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!is_media_entity_v4l2_subdev(source))
> > >  		return 0;
> > >  
> > >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > > index eae667eab1b9..fb5b016cc0a1 100644
> > > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> > >  
> > >  	/* Retrieve format at the sensor subdev source pad */
> > >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  		return -EPIPE;
> > >  
> > >  	src_fmt.pad = pad->index;
> > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > > index 1f94c1a54e00..f74158224b93 100644
> > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> > >  	struct media_pad *remote;
> > >  
> > >  	remote = media_entity_remote_pad(local);
> > > -	if (remote == NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> > >  			return -EPIPE;
> > >  
> > >  		/* We've reached a video node, that shouldn't have happened. */
> > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > >  			return -EPIPE;
> > >  
> > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> > >  		struct vsp1_rwpf *rwpf;
> > >  		struct vsp1_entity *e;
> > >  
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > +		if (is_media_entity_v4l2_io(entity)) {
> > >  			pipe->num_video++;
> > >  			continue;
> > >  		}
> > > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> > >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> > >  
> > >  	while (pad) {
> > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > > index 88cd789cdaf7..8e14841bf445 100644
> > > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> > >  	struct media_pad *remote;
> > >  
> > >  	remote = media_entity_remote_pad(local);
> > > -	if (remote == NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > > index e6e1115d8215..60da43772de9 100644
> > > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > > @@ -526,7 +526,7 @@ static int
> > >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> > >  				     struct v4l2_subdev_format *fmt)
> > >  {
> > > -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> > > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> > >  		struct v4l2_subdev *sd =
> > >  			media_entity_to_v4l2_subdev(pad->entity);
> > >  
> > > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > index 92573fa852a9..16763e0831f2 100644
> > > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > >  		if (entity == &video->video_dev.entity)
> > >  			continue;
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if ((!is_media_entity_v4l2_io(remote->entity))
> > >  			continue;
> > >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> > >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > >  
> > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > +		if !is_media_entity_v4l2_subdev(entity))
> > >  			continue;
> > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > >  
> > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_subdev(entity))
> > >  			continue;
> > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > > index 40591963b42b..44b88ff3ba83 100644
> > > --- a/drivers/staging/media/omap4iss/iss.c
> > > +++ b/drivers/staging/media/omap4iss/iss.c
> > > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_io(entity))
> > >  			use += entity->use_count;
> > >  	}
> > >  
> > > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> > >  {
> > >  	struct v4l2_subdev *subdev;
> > >  
> > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > >  
> > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > >  	media_entity_graph_walk_start(&graph, entity);
> > >  
> > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(entity))
> > >  			ret = iss_pipeline_pm_power_one(entity, change);
> > >  
> > >  	if (!ret)
> > > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > >  
> > >  	while ((first = media_entity_graph_walk_next(&graph))
> > >  	       && first != entity)
> > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > +		if (is_media_entity_v4l2_subdev(first))
> > >  			iss_pipeline_pm_power_one(first, -change);
> > >  
> > >  	return ret;
> > > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> > >  			break;
> > >  
> > >  		pad = media_entity_remote_pad(pad);
> > > -		if (pad == NULL ||
> > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > >  			break;
> > >  
> > >  		entity = pad->entity;
> > > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > > index 45a3f2d778fc..cbe5783735dc 100644
> > > --- a/drivers/staging/media/omap4iss/iss_video.c
> > > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> > >  
> > >  	remote = media_entity_remote_pad(&video->pad);
> > >  
> > > -	if (remote == NULL ||
> > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > >  		return NULL;
> > >  
> > >  	if (pad)
> > > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> > >  		if (entity == &video->video.entity)
> > >  			continue;
> > >  
> > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > +		if (!is_media_entity_v4l2_io(entity))
> > >  			continue;
> > >  
> > >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> > 
> > I finally got around to test these patches eventually, and after some
> > debugging found this one. I think it's a good idea to have macros to
> > determine whether an entity exposes a V4L2 sub-device interface but it
> > should be more robust than is_media_entity_v4l2_subdev() right now is.
> 
> Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
> actually a separate graph object (interfaces). Those macros work at the
> entities, not at the interface objects.

is_media_entity_v4l2_subdev() will produce wrong results for a large part of
V4L2 sub-devices with these patches applied.

I checked again the original implementation, and it seems to be based only
on the type as well, albeit that's a range, not a set of different
functions.

I suppose this will change at some point in the future: the interface indeed
should not be determined by the function of the entity. At least it needs to
be fixed now until the rework. I'll submit a patch for that.

-- 
Regards,

Sakari Ailus
e-mail: sakari.ailus at iki.fi	XMPP: sailus at retiisi.org.uk

^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH 1/1] media: Correctly determine whether an entity is a sub-device
  2015-10-12  0:56       ` Mauro Carvalho Chehab
  (?)
@ 2015-10-12 15:38         ` Sakari Ailus
  -1 siblings, 0 replies; 309+ messages in thread
From: Sakari Ailus @ 2015-10-12 15:38 UTC (permalink / raw)
  To: linux-arm-kernel

If the function of an entity is not one of the pre-defined ones, it is not
correctly recognised as a V4L2 sub-device.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 include/media/media-entity.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index a60872a..76e9a124 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -328,6 +328,7 @@ static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
 	case MEDIA_ENT_F_LENS:
 	case MEDIA_ENT_F_ATV_DECODER:
 	case MEDIA_ENT_F_TUNER:
+	case MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN:
 		return true;
 
 	default:
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH 1/1] media: Correctly determine whether an entity is a sub-device
@ 2015-10-12 15:38         ` Sakari Ailus
  0 siblings, 0 replies; 309+ messages in thread
From: Sakari Ailus @ 2015-10-12 15:38 UTC (permalink / raw)
  To: mchehab
  Cc: linux-media, mchehab, kyungmin.park, s.nawrocki, kgene,
	k.kozlowski, laurent.pinchart, hyun.kwon, michal.simek,
	soren.brinkmann, gregkh, hans.verkuil, prabhakar.csengg, lars,
	elfring, sakari.ailus, javier, linux-arm-kernel,
	linux-samsung-soc, linux-sh, devel

If the function of an entity is not one of the pre-defined ones, it is not
correctly recognised as a V4L2 sub-device.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 include/media/media-entity.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index a60872a..76e9a124 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -328,6 +328,7 @@ static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
 	case MEDIA_ENT_F_LENS:
 	case MEDIA_ENT_F_ATV_DECODER:
 	case MEDIA_ENT_F_TUNER:
+	case MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN:
 		return true;
 
 	default:
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 309+ messages in thread

* [PATCH 1/1] media: Correctly determine whether an entity is a sub-device
@ 2015-10-12 15:38         ` Sakari Ailus
  0 siblings, 0 replies; 309+ messages in thread
From: Sakari Ailus @ 2015-10-12 15:38 UTC (permalink / raw)
  To: linux-arm-kernel

If the function of an entity is not one of the pre-defined ones, it is not
correctly recognised as a V4L2 sub-device.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 include/media/media-entity.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index a60872a..76e9a124 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -328,6 +328,7 @@ static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
 	case MEDIA_ENT_F_LENS:
 	case MEDIA_ENT_F_ATV_DECODER:
 	case MEDIA_ENT_F_TUNER:
+	case MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN:
 		return true;
 
 	default:
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH 1/1] media: Correctly determine whether an entity is a sub-device
  2015-10-12 15:38         ` Sakari Ailus
  (?)
  (?)
@ 2015-10-12 15:58           ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-10-12 15:58 UTC (permalink / raw)
  To: linux-arm-kernel

Em Mon, 12 Oct 2015 18:38:23 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> If the function of an entity is not one of the pre-defined ones, it is not
> correctly recognised as a V4L2 sub-device.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
>  include/media/media-entity.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index a60872a..76e9a124 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -328,6 +328,7 @@ static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
>  	case MEDIA_ENT_F_LENS:
>  	case MEDIA_ENT_F_ATV_DECODER:
>  	case MEDIA_ENT_F_TUNER:
> +	case MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN:
>  		return true;

OK.

Reviewed-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

>  
>  	default:

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH 1/1] media: Correctly determine whether an entity is a sub-device
@ 2015-10-12 15:58           ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-10-12 15:58 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, mchehab, kyungmin.park, s.nawrocki, kgene,
	k.kozlowski, laurent.pinchart, hyun.kwon, michal.simek,
	soren.brinkmann, gregkh, hans.verkuil, prabhakar.csengg, lars,
	elfring, sakari.ailus, javier, linux-arm-kernel,
	linux-samsung-soc, linux-sh, devel

Em Mon, 12 Oct 2015 18:38:23 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> If the function of an entity is not one of the pre-defined ones, it is not
> correctly recognised as a V4L2 sub-device.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
>  include/media/media-entity.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index a60872a..76e9a124 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -328,6 +328,7 @@ static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
>  	case MEDIA_ENT_F_LENS:
>  	case MEDIA_ENT_F_ATV_DECODER:
>  	case MEDIA_ENT_F_TUNER:
> +	case MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN:
>  		return true;

OK.

Reviewed-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

>  
>  	default:

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH 1/1] media: Correctly determine whether an entity is a sub-device
@ 2015-10-12 15:58           ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-10-12 15:58 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-arm-kernel, devel, k.kozlowski, lars, sakari.ailus,
	hyun.kwon, linux-sh, gregkh, michal.simek, mchehab, javier,
	kyungmin.park, kgene, hans.verkuil, laurent.pinchart, s.nawrocki,
	linux-samsung-soc, prabhakar.csengg, elfring, soren.brinkmann,
	linux-media

Em Mon, 12 Oct 2015 18:38:23 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> If the function of an entity is not one of the pre-defined ones, it is not
> correctly recognised as a V4L2 sub-device.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
>  include/media/media-entity.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index a60872a..76e9a124 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -328,6 +328,7 @@ static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
>  	case MEDIA_ENT_F_LENS:
>  	case MEDIA_ENT_F_ATV_DECODER:
>  	case MEDIA_ENT_F_TUNER:
> +	case MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN:
>  		return true;

OK.

Reviewed-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

>  
>  	default:

^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH 1/1] media: Correctly determine whether an entity is a sub-device
@ 2015-10-12 15:58           ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-10-12 15:58 UTC (permalink / raw)
  To: linux-arm-kernel

Em Mon, 12 Oct 2015 18:38:23 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> If the function of an entity is not one of the pre-defined ones, it is not
> correctly recognised as a V4L2 sub-device.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
>  include/media/media-entity.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index a60872a..76e9a124 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -328,6 +328,7 @@ static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
>  	case MEDIA_ENT_F_LENS:
>  	case MEDIA_ENT_F_ATV_DECODER:
>  	case MEDIA_ENT_F_TUNER:
> +	case MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN:
>  		return true;

OK.

Reviewed-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

>  
>  	default:

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
  2015-10-12 15:35         ` Sakari Ailus
  (?)
  (?)
@ 2015-10-12 16:00           ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-10-12 16:00 UTC (permalink / raw)
  To: linux-arm-kernel

Em Mon, 12 Oct 2015 18:35:05 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Sun, Oct 11, 2015 at 09:56:25PM -0300, Mauro Carvalho Chehab wrote:
> > Em Mon, 12 Oct 2015 00:07:52 +0300
> > Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> > 
> > > Hi Mauro,
> > > 
> > > On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > > > Instead of relying on media subtype, use the new macros to detect
> > > > if an entity is a subdev or an A/V DMA entity.
> > > > 
> > > > Please note that most drivers assume that there's just AV_DMA or
> > > > V4L2 subdevs. This is not true anymore, as we've added MC support
> > > > for DVB, and there are plans to add support for ALSA and FB/DRM
> > > > too.
> > > > 
> > > > Ok, on the current pipelines supported by those drivers, just V4L
> > > > stuff are there, but, assuming that some day a pipeline that also
> > > > works with other subsystems will ever added, it is better to add
> > > > explicit checks for the AV_DMA stuff.
> > > > 
> > > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > > 
> > > > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > > > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > > > --- a/drivers/media/platform/exynos4-is/common.c
> > > > +++ b/drivers/media/platform/exynos4-is/common.c
> > > > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> > > >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> > > >  		/* source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad = NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > index 0627a93b2f3b..e9810fee4c30 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> > > >  			}
> > > >  		}
> > > >  
> > > > -		if (src_pad = NULL ||
> > > > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> > > >  			break;
> > > >  
> > > >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > > > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> > > >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> > > >  	struct v4l2_subdev *sensor;
> > > >  
> > > > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return -EINVAL;
> > > >  
> > > >  	if (WARN_ON(fimc = NULL))
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> > > >  
> > > >  		/* Retrieve format at the source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad = NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > index b2607da4ad14..c2327147b360 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> > > >  		}
> > > >  		/* Retrieve format at the source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad = NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  {
> > > >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> > > >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > > > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> > > >  	int ret = 0;
> > > >  
> > > >  	if (WARN_ON(fimc = NULL))
> > > > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  
> > > >  	switch (local->index) {
> > > >  	case FLITE_SD_PAD_SINK:
> > > > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> > > >  			ret = -EINVAL;
> > > >  			break;
> > > >  		}
> > > > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  	case FLITE_SD_PAD_SOURCE_DMA:
> > > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > > -		else if (remote_ent_type = MEDIA_ENT_T_DEVNODE)
> > > > +		else if (is_media_entity_v4l2_io(remote->entity))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> > > >  		else
> > > >  			ret = -EINVAL;
> > > > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  	case FLITE_SD_PAD_SOURCE_ISP:
> > > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > > -		else if (remote_ent_type = MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> > > >  		else
> > > >  			ret = -EINVAL;
> > > > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > > > index 92dbade2fffc..4a25df9dd869 100644
> > > > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > > > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > > > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> > > >  				break;
> > > >  		}
> > > >  
> > > > -		if (pad = NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > >  
> > > > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > > > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > > >  	media_entity_graph_walk_start(&graph, entity_err);
> > > >  
> > > >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity_err))
> > > >  			continue;
> > > >  
> > > >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > > > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > > > index 69e7733d36cd..cb8ac90086c1 100644
> > > > --- a/drivers/media/platform/omap3isp/isp.c
> > > > +++ b/drivers/media/platform/omap3isp/isp.c
> > > > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_io(entity))
> > > >  			use += entity->use_count;
> > > >  	}
> > > >  
> > > > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> > > >  	struct v4l2_subdev *subdev;
> > > >  	int ret;
> > > >  
> > > > -	subdev = media_entity_type(entity) = MEDIA_ENT_T_V4L2_SUBDEV
> > > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > > >  
> > > >  	if (entity->use_count = 0 && change > 0 && subdev != NULL) {
> > > > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(entity))
> > > >  			ret = isp_pipeline_pm_power_one(entity, change);
> > > >  
> > > >  	if (!ret)
> > > > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  
> > > >  	while ((first = media_entity_graph_walk_next(&graph))
> > > >  	       && first != entity)
> > > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(first))
> > > >  			isp_pipeline_pm_power_one(first, -change);
> > > >  
> > > >  	return ret;
> > > > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad = NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad = NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > > > index 4c367352b1f7..52843ac2a9ca 100644
> > > > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > > > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > > > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> > > >  
> > > >  	remote = media_entity_remote_pad(&video->pad);
> > > >  
> > > > -	if (remote = NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> > > >  		if (entity = &video->video.entity)
> > > >  			continue;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > > > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> > > >  		return -EINVAL;
> > > >  	}
> > > >  
> > > > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!is_media_entity_v4l2_subdev(source))
> > > >  		return 0;
> > > >  
> > > >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > > > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > > > index eae667eab1b9..fb5b016cc0a1 100644
> > > > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > > > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > > > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> > > >  
> > > >  	/* Retrieve format at the sensor subdev source pad */
> > > >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > > > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  		return -EPIPE;
> > > >  
> > > >  	src_fmt.pad = pad->index;
> > > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > > > index 1f94c1a54e00..f74158224b93 100644
> > > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> > > >  	struct media_pad *remote;
> > > >  
> > > >  	remote = media_entity_remote_pad(local);
> > > > -	if (remote = NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> > > >  			return -EPIPE;
> > > >  
> > > >  		/* We've reached a video node, that shouldn't have happened. */
> > > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > > >  			return -EPIPE;
> > > >  
> > > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> > > >  		struct vsp1_rwpf *rwpf;
> > > >  		struct vsp1_entity *e;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +		if (is_media_entity_v4l2_io(entity)) {
> > > >  			pipe->num_video++;
> > > >  			continue;
> > > >  		}
> > > > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> > > >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> > > >  
> > > >  	while (pad) {
> > > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > > > index 88cd789cdaf7..8e14841bf445 100644
> > > > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > > > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > > > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> > > >  	struct media_pad *remote;
> > > >  
> > > >  	remote = media_entity_remote_pad(local);
> > > > -	if (remote = NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad = NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > > > index e6e1115d8215..60da43772de9 100644
> > > > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > > > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > > > @@ -526,7 +526,7 @@ static int
> > > >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> > > >  				     struct v4l2_subdev_format *fmt)
> > > >  {
> > > > -	if (media_entity_type(pad->entity) = MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> > > >  		struct v4l2_subdev *sd > > > >  			media_entity_to_v4l2_subdev(pad->entity);
> > > >  
> > > > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > index 92573fa852a9..16763e0831f2 100644
> > > > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  		if (entity = &video->video_dev.entity)
> > > >  			continue;
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if ((!is_media_entity_v4l2_io(remote->entity))
> > > >  			continue;
> > > >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> > > >  		if (far_end->type = V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > > > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  
> > > > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > > > +		if !is_media_entity_v4l2_subdev(entity))
> > > >  			continue;
> > > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > > > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  
> > > > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_subdev(entity))
> > > >  			continue;
> > > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > > > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > > > index 40591963b42b..44b88ff3ba83 100644
> > > > --- a/drivers/staging/media/omap4iss/iss.c
> > > > +++ b/drivers/staging/media/omap4iss/iss.c
> > > > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_io(entity))
> > > >  			use += entity->use_count;
> > > >  	}
> > > >  
> > > > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> > > >  {
> > > >  	struct v4l2_subdev *subdev;
> > > >  
> > > > -	subdev = media_entity_type(entity) = MEDIA_ENT_T_V4L2_SUBDEV
> > > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > > >  
> > > >  	if (entity->use_count = 0 && change > 0 && subdev != NULL) {
> > > > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(entity))
> > > >  			ret = iss_pipeline_pm_power_one(entity, change);
> > > >  
> > > >  	if (!ret)
> > > > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  
> > > >  	while ((first = media_entity_graph_walk_next(&graph))
> > > >  	       && first != entity)
> > > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(first))
> > > >  			iss_pipeline_pm_power_one(first, -change);
> > > >  
> > > >  	return ret;
> > > > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad = NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad = NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > > > index 45a3f2d778fc..cbe5783735dc 100644
> > > > --- a/drivers/staging/media/omap4iss/iss_video.c
> > > > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > > > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> > > >  
> > > >  	remote = media_entity_remote_pad(&video->pad);
> > > >  
> > > > -	if (remote = NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> > > >  		if (entity = &video->video.entity)
> > > >  			continue;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> > > 
> > > I finally got around to test these patches eventually, and after some
> > > debugging found this one. I think it's a good idea to have macros to
> > > determine whether an entity exposes a V4L2 sub-device interface but it
> > > should be more robust than is_media_entity_v4l2_subdev() right now is.
> > 
> > Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
> > actually a separate graph object (interfaces). Those macros work at the
> > entities, not at the interface objects.
> 
> is_media_entity_v4l2_subdev() will produce wrong results for a large part of
> V4L2 sub-devices with these patches applied.
> 
> I checked again the original implementation, and it seems to be based only
> on the type as well, albeit that's a range, not a set of different
> functions.

Yes. As we're getting rid of ranges for subdevs, we need to change the
implementation. Your patch does the job by recognizing the "unknown"
subdevs.

> I suppose this will change at some point in the future: the interface indeed
> should not be determined by the function of the entity. At least it needs to
> be fixed now until the rework. I'll submit a patch for that.
> 

Thanks!

Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-10-12 16:00           ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-10-12 16:00 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Kukjin Kim, Krzysztof Kozlowski,
	Laurent Pinchart, Hyun Kwon, Michal Simek, Sören Brinkmann,
	Greg Kroah-Hartman, Hans Verkuil, Prabhakar Lad,
	Lars-Peter Clausen, Markus Elfring, Sakari Ailus,
	Javier Martinez Canillas, linux-arm-kernel, linux-samsung-soc,
	linux-sh, devel

Em Mon, 12 Oct 2015 18:35:05 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Sun, Oct 11, 2015 at 09:56:25PM -0300, Mauro Carvalho Chehab wrote:
> > Em Mon, 12 Oct 2015 00:07:52 +0300
> > Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> > 
> > > Hi Mauro,
> > > 
> > > On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > > > Instead of relying on media subtype, use the new macros to detect
> > > > if an entity is a subdev or an A/V DMA entity.
> > > > 
> > > > Please note that most drivers assume that there's just AV_DMA or
> > > > V4L2 subdevs. This is not true anymore, as we've added MC support
> > > > for DVB, and there are plans to add support for ALSA and FB/DRM
> > > > too.
> > > > 
> > > > Ok, on the current pipelines supported by those drivers, just V4L
> > > > stuff are there, but, assuming that some day a pipeline that also
> > > > works with other subsystems will ever added, it is better to add
> > > > explicit checks for the AV_DMA stuff.
> > > > 
> > > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > > 
> > > > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > > > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > > > --- a/drivers/media/platform/exynos4-is/common.c
> > > > +++ b/drivers/media/platform/exynos4-is/common.c
> > > > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> > > >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> > > >  		/* source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > index 0627a93b2f3b..e9810fee4c30 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> > > >  			}
> > > >  		}
> > > >  
> > > > -		if (src_pad == NULL ||
> > > > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> > > >  			break;
> > > >  
> > > >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > > > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> > > >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> > > >  	struct v4l2_subdev *sensor;
> > > >  
> > > > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return -EINVAL;
> > > >  
> > > >  	if (WARN_ON(fimc == NULL))
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> > > >  
> > > >  		/* Retrieve format at the source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > index b2607da4ad14..c2327147b360 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> > > >  		}
> > > >  		/* Retrieve format at the source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  {
> > > >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> > > >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > > > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> > > >  	int ret = 0;
> > > >  
> > > >  	if (WARN_ON(fimc == NULL))
> > > > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  
> > > >  	switch (local->index) {
> > > >  	case FLITE_SD_PAD_SINK:
> > > > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> > > >  			ret = -EINVAL;
> > > >  			break;
> > > >  		}
> > > > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  	case FLITE_SD_PAD_SOURCE_DMA:
> > > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > > -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> > > > +		else if (is_media_entity_v4l2_io(remote->entity))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> > > >  		else
> > > >  			ret = -EINVAL;
> > > > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  	case FLITE_SD_PAD_SOURCE_ISP:
> > > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > > -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> > > >  		else
> > > >  			ret = -EINVAL;
> > > > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > > > index 92dbade2fffc..4a25df9dd869 100644
> > > > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > > > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > > > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> > > >  				break;
> > > >  		}
> > > >  
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > >  
> > > > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > > > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > > >  	media_entity_graph_walk_start(&graph, entity_err);
> > > >  
> > > >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity_err))
> > > >  			continue;
> > > >  
> > > >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > > > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > > > index 69e7733d36cd..cb8ac90086c1 100644
> > > > --- a/drivers/media/platform/omap3isp/isp.c
> > > > +++ b/drivers/media/platform/omap3isp/isp.c
> > > > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_io(entity))
> > > >  			use += entity->use_count;
> > > >  	}
> > > >  
> > > > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> > > >  	struct v4l2_subdev *subdev;
> > > >  	int ret;
> > > >  
> > > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > > >  
> > > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(entity))
> > > >  			ret = isp_pipeline_pm_power_one(entity, change);
> > > >  
> > > >  	if (!ret)
> > > > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  
> > > >  	while ((first = media_entity_graph_walk_next(&graph))
> > > >  	       && first != entity)
> > > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(first))
> > > >  			isp_pipeline_pm_power_one(first, -change);
> > > >  
> > > >  	return ret;
> > > > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > > > index 4c367352b1f7..52843ac2a9ca 100644
> > > > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > > > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > > > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> > > >  
> > > >  	remote = media_entity_remote_pad(&video->pad);
> > > >  
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> > > >  		if (entity == &video->video.entity)
> > > >  			continue;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > > > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> > > >  		return -EINVAL;
> > > >  	}
> > > >  
> > > > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!is_media_entity_v4l2_subdev(source))
> > > >  		return 0;
> > > >  
> > > >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > > > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > > > index eae667eab1b9..fb5b016cc0a1 100644
> > > > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > > > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > > > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> > > >  
> > > >  	/* Retrieve format at the sensor subdev source pad */
> > > >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > > > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  		return -EPIPE;
> > > >  
> > > >  	src_fmt.pad = pad->index;
> > > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > > > index 1f94c1a54e00..f74158224b93 100644
> > > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> > > >  	struct media_pad *remote;
> > > >  
> > > >  	remote = media_entity_remote_pad(local);
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> > > >  			return -EPIPE;
> > > >  
> > > >  		/* We've reached a video node, that shouldn't have happened. */
> > > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > > >  			return -EPIPE;
> > > >  
> > > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> > > >  		struct vsp1_rwpf *rwpf;
> > > >  		struct vsp1_entity *e;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +		if (is_media_entity_v4l2_io(entity)) {
> > > >  			pipe->num_video++;
> > > >  			continue;
> > > >  		}
> > > > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> > > >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> > > >  
> > > >  	while (pad) {
> > > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > > > index 88cd789cdaf7..8e14841bf445 100644
> > > > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > > > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > > > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> > > >  	struct media_pad *remote;
> > > >  
> > > >  	remote = media_entity_remote_pad(local);
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > > > index e6e1115d8215..60da43772de9 100644
> > > > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > > > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > > > @@ -526,7 +526,7 @@ static int
> > > >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> > > >  				     struct v4l2_subdev_format *fmt)
> > > >  {
> > > > -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> > > >  		struct v4l2_subdev *sd =
> > > >  			media_entity_to_v4l2_subdev(pad->entity);
> > > >  
> > > > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > index 92573fa852a9..16763e0831f2 100644
> > > > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  		if (entity == &video->video_dev.entity)
> > > >  			continue;
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if ((!is_media_entity_v4l2_io(remote->entity))
> > > >  			continue;
> > > >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> > > >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > > > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if !is_media_entity_v4l2_subdev(entity))
> > > >  			continue;
> > > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > > > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_subdev(entity))
> > > >  			continue;
> > > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > > > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > > > index 40591963b42b..44b88ff3ba83 100644
> > > > --- a/drivers/staging/media/omap4iss/iss.c
> > > > +++ b/drivers/staging/media/omap4iss/iss.c
> > > > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_io(entity))
> > > >  			use += entity->use_count;
> > > >  	}
> > > >  
> > > > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> > > >  {
> > > >  	struct v4l2_subdev *subdev;
> > > >  
> > > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > > >  
> > > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(entity))
> > > >  			ret = iss_pipeline_pm_power_one(entity, change);
> > > >  
> > > >  	if (!ret)
> > > > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  
> > > >  	while ((first = media_entity_graph_walk_next(&graph))
> > > >  	       && first != entity)
> > > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(first))
> > > >  			iss_pipeline_pm_power_one(first, -change);
> > > >  
> > > >  	return ret;
> > > > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > > > index 45a3f2d778fc..cbe5783735dc 100644
> > > > --- a/drivers/staging/media/omap4iss/iss_video.c
> > > > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > > > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> > > >  
> > > >  	remote = media_entity_remote_pad(&video->pad);
> > > >  
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> > > >  		if (entity == &video->video.entity)
> > > >  			continue;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> > > 
> > > I finally got around to test these patches eventually, and after some
> > > debugging found this one. I think it's a good idea to have macros to
> > > determine whether an entity exposes a V4L2 sub-device interface but it
> > > should be more robust than is_media_entity_v4l2_subdev() right now is.
> > 
> > Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
> > actually a separate graph object (interfaces). Those macros work at the
> > entities, not at the interface objects.
> 
> is_media_entity_v4l2_subdev() will produce wrong results for a large part of
> V4L2 sub-devices with these patches applied.
> 
> I checked again the original implementation, and it seems to be based only
> on the type as well, albeit that's a range, not a set of different
> functions.

Yes. As we're getting rid of ranges for subdevs, we need to change the
implementation. Your patch does the job by recognizing the "unknown"
subdevs.

> I suppose this will change at some point in the future: the interface indeed
> should not be determined by the function of the entity. At least it needs to
> be fixed now until the rework. I'll submit a patch for that.
> 

Thanks!

Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-10-12 16:00           ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-10-12 16:00 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Kukjin Kim, Krzysztof Kozlowski,
	Laurent Pinchart, Hyun Kwon, Michal Simek, Sören Brinkmann,
	Greg Kroah-Hartman, Hans Verkuil, Prabhakar Lad,
	Lars-Peter Clausen, Markus Elfring, Sakari Ailus,
	Javier Martinez Canillas, linux-arm-kernel, linux-samsung-soc,
	linux-sh

Em Mon, 12 Oct 2015 18:35:05 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Sun, Oct 11, 2015 at 09:56:25PM -0300, Mauro Carvalho Chehab wrote:
> > Em Mon, 12 Oct 2015 00:07:52 +0300
> > Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> > 
> > > Hi Mauro,
> > > 
> > > On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > > > Instead of relying on media subtype, use the new macros to detect
> > > > if an entity is a subdev or an A/V DMA entity.
> > > > 
> > > > Please note that most drivers assume that there's just AV_DMA or
> > > > V4L2 subdevs. This is not true anymore, as we've added MC support
> > > > for DVB, and there are plans to add support for ALSA and FB/DRM
> > > > too.
> > > > 
> > > > Ok, on the current pipelines supported by those drivers, just V4L
> > > > stuff are there, but, assuming that some day a pipeline that also
> > > > works with other subsystems will ever added, it is better to add
> > > > explicit checks for the AV_DMA stuff.
> > > > 
> > > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > > 
> > > > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > > > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > > > --- a/drivers/media/platform/exynos4-is/common.c
> > > > +++ b/drivers/media/platform/exynos4-is/common.c
> > > > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> > > >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> > > >  		/* source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > index 0627a93b2f3b..e9810fee4c30 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> > > >  			}
> > > >  		}
> > > >  
> > > > -		if (src_pad == NULL ||
> > > > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> > > >  			break;
> > > >  
> > > >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > > > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> > > >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> > > >  	struct v4l2_subdev *sensor;
> > > >  
> > > > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return -EINVAL;
> > > >  
> > > >  	if (WARN_ON(fimc == NULL))
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> > > >  
> > > >  		/* Retrieve format at the source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > index b2607da4ad14..c2327147b360 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> > > >  		}
> > > >  		/* Retrieve format at the source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  {
> > > >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> > > >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > > > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> > > >  	int ret = 0;
> > > >  
> > > >  	if (WARN_ON(fimc == NULL))
> > > > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  
> > > >  	switch (local->index) {
> > > >  	case FLITE_SD_PAD_SINK:
> > > > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> > > >  			ret = -EINVAL;
> > > >  			break;
> > > >  		}
> > > > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  	case FLITE_SD_PAD_SOURCE_DMA:
> > > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > > -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> > > > +		else if (is_media_entity_v4l2_io(remote->entity))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> > > >  		else
> > > >  			ret = -EINVAL;
> > > > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  	case FLITE_SD_PAD_SOURCE_ISP:
> > > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > > -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> > > >  		else
> > > >  			ret = -EINVAL;
> > > > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > > > index 92dbade2fffc..4a25df9dd869 100644
> > > > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > > > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > > > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> > > >  				break;
> > > >  		}
> > > >  
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > >  
> > > > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > > > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > > >  	media_entity_graph_walk_start(&graph, entity_err);
> > > >  
> > > >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity_err))
> > > >  			continue;
> > > >  
> > > >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > > > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > > > index 69e7733d36cd..cb8ac90086c1 100644
> > > > --- a/drivers/media/platform/omap3isp/isp.c
> > > > +++ b/drivers/media/platform/omap3isp/isp.c
> > > > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_io(entity))
> > > >  			use += entity->use_count;
> > > >  	}
> > > >  
> > > > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> > > >  	struct v4l2_subdev *subdev;
> > > >  	int ret;
> > > >  
> > > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > > >  
> > > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(entity))
> > > >  			ret = isp_pipeline_pm_power_one(entity, change);
> > > >  
> > > >  	if (!ret)
> > > > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  
> > > >  	while ((first = media_entity_graph_walk_next(&graph))
> > > >  	       && first != entity)
> > > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(first))
> > > >  			isp_pipeline_pm_power_one(first, -change);
> > > >  
> > > >  	return ret;
> > > > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > > > index 4c367352b1f7..52843ac2a9ca 100644
> > > > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > > > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > > > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> > > >  
> > > >  	remote = media_entity_remote_pad(&video->pad);
> > > >  
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> > > >  		if (entity == &video->video.entity)
> > > >  			continue;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > > > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> > > >  		return -EINVAL;
> > > >  	}
> > > >  
> > > > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!is_media_entity_v4l2_subdev(source))
> > > >  		return 0;
> > > >  
> > > >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > > > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > > > index eae667eab1b9..fb5b016cc0a1 100644
> > > > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > > > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > > > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> > > >  
> > > >  	/* Retrieve format at the sensor subdev source pad */
> > > >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > > > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  		return -EPIPE;
> > > >  
> > > >  	src_fmt.pad = pad->index;
> > > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > > > index 1f94c1a54e00..f74158224b93 100644
> > > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> > > >  	struct media_pad *remote;
> > > >  
> > > >  	remote = media_entity_remote_pad(local);
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> > > >  			return -EPIPE;
> > > >  
> > > >  		/* We've reached a video node, that shouldn't have happened. */
> > > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > > >  			return -EPIPE;
> > > >  
> > > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> > > >  		struct vsp1_rwpf *rwpf;
> > > >  		struct vsp1_entity *e;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +		if (is_media_entity_v4l2_io(entity)) {
> > > >  			pipe->num_video++;
> > > >  			continue;
> > > >  		}
> > > > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> > > >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> > > >  
> > > >  	while (pad) {
> > > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > > > index 88cd789cdaf7..8e14841bf445 100644
> > > > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > > > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > > > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> > > >  	struct media_pad *remote;
> > > >  
> > > >  	remote = media_entity_remote_pad(local);
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > > > index e6e1115d8215..60da43772de9 100644
> > > > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > > > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > > > @@ -526,7 +526,7 @@ static int
> > > >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> > > >  				     struct v4l2_subdev_format *fmt)
> > > >  {
> > > > -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> > > >  		struct v4l2_subdev *sd =
> > > >  			media_entity_to_v4l2_subdev(pad->entity);
> > > >  
> > > > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > index 92573fa852a9..16763e0831f2 100644
> > > > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  		if (entity == &video->video_dev.entity)
> > > >  			continue;
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if ((!is_media_entity_v4l2_io(remote->entity))
> > > >  			continue;
> > > >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> > > >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > > > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if !is_media_entity_v4l2_subdev(entity))
> > > >  			continue;
> > > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > > > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_subdev(entity))
> > > >  			continue;
> > > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > > > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > > > index 40591963b42b..44b88ff3ba83 100644
> > > > --- a/drivers/staging/media/omap4iss/iss.c
> > > > +++ b/drivers/staging/media/omap4iss/iss.c
> > > > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_io(entity))
> > > >  			use += entity->use_count;
> > > >  	}
> > > >  
> > > > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> > > >  {
> > > >  	struct v4l2_subdev *subdev;
> > > >  
> > > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > > >  
> > > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(entity))
> > > >  			ret = iss_pipeline_pm_power_one(entity, change);
> > > >  
> > > >  	if (!ret)
> > > > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  
> > > >  	while ((first = media_entity_graph_walk_next(&graph))
> > > >  	       && first != entity)
> > > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(first))
> > > >  			iss_pipeline_pm_power_one(first, -change);
> > > >  
> > > >  	return ret;
> > > > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > > > index 45a3f2d778fc..cbe5783735dc 100644
> > > > --- a/drivers/staging/media/omap4iss/iss_video.c
> > > > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > > > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> > > >  
> > > >  	remote = media_entity_remote_pad(&video->pad);
> > > >  
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> > > >  		if (entity == &video->video.entity)
> > > >  			continue;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> > > 
> > > I finally got around to test these patches eventually, and after some
> > > debugging found this one. I think it's a good idea to have macros to
> > > determine whether an entity exposes a V4L2 sub-device interface but it
> > > should be more robust than is_media_entity_v4l2_subdev() right now is.
> > 
> > Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
> > actually a separate graph object (interfaces). Those macros work at the
> > entities, not at the interface objects.
> 
> is_media_entity_v4l2_subdev() will produce wrong results for a large part of
> V4L2 sub-devices with these patches applied.
> 
> I checked again the original implementation, and it seems to be based only
> on the type as well, albeit that's a range, not a set of different
> functions.

Yes. As we're getting rid of ranges for subdevs, we need to change the
implementation. Your patch does the job by recognizing the "unknown"
subdevs.

> I suppose this will change at some point in the future: the interface indeed
> should not be determined by the function of the entity. At least it needs to
> be fixed now until the rework. I'll submit a patch for that.
> 

Thanks!

Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-10-12 16:00           ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-10-12 16:00 UTC (permalink / raw)
  To: linux-arm-kernel

Em Mon, 12 Oct 2015 18:35:05 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Sun, Oct 11, 2015 at 09:56:25PM -0300, Mauro Carvalho Chehab wrote:
> > Em Mon, 12 Oct 2015 00:07:52 +0300
> > Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> > 
> > > Hi Mauro,
> > > 
> > > On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > > > Instead of relying on media subtype, use the new macros to detect
> > > > if an entity is a subdev or an A/V DMA entity.
> > > > 
> > > > Please note that most drivers assume that there's just AV_DMA or
> > > > V4L2 subdevs. This is not true anymore, as we've added MC support
> > > > for DVB, and there are plans to add support for ALSA and FB/DRM
> > > > too.
> > > > 
> > > > Ok, on the current pipelines supported by those drivers, just V4L
> > > > stuff are there, but, assuming that some day a pipeline that also
> > > > works with other subsystems will ever added, it is better to add
> > > > explicit checks for the AV_DMA stuff.
> > > > 
> > > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > > 
> > > > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > > > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > > > --- a/drivers/media/platform/exynos4-is/common.c
> > > > +++ b/drivers/media/platform/exynos4-is/common.c
> > > > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> > > >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> > > >  		/* source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > index 0627a93b2f3b..e9810fee4c30 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> > > >  			}
> > > >  		}
> > > >  
> > > > -		if (src_pad == NULL ||
> > > > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> > > >  			break;
> > > >  
> > > >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > > > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> > > >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> > > >  	struct v4l2_subdev *sensor;
> > > >  
> > > > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return -EINVAL;
> > > >  
> > > >  	if (WARN_ON(fimc == NULL))
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> > > >  
> > > >  		/* Retrieve format at the source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > index b2607da4ad14..c2327147b360 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> > > >  		}
> > > >  		/* Retrieve format at the source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  {
> > > >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> > > >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > > > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> > > >  	int ret = 0;
> > > >  
> > > >  	if (WARN_ON(fimc == NULL))
> > > > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  
> > > >  	switch (local->index) {
> > > >  	case FLITE_SD_PAD_SINK:
> > > > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> > > >  			ret = -EINVAL;
> > > >  			break;
> > > >  		}
> > > > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  	case FLITE_SD_PAD_SOURCE_DMA:
> > > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > > -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> > > > +		else if (is_media_entity_v4l2_io(remote->entity))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> > > >  		else
> > > >  			ret = -EINVAL;
> > > > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  	case FLITE_SD_PAD_SOURCE_ISP:
> > > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > > -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> > > >  		else
> > > >  			ret = -EINVAL;
> > > > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > > > index 92dbade2fffc..4a25df9dd869 100644
> > > > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > > > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > > > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> > > >  				break;
> > > >  		}
> > > >  
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > >  
> > > > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > > > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > > >  	media_entity_graph_walk_start(&graph, entity_err);
> > > >  
> > > >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity_err))
> > > >  			continue;
> > > >  
> > > >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > > > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > > > index 69e7733d36cd..cb8ac90086c1 100644
> > > > --- a/drivers/media/platform/omap3isp/isp.c
> > > > +++ b/drivers/media/platform/omap3isp/isp.c
> > > > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_io(entity))
> > > >  			use += entity->use_count;
> > > >  	}
> > > >  
> > > > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> > > >  	struct v4l2_subdev *subdev;
> > > >  	int ret;
> > > >  
> > > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > > >  
> > > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(entity))
> > > >  			ret = isp_pipeline_pm_power_one(entity, change);
> > > >  
> > > >  	if (!ret)
> > > > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  
> > > >  	while ((first = media_entity_graph_walk_next(&graph))
> > > >  	       && first != entity)
> > > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(first))
> > > >  			isp_pipeline_pm_power_one(first, -change);
> > > >  
> > > >  	return ret;
> > > > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > > > index 4c367352b1f7..52843ac2a9ca 100644
> > > > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > > > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > > > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> > > >  
> > > >  	remote = media_entity_remote_pad(&video->pad);
> > > >  
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> > > >  		if (entity == &video->video.entity)
> > > >  			continue;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > > > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> > > >  		return -EINVAL;
> > > >  	}
> > > >  
> > > > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!is_media_entity_v4l2_subdev(source))
> > > >  		return 0;
> > > >  
> > > >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > > > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > > > index eae667eab1b9..fb5b016cc0a1 100644
> > > > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > > > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > > > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> > > >  
> > > >  	/* Retrieve format at the sensor subdev source pad */
> > > >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > > > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  		return -EPIPE;
> > > >  
> > > >  	src_fmt.pad = pad->index;
> > > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > > > index 1f94c1a54e00..f74158224b93 100644
> > > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> > > >  	struct media_pad *remote;
> > > >  
> > > >  	remote = media_entity_remote_pad(local);
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> > > >  			return -EPIPE;
> > > >  
> > > >  		/* We've reached a video node, that shouldn't have happened. */
> > > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > > >  			return -EPIPE;
> > > >  
> > > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> > > >  		struct vsp1_rwpf *rwpf;
> > > >  		struct vsp1_entity *e;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +		if (is_media_entity_v4l2_io(entity)) {
> > > >  			pipe->num_video++;
> > > >  			continue;
> > > >  		}
> > > > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> > > >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> > > >  
> > > >  	while (pad) {
> > > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > > > index 88cd789cdaf7..8e14841bf445 100644
> > > > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > > > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > > > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> > > >  	struct media_pad *remote;
> > > >  
> > > >  	remote = media_entity_remote_pad(local);
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > > > index e6e1115d8215..60da43772de9 100644
> > > > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > > > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > > > @@ -526,7 +526,7 @@ static int
> > > >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> > > >  				     struct v4l2_subdev_format *fmt)
> > > >  {
> > > > -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> > > >  		struct v4l2_subdev *sd =
> > > >  			media_entity_to_v4l2_subdev(pad->entity);
> > > >  
> > > > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > index 92573fa852a9..16763e0831f2 100644
> > > > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  		if (entity == &video->video_dev.entity)
> > > >  			continue;
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if ((!is_media_entity_v4l2_io(remote->entity))
> > > >  			continue;
> > > >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> > > >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > > > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if !is_media_entity_v4l2_subdev(entity))
> > > >  			continue;
> > > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > > > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_subdev(entity))
> > > >  			continue;
> > > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > > > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > > > index 40591963b42b..44b88ff3ba83 100644
> > > > --- a/drivers/staging/media/omap4iss/iss.c
> > > > +++ b/drivers/staging/media/omap4iss/iss.c
> > > > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_io(entity))
> > > >  			use += entity->use_count;
> > > >  	}
> > > >  
> > > > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> > > >  {
> > > >  	struct v4l2_subdev *subdev;
> > > >  
> > > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > > >  
> > > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(entity))
> > > >  			ret = iss_pipeline_pm_power_one(entity, change);
> > > >  
> > > >  	if (!ret)
> > > > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  
> > > >  	while ((first = media_entity_graph_walk_next(&graph))
> > > >  	       && first != entity)
> > > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(first))
> > > >  			iss_pipeline_pm_power_one(first, -change);
> > > >  
> > > >  	return ret;
> > > > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > > > index 45a3f2d778fc..cbe5783735dc 100644
> > > > --- a/drivers/staging/media/omap4iss/iss_video.c
> > > > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > > > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> > > >  
> > > >  	remote = media_entity_remote_pad(&video->pad);
> > > >  
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> > > >  		if (entity == &video->video.entity)
> > > >  			continue;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> > > 
> > > I finally got around to test these patches eventually, and after some
> > > debugging found this one. I think it's a good idea to have macros to
> > > determine whether an entity exposes a V4L2 sub-device interface but it
> > > should be more robust than is_media_entity_v4l2_subdev() right now is.
> > 
> > Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
> > actually a separate graph object (interfaces). Those macros work at the
> > entities, not at the interface objects.
> 
> is_media_entity_v4l2_subdev() will produce wrong results for a large part of
> V4L2 sub-devices with these patches applied.
> 
> I checked again the original implementation, and it seems to be based only
> on the type as well, albeit that's a range, not a set of different
> functions.

Yes. As we're getting rid of ranges for subdevs, we need to change the
implementation. Your patch does the job by recognizing the "unknown"
subdevs.

> I suppose this will change at some point in the future: the interface indeed
> should not be determined by the function of the entity. At least it needs to
> be fixed now until the rework. I'll submit a patch for that.
> 

Thanks!

Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8.2 19/55] [media] media: convert links from array to list
  2015-09-06 12:02       ` Mauro Carvalho Chehab
@ 2015-11-23 15:37         ` Laurent Pinchart
  2015-11-23 15:41           ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-11-23 15:37 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Akihiro Tsukada, Antti Palosaari,
	Jonathan Corbet, Stefan Richter, Tina Ruchandani, Dan Carpenter,
	Rafael Lourenço de Lima Chehab, Hans Verkuil, Shuah Khan,
	Lad, Prabhakar, Julia Lawall, Sakari Ailus, Boris BREZILLON

Hi Mauro,

(Resending as I've replied by mistake to the version of the patch you had sent 
to the media workshop list only)

Thank you for the patch.

On Monday 12 October 2015 13:43:13 Mauro Carvalho Chehab wrote:
> The entire logic that represent graph links were developed on a
> time where there were no needs to dynamic remove links. So,
> although links are created/removed one by one via some
> functions, they're stored as an array inside the entity struct.
> 
> As the array may grow, there's a logic inside the code that
> checks if the amount of space is not enough to store
> the needed links. If it isn't the core uses krealloc()
> to change the size of the link, with is bad, as it
> leaves the memory fragmented.

I agree with the change made in this patch, but I'm not sure if fragmentation 
is really the issue. I wouldn't be surprised if we ended up with more 
fragmented memory.

> So, convert links into a list.
> 
> Also, currently,  both source and sink entities need the link
> at the graph traversal logic inside media_entity. So there's
> a logic duplicating all links. That makes it to spend
> twice the memory needed. This is not a big deal for today's
> usage, where the number of links are not big.
> 
> Yet, if during the MC workshop discussions, it was said that
> IIO graphs could have up to 4,000 entities. So, we may
> want to remove the duplication on some future. The problem
> is that it would require a separate linked list to store
> the backlinks inside the entity, or to use a more complex
> algorithm to do graph backlink traversal, with is something
> that the current graph traversal inside the core can't cope
> with. So, let's postpone a such change if/when it is actually
> needed.

The media_link structure uses 44 bytes on 32-bit architectures and 84 bytes on 
64-bit architecture. It will thus be allocated out of the 64-bytes and 96-
bytes pools respectively. That's a 12.5% memory waste on 64-bit architectures 
and 31.25% on 32-bit architecture. If you're concerned about memory usage (and 
I think we all should) a linked list is less efficient than an array in this 
case (and even more so if you take the struct list_head into account).

> Change-Id: I558e8f87f200fe5f83ddaafe5560f91f0d906b63

No need to infect mainline with gerrit nonsense 

> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> ---
>  drivers/media/dvb-core/dvb_frontend.c     |   9 +--
>  drivers/media/media-device.c              |  25 +++---
>  drivers/media/media-entity.c              | 128 ++++++++++++---------------
>  drivers/media/usb/au0828/au0828-core.c    |  12 ++-
>  drivers/media/usb/au0828/au0828-video.c   |   8 +-
>  drivers/media/usb/cx231xx/cx231xx-video.c |   8 +-
>  include/media/media-entity.h              |  10 +--
>  7 files changed, 97 insertions(+), 103 deletions(-)

[snip]

> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 0d85c6c28004..3e649cacfc07 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -25,6 +25,7 @@
>  #include <linux/ioctl.h>
>  #include <linux/media.h>
>  #include <linux/types.h>
> +#include <linux/slab.h>

Could you please keep headers sorted alphabetically ?

>  #include <media/media-device.h>
>  #include <media/media-devnode.h>

[snip]

> @@ -150,22 +151,21 @@ static long __media_device_enum_links(struct
> media_device *mdev, }
> 
>       if (links->links) {
> -             struct media_link_desc __user *ulink;
> -             unsigned int l;
> +             struct media_link *ent_link;
> +             struct media_link_desc __user *ulink = links->links;

Might be slightly nitpicking, but I think variables would be more coherent if 
they were called

                struct media_link_desc __user *ulink = links->links;
                struct media_link *link;

...

> 
> -             for (l = 0, ulink = links->links; l < entity->num_links; l++) 
{
> +             list_for_each_entry(ent_link, &entity->links, list) {
>                       struct media_link_desc link;

and

                        struct media_link_desc klink;

here.

>                       /* Ignore backlinks. */
> -                     if (entity->links[l].source->entity != entity)
> +                     if (ent_link->source->entity != entity)
>                               continue;
> -
>                       memset(&link, 0, sizeof(link));
> -                     media_device_kpad_to_upad(entity->links[l].source,
> +                     media_device_kpad_to_upad(ent_link->source,
>                                                 &link.source);
> -                     media_device_kpad_to_upad(entity->links[l].sink,
> +                     media_device_kpad_to_upad(ent_link->sink,
>                                                 &link.sink);
> -                     link.flags = entity->links[l].flags;
> +                     link.flags = ent_link->flags;
>                       if (copy_to_user(ulink, &link, sizeof(*ulink)))
>                               return -EFAULT;
>                       ulink++;
> @@ -437,6 +437,7 @@ int __must_check media_device_register_entity(struct
> media_device *mdev, /* Warn if we apparently re-register an entity */
>       WARN_ON(entity->graph_obj.mdev != NULL);
>       entity->graph_obj.mdev = mdev;
> +     INIT_LIST_HEAD(&entity->links);

I'd move this to media_entity_init(). I've spent time wondering how the code 
could work without crashing during testing as the list wasn't initialized in 
media_entity_init().

Speaking of testing, have you checked for memory leaks with kmemleak ? Given 
the extent of the rework I think this should really be tested.

> 
>       spin_lock(&mdev->lock);
>       /* Initialize media_gobj embedded at the entity */
> @@ -465,13 +466,17 @@ void media_device_unregister_entity(struct
> media_entity *entity) {
>       int i;
>       struct media_device *mdev = entity->graph_obj.mdev;
> +     struct media_link *link, *tmp;
> 
>       if (mdev == NULL)
>               return;
> 
>       spin_lock(&mdev->lock);
> -     for (i = 0; i < entity->num_links; i++)
> -             media_gobj_remove(&entity->links[i].graph_obj);
> +     list_for_each_entry_safe(link, tmp, &entity->links, list) {
> +             media_gobj_remove(&link->graph_obj);
> +             list_del(&link->list);
> +             kfree(link);

Shouldn't you remove the backlinks too ? How about calling 
__media_entity_remove_link() to centralize the link removal code ?

> +     }
>       for (i = 0; i < entity->num_pads; i++)
>               media_gobj_remove(&entity->pads[i].graph_obj);
>       media_gobj_remove(&entity->graph_obj);
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 0926f08be981..d5efa0e2c88c 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -221,21 +221,13 @@ int
>  media_entity_init(struct media_entity *entity, u16 num_pads,
>                 struct media_pad *pads)
>  {
> -     struct media_link *links;
> -     unsigned int max_links = num_pads;
>       unsigned int i;
> 
> -     links = kzalloc(max_links * sizeof(links[0]), GFP_KERNEL);
> -     if (links == NULL)
> -             return -ENOMEM;
> -

Now that the function doesn't allocate links anymore you should fix its 
kerneldoc that still mentions preallocation.

>       entity->group_id = 0;
> -     entity->max_links = max_links;
>       entity->num_links = 0;
>       entity->num_backlinks = 0;
>       entity->num_pads = num_pads;
>       entity->pads = pads;
> -     entity->links = links;
> 
>       for (i = 0; i < num_pads; i++) {
>               pads[i].entity = entity;
> @@ -249,7 +241,13 @@ EXPORT_SYMBOL_GPL(media_entity_init);
>  void
>  media_entity_cleanup(struct media_entity *entity)
>  {
> -     kfree(entity->links);
> +     struct media_link *link, *tmp;
> +
> +     list_for_each_entry_safe(link, tmp, &entity->links, list) {
> +             media_gobj_remove(&link->graph_obj);
> +             list_del(&link->list);
> +             kfree(link);
> +     }
>  }
>  EXPORT_SYMBOL_GPL(media_entity_cleanup);
> 
> @@ -275,7 +273,7 @@ static void stack_push(struct media_entity_graph *graph,
> return;
>       }
>       graph->top++;
> -     graph->stack[graph->top].link = 0;
> +     graph->stack[graph->top].link = (&entity->links)->next;

Anything wrong with entity->links.next ?

>       graph->stack[graph->top].entity = entity;
>  }
> 
> @@ -317,6 +315,7 @@ void media_entity_graph_walk_start(struct
> media_entity_graph *graph, }
>  EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
> 
> +

No need for an extra blank line.

>  /**
>   * media_entity_graph_walk_next - Get the next entity in the graph
>   * @graph: Media graph structure
> @@ -340,14 +339,16 @@ media_entity_graph_walk_next(struct media_entity_graph
> *graph) * top of the stack until no more entities on the level can be
>        * found.
>        */
> -     while (link_top(graph) < stack_top(graph)->num_links) {
> +     while (link_top(graph) != &(stack_top(graph)->links)) {

No need for parentheses around the second operand of !=.

>               struct media_entity *entity = stack_top(graph);
> -             struct media_link *link = &entity->links[link_top(graph)];
> +             struct media_link *link;
>               struct media_entity *next;
> 
> +             link = list_entry(link_top(graph), typeof(*link), list);
> +
>               /* The link is not enabled so we do not follow. */
>               if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {
> -                     link_top(graph)++;
> +                     link_top(graph) = link_top(graph)->next;
>                       continue;
>               }

[snip]

> @@ -395,6 +396,7 @@ __must_check int media_entity_pipeline_start(struct
> media_entity *entity, struct media_device *mdev = entity->graph_obj.mdev;
>       struct media_entity_graph graph;
>       struct media_entity *entity_err = entity;
> +     struct media_link *link;

Nitpicking, I would have placed the variable declaration inside of the while 
loop, where i was declared.

>       int ret;
> 
>       mutex_lock(&mdev->graph_mutex);
> @@ -404,7 +406,6 @@ __must_check int media_entity_pipeline_start(struct
> media_entity *entity, while ((entity =
> media_entity_graph_walk_next(&graph))) {
>               DECLARE_BITMAP(active, entity->num_pads);
>               DECLARE_BITMAP(has_no_links, entity->num_pads);
> -             unsigned int i;
> 
>               entity->stream_count++;
>               WARN_ON(entity->pipe && entity->pipe != pipe);
> @@ -420,8 +421,7 @@ __must_check int media_entity_pipeline_start(struct
> media_entity *entity, bitmap_zero(active, entity->num_pads);
>               bitmap_fill(has_no_links, entity->num_pads);
> 
> -             for (i = 0; i < entity->num_links; i++) {
> -                     struct media_link *link = &entity->links[i];
> +             list_for_each_entry(link, &entity->links, list) {
>                       struct media_pad *pad = link->sink->entity == entity
>                                               ? link->sink : link->source;

[snip]

> +static void __media_entity_remove_link(struct media_entity *entity,
> +                                    struct media_link *link);
> +

No forward declaration please, let's reorder functions instead.

>  int
>  media_create_pad_link(struct media_entity *source, u16 source_pad,
>                        struct media_entity *sink, u16 sink_pad, u32 flags)

[snip]

> -void __media_entity_remove_links(struct media_entity *entity)
> +static void __media_entity_remove_link(struct media_entity *entity,
> +                                    struct media_link *link)

No need for a __ in the function name, there's not media_entity_remove_link() 
function.

>  {
> -     unsigned int i;
> +     struct media_link *rlink, *tmp;
> +     struct media_entity *remote;
> +     unsigned int r = 0;
> +
> +     if (link->source->entity == entity)
> +             remote = link->sink->entity;
> +     else
> +             remote = link->source->entity;
> 
> -     for (i = 0; i < entity->num_links; i++) {
> -             struct media_link *link = &entity->links[i];
> -             struct media_entity *remote;
> -             unsigned int r = 0;
> +     list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
> +             if (rlink != link->reverse) {
> +                     r++;

The variable is incremented here but otherwise never used, you can remove it.

> +                     continue;
> +             }
> 
>               if (link->source->entity == entity)
> -                     remote = link->sink->entity;
> -             else
> -                     remote = link->source->entity;
> +                     remote->num_backlinks--;
> 
> -             while (r < remote->num_links) {
> -                     struct media_link *rlink = &remote->links[r];
> -
> -                     if (rlink != link->reverse) {
> -                             r++;
> -                             continue;
> -                     }
> +             if (--remote->num_links == 0)
> +                     break;
> 
> -                     if (link->source->entity == entity)
> -                             remote->num_backlinks--;
> +             /* Remove the remote link */

Shouldn't you call media_gobj_remove() ?

> +             list_del(&rlink->list);
> +             kfree(rlink);
> +     }

And here too ?

> +     list_del(&link->list);
> +     kfree(link);
> +}
> 
> -                     if (--remote->num_links == 0)
> -                             break;
> +void __media_entity_remove_links(struct media_entity *entity)
> +{
> +     struct media_link *link, *tmp;
> 
> -                     /* Insert last entry in place of the dropped link. */
> -                     *rlink = remote->links[remote->num_links];
> -             }
> -     }
> +     list_for_each_entry_safe(link, tmp, &entity->links, list)
> +             __media_entity_remove_link(entity, link);
> 
>       entity->num_links = 0;
>       entity->num_backlinks = 0;

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8.2 19/55] [media] media: convert links from array to list
  2015-11-23 15:37         ` Laurent Pinchart
@ 2015-11-23 15:41           ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-11-23 15:41 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Akihiro Tsukada, Antti Palosaari,
	Jonathan Corbet, Stefan Richter, Tina Ruchandani, Dan Carpenter,
	Rafael Lourenço de Lima Chehab, Hans Verkuil, Shuah Khan,
	Lad, Prabhakar, Julia Lawall, Sakari Ailus, Boris BREZILLON

Em Mon, 23 Nov 2015 17:37:54 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> (Resending as I've replied by mistake to the version of the patch you had sent 
> to the media workshop list only)

(resending my answer to your previously sent review to the WS only ML.
 The e-mail contents is the same as the previously sent one)

> 
> Thank you for the patch.
> 

Hi Laurent,

I'll be addressing the points below on separate patches, to avoid rebasing
it and causing the need for we all (me, Shuah, Javier, Sakari) to re-test
everything after patch 24 again. This way, if a regression happens, we know
what change to blame ;)

Regards,
Mauro

Em Mon, 23 Nov 2015 15:30:36 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Monday 12 October 2015 13:43:13 Mauro Carvalho Chehab wrote:  
> > The entire logic that represent graph links were developed on a
> > time where there were no needs to dynamic remove links. So,
> > although links are created/removed one by one via some
> > functions, they're stored as an array inside the entity struct.
> > 
> > As the array may grow, there's a logic inside the code that
> > checks if the amount of space is not enough to store
> > the needed links. If it isn't the core uses krealloc()
> > to change the size of the link, with is bad, as it
> > leaves the memory fragmented.  
> 
> I agree with the change made in this patch, but I'm not sure if fragmentation 
> is really the issue. I wouldn't be surprised if we ended up with more 
> fragmented memory.  

That would actually depend on how things get allocated/deallocated.

If we discover that fragmentation is actually increasing, we could
change the code later to use a lookaside cache.

>   
> > So, convert links into a list.
> > 
> > Also, currently,  both source and sink entities need the link
> > at the graph traversal logic inside media_entity. So there's
> > a logic duplicating all links. That makes it to spend
> > twice the memory needed. This is not a big deal for today's
> > usage, where the number of links are not big.
> > 
> > Yet, if during the MC workshop discussions, it was said that
> > IIO graphs could have up to 4,000 entities. So, we may
> > want to remove the duplication on some future. The problem
> > is that it would require a separate linked list to store
> > the backlinks inside the entity, or to use a more complex
> > algorithm to do graph backlink traversal, with is something
> > that the current graph traversal inside the core can't cope
> > with. So, let's postpone a such change if/when it is actually
> > needed.  
> 
> The media_link structure uses 44 bytes on 32-bit architectures and 84 bytes on 
> 64-bit architecture. It will thus be allocated out of the 64-bytes and 96-
> bytes pools respectively. That's a 12.5% memory waste on 64-bit architectures 
> and 31.25% on 32-bit architecture. If you're concerned about memory usage (and 
> I think we all should) a linked list is less efficient than an array in this 
> case (and even more so if you take the struct list_head into account).  

I doubt that the amount of memory spent at the media controller
would actually cause impact, as the size of those structs are a
way smaller than the size of video buffers. Anyway, if we found
later that this would cause troubles, we can redesign it.

>   
> > Change-Id: I558e8f87f200fe5f83ddaafe5560f91f0d906b63  
> 
> No need to infect mainline with gerrit nonsense :-)  

I'm not using gerrit ;) I'm just adding this crap because the change ID
is a good way to detect if a patch is new or not. I have some scripts
that use those IDs to detect it, when working with this 80+ patch series.

In any case, the scripts I use to pull patches at the main tree will
remove those stuff.

>   
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > ---
> >  drivers/media/dvb-core/dvb_frontend.c     |   9 +--
> >  drivers/media/media-device.c              |  25 +++---
> >  drivers/media/media-entity.c              | 128 ++++++++++++---------------
> >  drivers/media/usb/au0828/au0828-core.c    |  12 ++-
> >  drivers/media/usb/au0828/au0828-video.c   |   8 +-
> >  drivers/media/usb/cx231xx/cx231xx-video.c |   8 +-
> >  include/media/media-entity.h              |  10 +--
> >  7 files changed, 97 insertions(+), 103 deletions(-)  
> 
> [snip]
>   
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index 0d85c6c28004..3e649cacfc07 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -25,6 +25,7 @@
> >  #include <linux/ioctl.h>
> >  #include <linux/media.h>
> >  #include <linux/types.h>
> > +#include <linux/slab.h>  
> 
> Could you please keep headers sorted alphabetically ?  

Ok, I'll reorder on a later patch.

>   
> >  #include <media/media-device.h>
> >  #include <media/media-devnode.h>  
> 
> [snip]
>   
> > @@ -150,22 +151,21 @@ static long __media_device_enum_links(struct
> > media_device *mdev, }
> > 
> >  	if (links->links) {
> > -		struct media_link_desc __user *ulink;
> > -		unsigned int l;
> > +		struct media_link *ent_link;
> > +		struct media_link_desc __user *ulink = links->links;  
> 
> Might be slightly nitpicking, but I think variables would be more coherent if 
> they were called
> 
> 		struct media_link_desc __user *ulink = links->links;
> 		struct media_link *link;  

Nomenclatures tend to generate endless discussions ;)

IMO, calling it as "link" here is confusing, as it is not clear if
this is a Kernel or an Userspace "link"...

> 
> ...
>   
> > 
> > -		for (l = 0, ulink = links->links; l < entity->num_links; l++) {
> > +		list_for_each_entry(ent_link, &entity->links, list) {
> >  			struct media_link_desc link;  
> 
> and
> 
> 			struct media_link_desc klink;  

and calling it as "klink" is confusing to me ;) as this is the struct
defined at the userspace API, and not the struct defined at the
Kernelspace ABI.

Perhaps we could call those media_link_desc as "klink_desc" and
"ulink_desc", instead.

> 
> here.
>   
> >  			/* Ignore backlinks. */
> > -			if (entity->links[l].source->entity != entity)
> > +			if (ent_link->source->entity != entity)
> >  				continue;
> > -
> >  			memset(&link, 0, sizeof(link));
> > -			media_device_kpad_to_upad(entity->links[l].source,
> > +			media_device_kpad_to_upad(ent_link->source,
> >  						  &link.source);
> > -			media_device_kpad_to_upad(entity->links[l].sink,
> > +			media_device_kpad_to_upad(ent_link->sink,
> >  						  &link.sink);
> > -			link.flags = entity->links[l].flags;
> > +			link.flags = ent_link->flags;
> >  			if (copy_to_user(ulink, &link, sizeof(*ulink)))
> >  				return -EFAULT;
> >  			ulink++;
> > @@ -437,6 +437,7 @@ int __must_check media_device_register_entity(struct
> > media_device *mdev, /* Warn if we apparently re-register an entity */
> >  	WARN_ON(entity->graph_obj.mdev != NULL);
> >  	entity->graph_obj.mdev = mdev;
> > +	INIT_LIST_HEAD(&entity->links);  
> 
> I'd move this to media_entity_init(). I've spent time wondering how the code 
> could work without crashing during testing as the list wasn't initialized in 
> media_entity_init().  

I wrote this code lots of months ago... I guess there was a reason for this
to be here, and not there, but I can't remember why.

I'll give it a try.

> 
> Speaking of testing, have you checked for memory leaks with kmemleak ? Given 
> the extent of the rework I think this should really be tested.  

No, I didn't. I'm not sure if au0828 currently passes on kmemleak
or not. What I did is I checked that all created graph objects were
removed, via enabling the dynamic_prinks at the graph object init/remove
functions.

>   
> > 
> >  	spin_lock(&mdev->lock);
> >  	/* Initialize media_gobj embedded at the entity */
> > @@ -465,13 +466,17 @@ void media_device_unregister_entity(struct
> > media_entity *entity) {
> >  	int i;
> >  	struct media_device *mdev = entity->graph_obj.mdev;
> > +	struct media_link *link, *tmp;
> > 
> >  	if (mdev == NULL)
> >  		return;
> > 
> >  	spin_lock(&mdev->lock);
> > -	for (i = 0; i < entity->num_links; i++)
> > -		media_gobj_remove(&entity->links[i].graph_obj);
> > +	list_for_each_entry_safe(link, tmp, &entity->links, list) {
> > +		media_gobj_remove(&link->graph_obj);
> > +		list_del(&link->list);
> > +		kfree(link);  
> 
> Shouldn't you remove the backlinks too ? How about calling 
> __media_entity_remove_link() to centralize the link removal code ?  

Yes. I'll use __media_entity_remove_link() here.

>   
> > +	}
> >  	for (i = 0; i < entity->num_pads; i++)
> >  		media_gobj_remove(&entity->pads[i].graph_obj);
> >  	media_gobj_remove(&entity->graph_obj);
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index 0926f08be981..d5efa0e2c88c 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -221,21 +221,13 @@ int
> >  media_entity_init(struct media_entity *entity, u16 num_pads,
> >  		  struct media_pad *pads)
> >  {
> > -	struct media_link *links;
> > -	unsigned int max_links = num_pads;
> >  	unsigned int i;
> > 
> > -	links = kzalloc(max_links * sizeof(links[0]), GFP_KERNEL);
> > -	if (links == NULL)
> > -		return -ENOMEM;
> > -  
> 
> Now that the function doesn't allocate links anymore you should fix its 
> kerneldoc that still mentions preallocation.  

OK.

> >  	entity->group_id = 0;
> > -	entity->max_links = max_links;
> >  	entity->num_links = 0;
> >  	entity->num_backlinks = 0;
> >  	entity->num_pads = num_pads;
> >  	entity->pads = pads;
> > -	entity->links = links;
> > 
> >  	for (i = 0; i < num_pads; i++) {
> >  		pads[i].entity = entity;
> > @@ -249,7 +241,13 @@ EXPORT_SYMBOL_GPL(media_entity_init);
> >  void
> >  media_entity_cleanup(struct media_entity *entity)
> >  {
> > -	kfree(entity->links);
> > +	struct media_link *link, *tmp;
> > +
> > +	list_for_each_entry_safe(link, tmp, &entity->links, list) {
> > +		media_gobj_remove(&link->graph_obj);
> > +		list_del(&link->list);
> > +		kfree(link);
> > +	}
> >  }
> >  EXPORT_SYMBOL_GPL(media_entity_cleanup);
> > 
> > @@ -275,7 +273,7 @@ static void stack_push(struct media_entity_graph *graph,
> > return;
> >  	}
> >  	graph->top++;
> > -	graph->stack[graph->top].link = 0;
> > +	graph->stack[graph->top].link = (&entity->links)->next;  
> 
> Anything wrong with entity->links.next ?  

No, but I use a regex to find all the occurrences of the previous
struct ;)

I'll change it.

>   
> >  	graph->stack[graph->top].entity = entity;
> >  }
> > 
> > @@ -317,6 +315,7 @@ void media_entity_graph_walk_start(struct
> > media_entity_graph *graph, }
> >  EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
> > 
> > +  
> 
> No need for an extra blank line.  

OK.

> >  /**
> >   * media_entity_graph_walk_next - Get the next entity in the graph
> >   * @graph: Media graph structure
> > @@ -340,14 +339,16 @@ media_entity_graph_walk_next(struct media_entity_graph
> > *graph) * top of the stack until no more entities on the level can be
> >  	 * found.
> >  	 */
> > -	while (link_top(graph) < stack_top(graph)->num_links) {
> > +	while (link_top(graph) != &(stack_top(graph)->links)) {  
> 
> No need for parentheses around the second operand of !=.  

Ok, I'll remove it.

> >  		struct media_entity *entity = stack_top(graph);
> > -		struct media_link *link = &entity->links[link_top(graph)];
> > +		struct media_link *link;
> >  		struct media_entity *next;
> > 
> > +		link = list_entry(link_top(graph), typeof(*link), list);
> > +
> >  		/* The link is not enabled so we do not follow. */
> >  		if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {
> > -			link_top(graph)++;
> > +			link_top(graph) = link_top(graph)->next;
> >  			continue;
> >  		}  
> 
> [snip]
>   
> > @@ -395,6 +396,7 @@ __must_check int media_entity_pipeline_start(struct
> > media_entity *entity, struct media_device *mdev = entity->graph_obj.mdev;
> >  	struct media_entity_graph graph;
> >  	struct media_entity *entity_err = entity;
> > +	struct media_link *link;  
> 
> Nitpicking, I would have placed the variable declaration inside of the while 
> loop, where i was declared.  

OK.

> >  	int ret;
> > 
> >  	mutex_lock(&mdev->graph_mutex);
> > @@ -404,7 +406,6 @@ __must_check int media_entity_pipeline_start(struct
> > media_entity *entity, while ((entity =
> > media_entity_graph_walk_next(&graph))) {
> >  		DECLARE_BITMAP(active, entity->num_pads);
> >  		DECLARE_BITMAP(has_no_links, entity->num_pads);
> > -		unsigned int i;
> > 
> >  		entity->stream_count++;
> >  		WARN_ON(entity->pipe && entity->pipe != pipe);
> > @@ -420,8 +421,7 @@ __must_check int media_entity_pipeline_start(struct
> > media_entity *entity, bitmap_zero(active, entity->num_pads);
> >  		bitmap_fill(has_no_links, entity->num_pads);
> > 
> > -		for (i = 0; i < entity->num_links; i++) {
> > -			struct media_link *link = &entity->links[i];
> > +		list_for_each_entry(link, &entity->links, list) {
> >  			struct media_pad *pad = link->sink->entity == entity
> >  						? link->sink : link->source;  
> 
> [snip]
>   
> > +static void __media_entity_remove_link(struct media_entity *entity,
> > +				       struct media_link *link);
> > +  
> 
> No forward declaration please, let's reorder functions instead.  

OK.

>   
> >  int
> >  media_create_pad_link(struct media_entity *source, u16 source_pad,
> >  			 struct media_entity *sink, u16 sink_pad, u32 flags)  
> 
> [snip]

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 17/55] [media] omap3isp: separate links creation from entities init
  2015-08-30  3:06 ` [PATCH v8 17/55] [media] omap3isp: separate links creation from entities init Mauro Carvalho Chehab
@ 2015-11-23 15:55   ` Laurent Pinchart
  2015-11-23 16:22     ` Javier Martinez Canillas
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-11-23 15:55 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Javier Martinez Canillas,
	Mauro Carvalho Chehab

Hi Javier and Mauro,

Thank you for the patch.

On Monday 12 October 2015 13:43:05 Mauro Carvalho Chehab wrote:
> From: Javier Martinez Canillas <javier@osg.samsung.com>
> 
> The omap3isp driver initializes the entities and creates the pads links
> before the entities are registered with the media device. This does not
> work now that object IDs are used to create links so the media_device
> has to be set.
> 
> Split out the pads links creation from the entity initialization so are
> made after the entities registration.

Is a part of this sentence missing ?

> Suggested-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> 
> Series-to: linux-kernel@vger.kernel.org
> Series-cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Series-cc: linux-media@vger.kernel.org
> Series-cc: Shuah Khan <shuahkh@osg.samsung.com>
> Series-cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> Cover-letter:

I don't think those are known tags. Could you rework the commit message to 
merge both part into something coherent without copying the cover letter ?

> Patches to test MC next gen patches in OMAP3 ISP
> Hello,
> 
> This series contains two patches that are needed to test the
> "[PATCH v7 00/44] MC next generation patches" [0] in a OMAP3
> board by using the omap3isp driver.
> 
> I found two issues during testing, the first one is that the
> media_entity_cleanup() function tries to empty the pad links
> list but the list is initialized when a entity is registered
> causing a NULL pointer deference error.
> 
> The second issue is that the omap3isp driver creates links
> when the entities are initialized but before the media device
> is registered causing a NULL pointer deference as well.
> 
> Patch 1/1 fixes the first issue by removing the links list
> empty logic from media_entity_cleanup() since that is made
> in media_device_unregister_entity() and 2/2 fixes the second
> issue by separating the entities initialization from the pads
> links creation after the entities have been registered.
> 
> Patch 1/1 was posted before [1] but forgot to add the [media]
> prefix in the subject line so I'm including in this set again.
> Sorry about that.
> 
> The testing was made on an OMAP3 DM3735 IGEPv2 board and test
> that the media-ctl -p prints out the topology. More extensive
> testing will be made but I wanted to share these patches in
> order to make easier for other people that were looking at it.
> 
> [0]: https://www.mail-archive.com/linux-media@vger.kernel.org/msg91528.html
> [1]: https://lkml.org/lkml/2015/8/24/649
> 
> Best regards,
> Javier
> END
> 
> Change-Id: I44abb9b67d6378cbd54ba4e0673a5d6d5721fc77

No gerrit craziness please.

> ---
>  drivers/media/platform/omap3isp/isp.c        | 152 ++++++++++++++----------
>  drivers/media/platform/omap3isp/ispccdc.c    |  22 ++--
>  drivers/media/platform/omap3isp/ispccdc.h    |   1 +
>  drivers/media/platform/omap3isp/ispccp2.c    |  22 ++--
>  drivers/media/platform/omap3isp/ispccp2.h    |   1 +
>  drivers/media/platform/omap3isp/ispcsi2.c    |  22 ++--
>  drivers/media/platform/omap3isp/ispcsi2.h    |   1 +
>  drivers/media/platform/omap3isp/isppreview.c |  33 +++---
>  drivers/media/platform/omap3isp/isppreview.h |   1 +
>  drivers/media/platform/omap3isp/ispresizer.c |  33 +++---
>  drivers/media/platform/omap3isp/ispresizer.h |   1 +
>  11 files changed, 185 insertions(+), 104 deletions(-)
> 
> diff --git a/drivers/media/platform/omap3isp/isp.c
> b/drivers/media/platform/omap3isp/isp.c index aa13b17d19a0..b8f6f81d2db2
> 100644
> --- a/drivers/media/platform/omap3isp/isp.c
> +++ b/drivers/media/platform/omap3isp/isp.c
> @@ -1933,6 +1933,100 @@ done:
>  	return ret;
>  }
> 
> +/*
> + * isp_create_pads_links - Pads links creation for the subdevices
> + * @isp : Pointer to ISP device

Missing blank line here. And missing description of the function for that 
matter. You can use

"This function creates all links between ISP internal and external entities."

> + * return negative error code or zero on success

In kerneldoc style that should be

Return: A negative error code on failure or zero on success. Possible error 
codes are those returned by media_create_pad_link().

Same for the other functions below, the return line should start with 
"Return:".

> + */
> +static int isp_create_pads_links(struct isp_device *isp)

This should be called isp_create_pad_links() if you want the include the pad 
prefix, but I'd just name it isp_create_links() as the driver doesn't handle 
any other kind of links. Same for all the *_create_pads_links() functions 
below.

> +{
> +	int ret;
> +
> +	ret = omap3isp_csi2_create_pads_links(isp);
> +	if (ret < 0) {
> +		dev_err(isp->dev, "CSI2 pads links creation failed\n");

That's lots of error strings. You would save memory by turning the messages 
into "%s pads links creation failed\n", "CSI2" as the compiler will then avoid 
multiple copies of the first string.

I would actually remove the messages as the only source of error is a memory 
allocation failure, which will already print a message. You could add a single 
dev_err() in the location where isp_create_pads_links() is called if you want 
to.

> +		return ret;
> +	}
> +
> +	ret = omap3isp_ccp2_create_pads_links(isp);
> +	if (ret < 0) {
> +		dev_err(isp->dev, "CCP2 pads links creation failed\n");
> +		return ret;
> +	}
> +
> +	ret = omap3isp_ccdc_create_pads_links(isp);
> +	if (ret < 0) {
> +		dev_err(isp->dev, "CCDC pads links creation failed\n");
> +		return ret;
> +	}
> +
> +	ret = omap3isp_preview_create_pads_links(isp);
> +	if (ret < 0) {
> +		dev_err(isp->dev, "Preview pads links creation failed\n");
> +		return ret;
> +	}
> +
> +	ret = omap3isp_resizer_create_pads_links(isp);
> +	if (ret < 0) {
> +		dev_err(isp->dev, "Resizer pads links creation failed\n");
> +		return ret;
> +	}
> +
> +	/* Connect the submodules. */

I'd write "Create links between entities." and add a comment at the beginning 
of the function that states "Create links between entities and video nodes.".

> +	ret = media_create_pad_link(
> +			&isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
> +			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = media_create_pad_link(
> +			&isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
> +			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = media_create_pad_link(
> +			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
> +			&isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = media_create_pad_link(
> +			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
> +			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = media_create_pad_link(
> +			&isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
> +			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = media_create_pad_link(
> +			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
> +			&isp->isp_aewb.subdev.entity, 0,
> +			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = media_create_pad_link(
> +			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
> +			&isp->isp_af.subdev.entity, 0,
> +			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = media_create_pad_link(
> +			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
> +			&isp->isp_hist.subdev.entity, 0,
> +			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;
> +}

[snip]

> @@ -2468,6 +2508,10 @@ static int isp_probe(struct platform_device *pdev)
>  	if (ret < 0)
>  		goto error_modules;
> 
> +	ret = isp_create_pads_links(isp);
> +	if (ret < 0)
> +		goto error_register_entities;
> +
>  	isp->notifier.bound = isp_subdev_notifier_bound;
>  	isp->notifier.complete = isp_subdev_notifier_complete;
> 
> diff --git a/drivers/media/platform/omap3isp/ispccdc.c
> b/drivers/media/platform/omap3isp/ispccdc.c index
> 27555e4f4aa8..9a811f5741fa 100644
> --- a/drivers/media/platform/omap3isp/ispccdc.c
> +++ b/drivers/media/platform/omap3isp/ispccdc.c
> @@ -2666,16 +2666,8 @@ static int ccdc_init_entities(struct isp_ccdc_device
> *ccdc) if (ret < 0)
>  		goto error_video;
> 
> -	/* Connect the CCDC subdev to the video node. */
> -	ret = media_create_pad_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
> -			&ccdc->video_out.video.entity, 0, 0);
> -	if (ret < 0)
> -		goto error_link;
> -
>  	return 0;
> 
> -error_link:
> -	omap3isp_video_cleanup(&ccdc->video_out);
>  error_video:

As there's now a single error label I'd rename it to just "error:". Same 
comment for the other ISP modules.

>  	media_entity_cleanup(me);
>  	return ret;
> @@ -2721,6 +2713,20 @@ int omap3isp_ccdc_init(struct isp_device *isp)
>  }
> 
>  /*
> + * omap3isp_ccdc_create_pads_links - CCDC pads links creation
> + * @isp : Pointer to ISP device
> + * return negative error code or zero on success
> + */
> +int omap3isp_ccdc_create_pads_links(struct isp_device *isp)
> +{
> +	struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
> +
> +	/* Connect the CCDC subdev to the video node. */
> +	return media_create_pad_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
> +				     &ccdc->video_out.video.entity, 0, 0);
> +}

Given that this function and the other similar functions for other modules 
just link entities and video devices, it could make sense to inline them 
directly in the caller in order to group all the link create calls together. 
No strong opinion though, I'll leave it up to you and on whether you want to 
fix the kerneldoc or remove it ;-)

> +
> +/*
>   * omap3isp_ccdc_cleanup - CCDC module cleanup.
>   * @isp: Device pointer specific to the OMAP3 ISP.
>   */

[snip]

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 17/55] [media] omap3isp: separate links creation from entities init
  2015-11-23 15:55   ` Laurent Pinchart
@ 2015-11-23 16:22     ` Javier Martinez Canillas
  0 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-11-23 16:22 UTC (permalink / raw)
  To: Laurent Pinchart, Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Hello Laurent,

On 11/23/2015 12:55 PM, Laurent Pinchart wrote:
> Hi Javier and Mauro,
> 
> Thank you for the patch.
>

Thanks for your feedback.
 
> On Monday 12 October 2015 13:43:05 Mauro Carvalho Chehab wrote:
>> From: Javier Martinez Canillas <javier@osg.samsung.com>
>>
>> The omap3isp driver initializes the entities and creates the pads links
>> before the entities are registered with the media device. This does not
>> work now that object IDs are used to create links so the media_device
>> has to be set.
>>
>> Split out the pads links creation from the entity initialization so are
>> made after the entities registration.
> 
> Is a part of this sentence missing ?
> 

The sentence is not clear indeed, I think it should be something like:

"so the links are created after the entities have been registered with
the media device"

>> Suggested-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
>>
>> Series-to: linux-kernel@vger.kernel.org
>> Series-cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>> Series-cc: linux-media@vger.kernel.org
>> Series-cc: Shuah Khan <shuahkh@osg.samsung.com>
>> Series-cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>
>> Cover-letter:
> 
> I don't think those are known tags. Could you rework the commit message to 
> merge both part into something coherent without copying the cover letter ?
>

Yes, sorry about that. I use patman to manage and post my patches and
forgot to remove the patman tags before handling the patches to Mauro.

I mentioned to him already and he told me that would strip the tags
before pushing to the media tree or posting the patches again.

[remove left over cover letter from a different series]

>>
>> Change-Id: I44abb9b67d6378cbd54ba4e0673a5d6d5721fc77
> 
> No gerrit craziness please.
>

I believe this is something similar, a left over from Mauro since he
uses gerrit to manage this patch series.

>> ---
>>  drivers/media/platform/omap3isp/isp.c        | 152 ++++++++++++++----------
>>  drivers/media/platform/omap3isp/ispccdc.c    |  22 ++--
>>  drivers/media/platform/omap3isp/ispccdc.h    |   1 +
>>  drivers/media/platform/omap3isp/ispccp2.c    |  22 ++--
>>  drivers/media/platform/omap3isp/ispccp2.h    |   1 +
>>  drivers/media/platform/omap3isp/ispcsi2.c    |  22 ++--
>>  drivers/media/platform/omap3isp/ispcsi2.h    |   1 +
>>  drivers/media/platform/omap3isp/isppreview.c |  33 +++---
>>  drivers/media/platform/omap3isp/isppreview.h |   1 +
>>  drivers/media/platform/omap3isp/ispresizer.c |  33 +++---
>>  drivers/media/platform/omap3isp/ispresizer.h |   1 +
>>  11 files changed, 185 insertions(+), 104 deletions(-)
>>
>> diff --git a/drivers/media/platform/omap3isp/isp.c
>> b/drivers/media/platform/omap3isp/isp.c index aa13b17d19a0..b8f6f81d2db2
>> 100644
>> --- a/drivers/media/platform/omap3isp/isp.c
>> +++ b/drivers/media/platform/omap3isp/isp.c
>> @@ -1933,6 +1933,100 @@ done:
>>  	return ret;
>>  }
>>
>> +/*
>> + * isp_create_pads_links - Pads links creation for the subdevices
>> + * @isp : Pointer to ISP device
> 
> Missing blank line here. And missing description of the function for that 
> matter. You can use
> 
> "This function creates all links between ISP internal and external entities."
> 
>> + * return negative error code or zero on success
> 
> In kerneldoc style that should be
> 
> Return: A negative error code on failure or zero on success. Possible error 
> codes are those returned by media_create_pad_link().
> 
> Same for the other functions below, the return line should start with 
> "Return:".
>

You are right, the kerneldoc is not correct. I'll fix it.

>> + */
>> +static int isp_create_pads_links(struct isp_device *isp)
> 
> This should be called isp_create_pad_links() if you want the include the pad 
> prefix, but I'd just name it isp_create_links() as the driver doesn't handle 
> any other kind of links. Same for all the *_create_pads_links() functions 
> below.
>

Ok.

>> +{
>> +	int ret;
>> +
>> +	ret = omap3isp_csi2_create_pads_links(isp);
>> +	if (ret < 0) {
>> +		dev_err(isp->dev, "CSI2 pads links creation failed\n");
> 
> That's lots of error strings. You would save memory by turning the messages 
> into "%s pads links creation failed\n", "CSI2" as the compiler will then avoid 
> multiple copies of the first string.
> 
> I would actually remove the messages as the only source of error is a memory 
> allocation failure, which will already print a message. You could add a single 
> dev_err() in the location where isp_create_pads_links() is called if you want 
> to.
>

Agreed, I'll just remove the messages.

>> +		return ret;
>> +	}
>> +
>> +	ret = omap3isp_ccp2_create_pads_links(isp);
>> +	if (ret < 0) {
>> +		dev_err(isp->dev, "CCP2 pads links creation failed\n");
>> +		return ret;
>> +	}
>> +
>> +	ret = omap3isp_ccdc_create_pads_links(isp);
>> +	if (ret < 0) {
>> +		dev_err(isp->dev, "CCDC pads links creation failed\n");
>> +		return ret;
>> +	}
>> +
>> +	ret = omap3isp_preview_create_pads_links(isp);
>> +	if (ret < 0) {
>> +		dev_err(isp->dev, "Preview pads links creation failed\n");
>> +		return ret;
>> +	}
>> +
>> +	ret = omap3isp_resizer_create_pads_links(isp);
>> +	if (ret < 0) {
>> +		dev_err(isp->dev, "Resizer pads links creation failed\n");
>> +		return ret;
>> +	}
>> +
>> +	/* Connect the submodules. */
> 
> I'd write "Create links between entities." and add a comment at the beginning 
> of the function that states "Create links between entities and video nodes.".
>

Ok.

>> +	ret = media_create_pad_link(
>> +			&isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
>> +			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
>> +	if (ret < 0)
>> +		return ret;
>> +
>> +	ret = media_create_pad_link(
>> +			&isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
>> +			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
>> +	if (ret < 0)
>> +		return ret;
>> +
>> +	ret = media_create_pad_link(
>> +			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
>> +			&isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
>> +	if (ret < 0)
>> +		return ret;
>> +
>> +	ret = media_create_pad_link(
>> +			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
>> +			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
>> +	if (ret < 0)
>> +		return ret;
>> +
>> +	ret = media_create_pad_link(
>> +			&isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
>> +			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
>> +	if (ret < 0)
>> +		return ret;
>> +
>> +	ret = media_create_pad_link(
>> +			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
>> +			&isp->isp_aewb.subdev.entity, 0,
>> +			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
>> +	if (ret < 0)
>> +		return ret;
>> +
>> +	ret = media_create_pad_link(
>> +			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
>> +			&isp->isp_af.subdev.entity, 0,
>> +			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
>> +	if (ret < 0)
>> +		return ret;
>> +
>> +	ret = media_create_pad_link(
>> +			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
>> +			&isp->isp_hist.subdev.entity, 0,
>> +			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
>> +	if (ret < 0)
>> +		return ret;
>> +
>> +	return 0;
>> +}
> 
> [snip]
> 
>> @@ -2468,6 +2508,10 @@ static int isp_probe(struct platform_device *pdev)
>>  	if (ret < 0)
>>  		goto error_modules;
>>
>> +	ret = isp_create_pads_links(isp);
>> +	if (ret < 0)
>> +		goto error_register_entities;
>> +
>>  	isp->notifier.bound = isp_subdev_notifier_bound;
>>  	isp->notifier.complete = isp_subdev_notifier_complete;
>>
>> diff --git a/drivers/media/platform/omap3isp/ispccdc.c
>> b/drivers/media/platform/omap3isp/ispccdc.c index
>> 27555e4f4aa8..9a811f5741fa 100644
>> --- a/drivers/media/platform/omap3isp/ispccdc.c
>> +++ b/drivers/media/platform/omap3isp/ispccdc.c
>> @@ -2666,16 +2666,8 @@ static int ccdc_init_entities(struct isp_ccdc_device
>> *ccdc) if (ret < 0)
>>  		goto error_video;
>>
>> -	/* Connect the CCDC subdev to the video node. */
>> -	ret = media_create_pad_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
>> -			&ccdc->video_out.video.entity, 0, 0);
>> -	if (ret < 0)
>> -		goto error_link;
>> -
>>  	return 0;
>>
>> -error_link:
>> -	omap3isp_video_cleanup(&ccdc->video_out);
>>  error_video:
> 
> As there's now a single error label I'd rename it to just "error:". Same 
> comment for the other ISP modules.
>

Ok.

>>  	media_entity_cleanup(me);
>>  	return ret;
>> @@ -2721,6 +2713,20 @@ int omap3isp_ccdc_init(struct isp_device *isp)
>>  }
>>
>>  /*
>> + * omap3isp_ccdc_create_pads_links - CCDC pads links creation
>> + * @isp : Pointer to ISP device
>> + * return negative error code or zero on success
>> + */
>> +int omap3isp_ccdc_create_pads_links(struct isp_device *isp)
>> +{
>> +	struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
>> +
>> +	/* Connect the CCDC subdev to the video node. */
>> +	return media_create_pad_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
>> +				     &ccdc->video_out.video.entity, 0, 0);
>> +}
> 
> Given that this function and the other similar functions for other modules 
> just link entities and video devices, it could make sense to inline them 
> directly in the caller in order to group all the link create calls together. 
> No strong opinion though, I'll leave it up to you and on whether you want to 
> fix the kerneldoc or remove it ;-)
>

Right, would make sense to remove them indeed and just inline in the caller.

>> +
>> +/*
>>   * omap3isp_ccdc_cleanup - CCDC module cleanup.
>>   * @isp: Device pointer specific to the OMAP3 ISP.
>>   */
> 
> [snip]
> 

Best regards,
-- 
Javier Martinez Canillas
Open Source Group
Samsung Research America

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 55/55] [media] media-entity.h: document all the structs
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-11 14:45     ` Hans Verkuil
@ 2015-11-23 20:19     ` Laurent Pinchart
  2015-12-10 18:16       ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-11-23 20:19 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:03:14 Mauro Carvalho Chehab wrote:
> Only a few structs are documented on kernel-doc-nano format
> (the ones added by the MC next gen patches).
> 
> Add a documentation for all structs, and ensure that they'll
> be producing the documentation at the Kernel's device driver
> DocBook.

Very good idea ! Please see below for some spelling mistakes or other 
corrections in addition to the ones pointed out by Hans.

> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index fb5f0e21f137..e1a89899deef 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -55,11 +55,13 @@ enum media_gobj_type {
>  /**
>   * struct media_gobj - Define a graph object.
>   *
> + * @mdev:	Pointer to the struct media_device that owns the object
>   * @id:		Non-zero object ID identifier. The ID should be unique
>   *		inside a media_device, as it is composed by
>   *		MEDIA_BITS_PER_TYPE to store the type plus
>   *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
>   *		(called as "local ID").
> + * @list:	Linked list associated to one of the per-type mdev object lists

I'd say "List entry stored in one of the ..." (or "List head" if you prefer).

>   *
>   * All objects on the media graph should have this struct embedded
>   */
> @@ -73,6 +75,28 @@ struct media_gobj {
>  struct media_pipeline {
>  };
> 
> +/**
> + * struct media_link - Define a media link graph object.

I think you can drop the "Define" and just say "A media link graph object". 
Or, rather, "A media graph link object" to mean "a link object part of a media 
graph".

Same comment for the other structures.

> + *
> + * @graph_obj:	Embedded structure containing the media object common data
> + * @list:	Linked list associated with an entity or an interface that
> + *		owns the link.
> + * @gobj0:	Part of an union. Used to get the pointer for the first
> + *		graph_object of the link.
> + * @source:	Part of an union. Used only if the first object (gobj0) is
> + *		a pad. On such case, it represents the source pad.
> + * @intf:	Part of an union. Used only if the first object (gobj0) is
> + *		an interface.
> + * @gobj1:	Part of an union. Used to get the pointer for the second
> + *		graph_object of the link.
> + * @source:	Part of an union. Used only if the second object (gobj0) is

s/gobj0/gobj1/

> + *		a pad. On such case, it represents the sink pad.
> + * @entity:	Part of an union. Used only if the second object (gobj0) is

Ditto.

> + *		an entity.
> + * @reverse:	Pointer to the link for the reverse direction of a pad to 
pad
> + *		link.
> + * @flags:	Link flags, as defined at uapi/media.h (MEDIA_LNK_FL_*)
> + */
>  struct media_link {
>  	struct media_gobj graph_obj;
>  	struct list_head list;
> @@ -86,15 +110,23 @@ struct media_link {
>  		struct media_pad *sink;
>  		struct media_entity *entity;
>  	};
> -	struct media_link *reverse;	/* Link in the reverse direction */
> -	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
> +	struct media_link *reverse;
> +	unsigned long flags;
>  };
> 
> +/**
> + * struct media_pad - Define a media pad graph object.
> + *
> + * @graph_obj:	Embedded structure containing the media object common data
> + * @entity:	Entity where this object belongs

"Entity this pad belongs to"

> + * @index:	Pad index in the entity pads array, numbered from 0 to n
> + * @flags:	Pad flags, as defined at uapi/media.h (MEDIA_PAD_FL_*)
> + */
>  struct media_pad {
>  	struct media_gobj graph_obj;	/* must be first field in struct */
> -	struct media_entity *entity;	/* Entity this pad belongs to */
> -	u16 index;			/* Pad index in the entity pads array */
> -	unsigned long flags;		/* Pad flags (MEDIA_PAD_FL_*) */
> +	struct media_entity *entity;
> +	u16 index;
> +	unsigned long flags;
>  };
> 
>  /**
> @@ -113,51 +145,73 @@ struct media_entity_operations {
>  	int (*link_validate)(struct media_link *link);
>  };
> 
> +/**
> + * struct media_entity - Define a media entity graph object.
> + *
> + * @graph_obj:	Embedded structure containing the media object common data.
> + * @name:	Entity name.
> + * @type:	Entity type, as defined at uapi/media.h (MEDIA_ENT_T_*)
> + * @revision:	Entity revision - OBSOLETE - should be removed soon.
> + * @flags:	Entity flags, as defined at uapi/media.h (MEDIA_ENT_FL_*)
> + * @group_id:	Entity group ID - OBSOLETE - should be removed soon.
> + * @num_pads:	Number of sink and source pads.
> + * @num_links:	Number of existing links, both enabled and disabled.

I'd mention there that it includes the backlinks too as it's always clearly 
apparent.

"Total number of links, forward and back, enabled and disabled"

> + * @num_backlinks: Number of backlinks
> + * @pads:	Pads array with the size defined by @num_pads.
> + * @links:	Linked list for the data links.

"List of data links" or "Linked list of data links" if you want to make it 
explicit that struct list_head is a linked list, but I think that should be 
known to the reader (and have the word link twice in the description for two 
different purpose can be slightly confusing).

> + * @ops:	Entity operations.
> + * @stream_count: Stream count for the entity.
> + * @use_count:	Use count for the entity.
> + * @pipe:	Pipeline this entity belongs to.
> + * @info:	Union with devnode information.  Kept just for backward
> + * 		compatibility.
> + * @major:	Devnode major number (zero if not applicable). Kept just

Maybe s/@major/@dev.major/ (and the same for minor) ?

> + * 		for backward compatibility.
> + * @minor:	Devnode minor number (zero if not applicable). Kept just
> + * 		for backward compatibility.

As this is an internal structure I think we should clean code up sooner than 
later and remove the major and minor fields. It will be confusing for driver 
authors otherwise. Same for the revision and group_id fields.

> + * NOTE: @stream_count and @use_count reference counts must never be
> + * negative, but are signed integers on purpose: a simple WARN_ON(<0) check
> + * can be used to detect reference count bugs that would make them
> negative.
> + */
>  struct media_entity {
>  	struct media_gobj graph_obj;	/* must be first field in struct */
> -	const char *name;		/* Entity name */
> -	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
> -	u32 revision;			/* Entity revision, driver specific */
> -	unsigned long flags;		/* Entity flags (MEDIA_ENT_FL_*) */
> -	u32 group_id;			/* Entity group ID */
> +	const char *name;
> +	u32 type;
> +	u32 revision;
> +	unsigned long flags;
> +	u32 group_id;
> 
> -	u16 num_pads;			/* Number of sink and source pads */
> -	u16 num_links;			/* Number of existing links, both
> -					 * enabled and disabled */
> -	u16 num_backlinks;		/* Number of backlinks */
> +	u16 num_pads;
> +	u16 num_links;
> +	u16 num_backlinks;
> 
> -	struct media_pad *pads;		/* Pads array (num_pads objects) */
> -	struct list_head links;		/* Pad-to-pad links list */
> +	struct media_pad *pads;
> +	struct list_head links;
> 
> -	const struct media_entity_operations *ops;	/* Entity operations */
> +	const struct media_entity_operations *ops;
> 
>  	/* Reference counts must never be negative, but are signed integers on
>  	 * purpose: a simple WARN_ON(<0) check can be used to detect reference
>  	 * count bugs that would make them negative.
>  	 */
> -	int stream_count;		/* Stream count for the entity. */
> -	int use_count;			/* Use count for the entity. */
> +	int stream_count;
> +	int use_count;
> 
> -	struct media_pipeline *pipe;	/* Pipeline this entity belongs to. */
> +	struct media_pipeline *pipe;
> 
>  	union {
> -		/* Node specifications */
>  		struct {
>  			u32 major;
>  			u32 minor;
>  		} dev;
> -
> -		/* Sub-device specifications */
> -		/* Nothing needed yet */
>  	} info;
>  };
> 
>  /**
> - * struct media_interface - Define a Kernel API interface
> + * struct media_interface - Define a media interface graph object
>   *
>   * @graph_obj:		embedded graph object
> - * @list:		Linked list used to find other interfaces that belong
> - *			to the same media controller

Usual pet peeve of mine, this should be squashed with the patch that 
introduces struct media_interface. Same for the next chunk. I would actually 
move this patch before any patch that introduces a new structure, just to 
document the existing structures, and then add documentation for new 
structures in the patches that introduce them. That would be easier to review.

>   * @links:		List of links pointing to graph entities
>   * @type:		Type of the interface as defined at the
>   *			uapi/media/media.h header, e. g.
> @@ -177,7 +231,7 @@ struct media_interface {
>  };
> 
>  /**
> - * struct media_intf_devnode - Define a Kernel API interface via a device
> node
> + * struct media_intf_devnode - Define a media interface via a device node
>   * @intf:	embedded interface object
>   * @major:	Major number of a device node

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-11 14:38     ` Hans Verkuil
@ 2015-11-23 21:10     ` Laurent Pinchart
  2015-11-24 11:25       ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-11-23 21:10 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Hans Verkuil, Sakari Ailus

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:03:13 Mauro Carvalho Chehab wrote:
> V4L2 device (and subdevice) nodes should create an interface, if the
> Media Controller support is enabled.
> 
> Please notice that radio devices should not create an entity, as radio
> input/output is either via wires or via ALSA.

I'd go one step further, video nodes should not create an entity, ever. This 
was one of the design principles behind the MC rework. We'll need to patch 
drivers to create DMA engine entity explicitly, possibly through a helper 
function (maybe a function to create and initialize a DMA engine entity based 
on a struct video_device). This can of course be done on a separate patch, but 
removing the entity field from struct video_device should be part of the 
series.

> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/v4l2-core/v4l2-dev.c
> b/drivers/media/v4l2-core/v4l2-dev.c index 44b330589787..07123dd569c4
> 100644
> --- a/drivers/media/v4l2-core/v4l2-dev.c
> +++ b/drivers/media/v4l2-core/v4l2-dev.c
> @@ -194,9 +194,12 @@ static void v4l2_device_release(struct device *cd)
>  	mutex_unlock(&videodev_lock);
> 
>  #if defined(CONFIG_MEDIA_CONTROLLER)
> -	if (v4l2_dev->mdev &&
> -	    vdev->vfl_type != VFL_TYPE_SUBDEV)
> -		media_device_unregister_entity(&vdev->entity);
> +	if (v4l2_dev->mdev) {
> +		/* Remove interfaces and interface links */
> +		media_devnode_remove(vdev->intf_devnode);
> +		if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN)
> +			media_device_unregister_entity(&vdev->entity);
> +	}
>  #endif
> 
>  	/* Do not call v4l2_device_put if there is no release callback set.
> @@ -713,6 +716,92 @@ static void determine_valid_ioctls(struct video_device
> *vdev) BASE_VIDIOC_PRIVATE);
>  }
> 
> +

Extra blank line.

> +static int video_register_media_controller(struct video_device *vdev, int
> type)
> +{
> +#if defined(CONFIG_MEDIA_CONTROLLER)
> +	u32 intf_type;
> +	int ret;
> +
> +	if (!vdev->v4l2_dev->mdev)
> +		return 0;
> +
> +	vdev->entity.type = MEDIA_ENT_T_UNKNOWN;
> +
> +	switch (type) {
> +	case VFL_TYPE_GRABBER:
> +		intf_type = MEDIA_INTF_T_V4L_VIDEO;
> +		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
> +		break;
> +	case VFL_TYPE_VBI:
> +		intf_type = MEDIA_INTF_T_V4L_VBI;
> +		vdev->entity.type = MEDIA_ENT_T_V4L2_VBI;
> +		break;
> +	case VFL_TYPE_SDR:
> +		intf_type = MEDIA_INTF_T_V4L_SWRADIO;
> +		vdev->entity.type = MEDIA_ENT_T_V4L2_SWRADIO;
> +		break;
> +	case VFL_TYPE_RADIO:
> +		intf_type = MEDIA_INTF_T_V4L_RADIO;
> +		/*
> +		 * Radio doesn't have an entity at the V4L2 side to represent
> +		 * radio input or output. Instead, the audio input/output goes
> +		 * via either physical wires or ALSA.
> +		 */
> +		break;
> +	case VFL_TYPE_SUBDEV:
> +		intf_type = MEDIA_INTF_T_V4L_SUBDEV;
> +		/* Entity will be created via v4l2_device_register_subdev() */
> +		break;
> +	default:
> +		return 0;
> +	}
> +
> +	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
> +		vdev->entity.name = vdev->name;
> +
> +		/* Needed just for backward compatibility with legacy MC API */
> +		vdev->entity.info.dev.major = VIDEO_MAJOR;
> +		vdev->entity.info.dev.minor = vdev->minor;
> +
> +		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
> +						   &vdev->entity);
> +		if (ret < 0) {
> +			printk(KERN_WARNING
> +				"%s: media_device_register_entity failed\n",
> +				__func__);
> +			return ret;
> +		}
> +	}
> +
> +	vdev->intf_devnode = media_devnode_create(vdev->v4l2_dev->mdev,
> +						  intf_type,
> +						  0, VIDEO_MAJOR,
> +						  vdev->minor,
> +						  GFP_KERNEL);
> +	if (!vdev->intf_devnode) {
> +		media_device_unregister_entity(&vdev->entity);
> +		return -ENOMEM;
> +	}
> +
> +	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
> +		struct media_link *link;
> +
> +		link = media_create_intf_link(&vdev->entity,
> +					      &vdev->intf_devnode->intf, 0);
> +		if (!link) {
> +			media_devnode_remove(vdev->intf_devnode);
> +			media_device_unregister_entity(&vdev->entity);
> +			return -ENOMEM;
> +		}
> +	}
> +
> +	/* FIXME: how to create the other interface links? */

If they're needed (and I'm still not sure they are) they should be created by 
drivers, possibly with the help of helper functions.

> +
> +#endif
> +	return 0;
> +}
> +
>  /**
>   *	__video_register_device - register video4linux devices
>   *	@vdev: video device structure we want to register
> @@ -908,22 +997,9 @@ int __video_register_device(struct video_device *vdev,
> int type, int nr, /* Increase v4l2_device refcount */
>  	v4l2_device_get(vdev->v4l2_dev);
> 
> -#if defined(CONFIG_MEDIA_CONTROLLER)
>  	/* Part 5: Register the entity. */
> -	if (vdev->v4l2_dev->mdev &&
> -	    vdev->vfl_type != VFL_TYPE_SUBDEV) {
> -		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
> -		vdev->entity.name = vdev->name;
> -		vdev->entity.info.dev.major = VIDEO_MAJOR;
> -		vdev->entity.info.dev.minor = vdev->minor;
> -		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
> -			&vdev->entity);
> -		if (ret < 0)
> -			printk(KERN_WARNING
> -			       "%s: media_device_register_entity failed\n",
> -			       __func__);
> -	}
> -#endif
> +	ret = video_register_media_controller(vdev, type);
> +
>  	/* Part 6: Activate this minor. The char device can now be used. */
>  	set_bit(V4L2_FL_REGISTERED, &vdev->flags);
> 
> diff --git a/drivers/media/v4l2-core/v4l2-device.c
> b/drivers/media/v4l2-core/v4l2-device.c index 5b0a30b9252b..e788a085ba96
> 100644
> --- a/drivers/media/v4l2-core/v4l2-device.c
> +++ b/drivers/media/v4l2-core/v4l2-device.c
> @@ -249,6 +249,17 @@ int v4l2_device_register_subdev_nodes(struct
> v4l2_device *v4l2_dev) #if defined(CONFIG_MEDIA_CONTROLLER)
>  		sd->entity.info.dev.major = VIDEO_MAJOR;
>  		sd->entity.info.dev.minor = vdev->minor;
> +
> +		/* Interface is created by __video_register_device() */
> +		if (vdev->v4l2_dev->mdev) {
> +			struct media_link *link;
> +
> +			link = media_create_intf_link(&sd->entity,
> +						      &vdev->intf_devnode->intf,
> +						      0);
> +			if (!link)
> +				goto clean_up;
> +		}
>  #endif
>  		sd->devnode = vdev;
>  	}
> @@ -285,7 +296,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev
> *sd)
> 
>  #if defined(CONFIG_MEDIA_CONTROLLER)
>  	if (v4l2_dev->mdev) {
> -		media_entity_remove_links(&sd->entity);
> +		/*
> +		 * No need to explicitly remove links, as both pads and
> +		 * links are removed by the function below, in the right order
> +		 */
>  		media_device_unregister_entity(&sd->entity);
>  	}
>  #endif
> diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
> index acbcd2f5fe7f..eeabf20e87a6 100644
> --- a/include/media/v4l2-dev.h
> +++ b/include/media/v4l2-dev.h
> @@ -86,6 +86,7 @@ struct video_device
>  {
>  #if defined(CONFIG_MEDIA_CONTROLLER)
>  	struct media_entity entity;
> +	struct media_intf_devnode *intf_devnode;
>  #endif
>  	/* device ops */
>  	const struct v4l2_file_operations *fops;

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 52/55] [media] media-device: remove interfaces and interface links
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-11 14:20     ` Hans Verkuil
@ 2015-11-23 21:22     ` Laurent Pinchart
  2015-12-09 13:39       ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-11-23 21:22 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:03:12 Mauro Carvalho Chehab wrote:
> Just like what's done with entities, when the media controller is
> unregistered, release any interface and interface links that
> might still be there.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 7c37aeab05bb..0238885fcc74 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -574,6 +574,22 @@ void media_device_unregister(struct media_device *mdev)
> {
>  	struct media_entity *entity;
>  	struct media_entity *next;
> +	struct media_link *link, *tmp_link;
> +	struct media_interface *intf, *tmp_intf;
> +
> +	/* Remove interface links from the media device */
> +	list_for_each_entry_safe(link, tmp_link, &mdev->links,
> +				 graph_obj.list) {
> +		media_gobj_remove(&link->graph_obj);
> +		kfree(link);
> +	}
> +
> +	/* Remove all interfaces from the media device */
> +	list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces,
> +				 graph_obj.list) {
> +		media_gobj_remove(&intf->graph_obj);
> +		kfree(intf);
> +	}
> 
>  	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
>  		media_device_unregister_entity(entity);
> @@ -651,7 +667,6 @@ void media_device_unregister_entity(struct media_entity
> *entity) /* Remove all data links that belong to this entity */
>  	list_for_each_entry_safe(link, tmp, &entity->links, list) {
>  		media_gobj_remove(&link->graph_obj);
> -		list_del(&link->list);
>  		kfree(link);

The link has already been freed in media_device_unregister(). You have access-
after-free and double-free issues here.

>  	}
> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index a37ccd2edfd5..cd4d767644df 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -206,6 +206,10 @@ void media_gobj_remove(struct media_gobj *gobj)
> 
>  	/* Remove the object from mdev list */
>  	list_del(&gobj->list);
> +
> +	/* Links have their own list - we need to drop them there too */
> +	if (media_type(gobj) == MEDIA_GRAPH_LINK)
> +		list_del(&gobj_to_link(gobj)->list);

Please... That's a very bad layering violation. Let's not do that. Generic 
graph object code should not contain any type-specific code. You can create a 
media_link_remove() function for links that will remove the link from the 
entity links list and call media_gobj_remove().

>  }
> 
>  /**
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index ca4a4f23362f..fb5f0e21f137 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -153,7 +153,7 @@ struct media_entity {
>  };
> 
>  /**
> - * struct media_intf_devnode - Define a Kernel API interface
> + * struct media_interface - Define a Kernel API interface

This belongs to a different patch ;-)

>   *
>   * @graph_obj:		embedded graph object
>   * @list:		Linked list used to find other interfaces that belong
> @@ -163,6 +163,11 @@ struct media_entity {
>   *			uapi/media/media.h header, e. g.
>   *			MEDIA_INTF_T_*
>   * @flags:		Interface flags as defined at uapi/media/media.h
> + *
> + * NOTE: As media_device_unregister() will free the address of the
> + *	 media_interface, this structure should be embedded as the first
> + *	 element of the derived functions, in order for the address to be
> + *	 the same.

s/NOTE/DIRTY HACK/

Or, much better, let's fix it :-) If you want to be able to destroy graph 
object without needing to know their type, you can add a destroy operation to 
the graph objects and have per-type implementations. There's probably other 
options as well.

>   */
>  struct media_interface {
>  	struct media_gobj		graph_obj;
> @@ -179,11 +184,11 @@ struct media_interface {
>   * @minor:	Minor number of a device node
>   */
>  struct media_intf_devnode {
> -	struct media_interface		intf;
> +	struct media_interface	intf; /* must be first field in struct */
> 
>  	/* Should match the fields at media_v2_intf_devnode */
> -	u32				major;
> -	u32				minor;
> +	u32			major;
> +	u32			minor;

This doesn't belong to this patch either.

>  };
> 
>  static inline u32 media_entity_id(struct media_entity *entity)

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 50/55] [media] media-entity: unregister entity links
  2015-09-06 12:03   ` Mauro Carvalho Chehab
@ 2015-11-23 21:27     ` Laurent Pinchart
  2015-12-08 20:23       ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-11-23 21:27 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:03:10 Mauro Carvalho Chehab wrote:
> Add functions to explicitly unregister all entity links.
> This function is called automatically when an entity
> link is destroyed.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 064515f2ba9b..a37ccd2edfd5 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -903,6 +903,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
> 
>  void media_devnode_remove(struct media_intf_devnode *devnode)
>  {
> +	media_remove_intf_links(&devnode->intf);
>  	media_gobj_remove(&devnode->intf.graph_obj);
>  	kfree(devnode);
>  }
> @@ -944,3 +945,25 @@ void media_remove_intf_link(struct media_link *link)
>  	mutex_unlock(&link->graph_obj.mdev->graph_mutex);
>  }
>  EXPORT_SYMBOL_GPL(media_remove_intf_link);
> +
> +void __media_remove_intf_links(struct media_interface *intf)
> +{
> +	struct media_link *link, *tmp;
> +
> +	list_for_each_entry_safe(link, tmp, &intf->links, list)
> +		__media_remove_intf_link(link);
> +
> +}
> +EXPORT_SYMBOL_GPL(__media_remove_intf_links);

The only place where this function is used is in media_remove_intf_links() 
below. How about inlining it for now ?

> +void media_remove_intf_links(struct media_interface *intf)
> +{
> +	/* Do nothing if the intf is not registered. */
> +	if (intf->graph_obj.mdev == NULL)
> +		return;
> +
> +	mutex_lock(&intf->graph_obj.mdev->graph_mutex);
> +	__media_remove_intf_links(intf);
> +	mutex_unlock(&intf->graph_obj.mdev->graph_mutex);
> +}
> +EXPORT_SYMBOL_GPL(media_remove_intf_links);

As this function is exported it should be documented with kerneldoc.

> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index bc7eb6240795..ca4a4f23362f 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -318,6 +318,9 @@ struct media_link *media_create_intf_link(struct
> media_entity *entity, struct media_interface *intf,
>  					    u32 flags);
>  void media_remove_intf_link(struct media_link *link);
> +void __media_remove_intf_links(struct media_interface *intf);
> +void media_remove_intf_links(struct media_interface *intf);
> +
> 
>  #define media_entity_call(entity, operation, args...)			\
>  	(((entity)->ops && (entity)->ops->operation) ?			\

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-07 22:18     ` Sakari Ailus
  2015-09-11 14:08     ` Hans Verkuil
@ 2015-11-23 22:04     ` Laurent Pinchart
  2015-12-08 20:17       ` Mauro Carvalho Chehab
  2 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-11-23 22:04 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

Hi Mauro,

Thank you for the patch.

Sakari and Hans have made several comments on this and the previous version of 
the same patch and I generally agree with them. I'll thus review the next 
version.

On Sunday 06 September 2015 09:03:09 Mauro Carvalho Chehab wrote:
> Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
> with the RFC for the MC next generation.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 5b2c9f7fcd45..96a476eeb16e 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -232,6 +232,156 @@ static long media_device_setup_link(struct
> media_device *mdev, return ret;
>  }
> 
> +static long __media_device_get_topology(struct media_device *mdev,
> +				      struct media_v2_topology *topo)
> +{
> +	struct media_entity *entity;
> +	struct media_interface *intf;
> +	struct media_pad *pad;
> +	struct media_link *link;
> +	struct media_v2_entity uentity;
> +	struct media_v2_interface uintf;
> +	struct media_v2_pad upad;
> +	struct media_v2_link ulink;
> +	int ret = 0, i;
> +
> +	topo->topology_version = mdev->topology_version;
> +
> +	/* Get entities and number of entities */
> +	i = 0;
> +	media_device_for_each_entity(entity, mdev) {
> +		i++;
> +
> +		if (ret || !topo->entities)
> +			continue;
> +
> +		if (i > topo->num_entities) {
> +			ret = -ENOSPC;
> +			continue;
> +		}
> +
> +		/* Copy fields to userspace struct if not error */
> +		memset(&uentity, 0, sizeof(uentity));
> +		uentity.id = entity->graph_obj.id;
> +		strncpy(uentity.name, entity->name,
> +			sizeof(uentity.name));
> +
> +		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_entities = i;
> +
> +	/* Get interfaces and number of interfaces */
> +	i = 0;
> +	media_device_for_each_intf(intf, mdev) {
> +		i++;
> +
> +		if (ret || !topo->interfaces)
> +			continue;
> +
> +		if (i > topo->num_interfaces) {
> +			ret = -ENOSPC;
> +			continue;
> +		}
> +
> +		memset(&uintf, 0, sizeof(uintf));
> +
> +		/* Copy intf fields to userspace struct */
> +		uintf.id = intf->graph_obj.id;
> +		uintf.intf_type = intf->type;
> +		uintf.flags = intf->flags;
> +
> +		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
> +			struct media_intf_devnode *devnode;
> +
> +			devnode = intf_to_devnode(intf);
> +
> +			uintf.devnode.major = devnode->major;
> +			uintf.devnode.minor = devnode->minor;
> +		}
> +
> +		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_interfaces = i;
> +
> +	/* Get pads and number of pads */
> +	i = 0;
> +	media_device_for_each_pad(pad, mdev) {
> +		i++;
> +
> +		if (ret || !topo->pads)
> +			continue;
> +
> +		if (i > topo->num_pads) {
> +			ret = -ENOSPC;
> +			continue;
> +		}
> +
> +		memset(&upad, 0, sizeof(upad));
> +
> +		/* Copy pad fields to userspace struct */
> +		upad.id = pad->graph_obj.id;
> +		upad.entity_id = pad->entity->graph_obj.id;
> +		upad.flags = pad->flags;
> +
> +		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_pads = i;
> +
> +	/* Get links and number of links */
> +	i = 0;
> +	media_device_for_each_link(link, mdev) {
> +		i++;
> +
> +		if (ret || !topo->links)
> +			continue;
> +
> +		if (i > topo->num_links) {
> +			ret = -ENOSPC;
> +			continue;
> +		}
> +
> +		memset(&ulink, 0, sizeof(ulink));
> +
> +		/* Copy link fields to userspace struct */
> +		ulink.id = link->graph_obj.id;
> +		ulink.source_id = link->gobj0->id;
> +		ulink.sink_id = link->gobj1->id;
> +		ulink.flags = link->flags;
> +
> +		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
> +			ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;
> +
> +		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
> +			ret = -EFAULT;
> +	}
> +	topo->num_links = i;
> +
> +	return ret;
> +}
> +
> +static long media_device_get_topology(struct media_device *mdev,
> +				      struct media_v2_topology __user *utopo)
> +{
> +	struct media_v2_topology ktopo;
> +	int ret;
> +
> +	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
> +
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = __media_device_get_topology(mdev, &ktopo);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));
> +
> +	return ret;
> +}
> +
>  static long media_device_ioctl(struct file *filp, unsigned int cmd,
>  			       unsigned long arg)
>  {
> @@ -264,6 +414,13 @@ static long media_device_ioctl(struct file *filp,
> unsigned int cmd, mutex_unlock(&dev->graph_mutex);
>  		break;
> 
> +	case MEDIA_IOC_G_TOPOLOGY:
> +		mutex_lock(&dev->graph_mutex);
> +		ret = media_device_get_topology(dev,
> +				(struct media_v2_topology __user *)arg);
> +		mutex_unlock(&dev->graph_mutex);
> +		break;
> +
>  	default:
>  		ret = -ENOIOCTLCMD;
>  	}
> @@ -312,6 +469,7 @@ static long media_device_compat_ioctl(struct file *filp,
> unsigned int cmd, case MEDIA_IOC_DEVICE_INFO:
>  	case MEDIA_IOC_ENUM_ENTITIES:
>  	case MEDIA_IOC_SETUP_LINK:
> +	case MEDIA_IOC_G_TOPOLOGY:
>  		return media_device_ioctl(filp, cmd, arg);
> 
>  	case MEDIA_IOC_ENUM_LINKS32:

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 48/55] [media] media_device: add a topology version field
  2015-09-04 17:08         ` Mauro Carvalho Chehab
@ 2015-11-23 22:18           ` Laurent Pinchart
  2015-12-08 20:05             ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-11-23 22:18 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Hans Verkuil, Linux Media Mailing List, Mauro Carvalho Chehab

Hi Mauro,

On Friday 04 September 2015 14:08:27 Mauro Carvalho Chehab wrote:
> Em Mon, 31 Aug 2015 15:35:38 +0200 Hans Verkuil escreveu:
> > On 08/31/2015 02:52 PM, Mauro Carvalho Chehab wrote:
> >> Em Mon, 31 Aug 2015 14:29:28 +0200 Hans Verkuil escreveu:
> >>> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> >>>> Every time a graph object is added or removed, the version
> >>>> of the topology changes. That's a requirement for the new
> >>>> MEDIA_IOC_G_TOPOLOGY, in order to allow userspace to know
> >>>> that the topology has changed after a previous call to it.
> >>>> 
> >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> >>> 
> >>> I think this should be postponed until we actually have dynamic
> >>> reconfigurable graphs.
> >> 
> >> So far, we're using the term "dynamic" to mean partial graph object
> >> removal.
> >> 
> >> But even today, MC does support "dynamic" in the sense of graph object
> >> additions.
> >> 
> >> You should notice that having a topology_version is something that IMHO,
> >> it is needed since the beginning, even without dynamic reconfigurable
> >> graphs, because the graph may grow in runtime.
> >> 
> >> That will happen, for example, if usb-snd-audio is blacklisted at
> >> /etc/modprobe*, and someone connects an au0828.
> >> 
> >> New entities/links will be created (after Shuah patches) if one would
> >> modprobe latter snd-usb-audio.
> > 
> > latter -> later :-)
> > 
> > You are right, this would trigger a topology change. I hadn't thought
> > about that.

First of all it won't be very useful without a topology change notification, 
so until we have them it doesn't matter too much. Then, the code is full of 
race conditions when it comes to dynamic updates, and I'm afraid Shua's 
patches can't go in before we fix them.

> >>> I would also like to reserve version 0: if 0 is returned, then the graph
> >>> is static.
> >> 
> >> Why? Implementing this would be really hard, as that would mean that
> >> G_TOPOLOGY would need to be blocked until all drivers and subdevices get
> >> probed.
> >> 
> >> In order to implement that, some logic would be needed at the drivers to
> >> identify if everything was set and unlock G_TOPOLOGY.
> > 
> > That wouldn't be needed if the media device node was created last. Which I
> > think is a good idea anyway.
> 
> Creating the media device node last won't work. It should be the first thing
> to be created, as all objects should be added to media_device linked lists.

I disagree with that. The media_device needs to be initialized first, but can 
be registered with userspace last. We don't want to generate a topology update 
event for every new entity, link or pad during the device probe sequence. 
Drivers should be in control and tell when they're done with initialization.

> Also, the numberspace should be local to a given media_device, as the graph
> traversal algorithm relies on having the number of entities <= 64,
> currently, in order to be able to detect loops. We should increase that
> number, but removing an "as low as possible" entity number limit is not
> trivial.
> 
> > > What would be the gain for that? I fail to see any.
> > 
> > It would tell userspace that it doesn't have to cope with dynamically
> > changing graphs.
> > 
> > Even though with the au0828 example you can expect to see cases like that,
> > I can pretty much guarantee that no generic v4l2 applications will ever
> > support dynamic changes.
> 
> Well, my test app supports it and it is generic ;) My plan is to use it as a
> basis for the library to be used on userspace for generic apps, extending it
> to be used by other tools like xawtv, qv4l2 and the dvbv5 apps.
> 
> I don't think it is hard to handle it on a generic app,

I'll quote you later on that :-)

> and this should be done anyway if we want dynamic support.
>
> The logic seems actually be simple:
> 
> at G_TOPOLOGY, if the topology changes, reload the objects;

And update everything in userspace. That's a very hard task if you don't 
design your applications extremely carefully.

> at SETUP_LINK_V2, the topology will be sent. if the driver detects that
> topology changed, it returns an error.
> 
> The caller will then need to reload the topology and re-apply the
> transaction to select the links, if the entities affected still exists. In
> other words, if the user's intent were to change the pipeline to receive the
> data at /dev/video2, e. g. something like:
> 	./yavta/yavta -f UYVY -s 720x312 -n 1 --capture=1 -F /dev/video2
> 
> What userspace would do is to reload everything, check if /dev/video2 still
> exists and then redo the function that it is equivalent to the above
> command, failing otherwise. That doesn't sound hard to implement.
> 
> > Those that will support it will be custom-made.
> > 
> > Being able to see that graphs can change dynamically would allow such apps
> > to either refuse to use the device, or warn the user.
> 
> The way I see is that applications that will assume that the graph
> is static will be the custom-made ones.

Or (some of) the generic ones.

> As they know the hardware, they can just either ignore the topology_version
> or wait for it to stabilize when the hardware is still being probed.
> 
> In any case, if we end by needing to have an explicit way for the
> Kernelspace to tell userspace that a graph is static, that could be done via
> an extra flag at MEDIA_INFO.

Why ? I don't see anything wrong with reversing version 0 for that purpose, as 
Hans proposed.

> Enabling this flag could be as easy as waiting for all graph elements to be
> created (where the topology is still dynamic), and raise such flag after
> finishing the probe sequence.

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 48/55] [media] media_device: add a topology version field
  2015-08-31 12:29   ` Hans Verkuil
  2015-08-31 12:52     ` Mauro Carvalho Chehab
@ 2015-11-23 22:20     ` Laurent Pinchart
  1 sibling, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2015-11-23 22:20 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List, Mauro Carvalho Chehab

Hi Mauro and Hans,

On Monday 31 August 2015 14:29:28 Hans Verkuil wrote:
> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> > Every time a graph object is added or removed, the version
> > of the topology changes. That's a requirement for the new
> > MEDIA_IOC_G_TOPOLOGY, in order to allow userspace to know
> > that the topology has changed after a previous call to it.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> I think this should be postponed until we actually have dynamic
> reconfigurable graphs.
> 
> I would also like to reserve version 0: if 0 is returned, then the graph is
> static.
> 
> In G_TOPOLOGY we'd return always 0 for now.

So would I. We need a way to group graph modifications to avoid incrementing 
the version number and generating an event for every entity, link or pad added 
or removed. As this patch doesn't address that I don't see a use for the 
version number now other than making our life more difficult when we'll 
implement dynamic updates by forcing us to consider backward compatibility 
with something that we know won't do the job.

> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index c89f51bc688d..c18f4af52771 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -185,6 +185,9 @@ void media_gobj_init(struct media_device *mdev,
> >  		list_add_tail(&gobj->list, &mdev->interfaces);
> >  		break;
> >  	}
> > +
> > +	mdev->topology_version++;
> > +
> >  	dev_dbg_obj(__func__, gobj);
> >  }
> > 
> > @@ -199,6 +202,8 @@ void media_gobj_remove(struct media_gobj *gobj)
> >  {
> >  	dev_dbg_obj(__func__, gobj);
> > 
> > +	gobj->mdev->topology_version++;
> > +
> >  	/* Remove the object from mdev list */
> >  	list_del(&gobj->list);
> >  }
> > diff --git a/include/media/media-device.h b/include/media/media-device.h
> > index 0d1b9c687454..1b12774a9ab4 100644
> > --- a/include/media/media-device.h
> > +++ b/include/media/media-device.h
> > @@ -41,6 +41,8 @@ struct device;
> >   * @bus_info:	Unique and stable device location identifier
> >   * @hw_revision: Hardware device revision
> >   * @driver_version: Device driver version
> > + * @topology_version: Monotonic counter for storing the version of the
> > graph
> > + *		topology. Should be incremented each time the topology changes.
> >   * @entity_id:	Unique ID used on the last entity registered
> >   * @pad_id:	Unique ID used on the last pad registered
> >   * @link_id:	Unique ID used on the last link registered
> > @@ -74,6 +76,8 @@ struct media_device {
> >  	u32 hw_revision;
> >  	u32 driver_version;
> > 
> > +	u32 topology_version;
> > +
> >  	u32 entity_id;
> >  	u32 pad_id;
> >  	u32 link_id;

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 47/55] [media] media-device: add pads and links to media_device
  2015-09-06 12:03   ` Mauro Carvalho Chehab
@ 2015-11-23 22:28     ` Laurent Pinchart
  2015-11-24 12:19       ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-11-23 22:28 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:03:07 Mauro Carvalho Chehab wrote:
> The MC next gen API sends objects to userspace grouped by
> their types.
> 
> In the case of pads and links, in order to improve performance

Are we sure it really improves performances ?

> and have a simpler code, the best is to store them also on
> separate linked lists at MC.

Have you considered the approach of storing them in a single list of objects 
instead of per-type lists ? I wonder if it could be helpful. What bothers me 
here is that we violate layers by using the list field in the graph object 
structure to store it in lists specific to the individual graph object types. 
Such violations have proved to be bad ideas in most cases, even if I can't 
pinpoint why right now. It could of course also be an exception.

> If we don't do that, we would need this kind of interaction
> to send data to userspace (code is in structured english):
> 
> 	for each entity:
> 		for each pad:
> 			store pads
> 
> 	for each entity:
> 		for each link:
> 			store link
> 
> 	for each interface:
> 		for each link:
> 			store link
> 
> With would require one nexted loop for pads and two nested

s/nexted loop/nested loop/

> loops for links. By using  separate linked lists for them,
> just one loop would be enough.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index ec98595b8a7a..5b2c9f7fcd45 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -382,6 +382,8 @@ int __must_check __media_device_register(struct
> media_device *mdev,
> 
>  	INIT_LIST_HEAD(&mdev->entities);
>  	INIT_LIST_HEAD(&mdev->interfaces);
> +	INIT_LIST_HEAD(&mdev->pads);
> +	INIT_LIST_HEAD(&mdev->links);
>  	spin_lock_init(&mdev->lock);
>  	mutex_init(&mdev->graph_mutex);
> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index cbb0604e81c1..568553d41f5d 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -174,13 +174,15 @@ void media_gobj_init(struct media_device *mdev,
>  		break;
>  	case MEDIA_GRAPH_PAD:
>  		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
> +		list_add_tail(&gobj->list, &mdev->pads);
>  		break;
>  	case MEDIA_GRAPH_LINK:
>  		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
> +		list_add_tail(&gobj->list, &mdev->links);
>  		break;
>  	case MEDIA_GRAPH_INTF_DEVNODE:
> -		list_add_tail(&gobj->list, &mdev->interfaces);
>  		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
> +		list_add_tail(&gobj->list, &mdev->interfaces);
>  		break;
>  	}
>  	dev_dbg_obj(__func__, gobj);
> @@ -195,17 +197,10 @@ void media_gobj_init(struct media_device *mdev,
>   */
>  void media_gobj_remove(struct media_gobj *gobj)
>  {
> +	dev_dbg_obj(__func__, gobj);
> +
>  	/* Remove the object from mdev list */
> -	switch (media_type(gobj)) {
> -	case MEDIA_GRAPH_ENTITY:
> -	case MEDIA_GRAPH_INTF_DEVNODE:
> -		list_del(&gobj->list);
> -		break;
> -	default:
> -		break;
> -	}
> -
> -	dev_dbg_obj(__func__, gobj);
> +	list_del(&gobj->list);
>  }
> 
>  /**
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index 85fa302047bd..0d1b9c687454 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -47,6 +47,8 @@ struct device;
>   * @intf_devnode_id: Unique ID used on the last interface devnode
> registered * @entities:	List of registered entities
>   * @interfaces:	List of registered interfaces
> + * @pads:	List of registered pads
> + * @links:	List of registered links
>   * @lock:	Entities list lock
>   * @graph_mutex: Entities graph operation lock
>   * @link_notify: Link state change notification callback
> @@ -79,6 +81,8 @@ struct media_device {
> 
>  	struct list_head entities;
>  	struct list_head interfaces;
> +	struct list_head pads;
> +	struct list_head links;
> 
>  	/* Protects the entities list */
>  	spinlock_t lock;
> @@ -117,6 +121,14 @@ struct media_device *media_device_find_devres(struct
> device *dev); #define media_device_for_each_intf(intf, mdev)			\
>  	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
> 
> +/* Iterate over all pads. */
> +#define media_device_for_each_pad(pad, mdev)			\
> +	list_for_each_entry(pad, &(mdev)->pads, graph_obj.list)
> +
> +/* Iterate over all links. */
> +#define media_device_for_each_link(link, mdev)			\
> +	list_for_each_entry(link, &(mdev)->links, graph_obj.list)
> +
> 
>  #else
>  static inline int media_device_register(struct media_device *mdev)

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 46/55] [media] media: move mdev list init to gobj
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-11 13:59     ` Hans Verkuil
@ 2015-11-23 22:32     ` Laurent Pinchart
  2015-12-08 19:31       ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-11-23 22:32 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:03:06 Mauro Carvalho Chehab wrote:
> Let's control the topology changes inside the graph_object. So, move the
> addition and removal of interfaces/entities from the mdev lists to
> media_gobj_init() and media_gobj_remove().
> 
> The main reason is that mdev should have lists for all object types, as
> the new MC api will require to store objects in separate places.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 134fe7510195..ec98595b8a7a 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -415,7 +415,7 @@ void media_device_unregister(struct media_device *mdev)
>  	struct media_entity *entity;
>  	struct media_entity *next;
> 
> -	list_for_each_entry_safe(entity, next, &mdev->entities, list)
> +	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
>  		media_device_unregister_entity(entity);
> 
>  	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
> @@ -449,7 +449,6 @@ int __must_check media_device_register_entity(struct
> media_device *mdev, spin_lock(&mdev->lock);
>  	/* Initialize media_gobj embedded at the entity */
>  	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
> -	list_add_tail(&entity->list, &mdev->entities);
> 
>  	/* Initialize objects at the pads */
>  	for (i = 0; i < entity->num_pads; i++)
> @@ -487,7 +486,6 @@ void media_device_unregister_entity(struct media_entity
> *entity) for (i = 0; i < entity->num_pads; i++)
>  		media_gobj_remove(&entity->pads[i].graph_obj);
>  	media_gobj_remove(&entity->graph_obj);
> -	list_del(&entity->list);
>  	spin_unlock(&mdev->lock);
>  	entity->graph_obj.mdev = NULL;
>  }
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 6ed5eef88593..cbb0604e81c1 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -170,6 +170,7 @@ void media_gobj_init(struct media_device *mdev,
>  	switch (type) {
>  	case MEDIA_GRAPH_ENTITY:
>  		gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
> +		list_add_tail(&gobj->list, &mdev->entities);
>  		break;
>  	case MEDIA_GRAPH_PAD:
>  		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
> @@ -178,6 +179,7 @@ void media_gobj_init(struct media_device *mdev,
>  		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
>  		break;
>  	case MEDIA_GRAPH_INTF_DEVNODE:
> +		list_add_tail(&gobj->list, &mdev->interfaces);
>  		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
>  		break;
>  	}
> @@ -193,6 +195,16 @@ void media_gobj_init(struct media_device *mdev,
>   */
>  void media_gobj_remove(struct media_gobj *gobj)
>  {
> +	/* Remove the object from mdev list */
> +	switch (media_type(gobj)) {
> +	case MEDIA_GRAPH_ENTITY:
> +	case MEDIA_GRAPH_INTF_DEVNODE:
> +		list_del(&gobj->list);
> +		break;

Type-specific handling in the graph object code doesn't seem right. I'd keep 
the list_del calls in the type-specific remove functions. Same for the 
list_add_tail calls above, unless we switch from per-type lists to a single 
graph objects list as I mentioned in a reply to another patch (and the more I 
think about it the more tempting it gets).

> +	default:
> +		break;
> +	}
> +
>  	dev_dbg_obj(__func__, gobj);
>  }
> 
> @@ -864,8 +876,6 @@ static void media_interface_init(struct media_device
> *mdev, INIT_LIST_HEAD(&intf->links);
> 
>  	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
> -
> -	list_add_tail(&intf->list, &mdev->interfaces);
>  }
> 
>  /* Functions related to the media interface via device nodes */
> @@ -894,7 +904,6 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
>  void media_devnode_remove(struct media_intf_devnode *devnode)
>  {
>  	media_gobj_remove(&devnode->intf.graph_obj);
> -	list_del(&devnode->intf.list);
>  	kfree(devnode);
>  }
>  EXPORT_SYMBOL_GPL(media_devnode_remove);
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index f23d686aaac6..85fa302047bd 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -111,11 +111,11 @@ struct media_device *media_device_find_devres(struct
> device *dev);
> 
>  /* Iterate over all entities. */
>  #define media_device_for_each_entity(entity, mdev)			\
> -	list_for_each_entry(entity, &(mdev)->entities, list)
> +	list_for_each_entry(entity, &(mdev)->entities, graph_obj.list)
> 
>  /* Iterate over all interfaces. */
>  #define media_device_for_each_intf(intf, mdev)			\
> -	list_for_each_entry(intf, &(mdev)->interfaces, list)
> +	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
> 
> 
>  #else
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 2d5ad40254b7..bc7eb6240795 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -66,6 +66,7 @@ enum media_gobj_type {
>  struct media_gobj {
>  	struct media_device	*mdev;
>  	u32			id;
> +	struct list_head	list;
>  };
> 
> 
> @@ -114,7 +115,6 @@ struct media_entity_operations {
> 
>  struct media_entity {
>  	struct media_gobj graph_obj;	/* must be first field in struct */
> -	struct list_head list;
>  	const char *name;		/* Entity name */
>  	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
>  	u32 revision;			/* Entity revision, driver specific */
> @@ -166,7 +166,6 @@ struct media_entity {
>   */
>  struct media_interface {
>  	struct media_gobj		graph_obj;
> -	struct list_head		list;
>  	struct list_head		links;
>  	u32				type;
>  	u32				flags;

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 45/55] [media] media: Use a macro to interate between all interfaces
  2015-09-06 12:03   ` Mauro Carvalho Chehab
@ 2015-11-23 22:36     ` Laurent Pinchart
  0 siblings, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2015-11-23 22:36 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Hans Verkuil, Sakari Ailus

Hi Mauro,

Thank you for the patch.

In the subject line, s/interate between all/iterate over all/

On Sunday 06 September 2015 09:03:05 Mauro Carvalho Chehab wrote:
> Just like we do with entities, use a similar macro for the
> interfaces loop.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> diff --git a/drivers/media/dvb-core/dvbdev.c
> b/drivers/media/dvb-core/dvbdev.c index 6babc688801b..f00f1a5f279c 100644
> --- a/drivers/media/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb-core/dvbdev.c
> @@ -578,9 +578,10 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
>  	}
> 
>  	/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca 
*/
> -	list_for_each_entry(intf, &mdev->interfaces, list) {
> +	media_device_for_each_intf(intf, mdev) {
>  		if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
>  			media_create_intf_link(ca, intf, 0);
> +
>  		if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
>  			media_create_intf_link(tuner, intf, 0);
> 
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index 51807efa505b..f23d686aaac6 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -113,6 +113,11 @@ struct media_device *media_device_find_devres(struct
> device *dev); #define media_device_for_each_entity(entity, mdev)			\
>  	list_for_each_entry(entity, &(mdev)->entities, list)
> 
> +/* Iterate over all interfaces. */
> +#define media_device_for_each_intf(intf, mdev)			\
> +	list_for_each_entry(intf, &(mdev)->interfaces, list)
> +
> +

One blank line should be enough.

>  #else
>  static inline int media_device_register(struct media_device *mdev)
>  {

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes
  2015-11-23 21:10     ` Laurent Pinchart
@ 2015-11-24 11:25       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-11-24 11:25 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Hans Verkuil, Sakari Ailus, Shuah Khan

Em Mon, 23 Nov 2015 23:10:04 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 06 September 2015 09:03:13 Mauro Carvalho Chehab wrote:
> > V4L2 device (and subdevice) nodes should create an interface, if the
> > Media Controller support is enabled.
> > 
> > Please notice that radio devices should not create an entity, as radio
> > input/output is either via wires or via ALSA.
> 
> I'd go one step further, video nodes should not create an entity, ever. This 
> was one of the design principles behind the MC rework. We'll need to patch 
> drivers to create DMA engine entity explicitly, possibly through a helper 
> function (maybe a function to create and initialize a DMA engine entity based 
> on a struct video_device). This can of course be done on a separate patch, but 
> removing the entity field from struct video_device should be part of the 
> series.

Not sure what exactly you mean here.

There are two separate things happening with regards to device
nodes that do stream I/O:

1) They may have a DMA engine somewhere at the hardware pipeline.
   On some drivers, like USB ones, the DMA engine is actually not
   responsible to deliver the data to userspace. This is also
   true on ALSA and DVB (right now). Also, eventually, some
   drivers may not have a DMA engine (they may eventually use PIO
   like some old sound cards);

2) The I/O interface to where the data stream is delivered. This is
   actually not a hardware interface, but a software implementation
   on Linux. Ok, on V4L2, this is typically associated with a DMA
   engine, but the actual interface is a buffer that could be
   obtained by one of the delivery methods: read()/write() sysctl,
   mmapped buffer and/or DMABUF.

IMHO, (2) would ideally be mapped as a media_interface, as this is
not hardware, but linux software. However, such change won't be
backward compatible. So, as agreed at the MC workshop, we're using
a media entity for such I/O interface, calling its function as
MEDIA_ENT_F_IO (as you may see at the review comments from the
others, Shuah requested to actually split this function into one
I/O function per type of interface, in order to be able to easily
distinguish ALSA I/O from V4L2 I/O). 

I agree that (1) should be driver-specific, as only the driver knows
where the DMA engine is at the pipeline.

However, (2) should be created by the media core. So, I can't see
any rationale to remove the entity field from struct video_device.

> 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/v4l2-core/v4l2-dev.c
> > b/drivers/media/v4l2-core/v4l2-dev.c index 44b330589787..07123dd569c4
> > 100644
> > --- a/drivers/media/v4l2-core/v4l2-dev.c
> > +++ b/drivers/media/v4l2-core/v4l2-dev.c
> > @@ -194,9 +194,12 @@ static void v4l2_device_release(struct device *cd)
> >  	mutex_unlock(&videodev_lock);
> > 
> >  #if defined(CONFIG_MEDIA_CONTROLLER)
> > -	if (v4l2_dev->mdev &&
> > -	    vdev->vfl_type != VFL_TYPE_SUBDEV)
> > -		media_device_unregister_entity(&vdev->entity);
> > +	if (v4l2_dev->mdev) {
> > +		/* Remove interfaces and interface links */
> > +		media_devnode_remove(vdev->intf_devnode);
> > +		if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN)
> > +			media_device_unregister_entity(&vdev->entity);
> > +	}
> >  #endif
> > 
> >  	/* Do not call v4l2_device_put if there is no release callback set.
> > @@ -713,6 +716,92 @@ static void determine_valid_ioctls(struct video_device
> > *vdev) BASE_VIDIOC_PRIVATE);
> >  }
> > 
> > +
> 
> Extra blank line.
> 
> > +static int video_register_media_controller(struct video_device *vdev, int
> > type)
> > +{
> > +#if defined(CONFIG_MEDIA_CONTROLLER)
> > +	u32 intf_type;
> > +	int ret;
> > +
> > +	if (!vdev->v4l2_dev->mdev)
> > +		return 0;
> > +
> > +	vdev->entity.type = MEDIA_ENT_T_UNKNOWN;
> > +
> > +	switch (type) {
> > +	case VFL_TYPE_GRABBER:
> > +		intf_type = MEDIA_INTF_T_V4L_VIDEO;
> > +		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
> > +		break;
> > +	case VFL_TYPE_VBI:
> > +		intf_type = MEDIA_INTF_T_V4L_VBI;
> > +		vdev->entity.type = MEDIA_ENT_T_V4L2_VBI;
> > +		break;
> > +	case VFL_TYPE_SDR:
> > +		intf_type = MEDIA_INTF_T_V4L_SWRADIO;
> > +		vdev->entity.type = MEDIA_ENT_T_V4L2_SWRADIO;
> > +		break;
> > +	case VFL_TYPE_RADIO:
> > +		intf_type = MEDIA_INTF_T_V4L_RADIO;
> > +		/*
> > +		 * Radio doesn't have an entity at the V4L2 side to represent
> > +		 * radio input or output. Instead, the audio input/output goes
> > +		 * via either physical wires or ALSA.
> > +		 */
> > +		break;
> > +	case VFL_TYPE_SUBDEV:
> > +		intf_type = MEDIA_INTF_T_V4L_SUBDEV;
> > +		/* Entity will be created via v4l2_device_register_subdev() */
> > +		break;
> > +	default:
> > +		return 0;
> > +	}
> > +
> > +	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
> > +		vdev->entity.name = vdev->name;
> > +
> > +		/* Needed just for backward compatibility with legacy MC API */
> > +		vdev->entity.info.dev.major = VIDEO_MAJOR;
> > +		vdev->entity.info.dev.minor = vdev->minor;
> > +
> > +		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
> > +						   &vdev->entity);
> > +		if (ret < 0) {
> > +			printk(KERN_WARNING
> > +				"%s: media_device_register_entity failed\n",
> > +				__func__);
> > +			return ret;
> > +		}
> > +	}
> > +
> > +	vdev->intf_devnode = media_devnode_create(vdev->v4l2_dev->mdev,
> > +						  intf_type,
> > +						  0, VIDEO_MAJOR,
> > +						  vdev->minor,
> > +						  GFP_KERNEL);
> > +	if (!vdev->intf_devnode) {
> > +		media_device_unregister_entity(&vdev->entity);
> > +		return -ENOMEM;
> > +	}
> > +
> > +	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
> > +		struct media_link *link;
> > +
> > +		link = media_create_intf_link(&vdev->entity,
> > +					      &vdev->intf_devnode->intf, 0);
> > +		if (!link) {
> > +			media_devnode_remove(vdev->intf_devnode);
> > +			media_device_unregister_entity(&vdev->entity);
> > +			return -ENOMEM;
> > +		}
> > +	}
> > +
> > +	/* FIXME: how to create the other interface links? */
> 
> If they're needed (and I'm still not sure they are) they should be created by 
> drivers, possibly with the help of helper functions.
> 
> > +
> > +#endif
> > +	return 0;
> > +}
> > +
> >  /**
> >   *	__video_register_device - register video4linux devices
> >   *	@vdev: video device structure we want to register
> > @@ -908,22 +997,9 @@ int __video_register_device(struct video_device *vdev,
> > int type, int nr, /* Increase v4l2_device refcount */
> >  	v4l2_device_get(vdev->v4l2_dev);
> > 
> > -#if defined(CONFIG_MEDIA_CONTROLLER)
> >  	/* Part 5: Register the entity. */
> > -	if (vdev->v4l2_dev->mdev &&
> > -	    vdev->vfl_type != VFL_TYPE_SUBDEV) {
> > -		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
> > -		vdev->entity.name = vdev->name;
> > -		vdev->entity.info.dev.major = VIDEO_MAJOR;
> > -		vdev->entity.info.dev.minor = vdev->minor;
> > -		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
> > -			&vdev->entity);
> > -		if (ret < 0)
> > -			printk(KERN_WARNING
> > -			       "%s: media_device_register_entity failed\n",
> > -			       __func__);
> > -	}
> > -#endif
> > +	ret = video_register_media_controller(vdev, type);
> > +
> >  	/* Part 6: Activate this minor. The char device can now be used. */
> >  	set_bit(V4L2_FL_REGISTERED, &vdev->flags);
> > 
> > diff --git a/drivers/media/v4l2-core/v4l2-device.c
> > b/drivers/media/v4l2-core/v4l2-device.c index 5b0a30b9252b..e788a085ba96
> > 100644
> > --- a/drivers/media/v4l2-core/v4l2-device.c
> > +++ b/drivers/media/v4l2-core/v4l2-device.c
> > @@ -249,6 +249,17 @@ int v4l2_device_register_subdev_nodes(struct
> > v4l2_device *v4l2_dev) #if defined(CONFIG_MEDIA_CONTROLLER)
> >  		sd->entity.info.dev.major = VIDEO_MAJOR;
> >  		sd->entity.info.dev.minor = vdev->minor;
> > +
> > +		/* Interface is created by __video_register_device() */
> > +		if (vdev->v4l2_dev->mdev) {
> > +			struct media_link *link;
> > +
> > +			link = media_create_intf_link(&sd->entity,
> > +						      &vdev->intf_devnode->intf,
> > +						      0);
> > +			if (!link)
> > +				goto clean_up;
> > +		}
> >  #endif
> >  		sd->devnode = vdev;
> >  	}
> > @@ -285,7 +296,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev
> > *sd)
> > 
> >  #if defined(CONFIG_MEDIA_CONTROLLER)
> >  	if (v4l2_dev->mdev) {
> > -		media_entity_remove_links(&sd->entity);
> > +		/*
> > +		 * No need to explicitly remove links, as both pads and
> > +		 * links are removed by the function below, in the right order
> > +		 */
> >  		media_device_unregister_entity(&sd->entity);
> >  	}
> >  #endif
> > diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
> > index acbcd2f5fe7f..eeabf20e87a6 100644
> > --- a/include/media/v4l2-dev.h
> > +++ b/include/media/v4l2-dev.h
> > @@ -86,6 +86,7 @@ struct video_device
> >  {
> >  #if defined(CONFIG_MEDIA_CONTROLLER)
> >  	struct media_entity entity;
> > +	struct media_intf_devnode *intf_devnode;
> >  #endif
> >  	/* device ops */
> >  	const struct v4l2_file_operations *fops;
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 47/55] [media] media-device: add pads and links to media_device
  2015-11-23 22:28     ` Laurent Pinchart
@ 2015-11-24 12:19       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-11-24 12:19 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List

Hi Laurent,

Em Tue, 24 Nov 2015 00:28:24 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 06 September 2015 09:03:07 Mauro Carvalho Chehab wrote:
> > The MC next gen API sends objects to userspace grouped by
> > their types.
> > 
> > In the case of pads and links, in order to improve performance
> 
> Are we sure it really improves performances ?

Yes. The comment here describes what would be needed at
__media_device_get_topology() to implement the logic that would
retrieve the topology.

Assuming that we have:
	e - number of entities
	i - number of interfaces
	p - number of pads
	dl - number of data links
	il - number of interface links

With the current code, the number of loop interactions is:
	e + i + p + 2 x (dl + il)

If we use, instead, a single list, the number of loop interactions
would be:
	4 x (e + i + p + dl + il)

This is at least two times slower than the option I used.

If we use instead:
> > 	for each entity:
> > 		for each pad:
> > 			store pads
> > 
> > 	for each entity:
> > 		for each link:
> > 			store link
> > 
> > 	for each interface:
> > 		for each link:
> > 			store link

We would have:
	(e + p) + (e + dl + il) + (i + dl + il)

With is worse than the loop we're doing, as it will go twice each
entity. Also, the logic of each loop interaction will be more
complex. So, the time spent on each loop interaction will be bigger.

The only doubt I actually have is if we should have a separate list
to distinguish data links and interface links, as this would improve
it even further, reducing the number of loop interactions to:
	e + i + p + dl + il

(with is the absolute minimum of interactions for it)

In any case, such change could be done latter, if we identify the
need in the future.

> 
> > and have a simpler code, the best is to store them also on
> > separate linked lists at MC.
> 
> Have you considered the approach of storing them in a single list of objects 
> instead of per-type lists ? I wonder if it could be helpful.

For the implementation of the __media_device_get_topology(), if
we implement the userspace API in a way that we would mix different
graph objects, e. g., if we define the API as something like:

struct media_v2_topology {
	__u32 topology_version;

	__u32 num_graph_objects;
	struct media_graph_object *obj;

	void *obj_properties;
};

Then it would make sense to have a single list, because we could
just send objects to userspace on any order. However, as we need to
split objects per their type, multiple lists can reduce up to 4 times
the number of loop interactions when passing those data to userspace.

About the same 4x impact happens internally every time some driver
or the core would need to use the object list to find for some
specific object of a given type.

> What bothers me 
> here is that we violate layers by using the list field in the graph object 
> structure to store it in lists specific to the individual graph object types. 
> Such violations have proved to be bad ideas in most cases, even if I can't 
> pinpoint why right now. It could of course also be an exception.

I guess your review on patch 46/55 and 52/55 about bad layering
violation are based on the above principle of avoiding to mix
layers. If I understood well, in your view media_graph_init()
should not do any type-specific code.

Well, on my view, we're actually implementing in C an optimized code
for an object-oriented implementation for the media objects.

In that sense, media_graph_init() is actually the constructor of
any graph object, and media_graph_remove() its destructor. While
on C++ we would use some virtual methods for type-specific handling
(and we could be doing that by adding some ops for the type-specific
handling at object creation/removal, I opted to just fold such
code inside those functions, as:
	1) the type-specific handling is actually a very small logic
	   with just a few lines per type;
	2) the code will be smaller and simpler;
	3) no need to add an "ops" field to be passed to the
	   constructor and be used by the destructor.

So, I think we should handle this as an exception. If this proofs to
be wrong, we can redesign it later, as changing it won't affect the
uAPI.


> 
> > If we don't do that, we would need this kind of interaction
> > to send data to userspace (code is in structured english):
> > 
> > 	for each entity:
> > 		for each pad:
> > 			store pads
> > 
> > 	for each entity:
> > 		for each link:
> > 			store link
> > 
> > 	for each interface:
> > 		for each link:
> > 			store link
> > 
> > With would require one nexted loop for pads and two nested
> 
> s/nexted loop/nested loop/
> 
> > loops for links. By using  separate linked lists for them,
> > just one loop would be enough.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index ec98595b8a7a..5b2c9f7fcd45 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -382,6 +382,8 @@ int __must_check __media_device_register(struct
> > media_device *mdev,
> > 
> >  	INIT_LIST_HEAD(&mdev->entities);
> >  	INIT_LIST_HEAD(&mdev->interfaces);
> > +	INIT_LIST_HEAD(&mdev->pads);
> > +	INIT_LIST_HEAD(&mdev->links);
> >  	spin_lock_init(&mdev->lock);
> >  	mutex_init(&mdev->graph_mutex);
> > 
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index cbb0604e81c1..568553d41f5d 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -174,13 +174,15 @@ void media_gobj_init(struct media_device *mdev,
> >  		break;
> >  	case MEDIA_GRAPH_PAD:
> >  		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
> > +		list_add_tail(&gobj->list, &mdev->pads);
> >  		break;
> >  	case MEDIA_GRAPH_LINK:
> >  		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
> > +		list_add_tail(&gobj->list, &mdev->links);
> >  		break;
> >  	case MEDIA_GRAPH_INTF_DEVNODE:
> > -		list_add_tail(&gobj->list, &mdev->interfaces);
> >  		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
> > +		list_add_tail(&gobj->list, &mdev->interfaces);
> >  		break;
> >  	}
> >  	dev_dbg_obj(__func__, gobj);
> > @@ -195,17 +197,10 @@ void media_gobj_init(struct media_device *mdev,
> >   */
> >  void media_gobj_remove(struct media_gobj *gobj)
> >  {
> > +	dev_dbg_obj(__func__, gobj);
> > +
> >  	/* Remove the object from mdev list */
> > -	switch (media_type(gobj)) {
> > -	case MEDIA_GRAPH_ENTITY:
> > -	case MEDIA_GRAPH_INTF_DEVNODE:
> > -		list_del(&gobj->list);
> > -		break;
> > -	default:
> > -		break;
> > -	}
> > -
> > -	dev_dbg_obj(__func__, gobj);
> > +	list_del(&gobj->list);
> >  }
> > 
> >  /**
> > diff --git a/include/media/media-device.h b/include/media/media-device.h
> > index 85fa302047bd..0d1b9c687454 100644
> > --- a/include/media/media-device.h
> > +++ b/include/media/media-device.h
> > @@ -47,6 +47,8 @@ struct device;
> >   * @intf_devnode_id: Unique ID used on the last interface devnode
> > registered * @entities:	List of registered entities
> >   * @interfaces:	List of registered interfaces
> > + * @pads:	List of registered pads
> > + * @links:	List of registered links
> >   * @lock:	Entities list lock
> >   * @graph_mutex: Entities graph operation lock
> >   * @link_notify: Link state change notification callback
> > @@ -79,6 +81,8 @@ struct media_device {
> > 
> >  	struct list_head entities;
> >  	struct list_head interfaces;
> > +	struct list_head pads;
> > +	struct list_head links;
> > 
> >  	/* Protects the entities list */
> >  	spinlock_t lock;
> > @@ -117,6 +121,14 @@ struct media_device *media_device_find_devres(struct
> > device *dev); #define media_device_for_each_intf(intf, mdev)			\
> >  	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
> > 
> > +/* Iterate over all pads. */
> > +#define media_device_for_each_pad(pad, mdev)			\
> > +	list_for_each_entry(pad, &(mdev)->pads, graph_obj.list)
> > +
> > +/* Iterate over all links. */
> > +#define media_device_for_each_link(link, mdev)			\
> > +	list_for_each_entry(link, &(mdev)->links, graph_obj.list)
> > +
> > 
> >  #else
> >  static inline int media_device_register(struct media_device *mdev)
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
@ 2015-12-06  0:47       ` Laurent Pinchart
  0 siblings, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  0:47 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, linux-api

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:03:04 Mauro Carvalho Chehab wrote:
> Add a new ioctl that will report the entire topology on
> one go.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 7320cdc45833..2d5ad40254b7 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -181,6 +181,8 @@ struct media_interface {
>   */
>  struct media_intf_devnode {
>  	struct media_interface		intf;
> +
> +	/* Should match the fields at media_v2_intf_devnode */
>  	u32				major;
>  	u32				minor;
>  };
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index a1bd7afba110..b17f6763aff4 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -206,6 +206,10 @@ struct media_pad_desc {
>  #define MEDIA_LNK_FL_IMMUTABLE		(1 << 1)
>  #define MEDIA_LNK_FL_DYNAMIC		(1 << 2)
> 
> +#define MEDIA_LNK_FL_LINK_TYPE		(0xf << 28)
> +#  define MEDIA_LNK_FL_DATA_LINK	(0 << 28)
> +#  define MEDIA_LNK_FL_INTERFACE_LINK	(1 << 28)
> +
>  struct media_link_desc {
>  	struct media_pad_desc source;
>  	struct media_pad_desc sink;
> @@ -249,11 +253,93 @@ struct media_links_enum {
>  #define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
>  #define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
> 
> -/* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
> +/*
> + * MC next gen API definitions
> + *
> + * NOTE: The declarations below are close to the MC RFC for the Media
> + *	 Controller, the next generation. Yet, there are a few adjustments
> + *	 to do, as we want to be able to have a functional API before
> + *	 the MC properties change. Those will be properly marked below.
> + *	 Please also notice that I removed "num_pads", "num_links",
> + *	 from the proposal, as a proper userspace application will likely
> + *	 use lists for pads/links, just as we intend to do in Kernelspace.
> + *	 The API definition should be freed from fields that are bound to
> + *	 some specific data structure.
> + *
> + * FIXME: Currently, I opted to name the new types as "media_v2", as this
> + *	  won't cause any conflict with the Kernelspace namespace, nor with
> + *	  the previous kAPI media_*_desc namespace. This can be changed
> + *	  later, before the adding this API upstream.

Yes, that's a good idea. Or at least we need to remove this comment if we 
decide to keep the v2 names :-)

> + */
> +
> +
> +struct media_v2_entity {
> +	__u32 id;
> +	char name[64];		/* FIXME: move to a property? (RFC says so) */

I agree with Sakari that we can keep the name here even if we also expose it 
as a property. However, there's one issue we need to address : we need to 
clearly define what the name field should contain and how it should be 
constructed, otherwise we'll end up with the exact same mess as today, and I 
don't want that. We can discuss it in this mail thread or as replies to a 
future documentation patch.

> +	__u16 reserved[14];

Sakari and Hans have already commented on using __u32 instead of __u16 for 
reserved fields, as well as on the number of reserved fields. I agree with 
them but have nothing to add.

> +};
> +
> +/* Should match the specific fields at media_intf_devnode */
> +struct media_v2_intf_devnode {
> +	__u32 major;
> +	__u32 minor;
> +};
> +
> +struct media_v2_interface {
> +	__u32 id;
> +	__u32 intf_type;
> +	__u32 flags;
> +	__u32 reserved[9];
> +
> +	union {
> +		struct media_v2_intf_devnode devnode;
> +		__u32 raw[16];
> +	};
> +};
> +
> +struct media_v2_pad {
> +	__u32 id;
> +	__u32 entity_id;
> +	__u32 flags;
> +	__u16 reserved[9];
> +};
> +
> +struct media_v2_link {
> +    __u32 id;
> +    __u32 source_id;
> +    __u32 sink_id;
> +    __u32 flags;
> +    __u32 reserved[5];
> +};
> +
> +struct media_v2_topology {
> +	__u32 topology_version;
> +
> +	__u32 num_entities;
> +	struct media_v2_entity *entities;

The kernel seems to be moving to using __u64 instead of pointers in userspace-
facing structures to avoid compat32 code.

> +
> +	__u32 num_interfaces;
> +	struct media_v2_interface *interfaces;
> +
> +	__u32 num_pads;
> +	struct media_v2_pad *pads;
> +
> +	__u32 num_links;
> +	struct media_v2_link *links;
> +
> +	struct {
> +		__u32 reserved_num;
> +		void *reserved_ptr;
> +	} reserved_types[16];
> +	__u32 reserved[8];

I'd just create __u32 reserved fields without any reserved_types, we can 
always use the reserved fields to add new types later.

> +};
> +
> +/* ioctls */
> 
>  #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct 
media_device_info)
>  #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct 
media_entity_desc)
> #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
> #define MEDIA_IOC_SETUP_LINK		_IOWR('|', 0x03, struct media_link_desc)
> +#define MEDIA_IOC_G_TOPOLOGY		_IOWR('|', 0x04, struct media_v2_topology)
> 
>  #endif /* __LINUX_MEDIA_H */

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
@ 2015-12-06  0:47       ` Laurent Pinchart
  0 siblings, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  0:47 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, linux-api-u79uwXL29TY76Z2rM5mHXA

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:03:04 Mauro Carvalho Chehab wrote:
> Add a new ioctl that will report the entire topology on
> one go.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 7320cdc45833..2d5ad40254b7 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -181,6 +181,8 @@ struct media_interface {
>   */
>  struct media_intf_devnode {
>  	struct media_interface		intf;
> +
> +	/* Should match the fields at media_v2_intf_devnode */
>  	u32				major;
>  	u32				minor;
>  };
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index a1bd7afba110..b17f6763aff4 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -206,6 +206,10 @@ struct media_pad_desc {
>  #define MEDIA_LNK_FL_IMMUTABLE		(1 << 1)
>  #define MEDIA_LNK_FL_DYNAMIC		(1 << 2)
> 
> +#define MEDIA_LNK_FL_LINK_TYPE		(0xf << 28)
> +#  define MEDIA_LNK_FL_DATA_LINK	(0 << 28)
> +#  define MEDIA_LNK_FL_INTERFACE_LINK	(1 << 28)
> +
>  struct media_link_desc {
>  	struct media_pad_desc source;
>  	struct media_pad_desc sink;
> @@ -249,11 +253,93 @@ struct media_links_enum {
>  #define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
>  #define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
> 
> -/* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
> +/*
> + * MC next gen API definitions
> + *
> + * NOTE: The declarations below are close to the MC RFC for the Media
> + *	 Controller, the next generation. Yet, there are a few adjustments
> + *	 to do, as we want to be able to have a functional API before
> + *	 the MC properties change. Those will be properly marked below.
> + *	 Please also notice that I removed "num_pads", "num_links",
> + *	 from the proposal, as a proper userspace application will likely
> + *	 use lists for pads/links, just as we intend to do in Kernelspace.
> + *	 The API definition should be freed from fields that are bound to
> + *	 some specific data structure.
> + *
> + * FIXME: Currently, I opted to name the new types as "media_v2", as this
> + *	  won't cause any conflict with the Kernelspace namespace, nor with
> + *	  the previous kAPI media_*_desc namespace. This can be changed
> + *	  later, before the adding this API upstream.

Yes, that's a good idea. Or at least we need to remove this comment if we 
decide to keep the v2 names :-)

> + */
> +
> +
> +struct media_v2_entity {
> +	__u32 id;
> +	char name[64];		/* FIXME: move to a property? (RFC says so) */

I agree with Sakari that we can keep the name here even if we also expose it 
as a property. However, there's one issue we need to address : we need to 
clearly define what the name field should contain and how it should be 
constructed, otherwise we'll end up with the exact same mess as today, and I 
don't want that. We can discuss it in this mail thread or as replies to a 
future documentation patch.

> +	__u16 reserved[14];

Sakari and Hans have already commented on using __u32 instead of __u16 for 
reserved fields, as well as on the number of reserved fields. I agree with 
them but have nothing to add.

> +};
> +
> +/* Should match the specific fields at media_intf_devnode */
> +struct media_v2_intf_devnode {
> +	__u32 major;
> +	__u32 minor;
> +};
> +
> +struct media_v2_interface {
> +	__u32 id;
> +	__u32 intf_type;
> +	__u32 flags;
> +	__u32 reserved[9];
> +
> +	union {
> +		struct media_v2_intf_devnode devnode;
> +		__u32 raw[16];
> +	};
> +};
> +
> +struct media_v2_pad {
> +	__u32 id;
> +	__u32 entity_id;
> +	__u32 flags;
> +	__u16 reserved[9];
> +};
> +
> +struct media_v2_link {
> +    __u32 id;
> +    __u32 source_id;
> +    __u32 sink_id;
> +    __u32 flags;
> +    __u32 reserved[5];
> +};
> +
> +struct media_v2_topology {
> +	__u32 topology_version;
> +
> +	__u32 num_entities;
> +	struct media_v2_entity *entities;

The kernel seems to be moving to using __u64 instead of pointers in userspace-
facing structures to avoid compat32 code.

> +
> +	__u32 num_interfaces;
> +	struct media_v2_interface *interfaces;
> +
> +	__u32 num_pads;
> +	struct media_v2_pad *pads;
> +
> +	__u32 num_links;
> +	struct media_v2_link *links;
> +
> +	struct {
> +		__u32 reserved_num;
> +		void *reserved_ptr;
> +	} reserved_types[16];
> +	__u32 reserved[8];

I'd just create __u32 reserved fields without any reserved_types, we can 
always use the reserved fields to add new types later.

> +};
> +
> +/* ioctls */
> 
>  #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct 
media_device_info)
>  #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct 
media_entity_desc)
> #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
> #define MEDIA_IOC_SETUP_LINK		_IOWR('|', 0x03, struct media_link_desc)
> +#define MEDIA_IOC_G_TOPOLOGY		_IOWR('|', 0x04, struct media_v2_topology)
> 
>  #endif /* __LINUX_MEDIA_H */

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 43/55] [media] media: report if a pad is sink or source at debug msg
  2015-09-06 12:03   ` Mauro Carvalho Chehab
  2015-09-11 13:52     ` Hans Verkuil
@ 2015-12-06  0:53     ` Laurent Pinchart
  2015-12-08 18:46       ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  0:53 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:03:03 Mauro Carvalho Chehab wrote:
> Sometimes, it is important to see if the created pad is
> sink or source. Add info to track that.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index d8038a53f945..6ed5eef88593 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -121,8 +121,11 @@ static void dev_dbg_obj(const char *event_name,  struct
> media_gobj *gobj) struct media_pad *pad = gobj_to_pad(gobj);
> 
>  		dev_dbg(gobj->mdev->dev,
> -			"%s: id 0x%08x pad#%d: '%s':%d\n",
> -			event_name, gobj->id, media_localid(gobj),
> +			"%s: id 0x%08x %s%spad#%d: '%s':%d\n",
> +			event_name, gobj->id,
> +			pad->flags & MEDIA_PAD_FL_SINK   ? "  sink " : "",
> +			pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",

I'm wondering if we really need the two leading spaces in "  sink ", as a 
bidirectional pad would print "  sink source pad" and mess up the alignment 
anyway.

> +			media_localid(gobj),
>  			pad->entity->name, pad->index);
>  		break;
>  	}

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 41/55] [media] DocBook: update descriptions for the media controller entities
  2015-09-11 13:13     ` Hans Verkuil
@ 2015-12-06  1:00       ` Laurent Pinchart
  2015-12-08 18:04         ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  1:00 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List, Jonathan Corbet,
	linux-doc

Hello,

On Friday 11 September 2015 15:13:30 Hans Verkuil wrote:
> On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> > Cleanup the media controller entities description:
> > - remove MEDIA_ENT_T_DEVNODE and MEDIA_ENT_T_V4L2_SUBDEV entity
> >   types, as they don't mean anything;
> > - add MEDIA_ENT_T_UNKNOWN with a proper description;
> > - remove ALSA and FB entity types. Those should not be used, as
> >   the types are deprecated. We'll soon be adidng ALSA, but with
> >   a different entity namespace;
> > - improve the description of some entities.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> > b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml index
> > 32a783635649..bc101516e372 100644
> > --- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> > +++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> > @@ -179,70 +179,65 @@
> >          <colspec colname="c2"/>
> >  	<tbody valign="top">
> >  	  <row>
> > -	    <entry><constant>MEDIA_ENT_T_DEVNODE</constant></entry>
> > -	    <entry>Unknown device node</entry>
> > +	    <entry><constant>MEDIA_ENT_T_UNKNOWN</constant> and
> > <constant>MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN</constant></entry> +	   
> > <entry>Unknown entity. That generally indicates that
> > +	    a driver didn't initialize properly the entity, with is a Kernel
> > bug</entry>> 
> >  	  </row>
> 
> I'm wondering: if userspace should never see an unknown entity, wouldn't it
> be better to move these UNKNOWN defines out of the public header to a kernel
> header and drop this from the documentation?

And shouldn't the bug be caught in kernelspace before it reaches the user ?

> >  	  <row>
> >  	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
> > -	    <entry>V4L video, radio or vbi device node</entry>
> > +	    <entry>V4L video streaming input or output entity</entry>
> >  	  </row>
> > -	  <row>
> > -	    <entry><constant>MEDIA_ENT_T_DEVNODE_FB</constant></entry>
> > -	    <entry>Frame buffer device node</entry>
> > +	    <entry><constant>MEDIA_ENT_T_V4L2_VBI</constant></entry>
> > +	    <entry>V4L VBI streaming input or output entity</entry>
> >  	  </row>
> > -	  <row>
> > -	    <entry><constant>MEDIA_ENT_T_DEVNODE_ALSA</constant></entry>
> > -	    <entry>ALSA card</entry>
> > +	    <entry><constant>MEDIA_ENT_T_V4L2_SWRADIO</constant></entry>
> > +	    <entry>V4L Sofware Digital Radio (SDR) streaming input or output
> > entity</entry>
>
> s/Sofware/Software/
> 
> >  	  </row>
> >  	  <row>
> >  	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD</constant></entry>
> > -	    <entry>DVB frontend devnode</entry>
> > +	    <entry>DVB demodulator entity</entry>
> >  	  </row>
> >  	  <row>
> >  	    <entry><constant>MEDIA_ENT_T_DVB_DEMUX</constant></entry>
> > -	    <entry>DVB demux devnode</entry>
> > +	    <entry>DVB demux entity. Could be implemented on hardware or in
> > Kernelspace</entry>

s/Could be/Can be/

> s/on/in/
> 
> >  	  </row>
> >  	  <row>
> >  	    <entry><constant>MEDIA_ENT_T_DVB_TSOUT</constant></entry>
> > -	    <entry>DVB DVR devnode</entry>
> > +	    <entry>DVB Transport Stream output entity</entry>
> >  	  </row>
> >  	  <row>
> >  	    <entry><constant>MEDIA_ENT_T_DVB_CA</constant></entry>
> > -	    <entry>DVB CAM devnode</entry>
> > +	    <entry>DVB Conditional Access module (CAM) entity</entry>
> >  	  </row>
> >  	  <row>
> >  	    
<entry><constant>MEDIA_ENT_T_DVB_DEMOD_NET_DECAP</constant></entry>
> > -	    <entry>DVB network devnode</entry>
> > -	  </row>
> > -	  <row>
> > -	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV</constant></entry>
> > -	    <entry>Unknown V4L sub-device</entry>
> > +	    <entry>DVB network ULE/MLE desencapsulation entity. Could be
> > implemented on hardware or in Kernelspace</entry>

s/Could be/Can be/

> s/on/in/
> 
> Hmm, is desencapsulation correct? Could it be 'de-encapsulation' instead? It
> looks weird.
>
> >  	  </row>
> >  	  <row>
> >  	    
<entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_SENSOR</constant></entry>
> > -	    <entry>Video sensor</entry>
> > +	    <entry>Camera video sensor entity</entry>

s/video sensor/image sensor/

> >  	  </row>
> >  	  <row>
> >  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_FLASH</constant></entry>
> > -	    <entry>Flash controller</entry>
> > +	    <entry>Flash controller entity</entry>
> >  	  </row>
> >  	  <row>
> >  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_LENS</constant></entry>
> > -	    <entry>Lens controller</entry>
> > +	    <entry>Lens controller entity</entry>
> >  	  </row>
> >  	  <row>
> >  	    
<entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_DECODER</constant></entry>
> > -	    <entry>Video decoder, the basic function of the video decoder is 
to
> > -	    accept analogue video from a wide variety of sources such as
> > +	    <entry>Analog video decoder, the basic function of the video 
decoder
> > +	    is to accept analogue video from a wide variety of sources such 
as
> >  	    broadcast, DVD players, cameras and video cassette recorders, in
> > -	    either NTSC, PAL or HD format and still occasionally SECAM, 
separate
> > -	    it into its component parts, luminance and chrominance, and 
output
> > +	    either NTSC, PAL, SECAM or HD format, separating the stream
> > +	    into its component parts, luminance and chrominance, and output
> >  	    it in some digital video standard, with appropriate embedded 
timing
> >  	    signals.</entry>

Does timing signals refer to synchronization signals ? They don't have to be 
embedded, do they ?

> >  	  </row>
> >  	  <row>
> >  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_TUNER</constant></entry>
> > -	    <entry>TV and/or radio tuner</entry>
> > +	    <entry>Digital TV, analog TV, radio and/or software radio
> > tuner</entry>> 
> >  	  </row>
> >  	</tbody>
> >        </tgroup>

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 40/55] [media] media.h: don't use legacy entity macros at Kernel
@ 2015-12-06  1:02       ` Laurent Pinchart
  0 siblings, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  1:02 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, linux-api

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:03:00 Mauro Carvalho Chehab wrote:
> Put the legacy MEDIA_ENT_* macros under a #ifndef __KERNEL__,
> in order to be sure that none of those old symbols are used
> inside the Kernel.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index f90147cb9b57..a1bd7afba110 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -105,6 +105,7 @@ struct media_device_info {
>  #define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 4)
>  #define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 5)
> 
> +#ifndef __KERNEL__
>  /* Legacy symbols used to avoid userspace compilation breakages */
>  #define MEDIA_ENT_TYPE_SHIFT		16
>  #define MEDIA_ENT_TYPE_MASK		0x00ff0000
> @@ -118,6 +119,7 @@ struct media_device_info {
>  #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
>  #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
>  #define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
> +#endif
> 
>  /* Entity types */

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 40/55] [media] media.h: don't use legacy entity macros at Kernel
@ 2015-12-06  1:02       ` Laurent Pinchart
  0 siblings, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  1:02 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, linux-api-u79uwXL29TY76Z2rM5mHXA

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:03:00 Mauro Carvalho Chehab wrote:
> Put the legacy MEDIA_ENT_* macros under a #ifndef __KERNEL__,
> in order to be sure that none of those old symbols are used
> inside the Kernel.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>
> Acked-by: Hans Verkuil <hans.verkuil-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>

Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>

> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index f90147cb9b57..a1bd7afba110 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -105,6 +105,7 @@ struct media_device_info {
>  #define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 4)
>  #define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 5)
> 
> +#ifndef __KERNEL__
>  /* Legacy symbols used to avoid userspace compilation breakages */
>  #define MEDIA_ENT_TYPE_SHIFT		16
>  #define MEDIA_ENT_TYPE_MASK		0x00ff0000
> @@ -118,6 +119,7 @@ struct media_device_info {
>  #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
>  #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
>  #define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
> +#endif
> 
>  /* Entity types */

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 39/55] [media] media controller: get rid of entity subtype on Kernel
@ 2015-12-06  1:03       ` Laurent Pinchart
  0 siblings, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  1:03 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, linux-api

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:02:59 Mauro Carvalho Chehab wrote:
> Don't use anymore the type/subtype entity data/macros
> inside the Kernel.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 220864319d21..7320cdc45833 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -185,16 +185,6 @@ struct media_intf_devnode {
>  	u32				minor;
>  };
> 
> -static inline u32 media_entity_type(struct media_entity *entity)
> -{
> -	return entity->type & MEDIA_ENT_TYPE_MASK;
> -}
> -
> -static inline u32 media_entity_subtype(struct media_entity *entity)
> -{
> -	return entity->type & MEDIA_ENT_SUBTYPE_MASK;
> -}
> -
>  static inline u32 media_entity_id(struct media_entity *entity)
>  {
>  	return entity->graph_obj.id;
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index 3d6210095336..f90147cb9b57 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -42,8 +42,6 @@ struct media_device_info {
> 
>  #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
> 
> -/* Used values for media_entity_desc::type */
> -
>  /*
>   * Initial value to be used when a new entity is created
>   * Drivers should change it to something useful

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 39/55] [media] media controller: get rid of entity subtype on Kernel
@ 2015-12-06  1:03       ` Laurent Pinchart
  0 siblings, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  1:03 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, linux-api-u79uwXL29TY76Z2rM5mHXA

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:02:59 Mauro Carvalho Chehab wrote:
> Don't use anymore the type/subtype entity data/macros
> inside the Kernel.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>

Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>

> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 220864319d21..7320cdc45833 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -185,16 +185,6 @@ struct media_intf_devnode {
>  	u32				minor;
>  };
> 
> -static inline u32 media_entity_type(struct media_entity *entity)
> -{
> -	return entity->type & MEDIA_ENT_TYPE_MASK;
> -}
> -
> -static inline u32 media_entity_subtype(struct media_entity *entity)
> -{
> -	return entity->type & MEDIA_ENT_SUBTYPE_MASK;
> -}
> -
>  static inline u32 media_entity_id(struct media_entity *entity)
>  {
>  	return entity->graph_obj.id;
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index 3d6210095336..f90147cb9b57 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -42,8 +42,6 @@ struct media_device_info {
> 
>  #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
> 
> -/* Used values for media_entity_desc::type */
> -
>  /*
>   * Initial value to be used when a new entity is created
>   * Drivers should change it to something useful

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 38/55] [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs
  2015-09-06 12:02   ` Mauro Carvalho Chehab
@ 2015-12-06  1:37     ` Laurent Pinchart
  2015-12-08 17:38       ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  1:37 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Hans Verkuil, Sylwester Nawrocki, Lad,
	Prabhakar, Markus Elfring, Lars-Peter Clausen, linux-api

Hi Mauro,

Thank you for the patch.

In addition to my reply to Sakari's e-mail, please see below for a few small 
comments.

On Sunday 06 September 2015 09:02:58 Mauro Carvalho Chehab wrote:
> Instead of abusing MEDIA_ENT_T_V4L2_SUBDEV, initialize
> new subdev entities as MEDIA_ENT_T_UNKNOWN.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 659507bce63f..134fe7510195 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -435,6 +435,12 @@ int __must_check media_device_register_entity(struct
> media_device *mdev, {
>  	int i;
> 
> +	if (entity->type == MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN ||
> +	    entity->type == MEDIA_ENT_T_UNKNOWN)
> +		dev_warn(mdev->dev,
> +			 "Entity type for entity %s was not initialized!\n",
> +			 entity->name);
> +
>  	/* Warn if we apparently re-register an entity */
>  	WARN_ON(entity->graph_obj.mdev != NULL);
>  	entity->graph_obj.mdev = mdev;
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c
> b/drivers/media/v4l2-core/v4l2-subdev.c index 60da43772de9..b3bcc8253182
> 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -584,7 +584,7 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const
> struct v4l2_subdev_ops *ops) sd->host_priv = NULL;
>  #if defined(CONFIG_MEDIA_CONTROLLER)
>  	sd->entity.name = sd->name;
> -	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
> +	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN;
>  #endif
>  }
>  EXPORT_SYMBOL(v4l2_subdev_init);
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index f8725b881a1d..3d6210095336 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -42,6 +42,14 @@ struct media_device_info {
> 
>  #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
> 
> +/* Used values for media_entity_desc::type */
> +

You remove this a couple of patches later, is it worth adding it in the first 
place ?

> +/*
> + * Initial value to be used when a new entity is created
> + * Drivers should change it to something useful

As you warn when the value isn't change I'd say "Drivers must change...".

> + */
> +#define MEDIA_ENT_T_UNKNOWN	0x00000000
> +
>  /*
>   * Base numbers for entity types
>   *
> @@ -75,6 +83,15 @@ struct media_device_info {
>  #define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 6)
> 
>  /* V4L2 Sub-device entities */
> +
> +	/*
> +	 * Subdevs are initialized with MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN,
> +	 * in order to preserve backward compatibility.
> +	 * Drivers should change to the proper subdev type before
> +	 * registering the entity.
> +	 */

Leading tabs look weird here.

> +#define MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN	MEDIA_ENT_T_V4L2_SUBDEV_BASE
> +
>  #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
>  #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
>  #define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 37/55] [media] omap4iss: stop MEDIA_ENT_T_V4L2_SUBDEV abuse
  2015-08-30  3:06 ` [PATCH v8 37/55] [media] omap4iss: " Mauro Carvalho Chehab
@ 2015-12-06  1:46   ` Laurent Pinchart
  2015-12-08 17:47     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  1:46 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, devel

Hi Mauro,

Thank you for the patch.

On Sunday 30 August 2015 00:06:48 Mauro Carvalho Chehab wrote:
> This driver is abusing MEDIA_ENT_T_V4L2_SUBDEV, as it uses a
> hack to check if the remote entity is a subdev. Get rid of it.

While I agree with the idea of the patch I don't think this is a hack, it was 
a totally valid implementation with the existing API.

> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/staging/media/omap4iss/iss_ipipe.c
> b/drivers/staging/media/omap4iss/iss_ipipe.c index
> e1a7b7ba7362..eb91ec48a21e 100644
> --- a/drivers/staging/media/omap4iss/iss_ipipe.c
> +++ b/drivers/staging/media/omap4iss/iss_ipipe.c
> @@ -447,8 +447,11 @@ static int ipipe_link_setup(struct media_entity
> *entity, struct iss_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
>  	struct iss_device *iss = to_iss_device(ipipe);
> 
> -	switch (local->index | media_entity_type(remote->entity)) {
> -	case IPIPE_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> +	if (!is_media_entity_v4l2_subdev(remote->entity))
> +		return -EINVAL;
> +

Furthermore the ipipe entity is never connected to anything else than a 
subdev, so you can remove this check completely.

I'd rewrite the subject line as "omap4iss: ipipe: Don't check entity type 
needlessly during link setup" and update the commit message accordingly.

> +	switch (local->index) {
> +	case IPIPE_PAD_SINK:
>  		/* Read from IPIPEIF. */
>  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  			ipipe->input = IPIPE_INPUT_NONE;
> @@ -463,7 +466,7 @@ static int ipipe_link_setup(struct media_entity *entity,
> 
>  		break;
> 
> -	case IPIPE_PAD_SOURCE_VP | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case IPIPE_PAD_SOURCE_VP:
>  		/* Send to RESIZER */
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (ipipe->output & ~IPIPE_OUTPUT_VP)

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 36/55] [media] davinci_vbpe: stop MEDIA_ENT_T_V4L2_SUBDEV abuse
  2015-08-30  3:06 ` [PATCH v8 36/55] [media] davinci_vbpe: stop MEDIA_ENT_T_V4L2_SUBDEV abuse Mauro Carvalho Chehab
@ 2015-12-06  1:52   ` Laurent Pinchart
  2015-12-08 17:22     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  1:52 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Hans Verkuil, Prabhakar Lad, Sakari Ailus,
	Aya Mahfouz, Boris BREZILLON, Javier Martinez Canillas, devel

Hi Mauro,

Thank you for the patch.

On Sunday 30 August 2015 00:06:47 Mauro Carvalho Chehab wrote:
> This driver is abusing MEDIA_ENT_T_V4L2_SUBDEV:
> 
> - it uses a hack to check if the remote entity is a subdev;

Same comment as for "omap4iss: stop MEDIA_ENT_T_V4L2_SUBDEV abuse", this isn't 
a hack.

> - it still uses the legacy entity subtype check macro, that
>   will be removed soon.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
> b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c index
> b89a057b8b7e..7fd78329e3e1 100644
> --- a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
> +++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
> @@ -1711,8 +1711,11 @@ ipipe_link_setup(struct media_entity *entity, const
> struct media_pad *local, struct vpfe_device *vpfe_dev =
> to_vpfe_device(ipipe);
>  	u16 ipipeif_sink = vpfe_dev->vpfe_ipipeif.input;
> 
> -	switch (local->index | media_entity_type(remote->entity)) {
> -	case IPIPE_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> +	if (!is_media_entity_v4l2_subdev(remote->entity))
> +		return -EINVAL;

You can drop the check (even though the implementation in the switch looks 
dubious to me, but that's not your fault).

> +	switch (local->index) {
> +	case IPIPE_PAD_SINK:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  			ipipe->input = IPIPE_INPUT_NONE;
>  			break;
> @@ -1725,7 +1728,7 @@ ipipe_link_setup(struct media_entity *entity, const
> struct media_pad *local, ipipe->input = IPIPE_INPUT_CCDC;
>  		break;
> 
> -	case IPIPE_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case IPIPE_PAD_SOURCE:
>  		/* out to RESIZER */
>  		if (flags & MEDIA_LNK_FL_ENABLED)
>  			ipipe->output = IPIPE_OUTPUT_RESIZER;
> diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> b/drivers/staging/media/davinci_vpfe/vpfe_video.c index
> 9eef64e0f0ab..2dbf14b9bb5f 100644
> --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> @@ -88,7 +88,7 @@ vpfe_video_remote_subdev(struct vpfe_video_device *video,
> u32 *pad) {
>  	struct media_pad *remote = media_entity_remote_pad(&video->pad);
> 
> -	if (remote == NULL || remote->entity->type != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
>  	if (pad)
>  		*pad = remote->index;
> @@ -243,8 +243,7 @@ static int vpfe_video_validate_pipeline(struct
> vpfe_pipeline *pipe)
> 
>  		/* Retrieve the source format */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -			pad->entity->type != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		subdev = media_entity_to_v4l2_subdev(pad->entity);

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 35/55] [media] s5k5baf: fix subdev type
  2015-08-30  3:06 ` [PATCH v8 35/55] [media] s5k5baf: " Mauro Carvalho Chehab
@ 2015-12-06  1:55   ` Laurent Pinchart
  2015-12-08 17:17     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  1:55 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Kyungmin Park,
	Andrzej Hajda

Hi Mauro,

Thank you for the patch.

On Sunday 30 August 2015 00:06:46 Mauro Carvalho Chehab wrote:
> X-Patchwork-Delegate: m.chehab@samsung.com
> This sensor driver is abusing MEDIA_ENT_T_V4L2_SUBDEV, creating
> some subdevs with a non-existing type.
> 
> As this is a sensor driver, the proper type is likely
> MEDIA_ENT_T_V4L2_SUBDEV_SENSOR.

That's actually not correct. The driver creates two subdevs, one for the image 
sensor pixel array (and the related readout logic) and one for an ISP. The 
first subdev already uses the MEDIA_ENT_T_V4L2_SUBDEV_SENSOR type, but the 
second subdev isn't a sensor pixel array.

> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
> index d3bff30bcb6f..0513196bd48c 100644
> --- a/drivers/media/i2c/s5k5baf.c
> +++ b/drivers/media/i2c/s5k5baf.c
> @@ -1919,7 +1919,7 @@ static int s5k5baf_configure_subdevs(struct s5k5baf
> *state,
> 
>  	state->pads[PAD_CIS].flags = MEDIA_PAD_FL_SINK;
>  	state->pads[PAD_OUT].flags = MEDIA_PAD_FL_SOURCE;
> -	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
> +	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
>  	ret = media_entity_init(&sd->entity, NUM_ISP_PADS, state->pads);
> 
>  	if (!ret)

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 34/55] [media] s5c73m3: fix subdev type
  2015-08-30  3:06 ` [PATCH v8 34/55] [media] s5c73m3: fix subdev type Mauro Carvalho Chehab
@ 2015-12-06  1:57   ` Laurent Pinchart
  2015-12-08 17:11     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  1:57 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Kyungmin Park,
	Andrzej Hajda

Hi Mauro,

Thank you for the patch.

On Sunday 30 August 2015 00:06:45 Mauro Carvalho Chehab wrote:
> This sensor driver is abusing MEDIA_ENT_T_V4L2_SUBDEV, creating
> some subdevs with a non-existing type.
> 
> As this is a sensor driver, the proper type is likely
> MEDIA_ENT_T_CAM_SENSOR.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> b/drivers/media/i2c/s5c73m3/s5c73m3-core.c index c81bfbfea32f..abae37321c0c
> 100644
> --- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> +++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> @@ -1688,7 +1688,7 @@ static int s5c73m3_probe(struct i2c_client *client,
> 
>  	state->sensor_pads[S5C73M3_JPEG_PAD].flags = MEDIA_PAD_FL_SOURCE;
>  	state->sensor_pads[S5C73M3_ISP_PAD].flags = MEDIA_PAD_FL_SOURCE;
> -	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
> +	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;

As explained in my review of "s5k5baf: fix subdev type", this is correct...

>  	ret = media_entity_init(&sd->entity, S5C73M3_NUM_PADS,
>  							state->sensor_pads);
> @@ -1704,7 +1704,7 @@ static int s5c73m3_probe(struct i2c_client *client,
>  	state->oif_pads[OIF_ISP_PAD].flags = MEDIA_PAD_FL_SINK;
>  	state->oif_pads[OIF_JPEG_PAD].flags = MEDIA_PAD_FL_SINK;
>  	state->oif_pads[OIF_SOURCE_PAD].flags = MEDIA_PAD_FL_SOURCE;
> -	oif_sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
> +	oif_sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;

... but this isn't.

>  	ret = media_entity_init(&oif_sd->entity, OIF_NUM_PADS,
>  							state->oif_pads);

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 33/55] [media] omap3/omap4/davinci: get rid of MEDIA_ENT_T_V4L2_SUBDEV abuse
  2015-08-30  3:06 ` [PATCH v8 33/55] [media] omap3/omap4/davinci: get rid of MEDIA_ENT_T_V4L2_SUBDEV abuse Mauro Carvalho Chehab
@ 2015-12-06  2:08   ` Laurent Pinchart
  2015-12-08 16:52     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  2:08 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Hans Verkuil, Sakari Ailus, Prabhakar Lad,
	Haneen Mohammed, Tapasweni Pathak, Boris BREZILLON,
	Mahati Chamarthy, Javier Martinez Canillas, devel

Hi Mauro,

Thank you for the patch.

On Sunday 30 August 2015 00:06:44 Mauro Carvalho Chehab wrote:
> On omap3/omap4/davinci drivers, MEDIA_ENT_T_V4L2_SUBDEV macro is
> abused in order to "simplify" the pad checks.

As explained in a couple of other replies to similar patches, it's not a hack 
:-)

> Basically, it does a logical or of this macro, in order to check
> for a local index and if the entity is either a subdev or not.
> 
> As we'll get rid of MEDIA_ENT_T_V4L2_SUBDEV macro,

This is the reason for this patch, and I agree with it.

> replace it by 2 << 16 where it occurs, and add a note saying that the code
> there is actually a hack.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/platform/omap3isp/ispccdc.c
> b/drivers/media/platform/omap3isp/ispccdc.c index
> 9a811f5741fa..f0e530c98188 100644
> --- a/drivers/media/platform/omap3isp/ispccdc.c
> +++ b/drivers/media/platform/omap3isp/ispccdc.c
> @@ -2513,9 +2513,14 @@ static int ccdc_link_setup(struct media_entity
> *entity, struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
>  	struct isp_device *isp = to_isp_device(ccdc);
> +	int index = local->index;

The index can never be negative, you can use unsigned int.

> 
> -	switch (local->index | media_entity_type(remote->entity)) {
> -	case CCDC_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> +	/* FIXME: this is actually a hack! */

Please, let's not introduce a hack to replace valid code. I'm certainly fine 
with removing usage of MEDIA_ENT_T_V4L2_SUBDEV, but drivers should be modified 
cleanly.

If you rename the index variable to link and use a macro (I would call it 
LINK_TO_SUBDEV for instance) instead of 2 << 16 the implementation wouldn't be 
that bad, as what the switch operates on is the link, not the pad. I would 
also create a LINK_TO_DEVNODE macro, even if it evaluates to 0, to clearly 
label each case.

> +	if (is_media_entity_v4l2_subdev(remote->entity))
> +		index |= 2 << 16;

Why 2 << 16 and not 1 << 16 ?

Same comments for all the other files below (but please see the very end for 
one last comment).

> +	switch (index) {
> +	case CCDC_PAD_SINK | 2 << 16:
>  		/* Read from the sensor (parallel interface), CCP2, CSI2a or
>  		 * CSI2c.
>  		 */
> @@ -2543,7 +2548,7 @@ static int ccdc_link_setup(struct media_entity
> *entity, * Revisit this when it will be implemented, and return -EBUSY for
> now. */
> 
> -	case CCDC_PAD_SOURCE_VP | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case CCDC_PAD_SOURCE_VP | 2 << 16:
>  		/* Write to preview engine, histogram and H3A. When none of
>  		 * those links are active, the video port can be disabled.
>  		 */
> @@ -2556,7 +2561,7 @@ static int ccdc_link_setup(struct media_entity
> *entity, }
>  		break;
> 
> -	case CCDC_PAD_SOURCE_OF | MEDIA_ENT_T_DEVNODE:
> +	case CCDC_PAD_SOURCE_OF:
>  		/* Write to memory */
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (ccdc->output & ~CCDC_OUTPUT_MEMORY)
> @@ -2567,7 +2572,7 @@ static int ccdc_link_setup(struct media_entity
> *entity, }
>  		break;
> 
> -	case CCDC_PAD_SOURCE_OF | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case CCDC_PAD_SOURCE_OF | 2 << 16:
>  		/* Write to resizer */
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (ccdc->output & ~CCDC_OUTPUT_RESIZER)
> diff --git a/drivers/media/platform/omap3isp/ispccp2.c
> b/drivers/media/platform/omap3isp/ispccp2.c index
> 6ec7d104ab75..ae3038e643cc 100644
> --- a/drivers/media/platform/omap3isp/ispccp2.c
> +++ b/drivers/media/platform/omap3isp/ispccp2.c
> @@ -956,9 +956,14 @@ static int ccp2_link_setup(struct media_entity *entity,
> {
>  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct isp_ccp2_device *ccp2 = v4l2_get_subdevdata(sd);
> +	int index = local->index;
> 
> -	switch (local->index | media_entity_type(remote->entity)) {
> -	case CCP2_PAD_SINK | MEDIA_ENT_T_DEVNODE:
> +	/* FIXME: this is actually a hack! */
> +	if (is_media_entity_v4l2_subdev(remote->entity))
> +		index |= 2 << 16;
> +
> +	switch (index) {
> +	case CCP2_PAD_SINK:
>  		/* read from memory */
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (ccp2->input == CCP2_INPUT_SENSOR)
> @@ -970,7 +975,7 @@ static int ccp2_link_setup(struct media_entity *entity,
>  		}
>  		break;
> 
> -	case CCP2_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case CCP2_PAD_SINK | 2 << 16:
>  		/* read from sensor/phy */
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (ccp2->input == CCP2_INPUT_MEMORY)
> @@ -981,7 +986,7 @@ static int ccp2_link_setup(struct media_entity *entity,
>  				ccp2->input = CCP2_INPUT_NONE;
>  		} break;
> 
> -	case CCP2_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case CCP2_PAD_SOURCE | 2 << 16:
>  		/* write to video port/ccdc */
>  		if (flags & MEDIA_LNK_FL_ENABLED)
>  			ccp2->output = CCP2_OUTPUT_CCDC;
> diff --git a/drivers/media/platform/omap3isp/ispcsi2.c
> b/drivers/media/platform/omap3isp/ispcsi2.c index
> 0fb057a74f69..b1617f7efdee 100644
> --- a/drivers/media/platform/omap3isp/ispcsi2.c
> +++ b/drivers/media/platform/omap3isp/ispcsi2.c
> @@ -1144,14 +1144,19 @@ static int csi2_link_setup(struct media_entity
> *entity, struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct isp_csi2_device *csi2 = v4l2_get_subdevdata(sd);
>  	struct isp_csi2_ctrl_cfg *ctrl = &csi2->ctrl;
> +	int index = local->index;
> 
>  	/*
>  	 * The ISP core doesn't support pipelines with multiple video outputs.
>  	 * Revisit this when it will be implemented, and return -EBUSY for now.
>  	 */
> 
> -	switch (local->index | media_entity_type(remote->entity)) {
> -	case CSI2_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
> +	/* FIXME: this is actually a hack! */
> +	if (is_media_entity_v4l2_subdev(remote->entity))
> +		index |= 2 << 16;
> +
> +	switch (index) {
> +	case CSI2_PAD_SOURCE:
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (csi2->output & ~CSI2_OUTPUT_MEMORY)
>  				return -EBUSY;
> @@ -1161,7 +1166,7 @@ static int csi2_link_setup(struct media_entity
> *entity, }
>  		break;
> 
> -	case CSI2_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case CSI2_PAD_SOURCE | 2 << 16:
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (csi2->output & ~CSI2_OUTPUT_CCDC)
>  				return -EBUSY;
> diff --git a/drivers/media/platform/omap3isp/isppreview.c
> b/drivers/media/platform/omap3isp/isppreview.c index
> 6986d2f65c19..cfb2debb02bf 100644
> --- a/drivers/media/platform/omap3isp/isppreview.c
> +++ b/drivers/media/platform/omap3isp/isppreview.c
> @@ -2144,9 +2144,14 @@ static int preview_link_setup(struct media_entity
> *entity, {
>  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
> +	int index = local->index;
> 
> -	switch (local->index | media_entity_type(remote->entity)) {
> -	case PREV_PAD_SINK | MEDIA_ENT_T_DEVNODE:
> +	/* FIXME: this is actually a hack! */
> +	if (is_media_entity_v4l2_subdev(remote->entity))
> +		index |= 2 << 16;
> +
> +	switch (index) {
> +	case PREV_PAD_SINK:
>  		/* read from memory */
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (prev->input == PREVIEW_INPUT_CCDC)
> @@ -2158,7 +2163,7 @@ static int preview_link_setup(struct media_entity
> *entity, }
>  		break;
> 
> -	case PREV_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case PREV_PAD_SINK | 2 << 16:
>  		/* read from ccdc */
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (prev->input == PREVIEW_INPUT_MEMORY)
> @@ -2175,7 +2180,7 @@ static int preview_link_setup(struct media_entity
> *entity, * Revisit this when it will be implemented, and return -EBUSY for
> now. */
> 
> -	case PREV_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
> +	case PREV_PAD_SOURCE:
>  		/* write to memory */
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (prev->output & ~PREVIEW_OUTPUT_MEMORY)
> @@ -2186,7 +2191,7 @@ static int preview_link_setup(struct media_entity
> *entity, }
>  		break;
> 
> -	case PREV_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case PREV_PAD_SOURCE | 2 << 16:
>  		/* write to resizer */
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (prev->output & ~PREVIEW_OUTPUT_RESIZER)
> diff --git a/drivers/media/platform/omap3isp/ispresizer.c
> b/drivers/media/platform/omap3isp/ispresizer.c index
> 249af7f524f9..e3ecf1787fc4 100644
> --- a/drivers/media/platform/omap3isp/ispresizer.c
> +++ b/drivers/media/platform/omap3isp/ispresizer.c
> @@ -1623,9 +1623,14 @@ static int resizer_link_setup(struct media_entity
> *entity, {
>  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct isp_res_device *res = v4l2_get_subdevdata(sd);
> +	int index = local->index;
> 
> -	switch (local->index | media_entity_type(remote->entity)) {
> -	case RESZ_PAD_SINK | MEDIA_ENT_T_DEVNODE:
> +	/* FIXME: this is actually a hack! */
> +	if (is_media_entity_v4l2_subdev(remote->entity))
> +		index |= 2 << 16;
> +
> +	switch (index) {
> +	case RESZ_PAD_SINK:
>  		/* read from memory */
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (res->input == RESIZER_INPUT_VP)
> @@ -1637,7 +1642,7 @@ static int resizer_link_setup(struct media_entity
> *entity, }
>  		break;
> 
> -	case RESZ_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case RESZ_PAD_SINK | 2 << 16:
>  		/* read from ccdc or previewer */
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (res->input == RESIZER_INPUT_MEMORY)
> @@ -1649,7 +1654,7 @@ static int resizer_link_setup(struct media_entity
> *entity, }
>  		break;
> 
> -	case RESZ_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
> +	case RESZ_PAD_SOURCE:
>  		/* resizer always write to memory */
>  		break;
> 
> diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
> b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c index
> d96bdaaae50e..b66584ecb693 100644
> --- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
> +++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
> @@ -885,9 +885,14 @@ ipipeif_link_setup(struct media_entity *entity, const
> struct media_pad *local, struct v4l2_subdev *sd =
> media_entity_to_v4l2_subdev(entity);
>  	struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
>  	struct vpfe_device *vpfe = to_vpfe_device(ipipeif);
> +	int index = local->index;
> 
> -	switch (local->index | media_entity_type(remote->entity)) {
> -	case IPIPEIF_PAD_SINK | MEDIA_ENT_T_DEVNODE:
> +	/* FIXME: this is actually a hack! */
> +	if (is_media_entity_v4l2_subdev(remote->entity))
> +		index |= 2 << 16;
> +
> +	switch (index) {
> +	case IPIPEIF_PAD_SINK:
>  		/* Single shot mode */
>  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  			ipipeif->input = IPIPEIF_INPUT_NONE;
> @@ -896,7 +901,7 @@ ipipeif_link_setup(struct media_entity *entity, const
> struct media_pad *local, ipipeif->input = IPIPEIF_INPUT_MEMORY;
>  		break;
> 
> -	case IPIPEIF_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case IPIPEIF_PAD_SINK | 2 << 16:
>  		/* read from isif */
>  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  			ipipeif->input = IPIPEIF_INPUT_NONE;
> @@ -908,7 +913,7 @@ ipipeif_link_setup(struct media_entity *entity, const
> struct media_pad *local, ipipeif->input = IPIPEIF_INPUT_ISIF;
>  		break;
> 
> -	case IPIPEIF_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case IPIPEIF_PAD_SOURCE | 2 << 16:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  			ipipeif->output = IPIPEIF_OUTPUT_NONE;
>  			break;
> diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c
> b/drivers/staging/media/davinci_vpfe/dm365_isif.c index
> df77288b0ec0..8ca0c1297ec8 100644
> --- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
> +++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
> @@ -1707,9 +1707,14 @@ isif_link_setup(struct media_entity *entity, const
> struct media_pad *local, {
>  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
> +	int index = local->index;
> 
> -	switch (local->index | media_entity_type(remote->entity)) {
> -	case ISIF_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> +	/* FIXME: this is actually a hack! */
> +	if (is_media_entity_v4l2_subdev(remote->entity))
> +		index |= 2 << 16;
> +
> +	switch (index) {
> +	case ISIF_PAD_SINK | 2 << 16:
>  		/* read from decoder/sensor */
>  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  			isif->input = ISIF_INPUT_NONE;
> @@ -1720,7 +1725,7 @@ isif_link_setup(struct media_entity *entity, const
> struct media_pad *local, isif->input = ISIF_INPUT_PARALLEL;
>  		break;
> 
> -	case ISIF_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
> +	case ISIF_PAD_SOURCE:
>  		/* write to memory */
>  		if (flags & MEDIA_LNK_FL_ENABLED)
>  			isif->output = ISIF_OUTPUT_MEMORY;
> @@ -1728,7 +1733,7 @@ isif_link_setup(struct media_entity *entity, const
> struct media_pad *local, isif->output = ISIF_OUTPUT_NONE;
>  		break;
> 
> -	case ISIF_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case ISIF_PAD_SOURCE | 2 << 16:
>  		if (flags & MEDIA_LNK_FL_ENABLED)
>  			isif->output = ISIF_OUTPUT_IPIPEIF;
>  		else
> diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
> b/drivers/staging/media/davinci_vpfe/dm365_resizer.c index
> ae942de3a23d..8eb6f5fda21c 100644
> --- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
> +++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
> @@ -1653,10 +1653,15 @@ static int resizer_link_setup(struct media_entity
> *entity, struct vpfe_device *vpfe_dev = to_vpfe_device(resizer);
>  	u16 ipipeif_source = vpfe_dev->vpfe_ipipeif.output;
>  	u16 ipipe_source = vpfe_dev->vpfe_ipipe.output;
> +	int index = local->index;
> +
> +	/* FIXME: this is actually a hack! */
> +	if (is_media_entity_v4l2_subdev(remote->entity))
> +		index |= 2 << 16;
> 
>  	if (&resizer->crop_resizer.subdev == sd) {
> -		switch (local->index | media_entity_type(remote->entity)) {
> -		case RESIZER_CROP_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> +		switch (index) {
> +		case RESIZER_CROP_PAD_SINK | 2 << 16:
>  			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  				resizer->crop_resizer.input =
>  					RESIZER_CROP_INPUT_NONE;
> @@ -1676,7 +1681,7 @@ static int resizer_link_setup(struct media_entity
> *entity, return -EINVAL;
>  			break;
> 
> -		case RESIZER_CROP_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> +		case RESIZER_CROP_PAD_SOURCE | 2 << 16:
>  			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  				resizer->crop_resizer.output =
>  				RESIZER_CROP_OUTPUT_NONE;
> @@ -1688,7 +1693,7 @@ static int resizer_link_setup(struct media_entity
> *entity, resizer->crop_resizer.output = RESIZER_A;
>  			break;
> 
> -		case RESIZER_CROP_PAD_SOURCE2 | MEDIA_ENT_T_V4L2_SUBDEV:
> +		case RESIZER_CROP_PAD_SOURCE2 | 2 << 16:
>  			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  				resizer->crop_resizer.output2 =
>  					RESIZER_CROP_OUTPUT_NONE;
> @@ -1704,8 +1709,8 @@ static int resizer_link_setup(struct media_entity
> *entity, return -EINVAL;
>  		}
>  	} else if (&resizer->resizer_a.subdev == sd) {
> -		switch (local->index | media_entity_type(remote->entity)) {
> -		case RESIZER_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> +		switch (index) {
> +		case RESIZER_PAD_SINK | 2 << 16:
>  			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  				resizer->resizer_a.input = RESIZER_INPUT_NONE;
>  				break;
> @@ -1715,7 +1720,7 @@ static int resizer_link_setup(struct media_entity
> *entity, resizer->resizer_a.input = RESIZER_INPUT_CROP_RESIZER;
>  			break;
> 
> -		case RESIZER_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
> +		case RESIZER_PAD_SOURCE:
>  			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  				resizer->resizer_a.output = RESIZER_OUTPUT_NONE;
>  				break;
> @@ -1729,8 +1734,8 @@ static int resizer_link_setup(struct media_entity
> *entity, return -EINVAL;
>  		}
>  	} else if (&resizer->resizer_b.subdev == sd) {
> -		switch (local->index | media_entity_type(remote->entity)) {
> -		case RESIZER_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> +		switch (index) {
> +		case RESIZER_PAD_SINK | 2 << 16:
>  			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  				resizer->resizer_b.input = RESIZER_INPUT_NONE;
>  				break;
> @@ -1740,7 +1745,7 @@ static int resizer_link_setup(struct media_entity
> *entity, resizer->resizer_b.input = RESIZER_INPUT_CROP_RESIZER;
>  			break;
> 
> -		case RESIZER_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
> +		case RESIZER_PAD_SOURCE:
>  			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  				resizer->resizer_b.output = RESIZER_OUTPUT_NONE;
>  				break;
> diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> b/drivers/staging/media/davinci_vpfe/vpfe_video.c index
> 16763e0831f2..9eef64e0f0ab 100644
> --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct
> vpfe_video_device *video) while ((entity =
> media_entity_graph_walk_next(&graph))) {
>  		if (entity == &video->video_dev.entity)
>  			continue;
> -		if ((!is_media_entity_v4l2_io(remote->entity))
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
>  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
>  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline
> *pipe) media_entity_graph_walk_start(&graph, entity);
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> 
> -		if !is_media_entity_v4l2_subdev(entity))
> +		if (!is_media_entity_v4l2_subdev(entity))
>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> diff --git a/drivers/staging/media/omap4iss/iss_csi2.c
> b/drivers/staging/media/omap4iss/iss_csi2.c index
> 6b4dcbfa9425..50a24e8e8129 100644
> --- a/drivers/staging/media/omap4iss/iss_csi2.c
> +++ b/drivers/staging/media/omap4iss/iss_csi2.c
> @@ -1170,14 +1170,19 @@ static int csi2_link_setup(struct media_entity
> *entity, struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct iss_csi2_device *csi2 = v4l2_get_subdevdata(sd);
>  	struct iss_csi2_ctrl_cfg *ctrl = &csi2->ctrl;
> +	int index = local->index;
> +
> +	/* FIXME: this is actually a hack! */
> +	if (is_media_entity_v4l2_subdev(remote->entity))
> +		index |= 2 << 16;
> 
>  	/*
>  	 * The ISS core doesn't support pipelines with multiple video outputs.
>  	 * Revisit this when it will be implemented, and return -EBUSY for now.
>  	 */
> 
> -	switch (local->index | media_entity_type(remote->entity)) {
> -	case CSI2_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
> +	switch (index) {
> +	case CSI2_PAD_SOURCE:
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (csi2->output & ~CSI2_OUTPUT_MEMORY)
>  				return -EBUSY;
> @@ -1187,7 +1192,7 @@ static int csi2_link_setup(struct media_entity
> *entity, }
>  		break;
> 
> -	case CSI2_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case CSI2_PAD_SOURCE | 2 << 16:
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (csi2->output & ~CSI2_OUTPUT_IPIPEIF)
>  				return -EBUSY;
> diff --git a/drivers/staging/media/omap4iss/iss_ipipeif.c
> b/drivers/staging/media/omap4iss/iss_ipipeif.c index
> 44c432ef2ac5..e46b2c07bd5d 100644
> --- a/drivers/staging/media/omap4iss/iss_ipipeif.c
> +++ b/drivers/staging/media/omap4iss/iss_ipipeif.c
> @@ -662,9 +662,14 @@ static int ipipeif_link_setup(struct media_entity
> *entity, struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct iss_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
>  	struct iss_device *iss = to_iss_device(ipipeif);
> +	int index = local->index;
> 
> -	switch (local->index | media_entity_type(remote->entity)) {
> -	case IPIPEIF_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> +	/* FIXME: this is actually a hack! */
> +	if (is_media_entity_v4l2_subdev(remote->entity))
> +		index |= 2 << 16;
> +
> +	switch (index) {
> +	case IPIPEIF_PAD_SINK | 2 << 16:
>  		/* Read from the sensor CSI2a or CSI2b. */
>  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  			ipipeif->input = IPIPEIF_INPUT_NONE;
> @@ -681,7 +686,7 @@ static int ipipeif_link_setup(struct media_entity
> *entity,
> 
>  		break;
> 
> -	case IPIPEIF_PAD_SOURCE_ISIF_SF | MEDIA_ENT_T_DEVNODE:
> +	case IPIPEIF_PAD_SOURCE_ISIF_SF:
>  		/* Write to memory */
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (ipipeif->output & ~IPIPEIF_OUTPUT_MEMORY)
> @@ -692,7 +697,7 @@ static int ipipeif_link_setup(struct media_entity
> *entity, }
>  		break;
> 
> -	case IPIPEIF_PAD_SOURCE_VP | MEDIA_ENT_T_V4L2_SUBDEV:
> +	case IPIPEIF_PAD_SOURCE_VP | 2 << 16:
>  		/* Send to IPIPE/RESIZER */
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (ipipeif->output & ~IPIPEIF_OUTPUT_VP)
> diff --git a/drivers/staging/media/omap4iss/iss_resizer.c
> b/drivers/staging/media/omap4iss/iss_resizer.c index
> b659e465cb56..bc5001002cc5 100644
> --- a/drivers/staging/media/omap4iss/iss_resizer.c
> +++ b/drivers/staging/media/omap4iss/iss_resizer.c
> @@ -717,9 +717,14 @@ static int resizer_link_setup(struct media_entity
> *entity, struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct iss_resizer_device *resizer = v4l2_get_subdevdata(sd);
>  	struct iss_device *iss = to_iss_device(resizer);
> +	int index = local->index;
> 
> -	switch (local->index | media_entity_type(remote->entity)) {
> -	case RESIZER_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> +	/* FIXME: this is actually a hack! */
> +	if (is_media_entity_v4l2_subdev(remote->entity))
> +		index |= 2 << 16;
> +
> +	switch (index) {
> +	case RESIZER_PAD_SINK | 2 << 16:
>  		/* Read from IPIPE or IPIPEIF. */
>  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
>  			resizer->input = RESIZER_INPUT_NONE;
> @@ -737,7 +742,7 @@ static int resizer_link_setup(struct media_entity
> *entity,
> 
>  		break;
> 
> -	case RESIZER_PAD_SOURCE_MEM | MEDIA_ENT_T_DEVNODE:
> +	case RESIZER_PAD_SOURCE_MEM :

There's an unneeded space before the :.

>  		/* Write to memory */
>  		if (flags & MEDIA_LNK_FL_ENABLED) {
>  			if (resizer->output & ~RESIZER_OUTPUT_MEMORY)

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
  2015-08-30  3:06   ` Mauro Carvalho Chehab
  (?)
@ 2015-12-06  2:16     ` Laurent Pinchart
  -1 siblings, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Mauro,

Thank you for the patch.

On Sunday 30 August 2015 00:06:43 Mauro Carvalho Chehab wrote:
> Instead of relying on media subtype, use the new macros to detect
> if an entity is a subdev or an A/V DMA entity.
> 
> Please note that most drivers assume that there's just AV_DMA or
> V4L2 subdevs. This is not true anymore, as we've added MC support
> for DVB, and there are plans to add support for ALSA and FB/DRM
> too.
> 
> Ok, on the current pipelines supported by those drivers, just V4L
> stuff are there, but, assuming that some day a pipeline that also
> works with other subsystems will ever added, it is better to add
> explicit checks for the AV_DMA stuff.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/platform/exynos4-is/common.c
> b/drivers/media/platform/exynos4-is/common.c index
> 0eb34ecb8ee4..8c9a29e0e294 100644
> --- a/drivers/media/platform/exynos4-is/common.c
> +++ b/drivers/media/platform/exynos4-is/common.c
> @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct
> media_entity *entity) while (pad->flags & MEDIA_PAD_FL_SINK) {
>  		/* source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c
> b/drivers/media/platform/exynos4-is/fimc-capture.c index
> 0627a93b2f3b..e9810fee4c30 100644
> --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev
> *fimc) }
>  		}
> 
> -		if (src_pad = NULL ||
> -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
>  			break;
> 
>  		/* Don't call FIMC subdev operation to avoid nested locking */
> @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity
> *entity, struct fimc_vid_cap *vc = &fimc->vid_cap;
>  	struct v4l2_subdev *sensor;
> 
> -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!is_media_entity_v4l2_subdev(remote->entity))
>  		return -EINVAL;
> 
>  	if (WARN_ON(fimc = NULL))
> diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> b/drivers/media/platform/exynos4-is/fimc-isp-video.c index
> 3d9ccbf5f10f..5fbaf5e39903 100644
> --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp
> *isp)
> 
>  		/* Retrieve format at the source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c
> b/drivers/media/platform/exynos4-is/fimc-lite.c index
> b2607da4ad14..c2327147b360 100644
> --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite
> *fimc) }
>  		/* Retrieve format at the source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity
> *entity, {
>  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> -	unsigned int remote_ent_type = media_entity_type(remote->entity);
>  	int ret = 0;
> 
>  	if (WARN_ON(fimc = NULL))
> @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity
> *entity,
> 
>  	switch (local->index) {
>  	case FLITE_SD_PAD_SINK:
> -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
>  			ret = -EINVAL;
>  			break;
>  		}
> @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity
> *entity, case FLITE_SD_PAD_SOURCE_DMA:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED))
>  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> -		else if (remote_ent_type = MEDIA_ENT_T_DEVNODE)
> +		else if (is_media_entity_v4l2_io(remote->entity))
>  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
>  		else
>  			ret = -EINVAL;
> @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity
> *entity, case FLITE_SD_PAD_SOURCE_ISP:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED))
>  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> -		else if (remote_ent_type = MEDIA_ENT_T_V4L2_SUBDEV)
> +		else if (is_media_entity_v4l2_subdev(remote->entity))
>  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
>  		else
>  			ret = -EINVAL;
> diff --git a/drivers/media/platform/exynos4-is/media-dev.c
> b/drivers/media/platform/exynos4-is/media-dev.c index
> 92dbade2fffc..4a25df9dd869 100644
> --- a/drivers/media/platform/exynos4-is/media-dev.c
> +++ b/drivers/media/platform/exynos4-is/media-dev.c
> @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> break;
>  		}
> 
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> 
> @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct
> media_entity *entity, bool enable) media_entity_graph_walk_start(&graph,
> entity);
> 
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
> 
>  		ret  = __fimc_md_modify_pipeline(entity, enable);
> @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct
> media_entity *entity, bool enable) media_entity_graph_walk_start(&graph,
> entity_err);
> 
>  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity_err))
>  			continue;
> 
>  		__fimc_md_modify_pipeline(entity_err, !enable);
> diff --git a/drivers/media/platform/omap3isp/isp.c
> b/drivers/media/platform/omap3isp/isp.c index 69e7733d36cd..cb8ac90086c1
> 100644
> --- a/drivers/media/platform/omap3isp/isp.c
> +++ b/drivers/media/platform/omap3isp/isp.c
> @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity
> *entity) media_entity_graph_walk_start(&graph, entity);
> 
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_io(entity))
>  			use += entity->use_count;
>  	}
> 
> @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity
> *entity, int change) struct v4l2_subdev *subdev;
>  	int ret;
> 
> -	subdev = media_entity_type(entity) = MEDIA_ENT_T_V4L2_SUBDEV
> +	subdev = is_media_entity_v4l2_subdev(entity)
>  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> 
>  	if (entity->use_count = 0 && change > 0 && subdev != NULL) {
> @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity
> *entity, int change) media_entity_graph_walk_start(&graph, entity);
> 
>  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(entity))
>  			ret = isp_pipeline_pm_power_one(entity, change);
> 
>  	if (!ret)
> @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity
> *entity, int change)
> 
>  	while ((first = media_entity_graph_walk_next(&graph))
>  	       && first != entity)
> -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(first))
>  			isp_pipeline_pm_power_one(first, -change);
> 
>  	return ret;
> @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline
> *pipe, break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline
> *pipe) break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> diff --git a/drivers/media/platform/omap3isp/ispvideo.c
> b/drivers/media/platform/omap3isp/ispvideo.c index
> 4c367352b1f7..52843ac2a9ca 100644
> --- a/drivers/media/platform/omap3isp/ispvideo.c
> +++ b/drivers/media/platform/omap3isp/ispvideo.c
> @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32
> *pad)
> 
>  	remote = media_entity_remote_pad(&video->pad);
> 
> -	if (remote = NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
> 
>  	if (pad)
> @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video
> *video, if (entity = &video->video.entity)
>  			continue;
> 
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
> 
>  		__video = to_isp_video(media_entity_to_video_device(entity));
> @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct
> isp_video *video, return -EINVAL;
>  	}
> 
> -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!is_media_entity_v4l2_subdev(source))
>  		return 0;
> 
>  	pipe->external = media_entity_to_v4l2_subdev(source);
> diff --git a/drivers/media/platform/s3c-camif/camif-capture.c
> b/drivers/media/platform/s3c-camif/camif-capture.c index
> eae667eab1b9..fb5b016cc0a1 100644
> --- a/drivers/media/platform/s3c-camif/camif-capture.c
> +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev
> *camif)
> 
>  	/* Retrieve format at the sensor subdev source pad */
>  	pad = media_entity_remote_pad(&camif->pads[0]);
> -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  		return -EPIPE;
> 
>  	src_fmt.pad = pad->index;
> diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> b/drivers/media/platform/vsp1/vsp1_video.c index 1f94c1a54e00..f74158224b93
> 100644
> --- a/drivers/media/platform/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32
> *pad) struct media_pad *remote;
> 
>  	remote = media_entity_remote_pad(local);
> -	if (remote = NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
> 
>  	if (pad)
> @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct
> vsp1_pipeline *pipe, return -EPIPE;
> 
>  		/* We've reached a video node, that shouldn't have happened. */
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!is_media_entity_v4l2_subdev(pad->entity))
>  			return -EPIPE;
> 
>  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline
> *pipe, struct vsp1_rwpf *rwpf;
>  		struct vsp1_entity *e;
> 
> -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> +		if (is_media_entity_v4l2_io(entity)) {
>  			pipe->num_video++;
>  			continue;
>  		}
> @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline
> *pipe, pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> 
>  	while (pad) {
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> diff --git a/drivers/media/platform/xilinx/xilinx-dma.c
> b/drivers/media/platform/xilinx/xilinx-dma.c index
> 88cd789cdaf7..8e14841bf445 100644
> --- a/drivers/media/platform/xilinx/xilinx-dma.c
> +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
>  	struct media_pad *remote;
> 
>  	remote = media_entity_remote_pad(local);
> -	if (remote = NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
> 
>  	if (pad)
> @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline
> *pipe, bool start) break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c
> b/drivers/media/v4l2-core/v4l2-subdev.c index e6e1115d8215..60da43772de9
> 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -526,7 +526,7 @@ static int
>  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
>  				     struct v4l2_subdev_format *fmt)
>  {
> -	if (media_entity_type(pad->entity) = MEDIA_ENT_T_V4L2_SUBDEV) {
> +	if (is_media_entity_v4l2_subdev(pad->entity)) {
>  		struct v4l2_subdev *sd >  			media_entity_to_v4l2_subdev(pad->entity);
> 
> diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> b/drivers/staging/media/davinci_vpfe/vpfe_video.c index
> 92573fa852a9..16763e0831f2 100644
> --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct
> vpfe_video_device *video) while ((entity > media_entity_graph_walk_next(&graph))) {
>  		if (entity = &video->video_dev.entity)
>  			continue;
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if ((!is_media_entity_v4l2_io(remote->entity))
>  			continue;
>  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
>  		if (far_end->type = V4L2_BUF_TYPE_VIDEO_OUTPUT)
> @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline
> *pipe) media_entity_graph_walk_start(&graph, entity);
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> 
> -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> +		if !is_media_entity_v4l2_subdev(entity))

With these two chunks fixed,

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

I'm wondering, however, why you replace some occurrences of = 
MEDIA_ENT_T_DEVNODE with !is_media_entity_v4l2_subdev and some other with 
is_media_entity_v4l2_io.

>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline
> *pipe)
> 
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> 
> -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_subdev(entity))
>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> diff --git a/drivers/staging/media/omap4iss/iss.c
> b/drivers/staging/media/omap4iss/iss.c index 40591963b42b..44b88ff3ba83
> 100644
> --- a/drivers/staging/media/omap4iss/iss.c
> +++ b/drivers/staging/media/omap4iss/iss.c
> @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity
> *entity) media_entity_graph_walk_start(&graph, entity);
> 
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_io(entity))
>  			use += entity->use_count;
>  	}
> 
> @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity
> *entity, int change) {
>  	struct v4l2_subdev *subdev;
> 
> -	subdev = media_entity_type(entity) = MEDIA_ENT_T_V4L2_SUBDEV
> +	subdev = is_media_entity_v4l2_subdev(entity)
>  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> 
>  	if (entity->use_count = 0 && change > 0 && subdev != NULL) {
> @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity
> *entity, int change) media_entity_graph_walk_start(&graph, entity);
> 
>  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(entity))
>  			ret = iss_pipeline_pm_power_one(entity, change);
> 
>  	if (!ret)
> @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity
> *entity, int change)
> 
>  	while ((first = media_entity_graph_walk_next(&graph))
>  	       && first != entity)
> -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(first))
>  			iss_pipeline_pm_power_one(first, -change);
> 
>  	return ret;
> @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline
> *pipe, break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline
> *pipe, break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad = NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> diff --git a/drivers/staging/media/omap4iss/iss_video.c
> b/drivers/staging/media/omap4iss/iss_video.c index
> 45a3f2d778fc..cbe5783735dc 100644
> --- a/drivers/staging/media/omap4iss/iss_video.c
> +++ b/drivers/staging/media/omap4iss/iss_video.c
> @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32
> *pad)
> 
>  	remote = media_entity_remote_pad(&video->pad);
> 
> -	if (remote = NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
> 
>  	if (pad)
> @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
>  		if (entity = &video->video.entity)
>  			continue;
> 
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
> 
>  		far_end = to_iss_video(media_entity_to_video_device(entity));

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-12-06  2:16     ` Laurent Pinchart
  0 siblings, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  2:16 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Kukjin Kim, Krzysztof Kozlowski, Hyun Kwon,
	Michal Simek, Sören Brinkmann, Greg Kroah-Hartman,
	Hans Verkuil, Prabhakar Lad, Lars-Peter Clausen, Markus Elfring,
	Sakari Ailus, Javier Martinez Canillas, linux-arm-kernel,
	linux-samsung-soc, linux-sh, devel

Hi Mauro,

Thank you for the patch.

On Sunday 30 August 2015 00:06:43 Mauro Carvalho Chehab wrote:
> Instead of relying on media subtype, use the new macros to detect
> if an entity is a subdev or an A/V DMA entity.
> 
> Please note that most drivers assume that there's just AV_DMA or
> V4L2 subdevs. This is not true anymore, as we've added MC support
> for DVB, and there are plans to add support for ALSA and FB/DRM
> too.
> 
> Ok, on the current pipelines supported by those drivers, just V4L
> stuff are there, but, assuming that some day a pipeline that also
> works with other subsystems will ever added, it is better to add
> explicit checks for the AV_DMA stuff.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/platform/exynos4-is/common.c
> b/drivers/media/platform/exynos4-is/common.c index
> 0eb34ecb8ee4..8c9a29e0e294 100644
> --- a/drivers/media/platform/exynos4-is/common.c
> +++ b/drivers/media/platform/exynos4-is/common.c
> @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct
> media_entity *entity) while (pad->flags & MEDIA_PAD_FL_SINK) {
>  		/* source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c
> b/drivers/media/platform/exynos4-is/fimc-capture.c index
> 0627a93b2f3b..e9810fee4c30 100644
> --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev
> *fimc) }
>  		}
> 
> -		if (src_pad == NULL ||
> -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
>  			break;
> 
>  		/* Don't call FIMC subdev operation to avoid nested locking */
> @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity
> *entity, struct fimc_vid_cap *vc = &fimc->vid_cap;
>  	struct v4l2_subdev *sensor;
> 
> -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!is_media_entity_v4l2_subdev(remote->entity))
>  		return -EINVAL;
> 
>  	if (WARN_ON(fimc == NULL))
> diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> b/drivers/media/platform/exynos4-is/fimc-isp-video.c index
> 3d9ccbf5f10f..5fbaf5e39903 100644
> --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp
> *isp)
> 
>  		/* Retrieve format at the source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c
> b/drivers/media/platform/exynos4-is/fimc-lite.c index
> b2607da4ad14..c2327147b360 100644
> --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite
> *fimc) }
>  		/* Retrieve format at the source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity
> *entity, {
>  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> -	unsigned int remote_ent_type = media_entity_type(remote->entity);
>  	int ret = 0;
> 
>  	if (WARN_ON(fimc == NULL))
> @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity
> *entity,
> 
>  	switch (local->index) {
>  	case FLITE_SD_PAD_SINK:
> -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
>  			ret = -EINVAL;
>  			break;
>  		}
> @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity
> *entity, case FLITE_SD_PAD_SOURCE_DMA:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED))
>  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> +		else if (is_media_entity_v4l2_io(remote->entity))
>  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
>  		else
>  			ret = -EINVAL;
> @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity
> *entity, case FLITE_SD_PAD_SOURCE_ISP:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED))
>  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> +		else if (is_media_entity_v4l2_subdev(remote->entity))
>  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
>  		else
>  			ret = -EINVAL;
> diff --git a/drivers/media/platform/exynos4-is/media-dev.c
> b/drivers/media/platform/exynos4-is/media-dev.c index
> 92dbade2fffc..4a25df9dd869 100644
> --- a/drivers/media/platform/exynos4-is/media-dev.c
> +++ b/drivers/media/platform/exynos4-is/media-dev.c
> @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> break;
>  		}
> 
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> 
> @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct
> media_entity *entity, bool enable) media_entity_graph_walk_start(&graph,
> entity);
> 
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
> 
>  		ret  = __fimc_md_modify_pipeline(entity, enable);
> @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct
> media_entity *entity, bool enable) media_entity_graph_walk_start(&graph,
> entity_err);
> 
>  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity_err))
>  			continue;
> 
>  		__fimc_md_modify_pipeline(entity_err, !enable);
> diff --git a/drivers/media/platform/omap3isp/isp.c
> b/drivers/media/platform/omap3isp/isp.c index 69e7733d36cd..cb8ac90086c1
> 100644
> --- a/drivers/media/platform/omap3isp/isp.c
> +++ b/drivers/media/platform/omap3isp/isp.c
> @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity
> *entity) media_entity_graph_walk_start(&graph, entity);
> 
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_io(entity))
>  			use += entity->use_count;
>  	}
> 
> @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity
> *entity, int change) struct v4l2_subdev *subdev;
>  	int ret;
> 
> -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> +	subdev = is_media_entity_v4l2_subdev(entity)
>  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> 
>  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity
> *entity, int change) media_entity_graph_walk_start(&graph, entity);
> 
>  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(entity))
>  			ret = isp_pipeline_pm_power_one(entity, change);
> 
>  	if (!ret)
> @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity
> *entity, int change)
> 
>  	while ((first = media_entity_graph_walk_next(&graph))
>  	       && first != entity)
> -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(first))
>  			isp_pipeline_pm_power_one(first, -change);
> 
>  	return ret;
> @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline
> *pipe, break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline
> *pipe) break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> diff --git a/drivers/media/platform/omap3isp/ispvideo.c
> b/drivers/media/platform/omap3isp/ispvideo.c index
> 4c367352b1f7..52843ac2a9ca 100644
> --- a/drivers/media/platform/omap3isp/ispvideo.c
> +++ b/drivers/media/platform/omap3isp/ispvideo.c
> @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32
> *pad)
> 
>  	remote = media_entity_remote_pad(&video->pad);
> 
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
> 
>  	if (pad)
> @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video
> *video, if (entity == &video->video.entity)
>  			continue;
> 
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
> 
>  		__video = to_isp_video(media_entity_to_video_device(entity));
> @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct
> isp_video *video, return -EINVAL;
>  	}
> 
> -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!is_media_entity_v4l2_subdev(source))
>  		return 0;
> 
>  	pipe->external = media_entity_to_v4l2_subdev(source);
> diff --git a/drivers/media/platform/s3c-camif/camif-capture.c
> b/drivers/media/platform/s3c-camif/camif-capture.c index
> eae667eab1b9..fb5b016cc0a1 100644
> --- a/drivers/media/platform/s3c-camif/camif-capture.c
> +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev
> *camif)
> 
>  	/* Retrieve format at the sensor subdev source pad */
>  	pad = media_entity_remote_pad(&camif->pads[0]);
> -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  		return -EPIPE;
> 
>  	src_fmt.pad = pad->index;
> diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> b/drivers/media/platform/vsp1/vsp1_video.c index 1f94c1a54e00..f74158224b93
> 100644
> --- a/drivers/media/platform/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32
> *pad) struct media_pad *remote;
> 
>  	remote = media_entity_remote_pad(local);
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
> 
>  	if (pad)
> @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct
> vsp1_pipeline *pipe, return -EPIPE;
> 
>  		/* We've reached a video node, that shouldn't have happened. */
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!is_media_entity_v4l2_subdev(pad->entity))
>  			return -EPIPE;
> 
>  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline
> *pipe, struct vsp1_rwpf *rwpf;
>  		struct vsp1_entity *e;
> 
> -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> +		if (is_media_entity_v4l2_io(entity)) {
>  			pipe->num_video++;
>  			continue;
>  		}
> @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline
> *pipe, pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> 
>  	while (pad) {
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> diff --git a/drivers/media/platform/xilinx/xilinx-dma.c
> b/drivers/media/platform/xilinx/xilinx-dma.c index
> 88cd789cdaf7..8e14841bf445 100644
> --- a/drivers/media/platform/xilinx/xilinx-dma.c
> +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
>  	struct media_pad *remote;
> 
>  	remote = media_entity_remote_pad(local);
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
> 
>  	if (pad)
> @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline
> *pipe, bool start) break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c
> b/drivers/media/v4l2-core/v4l2-subdev.c index e6e1115d8215..60da43772de9
> 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -526,7 +526,7 @@ static int
>  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
>  				     struct v4l2_subdev_format *fmt)
>  {
> -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> +	if (is_media_entity_v4l2_subdev(pad->entity)) {
>  		struct v4l2_subdev *sd =
>  			media_entity_to_v4l2_subdev(pad->entity);
> 
> diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> b/drivers/staging/media/davinci_vpfe/vpfe_video.c index
> 92573fa852a9..16763e0831f2 100644
> --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct
> vpfe_video_device *video) while ((entity =
> media_entity_graph_walk_next(&graph))) {
>  		if (entity == &video->video_dev.entity)
>  			continue;
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if ((!is_media_entity_v4l2_io(remote->entity))
>  			continue;
>  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
>  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline
> *pipe) media_entity_graph_walk_start(&graph, entity);
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> 
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if !is_media_entity_v4l2_subdev(entity))

With these two chunks fixed,

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

I'm wondering, however, why you replace some occurrences of == 
MEDIA_ENT_T_DEVNODE with !is_media_entity_v4l2_subdev and some other with 
is_media_entity_v4l2_io.

>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline
> *pipe)
> 
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> 
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_subdev(entity))
>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> diff --git a/drivers/staging/media/omap4iss/iss.c
> b/drivers/staging/media/omap4iss/iss.c index 40591963b42b..44b88ff3ba83
> 100644
> --- a/drivers/staging/media/omap4iss/iss.c
> +++ b/drivers/staging/media/omap4iss/iss.c
> @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity
> *entity) media_entity_graph_walk_start(&graph, entity);
> 
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_io(entity))
>  			use += entity->use_count;
>  	}
> 
> @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity
> *entity, int change) {
>  	struct v4l2_subdev *subdev;
> 
> -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> +	subdev = is_media_entity_v4l2_subdev(entity)
>  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> 
>  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity
> *entity, int change) media_entity_graph_walk_start(&graph, entity);
> 
>  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(entity))
>  			ret = iss_pipeline_pm_power_one(entity, change);
> 
>  	if (!ret)
> @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity
> *entity, int change)
> 
>  	while ((first = media_entity_graph_walk_next(&graph))
>  	       && first != entity)
> -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(first))
>  			iss_pipeline_pm_power_one(first, -change);
> 
>  	return ret;
> @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline
> *pipe, break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline
> *pipe, break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> diff --git a/drivers/staging/media/omap4iss/iss_video.c
> b/drivers/staging/media/omap4iss/iss_video.c index
> 45a3f2d778fc..cbe5783735dc 100644
> --- a/drivers/staging/media/omap4iss/iss_video.c
> +++ b/drivers/staging/media/omap4iss/iss_video.c
> @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32
> *pad)
> 
>  	remote = media_entity_remote_pad(&video->pad);
> 
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
> 
>  	if (pad)
> @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
>  		if (entity == &video->video.entity)
>  			continue;
> 
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
> 
>  		far_end = to_iss_video(media_entity_to_video_device(entity));

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-12-06  2:16     ` Laurent Pinchart
  0 siblings, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Mauro,

Thank you for the patch.

On Sunday 30 August 2015 00:06:43 Mauro Carvalho Chehab wrote:
> Instead of relying on media subtype, use the new macros to detect
> if an entity is a subdev or an A/V DMA entity.
> 
> Please note that most drivers assume that there's just AV_DMA or
> V4L2 subdevs. This is not true anymore, as we've added MC support
> for DVB, and there are plans to add support for ALSA and FB/DRM
> too.
> 
> Ok, on the current pipelines supported by those drivers, just V4L
> stuff are there, but, assuming that some day a pipeline that also
> works with other subsystems will ever added, it is better to add
> explicit checks for the AV_DMA stuff.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/platform/exynos4-is/common.c
> b/drivers/media/platform/exynos4-is/common.c index
> 0eb34ecb8ee4..8c9a29e0e294 100644
> --- a/drivers/media/platform/exynos4-is/common.c
> +++ b/drivers/media/platform/exynos4-is/common.c
> @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct
> media_entity *entity) while (pad->flags & MEDIA_PAD_FL_SINK) {
>  		/* source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c
> b/drivers/media/platform/exynos4-is/fimc-capture.c index
> 0627a93b2f3b..e9810fee4c30 100644
> --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev
> *fimc) }
>  		}
> 
> -		if (src_pad == NULL ||
> -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
>  			break;
> 
>  		/* Don't call FIMC subdev operation to avoid nested locking */
> @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity
> *entity, struct fimc_vid_cap *vc = &fimc->vid_cap;
>  	struct v4l2_subdev *sensor;
> 
> -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!is_media_entity_v4l2_subdev(remote->entity))
>  		return -EINVAL;
> 
>  	if (WARN_ON(fimc == NULL))
> diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> b/drivers/media/platform/exynos4-is/fimc-isp-video.c index
> 3d9ccbf5f10f..5fbaf5e39903 100644
> --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp
> *isp)
> 
>  		/* Retrieve format at the source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c
> b/drivers/media/platform/exynos4-is/fimc-lite.c index
> b2607da4ad14..c2327147b360 100644
> --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite
> *fimc) }
>  		/* Retrieve format at the source pad */
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity
> *entity, {
>  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
>  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> -	unsigned int remote_ent_type = media_entity_type(remote->entity);
>  	int ret = 0;
> 
>  	if (WARN_ON(fimc == NULL))
> @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity
> *entity,
> 
>  	switch (local->index) {
>  	case FLITE_SD_PAD_SINK:
> -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
>  			ret = -EINVAL;
>  			break;
>  		}
> @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity
> *entity, case FLITE_SD_PAD_SOURCE_DMA:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED))
>  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> +		else if (is_media_entity_v4l2_io(remote->entity))
>  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
>  		else
>  			ret = -EINVAL;
> @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity
> *entity, case FLITE_SD_PAD_SOURCE_ISP:
>  		if (!(flags & MEDIA_LNK_FL_ENABLED))
>  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> +		else if (is_media_entity_v4l2_subdev(remote->entity))
>  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
>  		else
>  			ret = -EINVAL;
> diff --git a/drivers/media/platform/exynos4-is/media-dev.c
> b/drivers/media/platform/exynos4-is/media-dev.c index
> 92dbade2fffc..4a25df9dd869 100644
> --- a/drivers/media/platform/exynos4-is/media-dev.c
> +++ b/drivers/media/platform/exynos4-is/media-dev.c
> @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> break;
>  		}
> 
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
>  		sd = media_entity_to_v4l2_subdev(pad->entity);
> 
> @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct
> media_entity *entity, bool enable) media_entity_graph_walk_start(&graph,
> entity);
> 
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
> 
>  		ret  = __fimc_md_modify_pipeline(entity, enable);
> @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct
> media_entity *entity, bool enable) media_entity_graph_walk_start(&graph,
> entity_err);
> 
>  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity_err))
>  			continue;
> 
>  		__fimc_md_modify_pipeline(entity_err, !enable);
> diff --git a/drivers/media/platform/omap3isp/isp.c
> b/drivers/media/platform/omap3isp/isp.c index 69e7733d36cd..cb8ac90086c1
> 100644
> --- a/drivers/media/platform/omap3isp/isp.c
> +++ b/drivers/media/platform/omap3isp/isp.c
> @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity
> *entity) media_entity_graph_walk_start(&graph, entity);
> 
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_io(entity))
>  			use += entity->use_count;
>  	}
> 
> @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity
> *entity, int change) struct v4l2_subdev *subdev;
>  	int ret;
> 
> -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> +	subdev = is_media_entity_v4l2_subdev(entity)
>  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> 
>  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity
> *entity, int change) media_entity_graph_walk_start(&graph, entity);
> 
>  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(entity))
>  			ret = isp_pipeline_pm_power_one(entity, change);
> 
>  	if (!ret)
> @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity
> *entity, int change)
> 
>  	while ((first = media_entity_graph_walk_next(&graph))
>  	       && first != entity)
> -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(first))
>  			isp_pipeline_pm_power_one(first, -change);
> 
>  	return ret;
> @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline
> *pipe, break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline
> *pipe) break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> diff --git a/drivers/media/platform/omap3isp/ispvideo.c
> b/drivers/media/platform/omap3isp/ispvideo.c index
> 4c367352b1f7..52843ac2a9ca 100644
> --- a/drivers/media/platform/omap3isp/ispvideo.c
> +++ b/drivers/media/platform/omap3isp/ispvideo.c
> @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32
> *pad)
> 
>  	remote = media_entity_remote_pad(&video->pad);
> 
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
> 
>  	if (pad)
> @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video
> *video, if (entity == &video->video.entity)
>  			continue;
> 
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
> 
>  		__video = to_isp_video(media_entity_to_video_device(entity));
> @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct
> isp_video *video, return -EINVAL;
>  	}
> 
> -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!is_media_entity_v4l2_subdev(source))
>  		return 0;
> 
>  	pipe->external = media_entity_to_v4l2_subdev(source);
> diff --git a/drivers/media/platform/s3c-camif/camif-capture.c
> b/drivers/media/platform/s3c-camif/camif-capture.c index
> eae667eab1b9..fb5b016cc0a1 100644
> --- a/drivers/media/platform/s3c-camif/camif-capture.c
> +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev
> *camif)
> 
>  	/* Retrieve format at the sensor subdev source pad */
>  	pad = media_entity_remote_pad(&camif->pads[0]);
> -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  		return -EPIPE;
> 
>  	src_fmt.pad = pad->index;
> diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> b/drivers/media/platform/vsp1/vsp1_video.c index 1f94c1a54e00..f74158224b93
> 100644
> --- a/drivers/media/platform/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32
> *pad) struct media_pad *remote;
> 
>  	remote = media_entity_remote_pad(local);
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
> 
>  	if (pad)
> @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct
> vsp1_pipeline *pipe, return -EPIPE;
> 
>  		/* We've reached a video node, that shouldn't have happened. */
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!is_media_entity_v4l2_subdev(pad->entity))
>  			return -EPIPE;
> 
>  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline
> *pipe, struct vsp1_rwpf *rwpf;
>  		struct vsp1_entity *e;
> 
> -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> +		if (is_media_entity_v4l2_io(entity)) {
>  			pipe->num_video++;
>  			continue;
>  		}
> @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline
> *pipe, pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> 
>  	while (pad) {
> -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> diff --git a/drivers/media/platform/xilinx/xilinx-dma.c
> b/drivers/media/platform/xilinx/xilinx-dma.c index
> 88cd789cdaf7..8e14841bf445 100644
> --- a/drivers/media/platform/xilinx/xilinx-dma.c
> +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
>  	struct media_pad *remote;
> 
>  	remote = media_entity_remote_pad(local);
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
> 
>  	if (pad)
> @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline
> *pipe, bool start) break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c
> b/drivers/media/v4l2-core/v4l2-subdev.c index e6e1115d8215..60da43772de9
> 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -526,7 +526,7 @@ static int
>  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
>  				     struct v4l2_subdev_format *fmt)
>  {
> -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> +	if (is_media_entity_v4l2_subdev(pad->entity)) {
>  		struct v4l2_subdev *sd =
>  			media_entity_to_v4l2_subdev(pad->entity);
> 
> diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> b/drivers/staging/media/davinci_vpfe/vpfe_video.c index
> 92573fa852a9..16763e0831f2 100644
> --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct
> vpfe_video_device *video) while ((entity =
> media_entity_graph_walk_next(&graph))) {
>  		if (entity == &video->video_dev.entity)
>  			continue;
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if ((!is_media_entity_v4l2_io(remote->entity))
>  			continue;
>  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
>  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline
> *pipe) media_entity_graph_walk_start(&graph, entity);
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> 
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if !is_media_entity_v4l2_subdev(entity))

With these two chunks fixed,

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

I'm wondering, however, why you replace some occurrences of == 
MEDIA_ENT_T_DEVNODE with !is_media_entity_v4l2_subdev and some other with 
is_media_entity_v4l2_io.

>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline
> *pipe)
> 
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> 
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_subdev(entity))
>  			continue;
>  		subdev = media_entity_to_v4l2_subdev(entity);
>  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> diff --git a/drivers/staging/media/omap4iss/iss.c
> b/drivers/staging/media/omap4iss/iss.c index 40591963b42b..44b88ff3ba83
> 100644
> --- a/drivers/staging/media/omap4iss/iss.c
> +++ b/drivers/staging/media/omap4iss/iss.c
> @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity
> *entity) media_entity_graph_walk_start(&graph, entity);
> 
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_io(entity))
>  			use += entity->use_count;
>  	}
> 
> @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity
> *entity, int change) {
>  	struct v4l2_subdev *subdev;
> 
> -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> +	subdev = is_media_entity_v4l2_subdev(entity)
>  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> 
>  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity
> *entity, int change) media_entity_graph_walk_start(&graph, entity);
> 
>  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(entity))
>  			ret = iss_pipeline_pm_power_one(entity, change);
> 
>  	if (!ret)
> @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity
> *entity, int change)
> 
>  	while ((first = media_entity_graph_walk_next(&graph))
>  	       && first != entity)
> -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> +		if (is_media_entity_v4l2_subdev(first))
>  			iss_pipeline_pm_power_one(first, -change);
> 
>  	return ret;
> @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline
> *pipe, break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline
> *pipe, break;
> 
>  		pad = media_entity_remote_pad(pad);
> -		if (pad == NULL ||
> -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
>  			break;
> 
>  		entity = pad->entity;
> diff --git a/drivers/staging/media/omap4iss/iss_video.c
> b/drivers/staging/media/omap4iss/iss_video.c index
> 45a3f2d778fc..cbe5783735dc 100644
> --- a/drivers/staging/media/omap4iss/iss_video.c
> +++ b/drivers/staging/media/omap4iss/iss_video.c
> @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32
> *pad)
> 
>  	remote = media_entity_remote_pad(&video->pad);
> 
> -	if (remote == NULL ||
> -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
>  		return NULL;
> 
>  	if (pad)
> @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
>  		if (entity == &video->video.entity)
>  			continue;
> 
> -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> +		if (!is_media_entity_v4l2_io(entity))
>  			continue;
> 
>  		far_end = to_iss_video(media_entity_to_video_device(entity));

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA
  2015-09-06 12:02   ` Mauro Carvalho Chehab
@ 2015-12-06  2:20     ` Laurent Pinchart
  2015-12-08 15:41       ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  2:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:02:57 Mauro Carvalho Chehab wrote:
> As we'll be removing entity subtypes from the Kernel, we need
> to provide a way for drivers and core to check if a given
> entity is represented by a V4L2 subdev or if it is an V4L2
> I/O entity (typically with DMA).
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 4e36b1f2b2d7..220864319d21 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -220,6 +220,39 @@ static inline u32 media_gobj_gen_id(enum
> media_gobj_type type, u32 local_id) return id;
>  }
> 
> +static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
> +{
> +	if (!entity)
> +		return false;
> +
> +	switch (entity->type) {
> +	case MEDIA_ENT_T_V4L2_VIDEO:
> +	case MEDIA_ENT_T_V4L2_VBI:
> +	case MEDIA_ENT_T_V4L2_SWRADIO:
> +		return true;
> +	default:
> +		return false;
> +	}
> +}
> +
> +static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
> +{
> +	if (!entity)
> +		return false;
> +
> +	switch (entity->type) {
> +	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
> +	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
> +	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
> +	case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
> +	case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:

I'm sorry but this simply won't scale. We need a better way to determine the 
entity type, and this could be a valid use case to actually retain an entity 
type field separate from the function, at least inside the kernel.

> +		return true;
> +
> +	default:
> +		return false;
> +	}
> +}
> +
>  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
>  #define MEDIA_ENTITY_ENUM_MAX_ID	64

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 18/55] [media] omap3isp: create links after all subdevs have been bound
  2015-09-09  8:48     ` Javier Martinez Canillas
@ 2015-12-06  3:05       ` Laurent Pinchart
  2015-12-07 15:17         ` Javier Martinez Canillas
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  3:05 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: Sakari Ailus, Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab

Hi Javier,

Thank you for the patch.

On Wednesday 09 September 2015 10:48:29 Javier Martinez Canillas wrote:
> On 09/09/2015 10:03 AM, Sakari Ailus wrote:
> > On Sun, Aug 30, 2015 at 12:06:29AM -0300, Mauro Carvalho Chehab wrote:
> >> From: Javier Martinez Canillas <javier@osg.samsung.com>
> >> 
> >> The omap3isp driver parses the graph endpoints to know how many
> >> subdevices needs to be registered async and register notifiers callbacks
> >> for to know when these are bound and when the async registrations are
> >> completed.
> >> 
> >> Currently the entities pad are linked with the correct ISP input
> >> interface when the subdevs are bound but it happens before entitities are
> >> registered with the media device so that won't work now that the entity
> >> links list is initialized on device registration.
> >> 
> >> So instead creating the pad links when the subdevice is bound, create
> >> them on the complete callback once all the subdevices have been bound but
> >> only try to create for the ones that have a bus configuration set during
> >> bound.
> >> 
> >> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> >> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> >> 
> >> diff --git a/drivers/media/platform/omap3isp/isp.c
> >> b/drivers/media/platform/omap3isp/isp.c index b8f6f81d2db2..69e7733d36cd
> >> 100644
> >> --- a/drivers/media/platform/omap3isp/isp.c
> >> +++ b/drivers/media/platform/omap3isp/isp.c
> >> @@ -2321,26 +2321,33 @@ static int isp_subdev_notifier_bound(struct
> >> v4l2_async_notifier *async,
> >>  				     struct v4l2_subdev *subdev,
> >>  				     struct v4l2_async_subdev *asd)
> >>  {
> >> -	struct isp_device *isp = container_of(async, struct isp_device,
> >> -					      notifier);
> >>  	struct isp_async_subdev *isd =
> >>  		container_of(asd, struct isp_async_subdev, asd);
> >> -	int ret;
> >> -
> >> -	ret = isp_link_entity(isp, &subdev->entity, isd->bus.interface);
> >> -	if (ret < 0)
> >> -		return ret;
> >> 
> >>  	isd->sd = subdev;
> >>  	isd->sd->host_priv = &isd->bus;
> >> 
> >> -	return ret;
> >> +	return 0;
> >>  }
> >>  
> >>  static int isp_subdev_notifier_complete(struct v4l2_async_notifier
> >>  *async)
> >>  {
> >>  	struct isp_device *isp = container_of(async, struct isp_device,
> >>  					      notifier);
> >> +	struct v4l2_device *v4l2_dev = &isp->v4l2_dev;
> >> +	struct v4l2_subdev *sd;
> >> +	struct isp_bus_cfg *bus;
> >> +	int ret;
> >> +
> >> +	list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
> >> +		/* Only try to link entities whose interface was set on bound */
> >> +		if (sd->host_priv) {
> >> +			bus = (struct isp_bus_cfg *)sd->host_priv;
> >> +			ret = isp_link_entity(isp, &sd->entity, bus->interface);
> >> +			if (ret < 0)
> >> +				return ret;
> >> +		}
> >> +	}
> >>  	return v4l2_device_register_subdev_nodes(&isp->v4l2_dev);
> >>  }
> > 
> > I think you're working around a problem here, not really fixing it.
> > 
> > This change will create the links only after the media device is
> > registered, which means the user may obtain a partial enumeration of
> > links if the enumeration is performed too early.
> > 
> > Before this set, the problem also was that the media device was registered
> > before the async entities were bound, again making it possible to obtain a
> > partial enumeration of entities.
> 
> You are absolutely correct but I think these are separate issues. The
> problem here is that v4l2_async_test_notify() [0] first invokes the bound
> notifier callback and then calls v4l2_device_register_subdev() that
> register the media entity with the media device.
> 
> Since now is a requirement that the entities must be registered prior
> creating pads links (because to init a MEDIA_GRAPH_LINK object a mdev has
> to be set), $SUBJECT is needed regardless of the race between subdev
> registration and the media dev node being available to user-space before
> everything is registered.
> > What I'd suggest instead is that we split media device initialisation and
> > registration to the system; that way the media device can be prepared
> > (entities registered and links created) before it becomes visible to the
> > user space. I can write a patch for that if you like.
> 
> Agreed, looking at the implementation it seems that
> __media_device_register() has to be split (possibly being renamed to
> __media_device_init) so it only contains the initialization logic and all
> the media device node registration logic moved to another function (that
> would become media_device_register).
> 
> I think the media dev node registration has to be made in the complete
> callback to make sure that happens when all the subdevs have been already
> registered.
> 
> Is that what you had in mind? I can also write such a patch if you want.

I think I've already commented on it in my review of another patch (but can't 
find it right now), I agree with you. We need to properly think about 
initialization (and, for that matter, cleanup as well) order, both for the 
media device and the entities. And, as a corollary, for subdevs too. The 
current media entity and subdevs initialization and registration code grew in 
an organic way without much design behind it, let's not repeat the same 
mistake.

> [0]:
> http://lxr.free-electrons.com/source/drivers/media/v4l2-core/v4l2-async.c#L
> 96 [1]:
> http://lxr.free-electrons.com/source/drivers/media/media-device.c#L372

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 16/55] [media] media: Don't accept early-created links
  2015-09-06 12:02   ` Mauro Carvalho Chehab
@ 2015-12-06  3:13     ` Laurent Pinchart
  0 siblings, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  3:13 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

Hi Mauro,

Thank you for the patch.

On Sunday 06 September 2015 09:02:47 Mauro Carvalho Chehab wrote:
> Links are graph objects that represent the links of two already
> existing objects in the graph.
> 
> While with the current implementation, it is possible to create
> the links earlier, It doesn't make any sense to allow linking
> two objects when they are not both created.
> 
> So, remove the code that would be handling those early-created
> links and add a BUG_ON() to ensure that.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 138b18416460..0d85c6c28004 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -443,13 +443,6 @@ int __must_check media_device_register_entity(struct
> media_device *mdev, media_gobj_init(mdev, MEDIA_GRAPH_ENTITY,
> &entity->graph_obj);
>  	list_add_tail(&entity->list, &mdev->entities);
> 
> -	/*
> -	 * Initialize objects at the links
> -	 * in the case where links got created before entity register
> -	 */
> -	for (i = 0; i < entity->num_links; i++)
> -		media_gobj_init(mdev, MEDIA_GRAPH_LINK,
> -				&entity->links[i].graph_obj);
>  	/* Initialize objects at the pads */
>  	for (i = 0; i < entity->num_pads; i++)
>  		media_gobj_init(mdev, MEDIA_GRAPH_PAD,
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 27fce6224972..0926f08be981 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -161,6 +161,8 @@ void media_gobj_init(struct media_device *mdev,
>  			   enum media_gobj_type type,
>  			   struct media_gobj *gobj)
>  {
> +	BUG_ON(!mdev);
> +

Please use a WARN_ON() and return (and possibly make the function return an 
int error code), we don't want to panic completely for this.

>  	gobj->mdev = mdev;
> 
>  	/* Create a per-type unique object ID */

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 03/55] [media] omap3isp: get entity ID using media_entity_id()
  2015-08-30  3:06 ` [PATCH v8 03/55] [media] omap3isp: " Mauro Carvalho Chehab
  2015-08-31 10:10   ` Hans Verkuil
@ 2015-12-06  3:16   ` Laurent Pinchart
  2015-12-07 15:22     ` Javier Martinez Canillas
  1 sibling, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  3:16 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Javier Martinez Canillas,
	Mauro Carvalho Chehab

Hi Javier,

Thank you for the patch.

On Sunday 30 August 2015 00:06:14 Mauro Carvalho Chehab wrote:
> From: Javier Martinez Canillas <javier@osg.samsung.com>
> 
> Assessing media_entity ID should now use media_entity_id() macro to

Did you mean "accessing" ?

> obtain the entity ID, as a next patch will remove the .id field from
> struct media_entity .
> 
> So, get rid of it, otherwise the omap3isp driver will fail to build.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

With the typo fixed,

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> diff --git a/drivers/media/platform/omap3isp/isp.c
> b/drivers/media/platform/omap3isp/isp.c index 56e683b19a73..e08183f9d0f7
> 100644
> --- a/drivers/media/platform/omap3isp/isp.c
> +++ b/drivers/media/platform/omap3isp/isp.c
> @@ -975,6 +975,7 @@ static int isp_pipeline_disable(struct isp_pipeline
> *pipe) struct v4l2_subdev *subdev;
>  	int failure = 0;
>  	int ret;
> +	u32 id;
> 
>  	/*
>  	 * We need to stop all the modules after CCDC first or they'll
> @@ -1027,8 +1028,10 @@ static int isp_pipeline_disable(struct isp_pipeline
> *pipe) if (ret) {
>  			dev_info(isp->dev, "Unable to stop %s\n", subdev->name);
>  			isp->stop_failure = true;
> -			if (subdev == &isp->isp_prev.subdev)
> -				isp->crashed |= 1U << subdev->entity.id;
> +			if (subdev == &isp->isp_prev.subdev) {
> +				id = media_entity_id(&subdev->entity);
> +				isp->crashed |= 1U << id;
> +			}
>  			failure = -ETIMEDOUT;
>  		}
>  	}
> diff --git a/drivers/media/platform/omap3isp/ispccdc.c
> b/drivers/media/platform/omap3isp/ispccdc.c index
> 3b10304b580b..d96e3be5e252 100644
> --- a/drivers/media/platform/omap3isp/ispccdc.c
> +++ b/drivers/media/platform/omap3isp/ispccdc.c
> @@ -1608,7 +1608,7 @@ static int ccdc_isr_buffer(struct isp_ccdc_device
> *ccdc) /* Wait for the CCDC to become idle. */
>  	if (ccdc_sbl_wait_idle(ccdc, 1000)) {
>  		dev_info(isp->dev, "CCDC won't become idle!\n");
> -		isp->crashed |= 1U << ccdc->subdev.entity.id;
> +		isp->crashed |= 1U << media_entity_id(&ccdc->subdev.entity);
>  		omap3isp_pipeline_cancel_stream(pipe);
>  		return 0;
>  	}
> diff --git a/drivers/media/platform/omap3isp/ispvideo.c
> b/drivers/media/platform/omap3isp/ispvideo.c index
> 3094572f8897..6c89dc40df85 100644
> --- a/drivers/media/platform/omap3isp/ispvideo.c
> +++ b/drivers/media/platform/omap3isp/ispvideo.c
> @@ -235,7 +235,7 @@ static int isp_video_get_graph_data(struct isp_video
> *video, while ((entity = media_entity_graph_walk_next(&graph))) {
>  		struct isp_video *__video;
> 
> -		pipe->entities |= 1 << entity->id;
> +		pipe->entities |= 1 << media_entity_id(entity);
> 
>  		if (far_end != NULL)
>  			continue;
> @@ -891,6 +891,7 @@ static int isp_video_check_external_subdevs(struct
> isp_video *video, struct v4l2_ext_control ctrl;
>  	unsigned int i;
>  	int ret;
> +	u32 id;
> 
>  	/* Memory-to-memory pipelines have no external subdev. */
>  	if (pipe->input != NULL)
> @@ -898,7 +899,7 @@ static int isp_video_check_external_subdevs(struct
> isp_video *video,
> 
>  	for (i = 0; i < ARRAY_SIZE(ents); i++) {
>  		/* Is the entity part of the pipeline? */
> -		if (!(pipe->entities & (1 << ents[i]->id)))
> +		if (!(pipe->entities & (1 << media_entity_id(ents[i]))))
>  			continue;
> 
>  		/* ISP entities have always sink pad == 0. Find source. */
> @@ -950,7 +951,8 @@ static int isp_video_check_external_subdevs(struct
> isp_video *video,
> 
>  	pipe->external_rate = ctrl.value64;
> 
> -	if (pipe->entities & (1 << isp->isp_ccdc.subdev.entity.id)) {
> +	id = media_entity_id(&isp->isp_ccdc.subdev.entity);
> +	if (pipe->entities & (1 << id)) {
>  		unsigned int rate = UINT_MAX;
>  		/*
>  		 * Check that maximum allowed CCDC pixel rate isn't

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 02/55] [media] staging: omap4iss: get entity ID using media_entity_id()
  2015-08-30  3:06 ` [PATCH v8 02/55] [media] staging: omap4iss: get entity ID using media_entity_id() Mauro Carvalho Chehab
@ 2015-12-06  3:18   ` Laurent Pinchart
  2015-12-07 15:24     ` Javier Martinez Canillas
  0 siblings, 1 reply; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  3:18 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Javier Martinez Canillas,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, devel

Hi Javier,

Thank you for the patch.

On Sunday 30 August 2015 00:06:13 Mauro Carvalho Chehab wrote:
> From: Javier Martinez Canillas <javier@osg.samsung.com>
> 
> Assessing media_entity ID should now use media_entity_id() macro to

Did you mean "accessing" ?

> obtain the entity ID, as a next patch will remove the .id field from
> struct media_entity .
> 
> So, get rid of it, otherwise the omap4iss driver will fail to build.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

With the typo fixed,

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> diff --git a/drivers/staging/media/omap4iss/iss.c
> b/drivers/staging/media/omap4iss/iss.c index 9bfb725b9986..e54a7afd31de
> 100644
> --- a/drivers/staging/media/omap4iss/iss.c
> +++ b/drivers/staging/media/omap4iss/iss.c
> @@ -607,7 +607,7 @@ static int iss_pipeline_disable(struct iss_pipeline
> *pipe, * crashed. Mark it as such, the ISS will be reset when
>  			 * applications will release it.
>  			 */
> -			iss->crashed |= 1U << subdev->entity.id;
> +			iss->crashed |= 1U << media_entity_id(&subdev->entity);
>  			failure = -ETIMEDOUT;
>  		}
>  	}
> diff --git a/drivers/staging/media/omap4iss/iss_video.c
> b/drivers/staging/media/omap4iss/iss_video.c index
> bae67742706f..25e9e7a6b99d 100644
> --- a/drivers/staging/media/omap4iss/iss_video.c
> +++ b/drivers/staging/media/omap4iss/iss_video.c
> @@ -784,7 +784,7 @@ iss_video_streamon(struct file *file, void *fh, enum
> v4l2_buf_type type) entity = &video->video.entity;
>  	media_entity_graph_walk_start(&graph, entity);
>  	while ((entity = media_entity_graph_walk_next(&graph)))
> -		pipe->entities |= 1 << entity->id;
> +		pipe->entities |= 1 << media_entity_id(entity);
> 
>  	/* Verify that the currently configured format matches the output of
>  	 * the connected subdev.

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 01/55] [media] media: create a macro to get entity ID
  2015-08-30  3:06   ` Mauro Carvalho Chehab
@ 2015-12-06  3:20     ` Laurent Pinchart
  -1 siblings, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  3:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-sh

Hi Mauro,

Thank you for the patch.

On Sunday 30 August 2015 00:06:12 Mauro Carvalho Chehab wrote:
> Instead of accessing directly entity.id, let's create a macro,
> as this field will be moved into a common struct later on.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index c55ab5029323..e429605ca2c3 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -77,8 +77,8 @@ static struct media_entity *find_entity(struct
> media_device *mdev, u32 id) spin_lock(&mdev->lock);
> 
>  	media_device_for_each_entity(entity, mdev) {
> -		if ((entity->id = id && !next) ||
> -		    (entity->id > id && next)) {
> +		if (((media_entity_id(entity) = id) && !next) ||
> +		    ((media_entity_id(entity) > id) && next)) {
>  			spin_unlock(&mdev->lock);
>  			return entity;
>  		}
> @@ -104,7 +104,7 @@ static long media_device_enum_entities(struct
> media_device *mdev, if (ent = NULL)
>  		return -EINVAL;
> 
> -	u_ent.id = ent->id;
> +	u_ent.id = media_entity_id(ent);
>  	if (ent->name)
>  		strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
>  	u_ent.type = ent->type;
> @@ -122,7 +122,7 @@ static long media_device_enum_entities(struct
> media_device *mdev, static void media_device_kpad_to_upad(const struct
> media_pad *kpad, struct media_pad_desc *upad)
>  {
> -	upad->entity = kpad->entity->id;
> +	upad->entity = media_entity_id(kpad->entity);
>  	upad->index = kpad->index;
>  	upad->flags = kpad->flags;
>  }
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 949e5f92cbdc..cb0ac4e0dfa5 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -140,10 +140,10 @@ void media_entity_graph_walk_start(struct
> media_entity_graph *graph, graph->stack[graph->top].entity = NULL;
>  	bitmap_zero(graph->entities, MEDIA_ENTITY_ENUM_MAX_ID);
> 
> -	if (WARN_ON(entity->id >= MEDIA_ENTITY_ENUM_MAX_ID))
> +	if (WARN_ON(media_entity_id(entity) >= MEDIA_ENTITY_ENUM_MAX_ID))
>  		return;
> 
> -	__set_bit(entity->id, graph->entities);
> +	__set_bit(media_entity_id(entity), graph->entities);
>  	stack_push(graph, entity);
>  }
>  EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
> @@ -184,11 +184,11 @@ media_entity_graph_walk_next(struct media_entity_graph
> *graph)
> 
>  		/* Get the entity in the other end of the link . */
>  		next = media_entity_other(entity, link);
> -		if (WARN_ON(next->id >= MEDIA_ENTITY_ENUM_MAX_ID))
> +		if (WARN_ON(media_entity_id(next) >= MEDIA_ENTITY_ENUM_MAX_ID))
>  			return NULL;
> 
>  		/* Has the entity already been visited? */
> -		if (__test_and_set_bit(next->id, graph->entities)) {
> +		if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
>  			link_top(graph)++;
>  			continue;
>  		}
> diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> b/drivers/media/platform/vsp1/vsp1_video.c index 17f08973f835..debe4e539df6
> 100644
> --- a/drivers/media/platform/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> @@ -352,10 +352,10 @@ static int vsp1_pipeline_validate_branch(struct
> vsp1_pipeline *pipe, break;
> 
>  		/* Ensure the branch has no loop. */
> -		if (entities & (1 << entity->subdev.entity.id))
> +		if (entities & (1 << media_entity_id(&entity->subdev.entity)))
>  			return -EPIPE;
> 
> -		entities |= 1 << entity->subdev.entity.id;
> +		entities |= 1 << media_entity_id(&entity->subdev.entity);
> 
>  		/* UDS can't be chained. */
>  		if (entity->type = VSP1_ENTITY_UDS) {
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 8b21a4d920d9..0a66fc225559 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -113,6 +113,11 @@ static inline u32 media_entity_subtype(struct
> media_entity *entity) return entity->type & MEDIA_ENT_SUBTYPE_MASK;
>  }
> 
> +static inline u32 media_entity_id(struct media_entity *entity)
> +{
> +	return entity->id;
> +}
> +
>  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
>  #define MEDIA_ENTITY_ENUM_MAX_ID	64

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 01/55] [media] media: create a macro to get entity ID
@ 2015-12-06  3:20     ` Laurent Pinchart
  0 siblings, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2015-12-06  3:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-sh

Hi Mauro,

Thank you for the patch.

On Sunday 30 August 2015 00:06:12 Mauro Carvalho Chehab wrote:
> Instead of accessing directly entity.id, let's create a macro,
> as this field will be moved into a common struct later on.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index c55ab5029323..e429605ca2c3 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -77,8 +77,8 @@ static struct media_entity *find_entity(struct
> media_device *mdev, u32 id) spin_lock(&mdev->lock);
> 
>  	media_device_for_each_entity(entity, mdev) {
> -		if ((entity->id == id && !next) ||
> -		    (entity->id > id && next)) {
> +		if (((media_entity_id(entity) == id) && !next) ||
> +		    ((media_entity_id(entity) > id) && next)) {
>  			spin_unlock(&mdev->lock);
>  			return entity;
>  		}
> @@ -104,7 +104,7 @@ static long media_device_enum_entities(struct
> media_device *mdev, if (ent == NULL)
>  		return -EINVAL;
> 
> -	u_ent.id = ent->id;
> +	u_ent.id = media_entity_id(ent);
>  	if (ent->name)
>  		strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
>  	u_ent.type = ent->type;
> @@ -122,7 +122,7 @@ static long media_device_enum_entities(struct
> media_device *mdev, static void media_device_kpad_to_upad(const struct
> media_pad *kpad, struct media_pad_desc *upad)
>  {
> -	upad->entity = kpad->entity->id;
> +	upad->entity = media_entity_id(kpad->entity);
>  	upad->index = kpad->index;
>  	upad->flags = kpad->flags;
>  }
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 949e5f92cbdc..cb0ac4e0dfa5 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -140,10 +140,10 @@ void media_entity_graph_walk_start(struct
> media_entity_graph *graph, graph->stack[graph->top].entity = NULL;
>  	bitmap_zero(graph->entities, MEDIA_ENTITY_ENUM_MAX_ID);
> 
> -	if (WARN_ON(entity->id >= MEDIA_ENTITY_ENUM_MAX_ID))
> +	if (WARN_ON(media_entity_id(entity) >= MEDIA_ENTITY_ENUM_MAX_ID))
>  		return;
> 
> -	__set_bit(entity->id, graph->entities);
> +	__set_bit(media_entity_id(entity), graph->entities);
>  	stack_push(graph, entity);
>  }
>  EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
> @@ -184,11 +184,11 @@ media_entity_graph_walk_next(struct media_entity_graph
> *graph)
> 
>  		/* Get the entity in the other end of the link . */
>  		next = media_entity_other(entity, link);
> -		if (WARN_ON(next->id >= MEDIA_ENTITY_ENUM_MAX_ID))
> +		if (WARN_ON(media_entity_id(next) >= MEDIA_ENTITY_ENUM_MAX_ID))
>  			return NULL;
> 
>  		/* Has the entity already been visited? */
> -		if (__test_and_set_bit(next->id, graph->entities)) {
> +		if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
>  			link_top(graph)++;
>  			continue;
>  		}
> diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> b/drivers/media/platform/vsp1/vsp1_video.c index 17f08973f835..debe4e539df6
> 100644
> --- a/drivers/media/platform/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> @@ -352,10 +352,10 @@ static int vsp1_pipeline_validate_branch(struct
> vsp1_pipeline *pipe, break;
> 
>  		/* Ensure the branch has no loop. */
> -		if (entities & (1 << entity->subdev.entity.id))
> +		if (entities & (1 << media_entity_id(&entity->subdev.entity)))
>  			return -EPIPE;
> 
> -		entities |= 1 << entity->subdev.entity.id;
> +		entities |= 1 << media_entity_id(&entity->subdev.entity);
> 
>  		/* UDS can't be chained. */
>  		if (entity->type == VSP1_ENTITY_UDS) {
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 8b21a4d920d9..0a66fc225559 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -113,6 +113,11 @@ static inline u32 media_entity_subtype(struct
> media_entity *entity) return entity->type & MEDIA_ENT_SUBTYPE_MASK;
>  }
> 
> +static inline u32 media_entity_id(struct media_entity *entity)
> +{
> +	return entity->id;
> +}
> +
>  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
>  #define MEDIA_ENTITY_ENUM_MAX_ID	64

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 18/55] [media] omap3isp: create links after all subdevs have been bound
  2015-12-06  3:05       ` Laurent Pinchart
@ 2015-12-07 15:17         ` Javier Martinez Canillas
  0 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-12-07 15:17 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Sakari Ailus, Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab

Hello Laurent,

On 12/06/2015 12:05 AM, Laurent Pinchart wrote:
> Hi Javier,
> 
> Thank you for the patch.
> 
> On Wednesday 09 September 2015 10:48:29 Javier Martinez Canillas wrote:
>> On 09/09/2015 10:03 AM, Sakari Ailus wrote:
>>> On Sun, Aug 30, 2015 at 12:06:29AM -0300, Mauro Carvalho Chehab wrote:
>>>> From: Javier Martinez Canillas <javier@osg.samsung.com>
>>>>
>>>> The omap3isp driver parses the graph endpoints to know how many
>>>> subdevices needs to be registered async and register notifiers callbacks
>>>> for to know when these are bound and when the async registrations are
>>>> completed.
>>>>
>>>> Currently the entities pad are linked with the correct ISP input
>>>> interface when the subdevs are bound but it happens before entitities are
>>>> registered with the media device so that won't work now that the entity
>>>> links list is initialized on device registration.
>>>>
>>>> So instead creating the pad links when the subdevice is bound, create
>>>> them on the complete callback once all the subdevices have been bound but
>>>> only try to create for the ones that have a bus configuration set during
>>>> bound.
>>>>
>>>> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
>>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>>>>
>>>> diff --git a/drivers/media/platform/omap3isp/isp.c
>>>> b/drivers/media/platform/omap3isp/isp.c index b8f6f81d2db2..69e7733d36cd
>>>> 100644
>>>> --- a/drivers/media/platform/omap3isp/isp.c
>>>> +++ b/drivers/media/platform/omap3isp/isp.c
>>>> @@ -2321,26 +2321,33 @@ static int isp_subdev_notifier_bound(struct
>>>> v4l2_async_notifier *async,
>>>>  				     struct v4l2_subdev *subdev,
>>>>  				     struct v4l2_async_subdev *asd)
>>>>  {
>>>> -	struct isp_device *isp = container_of(async, struct isp_device,
>>>> -					      notifier);
>>>>  	struct isp_async_subdev *isd =
>>>>  		container_of(asd, struct isp_async_subdev, asd);
>>>> -	int ret;
>>>> -
>>>> -	ret = isp_link_entity(isp, &subdev->entity, isd->bus.interface);
>>>> -	if (ret < 0)
>>>> -		return ret;
>>>>
>>>>  	isd->sd = subdev;
>>>>  	isd->sd->host_priv = &isd->bus;
>>>>
>>>> -	return ret;
>>>> +	return 0;
>>>>  }
>>>>  
>>>>  static int isp_subdev_notifier_complete(struct v4l2_async_notifier
>>>>  *async)
>>>>  {
>>>>  	struct isp_device *isp = container_of(async, struct isp_device,
>>>>  					      notifier);
>>>> +	struct v4l2_device *v4l2_dev = &isp->v4l2_dev;
>>>> +	struct v4l2_subdev *sd;
>>>> +	struct isp_bus_cfg *bus;
>>>> +	int ret;
>>>> +
>>>> +	list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
>>>> +		/* Only try to link entities whose interface was set on bound */
>>>> +		if (sd->host_priv) {
>>>> +			bus = (struct isp_bus_cfg *)sd->host_priv;
>>>> +			ret = isp_link_entity(isp, &sd->entity, bus->interface);
>>>> +			if (ret < 0)
>>>> +				return ret;
>>>> +		}
>>>> +	}
>>>>  	return v4l2_device_register_subdev_nodes(&isp->v4l2_dev);
>>>>  }
>>>
>>> I think you're working around a problem here, not really fixing it.
>>>
>>> This change will create the links only after the media device is
>>> registered, which means the user may obtain a partial enumeration of
>>> links if the enumeration is performed too early.
>>>
>>> Before this set, the problem also was that the media device was registered
>>> before the async entities were bound, again making it possible to obtain a
>>> partial enumeration of entities.
>>
>> You are absolutely correct but I think these are separate issues. The
>> problem here is that v4l2_async_test_notify() [0] first invokes the bound
>> notifier callback and then calls v4l2_device_register_subdev() that
>> register the media entity with the media device.
>>
>> Since now is a requirement that the entities must be registered prior
>> creating pads links (because to init a MEDIA_GRAPH_LINK object a mdev has
>> to be set), $SUBJECT is needed regardless of the race between subdev
>> registration and the media dev node being available to user-space before
>> everything is registered.
>>> What I'd suggest instead is that we split media device initialisation and
>>> registration to the system; that way the media device can be prepared
>>> (entities registered and links created) before it becomes visible to the
>>> user space. I can write a patch for that if you like.
>>
>> Agreed, looking at the implementation it seems that
>> __media_device_register() has to be split (possibly being renamed to
>> __media_device_init) so it only contains the initialization logic and all
>> the media device node registration logic moved to another function (that
>> would become media_device_register).
>>
>> I think the media dev node registration has to be made in the complete
>> callback to make sure that happens when all the subdevs have been already
>> registered.
>>
>> Is that what you had in mind? I can also write such a patch if you want.
> 
> I think I've already commented on it in my review of another patch (but can't 
> find it right now), I agree with you. We need to properly think about 

I'm glad that you agree, could you please review the v4 of patch series
"Fix race between graph enumeration and entities registration" [0] that
I posted a while ago?

> initialization (and, for that matter, cleanup as well) order, both for the 
> media device and the entities. And, as a corollary, for subdevs too. The
> current media entity and subdevs initialization and registration code grew in 
> an organic way without much design behind it, let's not repeat the same 
> mistake.
> 

Agreed, and this should be properly documented so driver authors can follow.

[0]: https://lkml.org/lkml/2015/9/15/371

Best regards,
-- 
Javier Martinez Canillas
Open Source Group
Samsung Research America

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 03/55] [media] omap3isp: get entity ID using media_entity_id()
  2015-12-06  3:16   ` Laurent Pinchart
@ 2015-12-07 15:22     ` Javier Martinez Canillas
  0 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-12-07 15:22 UTC (permalink / raw)
  To: Laurent Pinchart, Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Hello Laurent,

On 12/06/2015 12:16 AM, Laurent Pinchart wrote:
> Hi Javier,
> 
> Thank you for the patch.
> 
> On Sunday 30 August 2015 00:06:14 Mauro Carvalho Chehab wrote:
>> From: Javier Martinez Canillas <javier@osg.samsung.com>
>>
>> Assessing media_entity ID should now use media_entity_id() macro to
> 
> Did you mean "accessing" ?
>

Yes I did, sorry for the typo. Maybe Mauro can fix it when applying?
 
>> obtain the entity ID, as a next patch will remove the .id field from
>> struct media_entity .
>>
>> So, get rid of it, otherwise the omap3isp driver will fail to build.
>>
>> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> With the typo fixed,
> 
> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>

Thanks.

Best regards,
-- 
Javier Martinez Canillas
Open Source Group
Samsung Research America

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 02/55] [media] staging: omap4iss: get entity ID using media_entity_id()
  2015-12-06  3:18   ` Laurent Pinchart
@ 2015-12-07 15:24     ` Javier Martinez Canillas
  0 siblings, 0 replies; 309+ messages in thread
From: Javier Martinez Canillas @ 2015-12-07 15:24 UTC (permalink / raw)
  To: Laurent Pinchart, Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, devel

Hello Laurent,

On 12/06/2015 12:18 AM, Laurent Pinchart wrote:
> Hi Javier,
> 
> Thank you for the patch.
> 
> On Sunday 30 August 2015 00:06:13 Mauro Carvalho Chehab wrote:
>> From: Javier Martinez Canillas <javier@osg.samsung.com>
>>
>> Assessing media_entity ID should now use media_entity_id() macro to
> 
> Did you mean "accessing" ?
>

Sigh, yet another typo error that seems to be due copy and paste.
 
>> obtain the entity ID, as a next patch will remove the .id field from
>> struct media_entity .
>>
>> So, get rid of it, otherwise the omap4iss driver will fail to build.
>>
>> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
>> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> With the typo fixed,
> 
> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>

Thanks.

Best regards,
-- 
Javier Martinez Canillas
Open Source Group
Samsung Research America

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 14/55] [media] media: add functions to allow creating interfaces
  2015-09-11 12:57     ` Hans Verkuil
@ 2015-12-08 14:36       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 14:36 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Linux Media Mailing List

Em Fri, 11 Sep 2015 14:57:41 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 09/06/2015 02:02 PM, Mauro Carvalho Chehab wrote:
> > Interfaces are different than entities: they represent a
> > Kernel<->userspace interaction, while entities represent a
> > piece of hardware/firmware/software that executes a function.
> > 
> > Let's distinguish them by creating a separate structure to
> > store the interfaces.
> > 
> > Later patches should change the existing drivers and logic
> > to split the current interface embedded inside the entity
> > structure (device nodes) into a separate object of the graph.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> But see a small note below:
> 
> > 
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index a23c93369a04..dc679dfe8ade 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -44,11 +44,41 @@ static inline const char *gobj_type(enum media_gobj_type type)
> >  		return "pad";
> >  	case MEDIA_GRAPH_LINK:
> >  		return "link";
> > +	case MEDIA_GRAPH_INTF_DEVNODE:
> > +		return "intf-devnode";
> >  	default:
> >  		return "unknown";
> >  	}
> >  }
> >  
> > +static inline const char *intf_type(struct media_interface *intf)
> > +{
> > +	switch (intf->type) {
> > +	case MEDIA_INTF_T_DVB_FE:
> > +		return "frontend";
> > +	case MEDIA_INTF_T_DVB_DEMUX:
> > +		return "demux";
> > +	case MEDIA_INTF_T_DVB_DVR:
> > +		return "DVR";
> > +	case MEDIA_INTF_T_DVB_CA:
> > +		return  "CA";
> 
> Would lower case be better? "dvr" and "ca"? Although for some reason I feel that "CA"
> is fine too. Not sure why :-)
> 
> What is the name of the associated device node? Upper or lower case? I feel that the
> name here should match the name of the device node.

Not sure if I answered that before. I opted to use upper case for DVR and 
CA because both are initials:
	DVR - Digital Video Record
	CA - Conditional Access

and initials are in upper case, in English.

The devnode names are whatever the udev rules tell ;) The Kernel actually 
asks to create DVB class devices for the first DVR and CA, located on the first
DVB adapter as:
	/dev/dvb/adapter0/dvr0
	/dev/dvb/adapter0/ca0

I don't mind changing those to lowercase to match the devnames on some
future patch, if it is a consensus that making those names matching the
device node is a requirement, but, in this case, maybe we should rename the
dvb stuff to:
	dvb/adapter/foo, in order to better reflect how they'll appear
at devfs.

Please also notice that:

+	case MEDIA_INTF_T_DVB_NET:
+		return "dvbnet";


This is also not the device node. The device node there is actually:
	/dev/dvb/adapter0/net0

So, IMHO, it is fine the way it is, as we don't want big names here
on those printks.

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA
  2015-12-06  2:20     ` Laurent Pinchart
@ 2015-12-08 15:41       ` Mauro Carvalho Chehab
  2016-02-16  0:34         ` Laurent Pinchart
  0 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 15:41 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List

Em Sun, 06 Dec 2015 04:20:38 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 06 September 2015 09:02:57 Mauro Carvalho Chehab wrote:
> > As we'll be removing entity subtypes from the Kernel, we need
> > to provide a way for drivers and core to check if a given
> > entity is represented by a V4L2 subdev or if it is an V4L2
> > I/O entity (typically with DMA).
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index 4e36b1f2b2d7..220864319d21 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -220,6 +220,39 @@ static inline u32 media_gobj_gen_id(enum
> > media_gobj_type type, u32 local_id) return id;
> >  }
> > 
> > +static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
> > +{
> > +	if (!entity)
> > +		return false;
> > +
> > +	switch (entity->type) {
> > +	case MEDIA_ENT_T_V4L2_VIDEO:
> > +	case MEDIA_ENT_T_V4L2_VBI:
> > +	case MEDIA_ENT_T_V4L2_SWRADIO:
> > +		return true;
> > +	default:
> > +		return false;
> > +	}
> > +}
> > +
> > +static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
> > +{
> > +	if (!entity)
> > +		return false;
> > +
> > +	switch (entity->type) {
> > +	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
> > +	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
> > +	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
> > +	case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
> > +	case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
> 
> I'm sorry but this simply won't scale. We need a better way to determine the 
> entity type, and this could be a valid use case to actually retain an entity 
> type field separate from the function, at least inside the kernel.

As we're getting rid of a separate range for V4L2 subdevs, several drivers
need some logic to identify if an entity is a subdev or not. So, no matter
how we implement it, we need a is_media_entity_v4l2_subdev() function.

So, I guess you're discussing the actual implementation, not the need of
such function.

With that regards, I'm not sure if this won't scale. The gcc compiler 
optimizer usually uses binary search on switches. So, O(log(n)). 
Even if we had 256 subdev types, that would mean 8 ifs. Doesn't seem
too bad, specially since we have right now only 5 subdev types.

Ok, there's one thing bad on this: we need to update this function every
time a new V4L2 subdev is added. So, it may be a maintainance nightmare,
but I don't see any way to avoid the need of adding the subdevs at both
UAPI and kernelspace.

I'm not opposed to change this to some other method that we would find.
In any case, this is inside an inlined function. So, it is easy to
replace the implementation to any other logic we find better. So,
if you have a better idea, feel free to submit a followup patch
optimizing it.

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
  2015-10-12 15:35         ` Sakari Ailus
                           ` (3 preceding siblings ...)
  (?)
@ 2015-12-08 15:57         ` Mauro Carvalho Chehab
  2015-12-08 17:05           ` Mauro Carvalho Chehab
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 15:57 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	Laurent Pinchart, Hans Verkuil, Sakari Ailus,
	Javier Martinez Canillas

Em Mon, 12 Oct 2015 18:35:05 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Sun, Oct 11, 2015 at 09:56:25PM -0300, Mauro Carvalho Chehab wrote:
> > Em Mon, 12 Oct 2015 00:07:52 +0300
> > Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> > 
> > > Hi Mauro,
> > > 
> > > On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > > > Instead of relying on media subtype, use the new macros to detect
> > > > if an entity is a subdev or an A/V DMA entity.
> > > > 
> > > > Please note that most drivers assume that there's just AV_DMA or
> > > > V4L2 subdevs. This is not true anymore, as we've added MC support
> > > > for DVB, and there are plans to add support for ALSA and FB/DRM
> > > > too.
> > > > 
> > > > Ok, on the current pipelines supported by those drivers, just V4L
> > > > stuff are there, but, assuming that some day a pipeline that also
> > > > works with other subsystems will ever added, it is better to add
> > > > explicit checks for the AV_DMA stuff.
> > > > 
> > > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > > 
> > > > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > > > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > > > --- a/drivers/media/platform/exynos4-is/common.c
> > > > +++ b/drivers/media/platform/exynos4-is/common.c
> > > > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> > > >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> > > >  		/* source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > index 0627a93b2f3b..e9810fee4c30 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> > > >  			}
> > > >  		}
> > > >  
> > > > -		if (src_pad == NULL ||
> > > > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> > > >  			break;
> > > >  
> > > >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > > > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> > > >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> > > >  	struct v4l2_subdev *sensor;
> > > >  
> > > > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return -EINVAL;
> > > >  
> > > >  	if (WARN_ON(fimc == NULL))
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> > > >  
> > > >  		/* Retrieve format at the source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > index b2607da4ad14..c2327147b360 100644
> > > > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> > > >  		}
> > > >  		/* Retrieve format at the source pad */
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  {
> > > >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> > > >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > > > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> > > >  	int ret = 0;
> > > >  
> > > >  	if (WARN_ON(fimc == NULL))
> > > > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  
> > > >  	switch (local->index) {
> > > >  	case FLITE_SD_PAD_SINK:
> > > > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> > > >  			ret = -EINVAL;
> > > >  			break;
> > > >  		}
> > > > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  	case FLITE_SD_PAD_SOURCE_DMA:
> > > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > > -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> > > > +		else if (is_media_entity_v4l2_io(remote->entity))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> > > >  		else
> > > >  			ret = -EINVAL;
> > > > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > >  	case FLITE_SD_PAD_SOURCE_ISP:
> > > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > > -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> > > >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> > > >  		else
> > > >  			ret = -EINVAL;
> > > > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > > > index 92dbade2fffc..4a25df9dd869 100644
> > > > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > > > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > > > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> > > >  				break;
> > > >  		}
> > > >  
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > >  
> > > > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > > > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > > >  	media_entity_graph_walk_start(&graph, entity_err);
> > > >  
> > > >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity_err))
> > > >  			continue;
> > > >  
> > > >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > > > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > > > index 69e7733d36cd..cb8ac90086c1 100644
> > > > --- a/drivers/media/platform/omap3isp/isp.c
> > > > +++ b/drivers/media/platform/omap3isp/isp.c
> > > > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_io(entity))
> > > >  			use += entity->use_count;
> > > >  	}
> > > >  
> > > > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> > > >  	struct v4l2_subdev *subdev;
> > > >  	int ret;
> > > >  
> > > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > > >  
> > > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(entity))
> > > >  			ret = isp_pipeline_pm_power_one(entity, change);
> > > >  
> > > >  	if (!ret)
> > > > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  
> > > >  	while ((first = media_entity_graph_walk_next(&graph))
> > > >  	       && first != entity)
> > > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(first))
> > > >  			isp_pipeline_pm_power_one(first, -change);
> > > >  
> > > >  	return ret;
> > > > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > > > index 4c367352b1f7..52843ac2a9ca 100644
> > > > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > > > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > > > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> > > >  
> > > >  	remote = media_entity_remote_pad(&video->pad);
> > > >  
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> > > >  		if (entity == &video->video.entity)
> > > >  			continue;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > > > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> > > >  		return -EINVAL;
> > > >  	}
> > > >  
> > > > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!is_media_entity_v4l2_subdev(source))
> > > >  		return 0;
> > > >  
> > > >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > > > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > > > index eae667eab1b9..fb5b016cc0a1 100644
> > > > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > > > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > > > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> > > >  
> > > >  	/* Retrieve format at the sensor subdev source pad */
> > > >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > > > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  		return -EPIPE;
> > > >  
> > > >  	src_fmt.pad = pad->index;
> > > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > > > index 1f94c1a54e00..f74158224b93 100644
> > > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> > > >  	struct media_pad *remote;
> > > >  
> > > >  	remote = media_entity_remote_pad(local);
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> > > >  			return -EPIPE;
> > > >  
> > > >  		/* We've reached a video node, that shouldn't have happened. */
> > > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > > >  			return -EPIPE;
> > > >  
> > > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> > > >  		struct vsp1_rwpf *rwpf;
> > > >  		struct vsp1_entity *e;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +		if (is_media_entity_v4l2_io(entity)) {
> > > >  			pipe->num_video++;
> > > >  			continue;
> > > >  		}
> > > > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> > > >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> > > >  
> > > >  	while (pad) {
> > > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > > > index 88cd789cdaf7..8e14841bf445 100644
> > > > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > > > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > > > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> > > >  	struct media_pad *remote;
> > > >  
> > > >  	remote = media_entity_remote_pad(local);
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > > > index e6e1115d8215..60da43772de9 100644
> > > > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > > > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > > > @@ -526,7 +526,7 @@ static int
> > > >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> > > >  				     struct v4l2_subdev_format *fmt)
> > > >  {
> > > > -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> > > >  		struct v4l2_subdev *sd =
> > > >  			media_entity_to_v4l2_subdev(pad->entity);
> > > >  
> > > > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > index 92573fa852a9..16763e0831f2 100644
> > > > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  		if (entity == &video->video_dev.entity)
> > > >  			continue;
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if ((!is_media_entity_v4l2_io(remote->entity))
> > > >  			continue;
> > > >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> > > >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > > > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if !is_media_entity_v4l2_subdev(entity))
> > > >  			continue;
> > > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > > > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > >  
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_subdev(entity))
> > > >  			continue;
> > > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > > > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > > > index 40591963b42b..44b88ff3ba83 100644
> > > > --- a/drivers/staging/media/omap4iss/iss.c
> > > > +++ b/drivers/staging/media/omap4iss/iss.c
> > > > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_io(entity))
> > > >  			use += entity->use_count;
> > > >  	}
> > > >  
> > > > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> > > >  {
> > > >  	struct v4l2_subdev *subdev;
> > > >  
> > > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > > >  
> > > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  	media_entity_graph_walk_start(&graph, entity);
> > > >  
> > > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(entity))
> > > >  			ret = iss_pipeline_pm_power_one(entity, change);
> > > >  
> > > >  	if (!ret)
> > > > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > > >  
> > > >  	while ((first = media_entity_graph_walk_next(&graph))
> > > >  	       && first != entity)
> > > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (is_media_entity_v4l2_subdev(first))
> > > >  			iss_pipeline_pm_power_one(first, -change);
> > > >  
> > > >  	return ret;
> > > > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> > > >  			break;
> > > >  
> > > >  		pad = media_entity_remote_pad(pad);
> > > > -		if (pad == NULL ||
> > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > >  			break;
> > > >  
> > > >  		entity = pad->entity;
> > > > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > > > index 45a3f2d778fc..cbe5783735dc 100644
> > > > --- a/drivers/staging/media/omap4iss/iss_video.c
> > > > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > > > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> > > >  
> > > >  	remote = media_entity_remote_pad(&video->pad);
> > > >  
> > > > -	if (remote == NULL ||
> > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > >  		return NULL;
> > > >  
> > > >  	if (pad)
> > > > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> > > >  		if (entity == &video->video.entity)
> > > >  			continue;
> > > >  
> > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > +		if (!is_media_entity_v4l2_io(entity))
> > > >  			continue;
> > > >  
> > > >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> > > 
> > > I finally got around to test these patches eventually, and after some
> > > debugging found this one. I think it's a good idea to have macros to
> > > determine whether an entity exposes a V4L2 sub-device interface but it
> > > should be more robust than is_media_entity_v4l2_subdev() right now is.
> > 
> > Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
> > actually a separate graph object (interfaces). Those macros work at the
> > entities, not at the interface objects.
> 
> is_media_entity_v4l2_subdev() will produce wrong results for a large part of
> V4L2 sub-devices with these patches applied.
> 
> I checked again the original implementation, and it seems to be based only
> on the type as well, albeit that's a range, not a set of different
> functions.
> 
> I suppose this will change at some point in the future: the interface indeed
> should not be determined by the function of the entity. At least it needs to
> be fixed now until the rework. I'll submit a patch for that.

I'm folding this small fixup to this patch. It should fix the issues with
the unknown subdev types.

This is fixed on some latter patches in this series, adding 
MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN, but let's avoid breaking bisectability
here.

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 337d7b3e047f..b4a17a1bce58 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -241,6 +241,7 @@ static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
 		return false;
 
 	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_SUBDEV_BASE:
 	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
 	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
 	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:

> 

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
  2015-12-06  2:16     ` Laurent Pinchart
  (?)
@ 2015-12-08 16:03       ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 16:03 UTC (permalink / raw)
  To: linux-arm-kernel

Em Sun, 06 Dec 2015 04:16:15 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 30 August 2015 00:06:43 Mauro Carvalho Chehab wrote:
> > Instead of relying on media subtype, use the new macros to detect
> > if an entity is a subdev or an A/V DMA entity.
> > 
> > Please note that most drivers assume that there's just AV_DMA or
> > V4L2 subdevs. This is not true anymore, as we've added MC support
> > for DVB, and there are plans to add support for ALSA and FB/DRM
> > too.
> > 
> > Ok, on the current pipelines supported by those drivers, just V4L
> > stuff are there, but, assuming that some day a pipeline that also
> > works with other subsystems will ever added, it is better to add
> > explicit checks for the AV_DMA stuff.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/platform/exynos4-is/common.c
> > b/drivers/media/platform/exynos4-is/common.c index
> > 0eb34ecb8ee4..8c9a29e0e294 100644
> > --- a/drivers/media/platform/exynos4-is/common.c
> > +++ b/drivers/media/platform/exynos4-is/common.c
> > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct
> > media_entity *entity) while (pad->flags & MEDIA_PAD_FL_SINK) {
> >  		/* source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c
> > b/drivers/media/platform/exynos4-is/fimc-capture.c index
> > 0627a93b2f3b..e9810fee4c30 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev
> > *fimc) }
> >  		}
> > 
> > -		if (src_pad = NULL ||
> > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> >  			break;
> > 
> >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity
> > *entity, struct fimc_vid_cap *vc = &fimc->vid_cap;
> >  	struct v4l2_subdev *sensor;
> > 
> > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> >  		return -EINVAL;
> > 
> >  	if (WARN_ON(fimc = NULL))
> > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > b/drivers/media/platform/exynos4-is/fimc-isp-video.c index
> > 3d9ccbf5f10f..5fbaf5e39903 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp
> > *isp)
> > 
> >  		/* Retrieve format at the source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c
> > b/drivers/media/platform/exynos4-is/fimc-lite.c index
> > b2607da4ad14..c2327147b360 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite
> > *fimc) }
> >  		/* Retrieve format at the source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity
> > *entity, {
> >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> >  	int ret = 0;
> > 
> >  	if (WARN_ON(fimc = NULL))
> > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity
> > *entity,
> > 
> >  	switch (local->index) {
> >  	case FLITE_SD_PAD_SINK:
> > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> >  			ret = -EINVAL;
> >  			break;
> >  		}
> > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity
> > *entity, case FLITE_SD_PAD_SOURCE_DMA:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > -		else if (remote_ent_type = MEDIA_ENT_T_DEVNODE)
> > +		else if (is_media_entity_v4l2_io(remote->entity))
> >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> >  		else
> >  			ret = -EINVAL;
> > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity
> > *entity, case FLITE_SD_PAD_SOURCE_ISP:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > -		else if (remote_ent_type = MEDIA_ENT_T_V4L2_SUBDEV)
> > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> >  		else
> >  			ret = -EINVAL;
> > diff --git a/drivers/media/platform/exynos4-is/media-dev.c
> > b/drivers/media/platform/exynos4-is/media-dev.c index
> > 92dbade2fffc..4a25df9dd869 100644
> > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> > break;
> >  		}
> > 
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > 
> > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct
> > media_entity *entity, bool enable) media_entity_graph_walk_start(&graph,
> > entity);
> > 
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> > 
> >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct
> > media_entity *entity, bool enable) media_entity_graph_walk_start(&graph,
> > entity_err);
> > 
> >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity_err))
> >  			continue;
> > 
> >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > diff --git a/drivers/media/platform/omap3isp/isp.c
> > b/drivers/media/platform/omap3isp/isp.c index 69e7733d36cd..cb8ac90086c1
> > 100644
> > --- a/drivers/media/platform/omap3isp/isp.c
> > +++ b/drivers/media/platform/omap3isp/isp.c
> > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity
> > *entity) media_entity_graph_walk_start(&graph, entity);
> > 
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_io(entity))
> >  			use += entity->use_count;
> >  	}
> > 
> > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity
> > *entity, int change) struct v4l2_subdev *subdev;
> >  	int ret;
> > 
> > -	subdev = media_entity_type(entity) = MEDIA_ENT_T_V4L2_SUBDEV
> > +	subdev = is_media_entity_v4l2_subdev(entity)
> >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > 
> >  	if (entity->use_count = 0 && change > 0 && subdev != NULL) {
> > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity
> > *entity, int change) media_entity_graph_walk_start(&graph, entity);
> > 
> >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(entity))
> >  			ret = isp_pipeline_pm_power_one(entity, change);
> > 
> >  	if (!ret)
> > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity
> > *entity, int change)
> > 
> >  	while ((first = media_entity_graph_walk_next(&graph))
> >  	       && first != entity)
> > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(first))
> >  			isp_pipeline_pm_power_one(first, -change);
> > 
> >  	return ret;
> > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline
> > *pipe, break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline
> > *pipe) break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > diff --git a/drivers/media/platform/omap3isp/ispvideo.c
> > b/drivers/media/platform/omap3isp/ispvideo.c index
> > 4c367352b1f7..52843ac2a9ca 100644
> > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32
> > *pad)
> > 
> >  	remote = media_entity_remote_pad(&video->pad);
> > 
> > -	if (remote = NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> > 
> >  	if (pad)
> > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video
> > *video, if (entity = &video->video.entity)
> >  			continue;
> > 
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> > 
> >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct
> > isp_video *video, return -EINVAL;
> >  	}
> > 
> > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!is_media_entity_v4l2_subdev(source))
> >  		return 0;
> > 
> >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c
> > b/drivers/media/platform/s3c-camif/camif-capture.c index
> > eae667eab1b9..fb5b016cc0a1 100644
> > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev
> > *camif)
> > 
> >  	/* Retrieve format at the sensor subdev source pad */
> >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  		return -EPIPE;
> > 
> >  	src_fmt.pad = pad->index;
> > diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> > b/drivers/media/platform/vsp1/vsp1_video.c index 1f94c1a54e00..f74158224b93
> > 100644
> > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32
> > *pad) struct media_pad *remote;
> > 
> >  	remote = media_entity_remote_pad(local);
> > -	if (remote = NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> > 
> >  	if (pad)
> > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct
> > vsp1_pipeline *pipe, return -EPIPE;
> > 
> >  		/* We've reached a video node, that shouldn't have happened. */
> > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> >  			return -EPIPE;
> > 
> >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline
> > *pipe, struct vsp1_rwpf *rwpf;
> >  		struct vsp1_entity *e;
> > 
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > +		if (is_media_entity_v4l2_io(entity)) {
> >  			pipe->num_video++;
> >  			continue;
> >  		}
> > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline
> > *pipe, pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> > 
> >  	while (pad) {
> > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c
> > b/drivers/media/platform/xilinx/xilinx-dma.c index
> > 88cd789cdaf7..8e14841bf445 100644
> > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> >  	struct media_pad *remote;
> > 
> >  	remote = media_entity_remote_pad(local);
> > -	if (remote = NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> > 
> >  	if (pad)
> > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline
> > *pipe, bool start) break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c
> > b/drivers/media/v4l2-core/v4l2-subdev.c index e6e1115d8215..60da43772de9
> > 100644
> > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > @@ -526,7 +526,7 @@ static int
> >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> >  				     struct v4l2_subdev_format *fmt)
> >  {
> > -	if (media_entity_type(pad->entity) = MEDIA_ENT_T_V4L2_SUBDEV) {
> > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> >  		struct v4l2_subdev *sd > >  			media_entity_to_v4l2_subdev(pad->entity);
> > 
> > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > b/drivers/staging/media/davinci_vpfe/vpfe_video.c index
> > 92573fa852a9..16763e0831f2 100644
> > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct
> > vpfe_video_device *video) while ((entity > > media_entity_graph_walk_next(&graph))) {
> >  		if (entity = &video->video_dev.entity)
> >  			continue;
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if ((!is_media_entity_v4l2_io(remote->entity))
> >  			continue;
> >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> >  		if (far_end->type = V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline
> > *pipe) media_entity_graph_walk_start(&graph, entity);
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > 
> > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > +		if !is_media_entity_v4l2_subdev(entity))
> 
> With these two chunks fixed,
> 
> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> I'm wondering, however, why you replace some occurrences of = 
> MEDIA_ENT_T_DEVNODE with !is_media_entity_v4l2_subdev and some other with 
> is_media_entity_v4l2_io.

For devices that don't have non-V4L2 media controller nodes, this would
work, but if we ever add ALSA, DVB, IIO, etc to the media controller,
then we may have troubles.

That's why I opted to add a macro for checking for the V4L2 subdev.
This is more future-proof, as other patches may be adding other
non-V4L2 types of MC entities have the potential of breaking codes like
the above.

> 
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline
> > *pipe)
> > 
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > 
> > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_subdev(entity))
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > diff --git a/drivers/staging/media/omap4iss/iss.c
> > b/drivers/staging/media/omap4iss/iss.c index 40591963b42b..44b88ff3ba83
> > 100644
> > --- a/drivers/staging/media/omap4iss/iss.c
> > +++ b/drivers/staging/media/omap4iss/iss.c
> > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity
> > *entity) media_entity_graph_walk_start(&graph, entity);
> > 
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) = MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_io(entity))
> >  			use += entity->use_count;
> >  	}
> > 
> > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity
> > *entity, int change) {
> >  	struct v4l2_subdev *subdev;
> > 
> > -	subdev = media_entity_type(entity) = MEDIA_ENT_T_V4L2_SUBDEV
> > +	subdev = is_media_entity_v4l2_subdev(entity)
> >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > 
> >  	if (entity->use_count = 0 && change > 0 && subdev != NULL) {
> > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity
> > *entity, int change) media_entity_graph_walk_start(&graph, entity);
> > 
> >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(entity))
> >  			ret = iss_pipeline_pm_power_one(entity, change);
> > 
> >  	if (!ret)
> > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity
> > *entity, int change)
> > 
> >  	while ((first = media_entity_graph_walk_next(&graph))
> >  	       && first != entity)
> > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(first))
> >  			iss_pipeline_pm_power_one(first, -change);
> > 
> >  	return ret;
> > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline
> > *pipe, break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline
> > *pipe, break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad = NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > diff --git a/drivers/staging/media/omap4iss/iss_video.c
> > b/drivers/staging/media/omap4iss/iss_video.c index
> > 45a3f2d778fc..cbe5783735dc 100644
> > --- a/drivers/staging/media/omap4iss/iss_video.c
> > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32
> > *pad)
> > 
> >  	remote = media_entity_remote_pad(&video->pad);
> > 
> > -	if (remote = NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> > 
> >  	if (pad)
> > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> >  		if (entity = &video->video.entity)
> >  			continue;
> > 
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> > 
> >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-12-08 16:03       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 16:03 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Kukjin Kim, Krzysztof Kozlowski, Hyun Kwon,
	Michal Simek, Sören Brinkmann, Greg Kroah-Hartman,
	Hans Verkuil, Prabhakar Lad, Lars-Peter Clausen, Markus Elfring,
	Sakari Ailus, Javier Martinez Canillas, linux-arm-kernel,
	linux-samsung-soc, linux-sh, devel

Em Sun, 06 Dec 2015 04:16:15 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 30 August 2015 00:06:43 Mauro Carvalho Chehab wrote:
> > Instead of relying on media subtype, use the new macros to detect
> > if an entity is a subdev or an A/V DMA entity.
> > 
> > Please note that most drivers assume that there's just AV_DMA or
> > V4L2 subdevs. This is not true anymore, as we've added MC support
> > for DVB, and there are plans to add support for ALSA and FB/DRM
> > too.
> > 
> > Ok, on the current pipelines supported by those drivers, just V4L
> > stuff are there, but, assuming that some day a pipeline that also
> > works with other subsystems will ever added, it is better to add
> > explicit checks for the AV_DMA stuff.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/platform/exynos4-is/common.c
> > b/drivers/media/platform/exynos4-is/common.c index
> > 0eb34ecb8ee4..8c9a29e0e294 100644
> > --- a/drivers/media/platform/exynos4-is/common.c
> > +++ b/drivers/media/platform/exynos4-is/common.c
> > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct
> > media_entity *entity) while (pad->flags & MEDIA_PAD_FL_SINK) {
> >  		/* source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c
> > b/drivers/media/platform/exynos4-is/fimc-capture.c index
> > 0627a93b2f3b..e9810fee4c30 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev
> > *fimc) }
> >  		}
> > 
> > -		if (src_pad == NULL ||
> > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> >  			break;
> > 
> >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity
> > *entity, struct fimc_vid_cap *vc = &fimc->vid_cap;
> >  	struct v4l2_subdev *sensor;
> > 
> > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> >  		return -EINVAL;
> > 
> >  	if (WARN_ON(fimc == NULL))
> > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > b/drivers/media/platform/exynos4-is/fimc-isp-video.c index
> > 3d9ccbf5f10f..5fbaf5e39903 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp
> > *isp)
> > 
> >  		/* Retrieve format at the source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c
> > b/drivers/media/platform/exynos4-is/fimc-lite.c index
> > b2607da4ad14..c2327147b360 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite
> > *fimc) }
> >  		/* Retrieve format at the source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity
> > *entity, {
> >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> >  	int ret = 0;
> > 
> >  	if (WARN_ON(fimc == NULL))
> > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity
> > *entity,
> > 
> >  	switch (local->index) {
> >  	case FLITE_SD_PAD_SINK:
> > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> >  			ret = -EINVAL;
> >  			break;
> >  		}
> > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity
> > *entity, case FLITE_SD_PAD_SOURCE_DMA:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> > +		else if (is_media_entity_v4l2_io(remote->entity))
> >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> >  		else
> >  			ret = -EINVAL;
> > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity
> > *entity, case FLITE_SD_PAD_SOURCE_ISP:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> >  		else
> >  			ret = -EINVAL;
> > diff --git a/drivers/media/platform/exynos4-is/media-dev.c
> > b/drivers/media/platform/exynos4-is/media-dev.c index
> > 92dbade2fffc..4a25df9dd869 100644
> > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> > break;
> >  		}
> > 
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > 
> > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct
> > media_entity *entity, bool enable) media_entity_graph_walk_start(&graph,
> > entity);
> > 
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> > 
> >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct
> > media_entity *entity, bool enable) media_entity_graph_walk_start(&graph,
> > entity_err);
> > 
> >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity_err))
> >  			continue;
> > 
> >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > diff --git a/drivers/media/platform/omap3isp/isp.c
> > b/drivers/media/platform/omap3isp/isp.c index 69e7733d36cd..cb8ac90086c1
> > 100644
> > --- a/drivers/media/platform/omap3isp/isp.c
> > +++ b/drivers/media/platform/omap3isp/isp.c
> > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity
> > *entity) media_entity_graph_walk_start(&graph, entity);
> > 
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_io(entity))
> >  			use += entity->use_count;
> >  	}
> > 
> > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity
> > *entity, int change) struct v4l2_subdev *subdev;
> >  	int ret;
> > 
> > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > +	subdev = is_media_entity_v4l2_subdev(entity)
> >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > 
> >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity
> > *entity, int change) media_entity_graph_walk_start(&graph, entity);
> > 
> >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(entity))
> >  			ret = isp_pipeline_pm_power_one(entity, change);
> > 
> >  	if (!ret)
> > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity
> > *entity, int change)
> > 
> >  	while ((first = media_entity_graph_walk_next(&graph))
> >  	       && first != entity)
> > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(first))
> >  			isp_pipeline_pm_power_one(first, -change);
> > 
> >  	return ret;
> > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline
> > *pipe, break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline
> > *pipe) break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > diff --git a/drivers/media/platform/omap3isp/ispvideo.c
> > b/drivers/media/platform/omap3isp/ispvideo.c index
> > 4c367352b1f7..52843ac2a9ca 100644
> > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32
> > *pad)
> > 
> >  	remote = media_entity_remote_pad(&video->pad);
> > 
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> > 
> >  	if (pad)
> > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video
> > *video, if (entity == &video->video.entity)
> >  			continue;
> > 
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> > 
> >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct
> > isp_video *video, return -EINVAL;
> >  	}
> > 
> > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!is_media_entity_v4l2_subdev(source))
> >  		return 0;
> > 
> >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c
> > b/drivers/media/platform/s3c-camif/camif-capture.c index
> > eae667eab1b9..fb5b016cc0a1 100644
> > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev
> > *camif)
> > 
> >  	/* Retrieve format at the sensor subdev source pad */
> >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  		return -EPIPE;
> > 
> >  	src_fmt.pad = pad->index;
> > diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> > b/drivers/media/platform/vsp1/vsp1_video.c index 1f94c1a54e00..f74158224b93
> > 100644
> > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32
> > *pad) struct media_pad *remote;
> > 
> >  	remote = media_entity_remote_pad(local);
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> > 
> >  	if (pad)
> > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct
> > vsp1_pipeline *pipe, return -EPIPE;
> > 
> >  		/* We've reached a video node, that shouldn't have happened. */
> > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> >  			return -EPIPE;
> > 
> >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline
> > *pipe, struct vsp1_rwpf *rwpf;
> >  		struct vsp1_entity *e;
> > 
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > +		if (is_media_entity_v4l2_io(entity)) {
> >  			pipe->num_video++;
> >  			continue;
> >  		}
> > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline
> > *pipe, pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> > 
> >  	while (pad) {
> > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c
> > b/drivers/media/platform/xilinx/xilinx-dma.c index
> > 88cd789cdaf7..8e14841bf445 100644
> > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> >  	struct media_pad *remote;
> > 
> >  	remote = media_entity_remote_pad(local);
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> > 
> >  	if (pad)
> > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline
> > *pipe, bool start) break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c
> > b/drivers/media/v4l2-core/v4l2-subdev.c index e6e1115d8215..60da43772de9
> > 100644
> > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > @@ -526,7 +526,7 @@ static int
> >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> >  				     struct v4l2_subdev_format *fmt)
> >  {
> > -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> >  		struct v4l2_subdev *sd =
> >  			media_entity_to_v4l2_subdev(pad->entity);
> > 
> > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > b/drivers/staging/media/davinci_vpfe/vpfe_video.c index
> > 92573fa852a9..16763e0831f2 100644
> > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct
> > vpfe_video_device *video) while ((entity =
> > media_entity_graph_walk_next(&graph))) {
> >  		if (entity == &video->video_dev.entity)
> >  			continue;
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if ((!is_media_entity_v4l2_io(remote->entity))
> >  			continue;
> >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline
> > *pipe) media_entity_graph_walk_start(&graph, entity);
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > 
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if !is_media_entity_v4l2_subdev(entity))
> 
> With these two chunks fixed,
> 
> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> I'm wondering, however, why you replace some occurrences of == 
> MEDIA_ENT_T_DEVNODE with !is_media_entity_v4l2_subdev and some other with 
> is_media_entity_v4l2_io.

For devices that don't have non-V4L2 media controller nodes, this would
work, but if we ever add ALSA, DVB, IIO, etc to the media controller,
then we may have troubles.

That's why I opted to add a macro for checking for the V4L2 subdev.
This is more future-proof, as other patches may be adding other
non-V4L2 types of MC entities have the potential of breaking codes like
the above.

> 
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline
> > *pipe)
> > 
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > 
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_subdev(entity))
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > diff --git a/drivers/staging/media/omap4iss/iss.c
> > b/drivers/staging/media/omap4iss/iss.c index 40591963b42b..44b88ff3ba83
> > 100644
> > --- a/drivers/staging/media/omap4iss/iss.c
> > +++ b/drivers/staging/media/omap4iss/iss.c
> > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity
> > *entity) media_entity_graph_walk_start(&graph, entity);
> > 
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_io(entity))
> >  			use += entity->use_count;
> >  	}
> > 
> > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity
> > *entity, int change) {
> >  	struct v4l2_subdev *subdev;
> > 
> > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > +	subdev = is_media_entity_v4l2_subdev(entity)
> >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > 
> >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity
> > *entity, int change) media_entity_graph_walk_start(&graph, entity);
> > 
> >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(entity))
> >  			ret = iss_pipeline_pm_power_one(entity, change);
> > 
> >  	if (!ret)
> > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity
> > *entity, int change)
> > 
> >  	while ((first = media_entity_graph_walk_next(&graph))
> >  	       && first != entity)
> > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(first))
> >  			iss_pipeline_pm_power_one(first, -change);
> > 
> >  	return ret;
> > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline
> > *pipe, break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline
> > *pipe, break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > diff --git a/drivers/staging/media/omap4iss/iss_video.c
> > b/drivers/staging/media/omap4iss/iss_video.c index
> > 45a3f2d778fc..cbe5783735dc 100644
> > --- a/drivers/staging/media/omap4iss/iss_video.c
> > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32
> > *pad)
> > 
> >  	remote = media_entity_remote_pad(&video->pad);
> > 
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> > 
> >  	if (pad)
> > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> >  		if (entity == &video->video.entity)
> >  			continue;
> > 
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> > 
> >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
@ 2015-12-08 16:03       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 16:03 UTC (permalink / raw)
  To: linux-arm-kernel

Em Sun, 06 Dec 2015 04:16:15 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 30 August 2015 00:06:43 Mauro Carvalho Chehab wrote:
> > Instead of relying on media subtype, use the new macros to detect
> > if an entity is a subdev or an A/V DMA entity.
> > 
> > Please note that most drivers assume that there's just AV_DMA or
> > V4L2 subdevs. This is not true anymore, as we've added MC support
> > for DVB, and there are plans to add support for ALSA and FB/DRM
> > too.
> > 
> > Ok, on the current pipelines supported by those drivers, just V4L
> > stuff are there, but, assuming that some day a pipeline that also
> > works with other subsystems will ever added, it is better to add
> > explicit checks for the AV_DMA stuff.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/platform/exynos4-is/common.c
> > b/drivers/media/platform/exynos4-is/common.c index
> > 0eb34ecb8ee4..8c9a29e0e294 100644
> > --- a/drivers/media/platform/exynos4-is/common.c
> > +++ b/drivers/media/platform/exynos4-is/common.c
> > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct
> > media_entity *entity) while (pad->flags & MEDIA_PAD_FL_SINK) {
> >  		/* source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c
> > b/drivers/media/platform/exynos4-is/fimc-capture.c index
> > 0627a93b2f3b..e9810fee4c30 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev
> > *fimc) }
> >  		}
> > 
> > -		if (src_pad == NULL ||
> > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> >  			break;
> > 
> >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity
> > *entity, struct fimc_vid_cap *vc = &fimc->vid_cap;
> >  	struct v4l2_subdev *sensor;
> > 
> > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> >  		return -EINVAL;
> > 
> >  	if (WARN_ON(fimc == NULL))
> > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > b/drivers/media/platform/exynos4-is/fimc-isp-video.c index
> > 3d9ccbf5f10f..5fbaf5e39903 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp
> > *isp)
> > 
> >  		/* Retrieve format at the source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c
> > b/drivers/media/platform/exynos4-is/fimc-lite.c index
> > b2607da4ad14..c2327147b360 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite
> > *fimc) }
> >  		/* Retrieve format at the source pad */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity
> > *entity, {
> >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> >  	int ret = 0;
> > 
> >  	if (WARN_ON(fimc == NULL))
> > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity
> > *entity,
> > 
> >  	switch (local->index) {
> >  	case FLITE_SD_PAD_SINK:
> > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> >  			ret = -EINVAL;
> >  			break;
> >  		}
> > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity
> > *entity, case FLITE_SD_PAD_SOURCE_DMA:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> > +		else if (is_media_entity_v4l2_io(remote->entity))
> >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> >  		else
> >  			ret = -EINVAL;
> > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity
> > *entity, case FLITE_SD_PAD_SOURCE_ISP:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> >  		else
> >  			ret = -EINVAL;
> > diff --git a/drivers/media/platform/exynos4-is/media-dev.c
> > b/drivers/media/platform/exynos4-is/media-dev.c index
> > 92dbade2fffc..4a25df9dd869 100644
> > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> > break;
> >  		}
> > 
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > 
> > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct
> > media_entity *entity, bool enable) media_entity_graph_walk_start(&graph,
> > entity);
> > 
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> > 
> >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct
> > media_entity *entity, bool enable) media_entity_graph_walk_start(&graph,
> > entity_err);
> > 
> >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity_err))
> >  			continue;
> > 
> >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > diff --git a/drivers/media/platform/omap3isp/isp.c
> > b/drivers/media/platform/omap3isp/isp.c index 69e7733d36cd..cb8ac90086c1
> > 100644
> > --- a/drivers/media/platform/omap3isp/isp.c
> > +++ b/drivers/media/platform/omap3isp/isp.c
> > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity
> > *entity) media_entity_graph_walk_start(&graph, entity);
> > 
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_io(entity))
> >  			use += entity->use_count;
> >  	}
> > 
> > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity
> > *entity, int change) struct v4l2_subdev *subdev;
> >  	int ret;
> > 
> > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > +	subdev = is_media_entity_v4l2_subdev(entity)
> >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > 
> >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity
> > *entity, int change) media_entity_graph_walk_start(&graph, entity);
> > 
> >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(entity))
> >  			ret = isp_pipeline_pm_power_one(entity, change);
> > 
> >  	if (!ret)
> > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity
> > *entity, int change)
> > 
> >  	while ((first = media_entity_graph_walk_next(&graph))
> >  	       && first != entity)
> > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(first))
> >  			isp_pipeline_pm_power_one(first, -change);
> > 
> >  	return ret;
> > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline
> > *pipe, break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline
> > *pipe) break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > diff --git a/drivers/media/platform/omap3isp/ispvideo.c
> > b/drivers/media/platform/omap3isp/ispvideo.c index
> > 4c367352b1f7..52843ac2a9ca 100644
> > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32
> > *pad)
> > 
> >  	remote = media_entity_remote_pad(&video->pad);
> > 
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> > 
> >  	if (pad)
> > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video
> > *video, if (entity == &video->video.entity)
> >  			continue;
> > 
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> > 
> >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct
> > isp_video *video, return -EINVAL;
> >  	}
> > 
> > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!is_media_entity_v4l2_subdev(source))
> >  		return 0;
> > 
> >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c
> > b/drivers/media/platform/s3c-camif/camif-capture.c index
> > eae667eab1b9..fb5b016cc0a1 100644
> > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev
> > *camif)
> > 
> >  	/* Retrieve format at the sensor subdev source pad */
> >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  		return -EPIPE;
> > 
> >  	src_fmt.pad = pad->index;
> > diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> > b/drivers/media/platform/vsp1/vsp1_video.c index 1f94c1a54e00..f74158224b93
> > 100644
> > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32
> > *pad) struct media_pad *remote;
> > 
> >  	remote = media_entity_remote_pad(local);
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> > 
> >  	if (pad)
> > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct
> > vsp1_pipeline *pipe, return -EPIPE;
> > 
> >  		/* We've reached a video node, that shouldn't have happened. */
> > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> >  			return -EPIPE;
> > 
> >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline
> > *pipe, struct vsp1_rwpf *rwpf;
> >  		struct vsp1_entity *e;
> > 
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > +		if (is_media_entity_v4l2_io(entity)) {
> >  			pipe->num_video++;
> >  			continue;
> >  		}
> > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline
> > *pipe, pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> > 
> >  	while (pad) {
> > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c
> > b/drivers/media/platform/xilinx/xilinx-dma.c index
> > 88cd789cdaf7..8e14841bf445 100644
> > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> >  	struct media_pad *remote;
> > 
> >  	remote = media_entity_remote_pad(local);
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> > 
> >  	if (pad)
> > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline
> > *pipe, bool start) break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c
> > b/drivers/media/v4l2-core/v4l2-subdev.c index e6e1115d8215..60da43772de9
> > 100644
> > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > @@ -526,7 +526,7 @@ static int
> >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> >  				     struct v4l2_subdev_format *fmt)
> >  {
> > -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> >  		struct v4l2_subdev *sd =
> >  			media_entity_to_v4l2_subdev(pad->entity);
> > 
> > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > b/drivers/staging/media/davinci_vpfe/vpfe_video.c index
> > 92573fa852a9..16763e0831f2 100644
> > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct
> > vpfe_video_device *video) while ((entity =
> > media_entity_graph_walk_next(&graph))) {
> >  		if (entity == &video->video_dev.entity)
> >  			continue;
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if ((!is_media_entity_v4l2_io(remote->entity))
> >  			continue;
> >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline
> > *pipe) media_entity_graph_walk_start(&graph, entity);
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > 
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if !is_media_entity_v4l2_subdev(entity))
> 
> With these two chunks fixed,
> 
> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> I'm wondering, however, why you replace some occurrences of == 
> MEDIA_ENT_T_DEVNODE with !is_media_entity_v4l2_subdev and some other with 
> is_media_entity_v4l2_io.

For devices that don't have non-V4L2 media controller nodes, this would
work, but if we ever add ALSA, DVB, IIO, etc to the media controller,
then we may have troubles.

That's why I opted to add a macro for checking for the V4L2 subdev.
This is more future-proof, as other patches may be adding other
non-V4L2 types of MC entities have the potential of breaking codes like
the above.

> 
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline
> > *pipe)
> > 
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > 
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_subdev(entity))
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > diff --git a/drivers/staging/media/omap4iss/iss.c
> > b/drivers/staging/media/omap4iss/iss.c index 40591963b42b..44b88ff3ba83
> > 100644
> > --- a/drivers/staging/media/omap4iss/iss.c
> > +++ b/drivers/staging/media/omap4iss/iss.c
> > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity
> > *entity) media_entity_graph_walk_start(&graph, entity);
> > 
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_io(entity))
> >  			use += entity->use_count;
> >  	}
> > 
> > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity
> > *entity, int change) {
> >  	struct v4l2_subdev *subdev;
> > 
> > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > +	subdev = is_media_entity_v4l2_subdev(entity)
> >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > 
> >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity
> > *entity, int change) media_entity_graph_walk_start(&graph, entity);
> > 
> >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(entity))
> >  			ret = iss_pipeline_pm_power_one(entity, change);
> > 
> >  	if (!ret)
> > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity
> > *entity, int change)
> > 
> >  	while ((first = media_entity_graph_walk_next(&graph))
> >  	       && first != entity)
> > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > +		if (is_media_entity_v4l2_subdev(first))
> >  			iss_pipeline_pm_power_one(first, -change);
> > 
> >  	return ret;
> > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline
> > *pipe, break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline
> > *pipe, break;
> > 
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		entity = pad->entity;
> > diff --git a/drivers/staging/media/omap4iss/iss_video.c
> > b/drivers/staging/media/omap4iss/iss_video.c index
> > 45a3f2d778fc..cbe5783735dc 100644
> > --- a/drivers/staging/media/omap4iss/iss_video.c
> > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32
> > *pad)
> > 
> >  	remote = media_entity_remote_pad(&video->pad);
> > 
> > -	if (remote == NULL ||
> > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> > 
> >  	if (pad)
> > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> >  		if (entity == &video->video.entity)
> >  			continue;
> > 
> > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> > 
> >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 33/55] [media] omap3/omap4/davinci: get rid of MEDIA_ENT_T_V4L2_SUBDEV abuse
  2015-12-06  2:08   ` Laurent Pinchart
@ 2015-12-08 16:52     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 16:52 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Hans Verkuil, Sakari Ailus, Prabhakar Lad,
	Haneen Mohammed, Tapasweni Pathak, Boris BREZILLON,
	Mahati Chamarthy, Javier Martinez Canillas, devel

Em Sun, 06 Dec 2015 04:08:17 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 30 August 2015 00:06:44 Mauro Carvalho Chehab wrote:
> > On omap3/omap4/davinci drivers, MEDIA_ENT_T_V4L2_SUBDEV macro is
> > abused in order to "simplify" the pad checks.
> 
> As explained in a couple of other replies to similar patches, it's not a hack 
> :-)

That's actually the first reply (at least looking at the patches
order ;)

This is a hack, since it mixes a global subdev type with a private
PAD type, defined only inside the driver, on switch cases like:
	CCDC_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:

That implicitly consider that:
	local->index | media_entity_type(remote->entity)

will be a number where the local->index bits will never ever be
used by media_entity_type() return macro.

With such assumption, any change at the numberspace returned by
media_entity_type() would break the driver, and people changing
the core won't even be noticing it, as this is a driver-specific thing.

There's absolute nothing inside the core, even before this patchset
that would warrant that the bits used by local->index (CCDC_PAD_SINK 
and CCDC_PAD_SOURCE) won't be used on media_entity_type() return
value.

So, for me this is a hack, and a dangerous one, because it adds
hidden namespace coupling inside the driver that would break if the
core changes.

> 
> > Basically, it does a logical or of this macro, in order to check
> > for a local index and if the entity is either a subdev or not.
> > 
> > As we'll get rid of MEDIA_ENT_T_V4L2_SUBDEV macro,
> 
> This is the reason for this patch, and I agree with it.
> 
> > replace it by 2 << 16 where it occurs, and add a note saying that the code
> > there is actually a hack.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/platform/omap3isp/ispccdc.c
> > b/drivers/media/platform/omap3isp/ispccdc.c index
> > 9a811f5741fa..f0e530c98188 100644
> > --- a/drivers/media/platform/omap3isp/ispccdc.c
> > +++ b/drivers/media/platform/omap3isp/ispccdc.c
> > @@ -2513,9 +2513,14 @@ static int ccdc_link_setup(struct media_entity
> > *entity, struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
> >  	struct isp_device *isp = to_isp_device(ccdc);
> > +	int index = local->index;
> 
> The index can never be negative, you can use unsigned int.

Ok. Will address on a later patch.
> 
> > 
> > -	switch (local->index | media_entity_type(remote->entity)) {
> > -	case CCDC_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	/* FIXME: this is actually a hack! */
> 
> Please, let's not introduce a hack to replace valid code. I'm certainly fine 
> with removing usage of MEDIA_ENT_T_V4L2_SUBDEV, but drivers should be modified 
> cleanly.

I just preserved the existing hack, by replacing MEDIA_ENT_T_V4L2_SUBDEV macro
that will be removed by its value (2 << 16).

> If you rename the index variable to link and use a macro (I would call it 
> LINK_TO_SUBDEV for instance) instead of 2 << 16 the implementation wouldn't be 
> that bad, as what the switch operates on is the link, not the pad. I would 
> also create a LINK_TO_DEVNODE macro, even if it evaluates to 0, to clearly 
> label each case.

Sorry but I didn't follow you here. Could you please send us a patch
or a code example explaining what you're meaning?

> 
> > +	if (is_media_entity_v4l2_subdev(remote->entity))
> > +		index |= 2 << 16;
> 
> Why 2 << 16 and not 1 << 16 ?

Because that's the value of MEDIA_ENT_T_V4L2_SUBDEV. This is a hack:
any value here is just a magic number with no physical meaning.

Using 1 << 16 would be as good or as bad as 2 << 16.

> Same comments for all the other files below (but please see the very end for 
> one last comment).
> 
> > +	switch (index) {
> > +	case CCDC_PAD_SINK | 2 << 16:
> >  		/* Read from the sensor (parallel interface), CCP2, CSI2a or
> >  		 * CSI2c.
> >  		 */
> > @@ -2543,7 +2548,7 @@ static int ccdc_link_setup(struct media_entity
> > *entity, * Revisit this when it will be implemented, and return -EBUSY for
> > now. */
> > 
> > -	case CCDC_PAD_SOURCE_VP | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case CCDC_PAD_SOURCE_VP | 2 << 16:
> >  		/* Write to preview engine, histogram and H3A. When none of
> >  		 * those links are active, the video port can be disabled.
> >  		 */
> > @@ -2556,7 +2561,7 @@ static int ccdc_link_setup(struct media_entity
> > *entity, }
> >  		break;
> > 
> > -	case CCDC_PAD_SOURCE_OF | MEDIA_ENT_T_DEVNODE:
> > +	case CCDC_PAD_SOURCE_OF:
> >  		/* Write to memory */
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (ccdc->output & ~CCDC_OUTPUT_MEMORY)
> > @@ -2567,7 +2572,7 @@ static int ccdc_link_setup(struct media_entity
> > *entity, }
> >  		break;
> > 
> > -	case CCDC_PAD_SOURCE_OF | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case CCDC_PAD_SOURCE_OF | 2 << 16:
> >  		/* Write to resizer */
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (ccdc->output & ~CCDC_OUTPUT_RESIZER)
> > diff --git a/drivers/media/platform/omap3isp/ispccp2.c
> > b/drivers/media/platform/omap3isp/ispccp2.c index
> > 6ec7d104ab75..ae3038e643cc 100644
> > --- a/drivers/media/platform/omap3isp/ispccp2.c
> > +++ b/drivers/media/platform/omap3isp/ispccp2.c
> > @@ -956,9 +956,14 @@ static int ccp2_link_setup(struct media_entity *entity,
> > {
> >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct isp_ccp2_device *ccp2 = v4l2_get_subdevdata(sd);
> > +	int index = local->index;
> > 
> > -	switch (local->index | media_entity_type(remote->entity)) {
> > -	case CCP2_PAD_SINK | MEDIA_ENT_T_DEVNODE:
> > +	/* FIXME: this is actually a hack! */
> > +	if (is_media_entity_v4l2_subdev(remote->entity))
> > +		index |= 2 << 16;
> > +
> > +	switch (index) {
> > +	case CCP2_PAD_SINK:
> >  		/* read from memory */
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (ccp2->input == CCP2_INPUT_SENSOR)
> > @@ -970,7 +975,7 @@ static int ccp2_link_setup(struct media_entity *entity,
> >  		}
> >  		break;
> > 
> > -	case CCP2_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case CCP2_PAD_SINK | 2 << 16:
> >  		/* read from sensor/phy */
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (ccp2->input == CCP2_INPUT_MEMORY)
> > @@ -981,7 +986,7 @@ static int ccp2_link_setup(struct media_entity *entity,
> >  				ccp2->input = CCP2_INPUT_NONE;
> >  		} break;
> > 
> > -	case CCP2_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case CCP2_PAD_SOURCE | 2 << 16:
> >  		/* write to video port/ccdc */
> >  		if (flags & MEDIA_LNK_FL_ENABLED)
> >  			ccp2->output = CCP2_OUTPUT_CCDC;
> > diff --git a/drivers/media/platform/omap3isp/ispcsi2.c
> > b/drivers/media/platform/omap3isp/ispcsi2.c index
> > 0fb057a74f69..b1617f7efdee 100644
> > --- a/drivers/media/platform/omap3isp/ispcsi2.c
> > +++ b/drivers/media/platform/omap3isp/ispcsi2.c
> > @@ -1144,14 +1144,19 @@ static int csi2_link_setup(struct media_entity
> > *entity, struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct isp_csi2_device *csi2 = v4l2_get_subdevdata(sd);
> >  	struct isp_csi2_ctrl_cfg *ctrl = &csi2->ctrl;
> > +	int index = local->index;
> > 
> >  	/*
> >  	 * The ISP core doesn't support pipelines with multiple video outputs.
> >  	 * Revisit this when it will be implemented, and return -EBUSY for now.
> >  	 */
> > 
> > -	switch (local->index | media_entity_type(remote->entity)) {
> > -	case CSI2_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
> > +	/* FIXME: this is actually a hack! */
> > +	if (is_media_entity_v4l2_subdev(remote->entity))
> > +		index |= 2 << 16;
> > +
> > +	switch (index) {
> > +	case CSI2_PAD_SOURCE:
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (csi2->output & ~CSI2_OUTPUT_MEMORY)
> >  				return -EBUSY;
> > @@ -1161,7 +1166,7 @@ static int csi2_link_setup(struct media_entity
> > *entity, }
> >  		break;
> > 
> > -	case CSI2_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case CSI2_PAD_SOURCE | 2 << 16:
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (csi2->output & ~CSI2_OUTPUT_CCDC)
> >  				return -EBUSY;
> > diff --git a/drivers/media/platform/omap3isp/isppreview.c
> > b/drivers/media/platform/omap3isp/isppreview.c index
> > 6986d2f65c19..cfb2debb02bf 100644
> > --- a/drivers/media/platform/omap3isp/isppreview.c
> > +++ b/drivers/media/platform/omap3isp/isppreview.c
> > @@ -2144,9 +2144,14 @@ static int preview_link_setup(struct media_entity
> > *entity, {
> >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
> > +	int index = local->index;
> > 
> > -	switch (local->index | media_entity_type(remote->entity)) {
> > -	case PREV_PAD_SINK | MEDIA_ENT_T_DEVNODE:
> > +	/* FIXME: this is actually a hack! */
> > +	if (is_media_entity_v4l2_subdev(remote->entity))
> > +		index |= 2 << 16;
> > +
> > +	switch (index) {
> > +	case PREV_PAD_SINK:
> >  		/* read from memory */
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (prev->input == PREVIEW_INPUT_CCDC)
> > @@ -2158,7 +2163,7 @@ static int preview_link_setup(struct media_entity
> > *entity, }
> >  		break;
> > 
> > -	case PREV_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case PREV_PAD_SINK | 2 << 16:
> >  		/* read from ccdc */
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (prev->input == PREVIEW_INPUT_MEMORY)
> > @@ -2175,7 +2180,7 @@ static int preview_link_setup(struct media_entity
> > *entity, * Revisit this when it will be implemented, and return -EBUSY for
> > now. */
> > 
> > -	case PREV_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
> > +	case PREV_PAD_SOURCE:
> >  		/* write to memory */
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (prev->output & ~PREVIEW_OUTPUT_MEMORY)
> > @@ -2186,7 +2191,7 @@ static int preview_link_setup(struct media_entity
> > *entity, }
> >  		break;
> > 
> > -	case PREV_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case PREV_PAD_SOURCE | 2 << 16:
> >  		/* write to resizer */
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (prev->output & ~PREVIEW_OUTPUT_RESIZER)
> > diff --git a/drivers/media/platform/omap3isp/ispresizer.c
> > b/drivers/media/platform/omap3isp/ispresizer.c index
> > 249af7f524f9..e3ecf1787fc4 100644
> > --- a/drivers/media/platform/omap3isp/ispresizer.c
> > +++ b/drivers/media/platform/omap3isp/ispresizer.c
> > @@ -1623,9 +1623,14 @@ static int resizer_link_setup(struct media_entity
> > *entity, {
> >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct isp_res_device *res = v4l2_get_subdevdata(sd);
> > +	int index = local->index;
> > 
> > -	switch (local->index | media_entity_type(remote->entity)) {
> > -	case RESZ_PAD_SINK | MEDIA_ENT_T_DEVNODE:
> > +	/* FIXME: this is actually a hack! */
> > +	if (is_media_entity_v4l2_subdev(remote->entity))
> > +		index |= 2 << 16;
> > +
> > +	switch (index) {
> > +	case RESZ_PAD_SINK:
> >  		/* read from memory */
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (res->input == RESIZER_INPUT_VP)
> > @@ -1637,7 +1642,7 @@ static int resizer_link_setup(struct media_entity
> > *entity, }
> >  		break;
> > 
> > -	case RESZ_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case RESZ_PAD_SINK | 2 << 16:
> >  		/* read from ccdc or previewer */
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (res->input == RESIZER_INPUT_MEMORY)
> > @@ -1649,7 +1654,7 @@ static int resizer_link_setup(struct media_entity
> > *entity, }
> >  		break;
> > 
> > -	case RESZ_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
> > +	case RESZ_PAD_SOURCE:
> >  		/* resizer always write to memory */
> >  		break;
> > 
> > diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
> > b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c index
> > d96bdaaae50e..b66584ecb693 100644
> > --- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
> > +++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
> > @@ -885,9 +885,14 @@ ipipeif_link_setup(struct media_entity *entity, const
> > struct media_pad *local, struct v4l2_subdev *sd =
> > media_entity_to_v4l2_subdev(entity);
> >  	struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
> >  	struct vpfe_device *vpfe = to_vpfe_device(ipipeif);
> > +	int index = local->index;
> > 
> > -	switch (local->index | media_entity_type(remote->entity)) {
> > -	case IPIPEIF_PAD_SINK | MEDIA_ENT_T_DEVNODE:
> > +	/* FIXME: this is actually a hack! */
> > +	if (is_media_entity_v4l2_subdev(remote->entity))
> > +		index |= 2 << 16;
> > +
> > +	switch (index) {
> > +	case IPIPEIF_PAD_SINK:
> >  		/* Single shot mode */
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  			ipipeif->input = IPIPEIF_INPUT_NONE;
> > @@ -896,7 +901,7 @@ ipipeif_link_setup(struct media_entity *entity, const
> > struct media_pad *local, ipipeif->input = IPIPEIF_INPUT_MEMORY;
> >  		break;
> > 
> > -	case IPIPEIF_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case IPIPEIF_PAD_SINK | 2 << 16:
> >  		/* read from isif */
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  			ipipeif->input = IPIPEIF_INPUT_NONE;
> > @@ -908,7 +913,7 @@ ipipeif_link_setup(struct media_entity *entity, const
> > struct media_pad *local, ipipeif->input = IPIPEIF_INPUT_ISIF;
> >  		break;
> > 
> > -	case IPIPEIF_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case IPIPEIF_PAD_SOURCE | 2 << 16:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  			ipipeif->output = IPIPEIF_OUTPUT_NONE;
> >  			break;
> > diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c
> > b/drivers/staging/media/davinci_vpfe/dm365_isif.c index
> > df77288b0ec0..8ca0c1297ec8 100644
> > --- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
> > +++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
> > @@ -1707,9 +1707,14 @@ isif_link_setup(struct media_entity *entity, const
> > struct media_pad *local, {
> >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
> > +	int index = local->index;
> > 
> > -	switch (local->index | media_entity_type(remote->entity)) {
> > -	case ISIF_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	/* FIXME: this is actually a hack! */
> > +	if (is_media_entity_v4l2_subdev(remote->entity))
> > +		index |= 2 << 16;
> > +
> > +	switch (index) {
> > +	case ISIF_PAD_SINK | 2 << 16:
> >  		/* read from decoder/sensor */
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  			isif->input = ISIF_INPUT_NONE;
> > @@ -1720,7 +1725,7 @@ isif_link_setup(struct media_entity *entity, const
> > struct media_pad *local, isif->input = ISIF_INPUT_PARALLEL;
> >  		break;
> > 
> > -	case ISIF_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
> > +	case ISIF_PAD_SOURCE:
> >  		/* write to memory */
> >  		if (flags & MEDIA_LNK_FL_ENABLED)
> >  			isif->output = ISIF_OUTPUT_MEMORY;
> > @@ -1728,7 +1733,7 @@ isif_link_setup(struct media_entity *entity, const
> > struct media_pad *local, isif->output = ISIF_OUTPUT_NONE;
> >  		break;
> > 
> > -	case ISIF_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case ISIF_PAD_SOURCE | 2 << 16:
> >  		if (flags & MEDIA_LNK_FL_ENABLED)
> >  			isif->output = ISIF_OUTPUT_IPIPEIF;
> >  		else
> > diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
> > b/drivers/staging/media/davinci_vpfe/dm365_resizer.c index
> > ae942de3a23d..8eb6f5fda21c 100644
> > --- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
> > +++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
> > @@ -1653,10 +1653,15 @@ static int resizer_link_setup(struct media_entity
> > *entity, struct vpfe_device *vpfe_dev = to_vpfe_device(resizer);
> >  	u16 ipipeif_source = vpfe_dev->vpfe_ipipeif.output;
> >  	u16 ipipe_source = vpfe_dev->vpfe_ipipe.output;
> > +	int index = local->index;
> > +
> > +	/* FIXME: this is actually a hack! */
> > +	if (is_media_entity_v4l2_subdev(remote->entity))
> > +		index |= 2 << 16;
> > 
> >  	if (&resizer->crop_resizer.subdev == sd) {
> > -		switch (local->index | media_entity_type(remote->entity)) {
> > -		case RESIZER_CROP_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> > +		switch (index) {
> > +		case RESIZER_CROP_PAD_SINK | 2 << 16:
> >  			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  				resizer->crop_resizer.input =
> >  					RESIZER_CROP_INPUT_NONE;
> > @@ -1676,7 +1681,7 @@ static int resizer_link_setup(struct media_entity
> > *entity, return -EINVAL;
> >  			break;
> > 
> > -		case RESIZER_CROP_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> > +		case RESIZER_CROP_PAD_SOURCE | 2 << 16:
> >  			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  				resizer->crop_resizer.output =
> >  				RESIZER_CROP_OUTPUT_NONE;
> > @@ -1688,7 +1693,7 @@ static int resizer_link_setup(struct media_entity
> > *entity, resizer->crop_resizer.output = RESIZER_A;
> >  			break;
> > 
> > -		case RESIZER_CROP_PAD_SOURCE2 | MEDIA_ENT_T_V4L2_SUBDEV:
> > +		case RESIZER_CROP_PAD_SOURCE2 | 2 << 16:
> >  			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  				resizer->crop_resizer.output2 =
> >  					RESIZER_CROP_OUTPUT_NONE;
> > @@ -1704,8 +1709,8 @@ static int resizer_link_setup(struct media_entity
> > *entity, return -EINVAL;
> >  		}
> >  	} else if (&resizer->resizer_a.subdev == sd) {
> > -		switch (local->index | media_entity_type(remote->entity)) {
> > -		case RESIZER_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> > +		switch (index) {
> > +		case RESIZER_PAD_SINK | 2 << 16:
> >  			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  				resizer->resizer_a.input = RESIZER_INPUT_NONE;
> >  				break;
> > @@ -1715,7 +1720,7 @@ static int resizer_link_setup(struct media_entity
> > *entity, resizer->resizer_a.input = RESIZER_INPUT_CROP_RESIZER;
> >  			break;
> > 
> > -		case RESIZER_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
> > +		case RESIZER_PAD_SOURCE:
> >  			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  				resizer->resizer_a.output = RESIZER_OUTPUT_NONE;
> >  				break;
> > @@ -1729,8 +1734,8 @@ static int resizer_link_setup(struct media_entity
> > *entity, return -EINVAL;
> >  		}
> >  	} else if (&resizer->resizer_b.subdev == sd) {
> > -		switch (local->index | media_entity_type(remote->entity)) {
> > -		case RESIZER_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> > +		switch (index) {
> > +		case RESIZER_PAD_SINK | 2 << 16:
> >  			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  				resizer->resizer_b.input = RESIZER_INPUT_NONE;
> >  				break;
> > @@ -1740,7 +1745,7 @@ static int resizer_link_setup(struct media_entity
> > *entity, resizer->resizer_b.input = RESIZER_INPUT_CROP_RESIZER;
> >  			break;
> > 
> > -		case RESIZER_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
> > +		case RESIZER_PAD_SOURCE:
> >  			if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  				resizer->resizer_b.output = RESIZER_OUTPUT_NONE;
> >  				break;
> > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > b/drivers/staging/media/davinci_vpfe/vpfe_video.c index
> > 16763e0831f2..9eef64e0f0ab 100644
> > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct
> > vpfe_video_device *video) while ((entity =
> > media_entity_graph_walk_next(&graph))) {
> >  		if (entity == &video->video_dev.entity)
> >  			continue;
> > -		if ((!is_media_entity_v4l2_io(remote->entity))
> > +		if (!is_media_entity_v4l2_io(entity))
> >  			continue;
> >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline
> > *pipe) media_entity_graph_walk_start(&graph, entity);
> >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > 
> > -		if !is_media_entity_v4l2_subdev(entity))
> > +		if (!is_media_entity_v4l2_subdev(entity))
> >  			continue;
> >  		subdev = media_entity_to_v4l2_subdev(entity);
> >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > diff --git a/drivers/staging/media/omap4iss/iss_csi2.c
> > b/drivers/staging/media/omap4iss/iss_csi2.c index
> > 6b4dcbfa9425..50a24e8e8129 100644
> > --- a/drivers/staging/media/omap4iss/iss_csi2.c
> > +++ b/drivers/staging/media/omap4iss/iss_csi2.c
> > @@ -1170,14 +1170,19 @@ static int csi2_link_setup(struct media_entity
> > *entity, struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct iss_csi2_device *csi2 = v4l2_get_subdevdata(sd);
> >  	struct iss_csi2_ctrl_cfg *ctrl = &csi2->ctrl;
> > +	int index = local->index;
> > +
> > +	/* FIXME: this is actually a hack! */
> > +	if (is_media_entity_v4l2_subdev(remote->entity))
> > +		index |= 2 << 16;
> > 
> >  	/*
> >  	 * The ISS core doesn't support pipelines with multiple video outputs.
> >  	 * Revisit this when it will be implemented, and return -EBUSY for now.
> >  	 */
> > 
> > -	switch (local->index | media_entity_type(remote->entity)) {
> > -	case CSI2_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
> > +	switch (index) {
> > +	case CSI2_PAD_SOURCE:
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (csi2->output & ~CSI2_OUTPUT_MEMORY)
> >  				return -EBUSY;
> > @@ -1187,7 +1192,7 @@ static int csi2_link_setup(struct media_entity
> > *entity, }
> >  		break;
> > 
> > -	case CSI2_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case CSI2_PAD_SOURCE | 2 << 16:
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (csi2->output & ~CSI2_OUTPUT_IPIPEIF)
> >  				return -EBUSY;
> > diff --git a/drivers/staging/media/omap4iss/iss_ipipeif.c
> > b/drivers/staging/media/omap4iss/iss_ipipeif.c index
> > 44c432ef2ac5..e46b2c07bd5d 100644
> > --- a/drivers/staging/media/omap4iss/iss_ipipeif.c
> > +++ b/drivers/staging/media/omap4iss/iss_ipipeif.c
> > @@ -662,9 +662,14 @@ static int ipipeif_link_setup(struct media_entity
> > *entity, struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct iss_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
> >  	struct iss_device *iss = to_iss_device(ipipeif);
> > +	int index = local->index;
> > 
> > -	switch (local->index | media_entity_type(remote->entity)) {
> > -	case IPIPEIF_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	/* FIXME: this is actually a hack! */
> > +	if (is_media_entity_v4l2_subdev(remote->entity))
> > +		index |= 2 << 16;
> > +
> > +	switch (index) {
> > +	case IPIPEIF_PAD_SINK | 2 << 16:
> >  		/* Read from the sensor CSI2a or CSI2b. */
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  			ipipeif->input = IPIPEIF_INPUT_NONE;
> > @@ -681,7 +686,7 @@ static int ipipeif_link_setup(struct media_entity
> > *entity,
> > 
> >  		break;
> > 
> > -	case IPIPEIF_PAD_SOURCE_ISIF_SF | MEDIA_ENT_T_DEVNODE:
> > +	case IPIPEIF_PAD_SOURCE_ISIF_SF:
> >  		/* Write to memory */
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (ipipeif->output & ~IPIPEIF_OUTPUT_MEMORY)
> > @@ -692,7 +697,7 @@ static int ipipeif_link_setup(struct media_entity
> > *entity, }
> >  		break;
> > 
> > -	case IPIPEIF_PAD_SOURCE_VP | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case IPIPEIF_PAD_SOURCE_VP | 2 << 16:
> >  		/* Send to IPIPE/RESIZER */
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (ipipeif->output & ~IPIPEIF_OUTPUT_VP)
> > diff --git a/drivers/staging/media/omap4iss/iss_resizer.c
> > b/drivers/staging/media/omap4iss/iss_resizer.c index
> > b659e465cb56..bc5001002cc5 100644
> > --- a/drivers/staging/media/omap4iss/iss_resizer.c
> > +++ b/drivers/staging/media/omap4iss/iss_resizer.c
> > @@ -717,9 +717,14 @@ static int resizer_link_setup(struct media_entity
> > *entity, struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> >  	struct iss_resizer_device *resizer = v4l2_get_subdevdata(sd);
> >  	struct iss_device *iss = to_iss_device(resizer);
> > +	int index = local->index;
> > 
> > -	switch (local->index | media_entity_type(remote->entity)) {
> > -	case RESIZER_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	/* FIXME: this is actually a hack! */
> > +	if (is_media_entity_v4l2_subdev(remote->entity))
> > +		index |= 2 << 16;
> > +
> > +	switch (index) {
> > +	case RESIZER_PAD_SINK | 2 << 16:
> >  		/* Read from IPIPE or IPIPEIF. */
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  			resizer->input = RESIZER_INPUT_NONE;
> > @@ -737,7 +742,7 @@ static int resizer_link_setup(struct media_entity
> > *entity,
> > 
> >  		break;
> > 
> > -	case RESIZER_PAD_SOURCE_MEM | MEDIA_ENT_T_DEVNODE:
> > +	case RESIZER_PAD_SOURCE_MEM :
> 
> There's an unneeded space before the :.

That change is simple enough and very likely won't cause any rebasing
conflict or context changes, so, fixed.

> 
> >  		/* Write to memory */
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (resizer->output & ~RESIZER_OUTPUT_MEMORY)
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
  2015-12-08 15:57         ` Mauro Carvalho Chehab
@ 2015-12-08 17:05           ` Mauro Carvalho Chehab
  2015-12-08 17:08             ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 17:05 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Linux Media Mailing List, Laurent Pinchart, Hans Verkuil,
	Sakari Ailus, Javier Martinez Canillas

Em Tue, 8 Dec 2015 13:57:55 -0200
Mauro Carvalho Chehab <mchehab@osg.samsung.com> escreveu:

> Em Mon, 12 Oct 2015 18:35:05 +0300
> Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> 
> > Hi Mauro,
> > 
> > On Sun, Oct 11, 2015 at 09:56:25PM -0300, Mauro Carvalho Chehab wrote:
> > > Em Mon, 12 Oct 2015 00:07:52 +0300
> > > Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> > > 
> > > > Hi Mauro,
> > > > 
> > > > On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > > > > Instead of relying on media subtype, use the new macros to detect
> > > > > if an entity is a subdev or an A/V DMA entity.
> > > > > 
> > > > > Please note that most drivers assume that there's just AV_DMA or
> > > > > V4L2 subdevs. This is not true anymore, as we've added MC support
> > > > > for DVB, and there are plans to add support for ALSA and FB/DRM
> > > > > too.
> > > > > 
> > > > > Ok, on the current pipelines supported by those drivers, just V4L
> > > > > stuff are there, but, assuming that some day a pipeline that also
> > > > > works with other subsystems will ever added, it is better to add
> > > > > explicit checks for the AV_DMA stuff.
> > > > > 
> > > > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > > > 
> > > > > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > > > > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > > > > --- a/drivers/media/platform/exynos4-is/common.c
> > > > > +++ b/drivers/media/platform/exynos4-is/common.c
> > > > > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> > > > >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> > > > >  		/* source pad */
> > > > >  		pad = media_entity_remote_pad(pad);
> > > > > -		if (pad == NULL ||
> > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > >  			break;
> > > > >  
> > > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > > index 0627a93b2f3b..e9810fee4c30 100644
> > > > > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> > > > >  			}
> > > > >  		}
> > > > >  
> > > > > -		if (src_pad == NULL ||
> > > > > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> > > > >  			break;
> > > > >  
> > > > >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > > > > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> > > > >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> > > > >  	struct v4l2_subdev *sensor;
> > > > >  
> > > > > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> > > > >  		return -EINVAL;
> > > > >  
> > > > >  	if (WARN_ON(fimc == NULL))
> > > > > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > > > > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> > > > >  
> > > > >  		/* Retrieve format at the source pad */
> > > > >  		pad = media_entity_remote_pad(pad);
> > > > > -		if (pad == NULL ||
> > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > >  			break;
> > > > >  
> > > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > > index b2607da4ad14..c2327147b360 100644
> > > > > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> > > > >  		}
> > > > >  		/* Retrieve format at the source pad */
> > > > >  		pad = media_entity_remote_pad(pad);
> > > > > -		if (pad == NULL ||
> > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > >  			break;
> > > > >  
> > > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > > >  {
> > > > >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> > > > >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > > > > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> > > > >  	int ret = 0;
> > > > >  
> > > > >  	if (WARN_ON(fimc == NULL))
> > > > > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > > >  
> > > > >  	switch (local->index) {
> > > > >  	case FLITE_SD_PAD_SINK:
> > > > > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> > > > >  			ret = -EINVAL;
> > > > >  			break;
> > > > >  		}
> > > > > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > > >  	case FLITE_SD_PAD_SOURCE_DMA:
> > > > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > > > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > > > -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> > > > > +		else if (is_media_entity_v4l2_io(remote->entity))
> > > > >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> > > > >  		else
> > > > >  			ret = -EINVAL;
> > > > > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > > >  	case FLITE_SD_PAD_SOURCE_ISP:
> > > > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > > > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > > > -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> > > > >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> > > > >  		else
> > > > >  			ret = -EINVAL;
> > > > > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > > > > index 92dbade2fffc..4a25df9dd869 100644
> > > > > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > > > > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > > > > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> > > > >  				break;
> > > > >  		}
> > > > >  
> > > > > -		if (pad == NULL ||
> > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > >  			break;
> > > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > >  
> > > > > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > > > >  	media_entity_graph_walk_start(&graph, entity);
> > > > >  
> > > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > > +		if (!is_media_entity_v4l2_io(entity))
> > > > >  			continue;
> > > > >  
> > > > >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > > > > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > > > >  	media_entity_graph_walk_start(&graph, entity_err);
> > > > >  
> > > > >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > > > > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > > > > +		if (!is_media_entity_v4l2_io(entity_err))
> > > > >  			continue;
> > > > >  
> > > > >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > > > > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > > > > index 69e7733d36cd..cb8ac90086c1 100644
> > > > > --- a/drivers/media/platform/omap3isp/isp.c
> > > > > +++ b/drivers/media/platform/omap3isp/isp.c
> > > > > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> > > > >  	media_entity_graph_walk_start(&graph, entity);
> > > > >  
> > > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > > +		if (is_media_entity_v4l2_io(entity))
> > > > >  			use += entity->use_count;
> > > > >  	}
> > > > >  
> > > > > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> > > > >  	struct v4l2_subdev *subdev;
> > > > >  	int ret;
> > > > >  
> > > > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > > > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > > > >  
> > > > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > > > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > > > >  	media_entity_graph_walk_start(&graph, entity);
> > > > >  
> > > > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > > +		if (is_media_entity_v4l2_subdev(entity))
> > > > >  			ret = isp_pipeline_pm_power_one(entity, change);
> > > > >  
> > > > >  	if (!ret)
> > > > > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > > > >  
> > > > >  	while ((first = media_entity_graph_walk_next(&graph))
> > > > >  	       && first != entity)
> > > > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > > > +		if (is_media_entity_v4l2_subdev(first))
> > > > >  			isp_pipeline_pm_power_one(first, -change);
> > > > >  
> > > > >  	return ret;
> > > > > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> > > > >  			break;
> > > > >  
> > > > >  		pad = media_entity_remote_pad(pad);
> > > > > -		if (pad == NULL ||
> > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > >  			break;
> > > > >  
> > > > >  		entity = pad->entity;
> > > > > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> > > > >  			break;
> > > > >  
> > > > >  		pad = media_entity_remote_pad(pad);
> > > > > -		if (pad == NULL ||
> > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > >  			break;
> > > > >  
> > > > >  		entity = pad->entity;
> > > > > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > > > > index 4c367352b1f7..52843ac2a9ca 100644
> > > > > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > > > > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > > > > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> > > > >  
> > > > >  	remote = media_entity_remote_pad(&video->pad);
> > > > >  
> > > > > -	if (remote == NULL ||
> > > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > > >  		return NULL;
> > > > >  
> > > > >  	if (pad)
> > > > > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> > > > >  		if (entity == &video->video.entity)
> > > > >  			continue;
> > > > >  
> > > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > > +		if (!is_media_entity_v4l2_io(entity))
> > > > >  			continue;
> > > > >  
> > > > >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > > > > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> > > > >  		return -EINVAL;
> > > > >  	}
> > > > >  
> > > > > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +	if (!is_media_entity_v4l2_subdev(source))
> > > > >  		return 0;
> > > > >  
> > > > >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > > > > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > > > > index eae667eab1b9..fb5b016cc0a1 100644
> > > > > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > > > > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > > > > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> > > > >  
> > > > >  	/* Retrieve format at the sensor subdev source pad */
> > > > >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > > > > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > >  		return -EPIPE;
> > > > >  
> > > > >  	src_fmt.pad = pad->index;
> > > > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > > > > index 1f94c1a54e00..f74158224b93 100644
> > > > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > > > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> > > > >  	struct media_pad *remote;
> > > > >  
> > > > >  	remote = media_entity_remote_pad(local);
> > > > > -	if (remote == NULL ||
> > > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > > >  		return NULL;
> > > > >  
> > > > >  	if (pad)
> > > > > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> > > > >  			return -EPIPE;
> > > > >  
> > > > >  		/* We've reached a video node, that shouldn't have happened. */
> > > > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > > > >  			return -EPIPE;
> > > > >  
> > > > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > > > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> > > > >  		struct vsp1_rwpf *rwpf;
> > > > >  		struct vsp1_entity *e;
> > > > >  
> > > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > > +		if (is_media_entity_v4l2_io(entity)) {
> > > > >  			pipe->num_video++;
> > > > >  			continue;
> > > > >  		}
> > > > > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> > > > >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> > > > >  
> > > > >  	while (pad) {
> > > > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > > > >  			break;
> > > > >  
> > > > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > > > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > > > > index 88cd789cdaf7..8e14841bf445 100644
> > > > > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > > > > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > > > > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> > > > >  	struct media_pad *remote;
> > > > >  
> > > > >  	remote = media_entity_remote_pad(local);
> > > > > -	if (remote == NULL ||
> > > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > > >  		return NULL;
> > > > >  
> > > > >  	if (pad)
> > > > > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> > > > >  			break;
> > > > >  
> > > > >  		pad = media_entity_remote_pad(pad);
> > > > > -		if (pad == NULL ||
> > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > >  			break;
> > > > >  
> > > > >  		entity = pad->entity;
> > > > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > > > > index e6e1115d8215..60da43772de9 100644
> > > > > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > > > > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > > > > @@ -526,7 +526,7 @@ static int
> > > > >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> > > > >  				     struct v4l2_subdev_format *fmt)
> > > > >  {
> > > > > -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> > > > >  		struct v4l2_subdev *sd =
> > > > >  			media_entity_to_v4l2_subdev(pad->entity);
> > > > >  
> > > > > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > > index 92573fa852a9..16763e0831f2 100644
> > > > > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> > > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > >  		if (entity == &video->video_dev.entity)
> > > > >  			continue;
> > > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > > +		if ((!is_media_entity_v4l2_io(remote->entity))
> > > > >  			continue;
> > > > >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> > > > >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > > > > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> > > > >  	media_entity_graph_walk_start(&graph, entity);
> > > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > >  
> > > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > > +		if !is_media_entity_v4l2_subdev(entity))
> > > > >  			continue;
> > > > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > > > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > > > > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> > > > >  
> > > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > >  
> > > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > > +		if (!is_media_entity_v4l2_subdev(entity))
> > > > >  			continue;
> > > > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > > > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > > > > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > > > > index 40591963b42b..44b88ff3ba83 100644
> > > > > --- a/drivers/staging/media/omap4iss/iss.c
> > > > > +++ b/drivers/staging/media/omap4iss/iss.c
> > > > > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> > > > >  	media_entity_graph_walk_start(&graph, entity);
> > > > >  
> > > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > > +		if (is_media_entity_v4l2_io(entity))
> > > > >  			use += entity->use_count;
> > > > >  	}
> > > > >  
> > > > > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> > > > >  {
> > > > >  	struct v4l2_subdev *subdev;
> > > > >  
> > > > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > > > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > > > >  
> > > > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > > > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > > > >  	media_entity_graph_walk_start(&graph, entity);
> > > > >  
> > > > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > > +		if (is_media_entity_v4l2_subdev(entity))
> > > > >  			ret = iss_pipeline_pm_power_one(entity, change);
> > > > >  
> > > > >  	if (!ret)
> > > > > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > > > >  
> > > > >  	while ((first = media_entity_graph_walk_next(&graph))
> > > > >  	       && first != entity)
> > > > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > > > +		if (is_media_entity_v4l2_subdev(first))
> > > > >  			iss_pipeline_pm_power_one(first, -change);
> > > > >  
> > > > >  	return ret;
> > > > > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> > > > >  			break;
> > > > >  
> > > > >  		pad = media_entity_remote_pad(pad);
> > > > > -		if (pad == NULL ||
> > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > >  			break;
> > > > >  
> > > > >  		entity = pad->entity;
> > > > > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> > > > >  			break;
> > > > >  
> > > > >  		pad = media_entity_remote_pad(pad);
> > > > > -		if (pad == NULL ||
> > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > >  			break;
> > > > >  
> > > > >  		entity = pad->entity;
> > > > > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > > > > index 45a3f2d778fc..cbe5783735dc 100644
> > > > > --- a/drivers/staging/media/omap4iss/iss_video.c
> > > > > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > > > > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> > > > >  
> > > > >  	remote = media_entity_remote_pad(&video->pad);
> > > > >  
> > > > > -	if (remote == NULL ||
> > > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > > >  		return NULL;
> > > > >  
> > > > >  	if (pad)
> > > > > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> > > > >  		if (entity == &video->video.entity)
> > > > >  			continue;
> > > > >  
> > > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > > +		if (!is_media_entity_v4l2_io(entity))
> > > > >  			continue;
> > > > >  
> > > > >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> > > > 
> > > > I finally got around to test these patches eventually, and after some
> > > > debugging found this one. I think it's a good idea to have macros to
> > > > determine whether an entity exposes a V4L2 sub-device interface but it
> > > > should be more robust than is_media_entity_v4l2_subdev() right now is.
> > > 
> > > Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
> > > actually a separate graph object (interfaces). Those macros work at the
> > > entities, not at the interface objects.
> > 
> > is_media_entity_v4l2_subdev() will produce wrong results for a large part of
> > V4L2 sub-devices with these patches applied.
> > 
> > I checked again the original implementation, and it seems to be based only
> > on the type as well, albeit that's a range, not a set of different
> > functions.
> > 
> > I suppose this will change at some point in the future: the interface indeed
> > should not be determined by the function of the entity. At least it needs to
> > be fixed now until the rework. I'll submit a patch for that.
> 
> I'm folding this small fixup to this patch. It should fix the issues with
> the unknown subdev types.
> 
> This is fixed on some latter patches in this series, adding 
> MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN, but let's avoid breaking bisectability
> here.
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 337d7b3e047f..b4a17a1bce58 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -241,6 +241,7 @@ static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
>  		return false;
>  
>  	switch (entity->type) {
> +	case MEDIA_ENT_T_V4L2_SUBDEV_BASE:
>  	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
>  	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
>  	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:

Actually, due to some comments for the patch:
	s5c73m3: fix subdev type

And a few others, I'm actually adding MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN
definition on this patchset.

The new version of this patch is:

>From a1eb0e612166edf3bb07d9c699ad3264069d36d5 Mon Sep 17 00:00:00 2001
From: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Date: Fri, 21 Aug 2015 12:17:40 -0300
Subject: [PATCH] [media] media: add macros to check if subdev or V4L2 DMA

As we'll be removing entity subtypes from the Kernel, we need
to provide a way for drivers and core to check if a given
entity is represented by a V4L2 subdev or if it is an V4L2
I/O entity (typically with DMA). 

Drivers that create entities that don't belong to any defined subdev
category should use MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN.

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index ca35e07d9348..b4a17a1bce58 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -220,6 +220,40 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
 	return id;
 }
 
+static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_VIDEO:
+	case MEDIA_ENT_T_V4L2_VBI:
+	case MEDIA_ENT_T_V4L2_SWRADIO:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_SUBDEV_BASE:
+	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
+	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
+	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
+	case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
+	case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
+		return true;
+
+	default:
+		return false;
+	}
+}
+
 #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
 #define MEDIA_ENTITY_ENUM_MAX_ID	64
 
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 8e9896820bee..c9314645d933 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -75,6 +75,9 @@ struct media_device_info {
 #define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 6)
 
 /* V4L2 Sub-device entities */
+
+#define MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN	MEDIA_ENT_T_V4L2_SUBDEV_BASE
+
 #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
 #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
 #define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)

^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities
  2015-12-08 17:05           ` Mauro Carvalho Chehab
@ 2015-12-08 17:08             ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 17:08 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Linux Media Mailing List, Laurent Pinchart, Hans Verkuil,
	Sakari Ailus, Javier Martinez Canillas

Em Tue, 8 Dec 2015 15:05:51 -0200
Mauro Carvalho Chehab <mchehab@infradead.org> escreveu:

> Em Tue, 8 Dec 2015 13:57:55 -0200
> Mauro Carvalho Chehab <mchehab@osg.samsung.com> escreveu:
> 
> > Em Mon, 12 Oct 2015 18:35:05 +0300
> > Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> > 
> > > Hi Mauro,
> > > 
> > > On Sun, Oct 11, 2015 at 09:56:25PM -0300, Mauro Carvalho Chehab wrote:
> > > > Em Mon, 12 Oct 2015 00:07:52 +0300
> > > > Sakari Ailus <sakari.ailus@iki.fi> escreveu:
> > > > 
> > > > > Hi Mauro,
> > > > > 
> > > > > On Sun, Aug 30, 2015 at 12:06:43AM -0300, Mauro Carvalho Chehab wrote:
> > > > > > Instead of relying on media subtype, use the new macros to detect
> > > > > > if an entity is a subdev or an A/V DMA entity.
> > > > > > 
> > > > > > Please note that most drivers assume that there's just AV_DMA or
> > > > > > V4L2 subdevs. This is not true anymore, as we've added MC support
> > > > > > for DVB, and there are plans to add support for ALSA and FB/DRM
> > > > > > too.
> > > > > > 
> > > > > > Ok, on the current pipelines supported by those drivers, just V4L
> > > > > > stuff are there, but, assuming that some day a pipeline that also
> > > > > > works with other subsystems will ever added, it is better to add
> > > > > > explicit checks for the AV_DMA stuff.
> > > > > > 
> > > > > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > > > > 
> > > > > > diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
> > > > > > index 0eb34ecb8ee4..8c9a29e0e294 100644
> > > > > > --- a/drivers/media/platform/exynos4-is/common.c
> > > > > > +++ b/drivers/media/platform/exynos4-is/common.c
> > > > > > @@ -22,8 +22,7 @@ struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
> > > > > >  	while (pad->flags & MEDIA_PAD_FL_SINK) {
> > > > > >  		/* source pad */
> > > > > >  		pad = media_entity_remote_pad(pad);
> > > > > > -		if (pad == NULL ||
> > > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > > >  			break;
> > > > > >  
> > > > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > > > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > > > index 0627a93b2f3b..e9810fee4c30 100644
> > > > > > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > > > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > > > > > @@ -1141,8 +1141,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
> > > > > >  			}
> > > > > >  		}
> > > > > >  
> > > > > > -		if (src_pad == NULL ||
> > > > > > -		    media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +		if (!src_pad || !is_media_entity_v4l2_subdev(src_pad->entity))
> > > > > >  			break;
> > > > > >  
> > > > > >  		/* Don't call FIMC subdev operation to avoid nested locking */
> > > > > > @@ -1397,7 +1396,7 @@ static int fimc_link_setup(struct media_entity *entity,
> > > > > >  	struct fimc_vid_cap *vc = &fimc->vid_cap;
> > > > > >  	struct v4l2_subdev *sensor;
> > > > > >  
> > > > > > -	if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> > > > > >  		return -EINVAL;
> > > > > >  
> > > > > >  	if (WARN_ON(fimc == NULL))
> > > > > > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > > > index 3d9ccbf5f10f..5fbaf5e39903 100644
> > > > > > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > > > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > > > > > @@ -467,8 +467,7 @@ static int isp_video_pipeline_validate(struct fimc_isp *isp)
> > > > > >  
> > > > > >  		/* Retrieve format at the source pad */
> > > > > >  		pad = media_entity_remote_pad(pad);
> > > > > > -		if (pad == NULL ||
> > > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > > >  			break;
> > > > > >  
> > > > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > > > diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > > > index b2607da4ad14..c2327147b360 100644
> > > > > > --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > > > +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> > > > > > @@ -814,8 +814,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
> > > > > >  		}
> > > > > >  		/* Retrieve format at the source pad */
> > > > > >  		pad = media_entity_remote_pad(pad);
> > > > > > -		if (pad == NULL ||
> > > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > > >  			break;
> > > > > >  
> > > > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > > > @@ -988,7 +987,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > > > >  {
> > > > > >  	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> > > > > >  	struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
> > > > > > -	unsigned int remote_ent_type = media_entity_type(remote->entity);
> > > > > >  	int ret = 0;
> > > > > >  
> > > > > >  	if (WARN_ON(fimc == NULL))
> > > > > > @@ -1000,7 +998,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > > > >  
> > > > > >  	switch (local->index) {
> > > > > >  	case FLITE_SD_PAD_SINK:
> > > > > > -		if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > > > +		if (!is_media_entity_v4l2_subdev(remote->entity)) {
> > > > > >  			ret = -EINVAL;
> > > > > >  			break;
> > > > > >  		}
> > > > > > @@ -1018,7 +1016,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > > > >  	case FLITE_SD_PAD_SOURCE_DMA:
> > > > > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > > > > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > > > > -		else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
> > > > > > +		else if (is_media_entity_v4l2_io(remote->entity))
> > > > > >  			atomic_set(&fimc->out_path, FIMC_IO_DMA);
> > > > > >  		else
> > > > > >  			ret = -EINVAL;
> > > > > > @@ -1027,7 +1025,7 @@ static int fimc_lite_link_setup(struct media_entity *entity,
> > > > > >  	case FLITE_SD_PAD_SOURCE_ISP:
> > > > > >  		if (!(flags & MEDIA_LNK_FL_ENABLED))
> > > > > >  			atomic_set(&fimc->out_path, FIMC_IO_NONE);
> > > > > > -		else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +		else if (is_media_entity_v4l2_subdev(remote->entity))
> > > > > >  			atomic_set(&fimc->out_path, FIMC_IO_ISP);
> > > > > >  		else
> > > > > >  			ret = -EINVAL;
> > > > > > diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> > > > > > index 92dbade2fffc..4a25df9dd869 100644
> > > > > > --- a/drivers/media/platform/exynos4-is/media-dev.c
> > > > > > +++ b/drivers/media/platform/exynos4-is/media-dev.c
> > > > > > @@ -88,8 +88,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
> > > > > >  				break;
> > > > > >  		}
> > > > > >  
> > > > > > -		if (pad == NULL ||
> > > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > > >  			break;
> > > > > >  		sd = media_entity_to_v4l2_subdev(pad->entity);
> > > > > >  
> > > > > > @@ -1062,7 +1061,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > > > > >  	media_entity_graph_walk_start(&graph, entity);
> > > > > >  
> > > > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > > > +		if (!is_media_entity_v4l2_io(entity))
> > > > > >  			continue;
> > > > > >  
> > > > > >  		ret  = __fimc_md_modify_pipeline(entity, enable);
> > > > > > @@ -1076,7 +1075,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
> > > > > >  	media_entity_graph_walk_start(&graph, entity_err);
> > > > > >  
> > > > > >  	while ((entity_err = media_entity_graph_walk_next(&graph))) {
> > > > > > -		if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
> > > > > > +		if (!is_media_entity_v4l2_io(entity_err))
> > > > > >  			continue;
> > > > > >  
> > > > > >  		__fimc_md_modify_pipeline(entity_err, !enable);
> > > > > > diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> > > > > > index 69e7733d36cd..cb8ac90086c1 100644
> > > > > > --- a/drivers/media/platform/omap3isp/isp.c
> > > > > > +++ b/drivers/media/platform/omap3isp/isp.c
> > > > > > @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity)
> > > > > >  	media_entity_graph_walk_start(&graph, entity);
> > > > > >  
> > > > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > > > +		if (is_media_entity_v4l2_io(entity))
> > > > > >  			use += entity->use_count;
> > > > > >  	}
> > > > > >  
> > > > > > @@ -714,7 +714,7 @@ static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
> > > > > >  	struct v4l2_subdev *subdev;
> > > > > >  	int ret;
> > > > > >  
> > > > > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > > > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > > > > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > > > > >  
> > > > > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > > > > @@ -754,7 +754,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > > > > >  	media_entity_graph_walk_start(&graph, entity);
> > > > > >  
> > > > > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > > > +		if (is_media_entity_v4l2_subdev(entity))
> > > > > >  			ret = isp_pipeline_pm_power_one(entity, change);
> > > > > >  
> > > > > >  	if (!ret)
> > > > > > @@ -764,7 +764,7 @@ static int isp_pipeline_pm_power(struct media_entity *entity, int change)
> > > > > >  
> > > > > >  	while ((first = media_entity_graph_walk_next(&graph))
> > > > > >  	       && first != entity)
> > > > > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > > > > +		if (is_media_entity_v4l2_subdev(first))
> > > > > >  			isp_pipeline_pm_power_one(first, -change);
> > > > > >  
> > > > > >  	return ret;
> > > > > > @@ -897,8 +897,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
> > > > > >  			break;
> > > > > >  
> > > > > >  		pad = media_entity_remote_pad(pad);
> > > > > > -		if (pad == NULL ||
> > > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > > >  			break;
> > > > > >  
> > > > > >  		entity = pad->entity;
> > > > > > @@ -988,8 +987,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
> > > > > >  			break;
> > > > > >  
> > > > > >  		pad = media_entity_remote_pad(pad);
> > > > > > -		if (pad == NULL ||
> > > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > > >  			break;
> > > > > >  
> > > > > >  		entity = pad->entity;
> > > > > > diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> > > > > > index 4c367352b1f7..52843ac2a9ca 100644
> > > > > > --- a/drivers/media/platform/omap3isp/ispvideo.c
> > > > > > +++ b/drivers/media/platform/omap3isp/ispvideo.c
> > > > > > @@ -210,8 +210,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
> > > > > >  
> > > > > >  	remote = media_entity_remote_pad(&video->pad);
> > > > > >  
> > > > > > -	if (remote == NULL ||
> > > > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > > > >  		return NULL;
> > > > > >  
> > > > > >  	if (pad)
> > > > > > @@ -243,7 +242,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
> > > > > >  		if (entity == &video->video.entity)
> > > > > >  			continue;
> > > > > >  
> > > > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > > > +		if (!is_media_entity_v4l2_io(entity))
> > > > > >  			continue;
> > > > > >  
> > > > > >  		__video = to_isp_video(media_entity_to_video_device(entity));
> > > > > > @@ -917,7 +916,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> > > > > >  		return -EINVAL;
> > > > > >  	}
> > > > > >  
> > > > > > -	if (media_entity_type(source) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +	if (!is_media_entity_v4l2_subdev(source))
> > > > > >  		return 0;
> > > > > >  
> > > > > >  	pipe->external = media_entity_to_v4l2_subdev(source);
> > > > > > diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> > > > > > index eae667eab1b9..fb5b016cc0a1 100644
> > > > > > --- a/drivers/media/platform/s3c-camif/camif-capture.c
> > > > > > +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> > > > > > @@ -837,7 +837,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
> > > > > >  
> > > > > >  	/* Retrieve format at the sensor subdev source pad */
> > > > > >  	pad = media_entity_remote_pad(&camif->pads[0]);
> > > > > > -	if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +	if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > > >  		return -EPIPE;
> > > > > >  
> > > > > >  	src_fmt.pad = pad->index;
> > > > > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
> > > > > > index 1f94c1a54e00..f74158224b93 100644
> > > > > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > > > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > > > > @@ -160,8 +160,7 @@ vsp1_video_remote_subdev(struct media_pad *local, u32 *pad)
> > > > > >  	struct media_pad *remote;
> > > > > >  
> > > > > >  	remote = media_entity_remote_pad(local);
> > > > > > -	if (remote == NULL ||
> > > > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > > > >  		return NULL;
> > > > > >  
> > > > > >  	if (pad)
> > > > > > @@ -326,7 +325,7 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
> > > > > >  			return -EPIPE;
> > > > > >  
> > > > > >  		/* We've reached a video node, that shouldn't have happened. */
> > > > > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > > > > >  			return -EPIPE;
> > > > > >  
> > > > > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > > > > @@ -423,7 +422,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
> > > > > >  		struct vsp1_rwpf *rwpf;
> > > > > >  		struct vsp1_entity *e;
> > > > > >  
> > > > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > > > +		if (is_media_entity_v4l2_io(entity)) {
> > > > > >  			pipe->num_video++;
> > > > > >  			continue;
> > > > > >  		}
> > > > > > @@ -692,7 +691,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
> > > > > >  	pad = media_entity_remote_pad(&input->pads[RWPF_PAD_SOURCE]);
> > > > > >  
> > > > > >  	while (pad) {
> > > > > > -		if (media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +		if (!is_media_entity_v4l2_subdev(pad->entity))
> > > > > >  			break;
> > > > > >  
> > > > > >  		entity = to_vsp1_entity(media_entity_to_v4l2_subdev(pad->entity));
> > > > > > diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> > > > > > index 88cd789cdaf7..8e14841bf445 100644
> > > > > > --- a/drivers/media/platform/xilinx/xilinx-dma.c
> > > > > > +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> > > > > > @@ -49,8 +49,7 @@ xvip_dma_remote_subdev(struct media_pad *local, u32 *pad)
> > > > > >  	struct media_pad *remote;
> > > > > >  
> > > > > >  	remote = media_entity_remote_pad(local);
> > > > > > -	if (remote == NULL ||
> > > > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > > > >  		return NULL;
> > > > > >  
> > > > > >  	if (pad)
> > > > > > @@ -113,8 +112,7 @@ static int xvip_pipeline_start_stop(struct xvip_pipeline *pipe, bool start)
> > > > > >  			break;
> > > > > >  
> > > > > >  		pad = media_entity_remote_pad(pad);
> > > > > > -		if (pad == NULL ||
> > > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > > >  			break;
> > > > > >  
> > > > > >  		entity = pad->entity;
> > > > > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> > > > > > index e6e1115d8215..60da43772de9 100644
> > > > > > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > > > > > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > > > > > @@ -526,7 +526,7 @@ static int
> > > > > >  v4l2_subdev_link_validate_get_format(struct media_pad *pad,
> > > > > >  				     struct v4l2_subdev_format *fmt)
> > > > > >  {
> > > > > > -	if (media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) {
> > > > > > +	if (is_media_entity_v4l2_subdev(pad->entity)) {
> > > > > >  		struct v4l2_subdev *sd =
> > > > > >  			media_entity_to_v4l2_subdev(pad->entity);
> > > > > >  
> > > > > > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > > > index 92573fa852a9..16763e0831f2 100644
> > > > > > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > > > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > > > > > @@ -148,7 +148,7 @@ static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
> > > > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > > >  		if (entity == &video->video_dev.entity)
> > > > > >  			continue;
> > > > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > > > +		if ((!is_media_entity_v4l2_io(remote->entity))
> > > > > >  			continue;
> > > > > >  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
> > > > > >  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> > > > > > @@ -293,7 +293,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
> > > > > >  	media_entity_graph_walk_start(&graph, entity);
> > > > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > > >  
> > > > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > > > +		if !is_media_entity_v4l2_subdev(entity))
> > > > > >  			continue;
> > > > > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > > > > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
> > > > > > @@ -334,7 +334,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
> > > > > >  
> > > > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > > >  
> > > > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > > > +		if (!is_media_entity_v4l2_subdev(entity))
> > > > > >  			continue;
> > > > > >  		subdev = media_entity_to_v4l2_subdev(entity);
> > > > > >  		ret = v4l2_subdev_call(subdev, video, s_stream, 0);
> > > > > > diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> > > > > > index 40591963b42b..44b88ff3ba83 100644
> > > > > > --- a/drivers/staging/media/omap4iss/iss.c
> > > > > > +++ b/drivers/staging/media/omap4iss/iss.c
> > > > > > @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity)
> > > > > >  	media_entity_graph_walk_start(&graph, entity);
> > > > > >  
> > > > > >  	while ((entity = media_entity_graph_walk_next(&graph))) {
> > > > > > -		if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
> > > > > > +		if (is_media_entity_v4l2_io(entity))
> > > > > >  			use += entity->use_count;
> > > > > >  	}
> > > > > >  
> > > > > > @@ -419,7 +419,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
> > > > > >  {
> > > > > >  	struct v4l2_subdev *subdev;
> > > > > >  
> > > > > > -	subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
> > > > > > +	subdev = is_media_entity_v4l2_subdev(entity)
> > > > > >  	       ? media_entity_to_v4l2_subdev(entity) : NULL;
> > > > > >  
> > > > > >  	if (entity->use_count == 0 && change > 0 && subdev != NULL) {
> > > > > > @@ -461,7 +461,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > > > > >  	media_entity_graph_walk_start(&graph, entity);
> > > > > >  
> > > > > >  	while (!ret && (entity = media_entity_graph_walk_next(&graph)))
> > > > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > > > +		if (is_media_entity_v4l2_subdev(entity))
> > > > > >  			ret = iss_pipeline_pm_power_one(entity, change);
> > > > > >  
> > > > > >  	if (!ret)
> > > > > > @@ -471,7 +471,7 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
> > > > > >  
> > > > > >  	while ((first = media_entity_graph_walk_next(&graph))
> > > > > >  	       && first != entity)
> > > > > > -		if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
> > > > > > +		if (is_media_entity_v4l2_subdev(first))
> > > > > >  			iss_pipeline_pm_power_one(first, -change);
> > > > > >  
> > > > > >  	return ret;
> > > > > > @@ -590,8 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
> > > > > >  			break;
> > > > > >  
> > > > > >  		pad = media_entity_remote_pad(pad);
> > > > > > -		if (pad == NULL ||
> > > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > > >  			break;
> > > > > >  
> > > > > >  		entity = pad->entity;
> > > > > > @@ -658,8 +657,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
> > > > > >  			break;
> > > > > >  
> > > > > >  		pad = media_entity_remote_pad(pad);
> > > > > > -		if (pad == NULL ||
> > > > > > -		    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> > > > > >  			break;
> > > > > >  
> > > > > >  		entity = pad->entity;
> > > > > > diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> > > > > > index 45a3f2d778fc..cbe5783735dc 100644
> > > > > > --- a/drivers/staging/media/omap4iss/iss_video.c
> > > > > > +++ b/drivers/staging/media/omap4iss/iss_video.c
> > > > > > @@ -191,8 +191,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
> > > > > >  
> > > > > >  	remote = media_entity_remote_pad(&video->pad);
> > > > > >  
> > > > > > -	if (remote == NULL ||
> > > > > > -	    media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
> > > > > > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> > > > > >  		return NULL;
> > > > > >  
> > > > > >  	if (pad)
> > > > > > @@ -217,7 +216,7 @@ iss_video_far_end(struct iss_video *video)
> > > > > >  		if (entity == &video->video.entity)
> > > > > >  			continue;
> > > > > >  
> > > > > > -		if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
> > > > > > +		if (!is_media_entity_v4l2_io(entity))
> > > > > >  			continue;
> > > > > >  
> > > > > >  		far_end = to_iss_video(media_entity_to_video_device(entity));
> > > > > 
> > > > > I finally got around to test these patches eventually, and after some
> > > > > debugging found this one. I think it's a good idea to have macros to
> > > > > determine whether an entity exposes a V4L2 sub-device interface but it
> > > > > should be more robust than is_media_entity_v4l2_subdev() right now is.
> > > > 
> > > > Hmm... Not sure what you're meaning... the V4L2 sub-device interface is
> > > > actually a separate graph object (interfaces). Those macros work at the
> > > > entities, not at the interface objects.
> > > 
> > > is_media_entity_v4l2_subdev() will produce wrong results for a large part of
> > > V4L2 sub-devices with these patches applied.
> > > 
> > > I checked again the original implementation, and it seems to be based only
> > > on the type as well, albeit that's a range, not a set of different
> > > functions.
> > > 
> > > I suppose this will change at some point in the future: the interface indeed
> > > should not be determined by the function of the entity. At least it needs to
> > > be fixed now until the rework. I'll submit a patch for that.
> > 
> > I'm folding this small fixup to this patch. It should fix the issues with
> > the unknown subdev types.
> > 
> > This is fixed on some latter patches in this series, adding 
> > MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN, but let's avoid breaking bisectability
> > here.
> > 
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index 337d7b3e047f..b4a17a1bce58 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -241,6 +241,7 @@ static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
> >  		return false;
> >  
> >  	switch (entity->type) {
> > +	case MEDIA_ENT_T_V4L2_SUBDEV_BASE:
> >  	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
> >  	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
> >  	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
> 
> Actually, due to some comments for the patch:
> 	s5c73m3: fix subdev type
> 
> And a few others, I'm actually adding MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN
> definition on this patchset.
> 
> The new version of this patch is:

Sorry, wrong version. The right one is:


>From 5b7692b1bed4edf4a19b94d1883c21eb98754214 Mon Sep 17 00:00:00 2001
From: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Date: Fri, 21 Aug 2015 12:17:40 -0300
Subject: [PATCH] [media] media: add macros to check if subdev or V4L2 DMA

As we'll be removing entity subtypes from the Kernel, we need
to provide a way for drivers and core to check if a given
entity is represented by a V4L2 subdev or if it is an V4L2
I/O entity (typically with DMA).

Drivers that create entities that don't belong to any defined subdev
category should use MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN.

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index ca35e07d9348..2596878f4b9f 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -220,6 +220,40 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
 	return id;
 }
 
+static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_VIDEO:
+	case MEDIA_ENT_T_V4L2_VBI:
+	case MEDIA_ENT_T_V4L2_SWRADIO:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN:
+	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
+	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
+	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
+	case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
+	case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
+		return true;
+
+	default:
+		return false;
+	}
+}
+
 #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
 #define MEDIA_ENTITY_ENUM_MAX_ID	64
 
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 8e9896820bee..c9314645d933 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -75,6 +75,9 @@ struct media_device_info {
 #define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 6)
 
 /* V4L2 Sub-device entities */
+
+#define MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN	MEDIA_ENT_T_V4L2_SUBDEV_BASE
+
 #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
 #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
 #define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)




^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 34/55] [media] s5c73m3: fix subdev type
  2015-12-06  1:57   ` Laurent Pinchart
@ 2015-12-08 17:11     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 17:11 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Kyungmin Park,
	Andrzej Hajda

Em Sun, 06 Dec 2015 03:57:56 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 30 August 2015 00:06:45 Mauro Carvalho Chehab wrote:
> > This sensor driver is abusing MEDIA_ENT_T_V4L2_SUBDEV, creating
> > some subdevs with a non-existing type.
> > 
> > As this is a sensor driver, the proper type is likely
> > MEDIA_ENT_T_CAM_SENSOR.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> > b/drivers/media/i2c/s5c73m3/s5c73m3-core.c index c81bfbfea32f..abae37321c0c
> > 100644
> > --- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> > +++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> > @@ -1688,7 +1688,7 @@ static int s5c73m3_probe(struct i2c_client *client,
> > 
> >  	state->sensor_pads[S5C73M3_JPEG_PAD].flags = MEDIA_PAD_FL_SOURCE;
> >  	state->sensor_pads[S5C73M3_ISP_PAD].flags = MEDIA_PAD_FL_SOURCE;
> > -	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
> > +	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
> 
> As explained in my review of "s5k5baf: fix subdev type", this is correct...
> 
> >  	ret = media_entity_init(&sd->entity, S5C73M3_NUM_PADS,
> >  							state->sensor_pads);
> > @@ -1704,7 +1704,7 @@ static int s5c73m3_probe(struct i2c_client *client,
> >  	state->oif_pads[OIF_ISP_PAD].flags = MEDIA_PAD_FL_SINK;
> >  	state->oif_pads[OIF_JPEG_PAD].flags = MEDIA_PAD_FL_SINK;
> >  	state->oif_pads[OIF_SOURCE_PAD].flags = MEDIA_PAD_FL_SOURCE;
> > -	oif_sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
> > +	oif_sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
> 
> ... but this isn't.

Ok. Replacing this hunk by:

-	oif_sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
+	oif_sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN;


> 
> >  	ret = media_entity_init(&oif_sd->entity, OIF_NUM_PADS,
> >  							state->oif_pads);
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 35/55] [media] s5k5baf: fix subdev type
  2015-12-06  1:55   ` Laurent Pinchart
@ 2015-12-08 17:17     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 17:17 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Kyungmin Park,
	Andrzej Hajda

Em Sun, 06 Dec 2015 03:55:32 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 30 August 2015 00:06:46 Mauro Carvalho Chehab wrote:
> > X-Patchwork-Delegate: m.chehab@samsung.com
> > This sensor driver is abusing MEDIA_ENT_T_V4L2_SUBDEV, creating
> > some subdevs with a non-existing type.
> > 
> > As this is a sensor driver, the proper type is likely
> > MEDIA_ENT_T_V4L2_SUBDEV_SENSOR.
> 
> That's actually not correct. The driver creates two subdevs, one for the image 
> sensor pixel array (and the related readout logic) and one for an ISP. The 
> first subdev already uses the MEDIA_ENT_T_V4L2_SUBDEV_SENSOR type, but the 
> second subdev isn't a sensor pixel array.

OK.

Patch replaced by the one below.

Thanks,
Mauro

>From b1acc860aa845e9ea84fa597d540ad34047fe0cc Mon Sep 17 00:00:00 2001
From: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Date: Thu, 7 May 2015 22:12:35 -0300
Subject: [media] s5k5baf: fix subdev type
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>,
    Mauro Carvalho Chehab <mchehab@infradead.org>

The driver creates two subdevs, one for the image sensor pixel array
(and the related readout logic) and one for an ISP.

The first subdev already uses the MEDIA_ENT_T_V4L2_SUBDEV_SENSOR type,
but the second subdev isn't a sensor pixel array.

So, rename the second subdev as MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 drivers/media/i2c/s5k5baf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index d3bff30bcb6f..0513196bd48c 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -1919,7 +1919,7 @@ static int s5k5baf_configure_subdevs(struct s5k5baf *state,
 
 	state->pads[PAD_CIS].flags = MEDIA_PAD_FL_SINK;
 	state->pads[PAD_OUT].flags = MEDIA_PAD_FL_SOURCE;
-	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
+	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN;
 	ret = media_entity_init(&sd->entity, NUM_ISP_PADS, state->pads);
 
 	if (!ret)
-- 
2.5.0




^ permalink raw reply related	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 36/55] [media] davinci_vbpe: stop MEDIA_ENT_T_V4L2_SUBDEV abuse
  2015-12-06  1:52   ` Laurent Pinchart
@ 2015-12-08 17:22     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 17:22 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Hans Verkuil, Prabhakar Lad, Sakari Ailus,
	Aya Mahfouz, Boris BREZILLON, Javier Martinez Canillas, devel

Em Sun, 06 Dec 2015 03:52:01 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 30 August 2015 00:06:47 Mauro Carvalho Chehab wrote:
> > This driver is abusing MEDIA_ENT_T_V4L2_SUBDEV:
> > 
> > - it uses a hack to check if the remote entity is a subdev;
> 
> Same comment as for "omap4iss: stop MEDIA_ENT_T_V4L2_SUBDEV abuse", this isn't 
> a hack.
> 
> > - it still uses the legacy entity subtype check macro, that
> >   will be removed soon.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
> > b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c index
> > b89a057b8b7e..7fd78329e3e1 100644
> > --- a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
> > +++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
> > @@ -1711,8 +1711,11 @@ ipipe_link_setup(struct media_entity *entity, const
> > struct media_pad *local, struct vpfe_device *vpfe_dev =
> > to_vpfe_device(ipipe);
> >  	u16 ipipeif_sink = vpfe_dev->vpfe_ipipeif.input;
> > 
> > -	switch (local->index | media_entity_type(remote->entity)) {
> > -	case IPIPE_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> > +		return -EINVAL;
> 
> You can drop the check (even though the implementation in the switch looks 
> dubious to me, but that's not your fault).

I prefer to keep the above check, as it shouldn't hurt. 

As I said on a previous comment on your reviews, if someone adds later
some non-V4L2 entities to the media pipeline where the DaVinci media
driver belongs, it could be a problem without the above check.

> 
> > +	switch (local->index) {
> > +	case IPIPE_PAD_SINK:
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  			ipipe->input = IPIPE_INPUT_NONE;
> >  			break;
> > @@ -1725,7 +1728,7 @@ ipipe_link_setup(struct media_entity *entity, const
> > struct media_pad *local, ipipe->input = IPIPE_INPUT_CCDC;
> >  		break;
> > 
> > -	case IPIPE_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case IPIPE_PAD_SOURCE:
> >  		/* out to RESIZER */
> >  		if (flags & MEDIA_LNK_FL_ENABLED)
> >  			ipipe->output = IPIPE_OUTPUT_RESIZER;
> > diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > b/drivers/staging/media/davinci_vpfe/vpfe_video.c index
> > 9eef64e0f0ab..2dbf14b9bb5f 100644
> > --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> > @@ -88,7 +88,7 @@ vpfe_video_remote_subdev(struct vpfe_video_device *video,
> > u32 *pad) {
> >  	struct media_pad *remote = media_entity_remote_pad(&video->pad);
> > 
> > -	if (remote == NULL || remote->entity->type != MEDIA_ENT_T_V4L2_SUBDEV)
> > +	if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
> >  		return NULL;
> >  	if (pad)
> >  		*pad = remote->index;
> > @@ -243,8 +243,7 @@ static int vpfe_video_validate_pipeline(struct
> > vpfe_pipeline *pipe)
> > 
> >  		/* Retrieve the source format */
> >  		pad = media_entity_remote_pad(pad);
> > -		if (pad == NULL ||
> > -			pad->entity->type != MEDIA_ENT_T_V4L2_SUBDEV)
> > +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> >  			break;
> > 
> >  		subdev = media_entity_to_v4l2_subdev(pad->entity);
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 38/55] [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs
  2015-12-06  1:37     ` Laurent Pinchart
@ 2015-12-08 17:38       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 17:38 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Hans Verkuil, Sylwester Nawrocki, Lad,
	Prabhakar, Markus Elfring, Lars-Peter Clausen, linux-api

Em Sun, 06 Dec 2015 03:37:59 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> In addition to my reply to Sakari's e-mail, please see below for a few small 
> comments.
> 
> On Sunday 06 September 2015 09:02:58 Mauro Carvalho Chehab wrote:
> > Instead of abusing MEDIA_ENT_T_V4L2_SUBDEV, initialize
> > new subdev entities as MEDIA_ENT_T_UNKNOWN.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index 659507bce63f..134fe7510195 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -435,6 +435,12 @@ int __must_check media_device_register_entity(struct
> > media_device *mdev, {
> >  	int i;
> > 
> > +	if (entity->type == MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN ||
> > +	    entity->type == MEDIA_ENT_T_UNKNOWN)
> > +		dev_warn(mdev->dev,
> > +			 "Entity type for entity %s was not initialized!\n",
> > +			 entity->name);
> > +
> >  	/* Warn if we apparently re-register an entity */
> >  	WARN_ON(entity->graph_obj.mdev != NULL);
> >  	entity->graph_obj.mdev = mdev;
> > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c
> > b/drivers/media/v4l2-core/v4l2-subdev.c index 60da43772de9..b3bcc8253182
> > 100644
> > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > @@ -584,7 +584,7 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const
> > struct v4l2_subdev_ops *ops) sd->host_priv = NULL;
> >  #if defined(CONFIG_MEDIA_CONTROLLER)
> >  	sd->entity.name = sd->name;
> > -	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
> > +	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN;
> >  #endif
> >  }
> >  EXPORT_SYMBOL(v4l2_subdev_init);
> > diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> > index f8725b881a1d..3d6210095336 100644
> > --- a/include/uapi/linux/media.h
> > +++ b/include/uapi/linux/media.h
> > @@ -42,6 +42,14 @@ struct media_device_info {
> > 
> >  #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
> > 
> > +/* Used values for media_entity_desc::type */
> > +
> 
> You remove this a couple of patches later, is it worth adding it in the first 
> place ?

If you had come with that earlier, I would happily have it removed ;)
Right now, I really want to avoid changes on the patches. Handling a
83 patch series, with two ~20 patch series depending on it (Shuah's
ALSA patches and Sakari's internal entity numbering series) is not
fun.

So, as this is already removed on some other patch, I'll let this
hunk as-is.

> 
> > +/*
> > + * Initial value to be used when a new entity is created
> > + * Drivers should change it to something useful
> 
> As you warn when the value isn't change I'd say "Drivers must change...".

I'll fix this on a later patch.

> > + */
> > +#define MEDIA_ENT_T_UNKNOWN	0x00000000
> > +
> >  /*
> >   * Base numbers for entity types
> >   *
> > @@ -75,6 +83,15 @@ struct media_device_info {
> >  #define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 6)
> > 
> >  /* V4L2 Sub-device entities */
> > +
> > +	/*
> > +	 * Subdevs are initialized with MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN,
> > +	 * in order to preserve backward compatibility.
> > +	 * Drivers should change to the proper subdev type before
> > +	 * registering the entity.
> > +	 */
> 
> Leading tabs look weird here.

Ok, I'll remove the ident here. This hunk had to be conflict solved
anyway, as we merged the MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN addition
earlier. I'll do this specific change here, and hope to not cause
context conflicts later - it will likely cause - as we renamed from
ENT_T_foo to ENT_F_foo :( Let's hope git is smart enough here...

> 
> > +#define MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN	MEDIA_ENT_T_V4L2_SUBDEV_BASE
> > +
> >  #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
> >  #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
> >  #define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 37/55] [media] omap4iss: stop MEDIA_ENT_T_V4L2_SUBDEV abuse
  2015-12-06  1:46   ` Laurent Pinchart
@ 2015-12-08 17:47     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 17:47 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, devel

Em Sun, 06 Dec 2015 03:46:28 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 30 August 2015 00:06:48 Mauro Carvalho Chehab wrote:
> > This driver is abusing MEDIA_ENT_T_V4L2_SUBDEV, as it uses a
> > hack to check if the remote entity is a subdev. Get rid of it.
> 
> While I agree with the idea of the patch I don't think this is a hack, it was 
> a totally valid implementation with the existing API.
> 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/staging/media/omap4iss/iss_ipipe.c
> > b/drivers/staging/media/omap4iss/iss_ipipe.c index
> > e1a7b7ba7362..eb91ec48a21e 100644
> > --- a/drivers/staging/media/omap4iss/iss_ipipe.c
> > +++ b/drivers/staging/media/omap4iss/iss_ipipe.c
> > @@ -447,8 +447,11 @@ static int ipipe_link_setup(struct media_entity
> > *entity, struct iss_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
> >  	struct iss_device *iss = to_iss_device(ipipe);
> > 
> > -	switch (local->index | media_entity_type(remote->entity)) {
> > -	case IPIPE_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	if (!is_media_entity_v4l2_subdev(remote->entity))
> > +		return -EINVAL;
> > +
> 
> Furthermore the ipipe entity is never connected to anything else than a 
> subdev, so you can remove this check completely.
> 
> I'd rewrite the subject line as "omap4iss: ipipe: Don't check entity type 
> needlessly during link setup" and update the commit message accordingly.


The same rationale as patch 36/55: if one would later add some other
subsystem to the pipeline, the check will be needed. So, better to have
the check here.

I'm changing the description of this patch to:

[media] omap4iss: change the logic that checks if an entity is a subdev

As we're getting rid of an specific number range for the V4L2 subdev,
we need to replace the check for MEDIA_ENT_T_V4L2_SUBDEV by a macro.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

> 
> > +	switch (local->index) {
> > +	case IPIPE_PAD_SINK:
> >  		/* Read from IPIPEIF. */
> >  		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
> >  			ipipe->input = IPIPE_INPUT_NONE;
> > @@ -463,7 +466,7 @@ static int ipipe_link_setup(struct media_entity *entity,
> > 
> >  		break;
> > 
> > -	case IPIPE_PAD_SOURCE_VP | MEDIA_ENT_T_V4L2_SUBDEV:
> > +	case IPIPE_PAD_SOURCE_VP:
> >  		/* Send to RESIZER */
> >  		if (flags & MEDIA_LNK_FL_ENABLED) {
> >  			if (ipipe->output & ~IPIPE_OUTPUT_VP)
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 41/55] [media] DocBook: update descriptions for the media controller entities
  2015-12-06  1:00       ` Laurent Pinchart
@ 2015-12-08 18:04         ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 18:04 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Hans Verkuil, Linux Media Mailing List, Jonathan Corbet, linux-doc

Em Sun, 06 Dec 2015 03:00:57 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hello,
> 
> On Friday 11 September 2015 15:13:30 Hans Verkuil wrote:
> > On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> > > Cleanup the media controller entities description:
> > > - remove MEDIA_ENT_T_DEVNODE and MEDIA_ENT_T_V4L2_SUBDEV entity
> > >   types, as they don't mean anything;
> > > - add MEDIA_ENT_T_UNKNOWN with a proper description;
> > > - remove ALSA and FB entity types. Those should not be used, as
> > >   the types are deprecated. We'll soon be adidng ALSA, but with
> > >   a different entity namespace;
> > > - improve the description of some entities.
> > > 
> > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > 
> > > diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> > > b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml index
> > > 32a783635649..bc101516e372 100644
> > > --- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> > > +++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
> > > @@ -179,70 +179,65 @@
> > >          <colspec colname="c2"/>
> > >  	<tbody valign="top">
> > >  	  <row>
> > > -	    <entry><constant>MEDIA_ENT_T_DEVNODE</constant></entry>
> > > -	    <entry>Unknown device node</entry>
> > > +	    <entry><constant>MEDIA_ENT_T_UNKNOWN</constant> and
> > > <constant>MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN</constant></entry> +	   
> > > <entry>Unknown entity. That generally indicates that
> > > +	    a driver didn't initialize properly the entity, with is a Kernel
> > > bug</entry>> 
> > >  	  </row>
> > 
> > I'm wondering: if userspace should never see an unknown entity, wouldn't it
> > be better to move these UNKNOWN defines out of the public header to a kernel
> > header and drop this from the documentation?
> 
> And shouldn't the bug be caught in kernelspace before it reaches the user ?

I don't like the idea of moving this to a Kernel header.

Yes, ideally, the user should never saw this, but IMHO, programs
should address this somehow, instead of simply crashing if such value
is found. Also, keeping this at documentation helps to inform developers
that this value is invalid and should never be present on any driver.

It should be noticed that getting rid of MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN
is not easy, and should be addressed on a separate patchset. It
requires each driver maintainer to check and fix the non-initialized
subdevices, and add new definitions at the public header. This will take
a while, and such work is independent on the actual MC next gen
patch series.

So, better to keep it documented there, at least while we're not
able to enforce the Kernel do do a BUG_ON() or something similar
if a driver doesn't fill the entity type/function.

> 
> > >  	  <row>
> > >  	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
> > > -	    <entry>V4L video, radio or vbi device node</entry>
> > > +	    <entry>V4L video streaming input or output entity</entry>
> > >  	  </row>
> > > -	  <row>
> > > -	    <entry><constant>MEDIA_ENT_T_DEVNODE_FB</constant></entry>
> > > -	    <entry>Frame buffer device node</entry>
> > > +	    <entry><constant>MEDIA_ENT_T_V4L2_VBI</constant></entry>
> > > +	    <entry>V4L VBI streaming input or output entity</entry>
> > >  	  </row>
> > > -	  <row>
> > > -	    <entry><constant>MEDIA_ENT_T_DEVNODE_ALSA</constant></entry>
> > > -	    <entry>ALSA card</entry>
> > > +	    <entry><constant>MEDIA_ENT_T_V4L2_SWRADIO</constant></entry>
> > > +	    <entry>V4L Sofware Digital Radio (SDR) streaming input or output
> > > entity</entry>
> >
> > s/Sofware/Software/
> > 
> > >  	  </row>
> > >  	  <row>
> > >  	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD</constant></entry>
> > > -	    <entry>DVB frontend devnode</entry>
> > > +	    <entry>DVB demodulator entity</entry>
> > >  	  </row>
> > >  	  <row>
> > >  	    <entry><constant>MEDIA_ENT_T_DVB_DEMUX</constant></entry>
> > > -	    <entry>DVB demux devnode</entry>
> > > +	    <entry>DVB demux entity. Could be implemented on hardware or in
> > > Kernelspace</entry>
> 
> s/Could be/Can be/
> 
> > s/on/in/
> > 
> > >  	  </row>
> > >  	  <row>
> > >  	    <entry><constant>MEDIA_ENT_T_DVB_TSOUT</constant></entry>
> > > -	    <entry>DVB DVR devnode</entry>
> > > +	    <entry>DVB Transport Stream output entity</entry>
> > >  	  </row>
> > >  	  <row>
> > >  	    <entry><constant>MEDIA_ENT_T_DVB_CA</constant></entry>
> > > -	    <entry>DVB CAM devnode</entry>
> > > +	    <entry>DVB Conditional Access module (CAM) entity</entry>
> > >  	  </row>
> > >  	  <row>
> > >  	    
> <entry><constant>MEDIA_ENT_T_DVB_DEMOD_NET_DECAP</constant></entry>
> > > -	    <entry>DVB network devnode</entry>
> > > -	  </row>
> > > -	  <row>
> > > -	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV</constant></entry>
> > > -	    <entry>Unknown V4L sub-device</entry>
> > > +	    <entry>DVB network ULE/MLE desencapsulation entity. Could be
> > > implemented on hardware or in Kernelspace</entry>
> 
> s/Could be/Can be/
> 
> > s/on/in/
> > 
> > Hmm, is desencapsulation correct? Could it be 'de-encapsulation' instead? It
> > looks weird.
> >
> > >  	  </row>
> > >  	  <row>
> > >  	    
> <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_SENSOR</constant></entry>
> > > -	    <entry>Video sensor</entry>
> > > +	    <entry>Camera video sensor entity</entry>
> 
> s/video sensor/image sensor/
> 
> > >  	  </row>
> > >  	  <row>
> > >  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_FLASH</constant></entry>
> > > -	    <entry>Flash controller</entry>
> > > +	    <entry>Flash controller entity</entry>
> > >  	  </row>
> > >  	  <row>
> > >  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_LENS</constant></entry>
> > > -	    <entry>Lens controller</entry>
> > > +	    <entry>Lens controller entity</entry>
> > >  	  </row>
> > >  	  <row>
> > >  	    
> <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_DECODER</constant></entry>
> > > -	    <entry>Video decoder, the basic function of the video decoder is 
> to
> > > -	    accept analogue video from a wide variety of sources such as
> > > +	    <entry>Analog video decoder, the basic function of the video 
> decoder
> > > +	    is to accept analogue video from a wide variety of sources such 
> as
> > >  	    broadcast, DVD players, cameras and video cassette recorders, in
> > > -	    either NTSC, PAL or HD format and still occasionally SECAM, 
> separate
> > > -	    it into its component parts, luminance and chrominance, and 
> output
> > > +	    either NTSC, PAL, SECAM or HD format, separating the stream
> > > +	    into its component parts, luminance and chrominance, and output
> > >  	    it in some digital video standard, with appropriate embedded 
> timing
> > >  	    signals.</entry>
> 
> Does timing signals refer to synchronization signals ? They don't have to be 
> embedded, do they ?
> 
> > >  	  </row>
> > >  	  <row>
> > >  	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_TUNER</constant></entry>
> > > -	    <entry>TV and/or radio tuner</entry>
> > > +	    <entry>Digital TV, analog TV, radio and/or software radio
> > > tuner</entry>> 
> > >  	  </row>
> > >  	</tbody>
> > >        </tgroup>
> 

Changes done.

New patch follows.

>From 88a5f01638adaf0c5f0fe2dfb34b3a68a2997d8a Mon Sep 17 00:00:00 2001
From: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Date: Thu, 7 May 2015 22:12:40 -0300
Subject: [media] DocBook: update descriptions for the media controller
 entities
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>,
    Mauro Carvalho Chehab <mchehab@infradead.org>

Cleanup the media controller entities description:
- remove MEDIA_ENT_T_DEVNODE and MEDIA_ENT_T_V4L2_SUBDEV entity
  types, as they don't mean anything;
- add MEDIA_ENT_T_UNKNOWN with a proper description;
- remove ALSA and FB entity types. Those should not be used, as
  the types are deprecated. We'll soon be adidng ALSA, but with
  a different entity namespace;
- improve the description of some entities.

Change-Id: I0db7672809b567e04a5f367ff6b31315f7b7be8a
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml |   49 +++++-------
 1 file changed, 22 insertions(+), 27 deletions(-)

--- patchwork.orig/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
+++ patchwork/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
@@ -179,70 +179,65 @@
         <colspec colname="c2"/>
 	<tbody valign="top">
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE</constant></entry>
-	    <entry>Unknown device node</entry>
+	    <entry><constant>MEDIA_ENT_T_UNKNOWN</constant> and <constant>MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN</constant></entry>
+	    <entry>Unknown entity. That generally indicates that
+	    a driver didn't initialize properly the entity, with is a Kernel bug</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
-	    <entry>V4L video, radio or vbi device node</entry>
+	    <entry>V4L video streaming input or output entity</entry>
 	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_FB</constant></entry>
-	    <entry>Frame buffer device node</entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_VBI</constant></entry>
+	    <entry>V4L VBI streaming input or output entity</entry>
 	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_ALSA</constant></entry>
-	    <entry>ALSA card</entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_SWRADIO</constant></entry>
+	    <entry>V4L Software Digital Radio (SDR) streaming input or output entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD</constant></entry>
-	    <entry>DVB frontend devnode</entry>
+	    <entry>DVB demodulator entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMUX</constant></entry>
-	    <entry>DVB demux devnode</entry>
+	    <entry>DVB demux entity. Can be implemented in hardware or in Kernelspace</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_TSOUT</constant></entry>
-	    <entry>DVB DVR devnode</entry>
+	    <entry>DVB Transport Stream output entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_CA</constant></entry>
-	    <entry>DVB CAM devnode</entry>
+	    <entry>DVB Conditional Access module (CAM) entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD_NET_DECAP</constant></entry>
-	    <entry>DVB network devnode</entry>
-	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV</constant></entry>
-	    <entry>Unknown V4L sub-device</entry>
+	    <entry>DVB network ULE/MLE de-encapsulation entity. Can be implemented in hardware or in Kernelspace</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_SENSOR</constant></entry>
-	    <entry>Video sensor</entry>
+	    <entry>Camera image sensor entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_FLASH</constant></entry>
-	    <entry>Flash controller</entry>
+	    <entry>Flash controller entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_LENS</constant></entry>
-	    <entry>Lens controller</entry>
+	    <entry>Lens controller entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_DECODER</constant></entry>
-	    <entry>Video decoder, the basic function of the video decoder is to
-	    accept analogue video from a wide variety of sources such as
+	    <entry>Analog video decoder, the basic function of the video decoder
+	    is to accept analogue video from a wide variety of sources such as
 	    broadcast, DVD players, cameras and video cassette recorders, in
-	    either NTSC, PAL or HD format and still occasionally SECAM, separate
-	    it into its component parts, luminance and chrominance, and output
-	    it in some digital video standard, with appropriate embedded timing
+	    either NTSC, PAL, SECAM or HD format, separating the stream
+	    into its component parts, luminance and chrominance, and output
+	    it in some digital video standard, with appropriate timing
 	    signals.</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_TUNER</constant></entry>
-	    <entry>TV and/or radio tuner</entry>
+	    <entry>Digital TV, analog TV, radio and/or software radio tuner</entry>
 	  </row>
 	</tbody>
       </tgroup>



^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 43/55] [media] media: report if a pad is sink or source at debug msg
  2015-12-06  0:53     ` Laurent Pinchart
@ 2015-12-08 18:46       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 18:46 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List

Em Sun, 06 Dec 2015 02:53:57 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 06 September 2015 09:03:03 Mauro Carvalho Chehab wrote:
> > Sometimes, it is important to see if the created pad is
> > sink or source. Add info to track that.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index d8038a53f945..6ed5eef88593 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -121,8 +121,11 @@ static void dev_dbg_obj(const char *event_name,  struct
> > media_gobj *gobj) struct media_pad *pad = gobj_to_pad(gobj);
> > 
> >  		dev_dbg(gobj->mdev->dev,
> > -			"%s: id 0x%08x pad#%d: '%s':%d\n",
> > -			event_name, gobj->id, media_localid(gobj),
> > +			"%s: id 0x%08x %s%spad#%d: '%s':%d\n",
> > +			event_name, gobj->id,
> > +			pad->flags & MEDIA_PAD_FL_SINK   ? "  sink " : "",
> > +			pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
> 
> I'm wondering if we really need the two leading spaces in "  sink ", as a 
> bidirectional pad would print "  sink source pad" and mess up the alignment 
> anyway.

Good point. Right now, we don't have any bidirectional pad. For now, this
looks nicer and makes easier to check the logs. So, I prefer to keep it
as-is for now.

We can change it later, when we add bidirectional pads.

> 
> > +			media_localid(gobj),
> >  			pad->entity->name, pad->index);
> >  		break;
> >  	}
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
  2015-12-06  0:47       ` Laurent Pinchart
  (?)
@ 2015-12-08 19:23       ` Mauro Carvalho Chehab
  2015-12-08 19:48           ` Arnd Bergmann
  -1 siblings, 1 reply; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 19:23 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List, linux-api

Em Sun, 06 Dec 2015 02:47:39 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 06 September 2015 09:03:04 Mauro Carvalho Chehab wrote:
> > Add a new ioctl that will report the entire topology on
> > one go.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index 7320cdc45833..2d5ad40254b7 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -181,6 +181,8 @@ struct media_interface {
> >   */
> >  struct media_intf_devnode {
> >  	struct media_interface		intf;
> > +
> > +	/* Should match the fields at media_v2_intf_devnode */
> >  	u32				major;
> >  	u32				minor;
> >  };
> > diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> > index a1bd7afba110..b17f6763aff4 100644
> > --- a/include/uapi/linux/media.h
> > +++ b/include/uapi/linux/media.h
> > @@ -206,6 +206,10 @@ struct media_pad_desc {
> >  #define MEDIA_LNK_FL_IMMUTABLE		(1 << 1)
> >  #define MEDIA_LNK_FL_DYNAMIC		(1 << 2)
> > 
> > +#define MEDIA_LNK_FL_LINK_TYPE		(0xf << 28)
> > +#  define MEDIA_LNK_FL_DATA_LINK	(0 << 28)
> > +#  define MEDIA_LNK_FL_INTERFACE_LINK	(1 << 28)
> > +
> >  struct media_link_desc {
> >  	struct media_pad_desc source;
> >  	struct media_pad_desc sink;
> > @@ -249,11 +253,93 @@ struct media_links_enum {
> >  #define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
> >  #define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
> > 
> > -/* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
> > +/*
> > + * MC next gen API definitions
> > + *
> > + * NOTE: The declarations below are close to the MC RFC for the Media
> > + *	 Controller, the next generation. Yet, there are a few adjustments
> > + *	 to do, as we want to be able to have a functional API before
> > + *	 the MC properties change. Those will be properly marked below.
> > + *	 Please also notice that I removed "num_pads", "num_links",
> > + *	 from the proposal, as a proper userspace application will likely
> > + *	 use lists for pads/links, just as we intend to do in Kernelspace.
> > + *	 The API definition should be freed from fields that are bound to
> > + *	 some specific data structure.
> > + *
> > + * FIXME: Currently, I opted to name the new types as "media_v2", as this
> > + *	  won't cause any conflict with the Kernelspace namespace, nor with
> > + *	  the previous kAPI media_*_desc namespace. This can be changed
> > + *	  later, before the adding this API upstream.
> 
> Yes, that's a good idea. Or at least we need to remove this comment if we 
> decide to keep the v2 names :-)

True ;)

> 
> > + */
> > +
> > +
> > +struct media_v2_entity {
> > +	__u32 id;
> > +	char name[64];		/* FIXME: move to a property? (RFC says so) */
> 
> I agree with Sakari that we can keep the name here even if we also expose it 
> as a property. However, there's one issue we need to address : we need to 
> clearly define what the name field should contain and how it should be 
> constructed, otherwise we'll end up with the exact same mess as today, and I 
> don't want that. We can discuss it in this mail thread or as replies to a 
> future documentation patch.


Well, let's discuss it then. What's your proposal?

I guess there are actually some different goals that we want to archive
with "name":

1) an ideally short name used when displaying an entity on some graph. 
It would be good if such "short name" would be unique, but it won't
hurt much if such name is not unique;

2) an unique ID identifier that will likely take the position of an
entity inside the machine bus, like PCI ID, USB ID, I2C bus + I2C addr...

I guess such UID would be better addressed via properties, as it
would likely be constructed in userspace via a different set of
properties, depending on the device and/or bus type.

> 
> > +	__u16 reserved[14];
> 
> Sakari and Hans have already commented on using __u32 instead of __u16 for 
> reserved fields, as well as on the number of reserved fields. I agree with 
> them but have nothing to add.

Ok. I'll change this on a later patch.

> 
> > +};
> > +
> > +/* Should match the specific fields at media_intf_devnode */
> > +struct media_v2_intf_devnode {
> > +	__u32 major;
> > +	__u32 minor;
> > +};
> > +
> > +struct media_v2_interface {
> > +	__u32 id;
> > +	__u32 intf_type;
> > +	__u32 flags;
> > +	__u32 reserved[9];
> > +
> > +	union {
> > +		struct media_v2_intf_devnode devnode;
> > +		__u32 raw[16];
> > +	};
> > +};
> > +
> > +struct media_v2_pad {
> > +	__u32 id;
> > +	__u32 entity_id;
> > +	__u32 flags;
> > +	__u16 reserved[9];
> > +};
> > +
> > +struct media_v2_link {
> > +    __u32 id;
> > +    __u32 source_id;
> > +    __u32 sink_id;
> > +    __u32 flags;
> > +    __u32 reserved[5];
> > +};
> > +
> > +struct media_v2_topology {
> > +	__u32 topology_version;
> > +
> > +	__u32 num_entities;
> > +	struct media_v2_entity *entities;
> 
> The kernel seems to be moving to using __u64 instead of pointers in userspace-
> facing structures to avoid compat32 code.

We had such discussion at the MC summit. I don't object to change to
__u64, but we need to reach a consensus ;)

> 
> > +
> > +	__u32 num_interfaces;
> > +	struct media_v2_interface *interfaces;
> > +
> > +	__u32 num_pads;
> > +	struct media_v2_pad *pads;
> > +
> > +	__u32 num_links;
> > +	struct media_v2_link *links;
> > +
> > +	struct {
> > +		__u32 reserved_num;
> > +		void *reserved_ptr;
> > +	} reserved_types[16];
> > +	__u32 reserved[8];
> 
> I'd just create __u32 reserved fields without any reserved_types, we can 
> always use the reserved fields to add new types later.

It used to be __u32... Hans requested to change it to an struct.

Btw, I also prefer to use __u32 here ;)

> 
> > +};
> > +
> > +/* ioctls */
> > 
> >  #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct 
> media_device_info)
> >  #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct 
> media_entity_desc)
> > #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
> > #define MEDIA_IOC_SETUP_LINK		_IOWR('|', 0x03, struct media_link_desc)
> > +#define MEDIA_IOC_G_TOPOLOGY		_IOWR('|', 0x04, struct media_v2_topology)
> > 
> >  #endif /* __LINUX_MEDIA_H */
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 46/55] [media] media: move mdev list init to gobj
  2015-11-23 22:32     ` Laurent Pinchart
@ 2015-12-08 19:31       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 19:31 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List

Em Tue, 24 Nov 2015 00:32:49 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 06 September 2015 09:03:06 Mauro Carvalho Chehab wrote:
> > Let's control the topology changes inside the graph_object. So, move the
> > addition and removal of interfaces/entities from the mdev lists to
> > media_gobj_init() and media_gobj_remove().
> > 
> > The main reason is that mdev should have lists for all object types, as
> > the new MC api will require to store objects in separate places.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index 134fe7510195..ec98595b8a7a 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -415,7 +415,7 @@ void media_device_unregister(struct media_device *mdev)
> >  	struct media_entity *entity;
> >  	struct media_entity *next;
> > 
> > -	list_for_each_entry_safe(entity, next, &mdev->entities, list)
> > +	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
> >  		media_device_unregister_entity(entity);
> > 
> >  	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
> > @@ -449,7 +449,6 @@ int __must_check media_device_register_entity(struct
> > media_device *mdev, spin_lock(&mdev->lock);
> >  	/* Initialize media_gobj embedded at the entity */
> >  	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
> > -	list_add_tail(&entity->list, &mdev->entities);
> > 
> >  	/* Initialize objects at the pads */
> >  	for (i = 0; i < entity->num_pads; i++)
> > @@ -487,7 +486,6 @@ void media_device_unregister_entity(struct media_entity
> > *entity) for (i = 0; i < entity->num_pads; i++)
> >  		media_gobj_remove(&entity->pads[i].graph_obj);
> >  	media_gobj_remove(&entity->graph_obj);
> > -	list_del(&entity->list);
> >  	spin_unlock(&mdev->lock);
> >  	entity->graph_obj.mdev = NULL;
> >  }
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index 6ed5eef88593..cbb0604e81c1 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -170,6 +170,7 @@ void media_gobj_init(struct media_device *mdev,
> >  	switch (type) {
> >  	case MEDIA_GRAPH_ENTITY:
> >  		gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
> > +		list_add_tail(&gobj->list, &mdev->entities);
> >  		break;
> >  	case MEDIA_GRAPH_PAD:
> >  		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
> > @@ -178,6 +179,7 @@ void media_gobj_init(struct media_device *mdev,
> >  		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
> >  		break;
> >  	case MEDIA_GRAPH_INTF_DEVNODE:
> > +		list_add_tail(&gobj->list, &mdev->interfaces);
> >  		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
> >  		break;
> >  	}
> > @@ -193,6 +195,16 @@ void media_gobj_init(struct media_device *mdev,
> >   */
> >  void media_gobj_remove(struct media_gobj *gobj)
> >  {
> > +	/* Remove the object from mdev list */
> > +	switch (media_type(gobj)) {
> > +	case MEDIA_GRAPH_ENTITY:
> > +	case MEDIA_GRAPH_INTF_DEVNODE:
> > +		list_del(&gobj->list);
> > +		break;
> 
> Type-specific handling in the graph object code doesn't seem right. I'd keep 
> the list_del calls in the type-specific remove functions. Same for the 
> list_add_tail calls above, unless we switch from per-type lists to a single 
> graph objects list as I mentioned in a reply to another patch (and the more I 
> think about it the more tempting it gets).

I commented about that already. IMHO, keeping everything needed to
unregister a graph object is the way to go, as it saves troubles of
having type-specific unregister functions for everything, and the
state of the object removal will be sane after the end of calling
this function.

Using a single graph object list decreases the performance, as
already explained.

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
@ 2015-12-08 19:48           ` Arnd Bergmann
  0 siblings, 0 replies; 309+ messages in thread
From: Arnd Bergmann @ 2015-12-08 19:48 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Laurent Pinchart, Linux Media Mailing List, linux-api

On Tuesday 08 December 2015 17:23:40 Mauro Carvalho Chehab wrote:
> > > +
> > > +struct media_v2_topology {
> > > +   __u32 topology_version;
> > > +
> > > +   __u32 num_entities;
> > > +   struct media_v2_entity *entities;
> > 
> > The kernel seems to be moving to using __u64 instead of pointers in userspace-
> > facing structures to avoid compat32 code.
> 
> We had such discussion at the MC summit. I don't object to change to
> __u64, but we need to reach a consensus 
> 

Just saw the email fly by. Using a __u64 to pass a pointer is generally
the preferred method for most subsystems these days.

However, that means you probably want to extract the pointer from
that using something like

static inline void __user *get_upointer(u64 arg)
{
	return (void __user *)(uintptr_t)arg;
}

This is the only way that I know that works on both 32-bit and 64-bit
architectures as well as the oddball s390 compat mode (which you don't
care about because there are no media devices on s390).

	Arnd

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl
@ 2015-12-08 19:48           ` Arnd Bergmann
  0 siblings, 0 replies; 309+ messages in thread
From: Arnd Bergmann @ 2015-12-08 19:48 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Laurent Pinchart, Linux Media Mailing List,
	linux-api-u79uwXL29TY76Z2rM5mHXA

On Tuesday 08 December 2015 17:23:40 Mauro Carvalho Chehab wrote:
> > > +
> > > +struct media_v2_topology {
> > > +   __u32 topology_version;
> > > +
> > > +   __u32 num_entities;
> > > +   struct media_v2_entity *entities;
> > 
> > The kernel seems to be moving to using __u64 instead of pointers in userspace-
> > facing structures to avoid compat32 code.
> 
> We had such discussion at the MC summit. I don't object to change to
> __u64, but we need to reach a consensus 
> 

Just saw the email fly by. Using a __u64 to pass a pointer is generally
the preferred method for most subsystems these days.

However, that means you probably want to extract the pointer from
that using something like

static inline void __user *get_upointer(u64 arg)
{
	return (void __user *)(uintptr_t)arg;
}

This is the only way that I know that works on both 32-bit and 64-bit
architectures as well as the oddball s390 compat mode (which you don't
care about because there are no media devices on s390).

	Arnd

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 48/55] [media] media_device: add a topology version field
  2015-11-23 22:18           ` Laurent Pinchart
@ 2015-12-08 20:05             ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 20:05 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Hans Verkuil, Linux Media Mailing List, Mauro Carvalho Chehab,
	Javier Martinez Canillas

Em Tue, 24 Nov 2015 00:18:07 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> On Friday 04 September 2015 14:08:27 Mauro Carvalho Chehab wrote:
> > Em Mon, 31 Aug 2015 15:35:38 +0200 Hans Verkuil escreveu:
> > > On 08/31/2015 02:52 PM, Mauro Carvalho Chehab wrote:
> > >> Em Mon, 31 Aug 2015 14:29:28 +0200 Hans Verkuil escreveu:
> > >>> On 08/30/2015 05:06 AM, Mauro Carvalho Chehab wrote:
> > >>>> Every time a graph object is added or removed, the version
> > >>>> of the topology changes. That's a requirement for the new
> > >>>> MEDIA_IOC_G_TOPOLOGY, in order to allow userspace to know
> > >>>> that the topology has changed after a previous call to it.
> > >>>> 
> > >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > >>> 
> > >>> I think this should be postponed until we actually have dynamic
> > >>> reconfigurable graphs.
> > >> 
> > >> So far, we're using the term "dynamic" to mean partial graph object
> > >> removal.
> > >> 
> > >> But even today, MC does support "dynamic" in the sense of graph object
> > >> additions.
> > >> 
> > >> You should notice that having a topology_version is something that IMHO,
> > >> it is needed since the beginning, even without dynamic reconfigurable
> > >> graphs, because the graph may grow in runtime.
> > >> 
> > >> That will happen, for example, if usb-snd-audio is blacklisted at
> > >> /etc/modprobe*, and someone connects an au0828.
> > >> 
> > >> New entities/links will be created (after Shuah patches) if one would
> > >> modprobe latter snd-usb-audio.
> > > 
> > > latter -> later :-)
> > > 
> > > You are right, this would trigger a topology change. I hadn't thought
> > > about that.
> 
> First of all it won't be very useful without a topology change notification, 
> so until we have them it doesn't matter too much.

I'm not sure if we need an explicit topology change notification. The
way I see, we just need to add a topology_version at SET_LINK_V2. The
topology should be filled by userspace, based on the last topology from
G_TOPOLOGY.

If topology_version is different than the one at Kernelspace, Kernel
will return an error that would cause userspace to call G_TOPOLOGY
again.

Ok, a topology notification could be added in order to help userspace
to detect changes, but this is an unrelated.

> Then, the code is full of 
> race conditions when it comes to dynamic updates, and I'm afraid Shua's 
> patches can't go in before we fix them.

The race conditions are related to dynamic removal. Dynamic creation
should be OK.

We'll review the locks to be sure that this would work fine.

> 
> > >>> I would also like to reserve version 0: if 0 is returned, then the graph
> > >>> is static.
> > >> 
> > >> Why? Implementing this would be really hard, as that would mean that
> > >> G_TOPOLOGY would need to be blocked until all drivers and subdevices get
> > >> probed.
> > >> 
> > >> In order to implement that, some logic would be needed at the drivers to
> > >> identify if everything was set and unlock G_TOPOLOGY.
> > > 
> > > That wouldn't be needed if the media device node was created last. Which I
> > > think is a good idea anyway.
> > 
> > Creating the media device node last won't work. It should be the first thing
> > to be created, as all objects should be added to media_device linked lists.
> 
> I disagree with that. The media_device needs to be initialized first, but can 
> be registered with userspace last. We don't want to generate a topology update 
> event for every new entity, link or pad during the device probe sequence. 
> Drivers should be in control and tell when they're done with initialization.

This comment is outdated ;)

Javier wrote a patch series already addressing this: it basically splits
the internal registration from the userspace API registration. 

See:
	[PATCH v4 0/2] [media] Fix race between graph enumeration and entities registration


The idea is to postpone the latter to happen after having all 
entitites/links/subdevices created.

It is unrelated to the MC next gen, so he submitted in separate. I guess Sakari
already acked his patches.

I'll be merging his series after finishing the merge of MC next gen.

> 
> > Also, the numberspace should be local to a given media_device, as the graph
> > traversal algorithm relies on having the number of entities <= 64,
> > currently, in order to be able to detect loops. We should increase that
> > number, but removing an "as low as possible" entity number limit is not
> > trivial.
> > 
> > > > What would be the gain for that? I fail to see any.
> > > 
> > > It would tell userspace that it doesn't have to cope with dynamically
> > > changing graphs.
> > > 
> > > Even though with the au0828 example you can expect to see cases like that,
> > > I can pretty much guarantee that no generic v4l2 applications will ever
> > > support dynamic changes.
> > 
> > Well, my test app supports it and it is generic ;) My plan is to use it as a
> > basis for the library to be used on userspace for generic apps, extending it
> > to be used by other tools like xawtv, qv4l2 and the dvbv5 apps.
> > 
> > I don't think it is hard to handle it on a generic app,
> 
> I'll quote you later on that :-)
> 
> > and this should be done anyway if we want dynamic support.
> >
> > The logic seems actually be simple:
> > 
> > at G_TOPOLOGY, if the topology changes, reload the objects;
> 
> And update everything in userspace. That's a very hard task if you don't 
> design your applications extremely carefully.

True.

> 
> > at SETUP_LINK_V2, the topology will be sent. if the driver detects that
> > topology changed, it returns an error.
> > 
> > The caller will then need to reload the topology and re-apply the
> > transaction to select the links, if the entities affected still exists. In
> > other words, if the user's intent were to change the pipeline to receive the
> > data at /dev/video2, e. g. something like:
> > 	./yavta/yavta -f UYVY -s 720x312 -n 1 --capture=1 -F /dev/video2
> > 
> > What userspace would do is to reload everything, check if /dev/video2 still
> > exists and then redo the function that it is equivalent to the above
> > command, failing otherwise. That doesn't sound hard to implement.
> > 
> > > Those that will support it will be custom-made.
> > > 
> > > Being able to see that graphs can change dynamically would allow such apps
> > > to either refuse to use the device, or warn the user.
> > 
> > The way I see is that applications that will assume that the graph
> > is static will be the custom-made ones.
> 
> Or (some of) the generic ones.

If the app doesn't support dynamic changes, it is not generic, as it
will only support simple graphs that are provided by just a single driver.

> 
> > As they know the hardware, they can just either ignore the topology_version
> > or wait for it to stabilize when the hardware is still being probed.
> > 
> > In any case, if we end by needing to have an explicit way for the
> > Kernelspace to tell userspace that a graph is static, that could be done via
> > an extra flag at MEDIA_INFO.
> 
> Why ? I don't see anything wrong with reversing version 0 for that purpose, as 
> Hans proposed.

Well, we can do that: we can zero the topology_version at
media_device_register() (see Javier's patch "media-device: split media
initialization and registration")

This way, topology_version will be zero if the topology never changed
after registering the media controller userspace API.

That doesn't warrant that the topology will never change. Such change
will happen, for example, during driver (or sub-driver) removal
or unbind. Taking this into account, I doubt that we have any driver
that has a static topology, because the driver can be removed and/or
unbind from the hardware.

> 
> > Enabling this flag could be as easy as waiting for all graph elements to be
> > created (where the topology is still dynamic), and raise such flag after
> > finishing the probe sequence.
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-11-23 22:04     ` Laurent Pinchart
@ 2015-12-08 20:17       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 20:17 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List

Em Tue, 24 Nov 2015 00:04:02 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> Sakari and Hans have made several comments on this and the previous version of 
> the same patch and I generally agree with them. I'll thus review the next 
> version.

What next version? If I got it right, the issues that Sailus commented
are related to future implementations, needed if/when we need to have
dynamic PADs.

We're not adding support for dynamic PADs for now.

So, I don't have anything planned to change on this patch.

Regards,
Mauro

> 
> On Sunday 06 September 2015 09:03:09 Mauro Carvalho Chehab wrote:
> > Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
> > with the RFC for the MC next generation.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index 5b2c9f7fcd45..96a476eeb16e 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -232,6 +232,156 @@ static long media_device_setup_link(struct
> > media_device *mdev, return ret;
> >  }
> > 
> > +static long __media_device_get_topology(struct media_device *mdev,
> > +				      struct media_v2_topology *topo)
> > +{
> > +	struct media_entity *entity;
> > +	struct media_interface *intf;
> > +	struct media_pad *pad;
> > +	struct media_link *link;
> > +	struct media_v2_entity uentity;
> > +	struct media_v2_interface uintf;
> > +	struct media_v2_pad upad;
> > +	struct media_v2_link ulink;
> > +	int ret = 0, i;
> > +
> > +	topo->topology_version = mdev->topology_version;
> > +
> > +	/* Get entities and number of entities */
> > +	i = 0;
> > +	media_device_for_each_entity(entity, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->entities)
> > +			continue;
> > +
> > +		if (i > topo->num_entities) {
> > +			ret = -ENOSPC;
> > +			continue;
> > +		}
> > +
> > +		/* Copy fields to userspace struct if not error */
> > +		memset(&uentity, 0, sizeof(uentity));
> > +		uentity.id = entity->graph_obj.id;
> > +		strncpy(uentity.name, entity->name,
> > +			sizeof(uentity.name));
> > +
> > +		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_entities = i;
> > +
> > +	/* Get interfaces and number of interfaces */
> > +	i = 0;
> > +	media_device_for_each_intf(intf, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->interfaces)
> > +			continue;
> > +
> > +		if (i > topo->num_interfaces) {
> > +			ret = -ENOSPC;
> > +			continue;
> > +		}
> > +
> > +		memset(&uintf, 0, sizeof(uintf));
> > +
> > +		/* Copy intf fields to userspace struct */
> > +		uintf.id = intf->graph_obj.id;
> > +		uintf.intf_type = intf->type;
> > +		uintf.flags = intf->flags;
> > +
> > +		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
> > +			struct media_intf_devnode *devnode;
> > +
> > +			devnode = intf_to_devnode(intf);
> > +
> > +			uintf.devnode.major = devnode->major;
> > +			uintf.devnode.minor = devnode->minor;
> > +		}
> > +
> > +		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_interfaces = i;
> > +
> > +	/* Get pads and number of pads */
> > +	i = 0;
> > +	media_device_for_each_pad(pad, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->pads)
> > +			continue;
> > +
> > +		if (i > topo->num_pads) {
> > +			ret = -ENOSPC;
> > +			continue;
> > +		}
> > +
> > +		memset(&upad, 0, sizeof(upad));
> > +
> > +		/* Copy pad fields to userspace struct */
> > +		upad.id = pad->graph_obj.id;
> > +		upad.entity_id = pad->entity->graph_obj.id;
> > +		upad.flags = pad->flags;
> > +
> > +		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_pads = i;
> > +
> > +	/* Get links and number of links */
> > +	i = 0;
> > +	media_device_for_each_link(link, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->links)
> > +			continue;
> > +
> > +		if (i > topo->num_links) {
> > +			ret = -ENOSPC;
> > +			continue;
> > +		}
> > +
> > +		memset(&ulink, 0, sizeof(ulink));
> > +
> > +		/* Copy link fields to userspace struct */
> > +		ulink.id = link->graph_obj.id;
> > +		ulink.source_id = link->gobj0->id;
> > +		ulink.sink_id = link->gobj1->id;
> > +		ulink.flags = link->flags;
> > +
> > +		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
> > +			ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;
> > +
> > +		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_links = i;
> > +
> > +	return ret;
> > +}
> > +
> > +static long media_device_get_topology(struct media_device *mdev,
> > +				      struct media_v2_topology __user *utopo)
> > +{
> > +	struct media_v2_topology ktopo;
> > +	int ret;
> > +
> > +	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
> > +
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	ret = __media_device_get_topology(mdev, &ktopo);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));
> > +
> > +	return ret;
> > +}
> > +
> >  static long media_device_ioctl(struct file *filp, unsigned int cmd,
> >  			       unsigned long arg)
> >  {
> > @@ -264,6 +414,13 @@ static long media_device_ioctl(struct file *filp,
> > unsigned int cmd, mutex_unlock(&dev->graph_mutex);
> >  		break;
> > 
> > +	case MEDIA_IOC_G_TOPOLOGY:
> > +		mutex_lock(&dev->graph_mutex);
> > +		ret = media_device_get_topology(dev,
> > +				(struct media_v2_topology __user *)arg);
> > +		mutex_unlock(&dev->graph_mutex);
> > +		break;
> > +
> >  	default:
> >  		ret = -ENOIOCTLCMD;
> >  	}
> > @@ -312,6 +469,7 @@ static long media_device_compat_ioctl(struct file *filp,
> > unsigned int cmd, case MEDIA_IOC_DEVICE_INFO:
> >  	case MEDIA_IOC_ENUM_ENTITIES:
> >  	case MEDIA_IOC_SETUP_LINK:
> > +	case MEDIA_IOC_G_TOPOLOGY:
> >  		return media_device_ioctl(filp, cmd, arg);
> > 
> >  	case MEDIA_IOC_ENUM_LINKS32:
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl
  2015-09-11 14:08     ` Hans Verkuil
@ 2015-12-08 20:20       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 20:20 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Linux Media Mailing List

Em Fri, 11 Sep 2015 16:08:54 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 09/06/2015 02:03 PM, Mauro Carvalho Chehab wrote:
> > Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
> > with the RFC for the MC next generation.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> Two comments:
> 
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index 5b2c9f7fcd45..96a476eeb16e 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
> >  	return ret;
> >  }
> >  
> > +static long __media_device_get_topology(struct media_device *mdev,
> > +				      struct media_v2_topology *topo)
> > +{
> > +	struct media_entity *entity;
> > +	struct media_interface *intf;
> > +	struct media_pad *pad;
> > +	struct media_link *link;
> > +	struct media_v2_entity uentity;
> > +	struct media_v2_interface uintf;
> > +	struct media_v2_pad upad;
> > +	struct media_v2_link ulink;
> > +	int ret = 0, i;
> > +
> > +	topo->topology_version = mdev->topology_version;
> > +
> > +	/* Get entities and number of entities */
> > +	i = 0;
> > +	media_device_for_each_entity(entity, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->entities)
> > +			continue;
> > +
> > +		if (i > topo->num_entities) {
> > +			ret = -ENOSPC;
> > +			continue;
> > +		}
> > +
> > +		/* Copy fields to userspace struct if not error */
> > +		memset(&uentity, 0, sizeof(uentity));
> > +		uentity.id = entity->graph_obj.id;
> > +		strncpy(uentity.name, entity->name,
> > +			sizeof(uentity.name));
> > +
> > +		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_entities = i;
> > +
> > +	/* Get interfaces and number of interfaces */
> > +	i = 0;
> > +	media_device_for_each_intf(intf, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->interfaces)
> > +			continue;
> > +
> > +		if (i > topo->num_interfaces) {
> > +			ret = -ENOSPC;
> > +			continue;
> > +		}
> > +
> > +		memset(&uintf, 0, sizeof(uintf));
> > +
> > +		/* Copy intf fields to userspace struct */
> > +		uintf.id = intf->graph_obj.id;
> > +		uintf.intf_type = intf->type;
> > +		uintf.flags = intf->flags;
> > +
> > +		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
> > +			struct media_intf_devnode *devnode;
> > +
> > +			devnode = intf_to_devnode(intf);
> > +
> > +			uintf.devnode.major = devnode->major;
> > +			uintf.devnode.minor = devnode->minor;
> > +		}
> > +
> > +		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_interfaces = i;
> > +
> > +	/* Get pads and number of pads */
> > +	i = 0;
> > +	media_device_for_each_pad(pad, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->pads)
> > +			continue;
> > +
> > +		if (i > topo->num_pads) {
> > +			ret = -ENOSPC;
> > +			continue;
> > +		}
> > +
> > +		memset(&upad, 0, sizeof(upad));
> > +
> > +		/* Copy pad fields to userspace struct */
> > +		upad.id = pad->graph_obj.id;
> > +		upad.entity_id = pad->entity->graph_obj.id;
> > +		upad.flags = pad->flags;
> > +
> > +		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_pads = i;
> > +
> > +	/* Get links and number of links */
> > +	i = 0;
> > +	media_device_for_each_link(link, mdev) {
> > +		i++;
> > +
> > +		if (ret || !topo->links)
> > +			continue;
> > +
> > +		if (i > topo->num_links) {
> > +			ret = -ENOSPC;
> > +			continue;
> > +		}
> > +
> > +		memset(&ulink, 0, sizeof(ulink));
> > +
> > +		/* Copy link fields to userspace struct */
> > +		ulink.id = link->graph_obj.id;
> > +		ulink.source_id = link->gobj0->id;
> > +		ulink.sink_id = link->gobj1->id;
> > +		ulink.flags = link->flags;
> > +
> > +		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
> > +			ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;
> 
> Why isn't this flag part of link->flags? I would expect that when an interface
> link is created the media core code will set this flag automatically.
> 
> It's a bit strange that this flag is set here. Or am I missing something?

Well, this is a flag for the userspace API. The Kernel doesn't
need it. 

I don't object to move it to be set when link gets created on some
followup patch, if needed.

> 
> > +
> > +		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
> > +			ret = -EFAULT;
> > +	}
> > +	topo->num_links = i;
> > +
> > +	return ret;
> > +}
> > +
> > +static long media_device_get_topology(struct media_device *mdev,
> > +				      struct media_v2_topology __user *utopo)
> > +{
> > +	struct media_v2_topology ktopo;
> > +	int ret;
> > +
> > +	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
> > +
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	ret = __media_device_get_topology(mdev, &ktopo);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));
> > +
> > +	return ret;
> > +}
> > +
> >  static long media_device_ioctl(struct file *filp, unsigned int cmd,
> >  			       unsigned long arg)
> >  {
> > @@ -264,6 +414,13 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
> >  		mutex_unlock(&dev->graph_mutex);
> >  		break;
> >  
> > +	case MEDIA_IOC_G_TOPOLOGY:
> > +		mutex_lock(&dev->graph_mutex);
> > +		ret = media_device_get_topology(dev,
> > +				(struct media_v2_topology __user *)arg);
> > +		mutex_unlock(&dev->graph_mutex);
> > +		break;
> > +
> >  	default:
> >  		ret = -ENOIOCTLCMD;
> >  	}
> > @@ -312,6 +469,7 @@ static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
> >  	case MEDIA_IOC_DEVICE_INFO:
> >  	case MEDIA_IOC_ENUM_ENTITIES:
> >  	case MEDIA_IOC_SETUP_LINK:
> > +	case MEDIA_IOC_G_TOPOLOGY:
> >  		return media_device_ioctl(filp, cmd, arg);
> 
> This doesn't work: G_TOPOLOGY needs pointer conversion.

True. I'll address this on a separate patch.

> 
> Regards,
> 
> 	Hans
> 
> >  
> >  	case MEDIA_IOC_ENUM_LINKS32:
> > 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 50/55] [media] media-entity: unregister entity links
  2015-11-23 21:27     ` Laurent Pinchart
@ 2015-12-08 20:23       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-08 20:23 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List

Em Mon, 23 Nov 2015 23:27:40 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 06 September 2015 09:03:10 Mauro Carvalho Chehab wrote:
> > Add functions to explicitly unregister all entity links.
> > This function is called automatically when an entity
> > link is destroyed.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index 064515f2ba9b..a37ccd2edfd5 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -903,6 +903,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
> > 
> >  void media_devnode_remove(struct media_intf_devnode *devnode)
> >  {
> > +	media_remove_intf_links(&devnode->intf);
> >  	media_gobj_remove(&devnode->intf.graph_obj);
> >  	kfree(devnode);
> >  }
> > @@ -944,3 +945,25 @@ void media_remove_intf_link(struct media_link *link)
> >  	mutex_unlock(&link->graph_obj.mdev->graph_mutex);
> >  }
> >  EXPORT_SYMBOL_GPL(media_remove_intf_link);
> > +
> > +void __media_remove_intf_links(struct media_interface *intf)
> > +{
> > +	struct media_link *link, *tmp;
> > +
> > +	list_for_each_entry_safe(link, tmp, &intf->links, list)
> > +		__media_remove_intf_link(link);
> > +
> > +}
> > +EXPORT_SYMBOL_GPL(__media_remove_intf_links);
> 
> The only place where this function is used is in media_remove_intf_links() 
> below. How about inlining it for now ?
> 
> > +void media_remove_intf_links(struct media_interface *intf)
> > +{
> > +	/* Do nothing if the intf is not registered. */
> > +	if (intf->graph_obj.mdev == NULL)
> > +		return;
> > +
> > +	mutex_lock(&intf->graph_obj.mdev->graph_mutex);
> > +	__media_remove_intf_links(intf);
> > +	mutex_unlock(&intf->graph_obj.mdev->graph_mutex);
> > +}
> > +EXPORT_SYMBOL_GPL(media_remove_intf_links);
> 
> As this function is exported it should be documented with kerneldoc.

Will do both on a followup patch.

> 
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index bc7eb6240795..ca4a4f23362f 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -318,6 +318,9 @@ struct media_link *media_create_intf_link(struct
> > media_entity *entity, struct media_interface *intf,
> >  					    u32 flags);
> >  void media_remove_intf_link(struct media_link *link);
> > +void __media_remove_intf_links(struct media_interface *intf);
> > +void media_remove_intf_links(struct media_interface *intf);
> > +
> > 
> >  #define media_entity_call(entity, operation, args...)			\
> >  	(((entity)->ops && (entity)->ops->operation) ?			\
> 

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 52/55] [media] media-device: remove interfaces and interface links
  2015-11-23 21:22     ` Laurent Pinchart
@ 2015-12-09 13:39       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-09 13:39 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Hans Verkuil, Javier Martinez Canillas,
	Shuah Khan

Em Mon, 23 Nov 2015 23:22:56 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 06 September 2015 09:03:12 Mauro Carvalho Chehab wrote:
> > Just like what's done with entities, when the media controller is
> > unregistered, release any interface and interface links that
> > might still be there.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index 7c37aeab05bb..0238885fcc74 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -574,6 +574,22 @@ void media_device_unregister(struct media_device *mdev)
> > {
> >  	struct media_entity *entity;
> >  	struct media_entity *next;
> > +	struct media_link *link, *tmp_link;
> > +	struct media_interface *intf, *tmp_intf;
> > +
> > +	/* Remove interface links from the media device */
> > +	list_for_each_entry_safe(link, tmp_link, &mdev->links,
> > +				 graph_obj.list) {
> > +		media_gobj_remove(&link->graph_obj);
> > +		kfree(link);
> > +	}
> > +
> > +	/* Remove all interfaces from the media device */
> > +	list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces,
> > +				 graph_obj.list) {
> > +		media_gobj_remove(&intf->graph_obj);
> > +		kfree(intf);
> > +	}
> > 
> >  	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
> >  		media_device_unregister_entity(entity);
> > @@ -651,7 +667,6 @@ void media_device_unregister_entity(struct media_entity
> > *entity) /* Remove all data links that belong to this entity */
> >  	list_for_each_entry_safe(link, tmp, &entity->links, list) {
> >  		media_gobj_remove(&link->graph_obj);
> > -		list_del(&link->list);
> >  		kfree(link);
> 
> The link has already been freed in media_device_unregister(). You have access-
> after-free and double-free issues here.
> 
> >  	}
> > 
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index a37ccd2edfd5..cd4d767644df 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -206,6 +206,10 @@ void media_gobj_remove(struct media_gobj *gobj)
> > 
> >  	/* Remove the object from mdev list */
> >  	list_del(&gobj->list);
> > +
> > +	/* Links have their own list - we need to drop them there too */
> > +	if (media_type(gobj) == MEDIA_GRAPH_LINK)
> > +		list_del(&gobj_to_link(gobj)->list);
> 
> Please... That's a very bad layering violation. Let's not do that. Generic 
> graph object code should not contain any type-specific code. You can create a 
> media_link_remove() function for links that will remove the link from the 
> entity links list and call media_gobj_remove().
> 
> >  }
> > 
> >  /**
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index ca4a4f23362f..fb5f0e21f137 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -153,7 +153,7 @@ struct media_entity {
> >  };
> > 
> >  /**
> > - * struct media_intf_devnode - Define a Kernel API interface
> > + * struct media_interface - Define a Kernel API interface
> 
> This belongs to a different patch ;-)
> 
> >   *
> >   * @graph_obj:		embedded graph object
> >   * @list:		Linked list used to find other interfaces that belong
> > @@ -163,6 +163,11 @@ struct media_entity {
> >   *			uapi/media/media.h header, e. g.
> >   *			MEDIA_INTF_T_*
> >   * @flags:		Interface flags as defined at uapi/media/media.h
> > + *
> > + * NOTE: As media_device_unregister() will free the address of the
> > + *	 media_interface, this structure should be embedded as the first
> > + *	 element of the derived functions, in order for the address to be
> > + *	 the same.
> 
> s/NOTE/DIRTY HACK/
> 
> Or, much better, let's fix it :-) If you want to be able to destroy graph 
> object without needing to know their type, you can add a destroy operation to 
> the graph objects and have per-type implementations. There's probably other 
> options as well.
> 
> >   */
> >  struct media_interface {
> >  	struct media_gobj		graph_obj;
> > @@ -179,11 +184,11 @@ struct media_interface {
> >   * @minor:	Minor number of a device node
> >   */
> >  struct media_intf_devnode {
> > -	struct media_interface		intf;
> > +	struct media_interface	intf; /* must be first field in struct */
> > 
> >  	/* Should match the fields at media_v2_intf_devnode */
> > -	u32				major;
> > -	u32				minor;
> > +	u32			major;
> > +	u32			minor;
> 
> This doesn't belong to this patch either.
> 
> >  };
> > 
> >  static inline u32 media_entity_id(struct media_entity *entity)
> 

Thanks for review!

Indeed, this patch had several troubles. I reworked on it, fixing
the pointed issues. The new version is enclosed.

I tested it with both KASAN and KMEMLEAK, and it is working as
expected:
	- no memleaks at the media controller core;
	- no memory usage on a freed data.

Regards,
Mauro


[media] media-device: remove interfaces and interface links

Just like what's done with entities, when the media controller is
unregistered, release any interface and interface links that
might still be there.

Change-Id: I51c1742fe071965f4606d98ed890712e81a1d4d9
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 drivers/media/media-device.c |   30 +++++++++++++++++++-----------
 drivers/media/media-entity.c |    7 ++++++-
 include/media/media-entity.h |    1 +
 3 files changed, 26 insertions(+), 12 deletions(-)

--- patchwork.orig/drivers/media/media-device.c
+++ patchwork/drivers/media/media-device.c
@@ -574,6 +574,17 @@ void media_device_unregister(struct medi
 {
 	struct media_entity *entity;
 	struct media_entity *next;
+	struct media_interface *intf, *tmp_intf;
+
+	/* Remove all interfaces from the media device */
+	spin_lock(&mdev->lock);
+	list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces,
+				 graph_obj.list) {
+		__media_remove_intf_links(intf);
+		media_gobj_remove(&intf->graph_obj);
+		kfree(intf);
+	}
+	spin_unlock(&mdev->lock);
 
 	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
 		media_device_unregister_entity(entity);
@@ -633,27 +644,24 @@ void media_device_unregister_entity(stru
 	int i;
 	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_link *link, *tmp;
+	struct media_interface *intf;
 
 	if (mdev == NULL)
 		return;
 
 	spin_lock(&mdev->lock);
 
-	/* Remove interface links with this entity on it */
-	list_for_each_entry_safe(link, tmp, &mdev->links, graph_obj.list) {
-		if (media_type(link->gobj1) == MEDIA_GRAPH_ENTITY
-		    && link->entity == entity) {
-			media_gobj_remove(&link->graph_obj);
-			kfree(link);
+	/* Remove all interface links pointing to this entity */
+	list_for_each_entry(intf, &mdev->interfaces, graph_obj.list) {
+		list_for_each_entry_safe(link, tmp, &intf->links, list) {
+			if (media_type(link->gobj1) == MEDIA_GRAPH_ENTITY
+			    && link->entity == entity)
+				__media_remove_intf_link(link);
 		}
 	}
 
 	/* Remove all data links that belong to this entity */
-	list_for_each_entry_safe(link, tmp, &entity->links, list) {
-		media_gobj_remove(&link->graph_obj);
-		list_del(&link->list);
-		kfree(link);
-	}
+	__media_entity_remove_links(entity);
 
 	/* Remove all pads that belong to this entity */
 	for (i = 0; i < entity->num_pads; i++)
--- patchwork.orig/drivers/media/media-entity.c
+++ patchwork/drivers/media/media-entity.c
@@ -674,9 +674,12 @@ static void __media_entity_remove_link(s
 
 		/* Remove the remote link */
 		list_del(&rlink->list);
+		media_gobj_remove(&rlink->graph_obj);
+
 		kfree(rlink);
 	}
 	list_del(&link->list);
+	media_gobj_remove(&link->graph_obj);
 	kfree(link);
 }
 
@@ -920,11 +923,13 @@ struct media_link *media_create_intf_lin
 EXPORT_SYMBOL_GPL(media_create_intf_link);
 
 
-static void __media_remove_intf_link(struct media_link *link)
+void __media_remove_intf_link(struct media_link *link)
 {
+	list_del(&link->list);
 	media_gobj_remove(&link->graph_obj);
 	kfree(link);
 }
+EXPORT_SYMBOL_GPL(__media_remove_intf_link);
 
 void media_remove_intf_link(struct media_link *link)
 {
--- patchwork.orig/include/media/media-entity.h
+++ patchwork/include/media/media-entity.h
@@ -325,6 +325,7 @@ void media_devnode_remove(struct media_i
 struct media_link *media_create_intf_link(struct media_entity *entity,
 					    struct media_interface *intf,
 					    u32 flags);
+void __media_remove_intf_link(struct media_link *link);
 void media_remove_intf_link(struct media_link *link);
 void __media_remove_intf_links(struct media_interface *intf);
 void media_remove_intf_links(struct media_interface *intf);



^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 55/55] [media] media-entity.h: document all the structs
  2015-11-23 20:19     ` Laurent Pinchart
@ 2015-12-10 18:16       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 309+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-10 18:16 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List

Em Mon, 23 Nov 2015 22:19:19 +0200
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Sunday 06 September 2015 09:03:14 Mauro Carvalho Chehab wrote:
> > Only a few structs are documented on kernel-doc-nano format
> > (the ones added by the MC next gen patches).
> > 
> > Add a documentation for all structs, and ensure that they'll
> > be producing the documentation at the Kernel's device driver
> > DocBook.
> 
> Very good idea ! Please see below for some spelling mistakes or other 
> corrections in addition to the ones pointed out by Hans.
> 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index fb5f0e21f137..e1a89899deef 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -55,11 +55,13 @@ enum media_gobj_type {
> >  /**
> >   * struct media_gobj - Define a graph object.
> >   *
> > + * @mdev:	Pointer to the struct media_device that owns the object
> >   * @id:		Non-zero object ID identifier. The ID should be unique
> >   *		inside a media_device, as it is composed by
> >   *		MEDIA_BITS_PER_TYPE to store the type plus
> >   *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
> >   *		(called as "local ID").
> > + * @list:	Linked list associated to one of the per-type mdev object lists
> 
> I'd say "List entry stored in one of the ..." (or "List head" if you prefer).
> 
> >   *
> >   * All objects on the media graph should have this struct embedded
> >   */
> > @@ -73,6 +75,28 @@ struct media_gobj {
> >  struct media_pipeline {
> >  };
> > 
> > +/**
> > + * struct media_link - Define a media link graph object.
> 
> I think you can drop the "Define" and just say "A media link graph object". 
> Or, rather, "A media graph link object" to mean "a link object part of a media 
> graph".
> 
> Same comment for the other structures.
> 
> > + *
> > + * @graph_obj:	Embedded structure containing the media object common data
> > + * @list:	Linked list associated with an entity or an interface that
> > + *		owns the link.
> > + * @gobj0:	Part of an union. Used to get the pointer for the first
> > + *		graph_object of the link.
> > + * @source:	Part of an union. Used only if the first object (gobj0) is
> > + *		a pad. On such case, it represents the source pad.
> > + * @intf:	Part of an union. Used only if the first object (gobj0) is
> > + *		an interface.
> > + * @gobj1:	Part of an union. Used to get the pointer for the second
> > + *		graph_object of the link.
> > + * @source:	Part of an union. Used only if the second object (gobj0) is
> 
> s/gobj0/gobj1/
> 
> > + *		a pad. On such case, it represents the sink pad.
> > + * @entity:	Part of an union. Used only if the second object (gobj0) is
> 
> Ditto.
> 
> > + *		an entity.
> > + * @reverse:	Pointer to the link for the reverse direction of a pad to 
> pad
> > + *		link.
> > + * @flags:	Link flags, as defined at uapi/media.h (MEDIA_LNK_FL_*)
> > + */
> >  struct media_link {
> >  	struct media_gobj graph_obj;
> >  	struct list_head list;
> > @@ -86,15 +110,23 @@ struct media_link {
> >  		struct media_pad *sink;
> >  		struct media_entity *entity;
> >  	};
> > -	struct media_link *reverse;	/* Link in the reverse direction */
> > -	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
> > +	struct media_link *reverse;
> > +	unsigned long flags;
> >  };
> > 
> > +/**
> > + * struct media_pad - Define a media pad graph object.
> > + *
> > + * @graph_obj:	Embedded structure containing the media object common data
> > + * @entity:	Entity where this object belongs
> 
> "Entity this pad belongs to"
> 
> > + * @index:	Pad index in the entity pads array, numbered from 0 to n
> > + * @flags:	Pad flags, as defined at uapi/media.h (MEDIA_PAD_FL_*)
> > + */
> >  struct media_pad {
> >  	struct media_gobj graph_obj;	/* must be first field in struct */
> > -	struct media_entity *entity;	/* Entity this pad belongs to */
> > -	u16 index;			/* Pad index in the entity pads array */
> > -	unsigned long flags;		/* Pad flags (MEDIA_PAD_FL_*) */
> > +	struct media_entity *entity;
> > +	u16 index;
> > +	unsigned long flags;
> >  };
> > 
> >  /**
> > @@ -113,51 +145,73 @@ struct media_entity_operations {
> >  	int (*link_validate)(struct media_link *link);
> >  };
> > 
> > +/**
> > + * struct media_entity - Define a media entity graph object.
> > + *
> > + * @graph_obj:	Embedded structure containing the media object common data.
> > + * @name:	Entity name.
> > + * @type:	Entity type, as defined at uapi/media.h (MEDIA_ENT_T_*)
> > + * @revision:	Entity revision - OBSOLETE - should be removed soon.
> > + * @flags:	Entity flags, as defined at uapi/media.h (MEDIA_ENT_FL_*)
> > + * @group_id:	Entity group ID - OBSOLETE - should be removed soon.
> > + * @num_pads:	Number of sink and source pads.
> > + * @num_links:	Number of existing links, both enabled and disabled.
> 
> I'd mention there that it includes the backlinks too as it's always clearly 
> apparent.
> 
> "Total number of links, forward and back, enabled and disabled"
> 
> > + * @num_backlinks: Number of backlinks
> > + * @pads:	Pads array with the size defined by @num_pads.
> > + * @links:	Linked list for the data links.
> 
> "List of data links" or "Linked list of data links" if you want to make it 
> explicit that struct list_head is a linked list, but I think that should be 
> known to the reader (and have the word link twice in the description for two 
> different purpose can be slightly confusing).
> 
> > + * @ops:	Entity operations.
> > + * @stream_count: Stream count for the entity.
> > + * @use_count:	Use count for the entity.
> > + * @pipe:	Pipeline this entity belongs to.
> > + * @info:	Union with devnode information.  Kept just for backward
> > + * 		compatibility.
> > + * @major:	Devnode major number (zero if not applicable). Kept just
> 
> Maybe s/@major/@dev.major/ (and the same for minor) ?

I don't think it works. The kernel-doc script is not smart enough to
handle this kind of things.

> 
> > + * 		for backward compatibility.
> > + * @minor:	Devnode minor number (zero if not applicable). Kept just
> > + * 		for backward compatibility.
> 
> As this is an internal structure I think we should clean code up sooner than 
> later and remove the major and minor fields. It will be confusing for driver 
> authors otherwise. Same for the revision and group_id fields.

Yes, but we could delay such change for Kernel 4.6. There are already
too much changes for 4.5.

> 
> > + * NOTE: @stream_count and @use_count reference counts must never be
> > + * negative, but are signed integers on purpose: a simple WARN_ON(<0) check
> > + * can be used to detect reference count bugs that would make them
> > negative.
> > + */
> >  struct media_entity {
> >  	struct media_gobj graph_obj;	/* must be first field in struct */
> > -	const char *name;		/* Entity name */
> > -	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
> > -	u32 revision;			/* Entity revision, driver specific */
> > -	unsigned long flags;		/* Entity flags (MEDIA_ENT_FL_*) */
> > -	u32 group_id;			/* Entity group ID */
> > +	const char *name;
> > +	u32 type;
> > +	u32 revision;
> > +	unsigned long flags;
> > +	u32 group_id;
> > 
> > -	u16 num_pads;			/* Number of sink and source pads */
> > -	u16 num_links;			/* Number of existing links, both
> > -					 * enabled and disabled */
> > -	u16 num_backlinks;		/* Number of backlinks */
> > +	u16 num_pads;
> > +	u16 num_links;
> > +	u16 num_backlinks;
> > 
> > -	struct media_pad *pads;		/* Pads array (num_pads objects) */
> > -	struct list_head links;		/* Pad-to-pad links list */
> > +	struct media_pad *pads;
> > +	struct list_head links;
> > 
> > -	const struct media_entity_operations *ops;	/* Entity operations */
> > +	const struct media_entity_operations *ops;
> > 
> >  	/* Reference counts must never be negative, but are signed integers on
> >  	 * purpose: a simple WARN_ON(<0) check can be used to detect reference
> >  	 * count bugs that would make them negative.
> >  	 */
> > -	int stream_count;		/* Stream count for the entity. */
> > -	int use_count;			/* Use count for the entity. */
> > +	int stream_count;
> > +	int use_count;
> > 
> > -	struct media_pipeline *pipe;	/* Pipeline this entity belongs to. */
> > +	struct media_pipeline *pipe;
> > 
> >  	union {
> > -		/* Node specifications */
> >  		struct {
> >  			u32 major;
> >  			u32 minor;
> >  		} dev;
> > -
> > -		/* Sub-device specifications */
> > -		/* Nothing needed yet */
> >  	} info;
> >  };
> > 
> >  /**
> > - * struct media_interface - Define a Kernel API interface
> > + * struct media_interface - Define a media interface graph object
> >   *
> >   * @graph_obj:		embedded graph object
> > - * @list:		Linked list used to find other interfaces that belong
> > - *			to the same media controller
> 
> Usual pet peeve of mine, this should be squashed with the patch that 
> introduces struct media_interface. Same for the next chunk. I would actually 
> move this patch before any patch that introduces a new structure, just to 
> document the existing structures, and then add documentation for new 
> structures in the patches that introduce them. That would be easier to review.

Too late for doing that. It this patch were reviewed earlier...

> 
> >   * @links:		List of links pointing to graph entities
> >   * @type:		Type of the interface as defined at the
> >   *			uapi/media/media.h header, e. g.
> > @@ -177,7 +231,7 @@ struct media_interface {
> >  };
> > 
> >  /**
> > - * struct media_intf_devnode - Define a Kernel API interface via a device
> > node
> > + * struct media_intf_devnode - Define a media interface via a device node
> >   * @intf:	embedded interface object
> >   * @major:	Major number of a device node
> 

Fixed the remaining issues.

Regards,
Mauro

^ permalink raw reply	[flat|nested] 309+ messages in thread

* Re: [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA
  2015-12-08 15:41       ` Mauro Carvalho Chehab
@ 2016-02-16  0:34         ` Laurent Pinchart
  0 siblings, 0 replies; 309+ messages in thread
From: Laurent Pinchart @ 2016-02-16  0:34 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List

Hi Mauro,

On Tuesday 08 December 2015 13:41:00 Mauro Carvalho Chehab wrote:
> Em Sun, 06 Dec 2015 04:20:38 +0200 Laurent Pinchart escreveu:
> > On Sunday 06 September 2015 09:02:57 Mauro Carvalho Chehab wrote:
> > > As we'll be removing entity subtypes from the Kernel, we need
> > > to provide a way for drivers and core to check if a given
> > > entity is represented by a V4L2 subdev or if it is an V4L2
> > > I/O entity (typically with DMA).
> > > 
> > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > 
> > > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > > index 4e36b1f2b2d7..220864319d21 100644
> > > --- a/include/media/media-entity.h
> > > +++ b/include/media/media-entity.h
> > > @@ -220,6 +220,39 @@ static inline u32 media_gobj_gen_id(enum
> > > media_gobj_type type, u32 local_id) return id;
> > > 
> > >  }
> > > 
> > > +static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
> > > +{
> > > +	if (!entity)
> > > +		return false;
> > > +
> > > +	switch (entity->type) {
> > > +	case MEDIA_ENT_T_V4L2_VIDEO:
> > > +	case MEDIA_ENT_T_V4L2_VBI:
> > > +	case MEDIA_ENT_T_V4L2_SWRADIO:
> > > +		return true;
> > > +	default:
> > > +		return false;
> > > +	}
> > > +}
> > > +
> > > +static inline bool is_media_entity_v4l2_subdev(struct media_entity
> > > *entity)
> > > +{
> > > +	if (!entity)
> > > +		return false;
> > > +
> > > +	switch (entity->type) {
> > > +	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
> > > +	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
> > > +	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
> > > +	case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
> > > +	case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
> >
> > I'm sorry but this simply won't scale. We need a better way to determine
> > the entity type, and this could be a valid use case to actually retain an
> > entity type field separate from the function, at least inside the kernel.
>
> As we're getting rid of a separate range for V4L2 subdevs, several drivers
> need some logic to identify if an entity is a subdev or not. So, no matter
> how we implement it, we need a is_media_entity_v4l2_subdev() function.
> 
> So, I guess you're discussing the actual implementation, not the need of
> such function.

Correct. On a side note, though, the function should probably be moved to a 
V4L2-specific header file.

> With that regards, I'm not sure if this won't scale. The gcc compiler
> optimizer usually uses binary search on switches. So, O(log(n)).
> Even if we had 256 subdev types, that would mean 8 ifs. Doesn't seem
> too bad, specially since we have right now only 5 subdev types.
> 
> Ok, there's one thing bad on this: we need to update this function every
> time a new V4L2 subdev is added. So, it may be a maintainance nightmare,
> but I don't see any way to avoid the need of adding the subdevs at both
> UAPI and kernelspace.

That's part of my concern, yes. I've tried to add video processing functions 
today and received a WARN_ON() as the is_media_entity_v4l2_subdev() function 
wasn't updated.

> I'm not opposed to change this to some other method that we would find.
> In any case, this is inside an inlined function. So, it is easy to
> replace the implementation to any other logic we find better. So,
> if you have a better idea, feel free to submit a followup patch
> optimizing it.

I was hoping you would propose a solution, as you've introduced the problem 
:-) Any idea ?

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 309+ messages in thread

end of thread, other threads:[~2016-02-16  0:33 UTC | newest]

Thread overview: 309+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-30  3:06 [PATCH v8 00/55] MC next generation patches Mauro Carvalho Chehab
2015-08-30  3:06 ` Mauro Carvalho Chehab
2015-08-30  3:06 ` Mauro Carvalho Chehab
2015-08-30  3:06 ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 01/55] [media] media: create a macro to get entity ID Mauro Carvalho Chehab
2015-08-30  3:06   ` Mauro Carvalho Chehab
2015-09-10 13:58   ` Javier Martinez Canillas
2015-09-10 13:58     ` Javier Martinez Canillas
2015-12-06  3:20   ` Laurent Pinchart
2015-12-06  3:20     ` Laurent Pinchart
2015-08-30  3:06 ` [PATCH v8 02/55] [media] staging: omap4iss: get entity ID using media_entity_id() Mauro Carvalho Chehab
2015-12-06  3:18   ` Laurent Pinchart
2015-12-07 15:24     ` Javier Martinez Canillas
2015-08-30  3:06 ` [PATCH v8 03/55] [media] omap3isp: " Mauro Carvalho Chehab
2015-08-31 10:10   ` Hans Verkuil
2015-12-06  3:16   ` Laurent Pinchart
2015-12-07 15:22     ` Javier Martinez Canillas
2015-08-30  3:06 ` [PATCH v8 04/55] [media] media: add a common struct to be embed on media graph objects Mauro Carvalho Chehab
2015-09-09  7:01   ` Sakari Ailus
2015-09-09 11:10     ` Mauro Carvalho Chehab
2015-09-10 14:02   ` Javier Martinez Canillas
2015-08-30  3:06 ` [PATCH v8 05/55] [media] media: use media_gobj inside entities Mauro Carvalho Chehab
2015-09-10 14:04   ` Javier Martinez Canillas
2015-08-30  3:06 ` [PATCH v8 06/55] [media] media: use media_gobj inside pads Mauro Carvalho Chehab
2015-09-09  7:37   ` Sakari Ailus
2015-09-10 14:09   ` Javier Martinez Canillas
2015-08-30  3:06 ` [PATCH v8 07/55] [media] media: use media_gobj inside links Mauro Carvalho Chehab
2015-09-10 14:10   ` Javier Martinez Canillas
2015-08-30  3:06 ` [PATCH v8 08/55] [media] media: add messages when media device gets (un)registered Mauro Carvalho Chehab
2015-09-10 14:12   ` Javier Martinez Canillas
2015-08-30  3:06 ` [PATCH v8 09/55] [media] media: add a debug message to warn about gobj creation/removal Mauro Carvalho Chehab
2015-09-10 14:14   ` Javier Martinez Canillas
2015-08-30  3:06 ` [PATCH v8 10/55] [media] media: rename the function that create pad links Mauro Carvalho Chehab
2015-08-30  3:06   ` Mauro Carvalho Chehab
2015-08-30  3:06   ` Mauro Carvalho Chehab
2015-08-30  3:06   ` Mauro Carvalho Chehab
2015-09-10 14:16   ` Javier Martinez Canillas
2015-09-10 14:16     ` Javier Martinez Canillas
2015-09-10 14:16     ` Javier Martinez Canillas
2015-09-10 14:16     ` Javier Martinez Canillas
2015-08-30  3:06 ` [PATCH v8 11/55] [media] media: use entity.graph_obj.mdev instead of .parent Mauro Carvalho Chehab
2015-08-30  3:06   ` Mauro Carvalho Chehab
2015-08-30  3:06   ` Mauro Carvalho Chehab
2015-08-30  3:06   ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 12/55] [media] media: remove media entity .parent field Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 13/55] [media] uapi/media.h: Declare interface types for V4L2 and DVB Mauro Carvalho Chehab
2015-09-10 14:19   ` Javier Martinez Canillas
2015-09-10 14:19     ` Javier Martinez Canillas
2015-08-30  3:06 ` [PATCH v8 14/55] [media] media: add functions to allow creating interfaces Mauro Carvalho Chehab
2015-08-31 10:20   ` Hans Verkuil
2015-08-31 10:49     ` Mauro Carvalho Chehab
2015-09-06 12:02   ` Mauro Carvalho Chehab
2015-09-09  7:34     ` Sakari Ailus
2015-09-09 10:00       ` Mauro Carvalho Chehab
2015-09-10 14:22     ` Javier Martinez Canillas
2015-09-11 12:57     ` Hans Verkuil
2015-12-08 14:36       ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 15/55] [media] uapi/media.h: Declare interface types for ALSA Mauro Carvalho Chehab
2015-09-06 12:02   ` Mauro Carvalho Chehab
2015-09-06 12:02     ` Mauro Carvalho Chehab
2015-09-10 14:23     ` Javier Martinez Canillas
2015-08-30  3:06 ` [PATCH v8 16/55] [media] media: Don't accept early-created links Mauro Carvalho Chehab
2015-08-31 10:30   ` Hans Verkuil
2015-08-31 10:54     ` Mauro Carvalho Chehab
2015-08-31 11:01       ` Hans Verkuil
2015-08-31 14:39         ` Javier Martinez Canillas
2015-08-31 15:05           ` Mauro Carvalho Chehab
2015-09-06 12:02   ` Mauro Carvalho Chehab
2015-12-06  3:13     ` Laurent Pinchart
2015-08-30  3:06 ` [PATCH v8 17/55] [media] omap3isp: separate links creation from entities init Mauro Carvalho Chehab
2015-11-23 15:55   ` Laurent Pinchart
2015-11-23 16:22     ` Javier Martinez Canillas
2015-08-30  3:06 ` [PATCH v8 18/55] [media] omap3isp: create links after all subdevs have been bound Mauro Carvalho Chehab
2015-09-09  8:03   ` Sakari Ailus
2015-09-09  8:48     ` Javier Martinez Canillas
2015-12-06  3:05       ` Laurent Pinchart
2015-12-07 15:17         ` Javier Martinez Canillas
2015-09-09 10:28     ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 19/55] [media] media: convert links from array to list Mauro Carvalho Chehab
2015-09-04  8:41   ` Sakari Ailus
2015-09-04  9:00     ` Hans Verkuil
2015-09-04 11:10       ` Mauro Carvalho Chehab
2015-09-04 11:28   ` [PATCH v8.1 " Mauro Carvalho Chehab
2015-09-04 11:48     ` [PATCH v8.2 " Mauro Carvalho Chehab
2015-09-06 12:02       ` Mauro Carvalho Chehab
2015-11-23 15:37         ` Laurent Pinchart
2015-11-23 15:41           ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 20/55] [media] media: make add link more generic Mauro Carvalho Chehab
2015-08-31 10:44   ` Hans Verkuil
2015-09-06 12:02   ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 21/55] [media] media: make media_link more generic to handle interace links Mauro Carvalho Chehab
2015-08-31 10:44   ` Hans Verkuil
2015-09-06 12:02   ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 22/55] [media] media: make link debug printk more generic Mauro Carvalho Chehab
2015-09-06 12:02   ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 23/55] [media] media: add support to link interfaces and entities Mauro Carvalho Chehab
2015-08-31 10:48   ` Hans Verkuil
2015-09-06 12:02   ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 24/55] [media] media-entity: add a helper function to create interface Mauro Carvalho Chehab
2015-08-31 10:49   ` Hans Verkuil
2015-09-06 12:02   ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 25/55] [media] dvbdev: add support for interfaces Mauro Carvalho Chehab
2015-08-31 10:51   ` Hans Verkuil
2015-08-30  3:06 ` [PATCH v8 26/55] [media] media: add a linked list to track interfaces by mdev Mauro Carvalho Chehab
2015-08-31 10:52   ` Hans Verkuil
2015-09-06 12:02   ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 27/55] [media] dvbdev: add support for indirect interface links Mauro Carvalho Chehab
2015-08-31 10:54   ` Hans Verkuil
2015-09-06 12:02   ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 28/55] [media] uapi/media.h: Fix entity namespace Mauro Carvalho Chehab
2015-08-31 11:17   ` Hans Verkuil
2015-08-31 12:12     ` Mauro Carvalho Chehab
2015-09-06 12:02   ` Mauro Carvalho Chehab
2015-09-06 12:02     ` Mauro Carvalho Chehab
2015-09-11 13:06     ` Hans Verkuil
2015-09-11 13:06       ` Hans Verkuil
2015-08-30  3:06 ` [PATCH v8 29/55] [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_V4L Mauro Carvalho Chehab
2015-08-30  3:06   ` Mauro Carvalho Chehab
2015-08-31 11:22   ` Hans Verkuil
2015-08-31 11:22     ` Hans Verkuil
2015-08-30  3:06 ` [PATCH v8 30/55] [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_DVB Mauro Carvalho Chehab
2015-08-31 11:21   ` Hans Verkuil
2015-08-30  3:06 ` [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA Mauro Carvalho Chehab
2015-08-31 11:31   ` Hans Verkuil
2015-08-31 11:40     ` Hans Verkuil
2015-08-31 13:08     ` Mauro Carvalho Chehab
2015-08-31 13:46       ` Hans Verkuil
2015-09-06 12:02   ` Mauro Carvalho Chehab
2015-12-06  2:20     ` Laurent Pinchart
2015-12-08 15:41       ` Mauro Carvalho Chehab
2016-02-16  0:34         ` Laurent Pinchart
2015-08-30  3:06 ` [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities Mauro Carvalho Chehab
2015-08-30  3:06   ` Mauro Carvalho Chehab
2015-08-30  3:06   ` Mauro Carvalho Chehab
2015-08-30  3:06   ` Mauro Carvalho Chehab
2015-10-11 21:07   ` Sakari Ailus
2015-10-11 21:07     ` Sakari Ailus
2015-10-11 21:07     ` Sakari Ailus
2015-10-11 21:07     ` Sakari Ailus
2015-10-12  0:56     ` Mauro Carvalho Chehab
2015-10-12  0:56       ` Mauro Carvalho Chehab
2015-10-12  0:56       ` Mauro Carvalho Chehab
2015-10-12  0:56       ` Mauro Carvalho Chehab
2015-10-12 15:35       ` Sakari Ailus
2015-10-12 15:35         ` Sakari Ailus
2015-10-12 15:35         ` Sakari Ailus
2015-10-12 15:35         ` Sakari Ailus
2015-10-12 16:00         ` Mauro Carvalho Chehab
2015-10-12 16:00           ` Mauro Carvalho Chehab
2015-10-12 16:00           ` Mauro Carvalho Chehab
2015-10-12 16:00           ` Mauro Carvalho Chehab
2015-12-08 15:57         ` Mauro Carvalho Chehab
2015-12-08 17:05           ` Mauro Carvalho Chehab
2015-12-08 17:08             ` Mauro Carvalho Chehab
2015-10-12 15:38       ` [PATCH 1/1] media: Correctly determine whether an entity is a sub-device Sakari Ailus
2015-10-12 15:38         ` Sakari Ailus
2015-10-12 15:38         ` Sakari Ailus
2015-10-12 15:58         ` Mauro Carvalho Chehab
2015-10-12 15:58           ` Mauro Carvalho Chehab
2015-10-12 15:58           ` Mauro Carvalho Chehab
2015-10-12 15:58           ` Mauro Carvalho Chehab
2015-12-06  2:16   ` [PATCH v8 32/55] [media] media: use macros to check for V4L2 subdev entities Laurent Pinchart
2015-12-06  2:16     ` Laurent Pinchart
2015-12-06  2:16     ` Laurent Pinchart
2015-12-08 16:03     ` Mauro Carvalho Chehab
2015-12-08 16:03       ` Mauro Carvalho Chehab
2015-12-08 16:03       ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 33/55] [media] omap3/omap4/davinci: get rid of MEDIA_ENT_T_V4L2_SUBDEV abuse Mauro Carvalho Chehab
2015-12-06  2:08   ` Laurent Pinchart
2015-12-08 16:52     ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 34/55] [media] s5c73m3: fix subdev type Mauro Carvalho Chehab
2015-12-06  1:57   ` Laurent Pinchart
2015-12-08 17:11     ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 35/55] [media] s5k5baf: " Mauro Carvalho Chehab
2015-12-06  1:55   ` Laurent Pinchart
2015-12-08 17:17     ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 36/55] [media] davinci_vbpe: stop MEDIA_ENT_T_V4L2_SUBDEV abuse Mauro Carvalho Chehab
2015-12-06  1:52   ` Laurent Pinchart
2015-12-08 17:22     ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 37/55] [media] omap4iss: " Mauro Carvalho Chehab
2015-12-06  1:46   ` Laurent Pinchart
2015-12-08 17:47     ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 38/55] [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs Mauro Carvalho Chehab
2015-08-31 11:43   ` Hans Verkuil
2015-08-31 11:43     ` Hans Verkuil
2015-09-06 12:02   ` Mauro Carvalho Chehab
2015-12-06  1:37     ` Laurent Pinchart
2015-12-08 17:38       ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 39/55] [media] media controller: get rid of entity subtype on Kernel Mauro Carvalho Chehab
2015-08-31 11:44   ` Hans Verkuil
2015-08-31 11:44     ` Hans Verkuil
2015-09-06 12:02   ` Mauro Carvalho Chehab
2015-09-06 12:02     ` Mauro Carvalho Chehab
2015-09-11 13:08     ` Hans Verkuil
2015-09-11 13:08       ` Hans Verkuil
2015-12-06  1:03     ` Laurent Pinchart
2015-12-06  1:03       ` Laurent Pinchart
2015-08-30  3:06 ` [PATCH v8 40/55] [media] media.h: don't use legacy entity macros at Kernel Mauro Carvalho Chehab
2015-08-30  3:06   ` Mauro Carvalho Chehab
2015-08-31 11:44   ` Hans Verkuil
2015-08-31 11:44     ` Hans Verkuil
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-09-06 12:03     ` Mauro Carvalho Chehab
2015-12-06  1:02     ` Laurent Pinchart
2015-12-06  1:02       ` Laurent Pinchart
2015-08-30  3:06 ` [PATCH v8 41/55] [media] DocBook: update descriptions for the media controller entities Mauro Carvalho Chehab
2015-08-31 11:22   ` Hans Verkuil
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-09-11 13:13     ` Hans Verkuil
2015-12-06  1:00       ` Laurent Pinchart
2015-12-08 18:04         ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 42/55] [media] dvb: modify core to implement interfaces/entities at MC new gen Mauro Carvalho Chehab
2015-08-31 11:49   ` Hans Verkuil
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-09-11 13:51     ` Hans Verkuil
2015-08-30  3:06 ` [PATCH v8 43/55] [media] media: report if a pad is sink or source at debug msg Mauro Carvalho Chehab
2015-08-31 11:51   ` Hans Verkuil
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-09-11 13:52     ` Hans Verkuil
2015-12-06  0:53     ` Laurent Pinchart
2015-12-08 18:46       ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl Mauro Carvalho Chehab
2015-08-31 12:00   ` Hans Verkuil
2015-08-31 13:35     ` Mauro Carvalho Chehab
2015-08-31 13:35       ` Mauro Carvalho Chehab
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-09-06 12:03     ` Mauro Carvalho Chehab
2015-09-11 13:58     ` Hans Verkuil
2015-09-11 13:58       ` Hans Verkuil
2015-12-06  0:47     ` Laurent Pinchart
2015-12-06  0:47       ` Laurent Pinchart
2015-12-08 19:23       ` Mauro Carvalho Chehab
2015-12-08 19:48         ` Arnd Bergmann
2015-12-08 19:48           ` Arnd Bergmann
2015-08-30  3:06 ` [PATCH v8 45/55] [media] media: Use a macro to interate between all interfaces Mauro Carvalho Chehab
2015-08-31 12:01   ` Hans Verkuil
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-11-23 22:36     ` Laurent Pinchart
2015-08-30  3:06 ` [PATCH v8 46/55] [media] media: move mdev list init to gobj Mauro Carvalho Chehab
2015-08-31 12:03   ` Hans Verkuil
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-09-11 13:59     ` Hans Verkuil
2015-11-23 22:32     ` Laurent Pinchart
2015-12-08 19:31       ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 47/55] [media] media-device: add pads and links to media_device Mauro Carvalho Chehab
2015-08-31 12:25   ` Hans Verkuil
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-11-23 22:28     ` Laurent Pinchart
2015-11-24 12:19       ` Mauro Carvalho Chehab
2015-08-30  3:06 ` [PATCH v8 48/55] [media] media_device: add a topology version field Mauro Carvalho Chehab
2015-08-31 12:29   ` Hans Verkuil
2015-08-31 12:52     ` Mauro Carvalho Chehab
2015-08-31 13:35       ` Hans Verkuil
2015-09-04 17:08         ` Mauro Carvalho Chehab
2015-11-23 22:18           ` Laurent Pinchart
2015-12-08 20:05             ` Mauro Carvalho Chehab
2015-11-23 22:20     ` Laurent Pinchart
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-09-11 13:59     ` Hans Verkuil
2015-08-30  3:07 ` [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl Mauro Carvalho Chehab
2015-08-31 12:47   ` Hans Verkuil
2015-08-31 13:40     ` Mauro Carvalho Chehab
2015-08-31 13:48       ` Hans Verkuil
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-09-07 22:18     ` Sakari Ailus
2015-09-08  1:23       ` Mauro Carvalho Chehab
2015-09-08  7:26         ` Sakari Ailus
2015-09-08 10:49           ` Mauro Carvalho Chehab
2015-09-08 13:34             ` Sakari Ailus
2015-09-08 15:11               ` Mauro Carvalho Chehab
2015-09-11 14:08     ` Hans Verkuil
2015-12-08 20:20       ` Mauro Carvalho Chehab
2015-11-23 22:04     ` Laurent Pinchart
2015-12-08 20:17       ` Mauro Carvalho Chehab
2015-08-30  3:07 ` [PATCH v8 50/55] [media] media-entity: unregister entity links Mauro Carvalho Chehab
2015-08-31 12:48   ` Hans Verkuil
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-11-23 21:27     ` Laurent Pinchart
2015-12-08 20:23       ` Mauro Carvalho Chehab
2015-08-30  3:07 ` [PATCH v8 51/55] [media] remove interface links at media_entity_unregister() Mauro Carvalho Chehab
2015-08-31 12:53   ` Hans Verkuil
2015-08-31 13:42     ` Mauro Carvalho Chehab
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-09-11 14:18     ` Hans Verkuil
2015-08-30  3:07 ` [PATCH v8 52/55] [media] media-device: remove interfaces and interface links Mauro Carvalho Chehab
2015-08-31 12:57   ` Hans Verkuil
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-09-11 14:20     ` Hans Verkuil
2015-11-23 21:22     ` Laurent Pinchart
2015-12-09 13:39       ` Mauro Carvalho Chehab
2015-08-30  3:07 ` [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes Mauro Carvalho Chehab
2015-08-31 13:23   ` Hans Verkuil
2015-09-04 16:13     ` Mauro Carvalho Chehab
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-09-11 14:38     ` Hans Verkuil
2015-11-23 21:10     ` Laurent Pinchart
2015-11-24 11:25       ` Mauro Carvalho Chehab
2015-08-30  3:07 ` [PATCH v8 54/55] [media] au0828: unregister MC at the end Mauro Carvalho Chehab
2015-08-31 13:25   ` Hans Verkuil
2015-09-04 22:24     ` Mauro Carvalho Chehab
2015-08-30  3:07 ` [PATCH v8 55/55] [media] media-entity.h: document all the structs Mauro Carvalho Chehab
2015-09-06 12:03   ` Mauro Carvalho Chehab
2015-09-11 14:45     ` Hans Verkuil
2015-11-23 20:19     ` Laurent Pinchart
2015-12-10 18:16       ` Mauro Carvalho Chehab
2015-08-30 14:27 ` [PATCH v8 00/55] MC next generation patches Mauro Carvalho Chehab
2015-08-30 14:27   ` Mauro Carvalho Chehab
2015-08-30 14:27   ` Mauro Carvalho Chehab
2015-08-30 14:27   ` Mauro Carvalho Chehab

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.