Exemple #1
0
static void
parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
		       struct bdb_header *bdb)
{
	struct sdvo_device_mapping *p_mapping;
	struct bdb_general_definitions *p_defs;
	struct child_device_config *p_child;
	int i, child_device_num, count;
	u16	block_size;

	p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
	if (!p_defs) {
		DRM_DEBUG("No general definition block is found\n");
		return;
	}
	
	if (p_defs->child_dev_size != sizeof(*p_child)) {
		
		DRM_DEBUG("different child size is found. Invalid.\n");
		return;
	}
	
	block_size = get_blocksize(p_defs);
	
	child_device_num = (block_size - sizeof(*p_defs)) /
				sizeof(*p_child);
	count = 0;
	for (i = 0; i < child_device_num; i++) {
		p_child = &(p_defs->devices[i]);
		if (!p_child->device_type) {
			
			continue;
		}
		if (p_child->slave_addr != SLAVE_ADDR1 &&
			p_child->slave_addr != SLAVE_ADDR2) {
			
			continue;
		}
		if (p_child->dvo_port != DEVICE_PORT_DVOB &&
			p_child->dvo_port != DEVICE_PORT_DVOC) {
			
			DRM_DEBUG("Incorrect SDVO port. Skip it \n");
			continue;
		}
		DRM_DEBUG("the SDVO device with slave addr %2x is found on "
				"%s port\n",
				p_child->slave_addr,
				(p_child->dvo_port == DEVICE_PORT_DVOB) ?
					"SDVOB" : "SDVOC");
		p_mapping = &(dev_priv->sdvo_mappings[p_child->dvo_port - 1]);
		if (!p_mapping->initialized) {
			p_mapping->dvo_port = p_child->dvo_port;
			p_mapping->slave_addr = p_child->slave_addr;
			p_mapping->dvo_wiring = p_child->dvo_wiring;
			p_mapping->initialized = 1;
		} else {
			DRM_DEBUG("Maybe one SDVO port is shared by "
					 "two SDVO device.\n");
		}
		if (p_child->slave2_addr) {
			
			
			DRM_DEBUG("there exists the slave2_addr. Maybe this "
				"is a SDVO device with multiple inputs.\n");
		}
		count++;
	}

	if (!count) {
		
		DRM_DEBUG("No SDVO device info is found in VBT\n");
	}
	return;
}
Exemple #2
0
int ini_has_section(struct ini_file *ini, const char *sec) {
	return find_section(ini->sections, sec) != NULL;
}
Exemple #3
0
static void use_section(TCCState *s1, const char *name)
{
    Section *sec;
    sec = find_section(s1, name);
    use_section1(s1, sec);
}
EXPORT int CALL ConfigHasUnsavedChanges(const char *SectionName)
{
    config_section *input_section, *curr_section;
    config_var *active_var, *saved_var;

    /* check input conditions */
    if (!l_ConfigInit)
    {
        DebugMessage(M64MSG_ERROR, "ConfigHasUnsavedChanges(): Core config not initialized!");
        return 0;
    }

    /* if SectionName is NULL or blank, then check all sections */
    if (SectionName == NULL || strlen(SectionName) < 1)
    {
        int iNumActiveSections = 0, iNumSavedSections = 0;
        /* first, search through all sections in Active list.  Recursively call ourself and return 1 if changed */
        curr_section = l_ConfigListActive;
        while (curr_section != NULL)
        {
            if (ConfigHasUnsavedChanges(curr_section->name))
                return 1;
            curr_section = curr_section->next;
            iNumActiveSections++;
        }
        /* Next, count the number of Saved sections and see if the count matches */
        curr_section = l_ConfigListSaved;
        while (curr_section != NULL)
        {
            curr_section = curr_section->next;
            iNumSavedSections++;
        }
        if (iNumActiveSections == iNumSavedSections)
            return 0;  /* no changes */
        else
            return 1;
    }

    /* walk through the Active section list, looking for a case-insensitive name match with input string */
    input_section = find_section(l_ConfigListActive, SectionName);
    if (input_section == NULL)
    {
        DebugMessage(M64MSG_ERROR, "ConfigHasUnsavedChanges(): section name '%s' not found!", SectionName);
        return 0;
    }

    /* walk through the Saved section list, looking for a case-insensitive name match */
    curr_section = find_section(l_ConfigListSaved, SectionName);
    if (curr_section == NULL)
    {
        /* if this section isn't present in saved list, then it has been newly created */
        return 1;
    }

    /* compare all of the variables in the two sections. They are expected to be in the same order */
    active_var = input_section->first_var;
    saved_var = curr_section->first_var;
    while (active_var != NULL && saved_var != NULL)
    {
        if (strcmp(active_var->name, saved_var->name) != 0)
            return 1;
        if (active_var->type != saved_var->type)
            return 1;
        switch(active_var->type)
        {
            case M64TYPE_INT:
                if (active_var->val.integer != saved_var->val.integer)
                    return 1;
                break;
            case M64TYPE_FLOAT:
                if (active_var->val.number != saved_var->val.number)
                    return 1;
                break;
            case M64TYPE_BOOL:
                if ((active_var->val.integer != 0) != (saved_var->val.integer != 0))
                    return 1;
                break;
            case M64TYPE_STRING:
                if (active_var->val.string == NULL)
                {
                    DebugMessage(M64MSG_ERROR, "ConfigHasUnsavedChanges(): Variable '%s' NULL Active string pointer!", active_var->name);
                    return 1;
                }
                if (saved_var->val.string == NULL)
                {
                    DebugMessage(M64MSG_ERROR, "ConfigHasUnsavedChanges(): Variable '%s' NULL Saved string pointer!", active_var->name);
                    return 1;
                }
                if (strcmp(active_var->val.string, saved_var->val.string) != 0)
                    return 1;
                break;
            default:
                DebugMessage(M64MSG_ERROR, "ConfigHasUnsavedChanges(): Invalid variable '%s' type %i!", active_var->name, active_var->type);
                return 1;
        }
        if (active_var->comment != NULL && saved_var->comment != NULL && strcmp(active_var->comment, saved_var->comment) != 0)
            return 1;
        active_var = active_var->next;
        saved_var = saved_var->next;
    }

    /* any extra new variables on the end, or deleted variables? */
    if (active_var != NULL || saved_var != NULL)
        return 1;

    /* exactly the same */
    return 0;
}
Exemple #5
0
ini_t *ini_load(const char *path)
{
    FILE *fp = fopen(path, "r");
    if (fp == NULL)
        return NULL;

    struct ini_section *head = NULL;
    struct ini_section *prev = NULL;
    struct ini_section *curr = NULL;

    struct ini_arg *arg_curr = NULL;
    struct ini_arg *arg_prev = NULL;

    char *line  = NULL;
    size_t   n  = 0;
    ssize_t len = 0;

    while ((len = _getline(&line, &n, fp)) != -1)
    {
        char *s = line;
        if (is_comment(&s))
            continue;
        len = strlen(s);

        if (len >= 3 && s[0] == '[' && s[len - 1] == ']')
        {
            char *name = s + 1;
            while (isspace(*name))
                ++name;

            char *name_end = s + len - 1;
            *name_end-- = '\0';
            while (isspace(*name_end))
                *name_end-- = '\0';

            if ((curr = find_section(head, name)) == NULL)
            {
                if ((curr = create_section(head, name)) == NULL)
                {
                    free(line);

                    return NULL;
                }

                if (head == NULL)
                    head = curr;
                if (prev != NULL)
                    prev->next = curr;

                prev = curr;
                arg_prev = NULL;
            }
            else
            {
                arg_prev = curr->args;
                while (arg_prev->next != NULL)
                    arg_prev = arg_prev->next;
            }

            continue;
        }

        char *delimiter = strchr(s, '=');
        if (delimiter == NULL)
            continue;
        *delimiter = '\0';

        char *name = s;
        char *name_end = delimiter - 1;
        while (isspace(*name_end))
            *name_end-- = '\0';

        char *value = delimiter + 1;
        while (isspace(*value))
            value++;

        if (curr == NULL)
        {
            if ((curr = create_section(head, "global")) == NULL)
            {
                free(line);

                return NULL;
            }

            if (head == NULL)
                head = curr;
            prev = curr;
            arg_prev = NULL;
        }

        if ((arg_curr = find_arg(curr, name)) == NULL)
        {
            arg_curr = create_arg(head, name, value);
            if (arg_curr == NULL)
            {
                free(line);

                return NULL;
            }

            if (arg_prev)
                arg_prev->next = arg_curr;
            if (curr->args == NULL)
                curr->args = arg_curr;

            arg_prev = arg_curr;
        }
        else
        {
            char *old_value = arg_curr->value;

            if ((arg_curr->value = strdup(value)) == NULL)
            {
                ini_free(head);

                free(line);

                return NULL;
            }

            free(old_value);
        }
    }

    free(line);
    fclose(fp);

    if (head == NULL)
    {
        if ((head = calloc(1, sizeof(struct ini_section))) == NULL)
            return NULL;
    }

    ini_print(head);

    return head;
}
Exemple #6
0
static int inifile(char *section,char *item,char *value)
{
	char *s1,*s2;
	int ret = 0;
	int len;
	int remove_section = (substring(item,"/remove",1) == 0);
	section = trim(section);
	item = trim(item);
	if (remove_section && !*section)
		return 0;
	while (find_section(section))
	{
		if (remove_section)
		{
			filepos = pos;
			ret = read((unsigned long long)(unsigned int)"[*",2,GRUB_WRITE);
			continue;
		}
		while (len = (read_line(buff)))
		{
			if (*buff == '[')
			{
				filepos = pos;
				break;
			}
			s1 = check_eof(buff);
			if (s1)
			{
				s2 = skip_to(0x201,s1);
				if (!*item)
				{
					if (setenvi)
					{
						ret = envi_cmd(s1,s2,0);
					}
					else
						ret = printf("%s=%s\r\n",s1,s2);
				}
				else if (substring(item,s1,1) == 0)
				{
					if (value)
					{
						filepos = pos;
						if (substring(value,"/d",1) == 0)
							ret = read((unsigned long long)(unsigned int)";",1,GRUB_WRITE);
						else
						{
							ret = sprintf(buff,"%s=%s",item,value);
							if (ret > len)
								return 0;
							ret = read((unsigned long long)(unsigned int)buff,ret,GRUB_WRITE);
							if (ret < len)
								read((unsigned long long)(unsigned int)";",1,GRUB_WRITE);
						}
					}
					else if (setenvi)
					{
						ret = envi_cmd(s1,s2,0);
					}
					else
						return printf("%s",s2);
				}
			}
		}
		if (!*section)
			return ret;
	}
	return ret;
}
Exemple #7
0
/* Try to find integrated panel data */
static void
parse_lfp_panel_data(struct drm_i915_private *dev_priv,
			    struct bdb_header *bdb)
{
	struct bdb_lvds_options *lvds_options;
	struct bdb_lvds_lfp_data *lvds_lfp_data;
	struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
	struct bdb_lvds_lfp_data_entry *entry;
	struct lvds_dvo_timing *dvo_timing;
	struct drm_display_mode *panel_fixed_mode;
	int lfp_data_size, dvo_timing_offset;

