summaryrefslogtreecommitdiff
path: root/linux-core/intel_drv.h
blob: 256deac7c322ee5dd7a7a427cba3ba881c3b0831 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
/*
 * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
 * Copyright (c) 2007 Intel Corporation
 *   Jesse Barnes <jesse.barnes@intel.com>
 */
#ifndef __INTEL_DRV_H__
#define __INTEL_DRV_H__

#include <linux/i2c.h>
#include <linux/i2c-id.h>
#include <linux/i2c-algo-bit.h>
#include "drm_crtc.h"

#include "drm_crtc_helper.h"
/*
 * Display related stuff
 */

/* store information about an Ixxx DVO */
/* The i830->i865 use multiple DVOs with multiple i2cs */
/* the i915, i945 have a single sDVO i2c bus - which is different */
#define MAX_OUTPUTS 6
/* maximum connectors per crtcs in the mode set */
#define INTELFB_CONN_LIMIT 4

#define INTEL_I2C_BUS_DVO 1
#define INTEL_I2C_BUS_SDVO 2

/* these are outputs from the chip - integrated only 
   external chips are via DVO or SDVO output */
#define INTEL_OUTPUT_UNUSED 0
#define INTEL_OUTPUT_ANALOG 1
#define INTEL_OUTPUT_DVO 2
#define INTEL_OUTPUT_SDVO 3
#define INTEL_OUTPUT_LVDS 4
#define INTEL_OUTPUT_TVOUT 5

#define INTEL_DVO_CHIP_NONE 0
#define INTEL_DVO_CHIP_LVDS 1
#define INTEL_DVO_CHIP_TMDS 2
#define INTEL_DVO_CHIP_TVOUT 4

struct intel_i2c_chan {
	struct drm_device *drm_dev; /* for getting at dev. private (mmio etc.) */
	u32 reg; /* GPIO reg */
	struct i2c_adapter adapter;
	struct i2c_algo_bit_data algo;
        u8 slave_addr;
};

struct intel_framebuffer {
	struct drm_framebuffer base;
};


struct intel_output {
	struct drm_connector base;

	struct drm_encoder enc;
	int type;
	struct intel_i2c_chan *i2c_bus; /* for control functions */
	struct intel_i2c_chan *ddc_bus; /* for DDC only stuff */
	bool load_detect_temp;
	void *dev_priv;
};

struct intel_crtc {
	struct drm_crtc base;
	int pipe;
	int plane;
	uint32_t cursor_addr;
	u8 lut_r[256], lut_g[256], lut_b[256];
	int dpms_mode;
	struct intel_framebuffer *fbdev_fb;
	/* a mode_set for fbdev users on this crtc */
	struct drm_mode_set mode_set;
};

#define to_intel_crtc(x) container_of(x, struct intel_crtc, base)
#define to_intel_output(x) container_of(x, struct intel_output, base)
#define enc_to_intel_output(x) container_of(x, struct intel_output, enc)
#define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)

struct intel_i2c_chan *intel_i2c_create(struct drm_device *dev, const u32 reg,
					const char *name);
void intel_i2c_destroy(struct intel_i2c_chan *chan);
int intel_ddc_get_modes(struct intel_output *intel_output);
extern bool intel_ddc_probe(struct intel_output *intel_output);

extern void intel_crt_init(struct drm_device *dev);
extern void intel_sdvo_init(struct drm_device *dev, int output_device);
extern void intel_dvo_init(struct drm_device *dev);
extern void intel_tv_init(struct drm_device *dev);
extern void intel_lvds_init(struct drm_device *dev);

extern void intel_crtc_load_lut(struct drm_crtc *crtc);
extern void intel_encoder_prepare (struct drm_encoder *encoder);
extern void intel_encoder_commit (struct drm_encoder *encoder);

extern struct drm_encoder *intel_best_encoder(struct drm_connector *connector);

extern struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
 						    struct drm_crtc *crtc);
