Example #1
0
/*
 * This is main public interface: somehow allocate a ST-RAM block
 *
 *  - If we're before mem_init(), we have to make a static allocation. The
 *    region is taken in the kernel data area (if the kernel is in ST-RAM) or
 *    from the start of ST-RAM (if the kernel is in TT-RAM) and added to the
 *    rsvd_stram_* region. The ST-RAM is somewhere in the middle of kernel
 *    address space in the latter case.
 *
 *  - If mem_init() already has been called, try with __get_dma_pages().
 *    This has the disadvantage that it's very hard to get more than 1 page,
 *    and it is likely to fail :-(
 *
 */
void *atari_stram_alloc(long size, const char *owner)
{
	void *addr = NULL;
	BLOCK *block;
	int flags;

	DPRINTK("atari_stram_alloc(size=%08lx,owner=%s)\n", size, owner);

	if (!mem_init_done)
		return alloc_bootmem_low(size);
	else {
		/* After mem_init(): can only resort to __get_dma_pages() */
		addr = (void *)__get_dma_pages(GFP_KERNEL, get_order(size));
		flags = BLOCK_GFP;
		DPRINTK( "atari_stram_alloc: after mem_init, "
				 "get_pages=%p\n", addr );
	}

	if (addr) {
		if (!(block = add_region( addr, size ))) {
			/* out of memory for BLOCK structure :-( */
			DPRINTK( "atari_stram_alloc: out of mem for BLOCK -- "
					 "freeing again\n" );
			free_pages((unsigned long)addr, get_order(size));
			return( NULL );
		}
		block->owner = owner;
		block->flags |= flags;
	}
	return( addr );
}
Example #2
0
struct region *
create_gas_cloud(struct level *lev, xchar x, xchar y, int radius, int damage)
{
    struct region *cloud;
    int i, nrect;
    struct nhrect tmprect;

    cloud = create_region(NULL, 0);
    nrect = radius;
    tmprect.lx = x;
    tmprect.hx = x;
    tmprect.ly = y - (radius - 1);
    tmprect.hy = y + (radius - 1);
    for (i = 0; i < nrect; i++) {
        add_rect_to_reg(cloud, &tmprect);
        tmprect.lx--;
        tmprect.hx++;
        tmprect.ly++;
        tmprect.hy--;
    }
    cloud->ttl = rn1(3, 4);
    if (!in_mklev && !flags.mon_moving)
        set_heros_fault(cloud); /* assume player has created it */
    cloud->inside_f = INSIDE_GAS_CLOUD;
    cloud->expire_f = EXPIRE_GAS_CLOUD;
    cloud->arg = damage;
    cloud->visible = TRUE;
    cloud->effect_id = dbuf_effect(E_MISC, E_gascloud);
    add_region(lev, cloud);
    return cloud;
}
Example #3
0
void parse_region(FILE *fp, World *w)
{
    char texture_name[STRING_TOKEN_MAX_LENGTH];
    int texture_index;
    Region r;

    if (get_real_token(fp, &r.floor) != Token_real)
        parse_error("number expected");
    if (get_real_token(fp, &r.ceiling) != Token_real)
        parse_error("number expected");

    /* floor texture */
    if (get_string_token(fp, texture_name) != Token_string)
        parse_error("texture name expected");
    texture_index = get_texture_index(texture_name);
    if (texture_index < 0 || texture_index > TABLE_SIZE(w->textures))
        parse_error("non-existent texture");
    else
        r.floor_tex = WORLD_TEXTURE(w, texture_index);

    /* ceiling texture */
    if (get_string_token(fp, texture_name) != Token_string)
        parse_error("texture name expected");
    if (strcmp(texture_name, "sky") == 0)
        r.ceiling_tex = NULL;
    else {
        texture_index = get_texture_index(texture_name);
        if (texture_index < 0 || texture_index > TABLE_SIZE(w->textures))
            parse_error("non-existent texture");
        else
            r.ceiling_tex = WORLD_TEXTURE(w, texture_index);
    }

    add_region(w, &r);
}
Example #4
0
rc_t ref_walker_add_range( struct ref_walker * self, const char * name, const uint64_t start, const uint64_t end )
{
    rc_t rc = 0;
    if ( self == NULL )
        rc = RC( rcApp, rcNoTarg, rcConstructing, rcParam, rcNull );
    else
        rc = add_region( &self->regions, name, start, end );
    return rc;
}
Example #5
0
rc_t parse_and_add_region( BSTree * regions, const char * s )
{
    uint64_t start, end;
    char name[ 4096 ];
    parse_definition( s, name, sizeof name, &start, &end );
    if ( name[ 0 ] == 0 )
        return RC( rcApp, rcNoTarg, rcConstructing, rcMemory, rcExhausted );
    else
        return add_region( regions, name, start, end );
}
void setup() {
   set_name( "pumpkin" );
   set_information( "Pumpkin is a large orange ball shaped town.\n");
   add_region( "round",
               "Pumpkins which are round.",
               "/d/dist/start/entrance",
               "/std/nationality/accents/regional/round");

   add_region( "square",
               "Sto Lat is the second biggest city in the Morporkian kingdom, "
               "it sits on the river Ankh on the way to the Carrack "
               "Mountains.  It is a harder starting location than "
               "Ankh-Morpork but close enough that it is not that much of an "
               "issue.",
               "/d/dist/start/entrance",
               "/std/nationality/accents/regional/square");

   set_language("pumpkin");
   set_currency_area("Pumpkin");
   set_default_start_location("/d/am/buildings/drum/mendeddrum");
}
Example #7
0
void TDeviceFileInput::copy_contents(const TDeviceFileInput& new_device_input)
{
	int i;
	MaterialParam j;
	MaterialParamInput new_param_input;
	DopingInput new_doping;
	StructureInput new_structure;

	for (i=0;i<new_device_input.number_grid;i++) add_grid(*(new_device_input.grid_ptr+i));
	for (i=0;i<new_device_input.number_doping;i++) {
		new_doping.length=(new_device_input.doping_ptr+i)->length;
		new_doping.acceptor_function=(new_device_input.doping_ptr+i)->acceptor_function->create_copy();
		new_doping.donor_function=(new_device_input.doping_ptr+i)->donor_function->create_copy();
		new_doping.acceptor_degeneracy=(new_device_input.doping_ptr+i)->acceptor_degeneracy;
		new_doping.acceptor_level=(new_device_input.doping_ptr+i)->acceptor_level;
		new_doping.donor_degeneracy=(new_device_input.doping_ptr+i)->donor_degeneracy;
		new_doping.donor_level=(new_device_input.doping_ptr+i)->donor_level;
		add_doping(new_doping);
	}

	for (i=0;i<new_device_input.number_structure;i++) {
		new_structure.material_type=(new_device_input.structure_ptr+i)->material_type;
		new_structure.alloy_type=(new_device_input.structure_ptr+i)->alloy_type;
		new_structure.length=(new_device_input.structure_ptr+i)->length;
		new_structure.alloy_function=(new_device_input.structure_ptr+i)->alloy_function->create_copy();
		add_structure(new_structure);
	}

	for (i=0;i<new_device_input.number_region;i++) add_region(*(new_device_input.region_ptr+i));
	for (i=0;i<new_device_input.number_cavity;i++) add_cavity(*(new_device_input.cavity_ptr+i));
	for (i=0;i<new_device_input.number_mirror;i++) add_mirror(*(new_device_input.mirror_ptr+i));
	radius=new_device_input.radius;

	for (j=1;j<=MAT_MAX_NUMBER_PARAMETERS;j++) {
		for (i=0;i<new_device_input.number_material_param[j-1];i++) {
			new_param_input.length=(new_device_input.material_param_input[j-1]+i)->length;
			new_param_input.material_model=
				new TMaterialParamModel(*((new_device_input.material_param_input[j-1]+i)->material_model));
			add_material_param(j,new_param_input);
		}
	}

}
Example #8
0
static rc_t ref_walker_prepare_1_src( struct ref_walker * self, const char * name )
{
    VPath * path = NULL;
    const VPath * local_cache = NULL;
    const KFile * remote_file = NULL;
    rc_t rc = VFSManagerResolveSpec ( self->vfs_mgr, name, &path, &remote_file, &local_cache, true );
    if ( rc != 0 )
    {
        PLOGERR( klogErr, ( klogErr, rc, "cannot resolve '$(n)' via VFSManager", "n=%s", name ) );
    }
    else
    {
        char buffer[ 4096 ];
        size_t num_read;
        rc = VPathReadPath ( path, buffer, sizeof buffer, &num_read );
        if ( rc != 0 )
        {
            PLOGERR( klogErr, ( klogErr, rc, "cannot read path from vpath for '$(n)'", "n=%s", name ) );
        }
        else
        {
            if ( rc == 0 )
            {
                int path_type = ( VDBManagerPathType ( self->vmgr, "%s", buffer ) & ~ kptAlias );
                if ( path_type == kptDatabase )
                {
                    const ReferenceList * reflist;
                    uint32_t options = ( ereferencelist_usePrimaryIds | 
                                         ereferencelist_useSecondaryIds |
                                         ereferencelist_useEvidenceIds );
                    rc = ReferenceList_MakePath( &reflist, self->vmgr, name, options, 0, NULL, 0 );
                    if ( rc != 0 )
                    {
                        PLOGERR( klogErr, ( klogErr, rc, "cannot create ReferenceList for '$(n)'", "n=%s", name ) );
                    }
                    else
                    {
                        uint32_t count;
                        rc = ReferenceList_Count( reflist, &count );
                        if ( rc != 0 )
                        {
                            PLOGERR( klogErr, ( klogErr, rc, "ReferenceList_Count() for '$(n)' failed", "n=%s", name ) );
                        }
                        else
                        {
                            uint32_t idx;
                            for ( idx = 0; idx < count && rc == 0; ++idx )
                            {
                                const ReferenceObj * refobj;
                                rc = ReferenceList_Get( reflist, &refobj, idx );
                                if ( rc != 0 )
                                {
                                    LOGERR( klogInt, rc, "ReferenceList_Get() failed" );
                                }
                                else
                                {
                                    const char * seqid;
                                    rc = ReferenceObj_SeqId( refobj, &seqid );
                                    if ( rc == 0 )
                                    {
                                        INSDC_coord_len seqlen;
                                        rc = ReferenceObj_SeqLength( refobj, &seqlen );
                                        if ( rc == 0 )
                                        {
                                            rc = add_region( &self->regions, seqid, 0, seqlen - 1 );
                                        }
                                    }
                                    ReferenceObj_Release( refobj );
                                }
                            }
                        }
                        ReferenceList_Release( reflist );
                    }
                }
            }
        }
        KFileRelease( remote_file );
        VPathRelease ( local_cache );
        VPathRelease ( path );
    }
    return rc;
}
int main(void)
{
	const struct dt_property *names, *ranges;
	struct mem_region *r;
	unsigned int i, l, c;
	uint64_t *rangep;
	const char *name;
	void *buf;

	/* Use malloc for the heap, so valgrind can find issues. */
	skiboot_heap.start = (long)real_malloc(TEST_HEAP_SIZE);
	skiboot_heap.len = TEST_HEAP_SIZE;
	skiboot_os_reserve.len = skiboot_heap.start;

	dt_root = dt_new_root("");
	dt_add_property_cells(dt_root, "#address-cells", 2);
	dt_add_property_cells(dt_root, "#size-cells", 2);

	buf = real_malloc(1024*1024);
	add_mem_node((unsigned long)buf, 1024*1024);

	/* Now convert. */
	mem_region_init();

	/* create our reservations */
	for (i = 0; i < ARRAY_SIZE(test_regions); i++)
		mem_reserve(test_regions[i].name, test_regions[i].addr, 0x1000);

	/* release unused */
	mem_region_release_unused();

	/* and create reservations */
	mem_region_add_dt_reserved();

	/* ensure we can't create further reservations */
	r = new_region("test.4", 0x5000, 0x1000, NULL, REGION_RESERVED);
	assert(!add_region(r));

	/* check dt properties */
	names = dt_find_property(dt_root, "reserved-names");
	ranges = dt_find_property(dt_root, "reserved-ranges");

	assert(names && ranges);

	/* walk through names & ranges properies, ensuring that the test
	 * regions are all present */
	for (name = names->prop, rangep = (uint64_t *)ranges->prop, c = 0;
			name < names->prop + names->len;
			name += l, rangep += 2) {
		uint64_t addr;

		addr = dt_get_number(rangep, 2);
		l = strlen(name) + 1;

		for (i = 0; i < ARRAY_SIZE(test_regions); i++) {
			if (strcmp(test_regions[i].name, name))
				continue;
			assert(test_regions[i].addr == addr);
			assert(!test_regions[i].found);
			test_regions[i].found = true;
			c++;
		}
	}

	assert(c == ARRAY_SIZE(test_regions));

	dt_free(dt_root);
	real_free(buf);
	real_free((void *)(long)skiboot_heap.start);
	return 0;
}
Example #10
0
int main(int argc, char **argv)
{
    XEvent event;

    config_init();
    parse_cli_options(argc, argv);
    config_read();

    mixer_init(config.mixer_device, config.verbose, (const char **)config.exclude_channel);
    mixer_set_channel(0);

    display = XOpenDisplay(config.display_name);
    if (display == NULL) {
	const char *name;

	if (config.display_name) {
	    name = config.display_name;
	} else {
	    name = getenv("DISPLAY");
	    if (name == NULL) {
		fprintf(stderr, "wmix:error: Unable to open display, variable $DISPLAY not set\n");
		return EXIT_FAILURE;
	    }
	}
	fprintf(stderr, "wmix:error: Unable to open display \"%s\"\n", name);
	return EXIT_FAILURE;
    }
    display_width = (float)DisplayWidth(display, DefaultScreen(display)) / 4.0;
    display_height = (float)DisplayHeight(display, DefaultScreen(display)) / 2.0;

    dockapp_init(display);
    new_window("wmix", 64, 64);
    new_osd(DisplayWidth(display, DefaultScreen(display)) - 200, 60);

    if (config.mmkeys)
	    mmkey_install(display);

    config_release();

    blit_string("wmix " VERSION);
    scroll_text(3, 4, 57, true);
    ui_update();

    /* add click regions */
    add_region(1, 37, 36, 25, 25);	/* knob */
    add_region(2, 4, 42, 27, 15);	/* balancer */
    add_region(3, 2, 26, 7, 10);	/* previous channel */
    add_region(4, 10, 26, 7, 10);	/* next channel */
    add_region(5, 39, 14, 20, 7);	/* mute toggle */
    add_region(6, 4, 14, 13, 7);	/* rec toggle */
    add_region(10, 3, 4, 56, 7);	/* re-scroll current channel name */

    /* setup up/down signal handler */
    create_pid_file();
    signal(SIGUSR1, (void *) signal_catch);
    signal(SIGUSR2, (void *) signal_catch);

    while (true) {
	if (button_pressed || slider_pressed || (XPending(display) > 0)) {
	    XNextEvent(display, &event);
	    switch (event.type) {
		case KeyPress:
		    if (key_press_event(&event.xkey))
			idle_loop = 0;
		    break;
		case Expose:
		    redraw_window();
		    break;
		case ButtonPress:
		    button_press_event(&event.xbutton);
		    idle_loop = 0;
		    break;
		case ButtonRelease:
		    button_release_event(&event.xbutton);
		    idle_loop = 0;
		    break;
		case MotionNotify:
		    /* process cursor change, or drag events */
		    motion_event(&event.xmotion);
		    idle_loop = 0;
		    break;
		case LeaveNotify:
		    /* go back to standard cursor */
		    if ((!button_pressed) && (!slider_pressed))
			set_cursor(NORMAL_CURSOR);
		    break;
		case DestroyNotify:
		    XCloseDisplay(display);
		    return EXIT_SUCCESS;
		default:
		    break;
	    }
	} else {
	    usleep(100000);
	    scroll_text(3, 4, 57, false);
	    /* rescroll message after some delay */
	    if (idle_loop++ > 256) {
		scroll_text(3, 4, 57, true);
		idle_loop = 0;
	    }
	    /* get rid of OSD after a few seconds of idle */
	    if ((idle_loop > 15) && osd_mapped() && !button_pressed) {
		unmap_osd();
		idle_loop = 0;
	    }
	    if (mixer_is_changed())
		ui_update();
	}
    }
    return EXIT_SUCCESS;
}
Example #11
0
/*
 * This is main public interface: somehow allocate a ST-RAM block
 * There are three strategies:
 * 
 *  - If we're before mem_init(), we have to make a static allocation. The
 *    region is taken in the kernel data area (if the kernel is in ST-RAM) or
 *    from the start of ST-RAM (if the kernel is in TT-RAM) and added to the
 *    rsvd_stram_* region. The ST-RAM is somewhere in the middle of kernel
 *    address space in the latter case.
 * 
 *  - If mem_init() already has been called and ST-RAM swapping is enabled,
 *    try to get the memory from the (pseudo) swap-space, either free already
 *    or by moving some other pages out of the swap.
 *
 *  - If mem_init() already has been called, and ST-RAM swapping is not
 *    enabled, the only possibility is to try with __get_dma_pages(). This has
 *    the disadvantage that it's very hard to get more than 1 page, and it is
 *    likely to fail :-(
 * 
 */