	/* Defaults if we can't find VBT info */
	dev_priv->lvds_dither = 0;
	dev_priv->lvds_vbt = 0;

	lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
	if (!lvds_options)
		return;

	dev_priv->lvds_dither = lvds_options->pixel_dither;
	if (lvds_options->panel_type == 0xff)
		return;

	lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
	if (!lvds_lfp_data)
		return;

	lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
	if (!lvds_lfp_data_ptrs)
		return;

	dev_priv->lvds_vbt = 1;

	lfp_data_size = lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
		lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
	entry = (struct bdb_lvds_lfp_data_entry *)
		((uint8_t *)lvds_lfp_data->data + (lfp_data_size *
						   lvds_options->panel_type));
	dvo_timing_offset = lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
		lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;

	/*
	 * the size of fp_timing varies on the different platform.
	 * So calculate the DVO timing relative offset in LVDS data
	 * entry to get the DVO timing entry
	 */
	dvo_timing = (struct lvds_dvo_timing *)
			((unsigned char *)entry + dvo_timing_offset);

	panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);

	fill_detail_timing_data(panel_fixed_mode, dvo_timing);

	dev_priv->lfp_lvds_vbt_mode = panel_fixed_mode;

	DRM_DEBUG("Found panel mode in BIOS VBT tables:\n");
	drm_mode_debug_printmodeline(panel_fixed_mode);

	return;
}
Exemple #8
0
int main(int argc,char *argv[])
{
   int irw,isp,ispp[2],status[6],mnkv;
   int bs[4],Ns,nmx,nkv,nmr,ncy,ninv;
   double kappa,m0,dm,mu0,mu,res,mres;
   double sqne,sqnp[2];
   complex_dble lnw1[2],lnr,dr,drmx;
   solver_parms_t sp;
   mrw_masses_t ms;
   
   MPI_Init(&argc,&argv);
   MPI_Comm_rank(MPI_COMM_WORLD,&my_rank);
   
   if (my_rank==0)
   {
      flog=freopen("check2.log","w",stdout);
      fin=freopen("check2.in","r",stdin);
      
      printf("\n");
      printf("Direct check of mrw2\n");
      printf("----------------------\n\n");
      
      printf("%dx%dx%dx%d lattice, ",NPROC0*L0,NPROC1*L1,NPROC2*L2,NPROC3*L3);
      printf("%dx%dx%dx%d process grid, ",NPROC0,NPROC1,NPROC2,NPROC3);
      printf("%dx%dx%dx%d local lattice\n\n",L0,L1,L2,L3);
   }

   mnkv=0;
   
   mres=0.0;
   for (isp=0;isp<3;isp++)
   {
      read_solver_parms(isp);
      sp=solver_parms(isp);

      if (sp.res>mres)
         mres=sp.res;
      
      if (sp.nkv>mnkv)
         mnkv=sp.nkv;
   }

   read_bc_parms();
   
   if (my_rank==0)
   {
      find_section("SAP");
      read_line("bs","%d %d %d %d",bs,bs+1,bs+2,bs+3);
   }

   MPI_Bcast(bs,4,MPI_INT,0,MPI_COMM_WORLD);
   set_sap_parms(bs,0,1,1);

   if (my_rank==0)
   {
      find_section("Deflation subspace");
      read_line("bs","%d %d %d %d",bs,bs+1,bs+2,bs+3);
      read_line("Ns","%d",&Ns);
   }

   MPI_Bcast(bs,4,MPI_INT,0,MPI_COMM_WORLD);
   MPI_Bcast(&Ns,1,MPI_INT,0,MPI_COMM_WORLD);   
   set_dfl_parms(bs,Ns);

   if (my_rank==0)
   {
      find_section("Deflation subspace generation");
      read_line("kappa","%lf",&kappa);
      read_line("mu","%lf",&mu);
      read_line("ninv","%d",&ninv);
      read_line("nmr","%d",&nmr);
      read_line("ncy","%d",&ncy);
   }

   MPI_Bcast(&kappa,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
   MPI_Bcast(&mu,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
   MPI_Bcast(&ninv,1,MPI_INT,0,MPI_COMM_WORLD);
   MPI_Bcast(&nmr,1,MPI_INT,0,MPI_COMM_WORLD);
   MPI_Bcast(&ncy,1,MPI_INT,0,MPI_COMM_WORLD);
   set_dfl_gen_parms(kappa,mu,ninv,nmr,ncy);
   
   if (my_rank==0)
   {
      find_section("Deflation projection");
      read_line("nkv","%d",&nkv);
      read_line("nmx","%d",&nmx);
      read_line("res","%lf",&res);
      fclose(fin);
   }

   MPI_Bcast(&nkv,1,MPI_INT,0,MPI_COMM_WORLD);     
   MPI_Bcast(&nmx,1,MPI_INT,0,MPI_COMM_WORLD);  
   MPI_Bcast(&res,1,MPI_DOUBLE,0,MPI_COMM_WORLD);      
   set_dfl_pro_parms(nkv,nmx,res);

   set_lat_parms(6.0,1.0,0,NULL,1.234);

   print_solver_parms(status,status+1);
   print_sap_parms(0);
   print_dfl_parms(0);
   
   start_ranlux(0,1245);
   geometry();

   mnkv=2*mnkv+2;
   if (mnkv<(Ns+2))
      mnkv=Ns+2;
   if (mnkv<5)
      mnkv=5;
   
   alloc_ws(mnkv);
   alloc_wsd(7);
   alloc_wv(2*nkv+2);
   alloc_wvd(4);
   drmx.re=0.0;
   drmx.im=0.0;
    
   for (irw=0;irw<3;irw++)
   {
      dm=1.0e-2;
      
      for (isp=0;isp<3;isp++)
      {
         ispp[0]=isp;
         ispp[1]=isp;
         if (isp==0)
         {
            m0=1.0877;
            mu0=0.1;
         }
         else if (isp==1)
         {
            m0=0.0877;
            mu0=0.01;
         }
         else
         {
            m0=-0.0123;
            mu0=0.001;
         }
      
         random_ud();

         if (isp==2)
         {
            dfl_modes(status);
            error_root(status[0]<0,1,"main [check2.c]",
                        "dfl_modes failed");
         }      
         
         if (irw==0)
         {
            ms.m1=m0;
            ms.d1=dm;
            ms.mu1=mu0;
            ms.m2=m0;
            ms.d2=dm;
            ms.mu2=mu0;

            lnr=mrw2(ms,0,ispp,lnw1,sqnp,&sqne,status);            
            dr.re=fabs(lnw1[0].re-lnw1[1].re);
            dr.im=fabs(lnw1[0].im-lnw1[1].im);

            lnr=mrw2(ms,1,ispp,lnw1,sqnp,&sqne,status);            
            dr.re+=fabs(lnr.re-(2.0*mu0*dm+dm*dm)*sqnp[0]);
            dr.re+=fabs(lnw1[0].re-lnw1[1].re);
            dr.re+=fabs(sqnp[0]-sqnp[1]);
            dr.im+=fabs(lnr.im);
            dr.im+=fabs(lnw1[0].im-lnw1[1].im);
         }
         else if (irw==1)
         {
            ms.m1=m0;
            ms.d1=dm;
            ms.mu1=mu0;
            ms.m2=m0;
            ms.d2=-dm;
            ms.mu2=mu0;

            lnr=mrw2(ms,0,ispp,lnw1,sqnp,&sqne,status);            
            dr.re=fabs(lnw1[0].re+lnw1[1].re);
            dr.im=fabs(lnw1[0].im+lnw1[1].im);

            lnr=mrw2(ms,1,ispp,lnw1,sqnp,&sqne,status);            
            dr.re+=fabs(lnr.re+dm*dm*sqnp[0]);
            dr.re+=fabs(lnw1[0].re+lnw1[1].re);
            dr.re+=fabs(sqnp[0]-sqnp[1]);
            dr.im+=fabs(lnr.im-2.0*lnw1[0].im);
            dr.im+=fabs(lnw1[0].im+lnw1[1].im);
         }
         else
         {
            ms.m1=m0;
            ms.d1=dm;
            ms.mu1=mu0;
            ms.m2=m0+dm;
            ms.d2=-dm;
            ms.mu2=mu0;

            lnr=mrw2(ms,0,ispp,lnw1,sqnp,&sqne,status);            
            dr.re=fabs(lnr.re);
            dr.im=fabs(lnr.im);
         }
         
         if (dr.re>drmx.re)
            drmx.re=dr.re;
         if (dr.im>drmx.im)
            drmx.im=dr.im;

         if (my_rank==0)
         {
            if (irw==0)
               printf("mrw2(d2=d1): ");
            else if (irw==1)
               printf("mrw2(d2=-d1): ");
            else
               printf("mrw2(m2=m1+d1,d2=-d1): ");
            
            if ((isp==0)||(isp==1))
               printf("status = %d\n",status[0]);
            else if (isp==2)
               printf("status = (%d,%d,%d)\n",
                        status[0],status[1],status[2]);

            printf("diff = %.1e + i%.1e\n\n",dr.re,dr.im);
         }      
      
         error_chk();
      }
   }
   
   if (my_rank==0)
   {
      printf("\n");
      printf("max diff = %.1e + i%.1e\n",drmx.re,drmx.im);
      printf("(should be smaller than %.1e)\n\n",mres*sqrt((double)(VOLUME*NPROC*24)));
      fclose(flog);
   }
   
   MPI_Finalize();    
   exit(0);
}
Exemple #9
0
 Section::Section( const Deck& deck, const std::string& section )
     : DeckView( find_section( deck, section ) ),
       section_name( section )
 {}
Exemple #10
0
bool Config::get_localized(const char* section, const char* key, char* ret, unsigned int size) {
	char* lang = getenv("LANG");

	// fallback
	if (!lang)
		return get(section, key, ret, size);

	// do not use default locales
	if (lang[0] == 'C' || (strncmp(lang, "en_US", 5) == 0))
		return get(section, key, ret, size);

	ConfigSection* cs = find_section(section);
	if (!cs) {
		errcode = CONF_ERR_SECTION;
		return false;
	}

	char key_buf[128];

	/*
	 * Config class can accept Name[xxx] names as
	 * keys, so we use it here; first construct
	 * a key name, and try to find it
	 */
	snprintf(key_buf, sizeof(key_buf), "%s[%s]", key, lang);
	bool found = false;

	// first try to find it with full data
	ConfigEntry* ce = cs->find_entry(key_buf);
	if (ce)
		found = true;
	else {
		/*
		 * We will try in this order:
		 * 1. [email protected]
		 * 2. lc_CC@qualifier
		 * 3. lc_CC (language code with country code)
		 * 4. lc
		 */
		char delim[] = {'.', '@', '_'};
		char* p;
		char* code;
		for (int i = 0; i < 3; i++) {
			p = strchr(lang, delim[i]);
			if (p != NULL) {
				int sz = p - lang;
				code = new char[sz+1];
				strncpy(code, lang, sz);
				// damint strncpy does not add this
				code[sz] = '\0';

				snprintf(key_buf, sizeof(key_buf), "%s[%s]", key, code);
				delete [] code;

				ce = cs->find_entry(key_buf);
				if (ce) {
					found = true;
					break;
				}
			}
		}
	}

	if (found) {
		char* value = ce->value;
		strncpy(ret, value, size);
		ret[size-1] = '\0';
		return true;
	} else
		errcode = CONF_ERR_KEY;
	return false;
}
Exemple #11
0
bool Config::key_exist(const char* section, const char* key) {
	ConfigSection* cs = find_section(section);
	if(!cs)
		return false;
	return (cs->find_entry(key) != NULL);
}
Exemple #12
0
/* Flip through the executable and cache the info necessary for dumping.  */
void
get_section_info (file_data *p_infile)
{
  PIMAGE_DOS_HEADER dos_header;
  PIMAGE_NT_HEADERS nt_header;
  int overlap;

  dos_header = (PIMAGE_DOS_HEADER) p_infile->file_base;
  if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
    {
      printf ("Unknown EXE header in %s...bailing.\n", p_infile->name);
      exit (1);
    }
  nt_header = (PIMAGE_NT_HEADERS) (((DWORD_PTR) dos_header) +
				   dos_header->e_lfanew);
  if (nt_header == NULL)
    {
      printf ("Failed to find IMAGE_NT_HEADER in %s...bailing.\n",
	     p_infile->name);
      exit (1);
    }

  /* Check the NT header signature ...  */
  if (nt_header->Signature != IMAGE_NT_SIGNATURE)
    {
      printf ("Invalid IMAGE_NT_SIGNATURE 0x%x in %s...bailing.\n",
	      nt_header->Signature, p_infile->name);
      exit (1);
    }

  /* Locate the ".data" and ".bss" sections for Emacs.  (Note that the
     actual section names are probably different from these, and might
     actually be the same section.)

     We do this as follows: first we determine the virtual address
     ranges in this process for the data and bss variables that we wish
     to preserve.  Then we map these VAs to the section entries in the
     source image.  Finally, we determine the new size of the raw data
     area for the bss section, so we can make the new image the correct
     size.  */

  /* We arrange for the Emacs initialized data to be in a separate
     section if possible, because we cannot rely on my_begdata and
     my_edata marking out the full extent of the initialized data, at
     least on the Alpha where the linker freely reorders variables
     across libraries.  If we can arrange for this, all we need to do is
     find the start and size of the EMDATA section.  */
  data_section = find_section ("EMDATA", nt_header);
  if (data_section)
    {
      data_start = (char *) nt_header->OptionalHeader.ImageBase +
	data_section->VirtualAddress;
      data_size = data_section->Misc.VirtualSize;
    }
  else
    {
      /* Fallback on the old method if compiler doesn't support the
         data_set #pragma (or its equivalent).  */
      data_start = my_begdata;
      data_size = my_edata - my_begdata;
      data_section = rva_to_section (PTR_TO_RVA (my_begdata), nt_header);
      if (data_section != rva_to_section (PTR_TO_RVA (my_edata), nt_header))
	{
	  printf ("Initialized data is not in a single section...bailing\n");
	  exit (1);
	}
    }

  /* As noted in lastfile.c, the Alpha (but not the Intel) MSVC linker
     globally segregates all static and public bss data (ie. across all
     linked modules, not just per module), so we must take both static
     and public bss areas into account to determine the true extent of
     the bss area used by Emacs.

     To be strictly correct, we dump the static and public bss areas
     used by Emacs separately if non-overlapping (since otherwise we are
     dumping bss data belonging to system libraries, eg. the static bss
     system data on the Alpha).  */

  bss_start = my_begbss;
  bss_size = my_endbss - my_begbss;
  bss_section = rva_to_section (PTR_TO_RVA (my_begbss), nt_header);
  if (bss_section != rva_to_section (PTR_TO_RVA (my_endbss), nt_header))
    {
      printf ("Uninitialized data is not in a single section...bailing\n");
      exit (1);
    }
  /* Compute how much the .bss section's raw data will grow.  */
  extra_bss_size =
    ROUND_UP (RVA_TO_SECTION_OFFSET (PTR_TO_RVA (my_endbss), bss_section),
	      nt_header->OptionalHeader.FileAlignment)
    - bss_section->SizeOfRawData;

  bss_start_static = my_begbss_static;
  bss_size_static = my_endbss_static - my_begbss_static;
  bss_section_static = rva_to_section (PTR_TO_RVA (my_begbss_static), nt_header);
  if (bss_section_static != rva_to_section (PTR_TO_RVA (my_endbss_static), nt_header))
    {
      printf ("Uninitialized static data is not in a single section...bailing\n");
      exit (1);
    }
  /* Compute how much the static .bss section's raw data will grow.  */
  extra_bss_size_static =
    ROUND_UP (RVA_TO_SECTION_OFFSET (PTR_TO_RVA (my_endbss_static), bss_section_static),
	      nt_header->OptionalHeader.FileAlignment)
    - bss_section_static->SizeOfRawData;

  /* Combine the bss sections into one if they overlap.  */
#ifdef _ALPHA_
  overlap = 1;			/* force all bss data to be dumped */
#else
  overlap = 0;
#endif
  if (bss_start < bss_start_static)
    {
      if (bss_start_static < bss_start + bss_size)
	overlap = 1;
    }
  else
    {
      if (bss_start < bss_start_static + bss_size_static)
	overlap = 1;
    }
  if (overlap)
    {
      if (bss_section != bss_section_static)
	{
	  printf ("BSS data not in a single section...bailing\n");
	  exit (1);
	}
      bss_start = min (bss_start, bss_start_static);
      bss_size = max (my_endbss, my_endbss_static) - bss_start;
      bss_section_static = 0;
      extra_bss_size_static = 0;
    }

  heap_section = rva_to_section (PTR_TO_RVA (get_heap_start ()), nt_header);
}
Exemple #13
0
bool Config::load(const char* fname) {
	E_ASSERT(fname != NULL);

	clear();

	FILE *f = fopen(fname, "r");
	if (!f) {
		errcode = CONF_ERR_FILE;
		return false;
	}

	// set default return values
	errcode = CONF_SUCCESS;
	bool status = true;

	// we must have at least one section
	bool sect_found = false;

	// use fixed sizes for sections and keys
	char section[ESECT_MAX];
	char keybuf[EKEY_MAX];

	// line and value can grow
	int buflen = ELINE_SIZE_START;
	char* buf = new char[buflen];

	// use the same size as for line
	int valbuflen = buflen;
	char* valbuf = new char[valbuflen];

	char *bufp;
	ConfigSection* tsect = NULL;

	while(config_getline(&buf, &buflen, f) != -1) {
		++linenum;

		bufp = buf;
		EAT_SPACES(bufp);

		// comment or empty line
		if (*bufp == COMMENT || *bufp == '\0')
			continue;

		// we found an section
		if (*bufp == SECT_OPEN) {
			sect_found = true;
			bufp++;
			if (!scan_section(bufp, section, sizeof(section))) {
				errcode = CONF_ERR_BAD;
				status = false;
				break;
			} else {
				// first check if section exists, or create if not
				tsect = find_section(section);
				if (!tsect) {
					++sectnum;
					tsect = new ConfigSection(section);
					section_list.push_back(tsect);
				}
			}
		}
		// data part
		else {
			// file without sections
			if (!sect_found) {
				errcode = CONF_ERR_SECTION;
				status = false;
				break;
			}

			/*
			 * check if size of valbuf is less than buflen;
			 * in that case make it size as buflen (better would be to use 
			 * buflen - EKEY_MAX - '=' - <spaces>, but that would complicate thing,
			 * also more size does not hurts :P)
			 */
			if(valbuflen < buflen) {
				valbuflen = buflen;
				delete [] valbuf;
				valbuf = new char[valbuflen];
			}

			if (!scan_keyvalues(bufp, keybuf, valbuf, buflen, EKEY_MAX, valbuflen)) {
				errcode = CONF_ERR_BAD;
				status = false;
				break;
			}

			E_ASSERT(tsect != NULL && "Entry without a section ?!");
			tsect->add_entry(keybuf, valbuf);
		}
	}

	fclose(f);
	delete [] buf;
	delete [] valbuf;

	return status;
}
Exemple #14
0
bool Config::exist(const char* section) {
	return (find_section(section) != NULL);
}
Exemple #15
0
static void
parse_edp(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
{
	struct bdb_edp *edp;
	struct edp_power_seq *edp_pps;
	struct edp_link_params *edp_link_params;

	edp = find_section(bdb, BDB_EDP);
	if (!edp) {
		if (dev_priv->vbt.edp_support)
			DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
		return;
	}

	switch ((edp->color_depth >> (panel_type * 2)) & 3) {
	case EDP_18BPP:
		dev_priv->vbt.edp_bpp = 18;
		break;
	case EDP_24BPP:
		dev_priv->vbt.edp_bpp = 24;
		break;
	case EDP_30BPP:
		dev_priv->vbt.edp_bpp = 30;
		break;
	}

	/* Get the eDP sequencing and link info */
	edp_pps = &edp->power_seqs[panel_type];
	edp_link_params = &edp->link_params[panel_type];

	dev_priv->vbt.edp_pps = *edp_pps;

	dev_priv->vbt.edp_rate = edp_link_params->rate ? DP_LINK_BW_2_7 :
		DP_LINK_BW_1_62;
	switch (edp_link_params->lanes) {
	case 0:
		dev_priv->vbt.edp_lanes = 1;
		break;
	case 1:
		dev_priv->vbt.edp_lanes = 2;
		break;
	case 3:
	default:
		dev_priv->vbt.edp_lanes = 4;
		break;
	}
	switch (edp_link_params->preemphasis) {
	case 0:
		dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_0;
		break;
	case 1:
		dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_3_5;
		break;
	case 2:
		dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_6;
		break;
	case 3:
		dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_9_5;
		break;
	}
	switch (edp_link_params->vswing) {
	case 0:
		dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_400;
		break;
	case 1:
		dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_600;
		break;
	case 2:
		dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_800;
		break;
	case 3:
		dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_1200;
		break;
	}
}
Exemple #16
0
static void
parse_device_mapping(struct drm_i915_private *dev_priv,
		       struct bdb_header *bdb)
{
	struct bdb_general_definitions *p_defs;
	union child_device_config *p_child, *child_dev_ptr;
	int i, child_device_num, count;
	u16	block_size;

	p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
	if (!p_defs) {
		DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
		return;
	}
	/* judge whether the size of child device meets the requirements.
	 * If the child device size obtained from general definition block
	 * is different with sizeof(struct child_device_config), skip the
	 * parsing of sdvo device info
	 */
	if (p_defs->child_dev_size != sizeof(*p_child)) {
		/* different child dev size . Ignore it */
		DRM_DEBUG_KMS("different child size is found. Invalid.\n");
		return;
	}
	/* get the block size of general definitions */
	block_size = get_blocksize(p_defs);
	/* get the number of child device */
	child_device_num = (block_size - sizeof(*p_defs)) /
				sizeof(*p_child);
	count = 0;
	/* get the number of child device that is present */
	for (i = 0; i < child_device_num; i++) {
		p_child = &(p_defs->devices[i]);
		if (!p_child->common.device_type) {
			/* skip the device block if device type is invalid */
			continue;
		}
		count++;
	}
	if (!count) {
		DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
		return;
	}
	dev_priv->vbt.child_dev = kcalloc(count, sizeof(*p_child), GFP_KERNEL);
	if (!dev_priv->vbt.child_dev) {
		DRM_DEBUG_KMS("No memory space for child device\n");
		return;
	}

	dev_priv->vbt.child_dev_num = count;
	count = 0;
	for (i = 0; i < child_device_num; i++) {
		p_child = &(p_defs->devices[i]);
		if (!p_child->common.device_type) {
			/* skip the device block if device type is invalid */
			continue;
		}
		child_dev_ptr = dev_priv->vbt.child_dev + count;
		count++;
		memcpy((void *)child_dev_ptr, (void *)p_child,
					sizeof(*p_child));
	}
	return;
}
Exemple #17
0
/* Try to find integrated panel data */
static void
parse_lfp_panel_data(struct drm_i915_private *dev_priv,
			    struct bdb_header *bdb)
{
	const struct bdb_lvds_options *lvds_options;
	const struct bdb_lvds_lfp_data *lvds_lfp_data;
	const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
	const struct lvds_dvo_timing *panel_dvo_timing;
	const struct lvds_fp_timing *fp_timing;
	struct drm_display_mode *panel_fixed_mode;
	int i, downclock;

	lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
	if (!lvds_options)
		return;

	dev_priv->vbt.lvds_dither = lvds_options->pixel_dither;
	if (lvds_options->panel_type == 0xff)
		return;

	panel_type = lvds_options->panel_type;

	lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
	if (!lvds_lfp_data)
		return;

	lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
	if (!lvds_lfp_data_ptrs)
		return;

	dev_priv->vbt.lvds_vbt = 1;

	panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
					       lvds_lfp_data_ptrs,
					       lvds_options->panel_type);

	panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
	if (!panel_fixed_mode)
		return;

	fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);

	dev_priv->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;

	DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
	drm_mode_debug_printmodeline(panel_fixed_mode);

	/*
	 * Iterate over the LVDS panel timing info to find the lowest clock
	 * for the native resolution.
	 */
	downclock = panel_dvo_timing->clock;
	for (i = 0; i < 16; i++) {
		const struct lvds_dvo_timing *dvo_timing;

		dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
						 lvds_lfp_data_ptrs,
						 i);
		if (lvds_dvo_timing_equal_size(dvo_timing, panel_dvo_timing) &&
		    dvo_timing->clock < downclock)
			downclock = dvo_timing->clock;
	}

	if (downclock < panel_dvo_timing->clock && i915.lvds_downclock) {
		dev_priv->lvds_downclock_avail = 1;
		dev_priv->lvds_downclock = downclock * 10;
		DRM_DEBUG_KMS("LVDS downclock is found in VBT. "
			      "Normal Clock %dKHz, downclock %dKHz\n",
			      panel_fixed_mode->clock, 10*downclock);
	}

	fp_timing = get_lvds_fp_timing(bdb, lvds_lfp_data,
				       lvds_lfp_data_ptrs,
				       lvds_options->panel_type);
	if (fp_timing) {
		/* check the resolution, just to be sure */
		if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
		    fp_timing->y_res == panel_fixed_mode->vdisplay) {
			dev_priv->vbt.bios_lvds_val = fp_timing->lvds_reg_val;
			DRM_DEBUG_KMS("VBT initial LVDS value %x\n",
				      dev_priv->vbt.bios_lvds_val);
		}
	}
}
Exemple #18
0
static void
parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
			  struct bdb_header *bdb)
{
	struct sdvo_device_mapping *p_mapping;
	struct bdb_general_definitions *p_defs;
	union child_device_config *p_child;
	int i, child_device_num, count;
	u16	block_size;

