Commit 5a46e490 authored by Maxime Ripard's avatar Maxime Ripard

drm/vc4: Switch to container_of_const

container_of_const() allows to preserve the pointer constness and is
thus more flexible than inline functions.

Let's switch all our instances of container_of() to
container_of_const().
Reviewed-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
Link: https://lore.kernel.org/r/20221207-rpi-hdmi-improvements-v3-1-bdd54f66884e@cerno.techSigned-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
parent 322d716a
...@@ -43,6 +43,9 @@ struct vc4_dummy_output { ...@@ -43,6 +43,9 @@ struct vc4_dummy_output {
struct drm_connector connector; struct drm_connector connector;
}; };
#define encoder_to_vc4_dummy_output(_enc) \
container_of_const(_enc, struct vc4_dummy_output, encoder.base)
struct vc4_dummy_output *vc4_dummy_output(struct kunit *test, struct vc4_dummy_output *vc4_dummy_output(struct kunit *test,
struct drm_device *drm, struct drm_device *drm,
struct drm_crtc *crtc, struct drm_crtc *crtc,
......
...@@ -80,7 +80,7 @@ int vc4_mock_atomic_add_output(struct kunit *test, ...@@ -80,7 +80,7 @@ int vc4_mock_atomic_add_output(struct kunit *test,
crtc = vc4_find_crtc_for_encoder(test, drm, encoder); crtc = vc4_find_crtc_for_encoder(test, drm, encoder);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, crtc); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, crtc);
output = container_of(encoder, struct vc4_dummy_output, encoder.base); output = encoder_to_vc4_dummy_output(encoder);
conn = &output->connector; conn = &output->connector;
conn_state = drm_atomic_get_connector_state(state, conn); conn_state = drm_atomic_get_connector_state(state, conn);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, conn_state); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, conn_state);
...@@ -126,7 +126,7 @@ int vc4_mock_atomic_del_output(struct kunit *test, ...@@ -126,7 +126,7 @@ int vc4_mock_atomic_del_output(struct kunit *test,
ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL); ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL);
KUNIT_ASSERT_EQ(test, ret, 0); KUNIT_ASSERT_EQ(test, ret, 0);
output = container_of(encoder, struct vc4_dummy_output, encoder.base); output = encoder_to_vc4_dummy_output(encoder);
conn = &output->connector; conn = &output->connector;
conn_state = drm_atomic_get_connector_state(state, conn); conn_state = drm_atomic_get_connector_state(state, conn);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, conn_state); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, conn_state);
......
...@@ -97,11 +97,8 @@ struct vc4_dpi { ...@@ -97,11 +97,8 @@ struct vc4_dpi {
struct debugfs_regset32 regset; struct debugfs_regset32 regset;
}; };
static inline struct vc4_dpi * #define to_vc4_dpi(_encoder) \
to_vc4_dpi(struct drm_encoder *encoder) container_of_const(_encoder, struct vc4_dpi, encoder.base)
{
return container_of(encoder, struct vc4_dpi, encoder.base);
}
#define DPI_READ(offset) \ #define DPI_READ(offset) \
({ \ ({ \
......
...@@ -232,11 +232,8 @@ struct vc4_dev { ...@@ -232,11 +232,8 @@ struct vc4_dev {
struct kref bin_bo_kref; struct kref bin_bo_kref;
}; };
static inline struct vc4_dev * #define to_vc4_dev(_dev) \
to_vc4_dev(const struct drm_device *dev) container_of_const(_dev, struct vc4_dev, base)
{
return container_of(dev, struct vc4_dev, base);
}
struct vc4_bo { struct vc4_bo {
struct drm_gem_dma_object base; struct drm_gem_dma_object base;
...@@ -285,11 +282,8 @@ struct vc4_bo { ...@@ -285,11 +282,8 @@ struct vc4_bo {
struct mutex madv_lock; struct mutex madv_lock;
}; };
static inline struct vc4_bo * #define to_vc4_bo(_bo) \
to_vc4_bo(const struct drm_gem_object *bo) container_of_const(to_drm_gem_dma_obj(_bo), struct vc4_bo, base)
{
return container_of(to_drm_gem_dma_obj(bo), struct vc4_bo, base);
}
struct vc4_fence { struct vc4_fence {
struct dma_fence base; struct dma_fence base;
...@@ -298,11 +292,8 @@ struct vc4_fence { ...@@ -298,11 +292,8 @@ struct vc4_fence {
uint64_t seqno; uint64_t seqno;
}; };
static inline struct vc4_fence * #define to_vc4_fence(_fence) \
to_vc4_fence(const struct dma_fence *fence) container_of_const(_fence, struct vc4_fence, base)
{
return container_of(fence, struct vc4_fence, base);
}
struct vc4_seqno_cb { struct vc4_seqno_cb {
struct work_struct work; struct work_struct work;
...@@ -368,11 +359,8 @@ struct vc4_hvs_state { ...@@ -368,11 +359,8 @@ struct vc4_hvs_state {
} fifo_state[HVS_NUM_CHANNELS]; } fifo_state[HVS_NUM_CHANNELS];
}; };
static inline struct vc4_hvs_state * #define to_vc4_hvs_state(_state) \
to_vc4_hvs_state(const struct drm_private_state *priv) container_of_const(_state, struct vc4_hvs_state, base)
{
return container_of(priv, struct vc4_hvs_state, base);
}
struct vc4_hvs_state *vc4_hvs_get_global_state(struct drm_atomic_state *state); struct vc4_hvs_state *vc4_hvs_get_global_state(struct drm_atomic_state *state);
struct vc4_hvs_state *vc4_hvs_get_old_global_state(const struct drm_atomic_state *state); struct vc4_hvs_state *vc4_hvs_get_old_global_state(const struct drm_atomic_state *state);
...@@ -382,11 +370,8 @@ struct vc4_plane { ...@@ -382,11 +370,8 @@ struct vc4_plane {
struct drm_plane base; struct drm_plane base;
}; };
static inline struct vc4_plane * #define to_vc4_plane(_plane) \
to_vc4_plane(const struct drm_plane *plane) container_of_const(_plane, struct vc4_plane, base)
{
return container_of(plane, struct vc4_plane, base);
}
enum vc4_scaling_mode { enum vc4_scaling_mode {
VC4_SCALING_NONE, VC4_SCALING_NONE,
...@@ -458,11 +443,8 @@ struct vc4_plane_state { ...@@ -458,11 +443,8 @@ struct vc4_plane_state {
u64 membus_load; u64 membus_load;
}; };
static inline struct vc4_plane_state * #define to_vc4_plane_state(_state) \
to_vc4_plane_state(const struct drm_plane_state *state) container_of_const(_state, struct vc4_plane_state, base)
{
return container_of(state, struct vc4_plane_state, base);
}
enum vc4_encoder_type { enum vc4_encoder_type {
VC4_ENCODER_TYPE_NONE, VC4_ENCODER_TYPE_NONE,
...@@ -489,11 +471,8 @@ struct vc4_encoder { ...@@ -489,11 +471,8 @@ struct vc4_encoder {
void (*post_crtc_powerdown)(struct drm_encoder *encoder, struct drm_atomic_state *state); void (*post_crtc_powerdown)(struct drm_encoder *encoder, struct drm_atomic_state *state);
}; };
static inline struct vc4_encoder * #define to_vc4_encoder(_encoder) \
to_vc4_encoder(const struct drm_encoder *encoder) container_of_const(_encoder, struct vc4_encoder, base)
{
return container_of(encoder, struct vc4_encoder, base);
}
static inline static inline
struct drm_encoder *vc4_find_encoder_by_type(struct drm_device *drm, struct drm_encoder *vc4_find_encoder_by_type(struct drm_device *drm,
...@@ -591,11 +570,8 @@ struct vc4_crtc { ...@@ -591,11 +570,8 @@ struct vc4_crtc {
unsigned int current_hvs_channel; unsigned int current_hvs_channel;
}; };
static inline struct vc4_crtc * #define to_vc4_crtc(_crtc) \
to_vc4_crtc(const struct drm_crtc *crtc) container_of_const(_crtc, struct vc4_crtc, base)
{
return container_of(crtc, struct vc4_crtc, base);
}
static inline const struct vc4_crtc_data * static inline const struct vc4_crtc_data *
vc4_crtc_to_vc4_crtc_data(const struct vc4_crtc *crtc) vc4_crtc_to_vc4_crtc_data(const struct vc4_crtc *crtc)
...@@ -608,7 +584,7 @@ vc4_crtc_to_vc4_pv_data(const struct vc4_crtc *crtc) ...@@ -608,7 +584,7 @@ vc4_crtc_to_vc4_pv_data(const struct vc4_crtc *crtc)
{ {
const struct vc4_crtc_data *data = vc4_crtc_to_vc4_crtc_data(crtc); const struct vc4_crtc_data *data = vc4_crtc_to_vc4_crtc_data(crtc);
return container_of(data, struct vc4_pv_data, base); return container_of_const(data, struct vc4_pv_data, base);
} }
struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc, struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc,
...@@ -636,11 +612,8 @@ struct vc4_crtc_state { ...@@ -636,11 +612,8 @@ struct vc4_crtc_state {
#define VC4_HVS_CHANNEL_DISABLED ((unsigned int)-1) #define VC4_HVS_CHANNEL_DISABLED ((unsigned int)-1)
static inline struct vc4_crtc_state * #define to_vc4_crtc_state(_state) \
to_vc4_crtc_state(const struct drm_crtc_state *crtc_state) container_of_const(_state, struct vc4_crtc_state, base)
{
return container_of(crtc_state, struct vc4_crtc_state, base);
}
#define V3D_READ(offset) \ #define V3D_READ(offset) \
({ \ ({ \
......
...@@ -600,19 +600,14 @@ struct vc4_dsi { ...@@ -600,19 +600,14 @@ struct vc4_dsi {
struct debugfs_regset32 regset; struct debugfs_regset32 regset;
}; };
#define host_to_dsi(host) container_of(host, struct vc4_dsi, dsi_host) #define host_to_dsi(host) \
container_of_const(host, struct vc4_dsi, dsi_host)
static inline struct vc4_dsi * #define to_vc4_dsi(_encoder) \
to_vc4_dsi(struct drm_encoder *encoder) container_of_const(_encoder, struct vc4_dsi, encoder.base)
{
return container_of(encoder, struct vc4_dsi, encoder.base);
}
static inline struct vc4_dsi * #define bridge_to_vc4_dsi(_bridge) \
bridge_to_vc4_dsi(struct drm_bridge *bridge) container_of_const(_bridge, struct vc4_dsi, bridge)
{
return container_of(bridge, struct vc4_dsi, bridge);
}
static inline void static inline void
dsi_dma_workaround_write(struct vc4_dsi *dsi, u32 offset, u32 val) dsi_dma_workaround_write(struct vc4_dsi *dsi, u32 offset, u32 val)
......
...@@ -222,17 +222,14 @@ struct vc4_hdmi { ...@@ -222,17 +222,14 @@ struct vc4_hdmi {
enum vc4_hdmi_output_format output_format; enum vc4_hdmi_output_format output_format;
}; };
static inline struct vc4_hdmi * #define connector_to_vc4_hdmi(_connector) \
connector_to_vc4_hdmi(struct drm_connector *connector) container_of_const(_connector, struct vc4_hdmi, connector)
{
return container_of(connector, struct vc4_hdmi, connector);
}
static inline struct vc4_hdmi * static inline struct vc4_hdmi *
encoder_to_vc4_hdmi(struct drm_encoder *encoder) encoder_to_vc4_hdmi(struct drm_encoder *encoder)
{ {
struct vc4_encoder *_encoder = to_vc4_encoder(encoder); struct vc4_encoder *_encoder = to_vc4_encoder(encoder);
return container_of(_encoder, struct vc4_hdmi, encoder); return container_of_const(_encoder, struct vc4_hdmi, encoder);
} }
struct vc4_hdmi_connector_state { struct vc4_hdmi_connector_state {
...@@ -242,11 +239,8 @@ struct vc4_hdmi_connector_state { ...@@ -242,11 +239,8 @@ struct vc4_hdmi_connector_state {
enum vc4_hdmi_output_format output_format; enum vc4_hdmi_output_format output_format;
}; };
static inline struct vc4_hdmi_connector_state * #define conn_state_to_vc4_hdmi_conn_state(_state) \
conn_state_to_vc4_hdmi_conn_state(struct drm_connector_state *conn_state) container_of_const(_state, struct vc4_hdmi_connector_state, base)
{
return container_of(conn_state, struct vc4_hdmi_connector_state, base);
}
void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi, void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
struct vc4_hdmi_connector_state *vc4_conn_state); struct vc4_hdmi_connector_state *vc4_conn_state);
......
...@@ -31,11 +31,8 @@ struct vc4_ctm_state { ...@@ -31,11 +31,8 @@ struct vc4_ctm_state {
int fifo; int fifo;
}; };
static struct vc4_ctm_state * #define to_vc4_ctm_state(_state) \
to_vc4_ctm_state(const struct drm_private_state *priv) container_of_const(_state, struct vc4_ctm_state, base)
{
return container_of(priv, struct vc4_ctm_state, base);
}
struct vc4_load_tracker_state { struct vc4_load_tracker_state {
struct drm_private_state base; struct drm_private_state base;
...@@ -43,11 +40,8 @@ struct vc4_load_tracker_state { ...@@ -43,11 +40,8 @@ struct vc4_load_tracker_state {
u64 membus_load; u64 membus_load;
}; };
static struct vc4_load_tracker_state * #define to_vc4_load_tracker_state(_state) \
to_vc4_load_tracker_state(const struct drm_private_state *priv) container_of_const(_state, struct vc4_load_tracker_state, base)
{
return container_of(priv, struct vc4_load_tracker_state, base);
}
static struct vc4_ctm_state *vc4_get_ctm_state(struct drm_atomic_state *state, static struct vc4_ctm_state *vc4_get_ctm_state(struct drm_atomic_state *state,
struct drm_private_obj *manager) struct drm_private_obj *manager)
...@@ -717,7 +711,7 @@ static void vc4_hvs_channels_destroy_state(struct drm_private_obj *obj, ...@@ -717,7 +711,7 @@ static void vc4_hvs_channels_destroy_state(struct drm_private_obj *obj,
static void vc4_hvs_channels_print_state(struct drm_printer *p, static void vc4_hvs_channels_print_state(struct drm_printer *p,
const struct drm_private_state *state) const struct drm_private_state *state)
{ {
struct vc4_hvs_state *hvs_state = to_vc4_hvs_state(state); const struct vc4_hvs_state *hvs_state = to_vc4_hvs_state(state);
unsigned int i; unsigned int i;
drm_printf(p, "HVS State\n"); drm_printf(p, "HVS State\n");
......
...@@ -1334,8 +1334,7 @@ u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist) ...@@ -1334,8 +1334,7 @@ u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist)
u32 vc4_plane_dlist_size(const struct drm_plane_state *state) u32 vc4_plane_dlist_size(const struct drm_plane_state *state)
{ {
const struct vc4_plane_state *vc4_state = const struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
container_of(state, typeof(*vc4_state), base);
return vc4_state->dlist_count; return vc4_state->dlist_count;
} }
......
...@@ -168,15 +168,11 @@ struct vc4_txp { ...@@ -168,15 +168,11 @@ struct vc4_txp {
void __iomem *regs; void __iomem *regs;
}; };
static inline struct vc4_txp *encoder_to_vc4_txp(struct drm_encoder *encoder) #define encoder_to_vc4_txp(_encoder) \
{ container_of_const(_encoder, struct vc4_txp, encoder.base)
return container_of(encoder, struct vc4_txp, encoder.base);
}
static inline struct vc4_txp *connector_to_vc4_txp(struct drm_connector *conn) #define connector_to_vc4_txp(_connector) \
{ container_of_const(_connector, struct vc4_txp, connector.base)
return container_of(conn, struct vc4_txp, connector.base);
}
static const struct debugfs_reg32 txp_regs[] = { static const struct debugfs_reg32 txp_regs[] = {
VC4_REG32(TXP_DST_PTR), VC4_REG32(TXP_DST_PTR),
......
...@@ -219,17 +219,11 @@ struct vc4_vec { ...@@ -219,17 +219,11 @@ struct vc4_vec {
writel(val, vec->regs + (offset)); \ writel(val, vec->regs + (offset)); \
} while (0) } while (0)
static inline struct vc4_vec * #define encoder_to_vc4_vec(_encoder) \
encoder_to_vc4_vec(struct drm_encoder *encoder) container_of_const(_encoder, struct vc4_vec, encoder.base)
{
return container_of(encoder, struct vc4_vec, encoder.base);
}
static inline struct vc4_vec * #define connector_to_vc4_vec(_connector) \
connector_to_vc4_vec(struct drm_connector *connector) container_of_const(_connector, struct vc4_vec, connector)
{
return container_of(connector, struct vc4_vec, connector);
}
enum vc4_vec_tv_mode_id { enum vc4_vec_tv_mode_id {
VC4_VEC_TV_MODE_NTSC, VC4_VEC_TV_MODE_NTSC,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment