manifest.o \
module.o \
interface.o \
- function.o \
connection.o \
operation.o \
i2c-gb.o \
* 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);
/* 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);
}
#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);
+++ /dev/null
-/*
- * 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);
-}
+++ /dev/null
-/*
- * 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 */
#include "manifest.h"
#include "module.h"
#include "interface.h"
-#include "function.h"
#include "connection.h"
#include "operation.h"
/* 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++;
/* 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) {