/* sis_ds.h -- Private header for Direct Rendering Manager -*- linux-c -*- * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw * * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * Authors: * Sung-Ching Lin * */ #ifndef __SIS_DS_H__ #define __SIS_DS_H__ /* Set Data Structure */ #define SET_SIZE 5000 typedef unsigned int ITEM_TYPE; typedef struct { ITEM_TYPE val; int alloc_next, free_next; } list_item_t; typedef struct { int alloc; int free; int trace; list_item_t list[SET_SIZE]; } set_t; set_t *setInit(void); int setAdd(set_t *set, ITEM_TYPE item); int setDel(set_t *set, ITEM_TYPE item); int setFirst(set_t *set, ITEM_TYPE *item); int setNext(set_t *set, ITEM_TYPE *item); int setDestroy(set_t *set); /* * GLX Hardware Device Driver common code * Copyright (C) 1999 Keith Whitwell * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ struct mem_block_t { struct mem_block_t *next; struct mem_block_t *heap; int ofs,size; int align; int free:1; int reserved:1; }; typedef struct mem_block_t TMemBlock; typedef struct mem_block_t *PMemBlock; /* a heap is just the first block in a chain */ typedef struct mem_block_t memHeap_t; static __inline__ int mmBlockSize(PMemBlock b) { return b->size; } static __inline__ int mmOffset(PMemBlock b) { return b->ofs; } static __inline__ void mmMarkReserved(PMemBlock b) { b->reserved = 1; } /* * input: total size in bytes * return: a heap pointer if OK, NULL if error */ memHeap_t *mmInit( int ofs, int size ); memHeap_t *mmAddRange( memHeap_t *heap, int ofs, int size ); /* * Allocate 'size' bytes with 2^align2 bytes alignment, * restrict the search to free memory after 'startSearch' * depth and back buffers should be in different 4mb banks * to get better page hits if possible * input: size = size of block * align2 = 2^align2 bytes alignment * startSearch = linear offset from start of heap to begin search * return: pointer to the allocated block, 0 if error */ PMemBlock mmAllocMem( memHeap_t *heap, int size, int align2, int startSearch ); /* * Returns 1 if the block 'b' is part of the heap 'heap' */ int mmBlockInHeap( PMemBlock heap, PMemBlock b ); /* * Free block starts at offset * input: pointer to a block * return: 0 if OK, -1 if error */ int mmFreeMem( PMemBlock b ); /* * Reserve 'size' bytes block start at offset * This is used to prevent allocation of memory already used * by the X server for the front buffer, pixmaps, and cursor * input: size, offset * output: 0 if OK, -1 if error */ int mmReserveMem( memHeap_t *heap, int offset,int size ); int mmFreeReserved( memHeap_t *heap, int offset ); /* * destroy MM */ void mmDestroy( memHeap_t *mmInit ); /* For debuging purpose. */ void mmDumpMemInfo( memHeap_t *mmInit ); #endif /* __SIS_DS_H__ */ n64'>64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
/*
 * Copyright 2007 Jérôme Glisse
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */
/*
 * Authors:
 *    Jérôme Glisse <glisse@freedesktop.org>
 */
#include "radeon_ms.h"

extern struct radeon_ms_output radeon_ms_dac1;
extern struct radeon_ms_output radeon_ms_dac2;
extern const struct drm_output_funcs radeon_ms_output_funcs;

static struct combios_connector_chip_info *
radeon_ms_combios_get_connector_chip_info(struct drm_device *dev, int chip_num)
{
	struct drm_radeon_private *dev_priv = dev->dev_private;
	struct radeon_ms_rom *rom = &dev_priv->rom;
	struct combios_header *header;
	struct combios_connector_table *connector_table;
	struct combios_connector_chip_info *connector_chip_info;
	uint32_t offset;
	int numof_chips, i;

	if (rom->type != ROM_COMBIOS || rom->rom_image == NULL) {
		return NULL;
	}
	header = rom->rom.combios_header;
	offset = header->usPointerToExtendedInitTable2;
	if ((offset + sizeof(struct combios_connector_table)) > rom->rom_size) {
		DRM_INFO("[radeon_ms] wrong COMBIOS connector offset\n");
		return NULL;
	}
	if (!offset) {
		return NULL;
	}
	connector_table = (struct combios_connector_table *)
	                  &rom->rom_image[offset];
	numof_chips = (connector_table->ucConnectorHeader &
		       BIOS_CONNECTOR_HEADER__NUMBER_OF_CHIPS__MASK) >>
		      BIOS_CONNECTOR_HEADER__NUMBER_OF_CHIPS__SHIFT;
	DRM_INFO("[radeon_ms] COMBIOS number of chip: %d (table rev: %d)\n",
		 numof_chips,
		 (connector_table->ucConnectorHeader &
		  BIOS_CONNECTOR_HEADER__TABLE_REVISION__MASK) >>
		 BIOS_CONNECTOR_HEADER__TABLE_REVISION__SHIFT);
	for (i = 0; i < numof_chips; i++) {
		int chip;

		connector_chip_info = &connector_table->sChipConnectorInfo[i];
		chip = (connector_chip_info->ucChipHeader &
			BIOS_CHIPINFO_HEADER__CHIP_NUMBER__MASK) >>
		       BIOS_CHIPINFO_HEADER__CHIP_NUMBER__SHIFT;
		DRM_INFO("[radeon_ms] COMBIOS chip: %d (asked for: %d)\n",
		         chip, chip_num);
		if (chip == chip_num) {
			return connector_chip_info;
		}
	}
	return NULL;
}

