1
0
Files
Greg Kroah-Hartman 9a966fb881 Merge 4.9.231 into android-4.9-q
Changes in 4.9.231
	KVM: s390: reduce number of IO pins to 1
	gpu: host1x: Detach driver on unregister
	spi: spidev: fix a race between spidev_release and spidev_remove
	spi: spidev: fix a potential use-after-free in spidev_release()
	s390/kasan: fix early pgm check handler execution
	cifs: update ctime and mtime during truncate
	ARM: imx6: add missing put_device() call in imx6q_suspend_init()
	scsi: mptscsih: Fix read sense data size
	net: cxgb4: fix return error value in t4_prep_fw
	smsc95xx: check return value of smsc95xx_reset
	smsc95xx: avoid memory leak in smsc95xx_bind
	ALSA: compress: fix partial_drain completion state
	arm64: kgdb: Fix single-step exception handling oops
	bnxt_en: fix NULL dereference in case SR-IOV configuration fails
	net: macb: mark device wake capable when "magic-packet" property present
	ALSA: opl3: fix infoleak in opl3
	ALSA: hda - let hs_mic be picked ahead of hp_mic
	ALSA: usb-audio: add quirk for MacroSilicon MS2109
	KVM: arm64: Fix definition of PAGE_HYP_DEVICE
	KVM: x86: bit 8 of non-leaf PDPEs is not reserved
	Revert "ath9k: Fix general protection fault in ath9k_hif_usb_rx_cb"
	btrfs: fix fatal extent_buffer readahead vs releasepage race
	drm/radeon: fix double free
	ARC: entry: fix potential EFA clobber when TIF_SYSCALL_TRACE
	ARC: elf: use right ELF_ARCH
	s390/mm: fix huge pte soft dirty copying
	ipv4: fill fl4_icmp_{type,code} in ping_v4_sendmsg
	l2tp: remove skb_dst_set() from l2tp_xmit_skb()
	llc: make sure applications use ARPHRD_ETHER
	net: Added pointer check for dst->ops->neigh_lookup in dst_neigh_lookup_skb
	net: usb: qmi_wwan: add support for Quectel EG95 LTE modem
	tcp: md5: add missing memory barriers in tcp_md5_do_add()/tcp_md5_hash_key()
	tcp: md5: refine tcp_md5_do_add()/tcp_md5_hash_key() barriers
	genetlink: remove genl_bind
	tcp: make sure listeners don't initialize congestion-control state
	tcp: md5: do not send silly options in SYNCOOKIES
	tcp: md5: allow changing MD5 keys in all socket states
	cgroup: fix cgroup_sk_alloc() for sk_clone_lock()
	cgroup: Fix sock_cgroup_data on big-endian.
	i2c: eg20t: Load module automatically if ID matches
	iio:magnetometer:ak8974: Fix alignment and data leak issues
	iio: magnetometer: ak8974: Fix runtime PM imbalance on error
	iio: mma8452: Add missed iio_device_unregister() call in mma8452_probe()
	iio: pressure: zpa2326: handle pm_runtime_get_sync failure
	iio:pressure:ms5611 Fix buffer element alignment
	iio:health:afe4403 Fix timestamp alignment and prevent data leak.
	spi: fix initial SPI_SR value in spi-fsl-dspi
	net: dsa: bcm_sf2: Fix node reference count
	Revert "usb/ehci-platform: Set PM runtime as active on resume"
	Revert "usb/xhci-plat: Set PM runtime as active on resume"
	Revert "usb/ohci-platform: Fix a warning when hibernating"
	iio:health:afe4404 Fix timestamp alignment and prevent data leak.
	spi: spi-sun6i: sun6i_spi_transfer_one(): fix setting of clock rate
	usb: gadget: udc: atmel: fix uninitialized read in debug printk
	staging: comedi: verify array index is correct before using it
	Revert "thermal: mediatek: fix register index error"
	ARM: dts: socfpga: Align L2 cache-controller nodename with dtschema
	perf stat: Zero all the 'ena' and 'run' array slot stats for interval mode
	mtd: rawnand: brcmnand: fix CS0 layout
	HID: magicmouse: do not set up autorepeat
	usb: core: Add a helper function to check the validity of EP type in URB
	ALSA: line6: Perform sanity check for each URB creation
	ALSA: usb-audio: Fix race against the error recovery URB submission
	USB: c67x00: fix use after free in c67x00_giveback_urb
	usb: dwc2: Fix shutdown callback in platform
	usb: chipidea: core: add wakeup support for extcon
	usb: gadget: function: fix missing spinlock in f_uac1_legacy
	USB: serial: iuu_phoenix: fix memory corruption
	USB: serial: cypress_m8: enable Simply Automated UPB PIM
	USB: serial: ch341: add new Product ID for CH340
	USB: serial: option: add GosunCn GM500 series
	USB: serial: option: add Quectel EG95 LTE modem
	virtio: virtio_console: add missing MODULE_DEVICE_TABLE() for rproc serial
	fuse: Fix parameter for FS_IOC_{GET,SET}FLAGS
	mei: bus: don't clean driver pointer
	Input: i8042 - add Lenovo XiaoXin Air 12 to i8042 nomux list
	uio_pdrv_genirq: fix use without device tree and no interrupt
	timer: Fix wheel index calculation on last level
	MIPS: Fix build for LTS kernel caused by backporting lpj adjustment
	hwmon: (emc2103) fix unable to change fan pwm1_enable attribute
	dmaengine: fsl-edma: Fix NULL pointer exception in fsl_edma_tx_handler
	misc: atmel-ssc: lock with mutex instead of spinlock
	arm64: ptrace: Override SPSR.SS when single-stepping is enabled
	sched/fair: handle case of task_h_load() returning 0
	irqchip/gic: Atomically update affinity
	x86/cpu: Move x86_cache_bits settings
	Linux 4.9.231

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I57b0f3c4ffcdc49231d1c48f3f25fae424daeeb9
2020-07-25 00:36:12 +03:00

