Source
x
static int occ_getsram(struct occ *occ, u32 address, void *data, ssize_t len)
// SPDX-License-Identifier: GPL-2.0
/*
* Assume we don't have much FFDC, if we do we'll overflow and
* fail the command. This needs to be big enough for simple
* commands as well.
*/
struct occ {
struct device *dev;
struct device *sbefifo;
char name[32];
int idx;
struct miscdevice mdev;
struct mutex occ_lock;
};
struct occ_response {
u8 seq_no;
u8 cmd_type;
u8 return_status;
__be16 data_length;
u8 data[OCC_RESP_DATA_BYTES + 2]; /* two bytes checksum */
} __packed;
struct occ_client {
struct occ *occ;
struct mutex lock;
size_t data_size;
size_t read_offset;
u8 *buffer;
};
static DEFINE_IDA(occ_ida);
static int occ_open(struct inode *inode, struct file *file)
{
struct occ_client *client = kzalloc(sizeof(*client), GFP_KERNEL);
struct miscdevice *mdev = file->private_data;
struct occ *occ = to_occ(mdev);
if (!client)
return -ENOMEM;
client->buffer = (u8 *)__get_free_page(GFP_KERNEL);
if (!client->buffer) {
kfree(client);
return -ENOMEM;
}
client->occ = occ;
mutex_init(&client->lock);
file->private_data = client;
/* We allocate a 1-page buffer, make sure it all fits */
BUILD_BUG_ON((OCC_CMD_DATA_BYTES + 3) > PAGE_SIZE);
BUILD_BUG_ON((OCC_RESP_DATA_BYTES + 7) > PAGE_SIZE);