extern void intel_wait_for_vblank(struct drm_device *dev);
extern struct drm_crtc *intel_get_crtc_from_pipe(struct drm_device *dev, int pipe);
extern struct drm_crtc *intel_get_load_detect_pipe(struct intel_output *intel_output,
						   struct drm_display_mode *mode,
						   int *dpms_mode);
extern void intel_release_load_detect_pipe(struct intel_output *intel_output,
					   int dpms_mode);

extern struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB);
extern int intel_sdvo_supports_hotplug(struct drm_connector *connector);
extern void intel_sdvo_set_hotplug(struct drm_connector *connector, int enable);
extern int intelfb_probe(struct drm_device *dev);
extern int intelfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
extern int intelfb_resize(struct drm_device *dev, struct drm_crtc *crtc);
extern void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
				    u16 blue, int regno);

extern struct drm_framebuffer *
intel_framebuffer_create(struct drm_device *dev,
			 struct drm_mode_fb_cmd *mode_cmd,
			 void *mm_private);
#endif /* __INTEL_DRV_H__ */
ic hash tables was postponed until the need arises. A common (and * naive) approach to dynamic hash table implementation simply creates a * new hash table when necessary, rehashes all the data into the new table, * and destroys the old table. The approach in [Larson88] is superior in * two ways: 1) only a portion of the table is expanded when needed, * distributing the expansion cost over several insertions, and 2) portions * of the table can be locked, enabling a scalable thread-safe * implementation. * * REFERENCES * * [Hanson97] David R. Hanson. C Interfaces and Implementations: * Techniques for Creating Reusable Software. Reading, Massachusetts: * Addison-Wesley, 1997. * * [Knuth73] Donald E. Knuth. The Art of Computer Programming. Volume 3: * Sorting and Searching. Reading, Massachusetts: Addison-Wesley, 1973. * * [Larson88] Per-Ake Larson. "Dynamic Hash Tables". CACM 31(4), April * 1988, pp. 446-457. * */ #define HASH_MAIN 0 #if HASH_MAIN # include <stdio.h> # include <stdlib.h> #else # include "xf86drm.h" # ifdef XFree86LOADER # include "xf86.h" # include "xf86_ansic.h" # else # include <stdio.h> # include <stdlib.h> # endif #endif #define N(x) drm##x #define HASH_MAGIC 0xdeadbeef #define HASH_DEBUG 0 #define HASH_SIZE 512 /* Good for about 100 entries */ /* If you change this value, you probably have to change the HashHash hashing function! */ #if HASH_MAIN #define HASH_ALLOC malloc #define HASH_FREE free #define HASH_RANDOM_DECL #define HASH_RANDOM_INIT(seed) srandom(seed) #define HASH_RANDOM random() #else #define HASH_ALLOC drmMalloc #define HASH_FREE drmFree #define HASH_RANDOM_DECL void *state #define HASH_RANDOM_INIT(seed) state = drmRandomCreate(seed) #define HASH_RANDOM drmRandom(state) #endif typedef struct HashBucket { unsigned long key; void *value; struct HashBucket *next; } HashBucket, *HashBucketPtr; typedef struct HashTable { unsigned long magic; unsigned long entries; unsigned long hits; /* At top of linked list */ unsigned long partials; /* Not at top of linked list */ unsigned long misses; /* Not in table */ HashBucketPtr buckets[HASH_SIZE]; int p0; HashBucketPtr p1; } HashTable, *HashTablePtr; #if HASH_MAIN extern void *N(HashCreate)(void); extern int N(HashDestroy)(void *t); extern int N(HashLookup)(void *t, unsigned long key, unsigned long *value); extern int N(HashInsert)(void *t, unsigned long key, unsigned long value); extern int N(HashDelete)(void *t, unsigned long key); #endif static unsigned long HashHash(unsigned long key) { unsigned long hash = 0; unsigned long tmp = key; static int init = 0; static unsigned long scatter[256]; int i; if (!init) { HASH_RANDOM_DECL; HASH_RANDOM_INIT(37); for (i = 0; i < 256; i++) scatter[i] = HASH_RANDOM; ++init; } while (tmp) { hash = (hash << 1) + scatter[tmp & 0xff]; tmp >>= 8; } hash %= HASH_SIZE; #if HASH_DEBUG printf( "Hash(%d) = %d\n", key, hash); #endif return hash; } void *N(HashCreate)(void) { HashTablePtr table; int i; table = HASH_ALLOC(sizeof(*table)); if (!table) return NULL; table->magic = HASH_MAGIC; table->entries = 0; table->hits = 0; table->partials = 0; table->misses = 0; for (i = 0; i < HASH_SIZE; i++) table->buckets[i] = NULL; return table; } int N(HashDestroy)(void *t) { HashTablePtr table = (HashTablePtr)t; HashBucketPtr bucket; HashBucketPtr next; int i; if (table->magic != HASH_MAGIC) return -1; /* Bad magic */ for (i = 0; i < HASH_SIZE; i++) { for (bucket = table->buckets[i]; bucket;) { next = bucket->next; HASH_FREE(bucket); bucket = next; } } HASH_FREE(table); return 0; } /* Find the bucket and organize the list so that this bucket is at the top. */ static HashBucketPtr HashFind(HashTablePtr table, unsigned long key, unsigned long *h) { unsigned long hash = HashHash(key); HashBucketPtr prev = NULL; HashBucketPtr bucket; if (h) *h = hash; for (bucket = table->buckets[hash]; bucket; bucket = bucket->next) { if (bucket->key == key) { if (prev) { /* Organize */ prev->next = bucket->next; bucket->next = table->buckets[hash]; table->buckets[hash] = bucket; ++table->partials; } else { ++table->hits; } return bucket; } prev = bucket; } ++table->misses; return NULL; } int N(HashLookup)(void *t, unsigned long key, void **value) { HashTablePtr table = (HashTablePtr)t; HashBucketPtr bucket; if (table->magic != HASH_MAGIC) return -1; /* Bad magic */ bucket = HashFind(table, key, NULL); if (!bucket) return 1; /* Not found */ *value = bucket->value; return 0; /* Found */ } int N(HashInsert)(void *t, unsigned long key, void *value) { HashTablePtr table = (HashTablePtr)t; HashBucketPtr bucket; unsigned long hash; if (table->magic != HASH_MAGIC) return -1; /* Bad magic */ if (HashFind(table, key, &hash)) return 1; /* Already in table */ bucket = HASH_ALLOC(sizeof(*bucket)); if (!bucket) return -1; /* Error */ bucket->key = key; bucket->value = value; bucket->next = table->buckets[hash]; table->buckets[hash] = bucket; #if HASH_DEBUG printf("Inserted %d at %d/%p\n", key, hash, bucket); #endif return 0; /* Added to table */ } int N(HashDelete)(void *t, unsigned long key) { HashTablePtr table = (HashTablePtr)t; unsigned long hash; HashBucketPtr bucket; if (table->magic != HASH_MAGIC) return -1; /* Bad magic */ bucket = HashFind(table, key, &hash); if (!bucket) return 1; /* Not found */ table->buckets[hash] = bucket->next; HASH_FREE(bucket); return 0; } int N(HashNext)(void *t, unsigned long *key, void **value) { HashTablePtr table = (HashTablePtr)t; for (; table->p0 < HASH_SIZE; ++table->p0, table->p1 = table->buckets[table->p0]) { if (table->p1) { *key = table->p1->key; *value = table->p1->value; table->p1 = table->p1->next; return 1; } } return 0; } int N(HashFirst)(void *t, unsigned long *key, void **value) { HashTablePtr table = (HashTablePtr)t; if (table->magic != HASH_MAGIC) return -1; /* Bad magic */ table->p0 = 0; table->p1 = table->buckets[0]; return N(HashNext)(table, key, value); } #if HASH_MAIN #define DIST_LIMIT 10 static int dist[DIST_LIMIT]; static void clear_dist(void) { int i; for (i = 0; i < DIST_LIMIT; i++) dist[i] = 0; } static int count_entries(HashBucketPtr bucket) { int count = 0; for (; bucket; bucket = bucket->next) ++count; return count; } static void update_dist(int count) { if (count >= DIST_LIMIT) ++dist[DIST_LIMIT-1]; else ++dist[count]; } static void compute_dist(HashTablePtr table) { int i; HashBucketPtr bucket; printf("Entries = %ld, hits = %ld, partials = %ld, misses = %ld\n", table->entries, table->hits, table->partials, table->misses); clear_dist(); for (i = 0; i < HASH_SIZE; i++) { bucket = table->buckets[i]; update_dist(count_entries(bucket)); } for (i = 0; i < DIST_LIMIT; i++) { if (i != DIST_LIMIT-1) printf("%5d %10d\n", i, dist[i]); else printf("other %10d\n", dist[i]); } } static void check_table(HashTablePtr table, unsigned long key, unsigned long value) { unsigned long retval = 0; int retcode = N(HashLookup)(table, key, &retval); switch (retcode) { case -1: printf("Bad magic = 0x%08lx:" " key = %lu, expected = %lu, returned = %lu\n", table->magic, key, value, retval); break; case 1: printf("Not found: key = %lu, expected = %lu returned = %lu\n", key, value, retval); break; case 0: if (value != retval) printf("Bad value: key = %lu, expected = %lu, returned = %lu\n", key, value, retval); break; default: printf("Bad retcode = %d: key = %lu, expected = %lu, returned = %lu\n", retcode, key, value, retval); break; } } int main(void) { HashTablePtr table; int i; printf("\n***** 256 consecutive integers ****\n"); table = N(HashCreate)(); for (i = 0; i < 256; i++) N(HashInsert)(table, i, i); for (i = 0; i < 256; i++) check_table(table, i, i); for (i = 256; i >= 0; i--) check_table(table, i, i); compute_dist(table); N(HashDestroy)(table); printf("\n***** 1024 consecutive integers ****\n"); table = N(HashCreate)(); for (i = 0; i < 1024; i++) N(HashInsert)(table, i, i); for (i = 0; i < 1024; i++) check_table(table, i, i); for (i = 1024; i >= 0; i--) check_table(table, i, i); compute_dist(table); N(HashDestroy)(table); printf("\n***** 1024 consecutive page addresses (4k pages) ****\n"); table = N(HashCreate)(); for (i = 0; i < 1024; i++) N(HashInsert)(table, i*4096, i); for (i = 0; i < 1024; i++) check_table(table, i*4096, i); for (i = 1024; i >= 0; i--) check_table(table, i*4096, i); compute_dist(table); N(HashDestroy)(table); printf("\n***** 1024 random integers ****\n"); table = N(HashCreate)(); srandom(0xbeefbeef); for (i = 0; i < 1024; i++) N(HashInsert)(table, random(), i); srandom(0xbeefbeef); for (i = 0; i < 1024; i++) check_table(table, random(), i); srandom(0xbeefbeef); for (i = 0; i < 1024; i++) check_table(table, random(), i); compute_dist(table); N(HashDestroy)(table); printf("\n***** 5000 random integers ****\n"); table = N(HashCreate)(); srandom(0xbeefbeef); for (i = 0; i < 5000; i++) N(HashInsert)(table, random(), i); srandom(0xbeefbeef); for (i = 0; i < 5000; i++) check_table(table, random(), i); srandom(0xbeefbeef); for (i = 0; i < 5000; i++) check_table(table, random(), i); compute_dist(table); N(HashDestroy)(table); return 0; } #endif