Commit cd345074 authored by Alex Elder's avatar Alex Elder Committed by Greg Kroah-Hartman

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: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 9e8a6860
...@@ -6,7 +6,6 @@ greybus-y := core.o \ ...@@ -6,7 +6,6 @@ greybus-y := core.o \
manifest.o \ manifest.o \
module.o \ module.o \
interface.o \ interface.o \
function.o \
connection.o \ connection.o \
operation.o \ operation.o \
i2c-gb.o \ i2c-gb.o \
......
...@@ -22,23 +22,25 @@ ...@@ -22,23 +22,25 @@
* Returns a pointer to the new connection if successful, or a null * Returns a pointer to the new connection if successful, or a null
* pointer otherwise. * pointer otherwise.
*/ */
struct gb_connection *gb_connection_create(struct greybus_host_device *hd, struct gb_connection *gb_connection_create(struct gb_interface *interface,
struct gb_function *function) u16 cport_id)
{ {
struct gb_connection *connection; struct gb_connection *connection;
struct greybus_host_device *hd;
connection = kzalloc(sizeof(*connection), GFP_KERNEL); connection = kzalloc(sizeof(*connection), GFP_KERNEL);
if (!connection) if (!connection)
return NULL; return NULL;
connection->cport_id = greybus_hd_cport_id_alloc(hd); hd = interface->gmod->hd;
if (connection->cport_id == CPORT_ID_BAD) { connection->hd_cport_id = greybus_hd_cport_id_alloc(hd);
if (connection->hd_cport_id == CPORT_ID_BAD) {
kfree(connection); kfree(connection);
return NULL; return NULL;
} }
connection->hd = hd; /* XXX refcount? */ 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); INIT_LIST_HEAD(&connection->operations);
atomic_set(&connection->op_cycle, 0); atomic_set(&connection->op_cycle, 0);
...@@ -56,9 +58,9 @@ void gb_connection_destroy(struct gb_connection *connection) ...@@ -56,9 +58,9 @@ void gb_connection_destroy(struct gb_connection *connection)
/* XXX Need to wait for any outstanding requests to complete */ /* XXX Need to wait for any outstanding requests to complete */
WARN_ON(!list_empty(&connection->operations)); WARN_ON(!list_empty(&connection->operations));
greybus_hd_cport_id_free(connection->hd, connection->cport_id); greybus_hd_cport_id_free(connection->hd, connection->hd_cport_id);
/* kref_put(function); */ /* kref_put(connection->interface); */
/* kref_put(hd); */ /* kref_put(connection->hd); */
kfree(connection); kfree(connection);
} }
......
...@@ -14,18 +14,21 @@ ...@@ -14,18 +14,21 @@
#include "greybus.h" #include "greybus.h"
struct gb_connection { struct gb_connection {
struct gb_function *function;
struct greybus_host_device *hd; 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; struct list_head operations;
atomic_t op_cycle; atomic_t op_cycle;
}; };
struct gb_connection *gb_connection_create(struct greybus_host_device *hd, struct gb_connection *gb_connection_create(struct gb_interface *interface,
struct gb_function *function); u16 cport_id);
void gb_connection_destroy(struct gb_connection *connection); void gb_connection_destroy(struct gb_connection *connection);
u16 gb_connection_op_id(struct gb_connection *connection); u16 gb_connection_op_id(struct gb_connection *connection);
......
/*
* 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);
}
/*
* 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 */
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "manifest.h" #include "manifest.h"
#include "module.h" #include "module.h"
#include "interface.h" #include "interface.h"
#include "function.h"
#include "connection.h" #include "connection.h"
#include "operation.h" #include "operation.h"
......
...@@ -204,7 +204,7 @@ u32 gb_manifest_parse_cports(struct gb_interface *interface) ...@@ -204,7 +204,7 @@ u32 gb_manifest_parse_cports(struct gb_interface *interface)
/* Found one. Set up its function structure */ /* Found one. Set up its function structure */
protocol = (enum greybus_protocol)desc_cport->protocol; protocol = (enum greybus_protocol)desc_cport->protocol;
cport_id = le16_to_cpu(desc_cport->id); 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 */ return 0; /* Error */
count++; count++;
......
...@@ -124,8 +124,8 @@ struct gb_operation *gb_operation_create(struct gb_connection *connection, ...@@ -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 */ /* Our buffer holds a header in addition to the requested payload */
size += sizeof(*header); size += sizeof(*header);
gbuf = greybus_alloc_gbuf(connection->function->interface->gmod, gbuf = greybus_alloc_gbuf(connection->interface->gmod,
connection->cport_id, connection->hd_cport_id,
gbuf_out_callback, size, gbuf_out_callback, size,
GFP_KERNEL, operation); GFP_KERNEL, operation);
if (gbuf) { if (gbuf) {
......
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