618 lines
14 KiB
C

/*
* Copyright (C) 2012 Avionic Design GmbH
* Copyright (C) 2012-2013, NVIDIA Corporation
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/host1x.h>
#include <linux/of.h>
#include <linux/slab.h>
#include <linux/of_device.h>
#include "bus.h"
#include "dev.h"
static DEFINE_MUTEX(clients_lock);
static LIST_HEAD(clients);
static DEFINE_MUTEX(drivers_lock);
static LIST_HEAD(drivers);
static DEFINE_MUTEX(devices_lock);
static LIST_HEAD(devices);
struct host1x_subdev {
struct host1x_client *client;
struct device_node *np;
struct list_head list;
};
/**
* host1x_subdev_add() - add a new subdevice with an associated device node
*/
static int host1x_subdev_add(struct host1x_device *device,
struct device_node *np)
{
struct host1x_subdev *subdev;
subdev = kzalloc(sizeof(*subdev), GFP_KERNEL);
if (!subdev)
return -ENOMEM;
INIT_LIST_HEAD(&subdev->list);
subdev->np = of_node_get(np);
mutex_lock(&device->subdevs_lock);
list_add_tail(&subdev->list, &device->subdevs);
mutex_unlock(&device->subdevs_lock);
return 0;
}
/**
* host1x_subdev_del() - remove subdevice
*/
static void host1x_subdev_del(struct host1x_subdev *subdev)
{
list_del(&subdev->list);
of_node_put(subdev->np);
kfree(subdev);
}
/**
* host1x_device_parse_dt() - scan device tree and add matching subdevices
*/
static int host1x_device_parse_dt(struct host1x_device *device,
struct host1x_driver *driver)
{
struct device_node *np;
int err;
for_each_child_of_node(device->dev.parent->of_node, np) {
if (of_match_node(driver->subdevs, np) &&
of_device_is_available(np)) {
err = host1x_subdev_add(device, np);
if (err < 0) {
of_node_put(np);
return err;
}
}
}
return 0;
}
static void host1x_subdev_register(struct host1x_device *device,
struct host1x_subdev *subdev,
struct host1x_client *client)
{
int err;
/*
* Move the subdevice to the list of active (registered) subdevices
* and associate it with a client. At the same time, associate the
* client with its parent device.
*/
mutex_lock(&device->subdevs_lock);
mutex_lock(&device->clients_lock);
list_move_tail(&client->list, &device->clients);
list_move_tail(&subdev->list, &device->active);
client->parent = &device->dev;
subdev->client = client;
mutex_unlock(&device->clients_lock);
mutex_unlock(&device->subdevs_lock);
if (list_empty(&device->subdevs)) {
err = device_add(&device->dev);
if (err < 0)
dev_err(&device->dev, "failed to add: %d\n", err);
else
device->registered = true;
}
}
static void __host1x_subdev_unregister(struct host1x_device *device,
struct host1x_subdev *subdev)
{
struct host1x_client *client = subdev->client;
/*
* If all subdevices have been activated, we're about to remove the
* first active subdevice, so unload the driver first.
*/
if (list_empty(&device->subdevs)) {
if (device->registered) {
device->registered = false;
device_del(&device->dev);
}
}
/*
* Move the subdevice back to the list of idle subdevices and remove
* it from list of clients.
*/
mutex_lock(&device->clients_lock);
subdev->client = NULL;
client->parent = NULL;
list_move_tail(&subdev->list, &device->subdevs);
/*
* XXX: Perhaps don't do this here, but rather explicitly remove it
* when the device is about to be deleted.
*
* This is somewhat complicated by the fact that this function is
* used to remove the subdevice when a client is unregistered but
* also when the composite device is about to be removed.
*/
list_del_init(&client->list);
mutex_unlock(&device->clients_lock);
}
static void host1x_subdev_unregister(struct host1x_device *device,
struct host1x_subdev *subdev)
{
mutex_lock(&device->subdevs_lock);
__host1x_subdev_unregister(device, subdev);
mutex_unlock(&device->subdevs_lock);
}
int host1x_device_init(struct host1x_device *device)
{
struct host1x_client *client;
int err;
mutex_lock(&device->clients_lock);
list_for_each_entry(client, &device->clients, list) {
if (client->ops && client->ops->init) {
err = client->ops->init(client);
if (err < 0) {
dev_err(&device->dev,
"failed to initialize %s: %d\n",
dev_name(client->dev), err);
mutex_unlock(&device->clients_lock);
return err;
}
}
}
mutex_unlock(&device->clients_lock);
return 0;
}
EXPORT_SYMBOL(host1x_device_init);
int host1x_device_exit(struct host1x_device *device)
{
struct host1x_client *client;
int err;
mutex_lock(&device->clients_lock);
list_for_each_entry_reverse(client, &device->clients, list) {
if (client->ops && client->ops->exit) {
err = client->ops->exit(client);
if (err < 0) {
dev_err(&device->dev,
"failed to cleanup %s: %d\n",
dev_name(client->dev), err);
mutex_unlock(&device->clients_lock);
return err;
}
}
}
mutex_unlock(&device->clients_lock);
return 0;
}
EXPORT_SYMBOL(host1x_device_exit);
static int host1x_add_client(struct host1x *host1x,
struct host1x_client *client)
{
struct host1x_device *device;
struct host1x_subdev *subdev;
mutex_lock(&host1x->devices_lock);
list_for_each_entry(device, &host1x->devices, list) {
list_for_each_entry(subdev, &device->subdevs, list) {
if (subdev->np == client->dev->of_node) {
host1x_subdev_register(device, subdev, client);
mutex_unlock(&host1x->devices_lock);
return 0;
}
}
}
mutex_unlock(&host1x->devices_lock);
return -ENODEV;
}
static int host1x_del_client(struct host1x *host1x,
struct host1x_client *client)
{
struct host1x_device *device, *dt;
struct host1x_subdev *subdev;
mutex_lock(&host1x->devices_lock);
list_for_each_entry_safe(device, dt, &host1x->devices, list) {
list_for_each_entry(subdev, &device->active, list) {
if (subdev->client == client) {
host1x_subdev_unregister(device, subdev);
mutex_unlock(&host1x->devices_lock);
return 0;
}
}
}
mutex_unlock(&host1x->devices_lock);
return -ENODEV;
}
static int host1x_device_match(struct device *dev, struct device_driver *drv)
{
return strcmp(dev_name(dev), drv->name) == 0;
}
static int host1x_device_probe(struct device *dev)
{
struct host1x_driver *driver = to_host1x_driver(dev->driver);
struct host1x_device *device = to_host1x_device(dev);
if (driver->probe)
return driver->probe(device);
return 0;
}
static int host1x_device_remove(struct device *dev)
{
struct host1x_driver *driver = to_host1x_driver(dev->driver);
struct host1x_device *device = to_host1x_device(dev);
if (driver->remove)
return driver->remove(device);
return 0;
}
static void host1x_device_shutdown(struct device *dev)
{
struct host1x_driver *driver = to_host1x_driver(dev->driver);
struct host1x_device *device = to_host1x_device(dev);
if (driver->shutdown)
driver->shutdown(device);
}
static const struct dev_pm_ops host1x_device_pm_ops = {
.suspend = pm_generic_suspend,
.resume = pm_generic_resume,
.freeze = pm_generic_freeze,
.thaw = pm_generic_thaw,
.poweroff = pm_generic_poweroff,
.restore = pm_generic_restore,
};
struct bus_type host1x_bus_type = {
.name = "host1x",
.match = host1x_device_match,
.probe = host1x_device_probe,
.remove = host1x_device_remove,
.shutdown = host1x_device_shutdown,
.pm = &host1x_device_pm_ops,
};
static void __host1x_device_del(struct host1x_device *device)
{
struct host1x_subdev *subdev, *sd;
struct host1x_client *client, *cl;
mutex_lock(&device->subdevs_lock);
/* unregister subdevices */
list_for_each_entry_safe(subdev, sd, &device->active, list) {
/*
* host1x_subdev_unregister() will remove the client from
* any lists, so we'll need to manually add it back to the
* list of idle clients.
*
* XXX: Alternatively, perhaps don't remove the client from
* any lists in host1x_subdev_unregister() and instead do
* that explicitly from host1x_unregister_client()?
*/
client = subdev->client;
__host1x_subdev_unregister(device, subdev);
/* add the client to the list of idle clients */
mutex_lock(&clients_lock);
list_add_tail(&client->list, &clients);
mutex_unlock(&clients_lock);
}
/* remove subdevices */
list_for_each_entry_safe(subdev, sd, &device->subdevs, list)
host1x_subdev_del(subdev);
mutex_unlock(&device->subdevs_lock);
/* move clients to idle list */
mutex_lock(&clients_lock);
mutex_lock(&device->clients_lock);
list_for_each_entry_safe(client, cl, &device->clients, list)
list_move_tail(&client->list, &clients);
mutex_unlock(&device->clients_lock);
mutex_unlock(&clients_lock);
/* finally remove the device */
list_del_init(&device->list);
}
static void host1x_device_release(struct device *dev)
{
struct host1x_device *device = to_host1x_device(dev);
__host1x_device_del(device);
kfree(device);
}
static int host1x_device_add(struct host1x *host1x,
struct host1x_driver *driver)
{
struct host1x_client *client, *tmp;
struct host1x_subdev *subdev;
struct host1x_device *device;
int err;
device = kzalloc(sizeof(*device), GFP_KERNEL);
if (!device)
return -ENOMEM;
device_initialize(&device->dev);
mutex_init(&device->subdevs_lock);
INIT_LIST_HEAD(&device->subdevs);
INIT_LIST_HEAD(&device->active);
mutex_init(&device->clients_lock);
INIT_LIST_HEAD(&device->clients);
INIT_LIST_HEAD(&device->list);
device->driver = driver;
device->dev.coherent_dma_mask = host1x->dev->coherent_dma_mask;
device->dev.dma_mask = &device->dev.coherent_dma_mask;
dev_set_name(&device->dev, "%s", driver->driver.name);
of_dma_configure(&device->dev, host1x->dev->of_node);
device->dev.release = host1x_device_release;
device->dev.bus = &host1x_bus_type;
device->dev.parent = host1x->dev;
err = host1x_device_parse_dt(device, driver);
if (err < 0) {
kfree(device);
return err;
}
list_add_tail(&device->list, &host1x->devices);
mutex_lock(&clients_lock);
list_for_each_entry_safe(client, tmp, &clients, list) {
list_for_each_entry(subdev, &device->subdevs, list) {
if (subdev->np == client->dev->of_node) {
host1x_subdev_register(device, subdev, client);
break;
}
}
}
mutex_unlock(&clients_lock);
return 0;
}
/*
* Removes a device by first unregistering any subdevices and then removing
* itself from the list of devices.
*
* This function must be called with the host1x->devices_lock held.
*/
static void host1x_device_del(struct host1x *host1x,
struct host1x_device *device)
{
if (device->registered) {
device->registered = false;
device_del(&device->dev);
}
put_device(&device->dev);
}
static void host1x_attach_driver(struct host1x *host1x,
struct host1x_driver *driver)
{
struct host1x_device *device;
int err;
mutex_lock(&host1x->devices_lock);
list_for_each_entry(device, &host1x->devices, list) {
if (device->driver == driver) {
mutex_unlock(&host1x->devices_lock);
return;
}
}
err = host1x_device_add(host1x, driver);
if (err < 0)
dev_err(host1x->dev, "failed to allocate device: %d\n", err);
mutex_unlock(&host1x->devices_lock);
}
static void host1x_detach_driver(struct host1x *host1x,
struct host1x_driver *driver)
{
struct host1x_device *device, *tmp;
mutex_lock(&host1x->devices_lock);
list_for_each_entry_safe(device, tmp, &host1x->devices, list)
if (device->driver == driver)
host1x_device_del(host1x, device);
mutex_unlock(&host1x->devices_lock);
}
int host1x_register(struct host1x *host1x)
{
struct host1x_driver *driver;
mutex_lock(&devices_lock);
list_add_tail(&host1x->list, &devices);
mutex_unlock(&devices_lock);
mutex_lock(&drivers_lock);
list_for_each_entry(driver, &drivers, list)
host1x_attach_driver(host1x, driver);
mutex_unlock(&drivers_lock);
return 0;
}
int host1x_unregister(struct host1x *host1x)
{
struct host1x_driver *driver;
mutex_lock(&drivers_lock);
list_for_each_entry(driver, &drivers, list)
host1x_detach_driver(host1x, driver);
mutex_unlock(&drivers_lock);
mutex_lock(&devices_lock);
list_del_init(&host1x->list);
mutex_unlock(&devices_lock);
return 0;
}
int host1x_driver_register_full(struct host1x_driver *driver,
struct module *owner)
{
struct host1x *host1x;
INIT_LIST_HEAD(&driver->list);
mutex_lock(&drivers_lock);
list_add_tail(&driver->list, &drivers);
mutex_unlock(&drivers_lock);
mutex_lock(&devices_lock);
list_for_each_entry(host1x, &devices, list)
host1x_attach_driver(host1x, driver);
mutex_unlock(&devices_lock);
driver->driver.bus = &host1x_bus_type;
driver->driver.owner = owner;
return driver_register(&driver->driver);
}
EXPORT_SYMBOL(host1x_driver_register_full);
void host1x_driver_unregister(struct host1x_driver *driver)
{
struct host1x *host1x;
driver_unregister(&driver->driver);
mutex_lock(&devices_lock);
list_for_each_entry(host1x, &devices, list)
host1x_detach_driver(host1x, driver);
mutex_unlock(&devices_lock);
mutex_lock(&drivers_lock);
list_del_init(&driver->list);
mutex_unlock(&drivers_lock);
}
EXPORT_SYMBOL(host1x_driver_unregister);
int host1x_client_register(struct host1x_client *client)
{
struct host1x *host1x;
int err;
mutex_lock(&devices_lock);
list_for_each_entry(host1x, &devices, list) {
err = host1x_add_client(host1x, client);
if (!err) {
mutex_unlock(&devices_lock);
return 0;
}
}
mutex_unlock(&devices_lock);
mutex_lock(&clients_lock);
list_add_tail(&client->list, &clients);
mutex_unlock(&clients_lock);
return 0;
}
EXPORT_SYMBOL(host1x_client_register);
int host1x_client_unregister(struct host1x_client *client)
{
struct host1x_client *c;
struct host1x *host1x;
int err;
mutex_lock(&devices_lock);
list_for_each_entry(host1x, &devices, list) {
err = host1x_del_client(host1x, client);
if (!err) {
mutex_unlock(&devices_lock);
return 0;
}
}
mutex_unlock(&devices_lock);
mutex_lock(&clients_lock);
list_for_each_entry(c, &clients, list) {
if (c == client) {
list_del_init(&c->list);
break;
}
}
mutex_unlock(&clients_lock);
return 0;
}
EXPORT_SYMBOL(host1x_client_unregister);