sticore.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. #ifndef STICORE_H
  2. #define STICORE_H
  3. /* generic STI structures & functions */
  4. #if 0
  5. #define DPRINTK(x) printk x
  6. #else
  7. #define DPRINTK(x)
  8. #endif
  9. #define MAX_STI_ROMS 4 /* max no. of ROMs which this driver handles */
  10. #define STI_REGION_MAX 8 /* hardcoded STI constants */
  11. #define STI_DEV_NAME_LENGTH 32
  12. #define STI_MONITOR_MAX 256
  13. #define STI_FONT_HPROMAN8 1
  14. #define STI_FONT_KANA8 2
  15. /* The latency of the STI functions cannot really be reduced by setting
  16. * this to 0; STI doesn't seem to be designed to allow calling a different
  17. * function (or the same function with different arguments) after a
  18. * function exited with 1 as return value.
  19. *
  20. * As all of the functions below could be called from interrupt context,
  21. * we have to spin_lock_irqsave around the do { ret = bla(); } while(ret==1)
  22. * block. Really bad latency there.
  23. *
  24. * Probably the best solution to all this is have the generic code manage
  25. * the screen buffer and a kernel thread to call STI occasionally.
  26. *
  27. * Luckily, the frame buffer guys have the same problem so we can just wait
  28. * for them to fix it and steal their solution. prumpf
  29. */
  30. #include <asm/io.h>
  31. #define STI_WAIT 1
  32. #define STI_PTR(p) ( virt_to_phys(p) )
  33. #define PTR_STI(p) ( phys_to_virt((unsigned long)p) )
  34. #define STI_CALL(func, flags, inptr, outptr, glob_cfg) \
  35. ({ \
  36. pdc_sti_call( func, STI_PTR(flags), \
  37. STI_PTR(inptr), \
  38. STI_PTR(outptr), \
  39. STI_PTR(glob_cfg)); \
  40. })
  41. #define sti_onscreen_x(sti) (sti->glob_cfg->onscreen_x)
  42. #define sti_onscreen_y(sti) (sti->glob_cfg->onscreen_y)
  43. /* sti_font_xy() use the native font ROM ! */
  44. #define sti_font_x(sti) (PTR_STI(sti->font)->width)
  45. #define sti_font_y(sti) (PTR_STI(sti->font)->height)
  46. /* STI function configuration structs */
  47. typedef union region {
  48. struct {
  49. u32 offset : 14; /* offset in 4kbyte page */
  50. u32 sys_only : 1; /* don't map to user space */
  51. u32 cache : 1; /* map to data cache */
  52. u32 btlb : 1; /* map to block tlb */
  53. u32 last : 1; /* last region in list */
  54. u32 length : 14; /* length in 4kbyte page */
  55. } region_desc;
  56. u32 region; /* complete region value */
  57. } region_t;
  58. #define REGION_OFFSET_TO_PHYS( rt, hpa ) \
  59. (((rt).region_desc.offset << 12) + (hpa))
  60. struct sti_glob_cfg_ext {
  61. u8 curr_mon; /* current monitor configured */
  62. u8 friendly_boot; /* in friendly boot mode */
  63. s16 power; /* power calculation (in Watts) */
  64. s32 freq_ref; /* frequency reference */
  65. u32 sti_mem_addr; /* pointer to global sti memory (size=sti_mem_request) */
  66. u32 future_ptr; /* pointer to future data */
  67. };
  68. struct sti_glob_cfg {
  69. s32 text_planes; /* number of planes used for text */
  70. s16 onscreen_x; /* screen width in pixels */
  71. s16 onscreen_y; /* screen height in pixels */
  72. s16 offscreen_x; /* offset width in pixels */
  73. s16 offscreen_y; /* offset height in pixels */
  74. s16 total_x; /* frame buffer width in pixels */
  75. s16 total_y; /* frame buffer height in pixels */
  76. u32 region_ptrs[STI_REGION_MAX]; /* region pointers */
  77. s32 reent_lvl; /* storage for reentry level value */
  78. u32 save_addr; /* where to save or restore reentrant state */
  79. u32 ext_ptr; /* pointer to extended glob_cfg data structure */
  80. };
  81. /* STI init function structs */
  82. struct sti_init_flags {
  83. u32 wait : 1; /* should routine idle wait or not */
  84. u32 reset : 1; /* hard reset the device? */
  85. u32 text : 1; /* turn on text display planes? */
  86. u32 nontext : 1; /* turn on non-text display planes? */
  87. u32 clear : 1; /* clear text display planes? */
  88. u32 cmap_blk : 1; /* non-text planes cmap black? */
  89. u32 enable_be_timer : 1; /* enable bus error timer */
  90. u32 enable_be_int : 1; /* enable bus error timer interrupt */
  91. u32 no_chg_tx : 1; /* don't change text settings */
  92. u32 no_chg_ntx : 1; /* don't change non-text settings */
  93. u32 no_chg_bet : 1; /* don't change berr timer settings */
  94. u32 no_chg_bei : 1; /* don't change berr int settings */
  95. u32 init_cmap_tx : 1; /* initialize cmap for text planes */
  96. u32 cmt_chg : 1; /* change current monitor type */
  97. u32 retain_ie : 1; /* don't allow reset to clear int enables */
  98. u32 caller_bootrom : 1; /* set only by bootrom for each call */
  99. u32 caller_kernel : 1; /* set only by kernel for each call */
  100. u32 caller_other : 1; /* set only by non-[BR/K] caller */
  101. u32 pad : 14; /* pad to word boundary */
  102. u32 future_ptr; /* pointer to future data */
  103. };
  104. struct sti_init_inptr_ext {
  105. u8 config_mon_type; /* configure to monitor type */
  106. u8 pad[1]; /* pad to word boundary */
  107. u16 inflight_data; /* inflight data possible on PCI */
  108. u32 future_ptr; /* pointer to future data */
  109. };
  110. struct sti_init_inptr {
  111. s32 text_planes; /* number of planes to use for text */
  112. u32 ext_ptr; /* pointer to extended init_graph inptr data structure*/
  113. };
  114. struct sti_init_outptr {
  115. s32 errno; /* error number on failure */
  116. s32 text_planes; /* number of planes used for text */
  117. u32 future_ptr; /* pointer to future data */
  118. };
  119. /* STI configuration function structs */
  120. struct sti_conf_flags {
  121. u32 wait : 1; /* should routine idle wait or not */
  122. u32 pad : 31; /* pad to word boundary */
  123. u32 future_ptr; /* pointer to future data */
  124. };
  125. struct sti_conf_inptr {
  126. u32 future_ptr; /* pointer to future data */
  127. };
  128. struct sti_conf_outptr_ext {
  129. u32 crt_config[3]; /* hardware specific X11/OGL information */
  130. u32 crt_hdw[3];
  131. u32 future_ptr;
  132. };
  133. struct sti_conf_outptr {
  134. s32 errno; /* error number on failure */
  135. s16 onscreen_x; /* screen width in pixels */
  136. s16 onscreen_y; /* screen height in pixels */
  137. s16 offscreen_x; /* offscreen width in pixels */
  138. s16 offscreen_y; /* offscreen height in pixels */
  139. s16 total_x; /* frame buffer width in pixels */
  140. s16 total_y; /* frame buffer height in pixels */
  141. s32 bits_per_pixel; /* bits/pixel device has configured */
  142. s32 bits_used; /* bits which can be accessed */
  143. s32 planes; /* number of fb planes in system */
  144. u8 dev_name[STI_DEV_NAME_LENGTH]; /* null terminated product name */
  145. u32 attributes; /* flags denoting attributes */
  146. u32 ext_ptr; /* pointer to future data */
  147. };
  148. struct sti_rom {
  149. u8 type[4];
  150. u8 res004;
  151. u8 num_mons;
  152. u8 revno[2];
  153. u32 graphics_id[2];
  154. u32 font_start;
  155. u32 statesize;
  156. u32 last_addr;
  157. u32 region_list;
  158. u16 reentsize;
  159. u16 maxtime;
  160. u32 mon_tbl_addr;
  161. u32 user_data_addr;
  162. u32 sti_mem_req;
  163. u32 user_data_size;
  164. u16 power;
  165. u8 bus_support;
  166. u8 ext_bus_support;
  167. u8 alt_code_type;
  168. u8 ext_dd_struct[3];
  169. u32 cfb_addr;
  170. u32 init_graph;
  171. u32 state_mgmt;
  172. u32 font_unpmv;
  173. u32 block_move;
  174. u32 self_test;
  175. u32 excep_hdlr;
  176. u32 inq_conf;
  177. u32 set_cm_entry;
  178. u32 dma_ctrl;
  179. u8 res040[7 * 4];
  180. u32 init_graph_addr;
  181. u32 state_mgmt_addr;
  182. u32 font_unp_addr;
  183. u32 block_move_addr;
  184. u32 self_test_addr;
  185. u32 excep_hdlr_addr;
  186. u32 inq_conf_addr;
  187. u32 set_cm_entry_addr;
  188. u32 image_unpack_addr;
  189. u32 pa_risx_addrs[7];
  190. };
  191. struct sti_rom_font {
  192. u16 first_char;
  193. u16 last_char;
  194. u8 width;
  195. u8 height;
  196. u8 font_type; /* language type */
  197. u8 bytes_per_char;
  198. u32 next_font;
  199. u8 underline_height;
  200. u8 underline_pos;
  201. u8 res008[2];
  202. };
  203. /* sticore internal font handling */
  204. struct sti_cooked_font {
  205. struct sti_rom_font *raw;
  206. struct sti_cooked_font *next_font;
  207. };
  208. struct sti_cooked_rom {
  209. struct sti_rom *raw;
  210. struct sti_cooked_font *font_start;
  211. };
  212. /* STI font printing function structs */
  213. struct sti_font_inptr {
  214. u32 font_start_addr; /* address of font start */
  215. s16 index; /* index into font table of character */
  216. u8 fg_color; /* foreground color of character */
  217. u8 bg_color; /* background color of character */
  218. s16 dest_x; /* X location of character upper left */
  219. s16 dest_y; /* Y location of character upper left */
  220. u32 future_ptr; /* pointer to future data */
  221. };
  222. struct sti_font_flags {
  223. u32 wait : 1; /* should routine idle wait or not */
  224. u32 non_text : 1; /* font unpack/move in non_text planes =1, text =0 */
  225. u32 pad : 30; /* pad to word boundary */
  226. u32 future_ptr; /* pointer to future data */
  227. };
  228. struct sti_font_outptr {
  229. s32 errno; /* error number on failure */
  230. u32 future_ptr; /* pointer to future data */
  231. };
  232. /* STI blockmove structs */
  233. struct sti_blkmv_flags {
  234. u32 wait : 1; /* should routine idle wait or not */
  235. u32 color : 1; /* change color during move? */
  236. u32 clear : 1; /* clear during move? */
  237. u32 non_text : 1; /* block move in non_text planes =1, text =0 */
  238. u32 pad : 28; /* pad to word boundary */
  239. u32 future_ptr; /* pointer to future data */
  240. };
  241. struct sti_blkmv_inptr {
  242. u8 fg_color; /* foreground color after move */
  243. u8 bg_color; /* background color after move */
  244. s16 src_x; /* source upper left pixel x location */
  245. s16 src_y; /* source upper left pixel y location */
  246. s16 dest_x; /* dest upper left pixel x location */
  247. s16 dest_y; /* dest upper left pixel y location */
  248. s16 width; /* block width in pixels */
  249. s16 height; /* block height in pixels */
  250. u32 future_ptr; /* pointer to future data */
  251. };
  252. struct sti_blkmv_outptr {
  253. s32 errno; /* error number on failure */
  254. u32 future_ptr; /* pointer to future data */
  255. };
  256. /* internal generic STI struct */
  257. struct sti_struct {
  258. spinlock_t lock;
  259. /* the following fields needs to be filled in by the word/byte routines */
  260. int font_width;
  261. int font_height;
  262. /* char **mon_strings; */
  263. int sti_mem_request;
  264. u32 graphics_id[2];
  265. struct sti_cooked_rom *rom;
  266. unsigned long font_unpmv;
  267. unsigned long block_move;
  268. unsigned long init_graph;
  269. unsigned long inq_conf;
  270. /* all following fields are initialized by the generic routines */
  271. int text_planes;
  272. region_t regions[STI_REGION_MAX];
  273. unsigned long regions_phys[STI_REGION_MAX];
  274. struct sti_glob_cfg *glob_cfg;
  275. struct sti_cooked_font *font; /* ptr to selected font (cooked) */
  276. struct sti_conf_outptr outptr; /* configuration */
  277. struct sti_conf_outptr_ext outptr_ext;
  278. struct pci_dev *pd;
  279. /* PCI data structures (pg. 17ff from sti.pdf) */
  280. u8 rm_entry[16]; /* pci region mapper array == pci config space offset */
  281. /* pointer to the fb_info where this STI device is used */
  282. struct fb_info *info;
  283. };
  284. /* sticore interface functions */
  285. struct sti_struct *sti_get_rom(unsigned int index); /* 0: default sti */
  286. /* functions to call the STI ROM directly */
  287. void sti_putc(struct sti_struct *sti, int c, int y, int x);
  288. void sti_set(struct sti_struct *sti, int src_y, int src_x,
  289. int height, int width, u8 color);
  290. void sti_clear(struct sti_struct *sti, int src_y, int src_x,
  291. int height, int width, int c);
  292. void sti_bmove(struct sti_struct *sti, int src_y, int src_x,
  293. int dst_y, int dst_x, int height, int width);
  294. #endif /* STICORE_H */