static int radeon_combios_get_connector_infos(struct drm_device *dev,
					      int connector_info, 
					      int *connector_type, 
					      int *ddc_line,
					      int *tmds_type,
					      int *dac_type)
{
	struct drm_radeon_private *dev_priv = dev->dev_private;

	*connector_type = (connector_info & BIOS_CONNECTOR_INFO__TYPE__MASK) >>
			  BIOS_CONNECTOR_INFO__TYPE__SHIFT;
	*ddc_line = (connector_info & BIOS_CONNECTOR_INFO__DDC_LINE__MASK) >>
		    BIOS_CONNECTOR_INFO__DDC_LINE__SHIFT;
	*tmds_type = (connector_info & BIOS_CONNECTOR_INFO__TMDS_TYPE__MASK) >>
		     BIOS_CONNECTOR_INFO__TMDS_TYPE__SHIFT;
	*dac_type = (connector_info & BIOS_CONNECTOR_INFO__DAC_TYPE__MASK) >>
		    BIOS_CONNECTOR_INFO__DAC_TYPE__SHIFT;

	/* most XPRESS chips seem to specify DDC_CRT2 for their 
	 * VGA DDC port, however DDC never seems to work on that
	 * port.  Some have reported success on DDC_MONID, so 
	 * lets see what happens with that.
	 */
	if (dev_priv->family == CHIP_RS400 &&
	    *connector_type == BIOS_CONNECTOR_TYPE__CRT &&
	    *ddc_line == BIOS_DDC_LINE__CRT2) {
		*ddc_line = BIOS_DDC_LINE__MONID01;
	}
	/* XPRESS desktop chips seem to have a proprietary
	 * connector listed for DVI-D, try and do the right
	 * thing here.
	 */
	if (dev_priv->family == CHIP_RS400 &&
	    *connector_type == BIOS_CONNECTOR_TYPE__PROPRIETARY) {
		DRM_INFO("[radeon_ms] COMBIOS Proprietary connector "
		         "found, assuming DVI-D\n");
		*dac_type = 2;
	        *tmds_type = BIOS_TMDS_TYPE__EXTERNAL;
		*connector_type = BIOS_CONNECTOR_TYPE__DVI_D;
	}
	return 0;
}

static int radeon_ms_combios_connector_add(struct drm_device *dev,
					   int connector_number,
					   int connector_type,
					   uint32_t i2c_reg)
{
	struct drm_radeon_private *dev_priv = dev->dev_private;
	struct radeon_ms_connector *connector = NULL;
	struct drm_output *output = NULL;

	connector = drm_alloc(sizeof(struct radeon_ms_connector),
			      DRM_MEM_DRIVER);
	if (connector == NULL) {
		radeon_ms_connectors_destroy(dev);
		return -ENOMEM;
	}
	memset(connector, 0, sizeof(struct radeon_ms_connector));
	connector->monitor_type = MT_NONE;
	connector->type = connector_type;
	connector->i2c_reg = i2c_reg;

	switch (connector->type) {
	case CONNECTOR_VGA:
		sprintf(connector->name, "VGA");
		break;
	case CONNECTOR_DVI_I:
		sprintf(connector->name, "DVI-I");
		break;
	case CONNECTOR_DVI_D:
		sprintf(connector->name, "DVI-D");
		break;
	default:
		sprintf(connector->name, "UNKNOWN-CONNECTOR");
		break;
	}

	if (i2c_reg) {
		connector->i2c = radeon_ms_i2c_create(dev,
						      connector->i2c_reg,
						      connector->name);
		if (connector->i2c == NULL) {
			radeon_ms_connectors_destroy(dev);
			return -ENOMEM;
		}
	} else {
		connector->i2c = NULL;
	}

	output = drm_output_create(dev, &radeon_ms_output_funcs,
				   connector->type);
	if (output == NULL) {
		radeon_ms_connectors_destroy(dev);
		return -EINVAL;
	}
	connector->output = output;
	output->driver_private = connector;
	output->possible_crtcs = 0x3;
	dev_priv->connectors[connector_number] = connector;
	return 0;
}

