From: Alex Elder Date: Thu, 2 Oct 2014 17:30:05 +0000 (-0500) Subject: greybus: get rid of functions now... X-Git-Tag: v4.9-rc1~119^2~378^2~21^2~2052 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=cd345074bb7cb2c2bdd6bc3b042c38a74128ed6c;p=karo-tx-linux.git greybus: get rid of functions now... We decided yesterday that we would no longer support the notion of a "function." Instead, a connection will simply exist between the AP and an interface on a module (and a CPort Id on each end). What was previously considered the "function type" will now be handled as the "protocol" associated with the connection. Update gb_connection_create() to take just the interface and a cport id associated with that interface. Right now every module points back to a host device, so for now we'll establish the connection back to that. Signed-off-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/Makefile b/drivers/staging/greybus/Makefile index a303f81a542d..42a3944f4eeb 100644 --- a/drivers/staging/greybus/Makefile +++ b/drivers/staging/greybus/Makefile @@ -6,7 +6,6 @@ greybus-y := core.o \ manifest.o \ module.o \ interface.o \ - function.o \ connection.o \ operation.o \ i2c-gb.o \ diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c index b16ac4c0cc81..f3f774d2ed7b 100644 --- a/drivers/staging/greybus/connection.c +++ b/drivers/staging/greybus/connection.c @@ -22,23 +22,25 @@ * Returns a pointer to the new connection if successful, or a null * pointer otherwise. */ -struct gb_connection *gb_connection_create(struct greybus_host_device *hd, - struct gb_function *function) +struct gb_connection *gb_connection_create(struct gb_interface *interface, + u16 cport_id) { struct gb_connection *connection; + struct greybus_host_device *hd; connection = kzalloc(sizeof(*connection), GFP_KERNEL); if (!connection) return NULL; - connection->cport_id = greybus_hd_cport_id_alloc(hd); - if (connection->cport_id == CPORT_ID_BAD) { + hd = interface->gmod->hd; + connection->hd_cport_id = greybus_hd_cport_id_alloc(hd); + if (connection->hd_cport_id == CPORT_ID_BAD) { kfree(connection); return NULL; } - connection->hd = hd; /* XXX refcount? */ - connection->function = function; /* XXX refcount? */ + connection->interface = interface; /* XXX refcount? */ + connection->interface_cport_id = cport_id; INIT_LIST_HEAD(&connection->operations); atomic_set(&connection->op_cycle, 0); @@ -56,9 +58,9 @@ void gb_connection_destroy(struct gb_connection *connection) /* XXX Need to wait for any outstanding requests to complete */ WARN_ON(!list_empty(&connection->operations)); - greybus_hd_cport_id_free(connection->hd, connection->cport_id); - /* kref_put(function); */ - /* kref_put(hd); */ + greybus_hd_cport_id_free(connection->hd, connection->hd_cport_id); + /* kref_put(connection->interface); */ + /* kref_put(connection->hd); */ kfree(connection); } diff --git a/drivers/staging/greybus/connection.h b/drivers/staging/greybus/connection.h index f06ff92d7487..530d6451c75d 100644 --- a/drivers/staging/greybus/connection.h +++ b/drivers/staging/greybus/connection.h @@ -14,18 +14,21 @@ #include "greybus.h" struct gb_connection { - struct gb_function *function; struct greybus_host_device *hd; - u16 cport_id; /* Host side */ + struct gb_interface *interface; + u16 hd_cport_id; + u16 interface_cport_id; - struct list_head host_links; + struct list_head hd_links; + struct list_head interface_links; + /* protocol */ struct list_head operations; atomic_t op_cycle; }; -struct gb_connection *gb_connection_create(struct greybus_host_device *hd, - struct gb_function *function); +struct gb_connection *gb_connection_create(struct gb_interface *interface, + u16 cport_id); void gb_connection_destroy(struct gb_connection *connection); u16 gb_connection_op_id(struct gb_connection *connection); diff --git a/drivers/staging/greybus/function.c b/drivers/staging/greybus/function.c deleted file mode 100644 index bfc9ac7e4c81..000000000000 --- a/drivers/staging/greybus/function.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Greybus functions - * - * Copyright 2014 Google Inc. - * - * Released under the GPLv2 only. - */ - -#include "greybus.h" - -/* XXX This could be per-host device or per-module or per-interface */ -static DEFINE_SPINLOCK(gb_functions_lock); - -/* - * A Greybus function generically defines an entity associated with - * a CPort within a module. Each function has a type (e.g. i2c, - * GPIO, etc.) that defines how it behaves and how the AP interacts - * with it. - * - * Create a gb_function structure to represent a discovered - * function. Returns a pointer to the new function or a null - * pointer if a failure occurs due to memory exhaustion. - */ -struct gb_function *gb_function_create(struct gb_interface *interface, - u16 cport_id) -{ - struct gb_function *function; - - function = kzalloc(sizeof(*function), GFP_KERNEL); - if (!function) - return NULL; - - function->interface = interface; /* XXX refcount? */ - function->cport_id = cport_id; - - spin_lock_irq(&gb_functions_lock); - list_add_tail(&function->links, &interface->functions); - spin_unlock_irq(&gb_functions_lock); - - return function; -} - -/* - * Tear down a previously set up function. - */ -void gb_function_destroy(struct gb_function *function) -{ - if (WARN_ON(!function)) - return; - - spin_lock_irq(&gb_functions_lock); - list_del(&function->links); - spin_unlock_irq(&gb_functions_lock); - - /* kref_put(gmod); */ - kfree(function); -} diff --git a/drivers/staging/greybus/function.h b/drivers/staging/greybus/function.h deleted file mode 100644 index e1b30c515a2a..000000000000 --- a/drivers/staging/greybus/function.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Greybus functions - * - * Copyright 2014 Google Inc. - * - * Released under the GPLv2 only. - */ - -#ifndef __FUNCTION_H -#define __FUNCTION_H - -struct gb_function { - struct gb_interface *interface; - u16 cport_id; - - struct list_head links; /* interface->functions */ -}; - -struct gb_function *gb_function_create(struct gb_interface *interface, - u16 cport_id); -void gb_function_destroy(struct gb_function *function); - -#endif /* __FUNCTION_H */ diff --git a/drivers/staging/greybus/greybus.h b/drivers/staging/greybus/greybus.h index 077daf0a92bf..0813201260b1 100644 --- a/drivers/staging/greybus/greybus.h +++ b/drivers/staging/greybus/greybus.h @@ -24,7 +24,6 @@ #include "manifest.h" #include "module.h" #include "interface.h" -#include "function.h" #include "connection.h" #include "operation.h" diff --git a/drivers/staging/greybus/manifest.c b/drivers/staging/greybus/manifest.c index 4066547cd2e5..6411c26928b3 100644 --- a/drivers/staging/greybus/manifest.c +++ b/drivers/staging/greybus/manifest.c @@ -204,7 +204,7 @@ u32 gb_manifest_parse_cports(struct gb_interface *interface) /* Found one. Set up its function structure */ protocol = (enum greybus_protocol)desc_cport->protocol; cport_id = le16_to_cpu(desc_cport->id); - if (!gb_function_create(interface, cport_id)) + if (!gb_connection_create(interface, cport_id)) return 0; /* Error */ count++; diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c index 5cb23aa3867a..b930d24ce552 100644 --- a/drivers/staging/greybus/operation.c +++ b/drivers/staging/greybus/operation.c @@ -124,8 +124,8 @@ struct gb_operation *gb_operation_create(struct gb_connection *connection, /* Our buffer holds a header in addition to the requested payload */ size += sizeof(*header); - gbuf = greybus_alloc_gbuf(connection->function->interface->gmod, - connection->cport_id, + gbuf = greybus_alloc_gbuf(connection->interface->gmod, + connection->hd_cport_id, gbuf_out_callback, size, GFP_KERNEL, operation); if (gbuf) {