static int mips_next_event(unsigned long delta,
				struct clock_event_device *evt)
{
	unsigned long flags;
	unsigned int mtflags;
	unsigned long timestamp, reference, previous;
	unsigned long nextcomp = 0L;
	int vpe = current_cpu_data.vpe_id;
	int cpu = smp_processor_id();
	local_irq_save(flags);
	mtflags = dmt();

	/*
	 * Maintain the per-TC virtual timer
	 * and program the per-VPE shared Count register
	 * as appropriate here...
	 */
	reference = (unsigned long)read_c0_count();
	timestamp = MAKEVALID(reference + delta);
	/*
	 * To really model the clock, we have to catch the case
	 * where the current next-in-VPE timestamp is the old
	 * timestamp for the calling CPE, but the new value is
	 * in fact later.  In that case, we have to do a full
	 * scan and discover the new next-in-VPE CPU id and
	 * timestamp.
	 */
	previous = smtc_nexttime[vpe][cpu];
	if (cpu == smtc_nextinvpe[vpe] && ISVALID(previous)
	    && IS_SOONER(previous, timestamp, reference)) {
		int i;
		int soonest = cpu;

		/*
		 * Update timestamp array here, so that new
		 * value gets considered along with those of
		 * other virtual CPUs on the VPE.
		 */
		smtc_nexttime[vpe][cpu] = timestamp;
		for_each_online_cpu(i) {
			if (ISVALID(smtc_nexttime[vpe][i])
			    && IS_SOONER(smtc_nexttime[vpe][i],
				smtc_nexttime[vpe][soonest], reference)) {
				    soonest = i;
			}
		}
		smtc_nextinvpe[vpe] = soonest;
		nextcomp = smtc_nexttime[vpe][soonest];
	/*
	 * Otherwise, we don't have to process the whole array rank,
	 * we just have to see if the event horizon has gotten closer.
	 */
	} else {
Example #2
0
static void env_init(void)
#endif	/* CFG_FLASH_ENV_ADDR */
{
#ifdef CONFIG_NVRAM_ENV
	if (crc32(0, (char *)environment, env_size) !=
	    *(ulong *)CFG_NVRAM_VAR_CRC_ADDR) {
		int i;
#if 0 /* still some problems with this printf - don't know why */
		printf ("*** Warning - Environment CRC mismatch, using defaults\n\n");
#endif
		for (i=0; i<env_size; i++)
			environment[i] = 0x00;
		memcpy (environment,
			default_environment,
			sizeof(default_environment));
		*(ulong *)CFG_NVRAM_VAR_CRC_ADDR =
			crc32(0, (char *)environment, env_size);
	}

#else	/* ! CONFIG_NVRAM_ENV */

#if defined(CFG_FLASH_ENV_ADDR)
	/*
	 * check if monitor has been relocated yet
	 */
	if (environment == rom_addr) {
		/*
		 * the monitor is still running from ROM. if the flash copy
		 * is valid, use that, otherwise use the default environment
		 *
		 * NOTE: can't printf here, because getenv() is called from
		 * serial_init() (and maybe before that) - hence the serial
		 * port is not ready - we can yell later that we are using
		 * the default environment... see below.
		 */
		if (ISVALID(flash_addr))
			return (flash_addr);
		else
			return (default_environment);
	}

	/*
	 * the monitor has been relocated - environment will now
	 * refer to the "in-memory" copy. If it isn't valid, copy it
	 * from the flash, or the default environment, if that isn't
	 * valid either.
	 */
	if (!ISVALID(environment)) {
		/*
		 * "in-memory" copy must be initialised
		 */
		if (!ISVALID(flash_addr)) {
			/* flash isn't valid either - use default */
			printf ("\n*** Warning - no Environment,"
				" using defaults\n\n");
			memcpy(environment, default_environment,
				sizeof (default_environment));
			MAKEVALID(environment, env_size);
		}
		else
			/* copy flash environment into RAM */
			memcpy(environment, flash_addr, env_size);
	}

	return (environment);

#else	/* !CFG_FLASH_ENV_ADDR */

	if (environment[0] == 0xFF) {
		printf ("*** Warning - no Environment, using defaults\n\n");
		memcpy (environment,
			default_environment,
			sizeof(default_environment));
	}

#endif	/* CFG_FLASH_ENV_ADDR */

#endif	/* CONFIG_NVRAM_ENV */
}
Example #3
0
void _do_setenv (bd_t *bd, int flag, int argc, char *argv[])
{
	int   i, len;
	int   console = -1;
	uchar *env, *nxt;
	uchar *oldval = NULL;
	uchar *name;

#if defined(CFG_FLASH_ENV_ADDR)
	uchar *environment = env_init();
	ulong real_env_size = env_size;
	ulong env_size = real_env_size - sizeof (ulong);
#else
	env_init();
#endif	/* CFG_FLASH_ENV_ADDR */

	name = argv[1];

	/*
	 * search if variable with this name already exists
	 */
	for (env=environment; *env; env=nxt+1) {
		for (nxt=env; *nxt; ++nxt)
			;
		if ((oldval=envmatch(name, env)) != NULL)
			break;
	}

	/*
	 * Delete any existing definition
	 */
	if (oldval) {
#ifndef CONFIG_ENV_OVERWRITE
		/*
		 * Ethernet Address and serial# can be set only once
		 */
		if ((strcmp (name, "ethaddr") == 0) ||
		    (strcmp (name, "serial#") == 0) ) {
			printf ("Can't overwrite \"%s\"\n", name);
			return;
		}
#endif

		/* Check for console redirection */
		if (strcmp(name,"stdin") == 0) {
			console = stdin;
		} else if (strcmp(name,"stdout") == 0) {
			console = stdout;
		} else if (strcmp(name,"stderr") == 0) {
			console = stderr;
		}

		if (console != -1) {
			if (argc < 3)		/* Cannot delete it! */
				return;

			/* Try assigning specified device */
			if (console_assign (console, argv[2]) < 0)
				return;
		}

		if (*++nxt == '\0') {
			*env = '\0';
		} else {
			for (;;) {
				*env = *nxt++;
				if ((*env == '\0') && (*nxt == '\0'))
					break;
				++env;
			}
		}
		*++env = '\0';
	}

#if defined(CFG_FLASH_ENV_ADDR)
	MAKEVALID(environment, real_env_size);
#endif	/* CFG_FLASH_ENV_ADDR */

	/* Delete only ? */
	if (argc < 3)
		return;

	/*
	 * Append new definition at the end
	 */
	for (env=environment; *env || *(env+1); ++env)
		;
	if (env > environment)
		++env;
	/*
	 * Overflow when:
	 * "name" + "=" + "val" +"\0\0"  > env_size - (env-environment)
	 */
	len = strlen(name) + 2;
	/* add '=' for first arg, ' ' for all others */
	for (i=2; i<argc; ++i) {
		len += strlen(argv[i]) + 1;
	}
	if (len > (&environment[env_size]-env)) {
		printf ("## Error: environment overflow, \"%s\" deleted\n", name);
		return;
	}
	while ((*env = *name++) != '\0')
		env++;
	for (i=2; i<argc; ++i) {
		char *val = argv[i];

		*env = (i==2) ? '=' : ' ';
		while ((*++env = *val++) != '\0')
			;
	}

	/* end is marked with double '\0' */
	*++env = '\0';

#ifdef CONFIG_NVRAM_ENV
	*(ulong *)CFG_NVRAM_VAR_CRC_ADDR = crc32(0, (char *)environment, env_size);
#endif
#if defined(CFG_FLASH_ENV_ADDR)
	MAKEVALID(environment, real_env_size);
#endif	/* CFG_FLASH_ENV_ADDR */

        /* Changes of the Ethernet or IP address should be reflected
         * in the board info structure.
	 */

	if (strcmp(argv[1],"ethaddr") == 0) {
		char *s = argv[2];	/* always use only one arg */
		char *e;
		for (i=0; i<6; ++i) {
			bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;
			if (s) s = (*e) ? e+1 : e;
		}
		return;
	}

	if (strcmp(argv[1],"ipaddr") == 0) {
		char *s = argv[2];	/* always use only one arg */
		char *e;
		bd->bi_ip_addr = 0;
		for (i=0; i<4; ++i) {
			ulong val = s ? simple_strtoul(s, &e, 10) : 0;
			bd->bi_ip_addr <<= 8;
			bd->bi_ip_addr  |= (val & 0xFF);
			if (s) s = (*e) ? e+1 : e;
		}
	}
}