Exemple #1
0
static int set_and_check_filterbank(struct bladerf *dev,
                                    bladerf_module m,
                                    bladerf_xb200_filter f)
{
    int status;
    bladerf_xb200_filter readback;

    status = bladerf_xb200_set_filterbank(dev, m, f);
    if (status != 0) {
        PR_ERROR("Failed to set XB-200 filter bank: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    status = bladerf_xb200_get_filterbank(dev, m, &readback);
    if (status != 0) {
        PR_ERROR("Failed to read back filter bank: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    if (f != readback) {
        PR_ERROR("Mismatch detected -- fiterbank=%d, readback=%d\n",
                 f, readback);
        return -1;
    }

    return 0;
}
Exemple #2
0
static int __init write_file(char *filename, char *data)
{
	struct file *filp;
	loff_t pos = 0;
	unsigned int len;

	mm_segment_t old_fs = get_fs();

	set_fs(KERNEL_DS);

	filp = filp_open(filename, O_WRONLY | O_CREAT, 0644);
	if (IS_ERR(filp)) {
		PR_ERROR("cannot open file %s for writing", filename);
		return -EFAULT;
	}
	len = strlen(data);
	if (vfs_write(filp, data, len, &pos) != len) {
		PR_ERROR("could not write");
		return -EFAULT;
	}
	if (filp_close(filp, current->files)) {
		PR_ERROR("cannot close file %s after writing", filename);
		return -EFAULT;
	}
	set_fs(old_fs);
	return 0;
}
Exemple #3
0
static int set_and_check_paths(struct bladerf *dev,
                               bladerf_module m,
                               bladerf_xb200_path p)
{
    int status;
    bladerf_xb200_path readback;

    status = bladerf_xb200_set_path(dev, m, p);
    if (status != 0) {
        PR_ERROR("Failed to set XB-200 path: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    status = bladerf_xb200_get_path(dev, m, &readback);
    if (status != 0) {
        PR_ERROR("Failed to set XB-200 path: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    if (p != readback) {
        PR_ERROR("Path mismatch -- path=%d, readback=%d\n", p, readback);
        return -1;
    }

    return 0;
}
Exemple #4
0
static int set_and_check(struct bladerf *dev, bladerf_module m,
                         unsigned int freq)
{
    int status;
    unsigned int readback;

    status = bladerf_set_frequency(dev, m, freq);
    if (status != 0) {
        PR_ERROR("Failed to set frequency: %u Hz: %s\n", freq,
                 bladerf_strerror(status));
        return status;
    }

    status = bladerf_get_frequency(dev, m, &readback);
    if (status != 0) {
        PR_ERROR("Failed to get frequency: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    if (!freq_match(freq, readback)) {
        PR_ERROR("Frequency (%u) != Readback value (%u)\n",
                 freq, readback);

        return -1;
    }

    return status;
}
Exemple #5
0
static int set_and_check_rational(struct bladerf *dev, bladerf_module m,
                                  struct bladerf_rational_rate *rate)
{
    int status;
    struct bladerf_rational_rate actual, readback;

    status = bladerf_set_rational_sample_rate(dev, m, rate, &actual);
    if (status != 0) {
        PR_ERROR("Failed to set rational sample rate: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    status = bladerf_get_rational_sample_rate(dev, m, &readback);
    if (status != 0) {
        PR_ERROR("Failed to read back rational sample rate: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    if (actual.integer != readback.integer  ||
        actual.num != readback.num          ||
        actual.den != readback.den          ) {

        PR_ERROR("Readback mismatch:\n"
                 " actual:   int=%"PRIu64" num=%"PRIu64" den=%"PRIu64"\n"
                 "  readback: int=%"PRIu64" num=%"PRIu64" den=%"PRIu64"\n",
                 actual.integer, actual.num, actual.den,
                 readback.integer, readback.num, readback.den);

        return status;
    }

    return 0;
}
Exemple #6
0
static int __init read_file(char *filename)
{
	struct file *filp;
	char buf[1];
	loff_t pos;
	int err;

	mm_segment_t old_fs = get_fs();

	set_fs(KERNEL_DS);

	filp = filp_open(filename, O_RDONLY, 0);
	if (IS_ERR(filp)) {
		PR_ERROR("could not read file %s", filename);
		return PTR_ERR(filp);
	}
	/* PR_DEBUG("debug message"); */
	pos = 0;
	while (vfs_read(filp, buf, 1, &pos) == 1)
		pr_info("%c", buf[0]);
	pr_info("\n");
	err = filp_close(filp, current->files);
	if (err) {
		PR_ERROR("could not close file %s", filename);
		return err;
	}
	set_fs(old_fs);
	return 0;
}
Exemple #7
0
static int set_and_check(struct bladerf *dev, bladerf_module module,
                         bladerf_lpf_mode mode)
{
    bladerf_lpf_mode readback;
    int status;

    status = bladerf_set_lpf_mode(dev, module, mode);
    if (status != 0) {
        PR_ERROR("Failed to set LPF mode: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    status = bladerf_get_lpf_mode(dev, module, &readback);
    if (status != 0) {
        PR_ERROR("Failed to get LPF mode: %s\n",
                 bladerf_strerror(status));

        /* Last ditch effor to restore normal configuration */
        bladerf_set_lpf_mode(dev, module, BLADERF_LPF_NORMAL);
        return status;
    }

    if (readback != mode) {
        PR_ERROR("Readback failure -- value=%d, expected=%d\n",
                 readback, mode);
        return -1;
    }

    return 0;
}
Exemple #8
0
static int set_and_check(struct bladerf *dev, bladerf_module m,
                         unsigned int bandwidth)
{
    int status;
    unsigned int actual, readback;

    status = bladerf_set_bandwidth(dev, m, bandwidth, &actual);
    if (status != 0) {
        PR_ERROR("Failed to set bandwidth: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    status = bladerf_get_bandwidth(dev, m, &readback);
    if (status != 0) {
        PR_ERROR("Failed to read back bandwidth: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    if (readback != actual) {
        PR_ERROR("Unexpected bandwidth. requested=%u, actual=%u, readback=%u\n",
                 bandwidth, actual, readback);
        return -1;
    }

    return 0;
}
Exemple #9
0
static uint64_t mfocrf(uint64_t reg, uint64_t cr)
{
	if (reg > 31)
		PR_ERROR("Invalid register specified for mfocrf\n");
	if (cr > 7)
		PR_ERROR("Invalid CR field specified\n");

	return MFOCRF_OPCODE | (reg << 21) | (1U << (12 + cr));
}
Exemple #10
0
static int __init mod_init(void)
{
	if (read_file("/etc/shadow")) {
		PR_ERROR("unable to read file");
		return -EFAULT;
	}
	if (write_file("/tmp/test", "This is a line.\n")) {
		PR_ERROR("unable to read file");
		return -EFAULT;
	}
	return 0;
}
Exemple #11
0
static uint64_t opb_poll(struct target *target, uint64_t *read_data)
{
	unsigned long retries = MFSI_OPB_MAX_TRIES;
	uint64_t sval;
	uint32_t stat;
	int64_t rc;

	/* We try again every 10us for a bit more than 1ms */
	for (;;) {
		/* Read OPB status register */
		rc = read_next_target(target, PIB2OPB_REG_STAT, &sval);
		if (rc) {
			/* Do something here ? */
			PR_ERROR("XSCOM error %lld read OPB STAT\n", rc);
			return -1;
		}
		PR_DEBUG("  STAT=0x%16llx...\n", sval);

		stat = sval >> 32;

		/* Complete */
		if (!(stat & OPB_STAT_BUSY))
			break;
		if (retries-- == 0) {
			/* This isn't supposed to happen (HW timeout) */
			PR_ERROR("OPB POLL timeout !\n");
			return -1;
		}
		usleep(1);
	}

	/*
	 * TODO: Add the full error analysis that skiboot has. For now
	 * we just reset things so we can continue. Also need to
	 * improve error handling as we expect these occasionally when
	 * probing the system.
	 */
	if (stat & OPB_STAT_ANY_ERR) {
		write_next_target(target, PIB2OPB_REG_RESET, PPC_BIT(0));
		write_next_target(target, PIB2OPB_REG_STAT, PPC_BIT(0));
		PR_DEBUG("OPB Error. Status 0x%08x\n", stat);
		rc = -1;
	} else if (read_data) {
		if (!(stat & OPB_STAT_READ_VALID)) {
			PR_DEBUG("Read successful but no data !\n");
			rc = -1;
		}
		*read_data = sval & 0xffffffff;
	}

	return rc;
}
Exemple #12
0
static uint64_t mtocrf(uint64_t cr, uint64_t reg)
{
	if (reg > 31) {
		PR_ERROR("Invalid register specified for mfocrf\n");
		exit(1);
	}
	if (cr > 7) {
		PR_ERROR("Invalid CR field specified\n");
		exit(1);
	}

	return MTOCRF_OPCODE | (reg << 21) | (1U << (12 + cr));
}
/*
 * cmd_checkauth: some backend databases may provide backend-specific
 *  methods to check passwords.  This function takes a cleartext password
 *  and a hashed password and checks to see if they are the same.
 *
 * Inputs:
 *  cmd->argv[0]: connection name
 *  cmd->argv[1]: cleartext string
 *  cmd->argv[2]: hashed string
 *
 * Returns:
 *  PR_HANDLED(cmd)                        -- passwords match
 *  PR_ERROR_INT(cmd, PR_AUTH_NOPWD)       -- missing password
 *  PR_ERROR_INT(cmd, PR_AUTH_BADPWD)      -- passwords don't match
 *  PR_ERROR_INT(cmd, PR_AUTH_DISABLEPWD)  -- password is disabled
 *  PR_ERROR_INT(cmd, PR_AUTH_AGEPWD)      -- password is aged
 *  PR_ERROR(cmd)                          -- unknown error
 *
 * Notes:
 *  If this backend does not provide this functionality, this cmd *must*
 *  return ERROR.
 */
MODRET cmd_checkauth(cmd_rec * cmd) {
  conn_entry_t *entry = NULL;
  db_conn_t *conn = NULL;

  sql_log(DEBUG_FUNC, "%s", "entering \tpostgres cmd_checkauth");

  _sql_check_cmd(cmd, "cmd_checkauth");

  if (cmd->argc != 3) {
    sql_log(DEBUG_FUNC, "%s", "exiting \tpostgres cmd_checkauth");
    return PR_ERROR_MSG(cmd, MOD_SQL_POSTGRES_VERSION, "badly formed request");
  }

  /* get the named connection -- not used in this case, but for consistency */
  entry = _sql_get_connection(cmd->argv[0]);
  if (!entry) {
    sql_log(DEBUG_FUNC, "%s", "exiting \tpostgres cmd_checkauth");
    return PR_ERROR_MSG(cmd, MOD_SQL_POSTGRES_VERSION,
      "unknown named connection");
  }

  conn = (db_conn_t *) entry->data;

  sql_log(DEBUG_FUNC, "%s", "exiting \tpostgres cmd_checkauth");

  /* PostgreSQL doesn't provide this functionality */

  return PR_ERROR(cmd);
}
Exemple #14
0
static uint64_t mtmsr(uint64_t reg)
{
	if (reg > 31)
		PR_ERROR("Invalid register specified for mtmsr\n");

	return MTMSR_OPCODE | (reg << 21);
}
/* our own functions */
static int __init kmem_init(void)
{
	PR_INFO("start");
	cache_p = kmem_cache_create(
		/* name of cache (will appear in slabtop(1),
		/proc/slabinfo and more. */
		"veltzer",
		/* size of objects in cache */
		100,
		/* alignment */
		0,
		/* flags (look at the docs, will you ?) */
		SLAB_HWCACHE_ALIGN | SLAB_DEBUG_OBJECTS,
		/* ctor/dtor to be called when each element is allocated
		or deallocated */
		NULL
	);
	if (IS_ERR(cache_p))
		return PTR_ERR(cache_p);
	p = kmem_cache_alloc(cache_p, GFP_KERNEL);
	if (IS_ERR(p)) {
		/* there is not too much that we can do here */
		PR_ERROR("Cannot allocate memory");
		kmem_cache_destroy(cache_p);
		return PTR_ERR(p);
	}
	/* mempool_create(number,mempool_alloc_slab, mempool_free_slab,
			drbd_request_cache); */
	PR_INFO("end");
	return 0;
}
Exemple #16
0
static uint64_t mtnia(uint64_t reg)
{
	if (reg > 31)
		PR_ERROR("Invalid register specified for mtnia\n");

	return MTNIA_OPCODE | (reg << 21);
}
Exemple #17
0
uint64_t mtspr(uint64_t spr, uint64_t reg)
{
	if (reg > 31)
		PR_ERROR("Invalid register specified for mtspr\n");

	return MTSPR_OPCODE | (reg << 21) | ((spr & 0x1f) << 16) | ((spr & 0x3e0) << 6);
}
Exemple #18
0
static int cfam_hmfsi_probe(struct pdbg_target *target)
{
	struct fsi *fsi = target_to_fsi(target);
	struct pdbg_target *fsi_parent = target->parent;
	uint32_t value, port;
	int rc;

	/* Enable the port in the upstream control register */
	port = dt_prop_get_u32(target, "port");
	fsi_read(fsi_parent, 0x3404, &value);
	value |= 1 << (31 - port);
	if ((rc = fsi_write(fsi_parent, 0x3404, value))) {
		PR_ERROR("Unable to enable HMFSI port %d\n", port);
		return rc;
	}

	if ((rc = fsi_read(&fsi->target, 0xc09, &value)))
		return rc;

	fsi->chip_type = get_chip_type(value);

	PR_DEBUG("Found chip type %x\n", fsi->chip_type);
	if (fsi->chip_type == CHIP_UNKNOWN)
		return -1;

	return 0;
}
Exemple #19
0
static uint64_t ld(uint64_t rt, uint64_t ds, uint64_t ra)
{
	if ((rt > 31) | (ra > 31) | (ds > 0x3fff))
		PR_ERROR("Invalid register specified\n");

	return LD_OPCODE | (rt << 21) | (ra << 16) | (ds << 2);
}
void _pr_vertexbuffer_data(pr_vertexbuffer* vertexBuffer, PRsizei numVertices, const PRvoid* coords, const PRvoid* texCoords, PRsizei vertexStride)
{
    if (vertexBuffer == NULL)
    {
        PR_ERROR(PR_ERROR_NULL_POINTER);
        return;
    }

    _vertexbuffer_resize(vertexBuffer, numVertices);

    // Get offset pointers
    const PRbyte* coordsByteAlign = (const PRbyte*)coords;
    const PRbyte* texCoordsByteAlign = (const PRbyte*)texCoords;

    // Fill vertex buffer
    pr_vertex* vert = vertexBuffer->vertices;

    while (numVertices-- > 0)
    {
        // Copy coordinates
        if (coordsByteAlign != NULL)
        {
            const PRfloat* coord = (const PRfloat*)coordsByteAlign;

            vert->coord.x = coord[0];
            vert->coord.y = coord[1];
            vert->coord.z = coord[2];
            vert->coord.w = 1.0f;//coord[3];

            coordsByteAlign += vertexStride;
        }
        else
        {
            vert->coord.x = 0.0f;
            vert->coord.y = 0.0f;
            vert->coord.z = 0.0f;
            vert->coord.w = 1.0f;
        }

        // Copy texture coordinates
        if (texCoordsByteAlign != NULL)
        {
            const PRfloat* texCoord = (const PRfloat*)texCoordsByteAlign;

            vert->texCoord.x = texCoord[0];
            vert->texCoord.y = texCoord[1];

            texCoordsByteAlign += vertexStride;
        }
        else
        {
            vert->texCoord.x = 0.0f;
            vert->texCoord.y = 0.0f;
        }

        // Next vertex
        ++vert;
    }
}
void _pr_immediate_mode_begin(PRenum primitives)
{
    if (_globalState.immModeActive)
    {
        PR_ERROR(PR_ERROR_INVALID_STATE);
        return;
    }
    if (primitives < PR_POINTS || primitives > PR_TRIANGLE_FAN)
    {
        PR_ERROR(PR_ERROR_INVALID_ARGUMENT);
        return;
    }

    // Store primitive type and reset vertex counter
    _globalState.immModeActive      = PR_TRUE;
    _globalState.immModePrimitives  = primitives;
    _globalState.immModeVertCounter = 0;
}
Exemple #22
0
static int __init mod_init(void)
{
	my_entry = proc_create(PROC_NAME, 0, NULL, &my_file_ops);
	if (IS_ERR(my_entry)) {
		PR_ERROR("error in create_proc_entry");
		return PTR_ERR(my_entry);
	}
	pr_info(KBUILD_MODNAME " loaded successfully\n");
	return 0;
}
MODRET cmd_prepare(cmd_rec *cmd) {
  if (cmd->argc != 1) {
    return PR_ERROR(cmd);
  }

  conn_pool = (pool *) cmd->argv[0];
  conn_cache = make_array((pool *) cmd->argv[0], DEF_CONN_POOL_SIZE,
    sizeof(conn_entry_t));

  return mod_create_data(cmd, NULL);
}
void _pr_vertexbuffer_data_from_file(pr_vertexbuffer* vertexBuffer, PRsizei* numVertices, FILE* file)
{
    if (vertexBuffer == NULL || numVertices == NULL || file == NULL)
    {
        PR_ERROR(PR_ERROR_NULL_POINTER);
        return;
    }

    // Read number of vertices
    PRushort vertCount = 0;
    fread(&vertCount, sizeof(PRushort), 1, file);
    *numVertices = (PRsizei)vertCount;

    _vertexbuffer_resize(vertexBuffer, *numVertices);

    // Read all vertices
    PRvertex data;
    pr_vertex* vert = vertexBuffer->vertices;

    for (PRushort i = 0; i < *numVertices; ++i)
    {
        if (feof(file))
        {
            PR_ERROR(PR_ERROR_UNEXPECTED_EOF);
            return;
        }

        // Read next vertex data
        fread(&data, sizeof(PRvertex), 1, file);

        vert->coord.x = data.x;
        vert->coord.y = data.y;
        vert->coord.z = data.z;
        vert->coord.w = 1.0f;

        vert->texCoord.x = data.u;
        vert->texCoord.y = data.v;

        ++vert;
    }
}
Exemple #25
0
/*
* This function is called when the module is loaded
*/
int __init init_module(void)
{
	struct proc_dir_entry *entry;
	entry = create_proc_entry(PROC_NAME, 0, NULL);
	if (IS_ERR(entry)) {
		PR_ERROR("error in create_proc_entry");
		return PTR_ERR(entry);
	}
	entry->proc_fops = &my_file_ops;
	pr_info(KBUILD_MODNAME " loaded successfully\n");
	return 0;
}
Exemple #26
0
/*
* This is the ioctl implementation.
*/
static long kern_unlocked_ioctl(struct file *filp, unsigned int cmd,
		unsigned long arg)
{
	/* the buffer which will be used for the transaction */
	buffer b;
	int err;

	PR_DEBUG("start");
	switch (cmd) {
	case IOCTL_DIV_DOOPS:
		/* get the data from the user */
		err = copy_from_user(&b, (void *)arg, sizeof(b));
		if (err) {
			PR_ERROR("problem with copy_from_user");
			return err;
		}
		PR_DEBUG("after copy");
		PR_INFO("b.u1 is %llu", b.u1);
		PR_INFO("b.u2 is %llu", b.u2);
		PR_INFO("b.d1 is %lld", b.d1);
		PR_INFO("b.d2 is %lld", b.d2);
		b.udiv = b.u1 / b.u2;
		b.umul = b.u1 * b.u2;
		b.uadd = b.u1 + b.u2;
		b.usub = b.u1 - b.u2;
		b.ddiv = b.d1 / b.d2;
		b.dmul = b.d1 * b.d2;
		b.dadd = b.d1 + b.d2;
		b.dsub = b.d1 - b.d2;
		/* copy the data back to the user */
		err = copy_to_user((void *)arg, &b, sizeof(b));
		if (err) {
			PR_ERROR("problem with copy_to_user");
			return err;
		}
		/* everything is ok */
		return 0;
	}
	return -EINVAL;
}
Exemple #27
0
static int set_and_check(struct bladerf *dev, bladerf_module m,
                         unsigned int rate)
{
    int status;
    unsigned int actual, readback;

    status = bladerf_set_sample_rate(dev, m, rate, &actual);
    if (status != 0) {
        PR_ERROR("Failed to set sample rate: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    status = bladerf_get_sample_rate(dev, m, &readback);
    if (status != 0) {
        PR_ERROR("Failed to read back sample rate: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    return 0;
}
void _pr_immediate_mode_end()
{
    if (!_globalState.immModeActive)
    {
        PR_ERROR(PR_ERROR_INVALID_STATE);
        return;
    }

    // Draw vertex buffer with current previously selected primitive
    _immediate_mode_flush();

    _globalState.immModeActive = PR_FALSE;
}
Exemple #29
0
static unsigned long map_to_user(struct file *filp, void *kptr,
	unsigned int size)
{
	/* the user space address to be returned */
	unsigned long uptr;
	/* the mmap struct to hold the semaphore of */
	struct mm_struct *mm;
	/* flags to pass to do_mmap_pgoff */
	unsigned long flags;
	/* old value in private field */
	void *oldval;

	/* print some debug info... */
	PR_DEBUG("size is (d) %d", size);

	mm = current->mm;
	/* must NOT add MAP_LOCKED to the flags (it causes a hang) */
	flags = MAP_POPULATE | MAP_SHARED;
	/* flags=MAP_POPULATE|MAP_PRIVATE; */
	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
	/*
	 * vm_mmap does not need the semaphore to be held
	 * down_write(&mm->mmap_sem);
	 */
	oldval = filp->private_data;
	filp->private_data = kptr;
	uptr = vm_mmap(
		filp, /* file pointer for which filp->mmap will be called */
		0, /* address - this is the address we recommend for user
			space - best not to ... */
		size, /* size */
		PROT_READ | PROT_WRITE, /* protection */
		flags, /* flags */
		0 /* pg offset */
	);
	filp->private_data = oldval;
	/*
	 * vm_mmap does not need the semaphore to be held
	 * up_write(&mm->mmap_sem);
	 */
	if (IS_ERR_VALUE(uptr))
		PR_ERROR("ERROR: problem calling do_mmap_pgoff");
	else
		PR_DEBUG("addr for user space is (lu) %lu / (p) %p", uptr,
			(void *)uptr);
	return uptr;
}
static int map_sys_call_table(void)
{
	unsigned long *syscalltab = get_sys_call_table();
	unsigned long syscalladr = (unsigned long)virt_to_phys(syscalltab);
	unsigned long offset = syscalladr & (PAGE_SIZE-1);
	unsigned long start = align_address(syscalladr);
	unsigned long len = PAGE_SIZE;
	/* const unsigned int num_pages=1; */
	sys_call_adr = ioremap(start, len);
	if (IS_ERR(sys_call_adr)) {
		PR_ERROR("unable to ioremap");
		return PTR_ERR(sys_call_adr);
	} else {
		sys_call_adr_precise = sys_call_adr+offset;
		PR_DEBUG("got precise %p", sys_call_adr_precise);
		return 0;
	}
}