summary refs log blame commit diff stats
path: root/plugins/sysinfo/pci.c
blob: bc8fb11ff9407a437f73003e5e90f9ea95edcc45 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                                                                 
                                                                            




























































































                                                                                                            



                                      
                          



                                       
                        

                                                                                                                                                                                              































                                                                            
/*
 * pci.c - PCI functions for X-Sys
 * Copyright (C) 1997-1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz> [PCI routines from lspci]
 * Copyright (C) 2000 Tom Rini <trini@kernel.crashing.org> [XorgAutoConfig pci.c, based on lspci]
 * Copyright (C) 2005, 2006 Tony Vroon
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <pci/pci.h>
#include "xsys.h"

static struct pci_filter filter;       /* Device filter */
static struct pci_access *pacc;
int bus, dev, func; /* Location of the card */

struct device {
  	struct device *next;
  	struct pci_dev *dev;
  	unsigned int config_cnt;
  	u8 config[256];
};

static struct device *first_dev;

static struct device *scan_device(struct pci_dev *p)
{
  	int how_much = 64;
  	struct device *d;

  	if (!pci_filter_match(&filter, p))
    		return NULL;
  	d = malloc(sizeof(struct device));
  	bzero(d, sizeof(*d));
  	d->dev = p;
  	if (!pci_read_block(p, 0, d->config, how_much))
    		exit(1);
  	if (how_much < 128 && (d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS) {
      		/* For cardbus bridges, we need to fetch 64 bytes more to get the full standard header... */
      		if (!pci_read_block(p, 64, d->config+64, 64))
        		exit(1);
      		how_much = 128;
    	}
  	d->config_cnt = how_much;
  	pci_setup_cache(p, d->config, d->config_cnt);
  	pci_fill_info(p, PCI_FILL_IDENT);
  	return d;
}

static void scan_devices(void)
{
  	struct device *d;
  	struct pci_dev *p;

  	pci_scan_bus(pacc);
  	for(p=pacc->devices; p; p=p->next)
    	if ((d = scan_device(p))) {
        	d->next = first_dev;
        	first_dev = d;
      	}
}

static u16 get_conf_word(struct device *d, unsigned int pos)
{
  	return d->config[pos] | (d->config[pos+1] << 8);
}

int pci_find_by_class(u16 *class, char *vendor, char *device)
{
	struct device *d;
	struct pci_dev *p;
	int nomatch = 1;

	pacc = pci_alloc();
	pci_filter_init(pacc, &filter);
	pci_init(pacc);
	scan_devices();

	for(d=first_dev; d; d=d->next) {
    		p = d->dev;
    		/* Acquire vendor & device ID if the class matches */
    		if(get_conf_word(d, PCI_CLASS_DEVICE) == *class) {
      			nomatch = 0;
			snprintf(vendor,7,"%04x",p->vendor_id);
			snprintf(device,7,"%04x",p->device_id);
      			break;
    		}
  	}

  	pci_cleanup(pacc);
  	return nomatch;
}

void pci_find_fullname(char *fullname, char *vendor, char *device)
{
	char buffer[bsize];
	char vendorname[bsize/2] = "";
	char devicename[bsize/2] = "";
	char *position;
	int cardfound = 0;

	sysinfo_get_pciids (buffer);
	FILE *fp = fopen (buffer, "r");

	if(fp == NULL) {
		snprintf(fullname, bsize, "%s:%s", vendor, device);
		sysinfo_print_error ("pci.ids file not found! You might want to adjust your pciids setting with /SYSINFO SET pciids (you can query its current value with /SYSINFO LIST).\n");
		return;
	}

	while(fgets(buffer, bsize, fp) != NULL)	{
		if (!isspace(buffer[0]) && strstr(buffer, vendor) != NULL) {
                       	position = strstr(buffer, vendor);
                       	position += 6;
                       	strncpy(vendorname, position, bsize/2);
                       	position = strstr(vendorname, "\n");
                       	*(position) = '\0';
			break;
                }
	}
	while(fgets(buffer, bsize, fp) != NULL) {
		if(strstr(buffer, device) != NULL) {
                        position = strstr(buffer, device);
                        position += 6;
                        strncpy(devicename, position, bsize/2);
			position = strstr(devicename, " (");
			if (position == NULL)
                        	position = strstr(devicename, "\n");
                        *(position) = '\0';
			cardfound = 1;
			break;
 		}
	}
	if (cardfound == 1)
		snprintf(fullname, bsize, "%s %s", vendorname, devicename);
	else
		snprintf(fullname, bsize, "%s:%s", vendor, device);	
	fclose(fp);
}
%C18$1%C: %C24$2%O second(s) 2 Ping Timeout XP_TE_PINGTIMEOUT pevt_pingtimeout_help %C20*%O$tNo ping reply for %C24$1%O seconds, disconnecting. 1 Private Action XP_TE_PRIVACTION pevt_privmsg_help %C18**$t$3$1%O $2 %C18** n3 Private Action to Dialog XP_TE_DPRIVACTION pevt_privmsg_help %C18*$t$3$1%O $2 n3 Private Message XP_TE_PRIVMSG pevt_privmsg_help %C18*%C18$3$1*%O$t$2 n3 Private Message to Dialog XP_TE_DPRIVMSG pevt_privmsg_help %C18%H<%H$3$1%H>%H%O$t$2 n3 Process Already Running XP_TE_ALREADYPROCESS pevt_generic_none_help %C24*%O$tA process is already running 0 Quit XP_TE_QUIT pevt_quit_help %C24*$t$1 has quit ($2) 3 Raw Modes XP_TE_RAWMODES pevt_rawmodes_help %C24*%O$t%C26$1%C sets modes %C30[%C24$2%C30]%O 2 Receive Wallops XP_TE_WALLOPS pevt_privmsg_help %O-%C29$1/Wallops%O-$t$2 2 Resolving User XP_TE_RESOLVINGUSER pevt_resolvinguser_help %C24*%O$tLooking up IP number for %C18$1%O... 2 SASL Authenticating XP_TE_SASLAUTH pevt_saslauth_help %C23*%O$tAuthenticating via SASL as %C18$1%O 1 SASL Response XP_TE_SASLRESPONSE pevt_saslresponse_help %C29*%O$t$4 n4 Server Connected XP_TE_SERVERCONNECTED pevt_generic_none_help %C29*%O$tConnected. 0 Server Error XP_TE_SERVERERROR pevt_servererror_help %C29*%O$t%C20$1%O n1 Server Lookup XP_TE_SERVERLOOKUP pevt_serverlookup_help %C29*%O$tLooking up %C29$1%O 1 Server Notice XP_TE_SERVNOTICE pevt_servertext_help %C29*%O$t$1 n2 Server Text XP_TE_SERVTEXT pevt_servertext_help %C29*%O$t$1 n3 SSL Message XP_TE_SSLMESSAGE pevt_sslmessage_help %C29*%O$t$1 n2 Stop Connection XP_TE_STOPCONNECT pevt_sconnect_help %C23*%O$tStopped previous connection attempt (%C24$1%O) 1 Topic XP_TE_TOPIC pevt_topic_help %C22*%O$tTopic for %C22$1%C is: $2%O 2 Topic Change XP_TE_NEWTOPIC pevt_newtopic_help %C22*%O$t%C26$1%C has changed the topic to: $2%O 3 Topic Creation XP_TE_TOPICDATE pevt_topicdate_help %C22*%O$tTopic for %C22$1%C set by %C26$2%C (%C24$3%O) 3 Unknown Host XP_TE_UKNHOST pevt_generic_none_help %C20*%O$tUnknown host. Maybe you misspelled it? 0 User Limit XP_TE_USERLIMIT pevt_generic_channel_help %C20*%O$tCannot join %C22$1%C (%C20User limit reached%O) 1 Users On Channel XP_TE_USERSONCHAN pevt_usersonchan_help %C22*%O$tUsers on %C22$1%C: %C24$2%O 2 WhoIs Authenticated XP_TE_WHOIS_AUTH pevt_whoisauth_help %C23*%O$t%C28[%C18$1%C28]%O $2 %C18$3%O n3 WhoIs Away Line XP_TE_WHOIS5 pevt_whois5_help %C23*%O$t%C28[%C18$1%C28]%C is away %C30(%C23$2%O%C30)%O 2 WhoIs Channel/Oper Line XP_TE_WHOIS2 pevt_whois2_help %C23*%O$t%C28[%C18$1%C28]%O $2 n2 WhoIs End XP_TE_WHOIS6 pevt_whois6_help %C23*%O$t%C28[%C18$1%C28] %OEnd of WHOIS list. 1 WhoIs Identified XP_TE_WHOIS_ID pevt_whoisid_help %C23*%O$t%C28[%C18$1%C28]%O $2 n2 WhoIs Idle Line XP_TE_WHOIS4 pevt_whois4_help %C23*%O$t%C28[%C18$1%C28]%O idle %C23$2%O 2 WhoIs Idle Line with Signon XP_TE_WHOIS4T pevt_whois4t_help %C23*%O$t%C28[%C18$1%C28]%O idle %C23$2%O, signon: %C23$3%O 3 WhoIs Name Line XP_TE_WHOIS1 pevt_whois1_help %C23*%O$t%C28[%C18$1%C28] %C30(%C24$2@$3%C30)%O: %C18$4%O n4 WhoIs Real Host XP_TE_WHOIS_REALHOST pevt_whoisrealhost_help %C23*%O$t%C28[%C18$1%C28]%O Real Host: %C23$2%O, Real IP: %C30[%C23$3%C30]%O 4 WhoIs Server Line XP_TE_WHOIS3 pevt_whois3_help %C23*%O$t%C28[%C18$1%C28]%O %C29$2%O n2 WhoIs Special XP_TE_WHOIS_SPECIAL pevt_whoisid_help %C23*%O$t%C28[%C18$1%C28]%O $2 n3 You Join XP_TE_UJOIN pevt_join_help %C19*%O$tNow talking on %C22$2%O 3 You Kicked XP_TE_UKICK pevt_ukick_help %C19*%O$tYou have been kicked from %C22$2%C by %C26$3%O (%C20$4%O) 4 You Part XP_TE_UPART pevt_part_help %C19*%O$tYou have left channel %C22$3%O 3 You Part with Reason XP_TE_UPARTREASON pevt_partreason_help %C19*%O$tYou have left channel %C22$3%C (%C24$4%O) 4 Your Action XP_TE_UACTION pevt_chanaction_help %C20*$t%B$1%B %C30$2%O n3 Your Invitation XP_TE_UINVITE pevt_uinvite_help %C20*%O$tYou've invited %C18$1%O to %C22$2%O (%C24$3%O) 3 Your Message XP_TE_UCHANMSG pevt_chanmsg_help %C20%H<%H$4$1%H>%H%O%C30$t$2%O n4 Your Nick Changing XP_TE_UCHANGENICK pevt_uchangenick_help %C20*%O$tYou are now known as %C18$2%O 2