	p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
	if (!p_defs) {
		DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n");
		return;
	}
	/* judge whether the size of child device meets the requirements.
	 * If the child device size obtained from general definition block
	 * is different with sizeof(struct child_device_config), skip the
	 * parsing of sdvo device info
	 */
	if (p_defs->child_dev_size != sizeof(*p_child)) {
		/* different child dev size . Ignore it */
		DRM_DEBUG_KMS("different child size is found. Invalid.\n");
		return;
	}
	/* get the block size of general definitions */
	block_size = get_blocksize(p_defs);
	/* get the number of child device */
	child_device_num = (block_size - sizeof(*p_defs)) /
				sizeof(*p_child);
	count = 0;
	for (i = 0; i < child_device_num; i++) {
		p_child = &(p_defs->devices[i]);
		if (!p_child->old.device_type) {
			/* skip the device block if device type is invalid */
			continue;
		}
		if (p_child->old.slave_addr != SLAVE_ADDR1 &&
			p_child->old.slave_addr != SLAVE_ADDR2) {
			/*
			 * If the slave address is neither 0x70 nor 0x72,
			 * it is not a SDVO device. Skip it.
			 */
			continue;
		}
		if (p_child->old.dvo_port != DEVICE_PORT_DVOB &&
			p_child->old.dvo_port != DEVICE_PORT_DVOC) {
			/* skip the incorrect SDVO port */
			DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n");
			continue;
		}
		DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
				" %s port\n",
				p_child->old.slave_addr,
				(p_child->old.dvo_port == DEVICE_PORT_DVOB) ?
					"SDVOB" : "SDVOC");
		p_mapping = &(dev_priv->sdvo_mappings[p_child->old.dvo_port - 1]);
		if (!p_mapping->initialized) {
			p_mapping->dvo_port = p_child->old.dvo_port;
			p_mapping->slave_addr = p_child->old.slave_addr;
			p_mapping->dvo_wiring = p_child->old.dvo_wiring;
			p_mapping->ddc_pin = p_child->old.ddc_pin;
			p_mapping->i2c_pin = p_child->old.i2c_pin;
			p_mapping->initialized = 1;
			DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
				      p_mapping->dvo_port,
				      p_mapping->slave_addr,
				      p_mapping->dvo_wiring,
				      p_mapping->ddc_pin,
				      p_mapping->i2c_pin);
		} else {
			DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
					 "two SDVO device.\n");
		}
		if (p_child->old.slave2_addr) {
			/* Maybe this is a SDVO device with multiple inputs */
			/* And the mapping info is not added */
			DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
				" is a SDVO device with multiple inputs.\n");
		}
		count++;
	}

	if (!count) {
		/* No SDVO device info is found */
		DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
	}
	return;
}
Exemple #19
0
/* Try to find integrated panel data */
static void
parse_lfp_panel_data(struct drm_i915_private *dev_priv,
			    struct bdb_header *bdb)
{
	const struct bdb_lvds_options *lvds_options;
	const struct bdb_lvds_lfp_data *lvds_lfp_data;
	const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
	const struct lvds_dvo_timing *panel_dvo_timing;
	struct drm_display_mode *panel_fixed_mode;
	int i, downclock;

	lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
	if (!lvds_options)
		return;

	dev_priv->lvds_dither = lvds_options->pixel_dither;
	if (lvds_options->panel_type == 0xff)
		return;

	panel_type = lvds_options->panel_type;

	lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
	if (!lvds_lfp_data)
		return;

	lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
	if (!lvds_lfp_data_ptrs)
		return;

	dev_priv->lvds_vbt = 1;

	panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
					       lvds_lfp_data_ptrs,
					       lvds_options->panel_type);

	panel_fixed_mode = allocz(sizeof(*panel_fixed_mode));
	if (!panel_fixed_mode)
		return;

	fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);

	dev_priv->lfp_lvds_vbt_mode = panel_fixed_mode;

	fprintf(stderr, "Found panel mode in BIOS VBT tables:\n");
	drm_mode_debug_printmodeline(panel_fixed_mode);

	/*
	 * Iterate over the LVDS panel timing info to find the lowest clock
	 * for the native resolution.
	 */
	downclock = panel_dvo_timing->clock;
	for (i = 0; i < 16; i++) {
		const struct lvds_dvo_timing *dvo_timing;

		dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
						 lvds_lfp_data_ptrs,
						 i);
		if (lvds_dvo_timing_equal_size(dvo_timing, panel_dvo_timing) &&
		    dvo_timing->clock < downclock)
			downclock = dvo_timing->clock;
	}

	if (downclock < panel_dvo_timing->clock && i915_lvds_downclock) {
		dev_priv->lvds_downclock_avail = 1;
		dev_priv->lvds_downclock = downclock * 10;
		fprintf(stderr, "LVDS downclock is found in VBT. "
			      "Normal Clock %dKHz, downclock %dKHz\n",
			      panel_fixed_mode->clock, 10*downclock);
	}
}
Exemple #20
0
static void
parse_edp(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
{
	struct bdb_edp *edp;
	struct edp_power_seq *edp_pps;
	struct edp_link_params *edp_link_params;

	edp = find_section(bdb, BDB_EDP);
	if (!edp) {
		if (SUPPORTS_EDP(dev_priv->dev) && dev_priv->edp.support) {
			fprintf(stderr, "No eDP BDB found but eDP panel "
				      "supported, assume %dbpp panel color "
				      "depth.\n",
				      dev_priv->edp.bpp);
		}
		return;
	}

	switch ((edp->color_depth >> (panel_type * 2)) & 3) {
	case EDP_18BPP:
		dev_priv->edp.bpp = 18;
		break;
	case EDP_24BPP:
		dev_priv->edp.bpp = 24;
		break;
	case EDP_30BPP:
		dev_priv->edp.bpp = 30;
		break;
	}

	/* Get the eDP sequencing and link info */
	edp_pps = &edp->power_seqs[panel_type];
	edp_link_params = &edp->link_params[panel_type];

	dev_priv->edp.pps = *edp_pps;

	dev_priv->edp.rate = edp_link_params->rate ? DP_LINK_BW_2_7 :
		DP_LINK_BW_1_62;
	switch (edp_link_params->lanes) {
	case 0:
		dev_priv->edp.lanes = 1;
		break;
	case 1:
		dev_priv->edp.lanes = 2;
		break;
	case 3:
	default:
		dev_priv->edp.lanes = 4;
		break;
	}
	switch (edp_link_params->preemphasis) {
	case 0:
		dev_priv->edp.preemphasis = DP_TRAIN_PRE_EMPHASIS_0;
		break;
	case 1:
		dev_priv->edp.preemphasis = DP_TRAIN_PRE_EMPHASIS_3_5;
		break;
	case 2:
		dev_priv->edp.preemphasis = DP_TRAIN_PRE_EMPHASIS_6;
		break;
	case 3:
		dev_priv->edp.preemphasis = DP_TRAIN_PRE_EMPHASIS_9_5;
		break;
	}
	switch (edp_link_params->vswing) {
	case 0:
		dev_priv->edp.vswing = DP_TRAIN_VOLTAGE_SWING_400;
		break;
	case 1:
		dev_priv->edp.vswing = DP_TRAIN_VOLTAGE_SWING_600;
		break;
	case 2:
		dev_priv->edp.vswing = DP_TRAIN_VOLTAGE_SWING_800;
		break;
	case 3:
		dev_priv->edp.vswing = DP_TRAIN_VOLTAGE_SWING_1200;
		break;
	}
}
Exemple #21
0
/* Try to find panel data */
static void
parse_panel_data(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
{
	struct bdb_lvds_options *lvds_options;
	struct bdb_lvds_lfp_data *lvds_lfp_data;
	struct bdb_lvds_lfp_data_entry *entry;
	struct lvds_dvo_timing *dvo_timing;
	struct drm_display_mode *panel_fixed_mode;

	/* Defaults if we can't find VBT info */
	dev_priv->lvds_dither = 0;
	dev_priv->lvds_vbt = 0;

	lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
	if (!lvds_options)
		return;

	dev_priv->lvds_dither = lvds_options->pixel_dither;
	if (lvds_options->panel_type == 0xff)
		return;

	lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
	if (!lvds_lfp_data)
		return;

	dev_priv->lvds_vbt = 1;

	entry = &lvds_lfp_data->data[lvds_options->panel_type];
	dvo_timing = &entry->dvo_timing;

	panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);

	panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
		dvo_timing->hactive_lo;
	panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
		((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
	panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
		dvo_timing->hsync_pulse_width;
	panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
		((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);

	panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
		dvo_timing->vactive_lo;
	panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
		dvo_timing->vsync_off;
	panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
		dvo_timing->vsync_pulse_width;
	panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
		((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
	panel_fixed_mode->clock = dvo_timing->clock * 10;
	panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;

	/* Some VBTs have bogus h/vtotal values */
	if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
		panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
	if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
		panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;

	drm_mode_set_name(panel_fixed_mode);

	dev_priv->vbt_mode = panel_fixed_mode;

	DRM_DEBUG("Found panel mode in BIOS VBT tables:\n");
	drm_mode_debug_printmodeline(panel_fixed_mode);

	return;
}
Exemple #22
0
bool Profile::cfg_write(const char *file, const char *section,
		 const char *option, const char *value) {
  off_t section_offset; 
  off_t option_offset;
  char val[MAX_VALUE_SIZE];
  char tmp[MAX_LINE_SIZE];
  FILE *fd, *tmp_fp;
  struct stat st;

  //  func("cfg_write(%s,%s,%s,%s)",file,section,option,value);

  if (stat(file, &st) == -1) {
    /* file is NEW */
    fd = fopen(file,"w");
    if(!fd) {
      error("cfg_write() : can't open %s",file);
      error("%s",strerror(errno));
      return(false); }
    fprintf(fd, "[%s]\n%s = %s\n", section,option,value);
    fflush(fd);
    fclose(fd);
    return(true);
  } else fd = fopen(file,"r+");
  if(!fd) {
    error("cfg_write : can't open %s (%s)",file, strerror(errno));
    return(false); }
  
  section_offset = find_section(fd, section);

  if(section_offset<0) { /* there is no section */
    func("cfg_write() : create new section [%s]",section);

    /* write at the end if section not found */
    fseek(fd, 0, SEEK_END);
    fprintf(fd, "\n[%s]\n%s = %s\n\n", section,option,value);
    //    fflush(fd);
    fclose(fd);
    return(true);
  }

  option_offset = find_option(fd, option, val, section_offset);

  if(option_offset>0) /* option found */
    if(!strncmp(val,value,MAX_VALUE_SIZE)) { /* value is the same */
      fclose(fd);
      return(true);
    }

  /* start a tmp file */
  tmp_fp = tmpfile();
  if (tmp_fp == NULL) {
    error("cfg_write(): can't create temp file (%s)",strerror(errno));
    fclose(fd);
    return(false);
  }

  if(option_offset>0) { /* option exists, change value */

    fseek(fd, option_offset, SEEK_SET);
    fgets(tmp, MAX_LINE_SIZE, fd);
    // func("substituting: %s\n",tmp);
    while(fgets(tmp, MAX_LINE_SIZE, fd))
      fputs(tmp, tmp_fp);
    ftruncate(fileno(fd), option_offset);
    fprintf(fd,"%s = %s\n", option, value);
    rewind(tmp_fp);
    while(fgets(tmp, MAX_LINE_SIZE, tmp_fp))
      fputs(tmp, fd);

  } else { /* option not found, add to section (on top) */

    fseek(fd, section_offset, SEEK_SET);
    fgets(tmp, MAX_LINE_SIZE, fd);
    option_offset = ftell(fd);
    while(fgets(tmp, MAX_LINE_SIZE, fd))
      fputs(tmp, tmp_fp);
    ftruncate(fileno(fd), option_offset);
    fseek(fd,0,SEEK_END);
    fprintf(fd,"%s = %s\n", option, value);
    rewind(tmp_fp);
    while(fgets(tmp, MAX_LINE_SIZE, tmp_fp))
      fputs(tmp, fd);

  }
  
  /* close tmp file (gets deleted automatically) */
  fclose(tmp_fp);
  
  fclose(fd);
  
  return(true);
}
Exemple #23
0
void init_jvm_args() {
  JavaVMOption *options;
  struct section *optsect;
  struct section *propsect;
  struct section *cpsect;
  int nopts;
  int n;
  struct property *prop;
  char *buf;
  char *p;
  int len;
  int first;

  cpsect = find_section(cfg, get_property(cfg, cfgname, "classpaths", "java.classpaths"));
  optsect = find_section(cfg, get_property(cfg, cfgname, "options", "java.options"));
  propsect = find_section(cfg, get_property(cfg, cfgname, "properties", "java.properties"));

  nopts = get_section_size(optsect) + get_section_size(propsect) + (cpsect ? 1 : 0);

  options = (JavaVMOption *) malloc(nopts * sizeof(JavaVMOption));
  memset(options, 0, nopts * sizeof(JavaVMOption));

  n = 0;

  if (cpsect) {
    len = strlen("-Djava.class.path=") + 1;
    prop = cpsect->properties;
    while (prop) {
      if (prop->name) len += strlen(prop->name) + 1;
      if (prop->value) len += strlen(prop->value) + 1;
      prop = prop->next;
    }

    buf = (char *) malloc(len);
    strcpy(buf, "-Djava.class.path=");
    p = buf + strlen(buf);
    first = 1;
    prop = cpsect->properties;
    while (prop) {
      if (!first) *p++ = ';';
      first = 0;

      if (prop->name) {
        len = strlen(prop->name);
        memcpy(p, prop->name, len + 1);
        p += len;
      }

      if (prop->value) {
        *p++ = ':';
        len = strlen(prop->value);
        memcpy(p, prop->value, len + 1);
        p += len;
      }

      prop = prop->next;
    }

    options[n++].optionString = buf;
  }

  if (optsect) {
    prop = optsect->properties;
    while (prop) {
      if (prop->value) {
        len = strlen(prop->name) + 1 + strlen(prop->value);
        buf = (char *) malloc(len + 1);
        strcpy(buf, prop->name);
        strcpy(buf + strlen(buf), ":");
        strcpy(buf + strlen(buf), prop->value);
      } else {
        len = strlen(prop->name);
        buf = (char *) malloc(len + 1);
        strcpy(buf, prop->name);
      }

      options[n++].optionString = buf;

      prop = prop->next;
    }
  }

  if (propsect) {
    prop = propsect->properties;
    while (prop) {
      if (prop->value) {
        len = 2 + strlen(prop->name) + 1 + strlen(prop->value);
      } else {
        len = 2 + strlen(prop->name);
      }

      buf = (char *) malloc(len + 1);
      strcpy(buf, "-D");
      strcpy(buf + strlen(buf), prop->name);

      if (prop->value) {
        strcpy(buf + strlen(buf), "=");
        strcpy(buf + strlen(buf), prop->value);
      }

      options[n++].optionString = buf;

      prop = prop->next;
    }
  }

  memset(&args, 0, sizeof(args));
  args.version  = JNI_VERSION_1_2;
  args.nOptions = nopts;
  args.options  = options;
  args.ignoreUnrecognized = JNI_FALSE;
}
/* Try to find integrated panel data */
static void
parse_lfp_panel_data(struct drm_i915_private *dev_priv,
			    struct bdb_header *bdb)
{
	struct bdb_lvds_options *lvds_options;
	struct bdb_lvds_lfp_data *lvds_lfp_data;
	struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
	struct bdb_lvds_lfp_data_entry *entry;
	struct lvds_dvo_timing *dvo_timing;
	struct drm_display_mode *panel_fixed_mode;
	int lfp_data_size, dvo_timing_offset;
	int i, temp_downclock;
	struct drm_display_mode *temp_mode;

	lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
	if (!lvds_options)
		return;

	dev_priv->lvds_dither = lvds_options->pixel_dither;
	if (lvds_options->panel_type == 0xff)
		return;

	panel_type = lvds_options->panel_type;

	lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
	if (!lvds_lfp_data)
		return;

	lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
	if (!lvds_lfp_data_ptrs)
		return;

	dev_priv->lvds_vbt = 1;

	lfp_data_size = lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
		lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
	entry = (struct bdb_lvds_lfp_data_entry *)
		((uint8_t *)lvds_lfp_data->data + (lfp_data_size *
						   lvds_options->panel_type));
	dvo_timing_offset = lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
		lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;

	/*
	 * the size of fp_timing varies on the different platform.
	 * So calculate the DVO timing relative offset in LVDS data
	 * entry to get the DVO timing entry
	 */
	dvo_timing = (struct lvds_dvo_timing *)
			((unsigned char *)entry + dvo_timing_offset);

	panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
	if (!panel_fixed_mode)
		return;

	fill_detail_timing_data(panel_fixed_mode, dvo_timing);

	dev_priv->lfp_lvds_vbt_mode = panel_fixed_mode;

	DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
	drm_mode_debug_printmodeline(panel_fixed_mode);

	temp_mode = kzalloc(sizeof(*temp_mode), GFP_KERNEL);
	temp_downclock = panel_fixed_mode->clock;
	/*
	 * enumerate the LVDS panel timing info entry in VBT to check whether
	 * the LVDS downclock is found.
	 */
	for (i = 0; i < 16; i++) {
		entry = (struct bdb_lvds_lfp_data_entry *)
			((uint8_t *)lvds_lfp_data->data + (lfp_data_size * i));
		dvo_timing = (struct lvds_dvo_timing *)
			((unsigned char *)entry + dvo_timing_offset);

		fill_detail_timing_data(temp_mode, dvo_timing);

		if (temp_mode->hdisplay == panel_fixed_mode->hdisplay &&
		temp_mode->hsync_start == panel_fixed_mode->hsync_start &&
		temp_mode->hsync_end == panel_fixed_mode->hsync_end &&
		temp_mode->htotal == panel_fixed_mode->htotal &&
		temp_mode->vdisplay == panel_fixed_mode->vdisplay &&
		temp_mode->vsync_start == panel_fixed_mode->vsync_start &&
		temp_mode->vsync_end == panel_fixed_mode->vsync_end &&
		temp_mode->vtotal == panel_fixed_mode->vtotal &&
		temp_mode->clock < temp_downclock) {
			/*
			 * downclock is already found. But we expect
			 * to find the lower downclock.
			 */
			temp_downclock = temp_mode->clock;
		}
		/* clear it to zero */
		memset(temp_mode, 0, sizeof(*temp_mode));
	}
	kfree(temp_mode);
	if (temp_downclock < panel_fixed_mode->clock &&
	    i915_lvds_downclock) {
		dev_priv->lvds_downclock_avail = 1;
		dev_priv->lvds_downclock = temp_downclock;
		DRM_DEBUG_KMS("LVDS downclock is found in VBT. "
			      "Normal Clock %dKHz, downclock %dKHz\n",
			      temp_downclock, panel_fixed_mode->clock);
	}
	return;
}
static void
copy_executable_and_add_section (file_data *p_infile,
				 file_data *p_outfile,
				 const char *new_section_name,
				 DWORD_PTR new_section_size)
{
  unsigned char *dst;
  PIMAGE_DOS_HEADER dos_header;
  PIMAGE_NT_HEADERS nt_header;
  PIMAGE_NT_HEADERS dst_nt_header;
  PIMAGE_SECTION_HEADER section;
  PIMAGE_SECTION_HEADER dst_section;
  DWORD_PTR offset;
  int i;
  int be_verbose = GetEnvironmentVariable ("DEBUG_DUMP", NULL, 0) > 0;

#define COPY_CHUNK(message, src, size, verbose)					\
  do {										\
    unsigned const char *s = (void *)(src);						\
    unsigned long count = (size);						\
    if (verbose)								\
      {										\
	printf ("%s\n", (message));						\
	printf ("\t0x%08x Offset in input file.\n", s - p_infile->file_base); 	\
	printf ("\t0x%08x Offset in output file.\n", dst - p_outfile->file_base); \
	printf ("\t0x%08x Size in bytes.\n", count);				\
      }										\
    memcpy (dst, s, count);							\
    dst += count;								\
  } while (0)

#define DST_TO_OFFSET()  PTR_TO_OFFSET (dst, p_outfile)
#define ROUND_UP_DST_AND_ZERO(align)						\
  do {										\
    unsigned char *newdst = p_outfile->file_base				\
      + ROUND_UP (DST_TO_OFFSET (), (align));					\
    /* Zero the alignment slop; it may actually initialize real data.  */	\
    memset (dst, 0, newdst - dst);						\
    dst = newdst;								\
  } while (0)

  /* Copy the source image sequentially, ie. section by section after
     copying the headers and section table, to simplify the process of
     adding an extra section table entry (which might force the raw
     section data to be relocated).

     Note that dst is updated implicitly by each COPY_CHUNK.  */

  dos_header = (PIMAGE_DOS_HEADER) p_infile->file_base;
  nt_header = (PIMAGE_NT_HEADERS) (((unsigned char *) dos_header) +
				   dos_header->e_lfanew);
  section = IMAGE_FIRST_SECTION (nt_header);

  dst = (unsigned char *) p_outfile->file_base;

  COPY_CHUNK ("Copying DOS header...", dos_header,
	      (DWORD_PTR) nt_header - (DWORD_PTR) dos_header, be_verbose);
  dst_nt_header = (PIMAGE_NT_HEADERS) dst;
  COPY_CHUNK ("Copying NT header...", nt_header,
	      (DWORD_PTR) section - (DWORD_PTR) nt_header, be_verbose);
  dst_section = (PIMAGE_SECTION_HEADER) dst;
  COPY_CHUNK ("Copying section table...", section,
	      nt_header->FileHeader.NumberOfSections * sizeof (*section),
	      be_verbose);

  /* To improve the efficiency of demand loading, make the file
     alignment match the section alignment (VC++ 6.0 does this by
     default anyway).  */
  dst_nt_header->OptionalHeader.FileAlignment =
    dst_nt_header->OptionalHeader.SectionAlignment;

  /* Add an uninitialized data section at the end, of the specified name
     and virtual size.  */
  if (find_section (new_section_name, nt_header) == NULL)
    /* Leave room for extra section table entry; filled in below.  */
    dst += sizeof (*section);
  else
    new_section_name = NULL;

  /* Align the first section's raw data area, and set the header size
     field accordingly.  */
  ROUND_UP_DST_AND_ZERO (dst_nt_header->OptionalHeader.FileAlignment);
  dst_nt_header->OptionalHeader.SizeOfHeaders = DST_TO_OFFSET ();

  for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
    {
      char msg[100];
      /* Windows section names are fixed 8-char strings, only
	 zero-terminated if the name is shorter than 8 characters.  */
      sprintf (msg, "Copying raw data for %.8s...", section->Name);

      /* Update the file-relative offset for this section's raw data (if
         it has any) in case things have been relocated; we will update
         the other offsets below once we know where everything is.  */
      if (dst_section->PointerToRawData)
	dst_section->PointerToRawData = DST_TO_OFFSET ();

      /* Can always copy the original raw data.  */
      COPY_CHUNK
	(msg, OFFSET_TO_PTR (section->PointerToRawData, p_infile),
	 section->SizeOfRawData, be_verbose);

      /* Round up the raw data size to the new alignment.  */
      dst_section->SizeOfRawData =
	ROUND_UP (dst_section->SizeOfRawData,
		  dst_nt_header->OptionalHeader.FileAlignment);

      /* Align the next section's raw data area.  */
      ROUND_UP_DST_AND_ZERO (dst_nt_header->OptionalHeader.FileAlignment);

      section++;
      dst_section++;
    }

  /* Add the extra section entry (which adds no raw data).  */
  if (new_section_name != NULL)
    {
      dst_nt_header->FileHeader.NumberOfSections++;
      dst_nt_header->OptionalHeader.SizeOfImage += new_section_size;
      strncpy (dst_section->Name, new_section_name, sizeof (dst_section->Name));
      dst_section->VirtualAddress =
	section[-1].VirtualAddress
	+ ROUND_UP (section[-1].Misc.VirtualSize,
		    dst_nt_header->OptionalHeader.SectionAlignment);
      dst_section->Misc.VirtualSize = new_section_size;
      dst_section->PointerToRawData = 0;
      dst_section->SizeOfRawData = 0;
      dst_section->Characteristics =
	IMAGE_SCN_CNT_UNINITIALIZED_DATA
	| IMAGE_SCN_MEM_READ
	| IMAGE_SCN_MEM_WRITE;
    }

  /* Copy remainder of source image.  */
  section--;
  offset = ROUND_UP (section->PointerToRawData + section->SizeOfRawData,
		     nt_header->OptionalHeader.FileAlignment);
  COPY_CHUNK
    ("Copying remainder of executable...",
     OFFSET_TO_PTR (offset, p_infile),
     p_infile->size - offset, be_verbose);

  /* Final size for new image.  */
  p_outfile->size = DST_TO_OFFSET ();

  /* Now patch up remaining file-relative offsets.  */
  section = IMAGE_FIRST_SECTION (nt_header);
  dst_section = IMAGE_FIRST_SECTION (dst_nt_header);

#define ADJUST_OFFSET(var)						\
  do {									\
    if ((var) != 0)							\
      (var) = relocate_offset ((var), nt_header, dst_nt_header);	\
  } while (0)

  dst_nt_header->OptionalHeader.SizeOfInitializedData = 0;
  dst_nt_header->OptionalHeader.SizeOfUninitializedData = 0;
  for (i = 0; i < dst_nt_header->FileHeader.NumberOfSections; i++)
    {
      /* Recompute data sizes for completeness.  */
      if (dst_section[i].Characteristics & IMAGE_SCN_CNT_INITIALIZED_DATA)
	dst_nt_header->OptionalHeader.SizeOfInitializedData +=
	  ROUND_UP (dst_section[i].Misc.VirtualSize, dst_nt_header->OptionalHeader.FileAlignment);
      else if (dst_section[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
	dst_nt_header->OptionalHeader.SizeOfUninitializedData +=
	  ROUND_UP (dst_section[i].Misc.VirtualSize, dst_nt_header->OptionalHeader.FileAlignment);

      ADJUST_OFFSET (dst_section[i].PointerToLinenumbers);
    }

  ADJUST_OFFSET (dst_nt_header->FileHeader.PointerToSymbolTable);

  /* Update offsets in debug directory entries. */
  {
    IMAGE_DATA_DIRECTORY debug_dir =
      dst_nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG];
    PIMAGE_DEBUG_DIRECTORY debug_entry;

    section = rva_to_section (debug_dir.VirtualAddress, dst_nt_header);
    if (section)
      {
	debug_entry = (PIMAGE_DEBUG_DIRECTORY)
	  (RVA_TO_OFFSET (debug_dir.VirtualAddress, section) + p_outfile->file_base);
	debug_dir.Size /= sizeof (IMAGE_DEBUG_DIRECTORY);

	for (i = 0; i < debug_dir.Size; i++, debug_entry++)
	  ADJUST_OFFSET (debug_entry->PointerToRawData);
      }
  }
}