Exemplo n.º 1
0
int nvram_del_env(partition_t part, char *envvar, int evlen)
{
	int last, current, pos, i;
	char *buffer;

	if(!part.addr)
		return -1;

	last=find_last_envvar(part);
	current = pos = get_past_env_pos(part, envvar, evlen);
	
	// TODO is this really required?
	/* go back to non-0 value */
	current--;

	while (nvram_read_byte(current))
		current--;

	// TODO is this required?
	current++;

	buffer=get_nvram_buffer(last-pos);

	for (i=0; i<last-pos; i++)
		buffer[i]=nvram_read_byte(i+pos);

	for (i=0; i<last-pos; i++)
		nvram_write_byte(i+current, buffer[i]);

	free_nvram_buffer(buffer);

	erase_nvram(last, current+last-pos);

	return 0;
}
Exemplo n.º 2
0
/**
 * @param partition name of the envvar partition
 * @param envvar name of the environment variable
 * @param evlen string length of the envvar parameter
 * @return pointer to temporary string containing the value of envvar
 */
char *nvram_get_env(partition_t part, char *envvar, int evlen)
{
	static char temp[256+1];
	int len, offset;
	uint8_t data;

	DEBUG("nvram_get_env %p... ", envvar);
	if(!part.addr) {
		/* ERROR: No environment variable partition */
		DEBUG("invalid partition.\n");
		return NULL;
	}

	offset=part.addr;

	do {
		len=0;
		while((data=nvram_read_byte(offset++)) && len < 256) {
			temp[len++]=data;
		}
		temp[len]=0;

		if (!strncmp(envvar, temp, evlen)) {
			int pos=0;
			while (temp[pos]!='=' && pos < len) pos++;
			// DEBUG("value='%s'\n", temp+pos+1); 
			return temp+pos+1;
		}
	} while (len);

	DEBUG("not found\n");
	return NULL;
}
Exemplo n.º 3
0
void test (void *data)
{
	int i;
	unsigned char c;

	for (;;) {
		printf (&uart, "\n\nTesting NVRAM, total %d bytes.", E2END+1);
		puts (&uart, "\nWriting: ");
		for (i=0; i<=E2END; ++i) {
			nvram_write_byte (i, ~i);
			if ((i & 63) == 63)
				putchar (&uart, '.');
		}
		puts (&uart, "\nReading: ");
		for (i=0; i<=E2END; ++i) {
			c = nvram_read_byte (i);
			if (c != (unsigned char) ~i) {
				printf (&uart, "error on byte 0x%x: written 0x%x, read 0x%x\n",
					i, (unsigned char) ~i, c);
				continue;
			}
			if ((i & 63) == 63)
				putchar (&uart, '.');
		}
		puts (&uart, "\nPress <Enter> to continue: ");
		getchar (&uart);
	}
}
Exemplo n.º 4
0
static int find_last_envvar(partition_t part)
{
	uint8_t last, current;
	int offset;

	offset=part.addr;

	last=nvram_read_byte(part.addr);

	for (offset=part.addr; offset<(int)(part.addr+part.len); offset++) {
		current=nvram_read_byte(offset);
		if(!last && !current)
			return offset;

		last=current;
	}

	return -1;
}
Exemplo n.º 5
0
static ssize_t read_nvram(struct file *file, char *buf,
			  size_t count, loff_t *ppos)
{
	unsigned int i;
	char *p = buf;

	if (verify_area(VERIFY_WRITE, buf, count))
		return -EFAULT;
	if (*ppos >= NVRAM_SIZE)
		return 0;
	for (i = *ppos; count > 0 && i < NVRAM_SIZE; ++i, ++p, --count)
		if (__put_user(nvram_read_byte(i), p))
			return -EFAULT;
	*ppos = i;
	return p - buf;
}
Exemplo n.º 6
0
static ssize_t read_nvram(struct file *file, char __user *buf,
			  size_t count, loff_t *ppos)
{
	unsigned int i;
	char __user *p = buf;

	if (!access_ok(VERIFY_WRITE, buf, count))
		return -EFAULT;
	if (*ppos >= nvram_len)
		return 0;
	for (i = *ppos; count > 0 && i < nvram_len; ++i, ++p, --count)
		if (__put_user(nvram_read_byte(i), p))
			return -EFAULT;
	*ppos = i;
	return p - buf;
}
Exemplo n.º 7
0
/* returns the offset of the first byte after the searched envvar */
static int get_past_env_pos(partition_t part, char *envvar, int evlen)
{
	int offset, len;
	static char temp[256];
	uint8_t data;

	offset=part.addr;

	memset(temp, 0, 256);

	do {
		len=0;
		while((data=nvram_read_byte(offset++)) && len < 256) {
			temp[len++]=data;
		}
		if (!strncmp(envvar, temp, evlen)) {
			return offset;
		}
	} while (len);

	return -1;
}
Exemplo n.º 8
0
int nvram_set_env(partition_t part, char *envvar, int evlen, char *value, int vallen)
{
	char *oldvalue, *buffer;
	int last, current, buffersize, i;

	DEBUG("nvram_set_env %lx[%lx]: %p=>%p\n", part.addr, part.len, envvar, value);

	if(!part.addr)
		return -1;

	/* Check whether the environment variable exists already */
	oldvalue = nvram_get_env(part, envvar, evlen);

	if (oldvalue == NULL)
		return nvram_add_env(part, envvar, evlen, value, vallen);


	/* The value did not change. So we succeeded! */
	if (strlen(oldvalue) == vallen && !strncmp(oldvalue, value, vallen))
		return 0;

	/* we need to overwrite environment variables, back them up first */

	// DEBUG("overwriting existing environment variable\n");

	/* allocate a buffer */
	last=find_last_envvar(part);
	current = get_past_env_pos(part, envvar, evlen);
	buffersize = last - current;
	buffer=get_nvram_buffer(buffersize);
	if(!buffer)
		return -1;

	for (i=0; i<buffersize; i++) {
		buffer[i] = nvram_read_byte(current+i);
	}

	/* walk back until the = */
	while (nvram_read_byte(current)!='=') {
		current--;
	}

	/* Start at envvar= */
	current++;

	/* Write the new value */
	for(i = 0; i < vallen; i++) {
		nvram_write_byte(current++, value[i]);
	}
	
	/* Write end of string marker */
	nvram_write_byte(current++, 0);

	/* Copy back the buffer */
	for (i=0; i<buffersize; i++) {
		nvram_write_byte(current++, buffer[i]);
	}

	free_nvram_buffer(buffer);

	/* If the new environment variable content is shorter than the old one,
	 * we need to erase the rest of the bytes 
	 */

	if (current<last) {
		for(i=current; i<last; i++) {
			nvram_write_byte(i, 0);
		}
	}

	return 0; /* success */
}
Exemplo n.º 9
0
int atari_scsi_detect (Scsi_Host_Template *host)
{
	static int called = 0;
	struct Scsi_Host *instance;

	if (!MACH_IS_ATARI ||
	    (!ATARIHW_PRESENT(ST_SCSI) && !ATARIHW_PRESENT(TT_SCSI)) ||
	    called)
		return( 0 );

	host->proc_name = "Atari";

	atari_scsi_reg_read  = IS_A_TT() ? atari_scsi_tt_reg_read :
					   atari_scsi_falcon_reg_read;
	atari_scsi_reg_write = IS_A_TT() ? atari_scsi_tt_reg_write :
					   atari_scsi_falcon_reg_write;

	/* setup variables */
	host->can_queue =
		(setup_can_queue > 0) ? setup_can_queue :
		IS_A_TT() ? ATARI_TT_CAN_QUEUE : ATARI_FALCON_CAN_QUEUE;
	host->cmd_per_lun =
		(setup_cmd_per_lun > 0) ? setup_cmd_per_lun :
		IS_A_TT() ? ATARI_TT_CMD_PER_LUN : ATARI_FALCON_CMD_PER_LUN;
	/* Force sg_tablesize to 0 on a Falcon! */
	host->sg_tablesize =
		!IS_A_TT() ? ATARI_FALCON_SG_TABLESIZE :
		(setup_sg_tablesize >= 0) ? setup_sg_tablesize : ATARI_TT_SG_TABLESIZE;

	if (setup_hostid >= 0)
		host->this_id = setup_hostid;
	else {
		/* use 7 as default */
		host->this_id = 7;
		/* Test if a host id is set in the NVRam */
		if (ATARIHW_PRESENT(TT_CLK) && nvram_check_checksum()) {
			unsigned char b = nvram_read_byte( 14 );
			/* Arbitration enabled? (for TOS) If yes, use configured host ID */
			if (b & 0x80)
				host->this_id = b & 7;
		}
	}

#ifdef SUPPORT_TAGS
	if (setup_use_tagged_queuing < 0)
		setup_use_tagged_queuing = DEFAULT_USE_TAGGED_QUEUING;
#endif
#ifdef REAL_DMA
	/* If running on a Falcon and if there's TT-Ram (i.e., more than one
	 * memory block, since there's always ST-Ram in a Falcon), then allocate a
	 * STRAM_BUFFER_SIZE byte dribble buffer for transfers from/to alternative
	 * Ram.
	 */
	if (MACH_IS_ATARI && ATARIHW_PRESENT(ST_SCSI) &&
	    !ATARIHW_PRESENT(EXTD_DMA) && m68k_num_memory > 1) {
		atari_dma_buffer = atari_stram_alloc(STRAM_BUFFER_SIZE, "SCSI");
		if (!atari_dma_buffer) {
			printk( KERN_ERR "atari_scsi_detect: can't allocate ST-RAM "
					"double buffer\n" );
			return( 0 );
		}
		atari_dma_phys_buffer = virt_to_phys( atari_dma_buffer );
		atari_dma_orig_addr = 0;
	}
#endif
	instance = scsi_register (host, sizeof (struct NCR5380_hostdata));
	if(instance == NULL)
	{
		atari_stram_free(atari_dma_buffer);
		atari_dma_buffer = 0;
		return 0;
	}
	atari_scsi_host = instance;
       /* Set irq to 0, to avoid that the mid-level code disables our interrupt
        * during queue_command calls. This is completely unnecessary, and even
        * worse causes bad problems on the Falcon, where the int is shared with
        * IDE and floppy! */
       instance->irq = 0;

#ifdef CONFIG_ATARI_SCSI_RESET_BOOT
	atari_scsi_reset_boot();
#endif
	NCR5380_init (instance, 0);

	if (IS_A_TT()) {

		/* This int is actually "pseudo-slow", i.e. it acts like a slow
		 * interrupt after having cleared the pending flag for the DMA
		 * interrupt. */
		if (request_irq(IRQ_TT_MFP_SCSI, scsi_tt_intr, IRQ_TYPE_SLOW,
				 "SCSI NCR5380", scsi_tt_intr)) {
			printk(KERN_ERR "atari_scsi_detect: cannot allocate irq %d, aborting",IRQ_TT_MFP_SCSI);
			scsi_unregister(atari_scsi_host);
			atari_stram_free(atari_dma_buffer);
			atari_dma_buffer = 0;
			return 0;
		}
		tt_mfp.active_edge |= 0x80;		/* SCSI int on L->H */
#ifdef REAL_DMA
		tt_scsi_dma.dma_ctrl = 0;
		atari_dma_residual = 0;
#ifdef CONFIG_TT_DMA_EMUL
		if (MACH_IS_HADES) {
			if (request_irq(IRQ_AUTO_2, hades_dma_emulator,
					 IRQ_TYPE_PRIO, "Hades DMA emulator",
					 hades_dma_emulator)) {
				printk(KERN_ERR "atari_scsi_detect: cannot allocate irq %d, aborting (MACH_IS_HADES)",IRQ_AUTO_2);
				free_irq(IRQ_TT_MFP_SCSI, scsi_tt_intr);
				scsi_unregister(atari_scsi_host);
				atari_stram_free(atari_dma_buffer);
				atari_dma_buffer = 0;
				return 0;
			}
		}
#endif
		if (MACH_IS_MEDUSA || MACH_IS_HADES) {
			/* While the read overruns (described by Drew Eckhardt in
			 * NCR5380.c) never happened on TTs, they do in fact on the Medusa
			 * (This was the cause why SCSI didn't work right for so long
			 * there.) Since handling the overruns slows down a bit, I turned
			 * the #ifdef's into a runtime condition.
			 *
			 * In principle it should be sufficient to do max. 1 byte with
			 * PIO, but there is another problem on the Medusa with the DMA
			 * rest data register. So 'atari_read_overruns' is currently set
			 * to 4 to avoid having transfers that aren't a multiple of 4. If
			 * the rest data bug is fixed, this can be lowered to 1.
			 */
			atari_read_overruns = 4;
		}		
#endif /*REAL_DMA*/
	}
	else { /* ! IS_A_TT */
		
		/* Nothing to do for the interrupt: the ST-DMA is initialized
		 * already by atari_init_INTS()
		 */

#ifdef REAL_DMA
		atari_dma_residual = 0;
		atari_dma_active = 0;
		atari_dma_stram_mask = (ATARIHW_PRESENT(EXTD_DMA) ? 0x00000000
					: 0xff000000);
#endif
	}

	printk(KERN_INFO "scsi%d: options CAN_QUEUE=%d CMD_PER_LUN=%d SCAT-GAT=%d "
#ifdef SUPPORT_TAGS
			"TAGGED-QUEUING=%s "
#endif
			"HOSTID=%d",
			instance->host_no, instance->hostt->can_queue,
			instance->hostt->cmd_per_lun,
			instance->hostt->sg_tablesize,
#ifdef SUPPORT_TAGS
			setup_use_tagged_queuing ? "yes" : "no",
#endif
			instance->hostt->this_id );
	NCR5380_print_options (instance);
	printk ("\n");

	called = 1;
	return( 1 );
}