Subversion Repositories Kolibri OS

Rev

Rev 868 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #include "pci.h"
  3. #include "rhd_regs.h"
  4.  
  5. #define IS_R300_3D   0
  6. #define IS_R500_3D   1
  7.  
  8. #define R300_PIO     1
  9.  
  10. enum RHD_CHIPSETS {
  11.     RHD_UNKNOWN = 0,
  12.     RHD_R300,
  13.     RHD_R350,
  14.     RHD_RV350,
  15.     RHD_RV370,
  16.     RHD_RV380,
  17.     /* R500 */
  18.     RHD_RV505,
  19.     RHD_RV515,
  20.     RHD_RV516,
  21.     RHD_R520,
  22.     RHD_RV530,
  23.     RHD_RV535,
  24.     RHD_RV550,
  25.     RHD_RV560,
  26.     RHD_RV570,
  27.     RHD_R580,
  28.     /* R500 Mobility */
  29.     RHD_M52,
  30.     RHD_M54,
  31.     RHD_M56,
  32.     RHD_M58,
  33.     RHD_M62,
  34.     RHD_M64,
  35.     RHD_M66,
  36.     RHD_M68,
  37.     RHD_M71,
  38.     /* R500 integrated */
  39.     RHD_RS600,
  40.     RHD_RS690,
  41.     RHD_RS740,
  42.     /* R600 */
  43.     RHD_R600,
  44.     RHD_RV610,
  45.     RHD_RV630,
  46.     /* R600 Mobility */
  47.     RHD_M72,
  48.     RHD_M74,
  49.     RHD_M76,
  50.     /* RV670 came into existence after RV6x0 and M7x */
  51.     RHD_RV670,
  52.     RHD_R680,
  53.     RHD_RV620,
  54.     RHD_M82,
  55.     RHD_RV635,
  56.     RHD_M86,
  57.     RHD_RS780,
  58.     RHD_CHIP_END
  59. };
  60.  
  61. enum RHD_FAMILIES {
  62.     RHD_FAMILY_UNKNOWN = 0,
  63.  
  64.     RHD_FAMILY_RADEON,
  65.  
  66.     RHD_FAMILY_RV100,
  67.     RHD_FAMILY_RS100,    /* U1 (IGP320M) or A3 (IGP320)*/
  68.     RHD_FAMILY_RV200,
  69.     RHD_FAMILY_RS200,    /* U2 (IGP330M/340M/350M) or A4 (IGP330/340/345/350), RS250 (IGP 7000) */
  70.     RHD_FAMILY_R200,
  71.     RHD_FAMILY_RV250,
  72.     RHD_FAMILY_RS300,    /* RS300/RS350 */
  73.     RHD_FAMILY_RV280,
  74.  
  75.     RHD_FAMILY_R300,
  76.     RHD_FAMILY_R350,
  77.     RHD_FAMILY_RV350,
  78.     RHD_FAMILY_RV380,    /* RV370/RV380/M22/M24 */
  79.     RHD_FAMILY_R420,     /* R420/R423/M18 */
  80.     RHD_FAMILY_RV410,    /* RV410, M26 */
  81.     RHD_FAMILY_RS400,    /* xpress 200, 200m (RS400) Intel */
  82.     RHD_FAMILY_RS480,    /* xpress 200, 200m (RS410/480/482/485) AMD */
  83.  
  84.     RHD_FAMILY_RV515,
  85.     RHD_FAMILY_R520,
  86.     RHD_FAMILY_RV530,
  87.     RHD_FAMILY_RV560,
  88.     RHD_FAMILY_RV570,
  89.     RHD_FAMILY_R580,
  90.     RHD_FAMILY_RS690,
  91.     RHD_FAMILY_R600,
  92.     RHD_FAMILY_RV610,
  93.     RHD_FAMILY_RV630,
  94.     RHD_FAMILY_RV670,
  95.     RHD_FAMILY_RV620,
  96.     RHD_FAMILY_RV635,
  97.     RHD_FAMILY_RS780
  98. };
  99.  
  100. #define RHD_FB_BAR         0
  101. #define RHD_MMIO_BAR       2
  102.  
  103. #define RHD_MEM_GART       1
  104. #define RHD_MEM_FB         2
  105.  
  106. typedef struct RHDRec
  107. {
  108.   CARD32            MMIOBase;
  109.   CARD32            MMIOMapSize;
  110.   CARD32            videoRam;
  111.  
  112. //  CARD32            FbBase;            /* map base of fb   */
  113.   CARD32            PhisBase;
  114.   CARD32            FbIntAddress;      /* card internal address of FB */
  115.   CARD32            FbMapSize;
  116.  
  117.   CARD32            FbFreeStart;
  118.   CARD32            FbFreeSize;
  119.  
  120.   /* visible part of the framebuffer */
  121.   unsigned int      FbScanoutStart;
  122.   unsigned int      FbScanoutSize;
  123.  
  124.   enum RHD_CHIPSETS ChipSet;
  125.   enum RHD_FAMILIES ChipFamily;
  126.  
  127.   char              *ChipName;
  128.  
  129.   Bool              IsIGP;
  130.  
  131.   CARD32            bus;
  132.   CARD32            devfn;
  133.  
  134.   PCITAG            PciTag;
  135.   CARD16            PciDeviceID;
  136.  
  137.   CARD16            subvendor_id;
  138.   CARD16            subdevice_id;
  139.  
  140.   CARD32            memBase[6];
  141.   CARD32            ioBase[6];
  142.   CARD32            memtype[6];
  143.   CARD32            memsize[6];
  144.  
  145.   struct mem_block  *fb_heap;
  146.   struct mem_block  *gart_heap;
  147.  
  148.   CARD32            displayWidth;
  149.   CARD32            displayHeight;
  150.  
  151.   CARD32            __xmin;
  152.   CARD32            __ymin;
  153.   CARD32            __xmax;
  154.   CARD32            __ymax;
  155.  
  156.   CARD32            gui_control;
  157.   CARD32            dst_pitch_offset;
  158.   CARD32            surface_cntl;
  159.  
  160.   u32               *ring_base;
  161.   u32               ring_rp;
  162.   u32               ring_wp;
  163.  
  164.   int               num_gb_pipes;
  165.   Bool              has_tcl;
  166. }RHD_t, *RHDPtr;
  167.  
  168. extern RHD_t rhd;
  169.  
  170.  
  171.  
  172. #define R5XX_DP_BRUSH_BKGD_CLR            0x1478
  173. #define R5XX_DP_BRUSH_FRGD_CLR            0x147c
  174. #define R5XX_BRUSH_DATA0                  0x1480
  175. #define R5XX_BRUSH_DATA1                  0x1484
  176.  
  177. # define RADEON_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0)
  178. #       define RADEON_GMC_DST_PITCH_OFFSET_CNTL (1 << 1)
  179. # define RADEON_GMC_BRUSH_SOLID_COLOR     (13 << 4)
  180. # define RADEON_GMC_BRUSH_NONE            (15 << 4)
  181. # define RADEON_GMC_DST_16BPP             (4 << 8)
  182. # define RADEON_GMC_DST_24BPP             (5 << 8)
  183. # define RADEON_GMC_DST_32BPP             (6 << 8)
  184. # define RADEON_GMC_DST_DATATYPE_SHIFT     8
  185. # define RADEON_GMC_SRC_DATATYPE_COLOR    (3 << 12)
  186. # define RADEON_DP_SRC_SOURCE_MEMORY      (2 << 24)
  187. # define RADEON_DP_SRC_SOURCE_HOST_DATA   (3 << 24)
  188. # define RADEON_GMC_CLR_CMP_CNTL_DIS      (1 << 28)
  189. # define RADEON_GMC_WR_MSK_DIS            (1 << 30)
  190. # define RADEON_ROP3_S                 0x00cc0000
  191. # define RADEON_ROP3_P                 0x00f00000
  192.  
  193. #define RADEON_CP_PACKET0              0x00000000
  194. #define RADEON_CP_PACKET1              0x40000000
  195. #define RADEON_CP_PACKET2              0x80000000
  196. #define RADEON_CP_PACKET3              0xC0000000
  197.  
  198. # define RADEON_CNTL_PAINT             0x00009100
  199. # define RADEON_CNTL_BITBLT            0x00009200
  200. # define RADEON_CNTL_TRANBLT           0x00009C00
  201.  
  202. # define RADEON_CNTL_PAINT_POLYLINE    0x00009500
  203. # define RADEON_CNTL_PAINT_MULTI       0x00009A00
  204.  
  205. #define CP_PACKET0(reg, n)            \
  206.         (RADEON_CP_PACKET0 | ((n) << 16) | ((reg) >> 2))
  207.  
  208. #define CP_PACKET1(reg0, reg1)            \
  209.         (RADEON_CP_PACKET1 | (((reg1) >> 2) << 11) | ((reg0) >> 2))
  210.  
  211. #define CP_PACKET2()              \
  212.   (RADEON_CP_PACKET2)
  213.  
  214. #define CP_PACKET3( pkt, n )            \
  215.         (RADEON_CP_PACKET3 | (pkt) | ((n) << 16))
  216.  
  217. #define BEGIN_RING( n ) do {            \
  218.   ring = rhd.ring_base;                 \
  219.   write = rhd.ring_wp;                  \
  220. } while (0)
  221.  
  222. #define ADVANCE_RING()
  223.  
  224. #define OUT_RING( x ) do {        \
  225.         ring[write++] = (x);                                            \
  226. } while (0)
  227.  
  228. #define OUT_RING_REG(reg, val)            \
  229. do {                                                                    \
  230.     OUT_RING(CP_PACKET0(reg, 0));                                       \
  231.     OUT_RING(val);                                                      \
  232. } while (0)
  233.  
  234. #define DRM_MEMORYBARRIER()  __asm volatile("lock; addl $0,0(%%esp)" : : : "memory");
  235.  
  236. #define COMMIT_RING() do {                            \
  237.   rhd.ring_wp = write & 0x1FFF;                       \
  238.   /* Flush writes to ring */                          \
  239.   DRM_MEMORYBARRIER();                                \
  240.   /*GET_RING_HEAD( dev_priv );          */            \
  241.   OUTREG( RADEON_CP_RB_WPTR, rhd.ring_wp);            \
  242.         /* read from PCI bus to ensure correct posting */               \
  243.   INREG( RADEON_CP_RB_RPTR );                         \
  244. } while (0)
  245.  
  246.  
  247.  
  248. typedef struct {
  249.     int                 token;          /* id of the token */
  250.     const char *        name;           /* token name */
  251. } SymTabRec, *SymTabPtr;
  252.  
  253.  
  254.  
  255. extern inline void
  256. OUTREG8(CARD16 offset, u8 value)
  257. {
  258.   *(volatile CARD8 *)((CARD8 *)(rhd.MMIOBase + offset)) = value;
  259. }
  260.  
  261.  
  262. extern inline CARD32 INREG(CARD16 offset)
  263. {
  264.   return *(volatile CARD32 *)((CARD8*)(rhd.MMIOBase + offset));
  265. }
  266.  
  267. //#define INREG(offset) *(volatile CARD32 *)((CARD8*)(rhd.MMIOBase + (offset)))
  268.  
  269. extern inline void
  270. OUTREG(CARD16 offset, CARD32 value)
  271. {
  272.   *(volatile CARD32 *)((CARD8 *)(rhd.MMIOBase + offset)) = value;
  273. }
  274.  
  275. extern inline CARD32 _RHDRegRead(RHDPtr rhdPtr, CARD16 offset)
  276. {
  277.   return *(volatile CARD32 *)((CARD8*)(rhdPtr->MMIOBase + offset));
  278. }
  279.  
  280. extern inline void
  281. MASKREG(CARD16 offset, CARD32 value, CARD32 mask)
  282. {
  283.   CARD32 tmp;
  284.  
  285.   tmp = INREG(offset);
  286.   tmp &= ~mask;
  287.   tmp |= (value & mask);
  288.   OUTREG(offset, tmp);
  289. };
  290.  
  291. extern inline void
  292. _RHDRegWrite(RHDPtr rhdPtr, CARD16 offset, CARD32 value)
  293. {
  294.   *(volatile CARD32 *)((CARD8 *)(rhdPtr->MMIOBase + offset)) = value;
  295. }
  296.  
  297. extern inline void
  298. _RHDRegMask(RHDPtr rhdPtr, CARD16 offset, CARD32 value, CARD32 mask)
  299. {
  300.   CARD32 tmp;
  301.  
  302.   tmp = _RHDRegRead(rhdPtr, offset);
  303.   tmp &= ~mask;
  304.   tmp |= (value & mask);
  305.   _RHDRegWrite(rhdPtr, offset, tmp);
  306. };
  307.  
  308. enum RHD_FAMILIES RHDFamily(enum RHD_CHIPSETS chipset);
  309.  
  310. #define RHDRegRead(ptr, offset) _RHDRegRead((ptr)->rhdPtr, (offset))
  311. #define RHDRegWrite(ptr, offset, value) _RHDRegWrite((ptr)->rhdPtr, (offset), (value))
  312. #define RHDRegMask(ptr, offset, value, mask) _RHDRegMask((ptr)->rhdPtr, (offset), (value), (mask))
  313.  
  314.  
  315. RHDPtr FindPciDevice();
  316.  
  317. Bool RHDPreInit();
  318. int rhdInitHeap(RHDPtr rhdPtr);
  319.  
  320. #define RHDFUNC(ptr)
  321.  
  322. #define DBG(x) x
  323. //  #define DBG(x)
  324.  
  325. #pragma pack (push,1)
  326. typedef struct s_cursor
  327. {
  328.    u32   magic;                           // 'CURS'
  329.    void  (*destroy)(struct s_cursor*);    // destructor
  330.    u32   fd;                              // next object in list
  331.    u32   bk;                              // prev object in list
  332.    u32   pid;                             // owner id
  333.  
  334.    void *base;                            // allocated memory
  335.    u32   hot_x;                           // hotspot coords
  336.    u32   hot_y;
  337. }cursor_t;
  338. #pragma pack (pop)
  339.  
  340. #define LOAD_FROM_FILE   0
  341. #define LOAD_FROM_MEM    1
  342. #define LOAD_INDIRECT    2
  343.  
  344. cursor_t *create_cursor(u32 pid, void *src, u32 flags);
  345. void __stdcall copy_cursor(void *img, void *src);
  346. void destroy_cursor(cursor_t *cursor);
  347. void __destroy_cursor(cursor_t *cursor);                // wrap
  348.  
  349. void __stdcall r500_SelectCursor(cursor_t *cursor);
  350. void __stdcall r500_SetCursor(cursor_t *cursor, int x, int y);
  351. void __stdcall r500_CursorRestore(int x, int y);
  352.  
  353. void  R5xx2DInit();
  354.  
  355.  
  356. typedef struct {
  357.     u32_t x ;
  358.     u32_t y ;
  359. } xPointFixed;
  360.  
  361. typedef u32_t   xFixed_16_16;
  362.  
  363. typedef xFixed_16_16  xFixed;
  364.  
  365. #define XFIXED_BITS 16
  366.  
  367. #define xFixedToInt(f)  (int) ((f) >> XFIXED_BITS)
  368. #define IntToxFixed(i)  ((xFixed) (i) << XFIXED_BITS)
  369.  
  370. #define xFixedToFloat(f) (((float) (f)) / 65536)
  371.  
  372. #define PICT_FORMAT(bpp,type,a,r,g,b) (((bpp) << 24) |  \
  373.                                          ((type) << 16) | \
  374.                                          ((a) << 12) | \
  375.                                          ((r) << 8) | \
  376.                                          ((g) << 4) | \
  377.                                          ((b)))
  378.  
  379. #define PICT_FORMAT_A(f)  (((f) >> 12) & 0x0f)
  380. #define PICT_FORMAT_RGB(f)  (((f)      ) & 0xfff)
  381.  
  382. #define PICT_TYPE_OTHER 0
  383. #define PICT_TYPE_A     1
  384. #define PICT_TYPE_ARGB  2
  385. #define PICT_TYPE_ABGR  3
  386. #define PICT_TYPE_COLOR 4
  387. #define PICT_TYPE_GRAY  5
  388.  
  389. typedef enum _PictFormatShort {
  390.    PICT_a8r8g8b8 =      PICT_FORMAT(32,PICT_TYPE_ARGB,8,8,8,8),
  391.    PICT_x8r8g8b8 =      PICT_FORMAT(32,PICT_TYPE_ARGB,0,8,8,8),
  392.    PICT_a8b8g8r8 =      PICT_FORMAT(32,PICT_TYPE_ABGR,8,8,8,8),
  393.    PICT_x8b8g8r8 =      PICT_FORMAT(32,PICT_TYPE_ABGR,0,8,8,8),
  394.  
  395. /* 24bpp formats */
  396.    PICT_r8g8b8 =        PICT_FORMAT(24,PICT_TYPE_ARGB,0,8,8,8),
  397.    PICT_b8g8r8 =        PICT_FORMAT(24,PICT_TYPE_ABGR,0,8,8,8),
  398.  
  399. /* 16bpp formats */
  400.    PICT_r5g6b5 =        PICT_FORMAT(16,PICT_TYPE_ARGB,0,5,6,5),
  401.    PICT_b5g6r5 =        PICT_FORMAT(16,PICT_TYPE_ABGR,0,5,6,5),
  402.  
  403.    PICT_a1r5g5b5 =      PICT_FORMAT(16,PICT_TYPE_ARGB,1,5,5,5),
  404.    PICT_x1r5g5b5 =      PICT_FORMAT(16,PICT_TYPE_ARGB,0,5,5,5),
  405.    PICT_a1b5g5r5 =      PICT_FORMAT(16,PICT_TYPE_ABGR,1,5,5,5),
  406.    PICT_x1b5g5r5 =      PICT_FORMAT(16,PICT_TYPE_ABGR,0,5,5,5),
  407.    PICT_a4r4g4b4 =      PICT_FORMAT(16,PICT_TYPE_ARGB,4,4,4,4),
  408.    PICT_x4r4g4b4 =      PICT_FORMAT(16,PICT_TYPE_ARGB,0,4,4,4),
  409.    PICT_a4b4g4r4 =      PICT_FORMAT(16,PICT_TYPE_ABGR,4,4,4,4),
  410.    PICT_x4b4g4r4 =      PICT_FORMAT(16,PICT_TYPE_ABGR,0,4,4,4),
  411.  
  412. /* 8bpp formats */
  413.    PICT_a8 =            PICT_FORMAT(8,PICT_TYPE_A,8,0,0,0),
  414.    PICT_r3g3b2 =        PICT_FORMAT(8,PICT_TYPE_ARGB,0,3,3,2),
  415.    PICT_b2g3r3 =        PICT_FORMAT(8,PICT_TYPE_ABGR,0,3,3,2),
  416.    PICT_a2r2g2b2 =      PICT_FORMAT(8,PICT_TYPE_ARGB,2,2,2,2),
  417.    PICT_a2b2g2r2 =      PICT_FORMAT(8,PICT_TYPE_ABGR,2,2,2,2),
  418.  
  419.    PICT_c8 =            PICT_FORMAT(8,PICT_TYPE_COLOR,0,0,0,0),
  420.    PICT_g8 =            PICT_FORMAT(8,PICT_TYPE_GRAY,0,0,0,0),
  421.  
  422.    PICT_x4a4 =          PICT_FORMAT(8,PICT_TYPE_A,4,0,0,0),
  423.  
  424.    PICT_x4c4 =          PICT_FORMAT(8,PICT_TYPE_COLOR,0,0,0,0),
  425.    PICT_x4g4 =          PICT_FORMAT(8,PICT_TYPE_GRAY,0,0,0,0),
  426.  
  427. /* 4bpp formats */
  428.    PICT_a4 =            PICT_FORMAT(4,PICT_TYPE_A,4,0,0,0),
  429.    PICT_r1g2b1 =        PICT_FORMAT(4,PICT_TYPE_ARGB,0,1,2,1),
  430.    PICT_b1g2r1 =        PICT_FORMAT(4,PICT_TYPE_ABGR,0,1,2,1),
  431.    PICT_a1r1g1b1 =      PICT_FORMAT(4,PICT_TYPE_ARGB,1,1,1,1),
  432.    PICT_a1b1g1r1 =      PICT_FORMAT(4,PICT_TYPE_ABGR,1,1,1,1),
  433.  
  434.    PICT_c4 =            PICT_FORMAT(4,PICT_TYPE_COLOR,0,0,0,0),
  435.    PICT_g4 =            PICT_FORMAT(4,PICT_TYPE_GRAY,0,0,0,0),
  436.  
  437. /* 1bpp formats */
  438.    PICT_a1 =            PICT_FORMAT(1,PICT_TYPE_A,1,0,0,0),
  439.  
  440.    PICT_g1 =            PICT_FORMAT(1,PICT_TYPE_GRAY,0,0,0,0),
  441. } PictFormatShort;
  442.  
  443. void dump_mem();
  444.