Skip to content

Commit 933deb8

Browse files
committed
gpu: host1x: Add early init and late exit callbacks
These callbacks can be used by client drivers to run code during early init and during late exit. Early init callbacks are run prior to the regular init callbacks while late exit callbacks run after the regular exit callbacks. Signed-off-by: Thierry Reding <treding@nvidia.com>
1 parent d3555eb commit 933deb8

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

drivers/gpu/host1x/bus.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ int host1x_device_init(struct host1x_device *device)
196196

197197
mutex_lock(&device->clients_lock);
198198

199+
list_for_each_entry(client, &device->clients, list) {
200+
if (client->ops && client->ops->early_init) {
201+
err = client->ops->early_init(client);
202+
if (err < 0) {
203+
dev_err(&device->dev, "failed to early initialize %s: %d\n",
204+
dev_name(client->dev), err);
205+
goto teardown_late;
206+
}
207+
}
208+
}
209+
199210
list_for_each_entry(client, &device->clients, list) {
200211
if (client->ops && client->ops->init) {
201212
err = client->ops->init(client);
@@ -217,6 +228,14 @@ int host1x_device_init(struct host1x_device *device)
217228
if (client->ops->exit)
218229
client->ops->exit(client);
219230

231+
/* reset client to end of list for late teardown */
232+
client = list_entry(&device->clients, struct host1x_client, list);
233+
234+
teardown_late:
235+
list_for_each_entry_continue_reverse(client, &device->clients, list)
236+
if (client->ops->late_exit)
237+
client->ops->late_exit(client);
238+
220239
mutex_unlock(&device->clients_lock);
221240
return err;
222241
}
@@ -251,6 +270,18 @@ int host1x_device_exit(struct host1x_device *device)
251270
}
252271
}
253272

273+
list_for_each_entry_reverse(client, &device->clients, list) {
274+
if (client->ops && client->ops->late_exit) {
275+
err = client->ops->late_exit(client);
276+
if (err < 0) {
277+
dev_err(&device->dev, "failed to late cleanup %s: %d\n",
278+
dev_name(client->dev), err);
279+
mutex_unlock(&device->clients_lock);
280+
return err;
281+
}
282+
}
283+
}
284+
254285
mutex_unlock(&device->clients_lock);
255286

256287
return 0;

include/linux/host1x.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@ u64 host1x_get_dma_mask(struct host1x *host1x);
2525

2626
/**
2727
* struct host1x_client_ops - host1x client operations
28+
* @early_init: host1x client early initialization code
2829
* @init: host1x client initialization code
2930
* @exit: host1x client tear down code
31+
* @late_exit: host1x client late tear down code
3032
* @suspend: host1x client suspend code
3133
* @resume: host1x client resume code
3234
*/
3335
struct host1x_client_ops {
36+
int (*early_init)(struct host1x_client *client);
3437
int (*init)(struct host1x_client *client);
3538
int (*exit)(struct host1x_client *client);
39+
int (*late_exit)(struct host1x_client *client);
3640
int (*suspend)(struct host1x_client *client);
3741
int (*resume)(struct host1x_client *client);
3842
};

0 commit comments

Comments
 (0)