1117N/A/*
1117N/A *
1117N/A * Copyright (c) 1997 Metro Link Incorporated
1117N/A *
1117N/A * Permission is hereby granted, free of charge, to any person obtaining a
1117N/A * copy of this software and associated documentation files (the "Software"),
1117N/A * to deal in the Software without restriction, including without limitation
1117N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1117N/A * and/or sell copies of the Software, and to permit persons to whom the
1117N/A * Software is furnished to do so, subject to the following conditions:
1117N/A *
1117N/A * The above copyright notice and this permission notice shall be included in
1117N/A * all copies or substantial portions of the Software.
1117N/A *
1117N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1117N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1117N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1117N/A * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
1117N/A * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
1117N/A * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1117N/A * SOFTWARE.
1117N/A *
1117N/A * Except as contained in this notice, the name of the Metro Link shall not be
1117N/A * used in advertising or otherwise to promote the sale, use or other dealings
1117N/A * in this Software without prior written authorization from Metro Link.
1117N/A *
1117N/A */
1117N/A/*
1117N/A * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
1117N/A *
1117N/A * Permission is hereby granted, free of charge, to any person obtaining a
1117N/A * copy of this software and associated documentation files (the "Software"),
1117N/A * to deal in the Software without restriction, including without limitation
1117N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1117N/A * and/or sell copies of the Software, and to permit persons to whom the
1117N/A * Software is furnished to do so, subject to the following conditions:
1117N/A *
1117N/A * The above copyright notice and this permission notice shall be included in
1117N/A * all copies or substantial portions of the Software.
1117N/A *
1117N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1117N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1117N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1117N/A * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1117N/A * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1117N/A * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1117N/A * OTHER DEALINGS IN THE SOFTWARE.
1117N/A *
1117N/A * Except as contained in this notice, the name of the copyright holder(s)
1117N/A * and author(s) shall not be used in advertising or otherwise to promote
1117N/A * the sale, use or other dealings in this Software without prior written
1117N/A * authorization from the copyright holder(s) and author(s).
1117N/A */
1117N/A
1117N/A
1117N/A/* View/edit this file with tab stops set to 4 */
1117N/A
1117N/A#ifdef HAVE_XORG_CONFIG_H
1117N/A#include <xorg-config.h>
1117N/A#endif
1117N/A
1117N/A#include "xf86Parser.h"
1117N/A#include "xf86tokens.h"
1117N/A#include "Configint.h"
1117N/A#include "fields.h" /* Config file output line fields */
1117N/A#if defined(SMI_FBCONFIG)
1117N/A#include "fbc_line_er.h" /* External Representation of config lines */
1117N/A#endif
1117N/A
1117N/Aextern LexRec val;
1117N/A
1117N/Astatic
1117N/Axf86ConfigSymTabRec DeviceTab[] =
1117N/A{
1117N/A {ENDSECTION, "endsection"},
1117N/A {IDENTIFIER, "identifier"},
1117N/A {VENDOR, "vendorname"},
1117N/A {BOARD, "boardname"},
1117N/A {CHIPSET, "chipset"},
1117N/A {RAMDAC, "ramdac"},
1117N/A {DACSPEED, "dacspeed"},
1117N/A {CLOCKS, "clocks"},
1117N/A {OPTION, "option"},
1117N/A {VIDEORAM, "videoram"},
1117N/A {BIOSBASE, "biosbase"},
1117N/A {MEMBASE, "membase"},
1117N/A {IOBASE, "iobase"},
1117N/A {CLOCKCHIP, "clockchip"},
1117N/A {CHIPID, "chipid"},
1117N/A {CHIPREV, "chiprev"},
1117N/A {CARD, "card"},
1117N/A {DRIVER, "driver"},
1117N/A {BUSID, "busid"},
1117N/A {TEXTCLOCKFRQ, "textclockfreq"},
1117N/A {IRQ, "irq"},
1117N/A {SCREEN, "screen"},
1117N/A {-1, ""},
1117N/A};
1117N/A
1117N/A#define CLEANUP xf86freeDeviceList
1117N/A
1117N/AXF86ConfDevicePtr
1117N/Axf86parseDeviceSection (void)
1117N/A{
1117N/A int i;
1117N/A int has_ident = FALSE;
1117N/A int token;
1117N/A#if defined(SMI_FBCONFIG)
1117N/A void *line_er; /* Ptr to Extnl Rep of config file line */
1117N/A#endif
1117N/A parsePrologue (XF86ConfDevicePtr, XF86ConfDeviceRec)
1117N/A
1117N/A /* Zero is a valid value for these */
1117N/A ptr->dev_chipid = -1;
1117N/A ptr->dev_chiprev = -1;
1117N/A ptr->dev_irq = -1;
1117N/A for (;;)
1117N/A {
1117N/A token = xf86getToken(DeviceTab);
1117N/A#if defined(SMI_FBCONFIG)
1117N/A /*
1117N/A * Get a ptr to the External Representation of this config line
1117N/A */
1117N/A line_er = fbc_get_current_line_ER();
1117N/A
1117N/A#endif
1117N/A if (token == ENDSECTION)
1117N/A {
1117N/A break;
1117N/A }
1117N/A switch (token)
1117N/A {
1117N/A case COMMENT:
1117N/A ptr->dev_comment = xf86addComment(ptr->dev_comment, val.str);
1117N/A break;
1117N/A case IDENTIFIER:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
1117N/A Error (QUOTE_MSG, "Identifier");
1117N/A if (has_ident == TRUE)
1117N/A Error (MULTIPLE_MSG, "Identifier");
1117N/A ptr->dev_identifier = val.str;
1117N/A has_ident = TRUE;
1117N/A break;
1117N/A case VENDOR:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
1117N/A Error (QUOTE_MSG, "Vendor");
1117N/A ptr->dev_vendor = val.str;
1117N/A break;
1117N/A case BOARD:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
1117N/A Error (QUOTE_MSG, "Board");
1117N/A ptr->dev_board = val.str;
1117N/A break;
1117N/A case CHIPSET:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
1117N/A Error (QUOTE_MSG, "Chipset");
1117N/A ptr->dev_chipset = val.str;
1117N/A break;
1117N/A case CARD:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
1117N/A Error (QUOTE_MSG, "Card");
1117N/A ptr->dev_card = val.str;
1117N/A break;
1117N/A case DRIVER:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
1117N/A Error (QUOTE_MSG, "Driver");
1117N/A ptr->dev_driver = val.str;
1117N/A break;
1117N/A case RAMDAC:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
1117N/A Error (QUOTE_MSG, "Ramdac");
1117N/A ptr->dev_ramdac = val.str;
1117N/A break;
1117N/A case DACSPEED:
1117N/A for (i = 0; i < CONF_MAXDACSPEEDS; i++)
1117N/A ptr->dev_dacSpeeds[i] = 0;
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
1117N/A {
1117N/A Error (DACSPEED_MSG, CONF_MAXDACSPEEDS);
1117N/A }
1117N/A else
1117N/A {
1117N/A ptr->dev_dacSpeeds[0] = (int) (val.realnum * 1000.0 + 0.5);
1117N/A for (i = 1; i < CONF_MAXDACSPEEDS; i++)
1117N/A {
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) == NUMBER)
1117N/A ptr->dev_dacSpeeds[i] = (int)
1117N/A (val.realnum * 1000.0 + 0.5);
1117N/A else
1117N/A {
1117N/A xf86unGetToken (token);
1117N/A break;
1117N/A }
1117N/A }
1117N/A }
1117N/A break;
1117N/A case VIDEORAM:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
1117N/A Error (NUMBER_MSG, "VideoRam");
1117N/A ptr->dev_videoram = val.num;
1117N/A break;
1117N/A case BIOSBASE:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
1117N/A Error (NUMBER_MSG, "BIOSBase");
1117N/A ptr->dev_bios_base = val.num;
1117N/A break;
1117N/A case MEMBASE:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
1117N/A Error (NUMBER_MSG, "MemBase");
1117N/A ptr->dev_mem_base = val.num;
1117N/A break;
1117N/A case IOBASE:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
1117N/A Error (NUMBER_MSG, "IOBase");
1117N/A ptr->dev_io_base = val.num;
1117N/A break;
1117N/A case CLOCKCHIP:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
1117N/A Error (QUOTE_MSG, "ClockChip");
1117N/A ptr->dev_clockchip = val.str;
1117N/A break;
1117N/A case CHIPID:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
1117N/A Error (NUMBER_MSG, "ChipID");
1117N/A ptr->dev_chipid = val.num;
1117N/A break;
1117N/A case CHIPREV:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
1117N/A Error (NUMBER_MSG, "ChipRev");
1117N/A ptr->dev_chiprev = val.num;
1117N/A break;
1117N/A
1117N/A case CLOCKS:
1117N/A token = xf86getSubToken(&(ptr->dev_comment));
1117N/A for( i = ptr->dev_clocks;
1117N/A token == NUMBER && i < CONF_MAXCLOCKS; i++ ) {
1117N/A ptr->dev_clock[i] = (int)(val.realnum * 1000.0 + 0.5);
1117N/A token = xf86getSubToken(&(ptr->dev_comment));
1117N/A }
1117N/A ptr->dev_clocks = i;
1117N/A xf86unGetToken (token);
1117N/A break;
1117N/A case TEXTCLOCKFRQ:
1117N/A if ((token = xf86getSubToken(&(ptr->dev_comment))) != NUMBER)
1117N/A Error (NUMBER_MSG, "TextClockFreq");
1117N/A ptr->dev_textclockfreq = (int)(val.realnum * 1000.0 + 0.5);
1117N/A break;
1117N/A case OPTION:
1117N/A ptr->dev_option_lst = xf86parseOption(ptr->dev_option_lst);
1117N/A break;
1117N/A case BUSID:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
1117N/A Error (QUOTE_MSG, "BusID");
1117N/A ptr->dev_busid = val.str;
1117N/A break;
1117N/A case IRQ:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
1117N/A Error (QUOTE_MSG, "IRQ");
1117N/A ptr->dev_irq = val.num;
1117N/A break;
1117N/A case SCREEN:
1117N/A if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
1117N/A Error (NUMBER_MSG, "Screen");
1117N/A ptr->dev_screen = val.num;
1117N/A break;
1117N/A case EOF_TOKEN:
1117N/A Error (UNEXPECTED_EOF_MSG, NULL);
1117N/A break;
1117N/A default:
1117N/A Error (INVALID_KEYWORD_MSG, xf86tokenString ());
1117N/A break;
1117N/A }
1117N/A }
1117N/A
1117N/A#if defined(SMI_FBCONFIG)
1117N/A /*
1117N/A * Link Internal & External Representations of the EndSection line
1117N/A */
1117N/A ptr->dev_end_line_er = line_er;
1117N/A fbc_link_line_ER(line_er,
1117N/A (void *)ptr,
1117N/A (xf86_print_fn_t *)&xf86printDeviceSectionEndSection,
1117N/A FBC_INDENT_0);
1117N/A
1117N/A#endif
1117N/A if (!has_ident)
1117N/A Error (NO_IDENT_MSG, NULL);
1117N/A
1117N/A#ifdef DEBUG
1117N/A printf ("Device section parsed\n");
1117N/A#endif
1117N/A
1117N/A return ptr;
1117N/A}
1117N/A
1117N/A#undef CLEANUP
1117N/A
1117N/A
1117N/A/*
1117N/A * xf86printDeviceSectionSection()
1117N/A *
1117N/A * Write the Device section Section line to the configuration file.
1117N/A */
1117N/Avoid
1117N/Axf86printDeviceSectionSection(
1117N/A FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[])
1117N/A{
1117N/A fprintf (cf, "Section \"Device\"\n");
1117N/A if (ptr->dev_comment != NULL) {
1117N/A fprintf(cf, "%s", ptr->dev_comment);
1117N/A }
1117N/A}
1117N/A
1117N/A
1117N/A/*
1117N/A * xf86printDeviceSectionIdentifier()
1117N/A *
1117N/A * Write the Device section Identifier line to the configuration
1117N/A * file.
1117N/A */
1117N/Avoid
1117N/Axf86printDeviceSectionIdentifier(
1117N/A FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[])
1117N/A{
1117N/A xf86printFields(cf, whitespace, "Identifier", NULL);
1117N/A fprintf(cf, "\"%s\"\n", ptr->dev_identifier);
1117N/A}
1117N/A
1117N/A
1117N/A/*
1117N/A * xf86printDeviceSectionDriver()
1117N/A *
1117N/A * Write the Device section Driver line to the configuration file.
1117N/A */
1117N/Avoid
1117N/Axf86printDeviceSectionDriver(
1117N/A FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[])
1117N/A{
1117N/A xf86printFields(cf, whitespace, "Driver", NULL);
1117N/A fprintf (cf, "\"%s\"\n", ptr->dev_driver);
1117N/A}
1117N/A
1117N/A
1117N/A/*
1117N/A * xf86printDeviceSectionVendorName()
1117N/A *
1117N/A * Write the Device section VendorName line to the configuration
1117N/A * file.
1117N/A */
1117N/Avoid
1117N/Axf86printDeviceSectionVendorName(
1117N/A FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[])
1117N/A{
1117N/A xf86printFields(cf, whitespace, "VendorName", NULL);
1117N/A fprintf (cf, "\"%s\"\n", ptr->dev_vendor);
1117N/A}
1117N/A
1117N/A
1117N/A/*
1117N/A * xf86printDeviceSectionBoardName()
1117N/A *
1117N/A * Write the Device section BoardName line to the configuration file.
1117N/A */
1117N/Avoid
1117N/Axf86printDeviceSectionBoardName(
1117N/A FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[])
1117N/A{
1117N/A xf86printFields(cf, whitespace, "BoardName", NULL);
1117N/A fprintf (cf, "\"%s\"\n", ptr->dev_board);
1117N/A}
1117N/A
1117N/A
1117N/A/*
1117N/A * xf86printDeviceSectionEndSection()
1117N/A *
1117N/A * Write the Device section EndSection line to the configuration
1117N/A * file.
1117N/A */
1117N/Avoid
1117N/Axf86printDeviceSectionEndSection(
1117N/A FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[])
1117N/A{
1117N/A fprintf (cf, "EndSection\n");
1117N/A}
1117N/A
1117N/A
1117N/A/*
1117N/A * xf86printDeviceSection()
1117N/A *
1117N/A * Write a Device section to the configuration file.
1117N/A */
1117N/Avoid
1117N/Axf86printDeviceSection (FILE * cf, XF86ConfDevicePtr ptr)
1117N/A{
1117N/A int i;
1117N/A
1117N/A while (ptr)
1117N/A {
1117N/A xf86printDeviceSectionSection(cf, ptr, xf86whitespace_0);
1117N/A if (ptr->dev_identifier != NULL) {
1117N/A xf86printDeviceSectionIdentifier(cf, ptr, xf86whitespace_1);
1117N/A }
1117N/A if (ptr->dev_driver != NULL) {
1117N/A xf86printDeviceSectionDriver(cf, ptr, xf86whitespace_1);
1117N/A }
1117N/A if (ptr->dev_vendor != NULL) {
1117N/A xf86printDeviceSectionVendorName(cf, ptr, xf86whitespace_1);
1117N/A }
1117N/A if (ptr->dev_board != NULL) {
1117N/A xf86printDeviceSectionBoardName(cf, ptr, xf86whitespace_1);
1117N/A }
1117N/A if (ptr->dev_chipset)
1117N/A fprintf (cf, "\tChipSet \"%s\"\n", ptr->dev_chipset);
1117N/A if (ptr->dev_card)
1117N/A fprintf (cf, "\tCard \"%s\"\n", ptr->dev_card);
1117N/A if (ptr->dev_ramdac)
1117N/A fprintf (cf, "\tRamDac \"%s\"\n", ptr->dev_ramdac);
1117N/A if (ptr->dev_dacSpeeds[0] > 0 ) {
1117N/A fprintf (cf, "\tDacSpeed ");
1117N/A for (i = 0; i < CONF_MAXDACSPEEDS
1117N/A && ptr->dev_dacSpeeds[i] > 0; i++ )
1117N/A fprintf (cf, "%g ", (double) (ptr->dev_dacSpeeds[i])/ 1000.0 );
1117N/A fprintf (cf, "\n");
1117N/A }
1117N/A if (ptr->dev_videoram)
1117N/A fprintf (cf, "\tVideoRam %d\n", ptr->dev_videoram);
1117N/A if (ptr->dev_bios_base)
1117N/A fprintf (cf, "\tBiosBase 0x%lx\n", ptr->dev_bios_base);
1117N/A if (ptr->dev_mem_base)
1117N/A fprintf (cf, "\tMemBase 0x%lx\n", ptr->dev_mem_base);
1117N/A if (ptr->dev_io_base)
1117N/A fprintf (cf, "\tIOBase 0x%lx\n", ptr->dev_io_base);
1117N/A if (ptr->dev_clockchip)
1117N/A fprintf (cf, "\tClockChip \"%s\"\n", ptr->dev_clockchip);
1117N/A if (ptr->dev_chipid != -1)
1117N/A fprintf (cf, "\tChipId 0x%x\n", ptr->dev_chipid);
1117N/A if (ptr->dev_chiprev != -1)
1117N/A fprintf (cf, "\tChipRev 0x%x\n", ptr->dev_chiprev);
1117N/A
1117N/A xf86printOptionList(cf, ptr->dev_option_lst, xf86whitespace_1);
1117N/A if (ptr->dev_clocks > 0 ) {
1117N/A fprintf (cf, "\tClocks ");
1117N/A for (i = 0; i < ptr->dev_clocks; i++ )
1117N/A fprintf (cf, "%.1f ", (double)ptr->dev_clock[i] / 1000.0 );
1117N/A fprintf (cf, "\n");
1117N/A }
1117N/A if (ptr->dev_textclockfreq) {
1117N/A fprintf (cf, "\tTextClockFreq %.1f\n",
1117N/A (double)ptr->dev_textclockfreq / 1000.0);
1117N/A }
1117N/A if (ptr->dev_busid)
1117N/A fprintf (cf, "\tBusID \"%s\"\n", ptr->dev_busid);
1117N/A if (ptr->dev_screen > 0)
1117N/A fprintf (cf, "\tScreen %d\n", ptr->dev_screen);
1117N/A if (ptr->dev_irq >= 0)
1117N/A fprintf (cf, "\tIRQ %d\n", ptr->dev_irq);
1117N/A xf86printDeviceSectionEndSection(cf, ptr, xf86whitespace_0);
1117N/A fprintf (cf, "\n");
1117N/A ptr = ptr->list.next;
1117N/A }
1117N/A}
1117N/A
1117N/Avoid
1117N/Axf86freeDeviceList (XF86ConfDevicePtr ptr)
1117N/A{
1117N/A XF86ConfDevicePtr prev;
1117N/A
1117N/A while (ptr)
1117N/A {
1117N/A TestFree (ptr->dev_identifier);
1117N/A TestFree (ptr->dev_vendor);
1117N/A TestFree (ptr->dev_board);
1117N/A TestFree (ptr->dev_chipset);
1117N/A TestFree (ptr->dev_card);
1117N/A TestFree (ptr->dev_driver);
1117N/A TestFree (ptr->dev_ramdac);
1117N/A TestFree (ptr->dev_clockchip);
1117N/A TestFree (ptr->dev_comment);
1117N/A xf86optionListFree (ptr->dev_option_lst);
1117N/A
1117N/A prev = ptr;
1117N/A ptr = ptr->list.next;
1117N/A xf86conffree (prev);
1117N/A }
1117N/A}
1117N/A
1117N/Aint
1117N/Axf86validateDevice (XF86ConfigPtr p)
1117N/A{
1117N/A XF86ConfDevicePtr device = p->conf_device_lst;
1117N/A
1117N/A#if !defined(SMI_FBCONFIG) /* Missing section will be constructed */
1117N/A if (!device) {
1117N/A xf86validationError ("At least one Device section is required.");
1117N/A return (FALSE);
1117N/A }
1117N/A
1117N/A#endif
1117N/A while (device) {
1117N/A if (!device->dev_driver) {
1117N/A xf86validationError (UNDEFINED_DRIVER_MSG, device->dev_identifier);
1117N/A return (FALSE);
1117N/A }
1117N/A device = device->list.next;
1117N/A }
1117N/A return (TRUE);
1117N/A}
1117N/A
1117N/AXF86ConfDevicePtr
1117N/Axf86findDevice (const char *ident, XF86ConfDevicePtr p)
1117N/A{
1117N/A while (p)
1117N/A {
1117N/A if (xf86nameCompare (ident, p->dev_identifier) == 0)
1117N/A return (p);
1117N/A
1117N/A p = p->list.next;
1117N/A }
1117N/A return (NULL);
1117N/A}
1117N/A
1117N/Achar *
1117N/Axf86configStrdup (const char *s)
1117N/A{
1117N/A char *tmp;
1117N/A if (!s) return NULL;
1117N/A tmp = xf86confmalloc (sizeof (char) * (strlen (s) + 1));
1117N/A if (tmp)
1117N/A strcpy (tmp, s);
1117N/A return (tmp);
1117N/A}
1117N/A