static BOOL sig_read_header(VISORCHANNEL *channel, U32 queue, SIGNAL_QUEUE_HEADER *sig_hdr) { BOOL rc = FALSE; if (channel->chan_hdr.oChannelSpace < sizeof(CHANNEL_HEADER)) { ERRDRV("oChannelSpace too small: (status=%d)\n", rc); goto Away; } /* Read the appropriate SIGNAL_QUEUE_HEADER into local memory. */ if (visor_memregion_read(channel->memregion, SIG_QUEUE_OFFSET(&channel->chan_hdr, queue), sig_hdr, sizeof(SIGNAL_QUEUE_HEADER)) < 0) { ERRDRV("queue=%d SIG_QUEUE_OFFSET=%d", queue, (int)SIG_QUEUE_OFFSET(&channel->chan_hdr, queue)); ERRDRV("visor_memregion_read of signal queue failed: (status=%d)\n", rc); goto Away; } rc = TRUE; Away: return rc; }
static BOOL sig_do_data(VISORCHANNEL *channel, u32 queue, struct signal_queue_header *sig_hdr, u32 slot, void *data, BOOL is_write) { BOOL rc = FALSE; int signal_data_offset = SIG_DATA_OFFSET(&channel->chan_hdr, queue, sig_hdr, slot); if (is_write) { if (visor_memregion_write(channel->memregion, signal_data_offset, data, sig_hdr->signal_size) < 0) { ERRDRV("visor_memregion_write of signal data failed: (status=%d)\n", rc); goto cleanup; } } else { if (visor_memregion_read(channel->memregion, signal_data_offset, data, sig_hdr->signal_size) < 0) { ERRDRV("visor_memregion_read of signal data failed: (status=%d)\n", rc); goto cleanup; } } rc = TRUE; cleanup: return rc; }
static BOOL signalremove_inner(struct visorchannel *channel, u32 queue, void *msg) { struct signal_queue_header sig_hdr; if (!sig_read_header(channel, queue, &sig_hdr)) { return FALSE; } if (sig_hdr.head == sig_hdr.tail) return FALSE; /* no signals to remove */ sig_hdr.tail = (sig_hdr.tail + 1) % sig_hdr.max_slots; if (!sig_read_data(channel, queue, &sig_hdr, sig_hdr.tail, msg)) { ERRDRV("sig_read_data failed\n"); return FALSE; } sig_hdr.num_received++; /* For each data field in SIGNAL_QUEUE_HEADER that was modified, * update host memory. */ mb(); /* required for channel synch */ if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, tail)) { ERRDRV("visor_memregion_write of Tail failed\n"); return FALSE; } if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, num_received)) { ERRDRV("visor_memregion_write of NumSignalsReceived failed\n"); return FALSE; } return TRUE; }
static BOOL sig_do_data(VISORCHANNEL *channel, U32 queue, SIGNAL_QUEUE_HEADER *sig_hdr, U32 slot, void *data, BOOL is_write) { BOOL rc = FALSE; int signal_data_offset = SIG_DATA_OFFSET(&channel->chan_hdr, queue, sig_hdr, slot); if (is_write) { if (visor_memregion_write(channel->memregion, signal_data_offset, data, sig_hdr->SignalSize) < 0) { ERRDRV("visor_memregion_write of signal data failed: (status=%d)\n", rc); goto Away; } } else { if (visor_memregion_read(channel->memregion, signal_data_offset, data, sig_hdr->SignalSize) < 0) { ERRDRV("visor_memregion_read of signal data failed: (status=%d)\n", rc); goto Away; } } rc = TRUE; Away: return rc; }
static BOOL sig_read_header(VISORCHANNEL *channel, u32 queue, struct signal_queue_header *sig_hdr) { BOOL rc = FALSE; if (channel->chan_hdr.ch_space_offset < sizeof(struct channel_header)) { ERRDRV("oChannelSpace too small: (status=%d)\n", rc); goto cleanup; } /* Read the appropriate SIGNAL_QUEUE_HEADER into local memory. */ if (visor_memregion_read(channel->memregion, SIG_QUEUE_OFFSET(&channel->chan_hdr, queue), sig_hdr, sizeof(struct signal_queue_header)) < 0) { ERRDRV("queue=%d SIG_QUEUE_OFFSET=%d", queue, (int)SIG_QUEUE_OFFSET(&channel->chan_hdr, queue)); ERRDRV("visor_memregion_read of signal queue failed: (status=%d)\n", rc); goto cleanup; } rc = TRUE; cleanup: return rc; }
MEMREGION * visor_memregion_create_overlapped(MEMREGION *parent, ulong offset, ulong nbytes) { MEMREGION *memregion = NULL; if (parent == NULL) { ERRDRV("%s parent is NULL", __func__); return NULL; } if (parent->mapped == NULL) { ERRDRV("%s parent is not mapped!", __func__); return NULL; } if ((offset >= parent->nbytes) || ((offset + nbytes) >= parent->nbytes)) { ERRDRV("%s range (%lu,%lu) out of parent range", __func__, offset, nbytes); return NULL; } memregion = kzalloc(sizeof(MEMREGION), GFP_KERNEL|__GFP_NORETRY); if (memregion == NULL) { ERRDRV("%s allocation failed", __func__); return NULL; } memregion->physaddr = parent->physaddr + offset; memregion->nbytes = nbytes; memregion->mapped = ((u8 *) (parent->mapped)) + offset; memregion->requested = FALSE; memregion->overlapped = TRUE; return memregion; }
BOOL visorchannel_signalinsert(VISORCHANNEL *channel, u32 queue, void *msg) { BOOL rc = FALSE; struct signal_queue_header sig_hdr; if (channel->needs_lock) spin_lock(&channel->insert_lock); if (!sig_read_header(channel, queue, &sig_hdr)) { rc = FALSE; goto cleanup; } sig_hdr.head = ((sig_hdr.head + 1) % sig_hdr.max_slots); if (sig_hdr.head == sig_hdr.tail) { sig_hdr.num_overflows++; if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, num_overflows)) { ERRDRV("visor_memregion_write of NumOverflows failed: (status=%d)\n", rc); goto cleanup; } rc = FALSE; goto cleanup; } if (!sig_write_data(channel, queue, &sig_hdr, sig_hdr.head, msg)) { ERRDRV("sig_write_data failed: (status=%d)\n", rc); goto cleanup; } sig_hdr.num_sent++; /* For each data field in SIGNAL_QUEUE_HEADER that was modified, * update host memory. */ mb(); /* required for channel synch */ if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, head)) { ERRDRV("visor_memregion_write of Head failed: (status=%d)\n", rc); goto cleanup; } if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, num_sent)) { ERRDRV("visor_memregion_write of NumSignalsSent failed: (status=%d)\n", rc); goto cleanup; } rc = TRUE; cleanup: if (channel->needs_lock) spin_unlock(&channel->insert_lock); return rc; }
BOOL visorchannel_signalinsert(VISORCHANNEL *channel, U32 queue, void *msg) { BOOL rc = FALSE; SIGNAL_QUEUE_HEADER sig_hdr; if (channel->needs_lock) spin_lock(&channel->insert_lock); if (!sig_read_header(channel, queue, &sig_hdr)) { rc = FALSE; goto Away; } sig_hdr.Head = ((sig_hdr.Head + 1) % sig_hdr.MaxSignalSlots); if (sig_hdr.Head == sig_hdr.Tail) { sig_hdr.NumOverflows++; if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, NumOverflows)) { ERRDRV("visor_memregion_write of NumOverflows failed: (status=%d)\n", rc); goto Away; } rc = FALSE; goto Away; } if (!sig_write_data(channel, queue, &sig_hdr, sig_hdr.Head, msg)) { ERRDRV("sig_write_data failed: (status=%d)\n", rc); goto Away; } sig_hdr.NumSignalsSent++; /* For each data field in SIGNAL_QUEUE_HEADER that was modified, * update host memory. */ MEMORYBARRIER; if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, Head)) { ERRDRV("visor_memregion_write of Head failed: (status=%d)\n", rc); goto Away; } if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, NumSignalsSent)) { ERRDRV("visor_memregion_write of NumSignalsSent failed: (status=%d)\n", rc); goto Away; } rc = TRUE; Away: if (channel->needs_lock) spin_unlock(&channel->insert_lock); return rc; }
MEMREGION * visor_memregion_create(HOSTADDRESS physaddr, ulong nbytes) { MEMREGION *rc = NULL; MEMREGION *memregion = kzalloc(sizeof(MEMREGION), GFP_KERNEL | __GFP_NORETRY); if (memregion == NULL) { ERRDRV("visor_memregion_create allocation failed"); return NULL; } memregion->physaddr = physaddr; memregion->nbytes = nbytes; memregion->overlapped = FALSE; if (!mapit(memregion)) { rc = NULL; goto Away; } rc = memregion; Away: if (rc == NULL) { if (memregion != NULL) { visor_memregion_destroy(memregion); memregion = NULL; } } return rc; }
static struct proc_dir_entry * createProcDir(const char *name, struct proc_dir_entry *parent) { struct proc_dir_entry *p = proc_mkdir_mode(name, S_IFDIR, parent); if (p == NULL) ERRDRV("failed to create /proc directory %s", name); return p; }
BOOL visorchannel_signalremove(VISORCHANNEL *channel, u32 queue, void *msg) { BOOL rc = FALSE; struct signal_queue_header sig_hdr; if (channel->needs_lock) spin_lock(&channel->remove_lock); if (!sig_read_header(channel, queue, &sig_hdr)) { rc = FALSE; goto cleanup; } if (sig_hdr.head == sig_hdr.tail) { rc = FALSE; /* no signals to remove */ goto cleanup; } sig_hdr.tail = (sig_hdr.tail + 1) % sig_hdr.max_slots; if (!sig_read_data(channel, queue, &sig_hdr, sig_hdr.tail, msg)) { ERRDRV("sig_read_data failed: (status=%d)\n", rc); goto cleanup; } sig_hdr.num_received++; /* For each data field in SIGNAL_QUEUE_HEADER that was modified, * update host memory. */ mb(); /* required for channel synch */ if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, tail)) { ERRDRV("visor_memregion_write of Tail failed: (status=%d)\n", rc); goto cleanup; } if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, num_received)) { ERRDRV("visor_memregion_write of NumSignalsReceived failed: (status=%d)\n", rc); goto cleanup; } rc = TRUE; cleanup: if (channel->needs_lock) spin_unlock(&channel->remove_lock); return rc; }
BOOL visorchannel_signalremove(VISORCHANNEL *channel, U32 queue, void *msg) { BOOL rc = FALSE; SIGNAL_QUEUE_HEADER sig_hdr; if (channel->needs_lock) spin_lock(&channel->remove_lock); if (!sig_read_header(channel, queue, &sig_hdr)) { rc = FALSE; goto Away; } if (sig_hdr.Head == sig_hdr.Tail) { rc = FALSE; /* no signals to remove */ goto Away; } sig_hdr.Tail = (sig_hdr.Tail + 1) % sig_hdr.MaxSignalSlots; if (!sig_read_data(channel, queue, &sig_hdr, sig_hdr.Tail, msg)) { ERRDRV("sig_read_data failed: (status=%d)\n", rc); goto Away; } sig_hdr.NumSignalsReceived++; /* For each data field in SIGNAL_QUEUE_HEADER that was modified, * update host memory. */ MEMORYBARRIER; if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, Tail)) { ERRDRV("visor_memregion_write of Tail failed: (status=%d)\n", rc); goto Away; } if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, NumSignalsReceived)) { ERRDRV("visor_memregion_write of NumSignalsReceived failed: (status=%d)\n", rc); goto Away; } rc = TRUE; Away: if (channel->needs_lock) spin_unlock(&channel->remove_lock); return rc; }
static struct proc_dir_entry * createProcFile(const char *name, struct proc_dir_entry *parent, const struct file_operations *fops, void *data) { struct proc_dir_entry *p = proc_create_data(name, 0, parent, fops, data); if (p == NULL) ERRDRV("failed to create /proc file %s", name); return p; }
static BOOL mapit(MEMREGION *memregion) { ulong physaddr = (ulong) (memregion->physaddr); ulong nbytes = memregion->nbytes; memregion->requested = FALSE; if (!request_mem_region(physaddr, nbytes, MYDRVNAME)) ERRDRV("cannot reserve channel memory @0x%lx for 0x%lx-- no big deal", physaddr, nbytes); else memregion->requested = TRUE; memregion->mapped = ioremap_cache(physaddr, nbytes); if (memregion->mapped == NULL) { ERRDRV("cannot ioremap_cache channel memory @0x%lx for 0x%lx", physaddr, nbytes); return FALSE; } return TRUE; }
static BOOL signalinsert_inner(struct visorchannel *channel, u32 queue, void *msg) { struct signal_queue_header sig_hdr; if (!sig_read_header(channel, queue, &sig_hdr)) { return FALSE; } sig_hdr.head = ((sig_hdr.head + 1) % sig_hdr.max_slots); if (sig_hdr.head == sig_hdr.tail) { sig_hdr.num_overflows++; if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, num_overflows)) ERRDRV("visor_memregion_write of NumOverflows failed\n"); return FALSE; } if (!sig_write_data(channel, queue, &sig_hdr, sig_hdr.head, msg)) { ERRDRV("sig_write_data failed\n"); return FALSE; } sig_hdr.num_sent++; /* For each data field in SIGNAL_QUEUE_HEADER that was modified, * update host memory. */ mb(); /* required for channel synch */ if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, head)) { ERRDRV("visor_memregion_write of Head failed\n"); return FALSE; } if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, num_sent)) { ERRDRV("visor_memregion_write of NumSignalsSent failed\n"); return FALSE; } return TRUE; }
uuid_le parser_id_get(PARSER_CONTEXT *ctx) { ULTRA_CONTROLVM_PARAMETERS_HEADER *phdr = NULL; if (ctx == NULL) { ERRDRV("%s (%s:%d) - no context", __func__, __FILE__, __LINE__); return NULL_UUID_LE; } phdr = (ULTRA_CONTROLVM_PARAMETERS_HEADER *) (ctx->data); return phdr->Id; }
uuid_le parser_id_get(PARSER_CONTEXT *ctx) { struct spar_controlvm_parameters_header *phdr = NULL; if (ctx == NULL) { ERRDRV("%s (%s:%d) - no context", __func__, __FILE__, __LINE__); return NULL_UUID_LE; } phdr = (struct spar_controlvm_parameters_header *)(ctx->data); return phdr->id; }
void parser_param_start(PARSER_CONTEXT *ctx, PARSER_WHICH_STRING which_string) { ULTRA_CONTROLVM_PARAMETERS_HEADER *phdr = NULL; if (ctx == NULL) { ERRDRV("%s (%s:%d) - no context", __func__, __FILE__, __LINE__); goto Away; } phdr = (ULTRA_CONTROLVM_PARAMETERS_HEADER *) (ctx->data); switch (which_string) { case PARSERSTRING_INITIATOR: ctx->curr = ctx->data + phdr->InitiatorOffset; ctx->bytes_remaining = phdr->InitiatorLength; break; case PARSERSTRING_TARGET: ctx->curr = ctx->data + phdr->TargetOffset; ctx->bytes_remaining = phdr->TargetLength; break; case PARSERSTRING_CONNECTION: ctx->curr = ctx->data + phdr->ConnectionOffset; ctx->bytes_remaining = phdr->ConnectionLength; break; case PARSERSTRING_NAME: ctx->curr = ctx->data + phdr->NameOffset; ctx->bytes_remaining = phdr->NameLength; break; default: ERRDRV("%s - bad which_string %d", __func__, which_string); break; } Away: return; }
CHARQUEUE *visor_charqueue_create(ulong nslots) { int alloc_size = sizeof(CHARQUEUE) + nslots + 1; CHARQUEUE *cq = kmalloc(alloc_size, GFP_KERNEL|__GFP_NORETRY); if (cq == NULL) { ERRDRV("visor_charqueue_create allocation failed (alloc_size=%d)", alloc_size); return NULL; } cq->alloc_size = alloc_size; cq->nslots = nslots; cq->head = cq->tail = 0; spin_lock_init(&cq->lock); return cq; }
void parser_param_start(PARSER_CONTEXT *ctx, PARSER_WHICH_STRING which_string) { struct spar_controlvm_parameters_header *phdr = NULL; if (ctx == NULL) { ERRDRV("%s (%s:%d) - no context", __func__, __FILE__, __LINE__); goto Away; } phdr = (struct spar_controlvm_parameters_header *)(ctx->data); switch (which_string) { case PARSERSTRING_INITIATOR: ctx->curr = ctx->data + phdr->initiator_offset; ctx->bytes_remaining = phdr->initiator_length; break; case PARSERSTRING_TARGET: ctx->curr = ctx->data + phdr->target_offset; ctx->bytes_remaining = phdr->target_length; break; case PARSERSTRING_CONNECTION: ctx->curr = ctx->data + phdr->connection_offset; ctx->bytes_remaining = phdr->connection_length; break; case PARSERSTRING_NAME: ctx->curr = ctx->data + phdr->name_offset; ctx->bytes_remaining = phdr->name_length; break; default: ERRDRV("%s - bad which_string %d", __func__, which_string); break; } Away: return; }
static int memregion_readwrite(BOOL is_write, MEMREGION *memregion, ulong offset, void *local, ulong nbytes) { if (offset + nbytes > memregion->nbytes) { ERRDRV("memregion_readwrite offset out of range!!"); return -EFAULT; } if (is_write) memcpy_toio(memregion->mapped + offset, local, nbytes); else memcpy_fromio(local, memregion->mapped + offset, nbytes); return 0; }
HOSTADDRESS controlvm_get_channel_address(void) { static BOOL warned = FALSE; U64 addr = 0; U32 size = 0; if (!VMCALL_SUCCESSFUL(Issue_VMCALL_IO_CONTROLVM_ADDR(&addr, &size))) { if (!warned) { ERRDRV("%s - vmcall to determine controlvm channel addr failed", __func__); warned = TRUE; } return 0; } INFODRV("controlvm addr=%Lx", addr); return addr; }
void visorchannel_dump_section(VISORCHANNEL *chan, char *s, int off, int len, struct seq_file *seq) { char *buf, *tbuf, *fmtbuf; int fmtbufsize = 0; int i; int errcode = 0; fmtbufsize = 100 * COVQ(len, 16); buf = kmalloc(len, GFP_KERNEL|__GFP_NORETRY); fmtbuf = kmalloc(fmtbufsize, GFP_KERNEL|__GFP_NORETRY); if (buf == NULL || fmtbuf == NULL) goto Away; errcode = visorchannel_read(chan, off, buf, len); if (errcode < 0) { ERRDRV("%s failed to read %s from channel errcode=%d", s, __func__, errcode); goto Away; } seq_printf(seq, "channel %s:\n", s); tbuf = buf; while (len > 0) { i = (len < 16) ? len : 16; hex_dump_to_buffer(tbuf, i, 16, 1, fmtbuf, fmtbufsize, TRUE); seq_printf(seq, "%s\n", fmtbuf); tbuf += 16; len -= 16; } Away: if (buf != NULL) { kfree(buf); buf = NULL; } if (fmtbuf != NULL) { kfree(fmtbuf); fmtbuf = NULL; } }
static inline unsigned char safe_sig_queue_validate(struct signal_queue_header *psafe_sqh, struct signal_queue_header *punsafe_sqh, u32 *phead, u32 *ptail) { if ((*phead >= psafe_sqh->max_slots) || (*ptail >= psafe_sqh->max_slots)) { /* Choose 0 or max, maybe based on current tail value */ *phead = 0; *ptail = 0; /* Sync with client as necessary */ punsafe_sqh->head = *phead; punsafe_sqh->tail = *ptail; ERRDRV("safe_sig_queue_validate: head = 0x%x, tail = 0x%x, MaxSlots = 0x%x", *phead, *ptail, psafe_sqh->max_slots); return 0; } return 1; } /* end safe_sig_queue_validate */
static inline unsigned char safe_sig_queue_validate(pSIGNAL_QUEUE_HEADER psafe_sqh, pSIGNAL_QUEUE_HEADER punsafe_sqh, U32 *phead, U32 *ptail) { if ((*phead >= psafe_sqh->MaxSignalSlots) || (*ptail >= psafe_sqh->MaxSignalSlots)) { /* Choose 0 or max, maybe based on current tail value */ *phead = 0; *ptail = 0; /* Sync with client as necessary */ punsafe_sqh->Head = *phead; punsafe_sqh->Tail = *ptail; ERRDRV("safe_sig_queue_validate: head = 0x%x, tail = 0x%x, MaxSlots = 0x%x", *phead, *ptail, psafe_sqh->MaxSignalSlots); return 0; } return 1; } /* end safe_sig_queue_validate */
int visorchannel_clear(struct visorchannel *channel, ulong offset, u8 ch, ulong nbytes) { int rc = -1; int bufsize = 65536; int written = 0; u8 *buf = vmalloc(bufsize); if (buf == NULL) { ERRDRV("%s failed memory allocation", __func__); goto cleanup; } memset(buf, ch, bufsize); while (nbytes > 0) { ulong thisbytes = bufsize; int x = -1; if (nbytes < thisbytes) thisbytes = nbytes; x = visor_memregion_write(channel->memregion, offset + written, buf, thisbytes); if (x < 0) { rc = x; goto cleanup; } written += thisbytes; nbytes -= thisbytes; } rc = 0; cleanup: if (buf != NULL) { vfree(buf); buf = NULL; } return rc; }
void visorchannel_debug(VISORCHANNEL *channel, int nQueues, struct seq_file *seq, U32 off) { HOSTADDRESS addr = 0; ulong nbytes = 0, nbytes_region = 0; MEMREGION *memregion = NULL; CHANNEL_HEADER hdr; CHANNEL_HEADER *phdr = &hdr; int i = 0; int errcode = 0; if (channel == NULL) { ERRDRV("%s no channel", __func__); return; } memregion = channel->memregion; if (memregion == NULL) { ERRDRV("%s no memregion", __func__); return; } addr = visor_memregion_get_physaddr(memregion); nbytes_region = visor_memregion_get_nbytes(memregion); errcode = visorchannel_read(channel, off, phdr, sizeof(CHANNEL_HEADER)); if (errcode < 0) { seq_printf(seq, "Read of channel header failed with errcode=%d)\n", errcode); if (off == 0) { phdr = &channel->chan_hdr; seq_puts(seq, "(following data may be stale)\n"); } else return; } nbytes = (ulong) (phdr->Size); seq_printf(seq, "--- Begin channel @0x%-16.16Lx for 0x%lx bytes (region=0x%lx bytes) ---\n", addr + off, nbytes, nbytes_region); seq_printf(seq, "Type = %pUL\n", &phdr->Type); seq_printf(seq, "ZoneGuid = %pUL\n", &phdr->ZoneGuid); seq_printf(seq, "Signature = 0x%-16.16Lx\n", (long long) phdr->Signature); seq_printf(seq, "LegacyState = %lu\n", (ulong) phdr->LegacyState); seq_printf(seq, "SrvState = %lu\n", (ulong) phdr->SrvState); seq_printf(seq, "CliStateBoot = %lu\n", (ulong) phdr->CliStateBoot); seq_printf(seq, "CliStateOS = %lu\n", (ulong) phdr->CliStateOS); seq_printf(seq, "HeaderSize = %lu\n", (ulong) phdr->HeaderSize); seq_printf(seq, "Size = %llu\n", (long long) phdr->Size); seq_printf(seq, "Features = 0x%-16.16llx\n", (long long) phdr->Features); seq_printf(seq, "PartitionHandle = 0x%-16.16llx\n", (long long) phdr->PartitionHandle); seq_printf(seq, "Handle = 0x%-16.16llx\n", (long long) phdr->Handle); seq_printf(seq, "VersionId = %lu\n", (ulong) phdr->VersionId); seq_printf(seq, "oChannelSpace = %llu\n", (long long) phdr->oChannelSpace); if ((phdr->oChannelSpace == 0) || (errcode < 0)) ; else for (i = 0; i < nQueues; i++) { SIGNAL_QUEUE_HEADER q; errcode = visorchannel_read(channel, off + phdr->oChannelSpace + (i * sizeof(q)), &q, sizeof(q)); if (errcode < 0) { seq_printf(seq, "failed to read signal queue #%d from channel @0x%-16.16Lx errcode=%d\n", i, addr, errcode); continue; } sigqueue_debug(&q, i, seq); } seq_printf(seq, "--- End channel @0x%-16.16Lx for 0x%lx bytes ---\n", addr + off, nbytes); }
/* Creates the VISORCHANNEL abstraction for a data area in memory, but does * NOT modify this data area. */ static VISORCHANNEL * visorchannel_create_guts(HOSTADDRESS physaddr, ulong channelBytes, VISORCHANNEL *parent, ulong off, uuid_le guid, BOOL needs_lock) { VISORCHANNEL *p = NULL; void *rc = NULL; p = kmalloc(sizeof(VISORCHANNEL), GFP_KERNEL|__GFP_NORETRY); if (p == NULL) { ERRDRV("allocation failed: (status=0)\n"); rc = NULL; goto Away; } p->memregion = NULL; p->needs_lock = needs_lock; spin_lock_init(&p->insert_lock); spin_lock_init(&p->remove_lock); /* prepare chan_hdr (abstraction to read/write channel memory) */ if (parent == NULL) p->memregion = visor_memregion_create(physaddr, sizeof(CHANNEL_HEADER)); else p->memregion = visor_memregion_create_overlapped(parent->memregion, off, sizeof(CHANNEL_HEADER)); if (p->memregion == NULL) { ERRDRV("visor_memregion_create failed failed: (status=0)\n"); rc = NULL; goto Away; } if (visor_memregion_read(p->memregion, 0, &p->chan_hdr, sizeof(CHANNEL_HEADER)) < 0) { ERRDRV("visor_memregion_read failed: (status=0)\n"); rc = NULL; goto Away; } if (channelBytes == 0) /* we had better be a CLIENT of this channel */ channelBytes = (ulong) p->chan_hdr.Size; if (uuid_le_cmp(guid, NULL_UUID_LE) == 0) /* we had better be a CLIENT of this channel */ guid = p->chan_hdr.Type; if (visor_memregion_resize(p->memregion, channelBytes) < 0) { ERRDRV("visor_memregion_resize failed: (status=0)\n"); rc = NULL; goto Away; } p->size = channelBytes; p->guid = guid; rc = p; Away: if (rc == NULL) { if (p != NULL) { visorchannel_destroy(p); p = NULL; } } return rc; }
MYPROCTYPE *visor_proc_CreateType(struct proc_dir_entry *procDirRoot, const char **name, const char **propertyNames, void (*show_property)(struct seq_file *, void *, int)) { int i = 0; MYPROCTYPE *rc = NULL, *type = NULL; struct proc_dir_entry *parent = NULL; if (procDirRoot == NULL) { ERRDRV("procDirRoot cannot be NULL!\n"); goto Away; } if (name == NULL || name[0] == NULL) { ERRDRV("name must contain at least 1 node name!\n"); goto Away; } type = kzalloc(sizeof(MYPROCTYPE), GFP_KERNEL | __GFP_NORETRY); if (type == NULL) { ERRDRV("out of memory\n"); goto Away; } type->name = name; type->propertyNames = propertyNames; type->nProperties = 0; type->nNames = 0; type->show_property = show_property; type->procDirRoot = procDirRoot; if (type->propertyNames != NULL) while (type->propertyNames[type->nProperties] != NULL) type->nProperties++; while (type->name[type->nNames] != NULL) type->nNames++; type->procDirs = kzalloc((type->nNames + 1) * sizeof(struct proc_dir_entry *), GFP_KERNEL | __GFP_NORETRY); if (type->procDirs == NULL) { ERRDRV("out of memory\n"); goto Away; } parent = procDirRoot; for (i = 0; i < type->nNames; i++) { type->procDirs[i] = createProcDir(type->name[i], parent); if (type->procDirs[i] == NULL) { rc = NULL; goto Away; } parent = type->procDirs[i]; } type->procDir = type->procDirs[type->nNames-1]; rc = type; Away: if (rc == NULL) { if (type != NULL) { visor_proc_DestroyType(type); type = NULL; } } return rc; }
MYPROCOBJECT *visor_proc_CreateObject(MYPROCTYPE *type, const char *name, void *context) { MYPROCOBJECT *obj = NULL, *rc = NULL; int i = 0; if (type == NULL) { ERRDRV("type cannot be NULL\n"); goto Away; } obj = kzalloc(sizeof(MYPROCOBJECT), GFP_KERNEL | __GFP_NORETRY); if (obj == NULL) { ERRDRV("out of memory\n"); goto Away; } obj->type = type; obj->context = context; if (name == NULL) { obj->name = NULL; obj->procDir = type->procDir; } else { obj->namesize = strlen(name)+1; obj->name = kmalloc(obj->namesize, GFP_KERNEL | __GFP_NORETRY); if (obj->name == NULL) { obj->namesize = 0; ERRDRV("out of memory\n"); goto Away; } strcpy(obj->name, name); obj->procDir = createProcDir(obj->name, type->procDir); if (obj->procDir == NULL) { goto Away; } } obj->procDirPropertyContexts = kzalloc((type->nProperties + 1) * sizeof(PROCDIRENTRYCONTEXT), GFP_KERNEL | __GFP_NORETRY); if (obj->procDirPropertyContexts == NULL) { ERRDRV("out of memory\n"); goto Away; } obj->procDirProperties = kzalloc((type->nProperties + 1) * sizeof(struct proc_dir_entry *), GFP_KERNEL | __GFP_NORETRY); if (obj->procDirProperties == NULL) { ERRDRV("out of memory\n"); goto Away; } for (i = 0; i < type->nProperties; i++) { obj->procDirPropertyContexts[i].procObject = obj; obj->procDirPropertyContexts[i].propertyIndex = i; obj->procDirPropertyContexts[i].show_property = type->show_property; if (type->propertyNames[i][0] != '\0') { /* only create properties that have names */ obj->procDirProperties[i] = createProcFile(type->propertyNames[i], obj->procDir, &proc_fops, &obj->procDirPropertyContexts[i]); if (obj->procDirProperties[i] == NULL) { rc = NULL; goto Away; } } } rc = obj; Away: if (rc == NULL) { if (obj != NULL) { visor_proc_DestroyObject(obj); obj = NULL; } } return rc; }