int radeon_ms_combios_get_properties(struct drm_device *dev)
{
	struct drm_radeon_private *dev_priv = dev->dev_private;
	struct radeon_ms_rom *rom = &dev_priv->rom;
	struct combios_pll_block *pll_block;
	struct combios_header *header;
	uint32_t offset;

	if (rom->type != ROM_COMBIOS || rom->rom_image == NULL) {
		return 0;
	}
	header = rom->rom.combios_header;
	offset = header->usPointerToPllInfoBlock;
	if ((offset + sizeof(struct combios_pll_block)) > rom->rom_size) {
		DRM_INFO("[radeon_ms] wrong COMBIOS pll block offset\n");
		return 0;
	}
	if (!offset) {
		return 0;
	}
	pll_block = (struct combios_pll_block *)&rom->rom_image[offset];
	dev_priv->properties.pll_reference_freq = pll_block->usDotClockRefFreq;
	dev_priv->properties.pll_reference_div = pll_block->usDotClockRefDiv;
	dev_priv->properties.pll_min_pll_freq = pll_block->ulDotClockMinFreq;
	dev_priv->properties.pll_max_pll_freq = pll_block->ulDotClockMaxFreq;
	dev_priv->properties.pll_reference_freq *= 10;
	dev_priv->properties.pll_min_pll_freq *= 10;
	dev_priv->properties.pll_max_pll_freq *= 10;
	DRM_INFO("[radeon_ms] COMBIOS pll reference frequency : %d\n",
		 dev_priv->properties.pll_reference_freq);
	DRM_INFO("[radeon_ms] COMBIOS pll reference divider   : %d\n",
		 dev_priv->properties.pll_reference_div);
	DRM_INFO("[radeon_ms] COMBIOS pll minimum frequency   : %d\n",
		 dev_priv->properties.pll_min_pll_freq);
	DRM_INFO("[radeon_ms] COMBIOS pll maximum frequency   : %d\n",
		 dev_priv->properties.pll_max_pll_freq);
	return 1;
}

int radeon_ms_connectors_from_combios(struct drm_device *dev)
{
	struct drm_radeon_private *dev_priv = dev->dev_private;
	struct combios_connector_chip_info *connector_chip_info;
	int connector_type, ddc_line, tmds_type, dac_type;
	int dac1, dac2, tmdsint, tmdsext;
	int numof_connector, i, c = 0, added, j;
	uint32_t i2c_reg;
	int ret;

	dac1 = dac2 = tmdsint = tmdsext = -1;
	connector_chip_info = radeon_ms_combios_get_connector_chip_info(dev, 1);
	if (connector_chip_info == NULL) {
		return -1;
	}
	numof_connector = (connector_chip_info->ucChipHeader &
			   BIOS_CHIPINFO_HEADER__NUMBER_OF_CONNECTORS__MASK) >>
			  BIOS_CHIPINFO_HEADER__NUMBER_OF_CONNECTORS__SHIFT;
	DRM_INFO("[radeon_ms] COMBIOS number of connector: %d\n",
	         numof_connector);
	for (i = 0; i < numof_connector; i++) {
		int connector_info = connector_chip_info->sConnectorInfo[i];

		ret = radeon_combios_get_connector_infos(dev,
							 connector_info, 
							 &connector_type, 
							 &ddc_line,
							 &tmds_type,
							 &dac_type);

		switch (ddc_line) {
		case BIOS_DDC_LINE__MONID01:
			i2c_reg = GPIO_MONID;
			break;
		case BIOS_DDC_LINE__DVI:
			i2c_reg =  GPIO_DVI_DDC;
			break;
		case BIOS_DDC_LINE__VGA:
			i2c_reg = GPIO_DDC1;
			break;
		case BIOS_DDC_LINE__CRT2:
			i2c_reg = GPIO_CRT2_DDC;
			break;
		case BIOS_DDC_LINE__GPIOPAD:
			i2c_reg = VIPPAD_EN;
			break;
		case BIOS_DDC_LINE__ZV_LCDPAD:
			i2c_reg = VIPPAD1_EN;
			break;
		default:
			i2c_reg = 0;
			break;
		}
		added = 0;
		switch (connector_type) {
		case BIOS_CONNECTOR_TYPE__CRT:
			ret = radeon_ms_combios_connector_add(dev, c,
							      CONNECTOR_VGA,
							      i2c_reg);
			if (ret) {
				return ret;
			}
			added = 1;
			break;
		case BIOS_CONNECTOR_TYPE__DVI_I:
			ret = radeon_ms_combios_connector_add(dev, c,
							      CONNECTOR_DVI_I,
							      i2c_reg);
			if (ret) {
				return ret;
			}
			added = 1;
			break;
		case BIOS_CONNECTOR_TYPE__DVI_D:
			ret = radeon_ms_combios_connector_add(dev, c,
							      CONNECTOR_DVI_D,
							      i2c_reg);
			if (ret) {
				return ret;
			}
			added = 1;
			break;
		default:
			break;
		}
		if (added) {
			j = 0;
			/* find to which output this connector is associated 
			 * by following same algo as in:
			 * radeon_ms_outputs_from_combios*/
			switch (dac_type) {
			case BIOS_DAC_TYPE__CRT:
				if (dac1 == -1) {