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 <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This commit is contained in:
Alex Elder 2014-10-02 12:30:05 -05:00 committed by Greg Kroah-Hartman
parent 9e8a6860f5
commit cd345074bb
8 changed files with 22 additions and 99 deletions

View file

@ -6,7 +6,6 @@ greybus-y := core.o \
manifest.o \
module.o \
interface.o \
function.o \
connection.o \
operation.o \
i2c-gb.o \

View file

@ -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);
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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 */

View file

@ -24,7 +24,6 @@
#include "manifest.h"
#include "module.h"
#include "interface.h"
#include "function.h"
#include "connection.h"
#include "operation.h"

View file

@ -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++;

View file

@ -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) {