sticore.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. #define ALT_CODE_TYPE_UNKNOWN 0x00 /* alt code type values */
  16. #define ALT_CODE_TYPE_PA_RISC_64 0x01
  17. /* The latency of the STI functions cannot really be reduced by setting
  18. * this to 0; STI doesn't seem to be designed to allow calling a different
  19. * function (or the same function with different arguments) after a
  20. * function exited with 1 as return value.
  21. *
  22. * As all of the functions below could be called from interrupt context,
  23. * we have to spin_lock_irqsave around the do { ret = bla(); } while(ret==1)
  24. * block. Really bad latency there.
  25. *
  26. * Probably the best solution to all this is have the generic code manage
  27. * the screen buffer and a kernel thread to call STI occasionally.
  28. *
  29. * Luckily, the frame buffer guys have the same problem so we can just wait
  30. * for them to fix it and steal their solution. prumpf
  31. */
  32. #include <asm/io.h>
  33. #define STI_WAIT 1
  34. #define STI_PTR(p) ( virt_to_phys(p) )
  35. #define PTR_STI(p) ( phys_to_virt((unsigned long)p) )
  36. #define sti_onscreen_x(sti) (sti->glob_cfg->onscreen_x)
  37. #define sti_onscreen_y(sti) (sti->glob_cfg->onscreen_y)
  38. /* sti_font_xy() use the native font ROM ! */
  39. #define sti_font_x(sti) (PTR_STI(sti->font)->width)
  40. #define sti_font_y(sti) (PTR_STI(sti->font)->height)
  41. #ifdef CONFIG_64BIT
  42. #define STI_LOWMEM (GFP_KERNEL | GFP_DMA)
  43. #else
  44. #define STI_LOWMEM (GFP_KERNEL)
  45. #endif
  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. /* sti_all_data is an internal struct which needs to be allocated in
  257. * low memory (< 4GB) if STI is used with 32bit STI on a 64bit kernel */
  258. struct sti_all_data {
  259. struct sti_glob_cfg glob_cfg;
  260. struct sti_glob_cfg_ext glob_cfg_ext;
  261. struct sti_conf_inptr inq_inptr;
  262. struct sti_conf_outptr inq_outptr; /* configuration */
  263. struct sti_conf_outptr_ext inq_outptr_ext;
  264. struct sti_init_inptr_ext init_inptr_ext;
  265. struct sti_init_inptr init_inptr;
  266. struct sti_init_outptr init_outptr;
  267. struct sti_blkmv_inptr blkmv_inptr;
  268. struct sti_blkmv_outptr blkmv_outptr;
  269. struct sti_font_inptr font_inptr;
  270. struct sti_font_outptr font_outptr;
  271. /* leave as last entries */
  272. unsigned long save_addr[1024 / sizeof(unsigned long)];
  273. /* min 256 bytes which is STI default, max sti->sti_mem_request */
  274. unsigned long sti_mem_addr[256 / sizeof(unsigned long)];
  275. /* do not add something below here ! */
  276. };
  277. /* internal generic STI struct */
  278. struct sti_struct {
  279. spinlock_t lock;
  280. /* the following fields needs to be filled in by the word/byte routines */
  281. int font_width;
  282. int font_height;
  283. /* char **mon_strings; */
  284. int sti_mem_request;
  285. u32 graphics_id[2];
  286. struct sti_cooked_rom *rom;
  287. unsigned long font_unpmv;
  288. unsigned long block_move;
  289. unsigned long init_graph;
  290. unsigned long inq_conf;
  291. /* all following fields are initialized by the generic routines */
  292. int text_planes;
  293. region_t regions[STI_REGION_MAX];
  294. unsigned long regions_phys[STI_REGION_MAX];
  295. struct sti_glob_cfg *glob_cfg; /* points into sti_all_data */
  296. struct sti_cooked_font *font; /* ptr to selected font (cooked) */
  297. struct pci_dev *pd;
  298. /* PCI data structures (pg. 17ff from sti.pdf) */
  299. u8 rm_entry[16]; /* pci region mapper array == pci config space offset */
  300. /* pointer to the fb_info where this STI device is used */
  301. struct fb_info *info;
  302. /* pointer to all internal data */
  303. struct sti_all_data *sti_data;
  304. };
  305. /* sticore interface functions */
  306. struct sti_struct *sti_get_rom(unsigned int index); /* 0: default sti */
  307. /* sticore main function to call STI firmware */
  308. int sti_call(const struct sti_struct *sti, unsigned long func,
  309. const void *flags, void *inptr, void *outptr,
  310. struct sti_glob_cfg *glob_cfg);
  311. /* functions to call the STI ROM directly */
  312. void sti_putc(struct sti_struct *sti, int c, int y, int x);
  313. void sti_set(struct sti_struct *sti, int src_y, int src_x,
  314. int height, int width, u8 color);
  315. void sti_clear(struct sti_struct *sti, int src_y, int src_x,
  316. int height, int width, int c);
  317. void sti_bmove(struct sti_struct *sti, int src_y, int src_x,
  318. int dst_y, int dst_x, int height, int width);
  319. #endif /* STICORE_H */