void *atari_stram_alloc( long size, unsigned long *start_mem,
						 const char *owner )
{
	void *addr = NULL;
	BLOCK *block;
	int flags;

	DPRINTK( "atari_stram_alloc(size=%08lx,*start_mem=%08lx,owner=%s)\n",
			 size, start_mem ? *start_mem : 0xffffffff, owner );
	
	if (start_mem && mem_init_done) {
		printk( KERN_ERR "atari_stram_alloc called with start_mem!=NULL "
				"after mem_init() from %p\n", __builtin_return_address(0) );
		return( NULL );
	}
	if (!start_mem && !mem_init_done) {
		printk( KERN_ERR "atari_stram_alloc called with start_mem==NULL "
				"before mem_init() from %p\n", __builtin_return_address(0) );
		return( NULL );
	}

	size = ALIGN_IF_SWAP(size);
	DPRINTK( "atari_stram_alloc: rounded size = %08lx\n", size );
	if (!mem_init_done) {
		/* before mem_init(): allocate "statically", i.e. either in the kernel
		 * data space (current end in *start_mem), or at the end of currently
		 * reserved ST-RAM. */
		if (kernel_in_stram) {
			/* Get memory from kernel data space */
			*start_mem = ALIGN_IF_SWAP(*start_mem);
			addr = (void *)*start_mem;
			*start_mem += size;
			DPRINTK( "atari_stram_alloc: pre-mem_init and k/ST: "
					 "shifted start_mem to %08lx, addr=%p\n",
					 *start_mem, addr );
		}
		else {
			/* Get memory from rsvd_stram_beg */
			if (rsvd_stram_end + size < stram_end) {
				addr = (void *) rsvd_stram_end;
				rsvd_stram_end += size;
				DPRINTK( "atari_stram_alloc: pre-mem_init and k/TT: "
						 "shifted rsvd_stram_end to %08lx, addr=%p\n",
						 rsvd_stram_end, addr );
			}
		}
		flags = BLOCK_STATIC;
	}
#ifdef CONFIG_STRAM_SWAP
	else if (max_swap_size) {
		/* If swapping is active (can only be the case after mem_init()!):
		 * make some free space in the swap "device". */
		DPRINTK( "atari_stram_alloc: after mem_init, swapping ok, "
				 "calling get_region\n" );
		addr = get_stram_region( N_PAGES(size) );
		flags = BLOCK_INSWAP;
	}
#endif
	else {
		/* After mem_init() and no swapping: can only resort to
		 * __get_dma_pages() */
		addr = (void *)__get_dma_pages(GFP_KERNEL, get_gfp_order(size));
		flags = BLOCK_GFP;
		DPRINTK( "atari_stram_alloc: after mem_init, swapping off, "
				 "get_pages=%p\n", addr );
	}

	if (addr) {
		if (!(block = add_region( addr, size ))) {
			/* out of memory for BLOCK structure :-( */
			DPRINTK( "atari_stram_alloc: out of mem for BLOCK -- "
					 "freeing again\n" );
			if (flags == BLOCK_STATIC)
				rsvd_stram_end -= size;
#ifdef CONFIG_STRAM_SWAP
			else if (flags == BLOCK_INSWAP)
				free_stram_region( SWAP_NR(addr), N_PAGES(size) );
#endif
			else
				free_pages( (unsigned long)addr, get_gfp_order(size));
			return( NULL );
		}
		block->owner = owner;
		block->flags |= flags;
	}
	return( addr );
}
Example #12
0
static void region_mix_callback(GtkWidget *w, gpointer context)
{
  if ((current_region != -1) &&
      (selected_channel()))
    add_region(region_list_position_to_id(current_region), selected_channel());
}